Simplify ownership of CefBrowserContext objects (issue #2083)

This commit is contained in:
Marshall Greenblatt
2017-02-14 17:27:19 -05:00
parent 43001c0a94
commit 897c0f01ed
21 changed files with 351 additions and 307 deletions

View File

@@ -8,32 +8,35 @@
#include "include/cef_request_context.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/thread_util.h"
class CefBrowserContextImpl;
class CefBrowserContextProxy;
// Implementation of the CefRequestContext interface. All methods are thread-
// safe unless otherwise indicated.
// safe unless otherwise indicated. Will be deleted on the UI thread.
class CefRequestContextImpl : public CefRequestContext {
public:
~CefRequestContextImpl() override;
// Returns a CefRequestContextImpl for the specified |request_context|.
// Will return the global context if |request_context| is NULL.
static CefRefPtr<CefRequestContextImpl> GetForRequestContext(
static CefRefPtr<CefRequestContextImpl> GetOrCreateForRequestContext(
CefRefPtr<CefRequestContext> request_context);
// Returns a CefRequestContextImpl for the specified |browser_context|.
// |browser_context| must be non-NULL.
static CefRefPtr<CefRequestContextImpl> GetForBrowserContext(
scoped_refptr<CefBrowserContext> browser_context);
static CefRefPtr<CefRequestContextImpl> CreateForBrowserContext(
CefBrowserContext* browser_context);
// Returns the browser context object. Can only be called on the UI thread.
scoped_refptr<CefBrowserContext> GetBrowserContext();
CefBrowserContext* GetBrowserContext();
// Executes |callback| either synchronously or asynchronously with the browser
// context object when it's available. If |task_runner| is NULL the callback
// will be executed on the originating thread. The resulting context object
// can only be accessed on the UI thread.
typedef base::Callback<void(scoped_refptr<CefBrowserContext>)>
BrowserContextCallback;
typedef base::Callback<void(CefBrowserContext*)> BrowserContextCallback;
void GetBrowserContext(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const BrowserContextCallback& callback);
@@ -79,17 +82,36 @@ class CefRequestContextImpl : public CefRequestContext {
const CefString& origin,
std::vector<CefString>& resolved_ips) override;
const CefRequestContextSettings& settings() const { return settings_; }
const CefRequestContextSettings& settings() const { return config_.settings; }
private:
friend class CefRequestContext;
explicit CefRequestContextImpl(
scoped_refptr<CefBrowserContext> browser_context);
CefRequestContextImpl(const CefRequestContextSettings& settings,
CefRefPtr<CefRequestContextHandler> handler);
CefRequestContextImpl(CefRefPtr<CefRequestContextImpl> other,
CefRefPtr<CefRequestContextHandler> handler);
struct Config {
// True if wrapping the global context.
bool is_global = false;
// |settings| or |other| will be set when creating a new CefRequestContext
// via the API. When wrapping an existing CefBrowserContext* both will be
// empty and Initialize(CefBrowserContext*) will be called immediately after
// CefRequestContextImpl construction.
CefRequestContextSettings settings;
CefRefPtr<CefRequestContextImpl> other;
// Optionally use this handler, in which case a CefBrowserContextProxy will
// be created.
CefRefPtr<CefRequestContextHandler> handler;
// Used to uniquely identify CefRequestContext objects before an associated
// CefBrowserContext has been created. Should be set when a new
// CefRequestContext via the API.
int unique_id = -1;
};
explicit CefRequestContextImpl(const Config& config);
void Initialize();
void Initialize(CefBrowserContext* other_browser_context);
// Make sure the browser context exists. Only called on the UI thread.
void EnsureBrowserContext();
@@ -100,7 +122,7 @@ class CefRequestContextImpl : public CefRequestContext {
void GetRequestContextImplOnIOThread(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const RequestContextCallback& callback,
scoped_refptr<CefBrowserContext> browser_context);
CefBrowserContext* browser_context);
void RegisterSchemeHandlerFactoryInternal(
const CefString& scheme_name,
@@ -111,10 +133,10 @@ class CefRequestContextImpl : public CefRequestContext {
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
void PurgePluginListCacheInternal(
bool reload_pages,
scoped_refptr<CefBrowserContext> browser_context);
CefBrowserContext* browser_context);
void ClearCertificateExceptionsInternal(
CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefBrowserContext> browser_context);
CefBrowserContext* browser_context);
void CloseAllConnectionsInternal(
CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
@@ -123,19 +145,19 @@ class CefRequestContextImpl : public CefRequestContext {
CefRefPtr<CefResolveCallback> callback,
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
scoped_refptr<CefBrowserContext> browser_context_;
CefRequestContextSettings settings_;
CefRefPtr<CefRequestContextImpl> other_;
CefRefPtr<CefRequestContextHandler> handler_;
CefBrowserContext* browser_context() const;
// Used to uniquely identify CefRequestContext objects before an associated
// CefBrowserContext has been created.
int unique_id_;
// If *Impl then we must disassociate from it on destruction.
CefBrowserContextImpl* browser_context_impl_ = nullptr;
// If *Proxy then we own it.
std::unique_ptr<CefBrowserContextProxy> browser_context_proxy_;
Config config_;
// Owned by the CefBrowserContext.
CefURLRequestContextGetterImpl* request_context_impl_;
CefURLRequestContextGetterImpl* request_context_impl_ = nullptr;
IMPLEMENT_REFCOUNTING(CefRequestContextImpl);
IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(CefRequestContextImpl);
DISALLOW_COPY_AND_ASSIGN(CefRequestContextImpl);
};