refactor: add ElectronBrowserContext::GetDefaultBrowserContext()
(#46085)
* refactor: add ElectronBrowserContext::DestroyAllContexts()
Simpler semantics than previous implementation; also hides the
"default context must be destroyed last" implementation detail.
Co-authored-by: Charles Kerr <charles@charleskerr.com>
* refactor: add ElectronBrowserContext::GetDefaultBrowserContext()
clearer semantics than everyone calling From("", false)
Co-authored-by: Charles Kerr <charles@charleskerr.com>
* fixup! refactor: add ElectronBrowserContext::DestroyAllContexts()
fix: collision with 998de7a
---------
Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
a3ba653bee
commit
c6c67208d2
7 changed files with 15 additions and 6 deletions
|
@ -122,7 +122,7 @@ bool GlobalShortcut::Register(const ui::Accelerator& accelerator,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (instance->IsRegistrationHandledExternally()) {
|
if (instance->IsRegistrationHandledExternally()) {
|
||||||
auto* context = ElectronBrowserContext::From("", false);
|
auto* context = ElectronBrowserContext::GetDefaultBrowserContext();
|
||||||
PrefService* prefs = context->prefs();
|
PrefService* prefs = context->prefs();
|
||||||
|
|
||||||
// Need a unique profile id. Set one if not generated yet, otherwise re-use
|
// Need a unique profile id. Set one if not generated yet, otherwise re-use
|
||||||
|
|
|
@ -1779,7 +1779,7 @@ gin::Handle<Session> Session::FromPartition(v8::Isolate* isolate,
|
||||||
ElectronBrowserContext* browser_context;
|
ElectronBrowserContext* browser_context;
|
||||||
if (partition.empty()) {
|
if (partition.empty()) {
|
||||||
browser_context =
|
browser_context =
|
||||||
ElectronBrowserContext::From("", false, std::move(options));
|
ElectronBrowserContext::GetDefaultBrowserContext(std::move(options));
|
||||||
} else if (partition.starts_with(kPersistPrefix)) {
|
} else if (partition.starts_with(kPersistPrefix)) {
|
||||||
std::string name = partition.substr(8);
|
std::string name = partition.substr(8);
|
||||||
browser_context =
|
browser_context =
|
||||||
|
|
|
@ -882,6 +882,12 @@ ElectronBrowserContext* ElectronBrowserContext::From(
|
||||||
return context.get();
|
return context.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
ElectronBrowserContext* ElectronBrowserContext::GetDefaultBrowserContext(
|
||||||
|
base::Value::Dict options) {
|
||||||
|
return ElectronBrowserContext::From("", false, std::move(options));
|
||||||
|
}
|
||||||
|
|
||||||
ElectronBrowserContext* ElectronBrowserContext::FromPath(
|
ElectronBrowserContext* ElectronBrowserContext::FromPath(
|
||||||
const base::FilePath& path,
|
const base::FilePath& path,
|
||||||
base::Value::Dict options) {
|
base::Value::Dict options) {
|
||||||
|
|
|
@ -63,6 +63,10 @@ class ElectronBrowserContext : public content::BrowserContext {
|
||||||
|
|
||||||
[[nodiscard]] static bool IsValidContext(const void* context);
|
[[nodiscard]] static bool IsValidContext(const void* context);
|
||||||
|
|
||||||
|
// Get or create the default BrowserContext.
|
||||||
|
static ElectronBrowserContext* GetDefaultBrowserContext(
|
||||||
|
base::Value::Dict options = {});
|
||||||
|
|
||||||
// Get or create the BrowserContext according to its |partition| and
|
// Get or create the BrowserContext according to its |partition| and
|
||||||
// |in_memory|. The |options| will be passed to constructor when there is no
|
// |in_memory|. The |options| will be passed to constructor when there is no
|
||||||
// existing BrowserContext.
|
// existing BrowserContext.
|
||||||
|
|
|
@ -108,7 +108,7 @@ BrowserContext* ElectronExtensionsBrowserClient::GetOriginalContext(
|
||||||
BrowserContext* context) {
|
BrowserContext* context) {
|
||||||
DCHECK(context);
|
DCHECK(context);
|
||||||
if (context->IsOffTheRecord()) {
|
if (context->IsOffTheRecord()) {
|
||||||
return ElectronBrowserContext::From("", false);
|
return ElectronBrowserContext::GetDefaultBrowserContext();
|
||||||
} else {
|
} else {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
|
@ -671,8 +671,7 @@ void ElectronURLLoaderFactory::StartLoadingHttp(
|
||||||
request->method != net::HttpRequestHeaders::kHeadMethod)
|
request->method != net::HttpRequestHeaders::kHeadMethod)
|
||||||
dict.Get("uploadData", &upload_data);
|
dict.Get("uploadData", &upload_data);
|
||||||
|
|
||||||
ElectronBrowserContext* browser_context =
|
auto* browser_context = ElectronBrowserContext::GetDefaultBrowserContext();
|
||||||
ElectronBrowserContext::From("", false);
|
|
||||||
v8::Local<v8::Value> value;
|
v8::Local<v8::Value> value;
|
||||||
if (dict.Get("session", &value)) {
|
if (dict.Get("session", &value)) {
|
||||||
if (value->IsNull()) {
|
if (value->IsNull()) {
|
||||||
|
|
|
@ -139,7 +139,7 @@ bool DevToolsManagerDelegate::HasBundledFrontendResources() {
|
||||||
}
|
}
|
||||||
|
|
||||||
content::BrowserContext* DevToolsManagerDelegate::GetDefaultBrowserContext() {
|
content::BrowserContext* DevToolsManagerDelegate::GetDefaultBrowserContext() {
|
||||||
return ElectronBrowserContext::From("", false);
|
return ElectronBrowserContext::GetDefaultBrowserContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue