From ffed3e9c0c17ec109d5d8e34b7554a10a57fee4f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 1 Aug 2016 20:11:17 +0900 Subject: [PATCH] Move the code to native --- atom/browser/api/atom_api_session.cc | 11 +++++++++++ lib/browser/api/session.js | 6 ------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/atom/browser/api/atom_api_session.cc b/atom/browser/api/atom_api_session.cc index 02fafddf940d..9117ff58a9fb 100644 --- a/atom/browser/api/atom_api_session.cc +++ b/atom/browser/api/atom_api_session.cc @@ -4,6 +4,7 @@ #include "atom/browser/api/atom_api_session.h" +#include #include #include @@ -173,6 +174,9 @@ const char kPersistPrefix[] = "persist:"; using WrapSessionCallback = base::Callback)>; WrapSessionCallback g_wrap_session; +// Referenced session objects. +std::map> g_sessions; + class ResolveProxyHelper { public: ResolveProxyHelper(AtomBrowserContext* browser_context, @@ -346,6 +350,7 @@ Session::Session(v8::Isolate* isolate, AtomBrowserContext* browser_context) Session::~Session() { content::BrowserContext::GetDownloadManager(browser_context())-> RemoveObserver(this); + g_sessions.erase(weak_map_id()); } void Session::OnDownloadCreated(content::DownloadManager* manager, @@ -537,6 +542,12 @@ mate::Handle Session::CreateFrom( auto handle = mate::CreateHandle( isolate, new Session(isolate, browser_context)); g_wrap_session.Run(handle.ToV8()); + + // The Sessions should never be garbage collected, since the common pattern is + // to use partition strings, instead of using the Session object directly. + g_sessions[handle->weak_map_id()] = + v8::Global(isolate, handle.ToV8()); + return handle; } diff --git a/lib/browser/api/session.js b/lib/browser/api/session.js index ab2d27785921..d82e6d015461 100644 --- a/lib/browser/api/session.js +++ b/lib/browser/api/session.js @@ -14,15 +14,9 @@ Object.defineProperties(exports, { } }) -const sessions = [] - // Wraps native Session class. _setWrapSession(function (session) { // Session is an EventEmitter. Object.setPrototypeOf(session, EventEmitter.prototype) app.emit('session-created', session) - - // The Sessions should never be garbage collected, since the common pattern is - // to use partition strings, instead of using the Session object directly. - sessions.push(session) })