Chromium Code Reviews| 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 faba3535fa634f92fc430102620364147e664686..0332ec8275169081edcddf305b9b6dfc73bc6469 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 |
| + // 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,40 @@ 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. |
|
awong
2012/10/29 23:37:40
add a extra line before the start of the TODO()
nasko
2012/10/30 00:32:59
Done.
|
| + // 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; |
| } |
| @@ -468,7 +478,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(); |
| } |
| @@ -476,23 +488,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 |
| @@ -504,7 +509,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( |
| @@ -519,7 +524,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. |
| @@ -564,10 +569,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. |
| @@ -575,16 +580,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. |
| @@ -620,12 +623,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; |
| @@ -634,10 +637,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; |
| } |