refactor: make session::browser_context_ a const raw_ref (#42728)
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
parent
0a8eae9019
commit
cf5fb4505e
2 changed files with 15 additions and 14 deletions
|
@ -544,7 +544,8 @@ gin::WrapperInfo Session::kWrapperInfo = {gin::kEmbedderNativeGin};
|
||||||
Session::Session(v8::Isolate* isolate, ElectronBrowserContext* browser_context)
|
Session::Session(v8::Isolate* isolate, ElectronBrowserContext* browser_context)
|
||||||
: isolate_(isolate),
|
: isolate_(isolate),
|
||||||
network_emulation_token_(base::UnguessableToken::Create()),
|
network_emulation_token_(base::UnguessableToken::Create()),
|
||||||
browser_context_(browser_context) {
|
browser_context_{
|
||||||
|
raw_ref<ElectronBrowserContext>::from_ptr(browser_context)} {
|
||||||
// Observe DownloadManager to get download notifications.
|
// Observe DownloadManager to get download notifications.
|
||||||
browser_context->GetDownloadManager()->AddObserver(this);
|
browser_context->GetDownloadManager()->AddObserver(this);
|
||||||
|
|
||||||
|
@ -556,9 +557,8 @@ Session::Session(v8::Isolate* isolate, ElectronBrowserContext* browser_context)
|
||||||
std::make_unique<UserDataLink>(this));
|
std::make_unique<UserDataLink>(this));
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
SpellcheckService* service =
|
if (auto* service =
|
||||||
SpellcheckServiceFactory::GetForContext(browser_context_);
|
SpellcheckServiceFactory::GetForContext(browser_context)) {
|
||||||
if (service) {
|
|
||||||
service->SetHunspellObserver(this);
|
service->SetHunspellObserver(this);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -572,9 +572,8 @@ Session::~Session() {
|
||||||
browser_context()->GetDownloadManager()->RemoveObserver(this);
|
browser_context()->GetDownloadManager()->RemoveObserver(this);
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
SpellcheckService* service =
|
if (auto* service =
|
||||||
SpellcheckServiceFactory::GetForContext(browser_context_);
|
SpellcheckServiceFactory::GetForContext(browser_context())) {
|
||||||
if (service) {
|
|
||||||
service->SetHunspellObserver(nullptr);
|
service->SetHunspellObserver(nullptr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -639,7 +638,7 @@ v8::Local<v8::Promise> Session::ResolveHost(
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
auto fn = base::MakeRefCounted<ResolveHostFunction>(
|
auto fn = base::MakeRefCounted<ResolveHostFunction>(
|
||||||
browser_context_, std::move(host),
|
browser_context(), std::move(host),
|
||||||
params ? std::move(params.value()) : nullptr,
|
params ? std::move(params.value()) : nullptr,
|
||||||
base::BindOnce(
|
base::BindOnce(
|
||||||
[](gin_helper::Promise<gin_helper::Dictionary> promise,
|
[](gin_helper::Promise<gin_helper::Dictionary> promise,
|
||||||
|
@ -1242,7 +1241,7 @@ void Session::Preconnect(const gin_helper::Dictionary& options,
|
||||||
DCHECK_GT(num_sockets_to_preconnect, 0);
|
DCHECK_GT(num_sockets_to_preconnect, 0);
|
||||||
content::GetUIThreadTaskRunner({})->PostTask(
|
content::GetUIThreadTaskRunner({})->PostTask(
|
||||||
FROM_HERE,
|
FROM_HERE,
|
||||||
base::BindOnce(&StartPreconnectOnUI, base::Unretained(browser_context_),
|
base::BindOnce(&StartPreconnectOnUI, base::Unretained(browser_context()),
|
||||||
url, num_sockets_to_preconnect));
|
url, num_sockets_to_preconnect));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1434,7 +1433,7 @@ v8::Local<v8::Promise> Session::ListWordsInSpellCheckerDictionary() {
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
SpellcheckService* spellcheck =
|
SpellcheckService* spellcheck =
|
||||||
SpellcheckServiceFactory::GetForContext(browser_context_);
|
SpellcheckServiceFactory::GetForContext(browser_context());
|
||||||
|
|
||||||
if (!spellcheck) {
|
if (!spellcheck) {
|
||||||
promise.RejectWithErrorMessage(
|
promise.RejectWithErrorMessage(
|
||||||
|
@ -1462,7 +1461,7 @@ bool Session::AddWordToSpellCheckerDictionary(const std::string& word) {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
SpellcheckService* service =
|
SpellcheckService* service =
|
||||||
SpellcheckServiceFactory::GetForContext(browser_context_);
|
SpellcheckServiceFactory::GetForContext(browser_context());
|
||||||
if (!service)
|
if (!service)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -1483,7 +1482,7 @@ bool Session::RemoveWordFromSpellCheckerDictionary(const std::string& word) {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
SpellcheckService* service =
|
SpellcheckService* service =
|
||||||
SpellcheckServiceFactory::GetForContext(browser_context_);
|
SpellcheckServiceFactory::GetForContext(browser_context());
|
||||||
if (!service)
|
if (!service)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,9 @@ class Session : public gin::Wrappable<Session>,
|
||||||
const base::FilePath& path,
|
const base::FilePath& path,
|
||||||
base::Value::Dict options = {});
|
base::Value::Dict options = {});
|
||||||
|
|
||||||
ElectronBrowserContext* browser_context() const { return browser_context_; }
|
ElectronBrowserContext* browser_context() const {
|
||||||
|
return &browser_context_.get();
|
||||||
|
}
|
||||||
|
|
||||||
// gin::Wrappable
|
// gin::Wrappable
|
||||||
static gin::WrapperInfo kWrapperInfo;
|
static gin::WrapperInfo kWrapperInfo;
|
||||||
|
@ -215,7 +217,7 @@ class Session : public gin::Wrappable<Session>,
|
||||||
// The client id to enable the network throttler.
|
// The client id to enable the network throttler.
|
||||||
base::UnguessableToken network_emulation_token_;
|
base::UnguessableToken network_emulation_token_;
|
||||||
|
|
||||||
raw_ptr<ElectronBrowserContext> browser_context_;
|
const raw_ref<ElectronBrowserContext> browser_context_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue