Commit 7a2ce640 authored by Marshall Greenblatt's avatar Marshall Greenblatt

Fix issues related to request and context object lifespan (issue #1037, issue #1044).

- Simplify and document the relationship between the various context object types. See browser_context.h for a description of the new relationships.
- cefclient: Add `request-context-per-browser` command-line flag for testing multiple CefRequestContext instances.
- cefclient: Add a CefURLRequest example.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@2032 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
parent 559ca19b
......@@ -904,6 +904,7 @@
],
'sources': [
'<@(includes_common)',
'libcef/browser/browser_context.cc',
'libcef/browser/browser_context.h',
'libcef/browser/browser_context_impl.cc',
'libcef/browser/browser_context_impl.h',
......@@ -937,6 +938,8 @@
'libcef/browser/context_menu_params_impl.h',
'libcef/browser/cookie_manager_impl.cc',
'libcef/browser/cookie_manager_impl.h',
'libcef/browser/cookie_store_proxy.cc',
'libcef/browser/cookie_store_proxy.h',
'libcef/browser/devtools_delegate.cc',
'libcef/browser/devtools_delegate.h',
'libcef/browser/devtools_frontend.cc',
......@@ -980,6 +983,8 @@
'libcef/browser/proxy_stubs.cc',
'libcef/browser/render_widget_host_view_osr.cc',
'libcef/browser/render_widget_host_view_osr.h',
'libcef/browser/resource_context.cc',
'libcef/browser/resource_context.h',
'libcef/browser/resource_dispatcher_host_delegate.cc',
'libcef/browser/resource_dispatcher_host_delegate.h',
'libcef/browser/resource_request_job.cc',
......@@ -1006,10 +1011,14 @@
'libcef/browser/thread_util.h',
'libcef/browser/url_network_delegate.cc',
'libcef/browser/url_network_delegate.h',
'libcef/browser/url_request_context_getter.cc',
'libcef/browser/url_request_context.cc',
'libcef/browser/url_request_context.h',
'libcef/browser/url_request_context_getter.h',
'libcef/browser/url_request_context_getter_impl.cc',
'libcef/browser/url_request_context_getter_impl.h',
'libcef/browser/url_request_context_getter_proxy.cc',
'libcef/browser/url_request_context_getter_proxy.h',
'libcef/browser/url_request_context_impl.h',
'libcef/browser/url_request_context_proxy.cc',
'libcef/browser/url_request_context_proxy.h',
'libcef/browser/url_request_interceptor.cc',
......
......@@ -174,6 +174,8 @@
'tests/cefclient/browser/temp_window.h',
'tests/cefclient/browser/test_runner.cc',
'tests/cefclient/browser/test_runner.h',
'tests/cefclient/browser/urlrequest_test.cc',
'tests/cefclient/browser/urlrequest_test.h',
'tests/cefclient/browser/window_test.cc',
'tests/cefclient/browser/window_test.h',
],
......@@ -209,6 +211,7 @@
'tests/cefclient/resources/performance.html',
'tests/cefclient/resources/performance2.html',
'tests/cefclient/resources/transparency.html',
'tests/cefclient/resources/urlrequest.html',
'tests/cefclient/resources/window.html',
'tests/cefclient/resources/xmlhttprequest.html',
],
......
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "libcef/browser/browser_context.h"
#include "libcef/browser/content_browser_client.h"
#include "base/logging.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_thread.h"
#ifndef NDEBUG
base::AtomicRefCount CefBrowserContext::DebugObjCt = 0;
#endif
CefBrowserContext::CefBrowserContext()
: resource_context_(new CefResourceContext) {
BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices(
this);
// Spell checking support and possibly other subsystems retrieve the
// PrefService associated with a BrowserContext via UserPrefs::Get().
PrefService* pref_service = CefContentBrowserClient::Get()->pref_service();
DCHECK(pref_service);
user_prefs::UserPrefs::Set(this, pref_service);
#ifndef NDEBUG
base::AtomicRefCountInc(&DebugObjCt);
#endif
}
CefBrowserContext::~CefBrowserContext() {
if (resource_context_.get()) {
// Destruction of the ResourceContext will trigger destruction of all
// associated URLRequests.
content::BrowserThread::DeleteSoon(
content::BrowserThread::IO, FROM_HERE, resource_context_.release());
}
// Remove any BrowserContextKeyedServiceFactory associations.
BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices(
this);
#ifndef NDEBUG
base::AtomicRefCountDec(&DebugObjCt);
#endif
}
content::ResourceContext* CefBrowserContext::GetResourceContext() {
return resource_context_.get();
}
......@@ -6,11 +6,115 @@
#define CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_H_
#pragma once
#include "libcef/browser/resource_context.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
class CefBrowserContext : public content::BrowserContext {
/*
// Classes used in request processing (network, storage, service, etc.):
//
// WC = WebContents
// Content API representation of a browser. Created by BHI or the system (for
// popups) and owned by BHI. Keeps a pointer to BCI/BCP.
//
// BHI = CefBrowserHostImpl
// Implements the CefBrowser and CefBrowserHost interfaces which are exposed
// to clients. References an RCI instance. Owns a WC. Life span is controlled
// by client references and CefContentBrowserClient.
//
// RCI = CefRequestContextImpl
// Implements the CefRequestContext interface which is exposed to clients.
// References the global BCI or creates a new BCP.
//
// BCI = CefBrowserContextImpl
// Entry point from WC when using the global RCI. Owns the RC and creates the
// URCGI. Life span controlled by RCI and CefBrowserMainParts.
//
// BCP = CefBrowserContextProxy
// Entry point from WC when using a custom RCI. Owns the RC and creates the
// URCGP. Life span controlled by RCI.
//
// RC = CefResourceContext
// Acts as a bridge for resource loading. URLRequest life span is tied to this
// object. Must be destroyed before the associated URCGI/URCGP. Life span is
// controlled by BCI/BCP.
//
// URCGI = CefURLRequestContextGetterImpl
// Creates and owns the URCI. Life span is controlled by RC and
// CefBrowserMainParts.
//
// URCGP = CefURLRequestContextGetterProxy
// Creates and owns the URCP. Life span is controlled by RC.
//
// URCI = CefURLRequestContextImpl
// Owns various network-related objects including the global cookie manager.
// Owns URLRequest objects which must be destroyed first. Life span is
// controlled by URCGI.
//
// URCP = CefURLRequestContextProxy
// Creates the CSP and forwards requests to the objects owned by URCI. Owns
// URLRequest objects which must be destroyed first. Life span is controlled
// by URCGP.
//
// CSP = CefCookieStoreProxy
// Gives the CefCookieManager instance retrieved via CefRequestContextHandler
// an opportunity to handle cookie requests. Otherwise forwards requests via
// URCI to the global cookie manager. Life span is controlled by URCP.
//
//
// Relationship diagram:
// ref = reference (CefRefPtr/scoped_refptr)
// own = ownership (scoped_ptr)
// ptr = raw pointer
//
// CefBrowserMainParts global cookie manager, etc...
// | | ^
// ref ref ref/own
// v v |
// /---> BCI -ref-> URCGI --own-> URCI <-ptr-- CSP
// / ^ ^ ^
// ptr ref ref /
// / | | /
// BHI -own-> WC -ptr-> BCP -ref-> URCGP -own-> URCP --ref-/
//
// BHI -ref-> RCI -ref-> BCI/BCP -own-> RC -ref-> URCGI/URCGP
//
//
// How shutdown works:
// 1. CefBrowserHostImpl is destroyed on any thread due to browser close,
// ref release, etc.
// 2. CefRequestContextImpl is destroyed on any thread due to
// CefBrowserHostImpl destruction, ref release, etc.
// 3. CefBrowserContext* is destroyed on the UI thread due to
// CefRequestContextImpl destruction (*Impl, *Proxy) or ref release in
// CefBrowserMainParts::PostMainMessageLoopRun() (*Impl).
// 4. CefResourceContext is destroyed asynchronously on the IO thread due to
// CefBrowserContext* destruction. This cancels/destroys any pending
// URLRequests.
// 5. CefURLRequestContextGetter* is destroyed asynchronously on the IO thread
// due to CefResourceContext destruction (*Impl, *Proxy) or ref release in
// CefBrowserMainParts::PostMainMessageLoopRun() (*Impl). This may be delayed
// if other network-related objects still have a reference to it.
// 6. CefURLRequestContext* is destroyed on the IO thread due to
// CefURLRequestContextGetter* destruction.
*/
// Main entry point for configuring behavior on a per-browser basis. An instance
// of this class is passed to WebContents::Create in CefBrowserHostImpl::
// CreateInternal. Only accessed on the UI thread.
class CefBrowserContext
: public content::BrowserContext,
public base::RefCountedThreadSafe<
CefBrowserContext, content::BrowserThread::DeleteOnUIThread> {
public:
CefBrowserContext();
// BrowserContext methods.
content::ResourceContext* GetResourceContext() override;
// Called from CefContentBrowserClient to create the URLRequestContextGetter.
virtual net::URLRequestContextGetter* CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) = 0;
......@@ -19,6 +123,28 @@ class CefBrowserContext : public content::BrowserContext {
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) = 0;
CefResourceContext* resource_context() const {
return resource_context_.get();
}
#ifndef NDEBUG
// Simple tracking of allocated objects.
static base::AtomicRefCount DebugObjCt; // NOLINT(runtime/int)
#endif
protected:
~CefBrowserContext() override;
private:
// Only allow deletion via scoped_refptr().
friend struct content::BrowserThread::DeleteOnThread<
content::BrowserThread::UI>;
friend class base::DeleteHelper<CefBrowserContext>;
scoped_ptr<CefResourceContext> resource_context_;
DISALLOW_COPY_AND_ASSIGN(CefBrowserContext);
};
#endif // CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_H_
......@@ -10,47 +10,15 @@
#include "libcef/browser/context.h"
#include "libcef/browser/download_manager_delegate.h"
#include "libcef/browser/thread_util.h"
#include "libcef/browser/url_request_context_getter.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/threading/thread.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_context.h"
#include "content/public/browser/storage_partition.h"
using content::BrowserThread;
class CefBrowserContextImpl::CefResourceContext : public content::ResourceContext {
public:
CefResourceContext() : getter_(NULL) {}
// ResourceContext implementation:
net::HostResolver* GetHostResolver() override {
CHECK(getter_);
return getter_->host_resolver();
}
net::URLRequestContext* GetRequestContext() override {
CHECK(getter_);
return getter_->GetURLRequestContext();
}
void set_url_request_context_getter(CefURLRequestContextGetter* getter) {
getter_ = getter;
}
private:
CefURLRequestContextGetter* getter_;
DISALLOW_COPY_AND_ASSIGN(CefResourceContext);
};
CefBrowserContextImpl::CefBrowserContextImpl()
: resource_context_(new CefResourceContext) {
BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices(
this);
CefBrowserContextImpl::CefBrowserContextImpl() {
}
CefBrowserContextImpl::~CefBrowserContextImpl() {
......@@ -58,15 +26,6 @@ CefBrowserContextImpl::~CefBrowserContextImpl() {
// when it's accessed from the content::BrowserContext destructor.
if (download_manager_delegate_.get())
download_manager_delegate_.reset(NULL);
if (resource_context_.get()) {
BrowserThread::DeleteSoon(
BrowserThread::IO, FROM_HERE, resource_context_.release());
}
// Remove any BrowserContextKeyedServiceFactory associations.
BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices(
this);
}
base::FilePath CefBrowserContextImpl::GetPath() const {
......@@ -120,10 +79,6 @@ net::URLRequestContextGetter*
return GetRequestContext();
}
content::ResourceContext* CefBrowserContextImpl::GetResourceContext() {
return resource_context_.get();
}
content::BrowserPluginGuestManager* CefBrowserContextImpl::GetGuestManager() {
return NULL;
}
......@@ -147,12 +102,12 @@ net::URLRequestContextGetter* CefBrowserContextImpl::CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
DCHECK(!url_request_getter_.get());
url_request_getter_ = new CefURLRequestContextGetter(
url_request_getter_ = new CefURLRequestContextGetterImpl(
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE),
protocol_handlers,
request_interceptors.Pass());
resource_context_->set_url_request_context_getter(url_request_getter_.get());
resource_context()->set_url_request_context_getter(url_request_getter_.get());
return url_request_getter_.get();
}
......
......@@ -8,6 +8,8 @@
#include "libcef/browser/browser_context.h"
#include "libcef/browser/url_request_context_getter_impl.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
......@@ -18,12 +20,13 @@ class SpeechRecognitionPreferences;
}
class CefDownloadManagerDelegate;
class CefURLRequestContextGetter;
// Global BrowserContext implementation. Life span is controlled by
// CefRequestContextImpl and CefBrowserMainParts. Only accessed on the UI
// thread. See browser_context.h for an object relationship diagram.
class CefBrowserContextImpl : public CefBrowserContext {
public:
CefBrowserContextImpl();
~CefBrowserContextImpl() override;
// BrowserContext methods.
base::FilePath GetPath() const override;
......@@ -41,7 +44,6 @@ class CefBrowserContextImpl : public CefBrowserContext {
GetMediaRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory) override;
content::ResourceContext* GetResourceContext() override;
content::BrowserPluginGuestManager* GetGuestManager() override;
storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
content::PushMessagingService* GetPushMessagingService() override;
......@@ -60,11 +62,15 @@ class CefBrowserContextImpl : public CefBrowserContext {
override;
private:
class CefResourceContext;
// Only allow deletion via scoped_refptr().
friend struct content::BrowserThread::DeleteOnThread<
content::BrowserThread::UI>;
friend class base::DeleteHelper<CefBrowserContextImpl>;
~CefBrowserContextImpl() override;
scoped_ptr<CefResourceContext> resource_context_;
scoped_ptr<CefDownloadManagerDelegate> download_manager_delegate_;
scoped_refptr<CefURLRequestContextGetter> url_request_getter_;
scoped_refptr<CefURLRequestContextGetterImpl> url_request_getter_;
DISALLOW_COPY_AND_ASSIGN(CefBrowserContextImpl);
};
......
......@@ -7,64 +7,19 @@
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/download_manager_delegate.h"
#include "libcef/browser/thread_util.h"
#include "libcef/browser/url_request_context_getter.h"
#include "libcef/browser/url_request_context_getter_proxy.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/threading/thread.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_context.h"
#include "content/public/browser/storage_partition.h"
using content::BrowserThread;
class CefBrowserContextProxy::CefResourceContext :
public content::ResourceContext {
public:
CefResourceContext() : getter_(NULL) {}
// ResourceContext implementation:
net::HostResolver* GetHostResolver() override {
CHECK(getter_);
return getter_->GetHostResolver();
}
net::URLRequestContext* GetRequestContext() override {
CHECK(getter_);
return getter_->GetURLRequestContext();
}
void set_url_request_context_getter(CefURLRequestContextGetterProxy* getter) {
getter_ = getter;
}
private:
CefURLRequestContextGetterProxy* getter_;
DISALLOW_COPY_AND_ASSIGN(CefResourceContext);
};
CefBrowserContextProxy::CefBrowserContextProxy(
CefRefPtr<CefRequestContextHandler> handler,
CefBrowserContext* parent)
: refct_(0),
handler_(handler),
parent_(parent),
resource_context_(new CefResourceContext) {
BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices(
this);
scoped_refptr<CefBrowserContextImpl> parent)
: handler_(handler),
parent_(parent) {
}
CefBrowserContextProxy::~CefBrowserContextProxy() {
if (resource_context_.get()) {
BrowserThread::DeleteSoon(
BrowserThread::IO, FROM_HERE, resource_context_.release());
}
// Remove any BrowserContextKeyedServiceFactory associations.
BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices(
this);
}
base::FilePath CefBrowserContextProxy::GetPath() const {
......@@ -119,10 +74,6 @@ net::URLRequestContextGetter*
return GetRequestContext();
}
content::ResourceContext* CefBrowserContextProxy::GetResourceContext() {
return resource_context_.get();
}
content::BrowserPluginGuestManager* CefBrowserContextProxy::GetGuestManager() {
return parent_->GetGuestManager();
}
......@@ -148,9 +99,8 @@ net::URLRequestContextGetter* CefBrowserContextProxy::CreateRequestContext(
DCHECK(!url_request_getter_.get());
url_request_getter_ =
new CefURLRequestContextGetterProxy(handler_,
static_cast<CefURLRequestContextGetter*>(
CefContentBrowserClient::Get()->request_context().get()));
resource_context_->set_url_request_context_getter(url_request_getter_.get());
CefContentBrowserClient::Get()->request_context().get());
resource_context()->set_url_request_context_getter(url_request_getter_.get());
return url_request_getter_.get();
}
......
......@@ -8,6 +8,7 @@
#include "include/cef_request_context_handler.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_context_impl.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
......@@ -21,17 +22,13 @@ class SpeechRecognitionPreferences;
class CefDownloadManagerDelegate;
class CefURLRequestContextGetterProxy;
// This class is only accessed on the UI thread.
// BrowserContext implementation for a particular CefRequestContext. Life span
// is controlled by CefRequestContextImpl. Only accessed on the UI thread. See
// browser_context.h for an object relationship diagram.
class CefBrowserContextProxy : public CefBrowserContext {
public:
CefBrowserContextProxy(CefRefPtr<CefRequestContextHandler> handler,
CefBrowserContext* parent);
~CefBrowserContextProxy() override;
// Reference counting and object life span is managed by
// CefContentBrowserClient.
void AddRef() { refct_++; }
bool Release() { return (--refct_ == 0); }
scoped_refptr<CefBrowserContextImpl> parent);
// BrowserContext methods.
base::FilePath GetPath() const override;
......@@ -49,7 +46,6 @@ class CefBrowserContextProxy : public CefBrowserContext {
GetMediaRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory) override;
content::ResourceContext* GetResourceContext() override;
content::BrowserPluginGuestManager* GetGuestManager() override;
storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
content::PushMessagingService* GetPushMessagingService() override;
......@@ -70,12 +66,15 @@ class CefBrowserContextProxy : public CefBrowserContext {
CefRefPtr<CefRequestContextHandler> handler() const { return handler_; }
private:
class CefResourceContext;
// Only allow deletion via scoped_refptr().
friend struct content::BrowserThread::DeleteOnThread<
content::BrowserThread::UI>;
friend class base::DeleteHelper<CefBrowserContextProxy>;
~CefBrowserContextProxy() override;
int refct_;
CefRefPtr<CefRequestContextHandler> handler_;
CefBrowserContext* parent_;
scoped_ptr<CefResourceContext> resource_context_;
scoped_refptr<CefBrowserContextImpl> parent_;
scoped_ptr<CefDownloadManagerDelegate> download_manager_delegate_;
scoped_refptr<CefURLRequestContextGetterProxy> url_request_getter_;
......
......@@ -8,7 +8,7 @@
#include <string>
#include <utility>
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_context_impl.h"
#include "libcef/browser/browser_info.h"
#include "libcef/browser/browser_pref_store.h"
#include "libcef/browser/chrome_scheme_handler.h"
......@@ -397,7 +397,7 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::CreateInternal(
DCHECK(opener == kNullWindowHandle || browser_info->is_popup());
if (!web_contents) {
CefBrowserContext* browser_context = NULL;
scoped_refptr<CefBrowserContext> browser_context = NULL;
if (request_context.get()) {
CefRequestContextImpl* request_context_impl =
static_cast<CefRequestContextImpl*>(request_context.get());
......@@ -408,7 +408,7 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::CreateInternal(
DCHECK(browser_context);
content::WebContents::CreateParams create_params(
browser_context);
browser_context.get());
CefWebContentsViewOSR* view_or = NULL;
if (window_info.windowless_rendering_enabled) {
......@@ -756,13 +756,13 @@ void CefBrowserHostImpl::StartDownload(const CefString& url) {
if (!web_contents())
return;
CefBrowserContext* context =
scoped_refptr<CefBrowserContext> context =
static_cast<CefBrowserContext*>(web_contents()->GetBrowserContext());
if (!context)
if (!context.get())
return;
content::DownloadManager* manager =
content::BrowserContext::GetDownloadManager(context);
content::BrowserContext::GetDownloadManager(context.get());
if (!manager)
return;
......@@ -2759,7 +2759,7 @@ CefBrowserHostImpl::CefBrowserHostImpl(
web_contents_.reset(web_contents);
web_contents->SetDelegate(this);
CefBrowserContext* browser_context =
scoped_refptr<CefBrowserContext> browser_context =
static_cast<CefBrowserContext*>(web_contents->GetBrowserContext());
request_context_ = new CefRequestContextImpl(browser_context);
......
......@@ -7,9 +7,11 @@
#include <string>
#include "libcef/browser/browser_context_impl.h"
#include "libcef/browser/browser_context_proxy.h"
#include "libcef/browser/browser_message_loop.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/devtools_delegate.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/net_resource_provider.h"
#include "base/bind.h"
......@@ -17,7 +19,6 @@
#include "base/message_loop/message_loop.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/net/proxy_service_factory.h"
#include "components/user_prefs/user_prefs.h"
#include "content/browser/webui/content_web_ui_controller_factory.h"
#include "content/public/browser/gpu_data_manager.h"
#include "content/public/browser/web_ui_controller_factory.h"
......@@ -126,8 +127,8 @@ int CefBrowserMainParts::PreCreateThreads() {
}
void CefBrowserMainParts::PreMainMessageLoopRun() {
// Create the global browser context.
global_browser_context_.reset(new CefBrowserContextImpl());
// Create the global BrowserContext.
global_browser_context_ = new CefBrowserContextImpl();
// Initialize the proxy configuration service. This needs to occur before
// CefURLRequestContextGetter::GetURLRequestContext() is called for the
......@@ -136,9 +137,12 @@ void CefBrowserMainParts::PreMainMessageLoopRun() {
ProxyServiceFactory::CreateProxyConfigService(
pref_proxy_config_tracker_.get()));
// Initialize the request context getter. This indirectly triggers a call
// to CefURLRequestContextGetter::GetURLRequestContext() on the IO thread.
global_request_context_ = global_browser_context_->GetRequestContext();
// Create the global URLRequestContextGetter via an indirect call to
// CefBrowserContextImpl::CreateRequestContext. Triggers a call to
// CefURLRequestContextGetter::GetURLRequestContext() on the IO thread which
// creates the URLRequestContext.
global_request_context_ = static_cast<CefURLRequestContextGetterImpl*>(
global_browser_context_->GetRequestContext());
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
......@@ -153,10 +157,6 @@ void CefBrowserMainParts::PreMainMessageLoopRun() {
LOG(WARNING) << "Invalid http debugger port number " << port;
}
}
// Spell checking support and possibly other subsystems retrieve the
// PrefService associated with a BrowserContext via UserPrefs::Get().
user_prefs::UserPrefs::Set(browser_context(), pref_service());
}
void CefBrowserMainParts::PostMainMessageLoopRun() {
......@@ -166,12 +166,13 @@ void CefBrowserMainParts::PostMainMessageLoopRun() {
}
pref_proxy_config_tracker_->DetachFromPrefService();
// Only the global browser context should still exist.
DCHECK(browser_contexts_.empty());
browser_contexts_.clear();
global_request_context_ = NULL;
global_browser_context_.reset();
global_browser_context_ = NULL;
#ifndef NDEBUG
// No CefBrowserContext instances should exist at this point.
DCHECK_EQ(0, CefBrowserContext::DebugObjCt);
#endif
}
void CefBrowserMainParts::PostDestroyThreads() {
......@@ -182,25 +183,10 @@ void CefBrowserMainParts::PostDestroyThreads() {
delete views::ViewsDelegate::views_delegate;
#endif
PlatformCleanup();