diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-01 13:42:32 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-01 13:42:32 +0000 |
commit | 77fb1a603884d91d429239925a305976ef5593de (patch) | |
tree | 06a23e5c3ee569b4083fbca93892473ddfdc2905 /chrome/browser/chromeos/drive | |
parent | 20eacd2b51c81881bc7c323610b5e6b618f9dc5b (diff) | |
download | chromium_src-77fb1a603884d91d429239925a305976ef5593de.zip chromium_src-77fb1a603884d91d429239925a305976ef5593de.tar.gz chromium_src-77fb1a603884d91d429239925a305976ef5593de.tar.bz2 |
chromeos: Rename DriveCache's methods in a UI-thread centric manner
BUG=None
TEST=unit_tests
Review URL: https://chromiumcodereview.appspot.com/11275068
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165365 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/drive')
11 files changed, 419 insertions, 465 deletions
diff --git a/chrome/browser/chromeos/drive/drive_cache.cc b/chrome/browser/chromeos/drive/drive_cache.cc index ba9d0af..9f1140f 100644 --- a/chrome/browser/chromeos/drive/drive_cache.cc +++ b/chrome/browser/chromeos/drive/drive_cache.cc @@ -229,7 +229,7 @@ void CollectAnyFile(std::vector<std::string>* resource_ids, } // Runs callback with pointers dereferenced. -// Used to implement SetMountedStateOnUIThread and ClearAllOnUIThread. +// Used to implement SetMountedState and ClearAll. void RunChangeCacheStateCallback(const ChangeCacheStateCallback& callback, const DriveFileError* error, const FilePath* cache_file_path) { @@ -242,7 +242,7 @@ void RunChangeCacheStateCallback(const ChangeCacheStateCallback& callback, } // Runs callback with pointers dereferenced. -// Used to implement *OnUIThread methods. +// Used to implement Store, ClearDirty and Remove. void RunCacheOperationCallback(const CacheOperationCallback& callback, DriveFileError* error, const std::string& resource_id, @@ -255,7 +255,7 @@ void RunCacheOperationCallback(const CacheOperationCallback& callback, } // Runs callback with pointers dereferenced. -// Used to implement *OnUIThread methods. +// Used to implement GetFile and MarkDirty. void RunGetFileFromCacheCallback(const GetFileFromCacheCallback& callback, DriveFileError* error, FilePath* cache_file_path) { @@ -268,7 +268,7 @@ void RunGetFileFromCacheCallback(const GetFileFromCacheCallback& callback, } // Runs callback with pointers dereferenced. -// Used to implement GetResourceIdsOfBacklogOnUIThread(). +// Used to implement GetResourceIdsOfBacklog(). void RunGetResourceIdsOfBacklogCallback( const GetResourceIdsOfBacklogCallback& callback, std::vector<std::string>* to_fetch, @@ -282,10 +282,9 @@ void RunGetResourceIdsOfBacklogCallback( } // Runs callback with pointers dereferenced. -// Used to implement GetResourceIdsOfExistingPinnedFilesOnUIThread(). -void RunGetResourceIdsCallback( - const GetResourceIdsCallback& callback, - std::vector<std::string>* resource_ids) { +// Used to implement GetResourceIdsOfExistingPinnedFiles(). +void RunGetResourceIdsCallback(const GetResourceIdsCallback& callback, + std::vector<std::string>* resource_ids) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(resource_ids); @@ -294,11 +293,10 @@ void RunGetResourceIdsCallback( } // Runs callback with pointers dereferenced. -// Used to implement GetCacheEntryOnUIThread(). -void RunGetCacheEntryCallback( - const GetCacheEntryCallback& callback, - bool* success, - DriveCacheEntry* cache_entry) { +// Used to implement GetCacheEntry(). +void RunGetCacheEntryCallback(const GetCacheEntryCallback& callback, + bool* success, + DriveCacheEntry* cache_entry) { DCHECK(success); DCHECK(cache_entry); @@ -384,10 +382,9 @@ void DriveCache::RemoveObserver(DriveCacheObserver* observer) { observers_.RemoveObserver(observer); } -void DriveCache::GetCacheEntryOnUIThread( - const std::string& resource_id, - const std::string& md5, - const GetCacheEntryCallback& callback) { +void DriveCache::GetCacheEntry(const std::string& resource_id, + const std::string& md5, + const GetCacheEntryCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); bool* success = new bool(false); @@ -406,7 +403,7 @@ void DriveCache::GetCacheEntryOnUIThread( base::Owned(cache_entry))); } -void DriveCache::GetResourceIdsOfBacklogOnUIThread( +void DriveCache::GetResourceIdsOfBacklog( const GetResourceIdsOfBacklogCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -414,7 +411,7 @@ void DriveCache::GetResourceIdsOfBacklogOnUIThread( std::vector<std::string>* to_upload = new std::vector<std::string>; blocking_task_runner_->PostTaskAndReply( FROM_HERE, - base::Bind(&DriveCache::GetResourceIdsOfBacklog, + base::Bind(&DriveCache::GetResourceIdsOfBacklogOnBlockingPool, base::Unretained(this), to_fetch, to_upload), @@ -424,14 +421,14 @@ void DriveCache::GetResourceIdsOfBacklogOnUIThread( base::Owned(to_upload))); } -void DriveCache::GetResourceIdsOfExistingPinnedFilesOnUIThread( +void DriveCache::GetResourceIdsOfExistingPinnedFiles( const GetResourceIdsCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); std::vector<std::string>* resource_ids = new std::vector<std::string>; blocking_task_runner_->PostTaskAndReply( FROM_HERE, - base::Bind(&DriveCache::GetResourceIdsOfExistingPinnedFiles, + base::Bind(&DriveCache::GetResourceIdsOfExistingPinnedFilesOnBlockingPool, base::Unretained(this), resource_ids), base::Bind(&RunGetResourceIdsCallback, @@ -439,14 +436,14 @@ void DriveCache::GetResourceIdsOfExistingPinnedFilesOnUIThread( base::Owned(resource_ids))); } -void DriveCache::GetResourceIdsOfAllFilesOnUIThread( +void DriveCache::GetResourceIdsOfAllFiles( const GetResourceIdsCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); std::vector<std::string>* resource_ids = new std::vector<std::string>; blocking_task_runner_->PostTaskAndReply( FROM_HERE, - base::Bind(&DriveCache::GetResourceIdsOfAllFiles, + base::Bind(&DriveCache::GetResourceIdsOfAllFilesOnBlockingPool, base::Unretained(this), resource_ids), base::Bind(&RunGetResourceIdsCallback, @@ -454,7 +451,7 @@ void DriveCache::GetResourceIdsOfAllFilesOnUIThread( base::Owned(resource_ids))); } -bool DriveCache::FreeDiskSpaceIfNeededFor(int64 num_bytes) { +bool DriveCache::FreeDiskSpaceOnBlockingPoolIfNeededFor(int64 num_bytes) { AssertOnSequencedWorkerPool(); // Do nothing and return if we have enough space. @@ -472,16 +469,16 @@ bool DriveCache::FreeDiskSpaceIfNeededFor(int64 num_bytes) { return HasEnoughSpaceFor(num_bytes); } -void DriveCache::GetFileOnUIThread(const std::string& resource_id, - const std::string& md5, - const GetFileFromCacheCallback& callback) { +void DriveCache::GetFile(const std::string& resource_id, + const std::string& md5, + const GetFileFromCacheCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); FilePath* cache_file_path = new FilePath; blocking_task_runner_->PostTaskAndReply( FROM_HERE, - base::Bind(&DriveCache::GetFile, + base::Bind(&DriveCache::GetFileOnBlockingPool, base::Unretained(this), resource_id, md5, @@ -493,17 +490,17 @@ void DriveCache::GetFileOnUIThread(const std::string& resource_id, base::Owned(cache_file_path))); } -void DriveCache::StoreOnUIThread(const std::string& resource_id, - const std::string& md5, - const FilePath& source_path, - FileOperationType file_operation_type, - const CacheOperationCallback& callback) { +void DriveCache::Store(const std::string& resource_id, + const std::string& md5, + const FilePath& source_path, + FileOperationType file_operation_type, + const CacheOperationCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); blocking_task_runner_->PostTaskAndReply( FROM_HERE, - base::Bind(&DriveCache::Store, + base::Bind(&DriveCache::StoreOnBlockingPool, base::Unretained(this), resource_id, md5, @@ -517,15 +514,15 @@ void DriveCache::StoreOnUIThread(const std::string& resource_id, md5)); } -void DriveCache::PinOnUIThread(const std::string& resource_id, - const std::string& md5, - const CacheOperationCallback& callback) { +void DriveCache::Pin(const std::string& resource_id, + const std::string& md5, + const CacheOperationCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); blocking_task_runner_->PostTaskAndReply( FROM_HERE, - base::Bind(&DriveCache::Pin, + base::Bind(&DriveCache::PinOnBlockingPool, base::Unretained(this), resource_id, md5, @@ -539,14 +536,14 @@ void DriveCache::PinOnUIThread(const std::string& resource_id, callback)); } -void DriveCache::UnpinOnUIThread(const std::string& resource_id, - const std::string& md5, - const CacheOperationCallback& callback) { +void DriveCache::Unpin(const std::string& resource_id, + const std::string& md5, + const CacheOperationCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); blocking_task_runner_->PostTaskAndReply( FROM_HERE, - base::Bind(&DriveCache::Unpin, + base::Bind(&DriveCache::UnpinOnBlockingPool, base::Unretained(this), resource_id, md5, @@ -560,17 +557,16 @@ void DriveCache::UnpinOnUIThread(const std::string& resource_id, callback)); } -void DriveCache::SetMountedStateOnUIThread( - const FilePath& file_path, - bool to_mount, - const ChangeCacheStateCallback& callback) { +void DriveCache::SetMountedState(const FilePath& file_path, + bool to_mount, + const ChangeCacheStateCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); FilePath* cache_file_path = new FilePath; blocking_task_runner_->PostTaskAndReply( FROM_HERE, - base::Bind(&DriveCache::SetMountedState, + base::Bind(&DriveCache::SetMountedStateOnBlockingPool, base::Unretained(this), file_path, to_mount, @@ -582,16 +578,16 @@ void DriveCache::SetMountedStateOnUIThread( base::Owned(cache_file_path))); } -void DriveCache::MarkDirtyOnUIThread(const std::string& resource_id, - const std::string& md5, - const GetFileFromCacheCallback& callback) { +void DriveCache::MarkDirty(const std::string& resource_id, + const std::string& md5, + const GetFileFromCacheCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); FilePath* cache_file_path = new FilePath; blocking_task_runner_->PostTaskAndReply( FROM_HERE, - base::Bind(&DriveCache::MarkDirty, + base::Bind(&DriveCache::MarkDirtyOnBlockingPool, base::Unretained(this), resource_id, md5, @@ -604,15 +600,15 @@ void DriveCache::MarkDirtyOnUIThread(const std::string& resource_id, base::Owned(cache_file_path))); } -void DriveCache::CommitDirtyOnUIThread(const std::string& resource_id, - const std::string& md5, - const CacheOperationCallback& callback) { +void DriveCache::CommitDirty(const std::string& resource_id, + const std::string& md5, + const CacheOperationCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); blocking_task_runner_->PostTaskAndReply( FROM_HERE, - base::Bind(&DriveCache::CommitDirty, + base::Bind(&DriveCache::CommitDirtyOnBlockingPool, base::Unretained(this), resource_id, md5, @@ -626,15 +622,15 @@ void DriveCache::CommitDirtyOnUIThread(const std::string& resource_id, callback)); } -void DriveCache::ClearDirtyOnUIThread(const std::string& resource_id, - const std::string& md5, - const CacheOperationCallback& callback) { +void DriveCache::ClearDirty(const std::string& resource_id, + const std::string& md5, + const CacheOperationCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); blocking_task_runner_->PostTaskAndReply( FROM_HERE, - base::Bind(&DriveCache::ClearDirty, + base::Bind(&DriveCache::ClearDirtyOnBlockingPool, base::Unretained(this), resource_id, md5, @@ -647,14 +643,14 @@ void DriveCache::ClearDirtyOnUIThread(const std::string& resource_id, md5)); } -void DriveCache::RemoveOnUIThread(const std::string& resource_id, - const CacheOperationCallback& callback) { +void DriveCache::Remove(const std::string& resource_id, + const CacheOperationCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); blocking_task_runner_->PostTaskAndReply( FROM_HERE, - base::Bind(&DriveCache::Remove, + base::Bind(&DriveCache::RemoveOnBlockingPool, base::Unretained(this), resource_id, error), @@ -665,13 +661,13 @@ void DriveCache::RemoveOnUIThread(const std::string& resource_id, "" /* md5 */)); } -void DriveCache::ClearAllOnUIThread(const ChangeCacheStateCallback& callback) { +void DriveCache::ClearAll(const ChangeCacheStateCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); blocking_task_runner_->PostTaskAndReply( FROM_HERE, - base::Bind(&DriveCache::ClearAll, + base::Bind(&DriveCache::ClearAllOnBlockingPool, base::Unretained(this), error), base::Bind(&RunChangeCacheStateCallback, @@ -680,15 +676,14 @@ void DriveCache::ClearAllOnUIThread(const ChangeCacheStateCallback& callback) { &cache_root_path_)); } -void DriveCache::RequestInitializeOnUIThread( - const InitializeCacheCallback& callback) { +void DriveCache::RequestInitialize(const InitializeCacheCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(!callback.is_null()); bool* success = new bool(false); blocking_task_runner_->PostTaskAndReply( FROM_HERE, - base::Bind(&DriveCache::Initialize, + base::Bind(&DriveCache::InitializeOnBlockingPool, base::Unretained(this), success), base::Bind(&RunInitializeCacheCallback, @@ -696,39 +691,41 @@ void DriveCache::RequestInitializeOnUIThread( base::Owned(success))); } -void DriveCache::RequestInitializeOnUIThreadForTesting() { +void DriveCache::RequestInitializeForTesting() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); blocking_task_runner_->PostTask( FROM_HERE, - base::Bind(&DriveCache::InitializeForTesting, base::Unretained(this))); + base::Bind(&DriveCache::InitializeOnBlockingPoolForTesting, + base::Unretained(this))); } -void DriveCache::ForceRescanOnUIThreadForTesting() { +void DriveCache::ForceRescanForTesting() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); blocking_task_runner_->PostTask( FROM_HERE, - base::Bind(&DriveCache::ForceRescanForTesting, base::Unretained(this))); + base::Bind(&DriveCache::ForceRescanOnBlockingPoolForTesting, + base::Unretained(this))); } -bool DriveCache::GetCacheEntry(const std::string& resource_id, - const std::string& md5, - DriveCacheEntry* entry) { +bool DriveCache::GetCacheEntryOnBlockingPool(const std::string& resource_id, + const std::string& md5, + DriveCacheEntry* entry) { DCHECK(entry); AssertOnSequencedWorkerPool(); return metadata_->GetCacheEntry(resource_id, md5, entry); } // static -DriveCache* DriveCache::CreateDriveCacheOnUIThread( +DriveCache* DriveCache::CreateDriveCache( const FilePath& cache_root_path, base::SequencedTaskRunner* blocking_task_runner) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); return new DriveCache(cache_root_path, blocking_task_runner); } -void DriveCache::DestroyOnUIThread() { +void DriveCache::Destroy() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // Invalidate the weak pointer. @@ -737,11 +734,11 @@ void DriveCache::DestroyOnUIThread() { // Destroy myself on the blocking pool. blocking_task_runner_->PostTask( FROM_HERE, - base::Bind(&DriveCache::Destroy, + base::Bind(&DriveCache::DestroyOnBlockingPool, base::Unretained(this))); } -void DriveCache::Initialize(bool* success) { +void DriveCache::InitializeOnBlockingPool(bool* success) { AssertOnSequencedWorkerPool(); DCHECK(success); @@ -755,7 +752,7 @@ void DriveCache::Initialize(bool* success) { *success = metadata_->Initialize(cache_paths_); } -void DriveCache::InitializeForTesting() { +void DriveCache::InitializeOnBlockingPoolForTesting() { AssertOnSequencedWorkerPool(); InitCachePaths(cache_paths_); @@ -764,17 +761,17 @@ void DriveCache::InitializeForTesting() { metadata_->Initialize(cache_paths_); } -void DriveCache::Destroy() { +void DriveCache::DestroyOnBlockingPool() { AssertOnSequencedWorkerPool(); delete this; } -void DriveCache::ForceRescanForTesting() { +void DriveCache::ForceRescanOnBlockingPoolForTesting() { AssertOnSequencedWorkerPool(); metadata_->ForceRescanForTesting(cache_paths_); } -void DriveCache::GetResourceIdsOfBacklog( +void DriveCache::GetResourceIdsOfBacklogOnBlockingPool( std::vector<std::string>* to_fetch, std::vector<std::string>* to_upload) { AssertOnSequencedWorkerPool(); @@ -784,7 +781,7 @@ void DriveCache::GetResourceIdsOfBacklog( metadata_->Iterate(base::Bind(&CollectBacklog, to_fetch, to_upload)); } -void DriveCache::GetResourceIdsOfExistingPinnedFiles( +void DriveCache::GetResourceIdsOfExistingPinnedFilesOnBlockingPool( std::vector<std::string>* resource_ids) { AssertOnSequencedWorkerPool(); DCHECK(resource_ids); @@ -792,7 +789,7 @@ void DriveCache::GetResourceIdsOfExistingPinnedFiles( metadata_->Iterate(base::Bind(&CollectExistingPinnedFile, resource_ids)); } -void DriveCache::GetResourceIdsOfAllFiles( +void DriveCache::GetResourceIdsOfAllFilesOnBlockingPool( std::vector<std::string>* resource_ids) { AssertOnSequencedWorkerPool(); DCHECK(resource_ids); @@ -800,16 +797,16 @@ void DriveCache::GetResourceIdsOfAllFiles( metadata_->Iterate(base::Bind(&CollectAnyFile, resource_ids)); } -void DriveCache::GetFile(const std::string& resource_id, - const std::string& md5, - DriveFileError* error, - FilePath* cache_file_path) { +void DriveCache::GetFileOnBlockingPool(const std::string& resource_id, + const std::string& md5, + DriveFileError* error, + FilePath* cache_file_path) { AssertOnSequencedWorkerPool(); DCHECK(error); DCHECK(cache_file_path); DriveCacheEntry cache_entry; - if (GetCacheEntry(resource_id, md5, &cache_entry) && + if (GetCacheEntryOnBlockingPool(resource_id, md5, &cache_entry) && cache_entry.is_present()) { CachedFileOrigin file_origin; if (cache_entry.is_mounted()) { @@ -830,11 +827,11 @@ void DriveCache::GetFile(const std::string& resource_id, } } -void DriveCache::Store(const std::string& resource_id, - const std::string& md5, - const FilePath& source_path, - FileOperationType file_operation_type, - DriveFileError* error) { +void DriveCache::StoreOnBlockingPool(const std::string& resource_id, + const std::string& md5, + const FilePath& source_path, + FileOperationType file_operation_type, + DriveFileError* error) { AssertOnSequencedWorkerPool(); DCHECK(error); @@ -846,7 +843,7 @@ void DriveCache::Store(const std::string& resource_id, return; } - const bool enough_space = FreeDiskSpaceIfNeededFor(file_size); + const bool enough_space = FreeDiskSpaceOnBlockingPoolIfNeededFor(file_size); if (!enough_space) { *error = DRIVE_FILE_ERROR_NO_SPACE; return; @@ -860,7 +857,8 @@ void DriveCache::Store(const std::string& resource_id, // If file was previously pinned, store it in persistent dir and create // symlink in pinned dir. DriveCacheEntry cache_entry; - if (GetCacheEntry(resource_id, md5, &cache_entry)) { // File exists in cache. + if (GetCacheEntryOnBlockingPool(resource_id, md5, &cache_entry)) { + // File exists in cache. // If file is dirty or mounted, return error. if (cache_entry.is_dirty() || cache_entry.is_mounted()) { LOG(WARNING) << "Can't store a file to replace a " @@ -926,10 +924,10 @@ void DriveCache::Store(const std::string& resource_id, } } -void DriveCache::Pin(const std::string& resource_id, - const std::string& md5, - FileOperationType file_operation_type, - DriveFileError* error) { +void DriveCache::PinOnBlockingPool(const std::string& resource_id, + const std::string& md5, + FileOperationType file_operation_type, + DriveFileError* error) { AssertOnSequencedWorkerPool(); DCHECK(error); @@ -940,7 +938,7 @@ void DriveCache::Pin(const std::string& resource_id, CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; DriveCacheEntry cache_entry; - if (!GetCacheEntry(resource_id, md5, &cache_entry)) { + if (!GetCacheEntryOnBlockingPool(resource_id, md5, &cache_entry)) { // Entry does not exist in cache. // Set both |dest_path| and |source_path| to /dev/null, so that: // 1) ModifyCacheState won't move files when |source_path| and |dest_path| @@ -1013,16 +1011,16 @@ void DriveCache::Pin(const std::string& resource_id, } } -void DriveCache::Unpin(const std::string& resource_id, - const std::string& md5, - FileOperationType file_operation_type, - DriveFileError* error) { +void DriveCache::UnpinOnBlockingPool(const std::string& resource_id, + const std::string& md5, + FileOperationType file_operation_type, + DriveFileError* error) { AssertOnSequencedWorkerPool(); DCHECK(error); // Unpinning a file means its entry must exist in cache. DriveCacheEntry cache_entry; - if (!GetCacheEntry(resource_id, md5, &cache_entry)) { + if (!GetCacheEntryOnBlockingPool(resource_id, md5, &cache_entry)) { LOG(WARNING) << "Can't unpin a file that wasn't pinned or cached: res_id=" << resource_id << ", md5=" << md5; @@ -1098,10 +1096,10 @@ void DriveCache::Unpin(const std::string& resource_id, } } -void DriveCache::SetMountedState(const FilePath& file_path, - bool to_mount, - DriveFileError *error, - FilePath* cache_file_path) { +void DriveCache::SetMountedStateOnBlockingPool(const FilePath& file_path, + bool to_mount, + DriveFileError *error, + FilePath* cache_file_path) { AssertOnSequencedWorkerPool(); DCHECK(error); DCHECK(cache_file_path); @@ -1116,7 +1114,7 @@ void DriveCache::SetMountedState(const FilePath& file_path, // Get cache entry associated with the resource_id and md5 DriveCacheEntry cache_entry; - if (!GetCacheEntry(resource_id, md5, &cache_entry)) { + if (!GetCacheEntryOnBlockingPool(resource_id, md5, &cache_entry)) { *error = DRIVE_FILE_ERROR_NOT_FOUND; return; } @@ -1162,11 +1160,11 @@ void DriveCache::SetMountedState(const FilePath& file_path, } } -void DriveCache::MarkDirty(const std::string& resource_id, - const std::string& md5, - FileOperationType file_operation_type, - DriveFileError* error, - FilePath* cache_file_path) { +void DriveCache::MarkDirtyOnBlockingPool(const std::string& resource_id, + const std::string& md5, + FileOperationType file_operation_type, + DriveFileError* error, + FilePath* cache_file_path) { AssertOnSequencedWorkerPool(); DCHECK(error); DCHECK(cache_file_path); @@ -1179,7 +1177,7 @@ void DriveCache::MarkDirty(const std::string& resource_id, // Marking a file dirty means its entry and actual file blob must exist in // cache. DriveCacheEntry cache_entry; - if (!GetCacheEntry(resource_id, std::string(), &cache_entry) || + if (!GetCacheEntryOnBlockingPool(resource_id, std::string(), &cache_entry) || !cache_entry.is_present()) { LOG(WARNING) << "Can't mark dirty a file that wasn't cached: res_id=" << resource_id @@ -1267,10 +1265,11 @@ void DriveCache::MarkDirty(const std::string& resource_id, } } -void DriveCache::CommitDirty(const std::string& resource_id, - const std::string& md5, - FileOperationType file_operation_type, - DriveFileError* error) { +void DriveCache::CommitDirtyOnBlockingPool( + const std::string& resource_id, + const std::string& md5, + FileOperationType file_operation_type, + DriveFileError* error) { AssertOnSequencedWorkerPool(); DCHECK(error); @@ -1282,7 +1281,7 @@ void DriveCache::CommitDirty(const std::string& resource_id, // Committing a file dirty means its entry and actual file blob must exist in // cache. DriveCacheEntry cache_entry; - if (!GetCacheEntry(resource_id, std::string(), &cache_entry) || + if (!GetCacheEntryOnBlockingPool(resource_id, std::string(), &cache_entry) || !cache_entry.is_present()) { LOG(WARNING) << "Can't commit dirty a file that wasn't cached: res_id=" << resource_id @@ -1326,10 +1325,10 @@ void DriveCache::CommitDirty(const std::string& resource_id, true /* create symlink */); } -void DriveCache::ClearDirty(const std::string& resource_id, - const std::string& md5, - FileOperationType file_operation_type, - DriveFileError* error) { +void DriveCache::ClearDirtyOnBlockingPool(const std::string& resource_id, + const std::string& md5, + FileOperationType file_operation_type, + DriveFileError* error) { AssertOnSequencedWorkerPool(); DCHECK(error); @@ -1339,7 +1338,7 @@ void DriveCache::ClearDirty(const std::string& resource_id, // Clearing a dirty file means its entry and actual file blob must exist in // cache. - if (!GetCacheEntry(resource_id, std::string(), &cache_entry) || + if (!GetCacheEntryOnBlockingPool(resource_id, std::string(), &cache_entry) || !cache_entry.is_present()) { LOG(WARNING) << "Can't clear dirty state of a file that wasn't cached: " << "res_id=" << resource_id @@ -1415,8 +1414,8 @@ void DriveCache::ClearDirty(const std::string& resource_id, } } -void DriveCache::Remove(const std::string& resource_id, - DriveFileError* error) { +void DriveCache::RemoveOnBlockingPool(const std::string& resource_id, + DriveFileError* error) { AssertOnSequencedWorkerPool(); DCHECK(error); @@ -1427,7 +1426,7 @@ void DriveCache::Remove(const std::string& resource_id, // If entry doesn't exist or is dirty or mounted in cache, nothing to do. const bool entry_found = - GetCacheEntry(resource_id, std::string(), &cache_entry); + GetCacheEntryOnBlockingPool(resource_id, std::string(), &cache_entry); if (!entry_found || cache_entry.is_dirty() || cache_entry.is_mounted()) { DVLOG(1) << "Entry is " << (entry_found ? @@ -1478,7 +1477,7 @@ void DriveCache::Remove(const std::string& resource_id, *error = DRIVE_FILE_OK; } -void DriveCache::ClearAll(DriveFileError* error) { +void DriveCache::ClearAllOnBlockingPool(DriveFileError* error) { AssertOnSequencedWorkerPool(); DCHECK(error); @@ -1489,7 +1488,7 @@ void DriveCache::ClearAll(DriveFileError* error) { return; } - Initialize(&success); + InitializeOnBlockingPool(&success); if (!success) { LOG(WARNING) << "Failed to initialize the cache"; *error = DRIVE_FILE_ERROR_FAILED; @@ -1535,8 +1534,10 @@ void DriveCache::OnUnpinned(DriveFileError* error, // It's a chance to free up space if needed. blocking_task_runner_->PostTask( FROM_HERE, - base::Bind(base::IgnoreResult(&DriveCache::FreeDiskSpaceIfNeededFor), - base::Unretained(this), 0)); + base::Bind( + base::IgnoreResult( + &DriveCache::FreeDiskSpaceOnBlockingPoolIfNeededFor), + base::Unretained(this), 0)); } void DriveCache::OnCommitDirty(DriveFileError* error, @@ -1563,7 +1564,7 @@ void DriveCache::GetCacheEntryHelper(const std::string& resource_id, DCHECK(success); DCHECK(cache_entry); - *success = GetCacheEntry(resource_id, md5, cache_entry); + *success = GetCacheEntryOnBlockingPool(resource_id, md5, cache_entry); } // static diff --git a/chrome/browser/chromeos/drive/drive_cache.h b/chrome/browser/chromeos/drive/drive_cache.h index 69575e8..2f0d318 100644 --- a/chrome/browser/chromeos/drive/drive_cache.h +++ b/chrome/browser/chromeos/drive/drive_cache.h @@ -29,7 +29,7 @@ class DriveCacheEntry; class DriveCacheMetadata; class DriveCacheObserver; -// Callback for SetMountedStateOnUIThread and ClearAllOnUIThread. +// Callback for SetMountedState and ClearAll. typedef base::Callback<void(DriveFileError error, const FilePath& file_path)> ChangeCacheStateCallback; @@ -44,25 +44,25 @@ typedef base::Callback<void(DriveFileError error, const FilePath& cache_file_path)> GetFileFromCacheCallback; -// Callback for GetResourceIdsOfBacklogOnUIThread. +// Callback for GetResourceIdsOfBacklog. // |to_fetch| is for resource IDs of pinned-but-not-fetched files. // |to_upload| is for resource IDs of dirty-but-not-uploaded files. typedef base::Callback<void(const std::vector<std::string>& to_fetch, const std::vector<std::string>& to_upload)> GetResourceIdsOfBacklogCallback; -// Callback for GetResourceIdsOfExistingPinnedFilesOnUIThread. +// Callback for GetResourceIdsOfExistingPinnedFiles. typedef base::Callback<void(const std::vector<std::string>& resource_ids)> GetResourceIdsCallback; -// Callback for GetCacheEntryOnUIThread. +// Callback for GetCacheEntry. // |success| indicates if the operation was successful. // |cache_entry| is the obtained cache entry. On failure, |cache_state| is // set to TEST_CACHE_STATE_NONE. typedef base::Callback<void(bool success, const DriveCacheEntry& cache_entry)> GetCacheEntryCallback; -// Callback for RequestInitializeOnUIThread. +// Callback for RequestInitialize. // |success| indicates if the operation was successful. // TODO(satorux): Change this to DriveFileError when it becomes necessary. typedef base::Callback<void(bool success)> @@ -71,12 +71,7 @@ typedef base::Callback<void(bool success)> // DriveCache is used to maintain cache states of DriveFileSystem. // // All non-static public member functions, unless mentioned otherwise (see -// GetCacheFilePath() for example), should be called from the sequenced -// worker pool with the sequence token set by CreateDriveCacheOnUIThread(). This -// threading model is enforced by AssertOnSequencedWorkerPool(). -// -// TODO(hashimoto): Change threading model of this class to make public methods -// being called on UI thread unless mentioned otherwise. crbug.com/132926 +// GetCacheFilePath() for example), should be called from the UI thread. class DriveCache { public: // Enum defining GCache subdirectory location. @@ -131,51 +126,42 @@ class DriveCache { bool IsUnderDriveCacheDirectory(const FilePath& path) const; // Adds observer. - // Must be called on UI thread. void AddObserver(DriveCacheObserver* observer); // Removes observer. - // Must be called on UI thread. void RemoveObserver(DriveCacheObserver* observer); - // Gets the cache entry by the given resource ID and MD5. - // See also GetCacheEntry(). - // - // Must be called on UI thread. |callback| is run on UI thread. - void GetCacheEntryOnUIThread( - const std::string& resource_id, - const std::string& md5, - const GetCacheEntryCallback& callback); + // Gets the cache entry for file corresponding to |resource_id| and |md5| + // and runs |callabck| with true and the entry found if entry exists in cache + // map. Otherwise, runs |callback| with false. + // |md5| can be empty if only matching |resource_id| is desired, which may + // happen when looking for pinned entries where symlinks' filenames have no + // extension and hence no md5. + void GetCacheEntry(const std::string& resource_id, + const std::string& md5, + const GetCacheEntryCallback& callback); // Gets the resource IDs of pinned-but-not-fetched files and // dirty-but-not-uploaded files. - // - // Must be called on UI thread. |callback| is run on UI thread. - void GetResourceIdsOfBacklogOnUIThread( - const GetResourceIdsOfBacklogCallback& callback); + void GetResourceIdsOfBacklog(const GetResourceIdsOfBacklogCallback& callback); // Gets the resource IDs of all existing (i.e. cached locally) pinned // files, including pinned dirty files. - // - // Must be called on UI thread. |callback| is run on UI thread. - void GetResourceIdsOfExistingPinnedFilesOnUIThread( + void GetResourceIdsOfExistingPinnedFiles( const GetResourceIdsCallback& callback); // Gets the resource IDs of all files in the cache. - // - // Must be called on UI thread. |callback| is run on UI thread. - void GetResourceIdsOfAllFilesOnUIThread( - const GetResourceIdsCallback& callback); + void GetResourceIdsOfAllFiles(const GetResourceIdsCallback& callback); // Frees up disk space to store the given number of bytes, while keeping // kMinFreeSpace bytes on the disk, if needed. // Returns true when we successfully manage to have enough space. - bool FreeDiskSpaceIfNeededFor(int64 num_bytes); + bool FreeDiskSpaceOnBlockingPoolIfNeededFor(int64 num_bytes); // Checks if file corresponding to |resource_id| and |md5| exists in cache. - void GetFileOnUIThread(const std::string& resource_id, - const std::string& md5, - const GetFileFromCacheCallback& callback); + void GetFile(const std::string& resource_id, + const std::string& md5, + const GetFileFromCacheCallback& callback); // Modifies cache state, which involves the following: // - moves or copies (per |file_operation_type|) |source_path| @@ -183,27 +169,27 @@ class DriveCache { // - if necessary, creates symlink // - deletes stale cached versions of |resource_id| in // |dest_path|'s directory. - void StoreOnUIThread(const std::string& resource_id, - const std::string& md5, - const FilePath& source_path, - FileOperationType file_operation_type, - const CacheOperationCallback& callback); + void Store(const std::string& resource_id, + const std::string& md5, + const FilePath& source_path, + FileOperationType file_operation_type, + const CacheOperationCallback& callback); // Modifies cache state, which involves the following: // - moves |source_path| to |dest_path| in persistent dir if // file is not dirty // - creates symlink in pinned dir that references downloaded or locally // modified file - void PinOnUIThread(const std::string& resource_id, - const std::string& md5, - const CacheOperationCallback& callback); + void Pin(const std::string& resource_id, + const std::string& md5, + const CacheOperationCallback& callback); // Modifies cache state, which involves the following: // - moves |source_path| to |dest_path| in tmp dir if file is not dirty // - deletes symlink from pinned dir - void UnpinOnUIThread(const std::string& resource_id, - const std::string& md5, - const CacheOperationCallback& callback); + void Unpin(const std::string& resource_id, + const std::string& md5, + const CacheOperationCallback& callback); // Modifies cache state, which involves the following: // - moves |source_path| to |dest_path|, where @@ -212,23 +198,23 @@ class DriveCache { // and has .<md5>.mounted extension; // if we're unmounting: the opposite is true for the two paths, i.e. // |dest_path| is the mounted path and |source_path| the unmounted path. - void SetMountedStateOnUIThread(const FilePath& file_path, - bool to_mount, - const ChangeCacheStateCallback& callback); + void SetMountedState(const FilePath& file_path, + bool to_mount, + const ChangeCacheStateCallback& callback); // Modifies cache state, which involves the following: // - moves |source_path| to |dest_path| in persistent dir, where // |source_path| has .<md5> extension and |dest_path| has .local extension // - if file is pinned, updates symlink in pinned dir to reference dirty file - void MarkDirtyOnUIThread(const std::string& resource_id, - const std::string& md5, - const GetFileFromCacheCallback& callback); + void MarkDirty(const std::string& resource_id, + const std::string& md5, + const GetFileFromCacheCallback& callback); // Modifies cache state, i.e. creates symlink in outgoing // dir to reference dirty file in persistent dir. - void CommitDirtyOnUIThread(const std::string& resource_id, - const std::string& md5, - const CacheOperationCallback& callback); + void CommitDirty(const std::string& resource_id, + const std::string& md5, + const CacheOperationCallback& callback); // Modifies cache state, which involves the following: // - moves |source_path| to |dest_path| in persistent dir if @@ -237,42 +223,38 @@ class DriveCache { // - deletes symlink in outgoing dir // - if file is pinned, updates symlink in pinned dir to reference // |dest_path| - void ClearDirtyOnUIThread(const std::string& resource_id, - const std::string& md5, - const CacheOperationCallback& callback); + void ClearDirty(const std::string& resource_id, + const std::string& md5, + const CacheOperationCallback& callback); // Does the following: // - remove all delete stale cache versions corresponding to |resource_id| in // persistent, tmp and pinned directories // - remove entry corresponding to |resource_id| from cache map. - void RemoveOnUIThread(const std::string& resource_id, - const CacheOperationCallback& callback); + void Remove(const std::string& resource_id, + const CacheOperationCallback& callback); // Does the following: // - remove all the files in the cache directory. // - re-create the |metadata_| instance. - void ClearAllOnUIThread(const ChangeCacheStateCallback& callback); + void ClearAll(const ChangeCacheStateCallback& callback); // Utility method to call Initialize on UI thread. |callback| is called on // UI thread when the initialization is complete. // |callback| must not be null. - void RequestInitializeOnUIThread( - const InitializeCacheCallback& callback); + void RequestInitialize(const InitializeCacheCallback& callback); // Utility method to call InitializeForTesting on UI thread. - void RequestInitializeOnUIThreadForTesting(); + void RequestInitializeForTesting(); // Force a rescan of cache files, for testing. - void ForceRescanOnUIThreadForTesting(); + void ForceRescanForTesting(); - // Gets the cache entry for file corresponding to |resource_id| and |md5| - // and returns true if entry exists in cache map. Otherwise, returns false. - // |md5| can be empty if only matching |resource_id| is desired, which may - // happen when looking for pinned entries where symlinks' filenames have no - // extension and hence no md5. - bool GetCacheEntry(const std::string& resource_id, - const std::string& md5, - DriveCacheEntry* entry); + // Gets the cache entry by the given resource ID and MD5. + // See also GetCacheEntry(). + bool GetCacheEntryOnBlockingPool(const std::string& resource_id, + const std::string& md5, + DriveCacheEntry* entry); // Factory methods for DriveCache. // |pool| and |sequence_token| are used to assert that the functions are @@ -280,12 +262,12 @@ class DriveCache { // // For testing, the thread assertion can be disabled by passing NULL and // the default value of SequenceToken. - static DriveCache* CreateDriveCacheOnUIThread( + static DriveCache* CreateDriveCache( const FilePath& cache_root_path, base::SequencedTaskRunner* blocking_task_runner); // Deletes the cache. - void DestroyOnUIThread(); + void Destroy(); // Gets the cache root path (i.e. <user_profile_dir>/GCache/v1) from the // profile. @@ -317,87 +299,87 @@ class DriveCache { void AssertOnSequencedWorkerPool(); // Initializes the cache. The result will be stored in |success|. - void Initialize(bool* success); + void InitializeOnBlockingPool(bool* success); // Initializes the cache with in-memory cache for testing. // The in-memory cache is used since it's faster than the db. - void InitializeForTesting(); + void InitializeOnBlockingPoolForTesting(); // Deletes the cache. - void Destroy(); + void DestroyOnBlockingPool(); // Force a rescan of cache directories. - void ForceRescanForTesting(); + void ForceRescanOnBlockingPoolForTesting(); - // Used to implement GetResourceIdsOfBacklogOnUIThread. - void GetResourceIdsOfBacklog( + // Used to implement GetResourceIdsOfBacklog. + void GetResourceIdsOfBacklogOnBlockingPool( std::vector<std::string>* to_fetch, std::vector<std::string>* to_upload); - // Used to implement GetResourceIdsOfExistingPinnedFilesOnUIThread. - void GetResourceIdsOfExistingPinnedFiles( + // Used to implement GetResourceIdsOfExistingPinnedFiles. + void GetResourceIdsOfExistingPinnedFilesOnBlockingPool( std::vector<std::string>* resource_ids); - // Used to implement GetResourceIdsOfAllFilesOnUIThread. - void GetResourceIdsOfAllFiles( + // Used to implement GetResourceIdsOfAllFiles. + void GetResourceIdsOfAllFilesOnBlockingPool( std::vector<std::string>* resource_ids); - // Used to implement GetFileOnUIThread. - void GetFile(const std::string& resource_id, - const std::string& md5, - DriveFileError* error, - FilePath* cache_file_path); - - // Used to implement StoreOnUIThread. - void Store(const std::string& resource_id, - const std::string& md5, - const FilePath& source_path, - FileOperationType file_operation_type, - DriveFileError* error); - - // Used to implement PinOnUIThread. - void Pin(const std::string& resource_id, - const std::string& md5, - FileOperationType file_operation_type, - DriveFileError* error); - - // Used to implement UnpinOnUIThread. - void Unpin(const std::string& resource_id, - const std::string& md5, - FileOperationType file_operation_type, - DriveFileError* error); - - // Used to implement SetMountedStateOnUIThread. - void SetMountedState(const FilePath& file_path, - bool to_mount, - DriveFileError* error, - FilePath* cache_file_path); - - // Used to implement MarkDirtyOnUIThread. - void MarkDirty(const std::string& resource_id, - const std::string& md5, - FileOperationType file_operation_type, - DriveFileError* error, - FilePath* cache_file_path); - - // Used to implement CommitDirtyOnUIThread. - void CommitDirty(const std::string& resource_id, - const std::string& md5, - FileOperationType file_operation_type, - DriveFileError* error); + // Used to implement GetFile. + void GetFileOnBlockingPool(const std::string& resource_id, + const std::string& md5, + DriveFileError* error, + FilePath* cache_file_path); - // Used to implement ClearDirtyOnUIThread. - void ClearDirty(const std::string& resource_id, - const std::string& md5, - FileOperationType file_operation_type, - DriveFileError* error); + // Used to implement Store. + void StoreOnBlockingPool(const std::string& resource_id, + const std::string& md5, + const FilePath& source_path, + FileOperationType file_operation_type, + DriveFileError* error); - // Used to implement RemoveOnUIThread. - void Remove(const std::string& resource_id, - DriveFileError* error); + // Used to implement Pin. + void PinOnBlockingPool(const std::string& resource_id, + const std::string& md5, + FileOperationType file_operation_type, + DriveFileError* error); - // Used to implement ClearAllUIThread. - void ClearAll(DriveFileError* error); + // Used to implement Unpin. + void UnpinOnBlockingPool(const std::string& resource_id, + const std::string& md5, + FileOperationType file_operation_type, + DriveFileError* error); + + // Used to implement SetMountedState. + void SetMountedStateOnBlockingPool(const FilePath& file_path, + bool to_mount, + DriveFileError* error, + FilePath* cache_file_path); + + // Used to implement MarkDirty. + void MarkDirtyOnBlockingPool(const std::string& resource_id, + const std::string& md5, + FileOperationType file_operation_type, + DriveFileError* error, + FilePath* cache_file_path); + + // Used to implement CommitDirty. + void CommitDirtyOnBlockingPool(const std::string& resource_id, + const std::string& md5, + FileOperationType file_operation_type, + DriveFileError* error); + + // Used to implement ClearDirty. + void ClearDirtyOnBlockingPool(const std::string& resource_id, + const std::string& md5, + FileOperationType file_operation_type, + DriveFileError* error); + + // Used to implement Remove. + void RemoveOnBlockingPool(const std::string& resource_id, + DriveFileError* error); + + // Used to implement ClearAll. + void ClearAllOnBlockingPool(DriveFileError* error); // Runs callback and notifies the observers when file is pinned. void OnPinned(DriveFileError* error, @@ -417,7 +399,7 @@ class DriveCache { const std::string& md5, const CacheOperationCallback& callback); - // Helper function to implement GetCacheEntryOnUIThread(). + // Helper function to implement GetCacheEntry(). void GetCacheEntryHelper(const std::string& resource_id, const std::string& md5, bool* success, @@ -460,8 +442,7 @@ class FreeDiskSpaceGetterInterface { // Sets the free disk space getter for testing. // The existing getter is deleted. -void SetFreeDiskSpaceGetterForTesting( - FreeDiskSpaceGetterInterface* getter); +void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter); } // namespace drive diff --git a/chrome/browser/chromeos/drive/drive_cache_unittest.cc b/chrome/browser/chromeos/drive/drive_cache_unittest.cc index 96ecd78..d3ea9a9 100644 --- a/chrome/browser/chromeos/drive/drive_cache_unittest.cc +++ b/chrome/browser/chromeos/drive/drive_cache_unittest.cc @@ -115,7 +115,7 @@ void OnGetResourceIds(std::vector<std::string>* out_resource_ids, *out_resource_ids = resource_ids; } -// Copies results from ClearAllOnUIThread. +// Copies results from ClearAll. void OnClearAll(DriveFileError* out_error, FilePath* out_file_path, DriveFileError error, @@ -153,14 +153,14 @@ class DriveCacheTest : public testing::Test { content::BrowserThread::GetBlockingPool(); blocking_task_runner_ = pool->GetSequencedTaskRunner(pool->GetSequenceToken()); - cache_ = DriveCache::CreateDriveCacheOnUIThread( + cache_ = DriveCache::CreateDriveCache( DriveCache::GetCacheRootPath(profile_.get()), blocking_task_runner_); mock_cache_observer_.reset(new StrictMock<MockDriveCacheObserver>); cache_->AddObserver(mock_cache_observer_.get()); bool initialization_success = false; - cache_->RequestInitializeOnUIThread( + cache_->RequestInitialize( base::Bind(&test_util::CopyResultFromInitializeCacheCallback, &initialization_success)); google_apis::test_util::RunBlockingPoolTask(); @@ -169,7 +169,7 @@ class DriveCacheTest : public testing::Test { virtual void TearDown() OVERRIDE { SetFreeDiskSpaceGetterForTesting(NULL); - cache_->DestroyOnUIThread(); + cache_->Destroy(); // The cache destruction requires to post a task to the blocking pool. google_apis::test_util::RunBlockingPoolTask(); @@ -241,7 +241,7 @@ class DriveCacheTest : public testing::Test { } DVLOG(1) << "PrepareForInitCacheTest finished"; - cache_->ForceRescanOnUIThreadForTesting(); + cache_->ForceRescanForTesting(); google_apis::test_util::RunBlockingPoolTask(); } @@ -282,13 +282,10 @@ class DriveCacheTest : public testing::Test { expected_error_ = expected_error; expected_file_extension_ = expected_file_extension; - cache_->GetFileOnUIThread( - resource_id, - md5, - base::Bind(&DriveCacheTest::VerifyGetFromCache, - base::Unretained(this), - resource_id, - md5)); + cache_->GetFile(resource_id, md5, + base::Bind(&DriveCacheTest::VerifyGetFromCache, + base::Unretained(this), + resource_id, md5)); google_apis::test_util::RunBlockingPoolTask(); } @@ -304,11 +301,10 @@ class DriveCacheTest : public testing::Test { expected_cache_state_ = expected_cache_state; expected_sub_dir_type_ = expected_sub_dir_type; - cache_->StoreOnUIThread( - resource_id, md5, source_path, - DriveCache::FILE_OPERATION_COPY, - base::Bind(&DriveCacheTest::VerifyCacheFileState, - base::Unretained(this))); + cache_->Store(resource_id, md5, source_path, + DriveCache::FILE_OPERATION_COPY, + base::Bind(&DriveCacheTest::VerifyCacheFileState, + base::Unretained(this))); google_apis::test_util::RunBlockingPoolTask(); } @@ -339,10 +335,9 @@ class DriveCacheTest : public testing::Test { DriveFileError expected_error) { expected_error_ = expected_error; - cache_->RemoveOnUIThread( - resource_id, - base::Bind(&DriveCacheTest::VerifyRemoveFromCache, - base::Unretained(this))); + cache_->Remove(resource_id, + base::Bind(&DriveCacheTest::VerifyRemoveFromCache, + base::Unretained(this))); google_apis::test_util::RunBlockingPoolTask(); } @@ -452,10 +447,9 @@ class DriveCacheTest : public testing::Test { expected_cache_state_ = expected_cache_state; expected_sub_dir_type_ = expected_sub_dir_type; - cache_->PinOnUIThread( - resource_id, md5, - base::Bind(&DriveCacheTest::VerifyCacheFileState, - base::Unretained(this))); + cache_->Pin(resource_id, md5, + base::Bind(&DriveCacheTest::VerifyCacheFileState, + base::Unretained(this))); google_apis::test_util::RunBlockingPoolTask(); } @@ -470,10 +464,9 @@ class DriveCacheTest : public testing::Test { expected_cache_state_ = expected_cache_state; expected_sub_dir_type_ = expected_sub_dir_type; - cache_->UnpinOnUIThread( - resource_id, md5, - base::Bind(&DriveCacheTest::VerifyCacheFileState, - base::Unretained(this))); + cache_->Unpin(resource_id, md5, + base::Bind(&DriveCacheTest::VerifyCacheFileState, + base::Unretained(this))); google_apis::test_util::RunBlockingPoolTask(); } @@ -489,13 +482,10 @@ class DriveCacheTest : public testing::Test { expected_sub_dir_type_ = expected_sub_dir_type; expect_outgoing_symlink_ = false; - cache_->MarkDirtyOnUIThread( - resource_id, - md5, - base::Bind(&DriveCacheTest::VerifyMarkDirty, - base::Unretained(this), - resource_id, - md5)); + cache_->MarkDirty(resource_id, md5, + base::Bind(&DriveCacheTest::VerifyMarkDirty, + base::Unretained(this), + resource_id, md5)); google_apis::test_util::RunBlockingPoolTask(); } @@ -529,10 +519,9 @@ class DriveCacheTest : public testing::Test { expected_sub_dir_type_ = expected_sub_dir_type; expect_outgoing_symlink_ = true; - cache_->CommitDirtyOnUIThread( - resource_id, md5, - base::Bind(&DriveCacheTest::VerifyCacheFileState, - base::Unretained(this))); + cache_->CommitDirty(resource_id, md5, + base::Bind(&DriveCacheTest::VerifyCacheFileState, + base::Unretained(this))); google_apis::test_util::RunBlockingPoolTask(); } @@ -548,9 +537,9 @@ class DriveCacheTest : public testing::Test { expected_sub_dir_type_ = expected_sub_dir_type; expect_outgoing_symlink_ = false; - cache_->ClearDirtyOnUIThread(resource_id, md5, - base::Bind(&DriveCacheTest::VerifyCacheFileState, - base::Unretained(this))); + cache_->ClearDirty(resource_id, md5, + base::Bind(&DriveCacheTest::VerifyCacheFileState, + base::Unretained(this))); google_apis::test_util::RunBlockingPoolTask(); } @@ -568,9 +557,10 @@ class DriveCacheTest : public testing::Test { expected_sub_dir_type_ = expected_sub_dir_type; expect_outgoing_symlink_ = false; - cache_->SetMountedStateOnUIThread(file_path, to_mount, - base::Bind(&DriveCacheTest::VerifySetMountedState, - base::Unretained(this), resource_id, md5, to_mount)); + cache_->SetMountedState(file_path, to_mount, + base::Bind(&DriveCacheTest::VerifySetMountedState, + base::Unretained(this), + resource_id, md5, to_mount)); google_apis::test_util::RunBlockingPoolTask(); } @@ -703,7 +693,8 @@ class DriveCacheTest : public testing::Test { const std::string& md5, DriveCacheEntry* cache_entry, bool* result) { - *result = cache_->GetCacheEntry(resource_id, md5, cache_entry); + *result = + cache_->GetCacheEntryOnBlockingPool(resource_id, md5, cache_entry); } // Returns true if the cache entry exists for the given resource ID and MD5. @@ -1497,12 +1488,12 @@ TEST_F(DriveCacheTest, MountUnmount) { EXPECT_EQ(1, num_callback_invocations_); } -TEST_F(DriveCacheTest, GetResourceIdsOfBacklogOnUIThread) { +TEST_F(DriveCacheTest, GetResourceIdsOfBacklog) { PrepareForInitCacheTest(); std::vector<std::string> to_fetch; std::vector<std::string> to_upload; - cache_->GetResourceIdsOfBacklogOnUIThread( + cache_->GetResourceIdsOfBacklog( base::Bind(&OnGetResourceIdsOfBacklog, &to_fetch, &to_upload)); google_apis::test_util::RunBlockingPoolTask(); @@ -1516,11 +1507,11 @@ TEST_F(DriveCacheTest, GetResourceIdsOfBacklogOnUIThread) { EXPECT_EQ("dirty_and_pinned:existing", to_upload[1]); } -TEST_F(DriveCacheTest, GetResourceIdsOfExistingPinnedFilesOnUIThread) { +TEST_F(DriveCacheTest, GetResourceIdsOfExistingPinnedFiles) { PrepareForInitCacheTest(); std::vector<std::string> resource_ids; - cache_->GetResourceIdsOfExistingPinnedFilesOnUIThread( + cache_->GetResourceIdsOfExistingPinnedFiles( base::Bind(&OnGetResourceIds, &resource_ids)); google_apis::test_util::RunBlockingPoolTask(); @@ -1530,11 +1521,11 @@ TEST_F(DriveCacheTest, GetResourceIdsOfExistingPinnedFilesOnUIThread) { EXPECT_EQ("pinned:existing", resource_ids[1]); } -TEST_F(DriveCacheTest, GetResourceIdsOfAllFilesOnUIThread) { +TEST_F(DriveCacheTest, GetResourceIdsOfAllFiles) { PrepareForInitCacheTest(); std::vector<std::string> resource_ids; - cache_->GetResourceIdsOfAllFilesOnUIThread( + cache_->GetResourceIdsOfAllFiles( base::Bind(&OnGetResourceIds, &resource_ids)); google_apis::test_util::RunBlockingPoolTask(); @@ -1549,7 +1540,7 @@ TEST_F(DriveCacheTest, GetResourceIdsOfAllFilesOnUIThread) { } -TEST_F(DriveCacheTest, ClearAllOnUIThread) { +TEST_F(DriveCacheTest, ClearAll) { PrepareForInitCacheTest(); EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) @@ -1572,9 +1563,7 @@ TEST_F(DriveCacheTest, ClearAllOnUIThread) { // Clear cache. DriveFileError error = DRIVE_FILE_OK; FilePath file_path; - cache_->ClearAllOnUIThread(base::Bind(&OnClearAll, - &error, - &file_path)); + cache_->ClearAll(base::Bind(&OnClearAll, &error, &file_path)); google_apis::test_util::RunBlockingPoolTask(); EXPECT_EQ(DRIVE_FILE_OK, error); @@ -1613,18 +1602,17 @@ TEST(DriveCacheExtraTest, InitializationFailure) { content::BrowserThread::GetBlockingPool(); // Set the cache root to a non existent path, so the initialization fails. - DriveCache* cache = DriveCache::CreateDriveCacheOnUIThread( + DriveCache* cache = DriveCache::CreateDriveCache( FilePath::FromUTF8Unsafe("/somewhere/nonexistent/blah/blah"), pool->GetSequencedTaskRunner(pool->GetSequenceToken())); bool success = false; - cache->RequestInitializeOnUIThread( - base::Bind(&test_util::CopyResultFromInitializeCacheCallback, - &success)); + cache->RequestInitialize( + base::Bind(&test_util::CopyResultFromInitializeCacheCallback, &success)); google_apis::test_util::RunBlockingPoolTask(); EXPECT_FALSE(success); - cache->DestroyOnUIThread(); + cache->Destroy(); google_apis::test_util::RunBlockingPoolTask(); } diff --git a/chrome/browser/chromeos/drive/drive_file_system.cc b/chrome/browser/chromeos/drive/drive_file_system.cc index 37c46c0..94aedf8 100644 --- a/chrome/browser/chromeos/drive/drive_file_system.cc +++ b/chrome/browser/chromeos/drive/drive_file_system.cc @@ -894,21 +894,20 @@ void DriveFileSystem::GetResolvedFileByPath( entry_proto->file_specific_info().file_md5(), DriveCache::CACHE_TYPE_TMP, DriveCache::CACHED_FILE_FROM_SERVER); - cache_->GetFileOnUIThread( - entry_proto->resource_id(), - entry_proto->file_specific_info().file_md5(), - base::Bind( - &DriveFileSystem::OnGetFileFromCache, - ui_weak_ptr_, - GetFileFromCacheParams( - file_path, - local_tmp_path, - GURL(entry_proto->content_url()), - entry_proto->resource_id(), - entry_proto->file_specific_info().file_md5(), - entry_proto->file_specific_info().content_mime_type(), - get_file_callback, - get_content_callback))); + cache_->GetFile(entry_proto->resource_id(), + entry_proto->file_specific_info().file_md5(), + base::Bind( + &DriveFileSystem::OnGetFileFromCache, + ui_weak_ptr_, + GetFileFromCacheParams( + file_path, + local_tmp_path, + GURL(entry_proto->content_url()), + entry_proto->resource_id(), + entry_proto->file_specific_info().file_md5(), + entry_proto->file_specific_info().content_mime_type(), + get_file_callback, + get_content_callback))); } void DriveFileSystem::GetFileByResourceId( @@ -1068,7 +1067,7 @@ void DriveFileSystem::CheckForSpaceBeforeDownload( google_apis::util::PostBlockingPoolSequencedTaskAndReplyWithResult( FROM_HERE, blocking_task_runner_, - base::Bind(&DriveCache::FreeDiskSpaceIfNeededFor, + base::Bind(&DriveCache::FreeDiskSpaceOnBlockingPoolIfNeededFor, base::Unretained(cache_), file_size), base::Bind(&DriveFileSystem::StartDownloadFileIfEnoughSpace, @@ -1353,14 +1352,13 @@ void DriveFileSystem::UpdateFileByEntryInfo( // Extract a pointer before we call Pass() so we can use it below. DriveEntryProto* entry_proto_ptr = entry_proto.get(); - cache_->GetFileOnUIThread( - entry_proto_ptr->resource_id(), - entry_proto_ptr->file_specific_info().file_md5(), - base::Bind(&DriveFileSystem::OnGetFileCompleteForUpdateFile, - ui_weak_ptr_, - callback, - drive_file_path, - base::Passed(&entry_proto))); + cache_->GetFile(entry_proto_ptr->resource_id(), + entry_proto_ptr->file_specific_info().file_md5(), + base::Bind(&DriveFileSystem::OnGetFileCompleteForUpdateFile, + ui_weak_ptr_, + callback, + drive_file_path, + base::Passed(&entry_proto))); } void DriveFileSystem::OnGetFileCompleteForUpdateFile( @@ -1726,13 +1724,12 @@ void DriveFileSystem::OnFileDownloaded( // If user cancels download of a pinned-but-not-fetched file, mark file as // unpinned so that we do not sync the file again. if (status == google_apis::GDATA_CANCELLED) { - cache_->GetCacheEntryOnUIThread( - params.resource_id, - params.md5, - base::Bind(&DriveFileSystem::UnpinIfPinned, - ui_weak_ptr_, - params.resource_id, - params.md5)); + cache_->GetCacheEntry(params.resource_id, + params.md5, + base::Bind(&DriveFileSystem::UnpinIfPinned, + ui_weak_ptr_, + params.resource_id, + params.md5)); } // At this point, the disk can be full or nearly full for several reasons: @@ -1746,7 +1743,7 @@ void DriveFileSystem::OnFileDownloaded( google_apis::util::PostBlockingPoolSequencedTaskAndReplyWithResult( FROM_HERE, blocking_task_runner_, - base::Bind(&DriveCache::FreeDiskSpaceIfNeededFor, + base::Bind(&DriveCache::FreeDiskSpaceOnBlockingPoolIfNeededFor, base::Unretained(cache_), 0), base::Bind(&DriveFileSystem::OnFileDownloadedAndSpaceChecked, @@ -1766,7 +1763,7 @@ void DriveFileSystem::UnpinIfPinned( // TODO(hshi): http://crbug.com/127138 notify when file properties change. // This allows file manager to clear the "Available offline" checkbox. if (success && cache_entry.is_pinned()) - cache_->UnpinOnUIThread(resource_id, md5, CacheOperationCallback()); + cache_->Unpin(resource_id, md5, CacheOperationCallback()); } void DriveFileSystem::OnFileDownloadedAndSpaceChecked( @@ -1785,13 +1782,12 @@ void DriveFileSystem::OnFileDownloadedAndSpaceChecked( // downloaded file. if (error == DRIVE_FILE_OK) { if (has_enough_space) { - cache_->StoreOnUIThread( - params.resource_id, - params.md5, - downloaded_file_path, - DriveCache::FILE_OPERATION_MOVE, - base::Bind(&DriveFileSystem::OnDownloadStoredToCache, - ui_weak_ptr_)); + cache_->Store(params.resource_id, + params.md5, + downloaded_file_path, + DriveCache::FILE_OPERATION_MOVE, + base::Bind(&DriveFileSystem::OnDownloadStoredToCache, + ui_weak_ptr_)); } else { // If we don't have enough space, remove the downloaded file, and // report "no space" error. @@ -2053,18 +2049,18 @@ void DriveFileSystem::AddUploadedFileToCache( if (params->upload_mode == google_apis::UPLOAD_NEW_FILE) { // Add the file to the cache if we have uploaded a new file. - cache_->StoreOnUIThread(params->resource_id, - params->md5, - params->file_content_path, - params->cache_operation, - base::Bind(&OnCacheUpdatedForAddUploadedFile, - params->callback)); + cache_->Store(params->resource_id, + params->md5, + params->file_content_path, + params->cache_operation, + base::Bind(&OnCacheUpdatedForAddUploadedFile, + params->callback)); } else if (params->upload_mode == google_apis::UPLOAD_EXISTING_FILE) { // Clear the dirty bit if we have updated an existing file. - cache_->ClearDirtyOnUIThread(params->resource_id, - params->md5, - base::Bind(&OnCacheUpdatedForAddUploadedFile, - params->callback)); + cache_->ClearDirty(params->resource_id, + params->md5, + base::Bind(&OnCacheUpdatedForAddUploadedFile, + params->callback)); } else { NOTREACHED() << "Unexpected upload mode: " << params->upload_mode; // Shouldn't reach here, so the line below should not make much sense, but @@ -2119,12 +2115,12 @@ void DriveFileSystem::UpdateCacheEntryOnUIThread( } // Add the file to the cache if we have uploaded a new file. - cache_->StoreOnUIThread(params.resource_id, - params.md5, - params.file_content_path, - DriveCache::FILE_OPERATION_MOVE, - base::Bind(&OnCacheUpdatedForAddUploadedFile, - params.callback)); + cache_->Store(params.resource_id, + params.md5, + params.file_content_path, + DriveCache::FILE_OPERATION_MOVE, + base::Bind(&OnCacheUpdatedForAddUploadedFile, + params.callback)); } DriveFileSystemMetadata DriveFileSystem::GetMetadata() const { @@ -2282,7 +2278,7 @@ void DriveFileSystem::OnGetFileCompleteForOpenFile( // OpenFileOnUIThread ensures that the file is a regular file. DCHECK_EQ(REGULAR_FILE, file_type); - cache_->MarkDirtyOnUIThread( + cache_->MarkDirty( entry_proto.resource_id, entry_proto.md5, base::Bind(&DriveFileSystem::OnMarkDirtyInCacheCompleteForOpenFile, @@ -2377,7 +2373,7 @@ void DriveFileSystem::CloseFileOnUIThreadAfterGetEntryInfo( // if the file has not been modified. Come up with a way to detect the // intactness effectively, or provide a method for user to declare it when // calling CloseFile(). - cache_->CommitDirtyOnUIThread( + cache_->CommitDirty( entry_proto->resource_id(), entry_proto->file_specific_info().file_md5(), base::Bind(&DriveFileSystem::CloseFileOnUIThreadAfterCommitDirtyInCache, @@ -2430,7 +2426,7 @@ void DriveFileSystem::CheckLocalModificationAndRun( // Checks if the file is cached and modified locally. const std::string resource_id = entry_proto->resource_id(); const std::string md5 = entry_proto->file_specific_info().file_md5(); - cache_->GetCacheEntryOnUIThread( + cache_->GetCacheEntry( resource_id, md5, base::Bind( @@ -2455,7 +2451,7 @@ void DriveFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry( // Gets the cache file path. const std::string& resource_id = entry_proto->resource_id(); const std::string& md5 = entry_proto->file_specific_info().file_md5(); - cache_->GetFileOnUIThread( + cache_->GetFile( resource_id, md5, base::Bind( diff --git a/chrome/browser/chromeos/drive/drive_file_system_unittest.cc b/chrome/browser/chromeos/drive/drive_file_system_unittest.cc index 9ca023d..6008a2b 100644 --- a/chrome/browser/chromeos/drive/drive_file_system_unittest.cc +++ b/chrome/browser/chromeos/drive/drive_file_system_unittest.cc @@ -196,7 +196,7 @@ class DriveFileSystemTest : public testing::Test { blocking_task_runner_ = pool->GetSequencedTaskRunner(pool->GetSequenceToken()); - cache_ = DriveCache::CreateDriveCacheOnUIThread( + cache_ = DriveCache::CreateDriveCache( DriveCache::GetCacheRootPath(profile_.get()), blocking_task_runner_); mock_uploader_.reset(new StrictMock<google_apis::MockDriveUploader>); @@ -217,7 +217,7 @@ class DriveFileSystemTest : public testing::Test { file_system_->AddObserver(mock_directory_observer_.get()); file_system_->Initialize(); - cache_->RequestInitializeOnUIThreadForTesting(); + cache_->RequestInitializeForTesting(); google_apis::test_util::RunBlockingPoolTask(); } @@ -229,7 +229,7 @@ class DriveFileSystemTest : public testing::Test { delete mock_drive_service_; mock_drive_service_ = NULL; SetFreeDiskSpaceGetterForTesting(NULL); - cache_->DestroyOnUIThread(); + cache_->Destroy(); // The cache destruction requires to post a task to the blocking pool. google_apis::test_util::RunBlockingPoolTask(); @@ -364,7 +364,8 @@ class DriveFileSystemTest : public testing::Test { const std::string& md5, DriveCacheEntry* cache_entry, bool* result) { - *result = cache_->GetCacheEntry(resource_id, md5, cache_entry); + *result = + cache_->GetCacheEntryOnBlockingPool(resource_id, md5, cache_entry); } // Returns true if the cache entry exists for the given resource ID and MD5. @@ -396,11 +397,10 @@ class DriveFileSystemTest : public testing::Test { expected_cache_state_ = expected_cache_state; expected_sub_dir_type_ = expected_sub_dir_type; - cache_->StoreOnUIThread( - resource_id, md5, source_path, - DriveCache::FILE_OPERATION_COPY, - base::Bind(&DriveFileSystemTest::VerifyCacheFileState, - base::Unretained(this))); + cache_->Store(resource_id, md5, source_path, + DriveCache::FILE_OPERATION_COPY, + base::Bind(&DriveFileSystemTest::VerifyCacheFileState, + base::Unretained(this))); google_apis::test_util::RunBlockingPoolTask(); } @@ -415,10 +415,9 @@ class DriveFileSystemTest : public testing::Test { expected_cache_state_ = expected_cache_state; expected_sub_dir_type_ = expected_sub_dir_type; - cache_->PinOnUIThread( - resource_id, md5, - base::Bind(&DriveFileSystemTest::VerifyCacheFileState, - base::Unretained(this))); + cache_->Pin(resource_id, md5, + base::Bind(&DriveFileSystemTest::VerifyCacheFileState, + base::Unretained(this))); google_apis::test_util::RunBlockingPoolTask(); } @@ -434,13 +433,10 @@ class DriveFileSystemTest : public testing::Test { expected_sub_dir_type_ = expected_sub_dir_type; expect_outgoing_symlink_ = false; - cache_->MarkDirtyOnUIThread( - resource_id, - md5, - base::Bind(&DriveFileSystemTest::VerifyMarkDirty, - base::Unretained(this), - resource_id, - md5)); + cache_->MarkDirty(resource_id, md5, + base::Bind(&DriveFileSystemTest::VerifyMarkDirty, + base::Unretained(this), + resource_id, md5)); google_apis::test_util::RunBlockingPoolTask(); } @@ -474,10 +470,9 @@ class DriveFileSystemTest : public testing::Test { expected_sub_dir_type_ = expected_sub_dir_type; expect_outgoing_symlink_ = true; - cache_->CommitDirtyOnUIThread( - resource_id, md5, - base::Bind(&DriveFileSystemTest::VerifyCacheFileState, - base::Unretained(this))); + cache_->CommitDirty(resource_id, md5, + base::Bind(&DriveFileSystemTest::VerifyCacheFileState, + base::Unretained(this))); google_apis::test_util::RunBlockingPoolTask(); } diff --git a/chrome/browser/chromeos/drive/drive_sync_client.cc b/chrome/browser/chromeos/drive/drive_sync_client.cc index f5273b3..04d43cd 100644 --- a/chrome/browser/chromeos/drive/drive_sync_client.cc +++ b/chrome/browser/chromeos/drive/drive_sync_client.cc @@ -107,7 +107,7 @@ void DriveSyncClient::Initialize() { void DriveSyncClient::StartProcessingBacklog() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - cache_->GetResourceIdsOfBacklogOnUIThread( + cache_->GetResourceIdsOfBacklog( base::Bind(&DriveSyncClient::OnGetResourceIdsOfBacklog, weak_ptr_factory_.GetWeakPtr())); } @@ -115,7 +115,7 @@ void DriveSyncClient::StartProcessingBacklog() { void DriveSyncClient::StartCheckingExistingPinnedFiles() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - cache_->GetResourceIdsOfExistingPinnedFilesOnUIThread( + cache_->GetResourceIdsOfExistingPinnedFiles( base::Bind(&DriveSyncClient::OnGetResourceIdsOfExistingPinnedFiles, weak_ptr_factory_.GetWeakPtr())); } @@ -325,7 +325,7 @@ void DriveSyncClient::OnGetEntryInfoByResourceId( return; } - cache_->GetCacheEntryOnUIThread( + cache_->GetCacheEntry( resource_id, "" /* don't check MD5 */, base::Bind(&DriveSyncClient::OnGetCacheEntry, @@ -350,10 +350,9 @@ void DriveSyncClient::OnGetCacheEntry( // the file is dirty (the MD5 is "local"). We should never re-fetch the // file when we have a locally modified version. if (latest_md5 != cache_entry.md5() && !cache_entry.is_dirty()) { - cache_->RemoveOnUIThread( - resource_id, - base::Bind(&DriveSyncClient::OnRemove, - weak_ptr_factory_.GetWeakPtr())); + cache_->Remove(resource_id, + base::Bind(&DriveSyncClient::OnRemove, + weak_ptr_factory_.GetWeakPtr())); } } @@ -369,10 +368,10 @@ void DriveSyncClient::OnRemove(DriveFileError error, // Before fetching, we should pin this file again, so that the fetched file // is downloaded properly to the persistent directory and marked pinned. - cache_->PinOnUIThread(resource_id, - md5, - base::Bind(&DriveSyncClient::OnPinned, - weak_ptr_factory_.GetWeakPtr())); + cache_->Pin(resource_id, + md5, + base::Bind(&DriveSyncClient::OnPinned, + weak_ptr_factory_.GetWeakPtr())); } void DriveSyncClient::OnPinned(DriveFileError error, diff --git a/chrome/browser/chromeos/drive/drive_sync_client_unittest.cc b/chrome/browser/chromeos/drive/drive_sync_client_unittest.cc index ba4bba7..6314a31 100644 --- a/chrome/browser/chromeos/drive/drive_sync_client_unittest.cc +++ b/chrome/browser/chromeos/drive/drive_sync_client_unittest.cc @@ -106,7 +106,7 @@ class DriveSyncClientTest : public testing::Test { // Initialize the sync client. scoped_refptr<base::SequencedWorkerPool> pool = content::BrowserThread::GetBlockingPool(); - cache_ = DriveCache::CreateDriveCacheOnUIThread( + cache_ = DriveCache::CreateDriveCache( temp_dir_.path(), pool->GetSequencedTaskRunner(pool->GetSequenceToken())); sync_client_.reset(new DriveSyncClient(profile_.get(), @@ -128,7 +128,7 @@ class DriveSyncClientTest : public testing::Test { // client registers itself as observer of NetworkLibrary. sync_client_->RemoveObserver(&observer_); sync_client_.reset(); - cache_->DestroyOnUIThread(); + cache_->Destroy(); google_apis::test_util::RunBlockingPoolTask(); mock_network_change_notifier_.reset(); } @@ -330,9 +330,8 @@ TEST_F(DriveSyncClientTest, StartInitialScan) { // Kick off the cache initialization. This will scan the contents in the // test cache directory. bool success = false; - cache_->RequestInitializeOnUIThread( - base::Bind(&test_util::CopyResultFromInitializeCacheCallback, - &success)); + cache_->RequestInitialize( + base::Bind(&test_util::CopyResultFromInitializeCacheCallback, &success)); // Start processing the files in the backlog. This will collect the // resource IDs of these files. sync_client_->StartProcessingBacklog(); @@ -570,7 +569,7 @@ TEST_F(DriveSyncClientTest, ExistingPinnedFiles) { // Kick off the cache initialization. This will scan the contents in the // test cache directory. bool initialization_success = false; - cache_->RequestInitializeOnUIThread( + cache_->RequestInitialize( base::Bind(&test_util::CopyResultFromInitializeCacheCallback, &initialization_success)); diff --git a/chrome/browser/chromeos/drive/drive_system_service.cc b/chrome/browser/chromeos/drive/drive_system_service.cc index b6ddbd7..ed6c017 100644 --- a/chrome/browser/chromeos/drive/drive_system_service.cc +++ b/chrome/browser/chromeos/drive/drive_system_service.cc @@ -80,7 +80,7 @@ DriveSystemService::DriveSystemService(Profile* profile) DriveSystemService::~DriveSystemService() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - cache_->DestroyOnUIThread(); + cache_->Destroy(); } void DriveSystemService::Initialize( @@ -89,9 +89,7 @@ void DriveSystemService::Initialize( DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); drive_service_.reset(drive_service); - cache_ = DriveCache::CreateDriveCacheOnUIThread( - cache_root, - blocking_task_runner_); + cache_ = DriveCache::CreateDriveCache(cache_root, blocking_task_runner_); uploader_.reset(new google_apis::DriveUploader(drive_service_.get())); webapps_registry_.reset(new DriveWebAppsRegistry); file_system_.reset(new DriveFileSystem(profile_, @@ -112,9 +110,8 @@ void DriveSystemService::Initialize( sync_client_->Initialize(); file_system_->Initialize(); - cache_->RequestInitializeOnUIThread( - base::Bind(&DriveSystemService::OnCacheInitialized, - weak_ptr_factory_.GetWeakPtr())); + cache_->RequestInitialize(base::Bind(&DriveSystemService::OnCacheInitialized, + weak_ptr_factory_.GetWeakPtr())); } void DriveSystemService::Shutdown() { @@ -186,10 +183,9 @@ void DriveSystemService::ClearCacheAndRemountFileSystem( RemoveDriveMountPoint(); drive_service()->CancelAll(); - cache_->ClearAllOnUIThread( - base::Bind(&DriveSystemService::AddBackDriveMountPoint, - weak_ptr_factory_.GetWeakPtr(), - callback)); + cache_->ClearAll(base::Bind(&DriveSystemService::AddBackDriveMountPoint, + weak_ptr_factory_.GetWeakPtr(), + callback)); } void DriveSystemService::AddBackDriveMountPoint( diff --git a/chrome/browser/chromeos/drive/file_system/remove_operation.cc b/chrome/browser/chromeos/drive/file_system/remove_operation.cc index d396df4..1a13f1b 100644 --- a/chrome/browser/chromeos/drive/file_system/remove_operation.cc +++ b/chrome/browser/chromeos/drive/file_system/remove_operation.cc @@ -95,7 +95,7 @@ void RemoveOperation::RemoveResourceLocally( weak_ptr_factory_.GetWeakPtr(), callback)); - cache_->RemoveOnUIThread(resource_id, CacheOperationCallback()); + cache_->Remove(resource_id, CacheOperationCallback()); } void RemoveOperation::NotifyDirectoryChanged( diff --git a/chrome/browser/chromeos/drive/stale_cache_files_remover.cc b/chrome/browser/chromeos/drive/stale_cache_files_remover.cc index 1451746..ac861fa 100644 --- a/chrome/browser/chromeos/drive/stale_cache_files_remover.cc +++ b/chrome/browser/chromeos/drive/stale_cache_files_remover.cc @@ -46,7 +46,7 @@ void StaleCacheFilesRemover::OnInitialLoadFinished(DriveFileError error) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); const FilePath root_path = FilePath(kDriveRootDirectory); - cache_->GetResourceIdsOfAllFilesOnUIThread( + cache_->GetResourceIdsOfAllFiles( base::Bind(&StaleCacheFilesRemover::OnGetResourceIdsOfAllFiles, weak_ptr_factory_.GetWeakPtr())); } @@ -57,7 +57,7 @@ void StaleCacheFilesRemover::OnGetResourceIdsOfAllFiles( for (size_t i = 0; i < resource_ids.size(); ++i) { const std::string& resource_id = resource_ids[i]; - cache_->GetCacheEntryOnUIThread( + cache_->GetCacheEntry( resource_id, "", // Don't check MD5. base::Bind( @@ -73,9 +73,9 @@ void StaleCacheFilesRemover::GetEntryInfoAndRemoveCacheIfNecessary( const DriveCacheEntry& cache_entry) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - // Removes the cache if GetCacheEntryOnUIThread() failed. + // Removes the cache if GetCacheEntry() failed. if (!success) { - LOG(WARNING) << "GetCacheEntryOnUIThread() failed"; + LOG(WARNING) << "GetCacheEntry() failed"; return; } @@ -97,7 +97,7 @@ void StaleCacheFilesRemover::RemoveCacheIfNecessary( // The entry is not found in the file system. if (error != DRIVE_FILE_OK) { - cache_->RemoveOnUIThread(resource_id, base::Bind(&EmitErrorLog)); + cache_->Remove(resource_id, base::Bind(&EmitErrorLog)); return; } @@ -105,7 +105,7 @@ void StaleCacheFilesRemover::RemoveCacheIfNecessary( DCHECK(entry_proto.get()); if (!entry_proto->has_file_specific_info() || cache_md5 != entry_proto->file_specific_info().file_md5()) { - cache_->RemoveOnUIThread(resource_id, base::Bind(&EmitErrorLog)); + cache_->Remove(resource_id, base::Bind(&EmitErrorLog)); return; } } diff --git a/chrome/browser/chromeos/drive/stale_cache_files_remover_unittest.cc b/chrome/browser/chromeos/drive/stale_cache_files_remover_unittest.cc index 1450300..2bda123 100644 --- a/chrome/browser/chromeos/drive/stale_cache_files_remover_unittest.cc +++ b/chrome/browser/chromeos/drive/stale_cache_files_remover_unittest.cc @@ -45,7 +45,7 @@ namespace { const int64 kLotsOfSpace = kMinFreeSpace * 10; -// Callback for DriveCache::StoreOnUIThread used in RemoveStaleCacheFiles test. +// Callback for DriveCache::Store used in RemoveStaleCacheFiles test. // Verifies that the result is not an error. void VerifyCacheFileState(DriveFileError error, const std::string& resource_id, @@ -87,7 +87,7 @@ class StaleCacheFilesRemoverTest : public testing::Test { blocking_task_runner_ = pool->GetSequencedTaskRunner(pool->GetSequenceToken()); - cache_ = DriveCache::CreateDriveCacheOnUIThread( + cache_ = DriveCache::CreateDriveCache( DriveCache::GetCacheRootPath(profile_.get()), blocking_task_runner_); mock_uploader_.reset(new StrictMock<google_apis::MockDriveUploader>); @@ -108,7 +108,7 @@ class StaleCacheFilesRemoverTest : public testing::Test { file_system_->AddObserver(mock_directory_observer_.get()); file_system_->Initialize(); - cache_->RequestInitializeOnUIThreadForTesting(); + cache_->RequestInitializeForTesting(); stale_cache_files_remover_.reset(new StaleCacheFilesRemover(file_system_, cache_)); @@ -125,7 +125,7 @@ class StaleCacheFilesRemoverTest : public testing::Test { delete mock_drive_service_; mock_drive_service_ = NULL; SetFreeDiskSpaceGetterForTesting(NULL); - cache_->DestroyOnUIThread(); + cache_->Destroy(); // The cache destruction requires to post a task to the blocking pool. google_apis::test_util::RunBlockingPoolTask(); @@ -162,9 +162,8 @@ TEST_F(StaleCacheFilesRemoverTest, RemoveStaleCacheFiles) { .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); // Create a stale cache file. - cache_->StoreOnUIThread(resource_id, md5, dummy_file, - DriveCache::FILE_OPERATION_COPY, - base::Bind(&VerifyCacheFileState)); + cache_->Store(resource_id, md5, dummy_file, DriveCache::FILE_OPERATION_COPY, + base::Bind(&VerifyCacheFileState)); google_apis::test_util::RunBlockingPoolTask(); // Verify that the cache file exists. |