Move the ability to create BrowserContext to embedder
This commit is contained in:
parent
240b5c42b4
commit
6413a4c516
2 changed files with 11 additions and 10 deletions
|
@ -85,16 +85,13 @@ class BrowserContext::ResourceContext : public content::ResourceContext {
|
||||||
BrowserContext::BrowserContextMap BrowserContext::browser_context_map_;
|
BrowserContext::BrowserContextMap BrowserContext::browser_context_map_;
|
||||||
|
|
||||||
// static
|
// static
|
||||||
scoped_refptr<BrowserContext> BrowserContext::From(
|
scoped_refptr<BrowserContext> BrowserContext::Get(
|
||||||
const std::string& partition, bool in_memory) {
|
const std::string& partition, bool in_memory) {
|
||||||
PartitionKey key(partition, in_memory);
|
PartitionKey key(partition, in_memory);
|
||||||
if (browser_context_map_[key].get())
|
if (browser_context_map_[key].get())
|
||||||
return make_scoped_refptr(browser_context_map_[key].get());
|
return make_scoped_refptr(browser_context_map_[key].get());
|
||||||
|
|
||||||
auto browser_context = BrowserContext::Create(partition, in_memory);
|
return nullptr;
|
||||||
browser_context->InitPrefs();
|
|
||||||
browser_context_map_[key] = browser_context->weak_factory_.GetWeakPtr();
|
|
||||||
return browser_context;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BrowserContext::BrowserContext(const std::string& partition, bool in_memory)
|
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"))
|
path_ = path_.Append(FILE_PATH_LITERAL("Partitions"))
|
||||||
.Append(base::FilePath::FromUTF8Unsafe(MakePartitionName(partition)));
|
.Append(base::FilePath::FromUTF8Unsafe(MakePartitionName(partition)));
|
||||||
|
|
||||||
|
InitPrefs();
|
||||||
content::BrowserContext::Initialize(this, path_);
|
content::BrowserContext::Initialize(this, path_);
|
||||||
|
|
||||||
|
browser_context_map_[PartitionKey(partition, in_memory)] = GetWeakPtr();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserContext::InitPrefs() {
|
void BrowserContext::InitPrefs() {
|
||||||
|
|
|
@ -30,13 +30,14 @@ class BrowserContext : public base::RefCounted<BrowserContext>,
|
||||||
public content::BrowserContext,
|
public content::BrowserContext,
|
||||||
public brightray::URLRequestContextGetter::Delegate {
|
public brightray::URLRequestContextGetter::Delegate {
|
||||||
public:
|
public:
|
||||||
// Get or Create the BrowserContext according to its |partition| and |in_memory|.
|
// Get the BrowserContext according to its |partition| and |in_memory|,
|
||||||
static scoped_refptr<BrowserContext> From(
|
// empty pointer when be returned when there is no matching BrowserContext.
|
||||||
|
static scoped_refptr<BrowserContext> Get(
|
||||||
const std::string& partition, bool in_memory);
|
const std::string& partition, bool in_memory);
|
||||||
|
|
||||||
// Create a new BrowserContext, embedders should implement it on their own.
|
base::WeakPtr<BrowserContext> GetWeakPtr() {
|
||||||
static scoped_refptr<BrowserContext> Create(
|
return weak_factory_.GetWeakPtr();
|
||||||
const std::string& partition, bool in_memory);
|
}
|
||||||
|
|
||||||
// content::BrowserContext:
|
// content::BrowserContext:
|
||||||
std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
|
std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue