diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-16 04:01:08 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-16 04:01:08 +0000 |
commit | 71ace01735e041c2633dca68de83f59946d60b00 (patch) | |
tree | fcb901ec49437b5a161805958b2fd096c743d12d | |
parent | 84ed2976c5e799f3eaa79cc938f6cd4b3a730477 (diff) | |
download | chromium_src-71ace01735e041c2633dca68de83f59946d60b00.zip chromium_src-71ace01735e041c2633dca68de83f59946d60b00.tar.gz chromium_src-71ace01735e041c2633dca68de83f59946d60b00.tar.bz2 |
Redo the Storage Partition directory layout to support guest tags and origin based partitions.
The new layout is
(1) ProfileDir/Default/Storage Partitions/extensions/{ extension_id }/default/
(2) ProfileDir/Default/Storage Partitions/extensions/{ extension_id }/{ hash(BrowserTag.partition) }/
In the future, after we add support for browser tags in webui or add support for server
administrators of websites to opt into storage isolation, we will also need:
(3) ProfileDir/Default/Storage Partitions/origins/{ hash(origin) }/default/
(4) ProfileDir/Default/Storage Partitions/origins/{ hash(origin) }/{ hash(BrowserTag.partition) }/
TBR=willchan
BUG=85121
Review URL: https://chromiumcodereview.appspot.com/10913265
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157039 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/data_deleter.cc | 5 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl.cc | 4 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl_io_data.cc | 18 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl_io_data.h | 4 | ||||
-rw-r--r-- | content/browser/storage_partition_impl.cc | 50 | ||||
-rw-r--r-- | content/browser/storage_partition_impl.h | 2 | ||||
-rw-r--r-- | content/browser/storage_partition_impl_map.cc | 17 | ||||
-rw-r--r-- | content/browser/storage_partition_impl_map.h | 1 | ||||
-rw-r--r-- | content/public/browser/storage_partition.h | 12 | ||||
-rw-r--r-- | content/public/common/content_constants.cc | 2 | ||||
-rw-r--r-- | content/public/common/content_constants.h | 5 |
11 files changed, 86 insertions, 34 deletions
diff --git a/chrome/browser/extensions/data_deleter.cc b/chrome/browser/extensions/data_deleter.cc index 409b8df..38c3775 100644 --- a/chrome/browser/extensions/data_deleter.cc +++ b/chrome/browser/extensions/data_deleter.cc @@ -93,8 +93,9 @@ DataDeleter::DataDeleter( } else if (is_storage_isolated) { extension_request_context_ = profile->GetRequestContextForIsolatedApp(extension_id); - isolated_app_path_ = profile->GetPath(). - Append(content::kStoragePartitionDirname).AppendASCII(extension_id); + isolated_app_path_ = + profile->GetPath().Append( + content::StoragePartition::GetPartitionPath(extension_id)); } else { extension_request_context_ = profile->GetRequestContext(); } diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 5933687..809ade67 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -382,8 +382,6 @@ void ProfileImpl::DoFinalInit(bool is_new_profile) { extensions_cookie_path = extensions_cookie_path.Append(chrome::kExtensionsCookieFilename); - FilePath app_path = GetPath().Append(content::kStoragePartitionDirname); - FilePath infinite_cache_path = GetPath(); infinite_cache_path = infinite_cache_path.Append(FILE_PATH_LITERAL("Infinite Cache")); @@ -407,7 +405,7 @@ void ProfileImpl::DoFinalInit(bool is_new_profile) { io_data_.Init(cookie_path, server_bound_cert_path, cache_path, cache_max_size, media_cache_path, media_cache_max_size, - extensions_cookie_path, app_path, infinite_cache_path, + extensions_cookie_path, GetPath(), infinite_cache_path, predictor_, g_browser_process->local_state(), g_browser_process->io_thread(), diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc index 60a781e..4e7e378 100644 --- a/chrome/browser/profiles/profile_impl_io_data.cc +++ b/chrome/browser/profiles/profile_impl_io_data.cc @@ -31,6 +31,7 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/resource_context.h" +#include "content/public/browser/storage_partition.h" #include "net/base/server_bound_cert_service.h" #include "net/ftp/ftp_network_layer.h" #include "net/http/http_cache.h" @@ -94,7 +95,7 @@ void ProfileImplIOData::Handle::Init( const FilePath& media_cache_path, int media_cache_max_size, const FilePath& extensions_cookie_path, - const FilePath& app_path, + const FilePath& profile_path, const FilePath& infinite_cache_path, chrome_browser_net::Predictor* predictor, PrefService* local_state, @@ -120,9 +121,9 @@ void ProfileImplIOData::Handle::Init( io_data_->lazy_params_.reset(lazy_params); - // Keep track of isolated app path and cache sizes separately so we can use - // them on demand. - io_data_->app_path_ = app_path; + // Keep track of profile path and cache sizes separately so we can use them + // on demand when creating storage isolated URLRequestContextGetters. + io_data_->profile_path_ = profile_path; io_data_->app_cache_max_size_ = cache_max_size; io_data_->app_media_cache_max_size_ = media_cache_max_size; @@ -510,7 +511,10 @@ ProfileImplIOData::InitializeAppRequestContext( AppRequestContext* context = new AppRequestContext(load_time_stats()); context->CopyFrom(main_context); - FilePath app_path = app_path_.AppendASCII(app_id); + 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); @@ -583,7 +587,9 @@ ProfileImplIOData::InitializeMediaRequestContext( MediaRequestContext* context = new MediaRequestContext(load_time_stats()); context->CopyFrom(original_context); - FilePath app_path = app_path_.AppendASCII(app_id); + 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()) { diff --git a/chrome/browser/profiles/profile_impl_io_data.h b/chrome/browser/profiles/profile_impl_io_data.h index 3cfad74..d13d780 100644 --- a/chrome/browser/profiles/profile_impl_io_data.h +++ b/chrome/browser/profiles/profile_impl_io_data.h @@ -44,7 +44,7 @@ class ProfileImplIOData : public ProfileIOData { const FilePath& media_cache_path, int media_cache_max_size, const FilePath& extensions_cookie_path, - const FilePath& app_path, + const FilePath& profile_path, const FilePath& infinite_cache_path, chrome_browser_net::Predictor* predictor, PrefService* local_state, @@ -177,7 +177,7 @@ class ProfileImplIOData : public ProfileIOData { mutable scoped_ptr<net::URLRequestJobFactory> extensions_job_factory_; // Parameters needed for isolated apps. - FilePath app_path_; + FilePath profile_path_; int app_cache_max_size_; int app_media_cache_max_size_; diff --git a/content/browser/storage_partition_impl.cc b/content/browser/storage_partition_impl.cc index e906a6a..02cb5d7 100644 --- a/content/browser/storage_partition_impl.cc +++ b/content/browser/storage_partition_impl.cc @@ -12,6 +12,46 @@ namespace content { +namespace { + +// These constants are used to create the directory structure under the profile +// where renderers with a non-default storage partition keep their persistent +// state. This will contain a set of directories that partially mirror the +// directory structure of BrowserContext::GetPath(). +// +// The kStoragePartitionDirname is contains an extensions directory which is +// further partitioned by extension id, followed by another level of directories +// for the "default" extension storage partition and one directory for each +// persistent partition used by an extension's browser tags. Example: +// +// {kStoragePartitionDirname}/extensions/ABCDEF/default +// {kStoragePartitionDirname}/extensions/ABCDEF/{hash(guest partition)} +// +// The code in GetPartitionPath() constructs these path names. +const FilePath::CharType kStoragePartitionDirname[] = + FILE_PATH_LITERAL("Storage Partitions"); +const FilePath::CharType kExtensionsDirname[] = + FILE_PATH_LITERAL("extensions"); +const FilePath::CharType kDefaultPartitionDirname[] = + FILE_PATH_LITERAL("default"); + +} // namespace + +// static +FilePath StoragePartition::GetPartitionPath(const std::string& partition_id) { + if (partition_id.empty()) { + // The default profile just sits inside the top-level profile directory. + return FilePath(); + } + + // TODO(ajwong): This should check that we create a valid path name. + CHECK(IsStringASCII(partition_id)); + return FilePath(kStoragePartitionDirname) + .Append(kExtensionsDirname) + .AppendASCII(partition_id) + .Append(kDefaultPartitionDirname); +} + StoragePartitionImpl::StoragePartitionImpl( const FilePath& partition_path, quota::QuotaManager* quota_manager, @@ -47,12 +87,16 @@ StoragePartitionImpl::~StoragePartitionImpl() { // need 3 pieces of info from it. StoragePartitionImpl* StoragePartitionImpl::Create( BrowserContext* context, - const FilePath& partition_path) { + const std::string& partition_id, + const FilePath& profile_path) { // Ensure that these methods are called on the UI thread, except for // unittests where a UI thread might not have been created. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); + FilePath partition_path = + profile_path.Append(GetPartitionPath(partition_id)); + // All of the clients have to be created and registered with the // QuotaManager prior to the QuotaManger being used. We do them // all together here prior to handing out a reference to anything @@ -99,6 +143,10 @@ StoragePartitionImpl* StoragePartitionImpl::Create( indexed_db_context); } +FilePath StoragePartitionImpl::GetPath() { + return partition_path_; +} + quota::QuotaManager* StoragePartitionImpl::GetQuotaManager() { return quota_manager_; } diff --git a/content/browser/storage_partition_impl.h b/content/browser/storage_partition_impl.h index 9ab7fc3..e7f2f5d 100644 --- a/content/browser/storage_partition_impl.h +++ b/content/browser/storage_partition_impl.h @@ -22,9 +22,11 @@ class StoragePartitionImpl : public StoragePartition { // TODO(ajwong): Break the direct dependency on |context|. We only // need 3 pieces of info from it. static StoragePartitionImpl* Create(BrowserContext* context, + const std::string& partition_id, const FilePath& partition_path); // StoragePartition interface. + virtual FilePath GetPath() OVERRIDE; virtual quota::QuotaManager* GetQuotaManager() OVERRIDE; virtual ChromeAppCacheService* GetAppCacheService() OVERRIDE; virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE; diff --git a/content/browser/storage_partition_impl_map.cc b/content/browser/storage_partition_impl_map.cc index b1ba82c..f943a5f 100644 --- a/content/browser/storage_partition_impl_map.cc +++ b/content/browser/storage_partition_impl_map.cc @@ -38,23 +38,17 @@ StoragePartitionImpl* StoragePartitionImplMap::Get( return it->second; // There was no previous partition, so let's make a new one. - FilePath partition_path = browser_context_->GetPath(); - if (!partition_id.empty()) { - // TODO(ajwong): This should check the path is valid? - CHECK(IsStringASCII(partition_id)); - partition_path = partition_path.Append(kStoragePartitionDirname) - .AppendASCII(partition_id); - } - StoragePartitionImpl* storage_partition = - StoragePartitionImpl::Create(browser_context_, partition_path); + StoragePartitionImpl::Create(browser_context_, + partition_id, + browser_context_->GetPath()); partitions_[partition_id] = storage_partition; net::URLRequestContextGetter* request_context = partition_id.empty() ? browser_context_->GetRequestContext() : browser_context_->GetRequestContextForStoragePartition(partition_id); - PostCreateInitialization(storage_partition, partition_path, request_context); + PostCreateInitialization(storage_partition, request_context); // TODO(ajwong): We need to remove this conditional by making // InitializeResourceContext() understand having different partition data @@ -78,7 +72,6 @@ void StoragePartitionImplMap::ForEach( void StoragePartitionImplMap::PostCreateInitialization( StoragePartitionImpl* partition, - const FilePath& partition_path, net::URLRequestContextGetter* request_context_getter) { // Check first to avoid memory leak in unittests. if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { @@ -87,7 +80,7 @@ void StoragePartitionImplMap::PostCreateInitialization( base::Bind(&ChromeAppCacheService::InitializeOnIOThread, partition->GetAppCacheService(), browser_context_->IsOffTheRecord() ? FilePath() : - partition_path.Append(kAppCacheDirname), + partition->GetPath().Append(kAppCacheDirname), browser_context_->GetResourceContext(), make_scoped_refptr(request_context_getter), make_scoped_refptr( diff --git a/content/browser/storage_partition_impl_map.h b/content/browser/storage_partition_impl_map.h index ff75c4d..b875353 100644 --- a/content/browser/storage_partition_impl_map.h +++ b/content/browser/storage_partition_impl_map.h @@ -39,7 +39,6 @@ class StoragePartitionImplMap : public base::SupportsUserData::Data { // doesn't need to be aware of this ordering? Revisit when refactoring // ResourceContext and AppCache to respect storage partitions. void PostCreateInitialization(StoragePartitionImpl* partition, - const FilePath& partition_path, net::URLRequestContextGetter* request_context); BrowserContext* browser_context_; // Not Owned. diff --git a/content/public/browser/storage_partition.h b/content/public/browser/storage_partition.h index d7c1363..6cdb328 100644 --- a/content/public/browser/storage_partition.h +++ b/content/public/browser/storage_partition.h @@ -5,7 +5,10 @@ #ifndef CONTENT_PUBLIC_BROWSER_STORAGE_PARTITION_H_ #define CONTENT_PUBLIC_BROWSER_STORAGE_PARTITION_H_ +#include <string> + #include "base/basictypes.h" +#include "base/file_path.h" namespace appcache { class AppCacheService; @@ -37,6 +40,7 @@ class DOMStorageContext; // the cookies, localStorage, etc., that normal web renderers have access to. class StoragePartition { public: + virtual FilePath GetPath() = 0; virtual quota::QuotaManager* GetQuotaManager() = 0; virtual appcache::AppCacheService* GetAppCacheService() = 0; virtual fileapi::FileSystemContext* GetFileSystemContext() = 0; @@ -44,6 +48,14 @@ class StoragePartition { virtual DOMStorageContext* GetDOMStorageContext() = 0; virtual IndexedDBContext* GetIndexedDBContext() = 0; + // Returns the relative path from the profile's base directory, to the + // directory that holds all the state for storage contexts in |partition_id|. + // + // TODO(ajwong): Remove this function from the public API once + // URLRequestContextGetter's creation is moved into StoragePartition. + static CONTENT_EXPORT FilePath GetPartitionPath( + const std::string& partition_id); + protected: virtual ~StoragePartition() {} }; diff --git a/content/public/common/content_constants.cc b/content/public/common/content_constants.cc index 9b0cdc4..b8e205f9 100644 --- a/content/public/common/content_constants.cc +++ b/content/public/common/content_constants.cc @@ -9,8 +9,6 @@ const FilePath::CharType kAppCacheDirname[] = FILE_PATH_LITERAL("Application Cache"); const FilePath::CharType kPepperDataDirname[] = FILE_PATH_LITERAL("Pepper Data"); -const FilePath::CharType kStoragePartitionDirname[] = - FILE_PATH_LITERAL("Storage Partitions"); const char kBrowserPluginMimeType[] = "application/browser-plugin"; // TODO(fsamuel): Remove this once upstreaming of the new browser plugin is diff --git a/content/public/common/content_constants.h b/content/public/common/content_constants.h index 369c4c1..12bd7dc 100644 --- a/content/public/common/content_constants.h +++ b/content/public/common/content_constants.h @@ -20,11 +20,6 @@ CONTENT_EXPORT extern const FilePath::CharType kAppCacheDirname[]; // The name of the directory under BrowserContext::GetPath where Pepper plugin // data is put. CONTENT_EXPORT extern const FilePath::CharType kPepperDataDirname[]; -// The name of the directory under BrowserContext::GetPath() where renderers -// with a non-default storage partition keep their persistent state. This will -// contain a set of directories that partially mirror the directory structure -// of BrowserContext::GetPath(). -CONTENT_EXPORT extern const FilePath::CharType kStoragePartitionDirname[]; // The MIME type used for the browser plugin. CONTENT_EXPORT extern const char kBrowserPluginMimeType[]; |