1 // Copyright 2020 The Chromium Embedded Framework Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CEF_LIBCEF_BROWSER_CHROME_CHROME_BROWSER_CONTEXT_H_ 6 #define CEF_LIBCEF_BROWSER_CHROME_CHROME_BROWSER_CONTEXT_H_ 7 #pragma once 8 9 #include "libcef/browser/browser_context.h" 10 11 #include "base/memory/weak_ptr.h" 12 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_observer.h" 14 15 class ScopedProfileKeepAlive; 16 17 // See CefBrowserContext documentation for usage. Only accessed on the UI thread 18 // unless otherwise indicated. 19 class ChromeBrowserContext : public CefBrowserContext, public ProfileObserver { 20 public: 21 explicit ChromeBrowserContext(const CefRequestContextSettings& settings); 22 23 ChromeBrowserContext(const ChromeBrowserContext&) = delete; 24 ChromeBrowserContext& operator=(const ChromeBrowserContext&) = delete; 25 26 void InitializeAsync(base::OnceClosure initialized_cb); 27 28 // CefBrowserContext overrides. 29 content::BrowserContext* AsBrowserContext() override; 30 Profile* AsProfile() override; 31 bool IsInitialized() const override; 32 void StoreOrTriggerInitCallback(base::OnceClosure callback) override; 33 void Shutdown() override; 34 35 // ProfileObserver overrides. 36 void OnProfileWillBeDestroyed(Profile* profile) override; 37 38 private: 39 ~ChromeBrowserContext() override; 40 41 void ProfileCreated(Profile* profile, Profile::CreateStatus status); 42 43 base::OnceClosure initialized_cb_; 44 Profile* profile_ = nullptr; 45 bool should_destroy_ = false; 46 47 bool destroyed_ = false; 48 std::unique_ptr<ScopedProfileKeepAlive> profile_keep_alive_; 49 50 std::vector<base::OnceClosure> init_callbacks_; 51 52 base::WeakPtrFactory<ChromeBrowserContext> weak_ptr_factory_; 53 }; 54 55 #endif // CEF_LIBCEF_BROWSER_CHROME_CHROME_BROWSER_CONTEXT_H_ 56