#include "atom/browser/api/atom_api_session.h"
+#include <map>
#include <string>
#include <vector>
using WrapSessionCallback = base::Callback<void(v8::Local<v8::Value>)>;
WrapSessionCallback g_wrap_session;
+// Referenced session objects.
+std::map<uint32_t, v8::Global<v8::Object>> g_sessions;
+
class ResolveProxyHelper {
public:
ResolveProxyHelper(AtomBrowserContext* browser_context,
Session::~Session() {
content::BrowserContext::GetDownloadManager(browser_context())->
RemoveObserver(this);
+ g_sessions.erase(weak_map_id());
}
void Session::OnDownloadCreated(content::DownloadManager* manager,
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<v8::Object>(isolate, handle.ToV8());
+
return handle;
}
}
})
-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)
})