]> khamidou — GitHub mirrors - electron.git/commitdiff
Move management of browser context to BrowserContext
authorCheng Zhao <zcbenz@gmail.com>
Sat, 5 Sep 2015 12:54:36 +0000 (20:54 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Sun, 6 Sep 2015 02:54:34 +0000 (10:54 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/atom_browser_context.cc
atom/browser/atom_browser_context.h
atom/browser/atom_browser_main_parts.cc
atom/browser/atom_browser_main_parts.h
vendor/brightray

index d8201973fd83cc83f641193c8f521d0cfcb92317..e91656570112abe4cc470bd6848783617dbfbadb 100644 (file)
@@ -170,10 +170,8 @@ WebContents::WebContents(v8::Isolate* isolate,
     bool in_memory = false;
     options.Get("partition", &partition);
     options.Get("inMemory", &in_memory);
-    if (!partition.empty()) {
-      browser_context = AtomBrowserMainParts::Get()
-          ->GetBrowserContextForPartition(partition, in_memory);
-    }
+    if (!partition.empty())
+      browser_context = brightray::BrowserContext::From(partition, in_memory);
     content::SiteInstance* site_instance = content::SiteInstance::CreateForURL(
         browser_context, GURL("chrome-guest://fake-host"));
     content::WebContents::CreateParams params(browser_context, site_instance);
index 43573b1c707685eeff52c0b44a6e4ee1f3aaab58..81973857b1249abbde893a7bfcf40050d06b0af3 100644 (file)
@@ -56,8 +56,10 @@ std::string RemoveWhitespace(const std::string& str) {
 
 }  // namespace
 
-AtomBrowserContext::AtomBrowserContext()
-    : job_factory_(new AtomURLRequestJobFactory) {
+AtomBrowserContext::AtomBrowserContext(const std::string& partition,
+                                       bool in_memory)
+    : brightray::BrowserContext(partition, in_memory),
+      job_factory_(new AtomURLRequestJobFactory) {
 }
 
 AtomBrowserContext::~AtomBrowserContext() {
@@ -162,3 +164,13 @@ void AtomBrowserContext::RegisterPrefs(PrefRegistrySimple* pref_registry) {
 }
 
 }  // namespace atom
+
+namespace brightray {
+
+// static
+BrowserContext* BrowserContext::Create(const std::string& partition,
+                                     bool in_memory) {
+  return new atom::AtomBrowserContext(partition, in_memory);
+}
+
+}  // namespace brightray
index c1ff613b8c074f0d8126496848edf9813167819e..c99461ad9a86f3fd6ea3b182f56d90fd1cff2d69 100644 (file)
@@ -17,8 +17,8 @@ class WebViewManager;
 
 class AtomBrowserContext : public brightray::BrowserContext {
  public:
-  AtomBrowserContext();
-  virtual ~AtomBrowserContext();
+  AtomBrowserContext(const std::string& partition, bool in_memory);
+  ~AtomBrowserContext() override;
 
   // brightray::URLRequestContextGetter::Delegate:
   std::string GetUserAgent() override;
@@ -41,7 +41,8 @@ class AtomBrowserContext : public brightray::BrowserContext {
   scoped_ptr<AtomDownloadManagerDelegate> download_manager_delegate_;
   scoped_ptr<WebViewManager> guest_manager_;
 
-  AtomURLRequestJobFactory* job_factory_;  // Weak reference.
+  // Managed by brightray::BrowserContext.
+  AtomURLRequestJobFactory* job_factory_;
 
   DISALLOW_COPY_AND_ASSIGN(AtomBrowserContext);
 };
index e614f9b63658fe3dcdb9c6744fdb8880c0dac9f5..31a490464143851a6e9443b753f235aec2b3ce90 100644 (file)
@@ -50,26 +50,11 @@ AtomBrowserMainParts* AtomBrowserMainParts::Get() {
   return self_;
 }
 
-content::BrowserContext* AtomBrowserMainParts::GetBrowserContextForPartition(
-    const std::string& partition, bool in_memory) {
-  if (ContainsKey(browser_context_map_, partition))
-    return browser_context_map_[partition].get();
-
-  brightray::BrowserContext* browser_context = CreateBrowserContext();
-  browser_context->Initialize(partition, in_memory);
-  browser_context_map_[partition] = make_scoped_refptr(browser_context);
-  return browser_context;
-}
-
 void AtomBrowserMainParts::RegisterDestructionCallback(
     const base::Closure& callback) {
   destruction_callbacks_.push_back(callback);
 }
 
-brightray::BrowserContext* AtomBrowserMainParts::CreateBrowserContext() {
-  return new AtomBrowserContext();
-}
-
 void AtomBrowserMainParts::PostEarlyInitialization() {
   brightray::BrowserMainParts::PostEarlyInitialization();
 
index de53f66788bc3b9c81f44d27ca41a27f63eee0bb..59ff7c977c82c49f0ddc3c431257db64b1545e2c 100644 (file)
@@ -6,7 +6,6 @@
 #define ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
 
 #include <list>
-#include <map>
 #include <string>
 
 #include "base/callback.h"
@@ -32,10 +31,6 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
 
   static AtomBrowserMainParts* Get();
 
-  // Returns the BrowserContext associated with the partition.
-  content::BrowserContext* GetBrowserContextForPartition(
-      const std::string& partition, bool in_memory);
-
   // Register a callback that should be destroyed before JavaScript environment
   // gets destroyed.
   void RegisterDestructionCallback(const base::Closure& callback);
@@ -43,10 +38,7 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
   Browser* browser() { return browser_.get(); }
 
  protected:
-  // Implementations of brightray::BrowserMainParts.
-  brightray::BrowserContext* CreateBrowserContext() override;
-
-  // Implementations of content::BrowserMainParts.
+  // content::BrowserMainParts:
   void PostEarlyInitialization() override;
   void PreMainMessageLoopRun() override;
 #if defined(OS_MACOSX)
@@ -77,10 +69,6 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
   // List of callbacks should be executed before destroying JS env.
   std::list<base::Closure> destruction_callbacks_;
 
-  // partition_id => browser_context
-  std::map<std::string, scoped_refptr<brightray::BrowserContext>>
-      browser_context_map_;
-
   static AtomBrowserMainParts* self_;
 
   DISALLOW_COPY_AND_ASSIGN(AtomBrowserMainParts);
index ca80107e3dec28d5b49d64da9985525c3e2c4e84..b103a37d05335766421f4228fcb392cc57f8ea67 160000 (submodule)
@@ -1 +1 @@
-Subproject commit ca80107e3dec28d5b49d64da9985525c3e2c4e84
+Subproject commit b103a37d05335766421f4228fcb392cc57f8ea67