diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-09 00:41:05 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-09 00:41:05 +0000 |
commit | 01ba15f7ff530575d976b57e92fb4433dcdc5aaf (patch) | |
tree | d92d084e1c31f1a4e80cef1d6165a3f47c81eee8 | |
parent | 9b6e4b434aa26d2001d7bae9e9e757c4cdfef97c (diff) | |
download | chromium_src-01ba15f7ff530575d976b57e92fb4433dcdc5aaf.zip chromium_src-01ba15f7ff530575d976b57e92fb4433dcdc5aaf.tar.gz chromium_src-01ba15f7ff530575d976b57e92fb4433dcdc5aaf.tar.bz2 |
gdata: Move IsUnderGDataCacheDirectory() to GDataCache
GDataFileSystem::IsUnderGDataCacheDirectory() is still kept.
This will be removed when we move the ownership of GDataCache
from GDataFileSystem to GDataSystemService.
BUG=131756
TEST=unit_tests --gtest_filter="GData*"
Review URL: https://chromiumcodereview.appspot.com/10541080
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141335 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_cache.cc | 34 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_cache.h | 13 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_file_system.cc | 13 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_file_system.h | 3 |
4 files changed, 42 insertions, 21 deletions
diff --git a/chrome/browser/chromeos/gdata/gdata_cache.cc b/chrome/browser/chromeos/gdata/gdata_cache.cc index e6031ef..13e81a8 100644 --- a/chrome/browser/chromeos/gdata/gdata_cache.cc +++ b/chrome/browser/chromeos/gdata/gdata_cache.cc @@ -10,12 +10,16 @@ #include "base/stringprintf.h" #include "base/string_util.h" #include "chrome/browser/chromeos/gdata/gdata_util.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/common/chrome_constants.h" +#include "chrome/common/chrome_paths_internal.h" namespace gdata { namespace { const char kLocallyModifiedFileExtension[] = "local"; +const FilePath::CharType kGDataCacheVersionDir[] = FILE_PATH_LITERAL("v1"); const FilePath::CharType kGDataCacheMetaDir[] = FILE_PATH_LITERAL("meta"); const FilePath::CharType kGDataCachePinnedDir[] = FILE_PATH_LITERAL("pinned"); const FilePath::CharType kGDataCacheOutgoingDir[] = @@ -75,16 +79,17 @@ GDataCache::GDataCache( const FilePath& cache_root_path, base::SequencedWorkerPool* pool, const base::SequencedWorkerPool::SequenceToken& sequence_token) - : pool_(pool), + : cache_root_path_(cache_root_path), + pool_(pool), sequence_token_(sequence_token) { // Insert into |cache_paths_| in order defined in enum CacheSubDirectoryType. - cache_paths_.push_back(cache_root_path.Append(kGDataCacheMetaDir)); - cache_paths_.push_back(cache_root_path.Append(kGDataCachePinnedDir)); - cache_paths_.push_back(cache_root_path.Append(kGDataCacheOutgoingDir)); - cache_paths_.push_back(cache_root_path.Append(kGDataCachePersistentDir)); - cache_paths_.push_back(cache_root_path.Append(kGDataCacheTmpDir)); - cache_paths_.push_back(cache_root_path.Append(kGDataCacheTmpDownloadsDir)); - cache_paths_.push_back(cache_root_path.Append(kGDataCacheTmpDocumentsDir)); + cache_paths_.push_back(cache_root_path_.Append(kGDataCacheMetaDir)); + cache_paths_.push_back(cache_root_path_.Append(kGDataCachePinnedDir)); + cache_paths_.push_back(cache_root_path_.Append(kGDataCacheOutgoingDir)); + cache_paths_.push_back(cache_root_path_.Append(kGDataCachePersistentDir)); + cache_paths_.push_back(cache_root_path_.Append(kGDataCacheTmpDir)); + cache_paths_.push_back(cache_root_path_.Append(kGDataCacheTmpDownloadsDir)); + cache_paths_.push_back(cache_root_path_.Append(kGDataCacheTmpDocumentsDir)); } GDataCache::~GDataCache() { @@ -129,6 +134,10 @@ void GDataCache::AssertOnSequencedWorkerPool() { DCHECK(!pool_ || pool_->IsRunningSequenceOnCurrentThread(sequence_token_)); } +bool GDataCache::IsUnderGDataCacheDirectory(const FilePath& path) const { + return cache_root_path_ == path || cache_root_path_.IsParent(path); +} + class GDataCacheMap : public GDataCache { public: GDataCacheMap( @@ -268,4 +277,13 @@ scoped_ptr<GDataCache> GDataCache::CreateGDataCache( cache_root_path, pool, sequence_token)); } +// static +FilePath GDataCache::GetCacheRootPath(Profile* profile) { + FilePath cache_base_path; + chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path); + FilePath cache_root_path = + cache_base_path.Append(chrome::kGDataCacheDirname); + return cache_root_path.Append(kGDataCacheVersionDir); +} + } // namespace gdata diff --git a/chrome/browser/chromeos/gdata/gdata_cache.h b/chrome/browser/chromeos/gdata/gdata_cache.h index 2c3266e..cde682a 100644 --- a/chrome/browser/chromeos/gdata/gdata_cache.h +++ b/chrome/browser/chromeos/gdata/gdata_cache.h @@ -13,6 +13,8 @@ #include "base/memory/scoped_ptr.h" #include "base/threading/sequenced_worker_pool.h" +class Profile; + namespace gdata { class GDataCache { @@ -128,6 +130,10 @@ class GDataCache { CacheSubDirectoryType sub_dir_type, CachedFileOrigin file_orign) const; + // Returns true if the given path is under gdata cache directory, i.e. + // <user_profile_dir>/GCache/v1 + bool IsUnderGDataCacheDirectory(const FilePath& path) const; + // TODO(hashimoto): Remove this method when crbug.com/131756 is fixed. const std::vector<FilePath>& cache_paths() const { return cache_paths_; } @@ -166,6 +172,11 @@ class GDataCache { base::SequencedWorkerPool* pool, const base::SequencedWorkerPool::SequenceToken& sequence_token); + // Gets the cache root path (i.e. <user_profile_dir>/GCache/v1) from the + // profile. + // TODO(satorux): Write a unit test for this. + static FilePath GetCacheRootPath(Profile* profile); + protected: GDataCache( const FilePath& cache_root_path, @@ -177,6 +188,8 @@ class GDataCache { void AssertOnSequencedWorkerPool(); private: + // The root directory of the cache (i.e. <user_profile_dir>/GCache/v1). + const FilePath cache_root_path_; // Paths for all subdirectories of GCache, one for each // GDataCache::CacheSubDirectoryType enum. std::vector<FilePath> cache_paths_; diff --git a/chrome/browser/chromeos/gdata/gdata_file_system.cc b/chrome/browser/chromeos/gdata/gdata_file_system.cc index 1c305b3..b38f1ef 100644 --- a/chrome/browser/chromeos/gdata/gdata_file_system.cc +++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc @@ -36,9 +36,7 @@ #include "chrome/browser/chromeos/gdata/gdata_util.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_notification_types.h" -#include "chrome/common/chrome_paths_internal.h" #include "chrome/common/pref_names.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_details.h" @@ -54,7 +52,6 @@ const char kMimeTypeOctetStream[] = "application/octet-stream"; const char kWildCard[] = "*"; -const FilePath::CharType kGDataCacheVersionDir[] = FILE_PATH_LITERAL("v1"); const FilePath::CharType kAccountMetadataFile[] = FILE_PATH_LITERAL("account_metadata.json"); const FilePath::CharType kFilesystemProtoFile[] = @@ -927,15 +924,11 @@ GDataFileSystem::GDataFileSystem(Profile* profile, void GDataFileSystem::Initialize() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - FilePath cache_base_path; - chrome::GetUserCacheDirectory(profile_->GetPath(), &cache_base_path); - gdata_cache_path_ = cache_base_path.Append(chrome::kGDataCacheDirname); - gdata_cache_path_ = gdata_cache_path_.Append(kGDataCacheVersionDir); - documents_service_->Initialize(profile_); root_.reset(new GDataRootDirectory); - cache_ = GDataCache::CreateGDataCache(gdata_cache_path_, + const FilePath cache_root_path = GDataCache::GetCacheRootPath(profile_); + cache_ = GDataCache::CreateGDataCache(cache_root_path, BrowserThread::GetBlockingPool(), sequence_token_).Pass(); @@ -3950,7 +3943,7 @@ void GDataFileSystem::SetHideHostedDocuments(bool hide) { //===================== GDataFileSystem: Cache entry points ==================== bool GDataFileSystem::IsUnderGDataCacheDirectory(const FilePath& path) const { - return gdata_cache_path_ == path || gdata_cache_path_.IsParent(path); + return cache_->IsUnderGDataCacheDirectory(path); } FilePath GDataFileSystem::GetCacheDirectoryPath( diff --git a/chrome/browser/chromeos/gdata/gdata_file_system.h b/chrome/browser/chromeos/gdata/gdata_file_system.h index b8daad4..2a4d337 100644 --- a/chrome/browser/chromeos/gdata/gdata_file_system.h +++ b/chrome/browser/chromeos/gdata/gdata_file_system.h @@ -1478,9 +1478,6 @@ class GDataFileSystem : public GDataFileSystemInterface, // The document service for the GDataFileSystem. DocumentsServiceInterface* documents_service_; - // Base path for GData cache, e.g. <user_profile_dir>/user/GCache/v1. - FilePath gdata_cache_path_; - // Waitable events used to block destructor until all the tasks on blocking // pool are run. scoped_ptr<base::WaitableEvent> on_io_completed_; |