Store BrowserContext in ref-counted ptr

This commit is contained in:
Cheng Zhao 2015-09-05 20:03:18 +08:00
parent 58fb166b0b
commit dc1e50c62e
3 changed files with 8 additions and 4 deletions

View file

@ -8,6 +8,7 @@
#include "browser/permission_manager.h" #include "browser/permission_manager.h"
#include "browser/url_request_context_getter.h" #include "browser/url_request_context_getter.h"
#include "base/memory/ref_counted.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
class PrefRegistrySimple; class PrefRegistrySimple;
@ -17,7 +18,8 @@ namespace brightray {
class PermissionManager; class PermissionManager;
class BrowserContext : public content::BrowserContext, class BrowserContext : public base::RefCounted<BrowserContext>,
public content::BrowserContext,
public brightray::URLRequestContextGetter::Delegate { public brightray::URLRequestContextGetter::Delegate {
public: public:
BrowserContext(); BrowserContext();
@ -66,6 +68,7 @@ class BrowserContext : public content::BrowserContext,
base::FilePath GetPath() const override; base::FilePath GetPath() const override;
private: private:
friend class base::RefCounted<BrowserContext>;
class ResourceContext; class ResourceContext;
void RegisterInternalPrefs(PrefRegistrySimple* pref_registry); void RegisterInternalPrefs(PrefRegistrySimple* pref_registry);

View file

@ -120,7 +120,7 @@ void BrowserMainParts::PreMainMessageLoopStart() {
} }
void BrowserMainParts::PreMainMessageLoopRun() { void BrowserMainParts::PreMainMessageLoopRun() {
browser_context_.reset(CreateBrowserContext()); browser_context_ = CreateBrowserContext();
browser_context_->Initialize(std::string()); browser_context_->Initialize(std::string());
content::WebUIControllerFactory::RegisterFactory( content::WebUIControllerFactory::RegisterFactory(
@ -133,7 +133,7 @@ void BrowserMainParts::PreMainMessageLoopRun() {
} }
void BrowserMainParts::PostMainMessageLoopRun() { void BrowserMainParts::PostMainMessageLoopRun() {
browser_context_.reset(); browser_context_ = nullptr;
} }
int BrowserMainParts::PreCreateThreads() { int BrowserMainParts::PreCreateThreads() {

View file

@ -6,6 +6,7 @@
#define BRIGHTRAY_BROWSER_BROWSER_MAIN_PARTS_H_ #define BRIGHTRAY_BROWSER_BROWSER_MAIN_PARTS_H_
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "content/public/browser/browser_main_parts.h" #include "content/public/browser/browser_main_parts.h"
@ -55,7 +56,7 @@ class BrowserMainParts : public content::BrowserMainParts {
void InitializeMainNib(); void InitializeMainNib();
#endif #endif
scoped_ptr<BrowserContext> browser_context_; scoped_refptr<BrowserContext> browser_context_;
scoped_ptr<devtools_http_handler::DevToolsHttpHandler> devtools_http_handler_; scoped_ptr<devtools_http_handler::DevToolsHttpHandler> devtools_http_handler_;
#if defined(TOOLKIT_VIEWS) #if defined(TOOLKIT_VIEWS)