mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: dangling raw_ptr<Session> in UserDataLink (#42786)
* fix: dangling raw_ptr<Session> in UserDataLink * chore: make linter happy
This commit is contained in:
@@ -530,9 +530,10 @@ class DictionaryObserver final : public SpellcheckCustomDictionary::Observer {
|
||||
#endif // BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||
|
||||
struct UserDataLink : base::SupportsUserData::Data {
|
||||
explicit UserDataLink(Session* ses) : session(ses) {}
|
||||
explicit UserDataLink(base::WeakPtr<Session> session_in)
|
||||
: session{std::move(session_in)} {}
|
||||
|
||||
raw_ptr<Session> session;
|
||||
base::WeakPtr<Session> session;
|
||||
};
|
||||
|
||||
const void* kElectronApiSessionKey = &kElectronApiSessionKey;
|
||||
@@ -553,8 +554,9 @@ Session::Session(v8::Isolate* isolate, ElectronBrowserContext* browser_context)
|
||||
|
||||
protocol_.Reset(isolate, Protocol::Create(isolate, browser_context).ToV8());
|
||||
|
||||
browser_context->SetUserData(kElectronApiSessionKey,
|
||||
std::make_unique<UserDataLink>(this));
|
||||
browser_context->SetUserData(
|
||||
kElectronApiSessionKey,
|
||||
std::make_unique<UserDataLink>(weak_factory_.GetWeakPtr()));
|
||||
|
||||
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||
if (auto* service =
|
||||
@@ -1511,7 +1513,7 @@ bool Session::IsSpellCheckerEnabled() const {
|
||||
Session* Session::FromBrowserContext(content::BrowserContext* context) {
|
||||
auto* data =
|
||||
static_cast<UserDataLink*>(context->GetUserData(kElectronApiSessionKey));
|
||||
return data ? data->session : nullptr;
|
||||
return data ? data->session.get() : nullptr;
|
||||
}
|
||||
|
||||
// static
|
||||
|
||||
Reference in New Issue
Block a user