зеркало из https://github.com/electron/electron.git
refactor: add SessionPreferences::CreateForBrowserContext() (#38656)
Copy the NativeWindowRelay::CreateForWebContents() idiom to simplify SessionPreferences's constructor and lifecycle.
This commit is contained in:
Родитель
12b85a77a8
Коммит
d95ae19edf
|
@ -345,7 +345,7 @@ Session::Session(v8::Isolate* isolate, ElectronBrowserContext* browser_context)
|
|||
// Observe DownloadManager to get download notifications.
|
||||
browser_context->GetDownloadManager()->AddObserver(this);
|
||||
|
||||
new SessionPreferences(browser_context);
|
||||
SessionPreferences::CreateForBrowserContext(browser_context);
|
||||
|
||||
protocol_.Reset(isolate, Protocol::Create(isolate, browser_context).ToV8());
|
||||
|
||||
|
|
|
@ -13,10 +13,15 @@ namespace electron {
|
|||
// static
|
||||
int SessionPreferences::kLocatorKey = 0;
|
||||
|
||||
SessionPreferences::SessionPreferences(content::BrowserContext* context) {
|
||||
context->SetUserData(&kLocatorKey, base::WrapUnique(this));
|
||||
// static
|
||||
void SessionPreferences::CreateForBrowserContext(
|
||||
content::BrowserContext* context) {
|
||||
DCHECK(context);
|
||||
context->SetUserData(&kLocatorKey,
|
||||
base::WrapUnique(new SessionPreferences{}));
|
||||
}
|
||||
|
||||
SessionPreferences::SessionPreferences() = default;
|
||||
SessionPreferences::~SessionPreferences() = default;
|
||||
|
||||
// static
|
||||
|
|
|
@ -23,7 +23,8 @@ class SessionPreferences : public base::SupportsUserData::Data {
|
|||
static std::vector<base::FilePath> GetValidPreloads(
|
||||
content::BrowserContext* context);
|
||||
|
||||
explicit SessionPreferences(content::BrowserContext* context);
|
||||
static void CreateForBrowserContext(content::BrowserContext* context);
|
||||
|
||||
~SessionPreferences() override;
|
||||
|
||||
void set_preloads(const std::vector<base::FilePath>& preloads) {
|
||||
|
@ -32,6 +33,8 @@ class SessionPreferences : public base::SupportsUserData::Data {
|
|||
const std::vector<base::FilePath>& preloads() const { return preloads_; }
|
||||
|
||||
private:
|
||||
SessionPreferences();
|
||||
|
||||
// The user data key.
|
||||
static int kLocatorKey;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче