diff options
Diffstat (limited to 'chrome/browser/profiles')
-rw-r--r-- | chrome/browser/profiles/off_the_record_profile_io_data.cc | 13 | ||||
-rw-r--r-- | chrome/browser/profiles/off_the_record_profile_io_data.h | 6 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl_io_data.cc | 20 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl_io_data.h | 8 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_io_data.cc | 38 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_io_data.h | 61 |
6 files changed, 45 insertions, 101 deletions
diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.cc b/chrome/browser/profiles/off_the_record_profile_io_data.cc index 2d9b368..11f8ae3 100644 --- a/chrome/browser/profiles/off_the_record_profile_io_data.cc +++ b/chrome/browser/profiles/off_the_record_profile_io_data.cc @@ -46,8 +46,7 @@ OffTheRecordProfileIOData::Handle::~Handle() { iter->second->CleanupOnUIThread(); } - io_data_->AddRef(); - io_data_.release()->ShutdownOnUIThread(); + io_data_->ShutdownOnUIThread(); } base::Callback<ChromeURLDataManagerBackend*(void)> @@ -56,7 +55,7 @@ GetChromeURLDataManagerBackendGetter() const { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); LazyInitialize(); return base::Bind(&ProfileIOData::GetChromeURLDataManagerBackend, - base::Unretained(io_data_.get())); + base::Unretained(io_data_)); } const content::ResourceContext& @@ -200,11 +199,11 @@ void OffTheRecordProfileIOData::LazyInitializeInternal( extensions_context->set_job_factory(job_factory()); } -scoped_refptr<ProfileIOData::RequestContext> +scoped_refptr<ChromeURLRequestContext> OffTheRecordProfileIOData::InitializeAppRequestContext( scoped_refptr<ChromeURLRequestContext> main_context, const std::string& app_id) const { - AppRequestContext* context = new AppRequestContext(app_id); + AppRequestContext* context = new AppRequestContext; // Copy most state from the main context. context->CopyFrom(main_context); @@ -232,12 +231,12 @@ OffTheRecordProfileIOData::AcquireMediaRequestContext() const { return NULL; } -scoped_refptr<ProfileIOData::RequestContext> +scoped_refptr<ChromeURLRequestContext> OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext( scoped_refptr<ChromeURLRequestContext> main_context, const std::string& app_id) const { // We create per-app contexts on demand, unlike the others above. - scoped_refptr<RequestContext> app_request_context = + scoped_refptr<ChromeURLRequestContext> app_request_context = InitializeAppRequestContext(main_context, app_id); DCHECK(app_request_context); return app_request_context; diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.h b/chrome/browser/profiles/off_the_record_profile_io_data.h index 5e01c15..cbeb632 100644 --- a/chrome/browser/profiles/off_the_record_profile_io_data.h +++ b/chrome/browser/profiles/off_the_record_profile_io_data.h @@ -72,7 +72,7 @@ class OffTheRecordProfileIOData : public ProfileIOData { extensions_request_context_getter_; mutable ChromeURLRequestContextGetterMap app_request_context_getter_map_; - scoped_refptr<OffTheRecordProfileIOData> io_data_; + OffTheRecordProfileIOData* const io_data_; Profile* const profile_; @@ -91,12 +91,12 @@ class OffTheRecordProfileIOData : public ProfileIOData { virtual ~OffTheRecordProfileIOData(); virtual void LazyInitializeInternal(ProfileParams* profile_params) const; - virtual scoped_refptr<RequestContext> InitializeAppRequestContext( + virtual scoped_refptr<ChromeURLRequestContext> InitializeAppRequestContext( scoped_refptr<ChromeURLRequestContext> main_context, const std::string& app_id) const; virtual scoped_refptr<ChromeURLRequestContext> AcquireMediaRequestContext() const; - virtual scoped_refptr<RequestContext> + virtual scoped_refptr<ChromeURLRequestContext> AcquireIsolatedAppRequestContext( scoped_refptr<ChromeURLRequestContext> main_context, const std::string& app_id) const; diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc index f917b1a..fa95deb 100644 --- a/chrome/browser/profiles/profile_impl_io_data.cc +++ b/chrome/browser/profiles/profile_impl_io_data.cc @@ -49,7 +49,7 @@ ProfileImplIOData::Handle::~Handle() { iter->second->CleanupOnUIThread(); } - io_data_.release()->ShutdownOnUIThread(); + io_data_->ShutdownOnUIThread(); } void ProfileImplIOData::Handle::Init(const FilePath& cookie_path, @@ -81,7 +81,7 @@ ProfileImplIOData::Handle::GetChromeURLDataManagerBackendGetter() const { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); LazyInitialize(); return base::Bind(&ProfileIOData::GetChromeURLDataManagerBackend, - base::Unretained(io_data_.get())); + base::Unretained(io_data_)); } const content::ResourceContext& @@ -185,7 +185,7 @@ void ProfileImplIOData::LazyInitializeInternal( ChromeURLRequestContext* main_context = main_request_context(); ChromeURLRequestContext* extensions_context = extensions_request_context(); - media_request_context_ = new RequestContext; + media_request_context_ = new ChromeURLRequestContext; IOThread* const io_thread = profile_params->io_thread; IOThread::Globals* const io_thread_globals = io_thread->globals(); @@ -310,11 +310,11 @@ void ProfileImplIOData::LazyInitializeInternal( lazy_params_.reset(); } -scoped_refptr<ProfileIOData::RequestContext> +scoped_refptr<ChromeURLRequestContext> ProfileImplIOData::InitializeAppRequestContext( scoped_refptr<ChromeURLRequestContext> main_context, const std::string& app_id) const { - ProfileIOData::AppRequestContext* context = new AppRequestContext(app_id); + AppRequestContext* context = new AppRequestContext; // Copy most state from the main context. context->CopyFrom(main_context); @@ -375,19 +375,15 @@ ProfileImplIOData::InitializeAppRequestContext( scoped_refptr<ChromeURLRequestContext> ProfileImplIOData::AcquireMediaRequestContext() const { DCHECK(media_request_context_); - scoped_refptr<ChromeURLRequestContext> context = media_request_context_; - media_request_context_->set_profile_io_data( - const_cast<ProfileImplIOData*>(this)); - media_request_context_ = NULL; - return context; + return media_request_context_; } -scoped_refptr<ProfileIOData::RequestContext> +scoped_refptr<ChromeURLRequestContext> ProfileImplIOData::AcquireIsolatedAppRequestContext( scoped_refptr<ChromeURLRequestContext> main_context, const std::string& app_id) const { // We create per-app contexts on demand, unlike the others above. - scoped_refptr<RequestContext> app_request_context = + scoped_refptr<ChromeURLRequestContext> app_request_context = InitializeAppRequestContext(main_context, app_id); DCHECK(app_request_context); return app_request_context; diff --git a/chrome/browser/profiles/profile_impl_io_data.h b/chrome/browser/profiles/profile_impl_io_data.h index 0e122c1..dea0c79 100644 --- a/chrome/browser/profiles/profile_impl_io_data.h +++ b/chrome/browser/profiles/profile_impl_io_data.h @@ -75,7 +75,7 @@ class ProfileImplIOData : public ProfileIOData { mutable scoped_refptr<ChromeURLRequestContextGetter> extensions_request_context_getter_; mutable ChromeURLRequestContextGetterMap app_request_context_getter_map_; - scoped_refptr<ProfileImplIOData> io_data_; + ProfileImplIOData* const io_data_; Profile* const profile_; @@ -107,12 +107,12 @@ class ProfileImplIOData : public ProfileIOData { virtual ~ProfileImplIOData(); virtual void LazyInitializeInternal(ProfileParams* profile_params) const; - virtual scoped_refptr<RequestContext> InitializeAppRequestContext( + virtual scoped_refptr<ChromeURLRequestContext> InitializeAppRequestContext( scoped_refptr<ChromeURLRequestContext> main_context, const std::string& app_id) const; virtual scoped_refptr<ChromeURLRequestContext> AcquireMediaRequestContext() const; - virtual scoped_refptr<RequestContext> + virtual scoped_refptr<ChromeURLRequestContext> AcquireIsolatedAppRequestContext( scoped_refptr<ChromeURLRequestContext> main_context, const std::string& app_id) const; @@ -120,7 +120,7 @@ class ProfileImplIOData : public ProfileIOData { // Lazy initialization params. mutable scoped_ptr<LazyParams> lazy_params_; - mutable scoped_refptr<RequestContext> media_request_context_; + mutable scoped_refptr<ChromeURLRequestContext> media_request_context_; mutable scoped_ptr<net::HttpTransactionFactory> main_http_factory_; mutable scoped_ptr<net::HttpTransactionFactory> media_http_factory_; diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc index 969560b..31a9e1a 100644 --- a/chrome/browser/profiles/profile_io_data.cc +++ b/chrome/browser/profiles/profile_io_data.cc @@ -249,15 +249,8 @@ void ProfileIOData::InitializeProfileParams(Profile* profile) { profile_params_.reset(params.release()); } -ProfileIOData::RequestContext::RequestContext() {} -ProfileIOData::RequestContext::~RequestContext() {} - -ProfileIOData::AppRequestContext::AppRequestContext(const std::string& app_id) - : app_id_(app_id) {} -ProfileIOData::AppRequestContext::~AppRequestContext() { - DCHECK(ContainsKey(profile_io_data()->app_request_context_map_, app_id_)); - profile_io_data()->app_request_context_map_.erase(app_id_); -} +ProfileIOData::AppRequestContext::AppRequestContext() {} +ProfileIOData::AppRequestContext::~AppRequestContext() {} void ProfileIOData::AppRequestContext::SetCookieStore( net::CookieStore* cookie_store) { @@ -332,10 +325,7 @@ ProfileIOData::GetChromeURLDataManagerBackend() const { scoped_refptr<ChromeURLRequestContext> ProfileIOData::GetMainRequestContext() const { LazyInitialize(); - scoped_refptr<RequestContext> context = main_request_context_; - context->set_profile_io_data(const_cast<ProfileIOData*>(this)); - main_request_context_ = NULL; - return context; + return main_request_context_; } scoped_refptr<ChromeURLRequestContext> @@ -350,11 +340,7 @@ ProfileIOData::GetMediaRequestContext() const { scoped_refptr<ChromeURLRequestContext> ProfileIOData::GetExtensionsRequestContext() const { LazyInitialize(); - scoped_refptr<RequestContext> context = - extensions_request_context_; - context->set_profile_io_data(const_cast<ProfileIOData*>(this)); - extensions_request_context_ = NULL; - return context; + return extensions_request_context_; } scoped_refptr<ChromeURLRequestContext> @@ -366,11 +352,8 @@ ProfileIOData::GetIsolatedAppRequestContext( if (ContainsKey(app_request_context_map_, app_id)) { context = app_request_context_map_[app_id]; } else { - scoped_refptr<RequestContext> request_context = - AcquireIsolatedAppRequestContext(main_context, app_id); - request_context->set_profile_io_data(const_cast<ProfileIOData*>(this)); - app_request_context_map_[app_id] = request_context; - context = request_context; + context = AcquireIsolatedAppRequestContext(main_context, app_id); + app_request_context_map_[app_id] = context; } DCHECK(context); return context; @@ -410,9 +393,8 @@ void ProfileIOData::LazyInitialize() const { const CommandLine& command_line = *CommandLine::ForCurrentProcess(); // Create the common request contexts. - main_request_context_ = new RequestContext; - extensions_request_context_ = new RequestContext; - weak_extensions_request_context_ = extensions_request_context_->GetWeakPtr(); + main_request_context_ = new ChromeURLRequestContext; + extensions_request_context_ = new ChromeURLRequestContext; profile_params_->appcache_service->set_request_context(main_request_context_); @@ -533,7 +515,7 @@ void ProfileIOData::ShutdownOnUIThread() { base::Unretained(g_browser_process->resource_dispatcher_host()), &resource_context_)); bool posted = BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, - new ReleaseTask<ProfileIOData>(this)); + new DeleteTask<ProfileIOData>(this)); if (!posted) - Release(); + delete this; } diff --git a/chrome/browser/profiles/profile_io_data.h b/chrome/browser/profiles/profile_io_data.h index f2a3e92..eddce0d 100644 --- a/chrome/browser/profiles/profile_io_data.h +++ b/chrome/browser/profiles/profile_io_data.h @@ -59,19 +59,13 @@ class DatabaseTracker; // Conceptually speaking, the ProfileIOData represents data that lives on the IO // thread that is owned by a Profile, such as, but not limited to, network -// objects like CookieMonster, HttpTransactionFactory, etc. The Profile -// implementation will maintain a reference to the ProfileIOData. The -// ProfileIOData will originally own a reference to the ChromeURLRequestContexts -// that reference its members. When an accessor for a ChromeURLRequestContext is -// invoked, then ProfileIOData will release its reference to the -// ChromeURLRequestContext and the ChromeURLRequestContext will acquire a -// reference to the ProfileIOData, so they exchange ownership. This is done -// because it's possible for a context's accessor never to be invoked, so this -// ownership reversal prevents shutdown leaks. ProfileIOData will lazily -// initialize its members on the first invocation of a ChromeURLRequestContext -// accessor. -class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> { +// objects like CookieMonster, HttpTransactionFactory, etc. Profile owns +// ProfileIOData, but will make sure to delete it on the IO thread (except +// possibly in unit tests where there is no IO thread). +class ProfileIOData { public: + virtual ~ProfileIOData(); + // Returns true if |scheme| is handled in Chrome, or by default handlers in // net::URLRequest. static bool IsHandledProtocol(const std::string& scheme); @@ -106,7 +100,7 @@ class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> { } ChromeURLRequestContext* extensions_request_context() const { - return weak_extensions_request_context_.get(); + return extensions_request_context_.get(); } BooleanPrefMember* safe_browsing_enabled() const { @@ -114,35 +108,15 @@ class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> { } protected: - friend class base::RefCountedThreadSafe<ProfileIOData>; - - class RequestContext : public ChromeURLRequestContext { + class AppRequestContext : public ChromeURLRequestContext { public: - RequestContext(); - virtual ~RequestContext(); - - // Setter is used to transfer ownership of the ProfileIOData to the context. - void set_profile_io_data(ProfileIOData* profile_io_data) { - profile_io_data_ = profile_io_data; - } - - protected: - ProfileIOData* profile_io_data() { return profile_io_data_; } - - private: - scoped_refptr<ProfileIOData> profile_io_data_; - }; - - class AppRequestContext : public RequestContext { - public: - explicit AppRequestContext(const std::string& app_id); + AppRequestContext(); virtual ~AppRequestContext(); void SetCookieStore(net::CookieStore* cookie_store); void SetHttpTransactionFactory(net::HttpTransactionFactory* http_factory); private: - const std::string app_id_; scoped_refptr<net::CookieStore> cookie_store_; scoped_ptr<net::HttpTransactionFactory> http_factory_; }; @@ -185,7 +159,6 @@ class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> { }; explicit ProfileIOData(bool is_incognito); - virtual ~ProfileIOData(); void InitializeProfileParams(Profile* profile); void ApplyProfileParamsToContext(ChromeURLRequestContext* context) const; @@ -239,7 +212,7 @@ class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> { const ProfileIOData* const io_data_; }; - typedef base::hash_map<std::string, ChromeURLRequestContext*> + typedef base::hash_map<std::string, scoped_refptr<ChromeURLRequestContext> > AppRequestContextMap; // -------------------------------------------- @@ -252,7 +225,7 @@ class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> { // Does an on-demand initialization of a RequestContext for the given // isolated app. - virtual scoped_refptr<RequestContext> InitializeAppRequestContext( + virtual scoped_refptr<ChromeURLRequestContext> InitializeAppRequestContext( scoped_refptr<ChromeURLRequestContext> main_context, const std::string& app_id) const = 0; @@ -260,7 +233,7 @@ class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> { // context from ProfileIOData to the URLRequestContextGetter. virtual scoped_refptr<ChromeURLRequestContext> AcquireMediaRequestContext() const = 0; - virtual scoped_refptr<RequestContext> + virtual scoped_refptr<ChromeURLRequestContext> AcquireIsolatedAppRequestContext( scoped_refptr<ChromeURLRequestContext> main_context, const std::string& app_id) const = 0; @@ -304,17 +277,11 @@ class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> { // These are only valid in between LazyInitialize() and their accessor being // called. - mutable scoped_refptr<RequestContext> main_request_context_; - mutable scoped_refptr<RequestContext> extensions_request_context_; + mutable scoped_refptr<ChromeURLRequestContext> main_request_context_; + mutable scoped_refptr<ChromeURLRequestContext> extensions_request_context_; // One AppRequestContext per isolated app. mutable AppRequestContextMap app_request_context_map_; - // Weak pointers to the request contexts. Only valid after LazyInitialize. - // These are weak so that they don't hold a reference to the RequestContext, - // because that holds a reference back to ProfileIOData. - mutable base::WeakPtr<ChromeURLRequestContext> - weak_extensions_request_context_; - DISALLOW_COPY_AND_ASSIGN(ProfileIOData); }; |