summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-03 20:05:12 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-03 20:05:12 +0000
commitbf9331ff06c2ede9414a4244712528abe9d9cad7 (patch)
treeb2c34029a345304574b6aa9678f8728ae2cbdd63
parent8524cb6cdeee14921f799b3a87733e24af6c32b7 (diff)
downloadchromium_src-bf9331ff06c2ede9414a4244712528abe9d9cad7.zip
chromium_src-bf9331ff06c2ede9414a4244712528abe9d9cad7.tar.gz
chromium_src-bf9331ff06c2ede9414a4244712528abe9d9cad7.tar.bz2
Create a ProfileIOData object to own ChromeURLRequestContext members.
This is the beginning of the ProfileIOData object. I hope to move more and more ChromeURLRequestContext members into it, so we can stop refcounting the members. Originally, I wanted ProfileIOData to own the ChromeURLRequestContext objects, but it would have caused too many difficulties with lifetime management for now. I'll save that for the future. This is an improvement since now URLRequestContext's members don't always have to be refcounted. TODO: Create an analog for OffTheRecordProfile objects. BUG=67237 TEST=existing Review URL: http://codereview.chromium.org/6315013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73651 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc132
-rw-r--r--chrome/browser/net/chrome_url_request_context.h17
-rw-r--r--chrome/browser/profiles/profile_impl.cc99
-rw-r--r--chrome/browser/profiles/profile_impl.h7
-rw-r--r--chrome/browser/profiles/profile_io_data.cc192
-rw-r--r--chrome/browser/profiles/profile_io_data.h123
-rw-r--r--chrome/chrome_browser.gypi2
7 files changed, 414 insertions, 158 deletions
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc
index 47580d8..6eda235 100644
--- a/chrome/browser/net/chrome_url_request_context.cc
+++ b/chrome/browser/net/chrome_url_request_context.cc
@@ -21,6 +21,7 @@
#include "chrome/browser/net/predictor_api.h"
#include "chrome/browser/net/pref_proxy_config_service.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_io_data.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension.h"
@@ -242,42 +243,29 @@ class ChromeCookieMonsterDelegate : public net::CookieMonster::Delegate {
class FactoryForOriginal : public ChromeURLRequestContextFactory {
public:
FactoryForOriginal(Profile* profile,
- const FilePath& cookie_store_path,
- const FilePath& disk_cache_path,
- int cache_size)
+ const ProfileIOData* profile_io_data)
: ChromeURLRequestContextFactory(profile),
- cookie_store_path_(cookie_store_path),
- disk_cache_path_(disk_cache_path),
- cache_size_(cache_size),
+ profile_io_data_(profile_io_data),
// We need to initialize the ProxyConfigService from the UI thread
// because on linux it relies on initializing things through gconf,
// and needs to be on the main thread.
proxy_config_service_(CreateProxyConfigService(profile)) {
}
- virtual ChromeURLRequestContext* Create();
+ virtual scoped_refptr<ChromeURLRequestContext> Create();
private:
- FilePath cookie_store_path_;
- FilePath disk_cache_path_;
- int cache_size_;
-
+ const scoped_refptr<const ProfileIOData> profile_io_data_;
scoped_ptr<net::ProxyConfigService> proxy_config_service_;
};
-ChromeURLRequestContext* FactoryForOriginal::Create() {
- ChromeURLRequestContext* context = new ChromeURLRequestContext;
+scoped_refptr<ChromeURLRequestContext> FactoryForOriginal::Create() {
+ scoped_refptr<ChromeURLRequestContext> context =
+ profile_io_data_->GetMainRequestContext();
ApplyProfileParametersToContext(context);
IOThread::Globals* io_thread_globals = io_thread()->globals();
-
- // Global host resolver for the context.
- context->set_host_resolver(io_thread_globals->host_resolver.get());
- context->set_cert_verifier(io_thread_globals->cert_verifier.get());
- context->set_dnsrr_resolver(io_thread_globals->dnsrr_resolver.get());
- context->set_network_delegate(&io_thread_globals->network_delegate);
- context->set_http_auth_handler_factory(
- io_thread_globals->http_auth_handler_factory.get());
+ const ProfileIOData::LazyParams& params = profile_io_data_->lazy_params();
context->set_dns_cert_checker(
CreateDnsCertProvenanceChecker(io_thread_globals->dnsrr_resolver.get(),
@@ -292,7 +280,7 @@ ChromeURLRequestContext* FactoryForOriginal::Create() {
command_line));
net::HttpCache::DefaultBackend* backend = new net::HttpCache::DefaultBackend(
- net::DISK_CACHE, disk_cache_path_, cache_size_,
+ net::DISK_CACHE, params.cache_path, params.cache_max_size,
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
net::HttpCache* cache = new net::HttpCache(
context->host_resolver(),
@@ -324,10 +312,10 @@ ChromeURLRequestContext* FactoryForOriginal::Create() {
// setup cookie store
if (!context->cookie_store()) {
- DCHECK(!cookie_store_path_.empty());
+ DCHECK(!params.cookie_path.empty());
scoped_refptr<SQLitePersistentCookieStore> cookie_db =
- new SQLitePersistentCookieStore(cookie_store_path_);
+ new SQLitePersistentCookieStore(params.cookie_path);
cookie_db->SetClearLocalStateOnExit(clear_local_state_on_exit_);
context->set_cookie_store(new net::CookieMonster(cookie_db.get(),
cookie_monster_delegate_));
@@ -337,30 +325,33 @@ ChromeURLRequestContext* FactoryForOriginal::Create() {
new ChromeCookiePolicy(host_content_settings_map_));
appcache_service_->set_request_context(context);
-
- context->set_net_log(io_thread()->net_log());
return context;
}
// Factory that creates the ChromeURLRequestContext for extensions.
class FactoryForExtensions : public ChromeURLRequestContextFactory {
public:
- FactoryForExtensions(Profile* profile, const FilePath& cookie_store_path,
+ FactoryForExtensions(Profile* profile, const ProfileIOData* profile_io_data,
bool incognito)
: ChromeURLRequestContextFactory(profile),
- cookie_store_path_(cookie_store_path),
+ profile_io_data_(profile_io_data),
incognito_(incognito) {
+ DCHECK(incognito || profile_io_data);
}
- virtual ChromeURLRequestContext* Create();
+ virtual scoped_refptr<ChromeURLRequestContext> Create();
private:
- FilePath cookie_store_path_;
- bool incognito_;
+ const scoped_refptr<const ProfileIOData> profile_io_data_;
+ const bool incognito_;
};
-ChromeURLRequestContext* FactoryForExtensions::Create() {
- ChromeURLRequestContext* context = new ChromeURLRequestContext;
+scoped_refptr<ChromeURLRequestContext> FactoryForExtensions::Create() {
+ scoped_refptr<ChromeURLRequestContext> context = NULL;
+ if (incognito_)
+ context = new ChromeURLRequestContext;
+ else
+ context = profile_io_data_->GetExtensionsRequestContext();
ApplyProfileParametersToContext(context);
IOThread::Globals* io_thread_globals = io_thread()->globals();
@@ -369,8 +360,10 @@ ChromeURLRequestContext* FactoryForExtensions::Create() {
// use a non-persistent cookie store.
scoped_refptr<SQLitePersistentCookieStore> cookie_db = NULL;
if (!incognito_) {
- DCHECK(!cookie_store_path_.empty());
- cookie_db = new SQLitePersistentCookieStore(cookie_store_path_);
+ const FilePath& cookie_store_path =
+ profile_io_data_->lazy_params().extensions_cookie_path;
+ DCHECK(!cookie_store_path.empty());
+ cookie_db = new SQLitePersistentCookieStore(cookie_store_path);
}
net::CookieMonster* cookie_monster =
@@ -400,15 +393,15 @@ class FactoryForOffTheRecord : public ChromeURLRequestContextFactory {
profile->GetOriginalProfile()->GetRequestContext())) {
}
- virtual ChromeURLRequestContext* Create();
+ virtual scoped_refptr<ChromeURLRequestContext> Create();
private:
scoped_ptr<net::ProxyConfigService> proxy_config_service_;
scoped_refptr<ChromeURLRequestContextGetter> original_context_getter_;
};
-ChromeURLRequestContext* FactoryForOffTheRecord::Create() {
- ChromeURLRequestContext* context = new ChromeURLRequestContext;
+scoped_refptr<ChromeURLRequestContext> FactoryForOffTheRecord::Create() {
+ scoped_refptr<ChromeURLRequestContext> context = new ChromeURLRequestContext;
ApplyProfileParametersToContext(context);
IOThread::Globals* io_thread_globals = io_thread()->globals();
@@ -458,37 +451,29 @@ ChromeURLRequestContext* FactoryForOffTheRecord::Create() {
class FactoryForMedia : public ChromeURLRequestContextFactory {
public:
FactoryForMedia(Profile* profile,
- const FilePath& disk_cache_path,
- int cache_size,
- bool off_the_record)
+ const ProfileIOData* profile_io_data)
: ChromeURLRequestContextFactory(profile),
main_context_getter_(
static_cast<ChromeURLRequestContextGetter*>(
profile->GetRequestContext())),
- disk_cache_path_(disk_cache_path),
- cache_size_(cache_size) {
- is_off_the_record_ = off_the_record;
+ profile_io_data_(profile_io_data) {
}
- virtual ChromeURLRequestContext* Create();
+ virtual scoped_refptr<ChromeURLRequestContext> Create();
private:
scoped_refptr<ChromeURLRequestContextGetter> main_context_getter_;
-
- FilePath disk_cache_path_;
- int cache_size_;
+ const scoped_refptr<const ProfileIOData> profile_io_data_;
};
-ChromeURLRequestContext* FactoryForMedia::Create() {
- ChromeURLRequestContext* context = new ChromeURLRequestContext;
+scoped_refptr<ChromeURLRequestContext> FactoryForMedia::Create() {
+ scoped_refptr<ChromeURLRequestContext> context =
+ profile_io_data_->GetMediaRequestContext();
ApplyProfileParametersToContext(context);
- ChromeURLRequestContext* main_context =
- main_context_getter_->GetIOContext();
+ ChromeURLRequestContext* main_context = main_context_getter_->GetIOContext();
- IOThread::Globals* io_thread_globals = io_thread()->globals();
- context->set_http_auth_handler_factory(
- io_thread_globals->http_auth_handler_factory.get());
+ const ProfileIOData::LazyParams& params = profile_io_data_->lazy_params();
// TODO(willchan): Make a global ProxyService available in IOThread::Globals.
context->set_proxy_service(main_context->proxy_service());
@@ -502,7 +487,7 @@ ChromeURLRequestContext* FactoryForMedia::Create() {
// Create a media cache with default size.
// TODO(hclam): make the maximum size of media cache configurable.
net::HttpCache::DefaultBackend* backend = new net::HttpCache::DefaultBackend(
- net::MEDIA_CACHE, disk_cache_path_, cache_size_,
+ net::MEDIA_CACHE, params.media_cache_path, params.media_cache_max_size,
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
net::HttpCache* main_cache =
@@ -610,34 +595,32 @@ ChromeURLRequestContextGetter::GetIOMessageLoopProxy() const {
// static
ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::CreateOriginal(
- Profile* profile, const FilePath& cookie_store_path,
- const FilePath& disk_cache_path, int cache_size) {
+ Profile* profile,
+ const ProfileIOData* profile_io_data) {
DCHECK(!profile->IsOffTheRecord());
return new ChromeURLRequestContextGetter(
profile,
- new FactoryForOriginal(profile,
- cookie_store_path,
- disk_cache_path,
- cache_size));
+ new FactoryForOriginal(profile, profile_io_data));
}
// static
ChromeURLRequestContextGetter*
ChromeURLRequestContextGetter::CreateOriginalForMedia(
- Profile* profile, const FilePath& disk_cache_path, int cache_size) {
+ Profile* profile, const ProfileIOData* profile_io_data) {
DCHECK(!profile->IsOffTheRecord());
- return CreateRequestContextForMedia(profile, disk_cache_path, cache_size,
- false);
+ return new ChromeURLRequestContextGetter(
+ profile,
+ new FactoryForMedia(profile, profile_io_data));
}
// static
ChromeURLRequestContextGetter*
ChromeURLRequestContextGetter::CreateOriginalForExtensions(
- Profile* profile, const FilePath& cookie_store_path) {
+ Profile* profile, const ProfileIOData* profile_io_data) {
DCHECK(!profile->IsOffTheRecord());
return new ChromeURLRequestContextGetter(
profile,
- new FactoryForExtensions(profile, cookie_store_path, false));
+ new FactoryForExtensions(profile, profile_io_data, false));
}
// static
@@ -654,7 +637,7 @@ ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(
Profile* profile) {
DCHECK(profile->IsOffTheRecord());
return new ChromeURLRequestContextGetter(
- profile, new FactoryForExtensions(profile, FilePath(), true));
+ profile, new FactoryForExtensions(profile, NULL, true));
}
void ChromeURLRequestContextGetter::CleanupOnUIThread() {
@@ -716,19 +699,6 @@ void ChromeURLRequestContextGetter::RegisterPrefsObserver(Profile* profile) {
registrar_.Add(prefs::kClearSiteDataOnExit, this);
}
-// static
-ChromeURLRequestContextGetter*
-ChromeURLRequestContextGetter::CreateRequestContextForMedia(
- Profile* profile, const FilePath& disk_cache_path, int cache_size,
- bool off_the_record) {
- return new ChromeURLRequestContextGetter(
- profile,
- new FactoryForMedia(profile,
- disk_cache_path,
- cache_size,
- off_the_record));
-}
-
void ChromeURLRequestContextGetter::OnAcceptLanguageChange(
const std::string& accept_language) {
GetIOContext()->OnAcceptLanguageChange(accept_language);
diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h
index 50f2d66..5d57b46 100644
--- a/chrome/browser/net/chrome_url_request_context.h
+++ b/chrome/browser/net/chrome_url_request_context.h
@@ -33,6 +33,7 @@
class CommandLine;
class PrefService;
class Profile;
+class ProfileIOData;
namespace net {
class DnsCertProvenanceChecker;
@@ -236,19 +237,18 @@ class ChromeURLRequestContextGetter : public URLRequestContextGetter,
// Create an instance for use with an 'original' (non-OTR) profile. This is
// expected to get called on the UI thread.
static ChromeURLRequestContextGetter* CreateOriginal(
- Profile* profile, const FilePath& cookie_store_path,
- const FilePath& disk_cache_path, int cache_size);
+ Profile* profile, const ProfileIOData* profile_io_data);
// Create an instance for an original profile for media. This is expected to
// get called on UI thread. This method takes a profile and reuses the
// 'original' net::URLRequestContext for common files.
static ChromeURLRequestContextGetter* CreateOriginalForMedia(
- Profile* profile, const FilePath& disk_cache_path, int cache_size);
+ Profile* profile, const ProfileIOData* profile_io_data);
// Create an instance for an original profile for extensions. This is expected
// to get called on UI thread.
static ChromeURLRequestContextGetter* CreateOriginalForExtensions(
- Profile* profile, const FilePath& cookie_store_path);
+ Profile* profile, const ProfileIOData* profile_io_data);
// Create an instance for use with an OTR profile. This is expected to get
// called on the UI thread.
@@ -276,13 +276,6 @@ class ChromeURLRequestContextGetter : public URLRequestContextGetter,
// to update the context when the default language and charset change.
void RegisterPrefsObserver(Profile* profile);
- // Creates a request context for media resources from a regular request
- // context. This helper method is called from CreateOriginalForMedia and
- // CreateOffTheRecordForMedia.
- static ChromeURLRequestContextGetter* CreateRequestContextForMedia(
- Profile* profile, const FilePath& disk_cache_path, int cache_size,
- bool off_the_record);
-
// These methods simply forward to the corresponding method on
// ChromeURLRequestContext.
void OnAcceptLanguageChange(const std::string& accept_language);
@@ -326,7 +319,7 @@ class ChromeURLRequestContextFactory {
virtual ~ChromeURLRequestContextFactory();
// Called to create a new instance (will only be called once).
- virtual ChromeURLRequestContext* Create() = 0;
+ virtual scoped_refptr<ChromeURLRequestContext> Create() = 0;
protected:
IOThread* io_thread() { return io_thread_; }
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index ef269c4..30f8fba 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -128,11 +128,6 @@ using base::TimeDelta;
namespace {
-void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
- if (context)
- context->CleanupOnUIThread();
-}
-
// Delay, in milliseconds, before we explicitly create the SessionService.
static const int kCreateSessionServiceDelayMS = 500;
@@ -248,9 +243,6 @@ ProfileImpl::ProfileImpl(const FilePath& path)
: path_(path),
visited_link_event_listener_(new VisitedLinkEventListener()),
extension_devtools_manager_(NULL),
- request_context_(NULL),
- media_request_context_(NULL),
- extensions_request_context_(NULL),
host_content_settings_map_(NULL),
host_zoom_map_(NULL),
history_service_created_(false),
@@ -285,6 +277,26 @@ ProfileImpl::ProfileImpl(const FilePath& path)
chrome::GetUserCacheDirectory(path_, &base_cache_path_);
file_util::CreateDirectory(base_cache_path_);
+ FilePath cookie_path = GetPath();
+ cookie_path = cookie_path.Append(chrome::kCookieFilename);
+ FilePath cache_path = base_cache_path_;
+ int cache_max_size;
+ GetCacheParameters(kNormalContext, &cache_path, &cache_max_size);
+ cache_path = GetCachePath(cache_path);
+
+ FilePath media_cache_path = base_cache_path_;
+ int media_cache_max_size;
+ GetCacheParameters(kMediaContext, &media_cache_path, &media_cache_max_size);
+ cache_path = GetMediaCachePath(cache_path);
+
+ FilePath extensions_cookie_path = GetPath();
+ extensions_cookie_path =
+ extensions_cookie_path.Append(chrome::kExtensionsCookieFilename);
+
+ io_data_.Init(cookie_path, cache_path, cache_max_size,
+ media_cache_path, media_cache_max_size, extensions_cookie_path,
+ this);
+
// Listen for theme installations from our original profile.
registrar_.Add(this, NotificationType::THEME_INSTALLED,
Source<Profile>(GetOriginalProfile()));
@@ -541,13 +553,10 @@ ProfileImpl::~ProfileImpl() {
if (spellcheck_host_.get())
spellcheck_host_->UnsetObserver();
- if (default_request_context_ == request_context_)
+ if (io_data_.HasMainRequestContext() &&
+ default_request_context_ == GetRequestContext()) {
default_request_context_ = NULL;
-
-
- CleanupRequestContext(request_context_);
- CleanupRequestContext(media_request_context_);
- CleanupRequestContext(extensions_request_context_);
+ }
// HistoryService may call into the BookmarkModel, as such we need to
// delete HistoryService before the BookmarkModel. The destructor for
@@ -754,47 +763,26 @@ FilePath ProfileImpl::GetPrefFilePath() {
}
URLRequestContextGetter* ProfileImpl::GetRequestContext() {
- if (!request_context_) {
- FilePath cookie_path = GetPath();
- cookie_path = cookie_path.Append(chrome::kCookieFilename);
- FilePath cache_path = base_cache_path_;
- int max_size;
- GetCacheParameters(kNormalContext, &cache_path, &max_size);
-
- cache_path = GetCachePath(cache_path);
- request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
- this, cookie_path, cache_path, max_size);
-
- // The first request context is always a normal (non-OTR) request context.
- // Even when Chromium is started in OTR mode, a normal profile is always
- // created first.
- if (!default_request_context_) {
- default_request_context_ = request_context_;
- request_context_->set_is_main(true);
- // TODO(eroman): this isn't terribly useful anymore now that the
- // net::URLRequestContext is constructed by the IO thread...
- NotificationService::current()->Notify(
- NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
- NotificationService::AllSources(), NotificationService::NoDetails());
- }
+ URLRequestContextGetter* request_context =
+ io_data_.GetMainRequestContextGetter();
+ // The first request context is always a normal (non-OTR) request context.
+ // Even when Chromium is started in OTR mode, a normal profile is always
+ // created first.
+ if (!default_request_context_) {
+ default_request_context_ = request_context;
+ request_context->set_is_main(true);
+ // TODO(eroman): this isn't terribly useful anymore now that the
+ // net::URLRequestContext is constructed by the IO thread...
+ NotificationService::current()->Notify(
+ NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
+ NotificationService::AllSources(), NotificationService::NoDetails());
}
- return request_context_;
+ return request_context;
}
URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
- if (!media_request_context_) {
- FilePath cache_path = base_cache_path_;
- int max_size;
- GetCacheParameters(kMediaContext, &cache_path, &max_size);
-
- cache_path = GetMediaCachePath(cache_path);
- media_request_context_ =
- ChromeURLRequestContextGetter::CreateOriginalForMedia(
- this, cache_path, max_size);
- }
-
- return media_request_context_;
+ return io_data_.GetMediaRequestContextGetter();
}
FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
@@ -807,16 +795,7 @@ FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
}
URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
- if (!extensions_request_context_) {
- FilePath cookie_path = GetPath();
- cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
-
- extensions_request_context_ =
- ChromeURLRequestContextGetter::CreateOriginalForExtensions(
- this, cookie_path);
- }
-
- return extensions_request_context_;
+ return io_data_.GetExtensionsRequestContextGetter();
}
void ProfileImpl::RegisterExtensionWithRequestContexts(
diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h
index d455bb9..ee36db5 100644
--- a/chrome/browser/profiles/profile_impl.h
+++ b/chrome/browser/profiles/profile_impl.h
@@ -13,6 +13,7 @@
#include "base/scoped_ptr.h"
#include "base/timer.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_io_data.h"
#include "chrome/browser/prefs/pref_change_registrar.h"
#include "chrome/browser/spellcheck_host_observer.h"
#include "chrome/common/notification_observer.h"
@@ -213,11 +214,7 @@ class ProfileImpl : public Profile,
scoped_ptr<ProfileSyncService> sync_service_;
scoped_refptr<CloudPrintProxyService> cloud_print_proxy_service_;
- scoped_refptr<ChromeURLRequestContextGetter> request_context_;
-
- scoped_refptr<ChromeURLRequestContextGetter> media_request_context_;
-
- scoped_refptr<ChromeURLRequestContextGetter> extensions_request_context_;
+ ProfileIOData::Handle io_data_;
scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc
new file mode 100644
index 0000000..9e0e96e
--- /dev/null
+++ b/chrome/browser/profiles/profile_io_data.cc
@@ -0,0 +1,192 @@
+// Copyright (c) 2011 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 "chrome/browser/profiles/profile_io_data.h"
+
+#include "base/basictypes.h"
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "build/build_config.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/net/chrome_net_log.h"
+#include "chrome/browser/net/chrome_url_request_context.h"
+
+ProfileIOData::Handle::Handle() : io_data_(new ProfileIOData) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+}
+
+ProfileIOData::Handle::~Handle() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (main_request_context_getter_)
+ main_request_context_getter_->CleanupOnUIThread();
+ if (media_request_context_getter_)
+ media_request_context_getter_->CleanupOnUIThread();
+ if (extensions_request_context_getter_)
+ extensions_request_context_getter_->CleanupOnUIThread();
+}
+
+void ProfileIOData::Handle::Init(const FilePath& cookie_path,
+ const FilePath& cache_path,
+ int cache_max_size,
+ const FilePath& media_cache_path,
+ int media_cache_max_size,
+ const FilePath& extensions_cookie_path,
+ Profile* profile) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(!io_data_->lazy_params_.get());
+ LazyParams* lazy_params = new LazyParams;
+ lazy_params->cookie_path = cookie_path;
+ lazy_params->cache_path = cache_path;
+ lazy_params->cache_max_size = cache_max_size;
+ lazy_params->media_cache_path = media_cache_path;
+ lazy_params->media_cache_max_size = media_cache_max_size;
+ lazy_params->extensions_cookie_path = extensions_cookie_path;
+ lazy_params->profile = profile;
+ lazy_params->io_thread = g_browser_process->io_thread();
+ io_data_->lazy_params_.reset(lazy_params);
+}
+
+scoped_refptr<ChromeURLRequestContextGetter>
+ProfileIOData::Handle::GetMainRequestContextGetter() const {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (!main_request_context_getter_) {
+ main_request_context_getter_ =
+ ChromeURLRequestContextGetter::CreateOriginal(
+ io_data_->lazy_params_->profile, io_data_);
+ }
+ return main_request_context_getter_;
+}
+
+scoped_refptr<ChromeURLRequestContextGetter>
+ProfileIOData::Handle::GetMediaRequestContextGetter() const {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (!media_request_context_getter_) {
+ media_request_context_getter_ =
+ ChromeURLRequestContextGetter::CreateOriginalForMedia(
+ io_data_->lazy_params_->profile, io_data_);
+ }
+ return media_request_context_getter_;
+}
+
+scoped_refptr<ChromeURLRequestContextGetter>
+ProfileIOData::Handle::GetExtensionsRequestContextGetter() const {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (!extensions_request_context_getter_) {
+ extensions_request_context_getter_ =
+ ChromeURLRequestContextGetter::CreateOriginalForExtensions(
+ io_data_->lazy_params_->profile, io_data_);
+ }
+ return extensions_request_context_getter_;
+}
+
+class ProfileIOData::RequestContext : public ChromeURLRequestContext {
+ public:
+ RequestContext();
+ ~RequestContext();
+
+ void set_profile_io_data(const ProfileIOData* profile_io_data) {
+ profile_io_data_ = profile_io_data;
+ }
+
+ private:
+ scoped_refptr<const ProfileIOData> profile_io_data_;
+};
+
+ProfileIOData::RequestContext::RequestContext() {}
+ProfileIOData::RequestContext::~RequestContext() {}
+
+ProfileIOData::ProfileIOData() : initialized_(false) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+}
+
+ProfileIOData::~ProfileIOData() {
+ // If we have never initialized ProfileIOData, then Handle may hold the only
+ // reference to it. The important thing is to make sure it hasn't been
+ // initialized yet, because the lazily initialized variables are supposed to
+ // live on the IO thread.
+ if (BrowserThread::CurrentlyOn(BrowserThread::UI))
+ DCHECK(!initialized_);
+ else
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+}
+
+scoped_refptr<ChromeURLRequestContext>
+ProfileIOData::GetMainRequestContext() const {
+ LazyInitialize();
+ DCHECK(main_request_context_);
+ scoped_refptr<ChromeURLRequestContext> context = main_request_context_;
+ main_request_context_->set_profile_io_data(this);
+ main_request_context_ = NULL;
+ return context;
+}
+
+scoped_refptr<ChromeURLRequestContext>
+ProfileIOData::GetMediaRequestContext() const {
+ LazyInitialize();
+ DCHECK(media_request_context_);
+ scoped_refptr<ChromeURLRequestContext> context = media_request_context_;
+ media_request_context_->set_profile_io_data(this);
+ media_request_context_ = NULL;
+ return context;
+}
+
+scoped_refptr<ChromeURLRequestContext>
+ProfileIOData::GetExtensionsRequestContext() const {
+ LazyInitialize();
+ DCHECK(extensions_request_context_);
+ scoped_refptr<ChromeURLRequestContext> context = extensions_request_context_;
+ extensions_request_context_->set_profile_io_data(this);
+ extensions_request_context_ = NULL;
+ return context;
+}
+
+const ProfileIOData::LazyParams& ProfileIOData::lazy_params() const {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(lazy_params_.get());
+ return *lazy_params_;
+}
+
+void ProfileIOData::LazyInitialize() const {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ if (initialized_)
+ return;
+
+ main_request_context_ = new RequestContext;
+ media_request_context_ = new RequestContext;
+ extensions_request_context_ = new RequestContext;
+
+ // Initialize context members.
+ IOThread::Globals* io_thread_globals = lazy_params_->io_thread->globals();
+
+ main_request_context_->set_net_log(lazy_params_->io_thread->net_log());
+ media_request_context_->set_net_log(lazy_params_->io_thread->net_log());
+
+ main_request_context_->set_host_resolver(
+ io_thread_globals->host_resolver.get());
+ main_request_context_->set_cert_verifier(
+ io_thread_globals->cert_verifier.get());
+ main_request_context_->set_dnsrr_resolver(
+ io_thread_globals->dnsrr_resolver.get());
+ main_request_context_->set_network_delegate(
+ &io_thread_globals->network_delegate);
+
+ main_request_context_->set_http_auth_handler_factory(
+ io_thread_globals->http_auth_handler_factory.get());
+ media_request_context_->set_http_auth_handler_factory(
+ io_thread_globals->http_auth_handler_factory.get());
+ // TODO(cbentzel): How should extensions handle HTTP Authentication?
+ extensions_request_context_->set_http_auth_handler_factory(
+ io_thread_globals->http_auth_handler_factory.get());
+
+ // TODO(willchan): Initialize more of the contexts!
+
+ // TODO(willchan): Enable this when LazyInitialize() is able to fully
+ // initialize all the ChromeURLRequestContexts.
+#if 0
+ params_.reset();
+#endif
+
+ initialized_ = true;
+}
diff --git a/chrome/browser/profiles/profile_io_data.h b/chrome/browser/profiles/profile_io_data.h
new file mode 100644
index 0000000..93c431c
--- /dev/null
+++ b/chrome/browser/profiles/profile_io_data.h
@@ -0,0 +1,123 @@
+// Copyright (c) 2011 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.
+
+#ifndef CHROME_BROWSER_PROFILES_PROFILE_IO_DATA_H_
+#define CHROME_BROWSER_PROFILES_PROFILE_IO_DATA_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/file_path.h"
+#include "base/ref_counted.h"
+#include "base/scoped_ptr.h"
+
+class ChromeURLRequestContext;
+class ChromeURLRequestContextGetter;
+class IOThread;
+class Profile;
+
+// ProfileImpl owns a ProfileIOData::Handle, which holds a reference to the
+// ProfileIOData. ProfileIOData is intended to own all the objects owned by
+// ProfileImpl which live on the IO thread, such as, but not limited to, network
+// objects like CookieMonster, HttpTransactionFactory, etc. ProfileIOData is
+// owned by the ProfileImpl and ProfileIOData's ChromeURLRequestContexts. When
+// all of them go away, then ProfileIOData will be deleted. Note that the
+// ProfileIOData will typically outlive the Profile it is "owned" by, so it's
+// important for ProfileIOData not to hold any references to the Profile beyond
+// what's used by LazyParams (which should be deleted after lazy
+// initialization).
+class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> {
+ public:
+ class Handle {
+ public:
+ Handle();
+ ~Handle();
+
+ // Init() must be called before ~Handle(). It records all the necessary
+ // parameters needed to construct a ChromeURLRequestContextGetter.
+ void Init(const FilePath& cookie_path,
+ const FilePath& cache_path,
+ int cache_max_size,
+ const FilePath& media_cache_path,
+ int media_cache_max_size,
+ const FilePath& extensions_cookie_path,
+ Profile* profile);
+
+ bool HasMainRequestContext() const {
+ return main_request_context_getter_ != NULL;
+ }
+ scoped_refptr<ChromeURLRequestContextGetter>
+ GetMainRequestContextGetter() const;
+ scoped_refptr<ChromeURLRequestContextGetter>
+ GetMediaRequestContextGetter() const;
+ scoped_refptr<ChromeURLRequestContextGetter>
+ GetExtensionsRequestContextGetter() const;
+
+ private:
+ // Ordering is important here. Do not reorder unless you know what you're
+ // doing.
+ const scoped_refptr<ProfileIOData> io_data_;
+ mutable scoped_refptr<ChromeURLRequestContextGetter>
+ main_request_context_getter_;
+ mutable scoped_refptr<ChromeURLRequestContextGetter>
+ media_request_context_getter_;
+ mutable scoped_refptr<ChromeURLRequestContextGetter>
+ extensions_request_context_getter_;
+
+ DISALLOW_COPY_AND_ASSIGN(Handle);
+ };
+
+ // TODO(willchan): Move this to the private section when
+ // ChromeURLRequestContextFactory subclasses don't need it anymore.
+ struct LazyParams {
+ // All of these parameters are intended to be read on the IO thread.
+ FilePath cookie_path;
+ FilePath cache_path;
+ int cache_max_size;
+ FilePath media_cache_path;
+ int media_cache_max_size;
+ FilePath extensions_cookie_path;
+ IOThread* io_thread;
+
+ // TODO(willchan): Kill this, since the IO thread shouldn't be reading from
+ // the Profile. Instead, replace this with the parameters we want to copy
+ // from the UI thread to the IO thread.
+ Profile* profile;
+ };
+
+ // These should only be called at most once each. Ownership is reversed they
+ // get called, from ProfileIOData owning ChromeURLRequestContext to vice
+ // versa.
+ scoped_refptr<ChromeURLRequestContext> GetMainRequestContext() const;
+ scoped_refptr<ChromeURLRequestContext> GetMediaRequestContext() const;
+ scoped_refptr<ChromeURLRequestContext> GetExtensionsRequestContext() const;
+
+ // TODO(willchan): Delete this when ChromeURLRequestContextFactory subclasses
+ // don't need it anymore.
+ const LazyParams& lazy_params() const;
+
+ private:
+ friend class base::RefCountedThreadSafe<ProfileIOData>;
+
+ class RequestContext;
+
+ ProfileIOData();
+ ~ProfileIOData();
+
+ // Lazily initializes ProfileIOData.
+ void LazyInitialize() const;
+
+ // Lazy initialization params.
+ // TODO(willchan): Delete after Initialize() finishes initializing all the
+ // contexts.
+ scoped_ptr<const LazyParams> lazy_params_;
+
+ mutable bool initialized_;
+ mutable scoped_refptr<RequestContext> main_request_context_;
+ mutable scoped_refptr<RequestContext> media_request_context_;
+ mutable scoped_refptr<RequestContext> extensions_request_context_;
+
+ DISALLOW_COPY_AND_ASSIGN(ProfileIOData);
+};
+
+#endif // CHROME_BROWSER_PROFILES_PROFILE_IO_DATA_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index cb0fe56..af08ba2 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1883,6 +1883,8 @@
'browser/profiles/profile.h',
'browser/profiles/profile_impl.cc',
'browser/profiles/profile_impl.h',
+ 'browser/profiles/profile_io_data.cc',
+ 'browser/profiles/profile_io_data.h',
'browser/profiles/profile_manager.cc',
'browser/profiles/profile_manager.h',
'browser/remoting/directory_add_request.cc',