Move management of browser context to BrowserContext
This commit is contained in:
parent
ba25bed45b
commit
fafb28e41a
6 changed files with 22 additions and 38 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
2
vendor/brightray
vendored
2
vendor/brightray
vendored
|
@ -1 +1 @@
|
|||
Subproject commit ca80107e3dec28d5b49d64da9985525c3e2c4e84
|
||||
Subproject commit b103a37d05335766421f4228fcb392cc57f8ea67
|
Loading…
Add table
Reference in a new issue