From dc1e50c62e0e13935684ec22e9a6cfa1712c2c0a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 5 Sep 2015 20:03:18 +0800 Subject: [PATCH] Store BrowserContext in ref-counted ptr --- brightray/browser/browser_context.h | 5 ++++- brightray/browser/browser_main_parts.cc | 4 ++-- brightray/browser/browser_main_parts.h | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 68328c0fae80..68ed6aafd25b 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -8,6 +8,7 @@ #include "browser/permission_manager.h" #include "browser/url_request_context_getter.h" +#include "base/memory/ref_counted.h" #include "content/public/browser/browser_context.h" class PrefRegistrySimple; @@ -17,7 +18,8 @@ namespace brightray { class PermissionManager; -class BrowserContext : public content::BrowserContext, +class BrowserContext : public base::RefCounted, + public content::BrowserContext, public brightray::URLRequestContextGetter::Delegate { public: BrowserContext(); @@ -66,6 +68,7 @@ class BrowserContext : public content::BrowserContext, base::FilePath GetPath() const override; private: + friend class base::RefCounted; class ResourceContext; void RegisterInternalPrefs(PrefRegistrySimple* pref_registry); diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index fd283f72ed05..1e35eca97ddf 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -120,7 +120,7 @@ void BrowserMainParts::PreMainMessageLoopStart() { } void BrowserMainParts::PreMainMessageLoopRun() { - browser_context_.reset(CreateBrowserContext()); + browser_context_ = CreateBrowserContext(); browser_context_->Initialize(std::string()); content::WebUIControllerFactory::RegisterFactory( @@ -133,7 +133,7 @@ void BrowserMainParts::PreMainMessageLoopRun() { } void BrowserMainParts::PostMainMessageLoopRun() { - browser_context_.reset(); + browser_context_ = nullptr; } int BrowserMainParts::PreCreateThreads() { diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 8822cb7c09d0..0e151d8dd485 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -6,6 +6,7 @@ #define BRIGHTRAY_BROWSER_BROWSER_MAIN_PARTS_H_ #include "base/compiler_specific.h" +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "content/public/browser/browser_main_parts.h" @@ -55,7 +56,7 @@ class BrowserMainParts : public content::BrowserMainParts { void InitializeMainNib(); #endif - scoped_ptr browser_context_; + scoped_refptr browser_context_; scoped_ptr devtools_http_handler_; #if defined(TOOLKIT_VIEWS)