Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5922)

Unified Diff: chrome/browser/profiles/profile_impl_io_data.cc

Issue 11147026: Initial refactor to get profiles to propagate storage partition details. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing Android's BrowserContext. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profiles/profile_impl_io_data.cc
diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc
index 3920aecdebd54c683b05eb1184b83dcb7d11b040..e6620ae3a51a2af41c1481b074aa9ecf24d06aa2 100644
--- a/chrome/browser/profiles/profile_impl_io_data.cc
+++ b/chrome/browser/profiles/profile_impl_io_data.cc
@@ -208,14 +208,18 @@ ProfileImplIOData::Handle::GetExtensionsRequestContextGetter() const {
scoped_refptr<ChromeURLRequestContextGetter>
ProfileImplIOData::Handle::GetIsolatedAppRequestContextGetter(
- const std::string& app_id) const {
+ const FilePath& partition_path,
+ bool in_memory) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- CHECK(!app_id.empty());
+ // TODO(nasko): Check that the partition_path is not the same as the
+ // base profile path. We expect isolated partition, which will never go
Charlie Reis 2012/10/30 17:47:48 nit: expect an Can we just put the check in rathe
nasko 2012/10/30 19:55:25 Your assumption is correct and that will be the ch
Charlie Reis 2012/10/30 20:13:07 Ah, ok.
+ // to the default profile path.
LazyInitialize();
- // Keep a map of request context getters, one per requested app ID.
+ // Keep a map of request context getters, one per requested storage partition.
+ StoragePartitionDescriptor descriptor(partition_path, in_memory);
ChromeURLRequestContextGetterMap::iterator iter =
- app_request_context_getter_map_.find(app_id);
+ app_request_context_getter_map_.find(descriptor);
if (iter != app_request_context_getter_map_.end())
return iter->second;
@@ -225,34 +229,41 @@ ProfileImplIOData::Handle::GetIsolatedAppRequestContextGetter(
CreateURLInterceptor());
ChromeURLRequestContextGetter* context =
ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp(
- profile_, io_data_, app_id, protocol_handler_interceptor.Pass());
- app_request_context_getter_map_[app_id] = context;
+ profile_, io_data_, descriptor,
+ protocol_handler_interceptor.Pass());
+ app_request_context_getter_map_[descriptor] = context;
return context;
}
scoped_refptr<ChromeURLRequestContextGetter>
ProfileImplIOData::Handle::GetIsolatedMediaRequestContextGetter(
- const std::string& app_id) const {
+ const FilePath& partition_path,
+ bool in_memory) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- // We must have an app ID, or this will act like the default media context.
- CHECK(!app_id.empty());
+ // We must have a non-default path, or this will act like the default media
+ // context.
+ //
+ // TODO(nasko): Check that the partition_path is not the same as the
+ // base profile path. We expect isolated partition, which will never go
+ // to the default profile path.
LazyInitialize();
- // Keep a map of request context getters, one per requested app ID.
+ // Keep a map of request context getters, one per requested storage partition.
+ StoragePartitionDescriptor descriptor(partition_path, in_memory);
ChromeURLRequestContextGetterMap::iterator iter =
- isolated_media_request_context_getter_map_.find(app_id);
+ isolated_media_request_context_getter_map_.find(descriptor);
if (iter != isolated_media_request_context_getter_map_.end())
return iter->second;
// Get the app context as the starting point for the media context, so that
// it uses the app's cookie store.
ChromeURLRequestContextGetter* app_context =
- GetIsolatedAppRequestContextGetter(app_id);
+ GetIsolatedAppRequestContextGetter(partition_path, in_memory);
ChromeURLRequestContextGetter* context =
ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia(
- profile_, app_context, io_data_, app_id);
- isolated_media_request_context_getter_map_[app_id] = context;
+ profile_, app_context, io_data_, descriptor);
+ isolated_media_request_context_getter_map_[descriptor] = context;
return context;
}
@@ -474,7 +485,9 @@ void ProfileImplIOData::LazyInitializeInternal(
// Create a media request context based on the main context, but using a
// media cache. It shares the same job factory as the main context.
- media_request_context_.reset(InitializeMediaRequestContext(main_context, ""));
+ StoragePartitionDescriptor details(FilePath(), false);
+ media_request_context_.reset(InitializeMediaRequestContext(main_context,
+ details));
lazy_params_.reset();
}
@@ -482,23 +495,16 @@ void ProfileImplIOData::LazyInitializeInternal(
ChromeURLRequestContext*
ProfileImplIOData::InitializeAppRequestContext(
ChromeURLRequestContext* main_context,
- const std::string& app_id,
+ const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
protocol_handler_interceptor) const {
- // If this is for a guest process, we should not persist cookies and http
- // cache.
- bool is_guest_process = (app_id.find("guest-") != std::string::npos);
-
// Copy most state from the main context.
AppRequestContext* context = new AppRequestContext(load_time_stats());
context->CopyFrom(main_context);
- using content::StoragePartition;
- FilePath app_path =
- profile_path_.Append(StoragePartition::GetPartitionPath(app_id));
-
- FilePath cookie_path = app_path.Append(chrome::kCookieFilename);
- FilePath cache_path = app_path.Append(chrome::kCacheDirname);
+ FilePath cookie_path = partition_descriptor.path.Append(
+ chrome::kCookieFilename);
+ FilePath cache_path = partition_descriptor.path.Append(chrome::kCacheDirname);
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
// Only allow Record Mode if we are in a Debug build or where we are running
@@ -510,7 +516,7 @@ ProfileImplIOData::InitializeAppRequestContext(
// Use a separate HTTP disk cache for isolated apps.
net::HttpCache::BackendFactory* app_backend = NULL;
- if (is_guest_process) {
+ if (partition_descriptor.in_memory) {
app_backend = net::HttpCache::DefaultBackend::InMemory(0);
} else {
app_backend = new net::HttpCache::DefaultBackend(
@@ -525,7 +531,7 @@ ProfileImplIOData::InitializeAppRequestContext(
new net::HttpCache(main_network_session, app_backend);
scoped_refptr<net::CookieStore> cookie_store = NULL;
- if (is_guest_process) {
+ if (partition_descriptor.in_memory) {
cookie_store = new net::CookieMonster(NULL, NULL);
} else if (record_mode || playback_mode) {
// Don't use existing cookies and use an in-memory store.
@@ -570,10 +576,10 @@ ProfileImplIOData::InitializeAppRequestContext(
ChromeURLRequestContext*
ProfileImplIOData::InitializeMediaRequestContext(
ChromeURLRequestContext* original_context,
- const std::string& app_id) const {
- // If this is for a guest process, we do not persist storage, so we can
- // simply use the app's in-memory cache (like off-the-record mode).
- if (app_id.find("guest-") != std::string::npos)
+ const StoragePartitionDescriptor& partition_descriptor) const {
+ // If this is for a in_memory partition, we can simply use the original
+ // context (like off-the-record mode).
+ if (partition_descriptor.in_memory)
return original_context;
// Copy most state from the original context.
@@ -581,16 +587,14 @@ ProfileImplIOData::InitializeMediaRequestContext(
context->CopyFrom(original_context);
using content::StoragePartition;
- FilePath app_path =
- profile_path_.Append(StoragePartition::GetPartitionPath(app_id));
FilePath cache_path;
int cache_max_size = app_media_cache_max_size_;
- if (app_id.empty()) {
+ if (partition_descriptor.path == profile_path_) {
// lazy_params_ is only valid for the default media context creation.
cache_path = lazy_params_->media_cache_path;
cache_max_size = lazy_params_->media_cache_max_size;
} else {
- cache_path = app_path.Append(chrome::kMediaCacheDirname);
+ cache_path = partition_descriptor.path.Append(chrome::kMediaCacheDirname);
}
// Use a separate HTTP disk cache for isolated apps.
@@ -626,12 +630,12 @@ ProfileImplIOData::AcquireMediaRequestContext() const {
ChromeURLRequestContext*
ProfileImplIOData::AcquireIsolatedAppRequestContext(
ChromeURLRequestContext* main_context,
- const std::string& app_id,
+ const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
protocol_handler_interceptor) const {
// We create per-app contexts on demand, unlike the others above.
ChromeURLRequestContext* app_request_context =
- InitializeAppRequestContext(main_context, app_id,
+ InitializeAppRequestContext(main_context, partition_descriptor,
protocol_handler_interceptor.Pass());
DCHECK(app_request_context);
return app_request_context;
@@ -640,10 +644,10 @@ ProfileImplIOData::AcquireIsolatedAppRequestContext(
ChromeURLRequestContext*
ProfileImplIOData::AcquireIsolatedMediaRequestContext(
ChromeURLRequestContext* app_context,
- const std::string& app_id) const {
+ const StoragePartitionDescriptor& partition_descriptor) const {
// We create per-app media contexts on demand, unlike the others above.
ChromeURLRequestContext* media_request_context =
- InitializeMediaRequestContext(app_context, app_id);
+ InitializeMediaRequestContext(app_context, partition_descriptor);
DCHECK(media_request_context);
return media_request_context;
}

Powered by Google App Engine
This is Rietveld 408576698