diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 236a8f5c1f2..91928d9e367 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -85,16 +85,13 @@ class BrowserContext::ResourceContext : public content::ResourceContext { BrowserContext::BrowserContextMap BrowserContext::browser_context_map_; // static -scoped_refptr BrowserContext::From( +scoped_refptr BrowserContext::Get( const std::string& partition, bool in_memory) { PartitionKey key(partition, in_memory); if (browser_context_map_[key].get()) return make_scoped_refptr(browser_context_map_[key].get()); - auto browser_context = BrowserContext::Create(partition, in_memory); - browser_context->InitPrefs(); - browser_context_map_[key] = browser_context->weak_factory_.GetWeakPtr(); - return browser_context; + return nullptr; } BrowserContext::BrowserContext(const std::string& partition, bool in_memory) @@ -112,7 +109,10 @@ BrowserContext::BrowserContext(const std::string& partition, bool in_memory) path_ = path_.Append(FILE_PATH_LITERAL("Partitions")) .Append(base::FilePath::FromUTF8Unsafe(MakePartitionName(partition))); + InitPrefs(); content::BrowserContext::Initialize(this, path_); + + browser_context_map_[PartitionKey(partition, in_memory)] = GetWeakPtr(); } void BrowserContext::InitPrefs() { diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 421ef51f43c..7ae9b269209 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -30,13 +30,14 @@ class BrowserContext : public base::RefCounted, public content::BrowserContext, public brightray::URLRequestContextGetter::Delegate { public: - // Get or Create the BrowserContext according to its |partition| and |in_memory|. - static scoped_refptr From( + // Get the BrowserContext according to its |partition| and |in_memory|, + // empty pointer when be returned when there is no matching BrowserContext. + static scoped_refptr Get( const std::string& partition, bool in_memory); - // Create a new BrowserContext, embedders should implement it on their own. - static scoped_refptr Create( - const std::string& partition, bool in_memory); + base::WeakPtr GetWeakPtr() { + return weak_factory_.GetWeakPtr(); + } // content::BrowserContext: std::unique_ptr CreateZoomLevelDelegate(