summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-26 03:04:07 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-26 03:04:07 +0000
commitc9e4738d4185a072c560f1c072516c7381d3c54a (patch)
tree2fdcd1e99a97875b60329500348bffd76299ae8a
parent96b2d292ffc51ee94709a57d729677937e8da500 (diff)
downloadchromium_src-c9e4738d4185a072c560f1c072516c7381d3c54a.zip
chromium_src-c9e4738d4185a072c560f1c072516c7381d3c54a.tar.gz
chromium_src-c9e4738d4185a072c560f1c072516c7381d3c54a.tar.bz2
drive: Stop mentioning resource ID in FileCache
BUG=275270 TEST=unit_tests Review URL: https://chromiumcodereview.appspot.com/23125019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219493 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/drive/file_cache.cc140
-rw-r--r--chrome/browser/chromeos/drive/file_cache.h57
-rw-r--r--chrome/browser/chromeos/drive/file_cache_unittest.cc357
3 files changed, 269 insertions, 285 deletions
diff --git a/chrome/browser/chromeos/drive/file_cache.cc b/chrome/browser/chromeos/drive/file_cache.cc
index b5a562f..61bc786 100644
--- a/chrome/browser/chromeos/drive/file_cache.cc
+++ b/chrome/browser/chromeos/drive/file_cache.cc
@@ -28,8 +28,8 @@ namespace {
typedef std::map<std::string, FileCacheEntry> CacheMap;
-// Returns resource ID extracted from the path.
-std::string GetResourceIdFromPath(const base::FilePath& path) {
+// Returns ID extracted from the path.
+std::string GetIdFromPath(const base::FilePath& path) {
return util::UnescapeCacheFileName(path.BaseName().AsUTF8Unsafe());
}
@@ -41,7 +41,7 @@ void ScanCacheDirectory(const base::FilePath& directory_path,
base::FileEnumerator::FILES);
for (base::FilePath current = enumerator.Next(); !current.empty();
current = enumerator.Next()) {
- std::string resource_id = GetResourceIdFromPath(current);
+ std::string id = GetIdFromPath(current);
// Calculate MD5.
std::string md5 = util::GetMd5Digest(current);
@@ -54,7 +54,7 @@ void ScanCacheDirectory(const base::FilePath& directory_path,
cache_entry.set_is_present(true);
// Create and insert new entry into cache map.
- cache_map->insert(std::make_pair(resource_id, cache_entry));
+ cache_map->insert(std::make_pair(id, cache_entry));
}
}
@@ -110,10 +110,9 @@ FileCache::~FileCache() {
AssertOnSequencedWorkerPool();
}
-base::FilePath FileCache::GetCacheFilePath(
- const std::string& resource_id) const {
+base::FilePath FileCache::GetCacheFilePath(const std::string& id) const {
return cache_file_directory_.Append(
- base::FilePath::FromUTF8Unsafe(util::EscapeCacheFileName(resource_id)));
+ base::FilePath::FromUTF8Unsafe(util::EscapeCacheFileName(id)));
}
void FileCache::AssertOnSequencedWorkerPool() {
@@ -125,7 +124,7 @@ bool FileCache::IsUnderFileCacheDirectory(const base::FilePath& path) const {
return cache_file_directory_.IsParent(path);
}
-void FileCache::GetCacheEntryOnUIThread(const std::string& resource_id,
+void FileCache::GetCacheEntryOnUIThread(const std::string& id,
const GetCacheEntryCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
@@ -136,17 +135,16 @@ void FileCache::GetCacheEntryOnUIThread(const std::string& resource_id,
FROM_HERE,
base::Bind(&FileCache::GetCacheEntry,
base::Unretained(this),
- resource_id,
+ id,
cache_entry),
base::Bind(
&RunGetCacheEntryCallback, callback, base::Owned(cache_entry)));
}
-bool FileCache::GetCacheEntry(const std::string& resource_id,
- FileCacheEntry* entry) {
+bool FileCache::GetCacheEntry(const std::string& id, FileCacheEntry* entry) {
DCHECK(entry);
AssertOnSequencedWorkerPool();
- return storage_->GetCacheEntry(resource_id, entry);
+ return storage_->GetCacheEntry(id, entry);
}
void FileCache::IterateOnUIThread(
@@ -198,8 +196,8 @@ bool FileCache::FreeDiskSpaceIfNeededFor(int64 num_bytes) {
FileCacheEntry entry;
for (base::FilePath current = enumerator.Next(); !current.empty();
current = enumerator.Next()) {
- std::string resource_id = GetResourceIdFromPath(current);
- if (!storage_->GetCacheEntry(resource_id, &entry))
+ std::string id = GetIdFromPath(current);
+ if (!storage_->GetCacheEntry(id, &entry))
base::DeleteFile(current, false /* recursive */);
}
@@ -207,7 +205,7 @@ bool FileCache::FreeDiskSpaceIfNeededFor(int64 num_bytes) {
return HasEnoughSpaceFor(num_bytes, cache_file_directory_);
}
-void FileCache::GetFileOnUIThread(const std::string& resource_id,
+void FileCache::GetFileOnUIThread(const std::string& id,
const GetFileFromCacheCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
@@ -217,28 +215,28 @@ void FileCache::GetFileOnUIThread(const std::string& resource_id,
FROM_HERE,
base::Bind(&FileCache::GetFile,
base::Unretained(this),
- resource_id,
+ id,
cache_file_path),
base::Bind(&RunGetFileFromCacheCallback,
callback,
base::Owned(cache_file_path)));
}
-FileError FileCache::GetFile(const std::string& resource_id,
+FileError FileCache::GetFile(const std::string& id,
base::FilePath* cache_file_path) {
AssertOnSequencedWorkerPool();
DCHECK(cache_file_path);
FileCacheEntry cache_entry;
- if (!storage_->GetCacheEntry(resource_id, &cache_entry) ||
+ if (!storage_->GetCacheEntry(id, &cache_entry) ||
!cache_entry.is_present())
return FILE_ERROR_NOT_FOUND;
- *cache_file_path = GetCacheFilePath(resource_id);
+ *cache_file_path = GetCacheFilePath(id);
return FILE_ERROR_OK;
}
-void FileCache::StoreOnUIThread(const std::string& resource_id,
+void FileCache::StoreOnUIThread(const std::string& id,
const std::string& md5,
const base::FilePath& source_path,
FileOperationType file_operation_type,
@@ -250,22 +248,22 @@ void FileCache::StoreOnUIThread(const std::string& resource_id,
FROM_HERE,
base::Bind(&FileCache::Store,
base::Unretained(this),
- resource_id,
+ id,
md5,
source_path,
file_operation_type),
callback);
}
-FileError FileCache::Store(const std::string& resource_id,
+FileError FileCache::Store(const std::string& id,
const std::string& md5,
const base::FilePath& source_path,
FileOperationType file_operation_type) {
AssertOnSequencedWorkerPool();
- return StoreInternal(resource_id, md5, source_path, file_operation_type);
+ return StoreInternal(id, md5, source_path, file_operation_type);
}
-void FileCache::PinOnUIThread(const std::string& resource_id,
+void FileCache::PinOnUIThread(const std::string& id,
const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
@@ -273,21 +271,21 @@ void FileCache::PinOnUIThread(const std::string& resource_id,
base::PostTaskAndReplyWithResult(
blocking_task_runner_.get(),
FROM_HERE,
- base::Bind(&FileCache::Pin, base::Unretained(this), resource_id),
+ base::Bind(&FileCache::Pin, base::Unretained(this), id),
callback);
}
-FileError FileCache::Pin(const std::string& resource_id) {
+FileError FileCache::Pin(const std::string& id) {
AssertOnSequencedWorkerPool();
FileCacheEntry cache_entry;
- storage_->GetCacheEntry(resource_id, &cache_entry);
+ storage_->GetCacheEntry(id, &cache_entry);
cache_entry.set_is_pinned(true);
- return storage_->PutCacheEntry(resource_id, cache_entry) ?
+ return storage_->PutCacheEntry(id, cache_entry) ?
FILE_ERROR_OK : FILE_ERROR_FAILED;
}
-void FileCache::UnpinOnUIThread(const std::string& resource_id,
+void FileCache::UnpinOnUIThread(const std::string& id,
const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
@@ -295,26 +293,26 @@ void FileCache::UnpinOnUIThread(const std::string& resource_id,
base::PostTaskAndReplyWithResult(
blocking_task_runner_.get(),
FROM_HERE,
- base::Bind(&FileCache::Unpin, base::Unretained(this), resource_id),
+ base::Bind(&FileCache::Unpin, base::Unretained(this), id),
callback);
}
-FileError FileCache::Unpin(const std::string& resource_id) {
+FileError FileCache::Unpin(const std::string& id) {
AssertOnSequencedWorkerPool();
// Unpinning a file means its entry must exist in cache.
FileCacheEntry cache_entry;
- if (!storage_->GetCacheEntry(resource_id, &cache_entry))
+ if (!storage_->GetCacheEntry(id, &cache_entry))
return FILE_ERROR_NOT_FOUND;
// Now that file operations have completed, update metadata.
if (cache_entry.is_present()) {
cache_entry.set_is_pinned(false);
- if (!storage_->PutCacheEntry(resource_id, cache_entry))
+ if (!storage_->PutCacheEntry(id, cache_entry))
return FILE_ERROR_FAILED;
} else {
// Remove the existing entry if we are unpinning a non-present file.
- if (!storage_->RemoveCacheEntry(resource_id))
+ if (!storage_->RemoveCacheEntry(id))
return FILE_ERROR_FAILED;
}
@@ -325,7 +323,7 @@ FileError FileCache::Unpin(const std::string& resource_id) {
}
void FileCache::MarkAsMountedOnUIThread(
- const std::string& resource_id,
+ const std::string& id,
const GetFileFromCacheCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
@@ -336,7 +334,7 @@ void FileCache::MarkAsMountedOnUIThread(
FROM_HERE,
base::Bind(&FileCache::MarkAsMounted,
base::Unretained(this),
- resource_id,
+ id,
cache_file_path),
base::Bind(
RunGetFileFromCacheCallback, callback, base::Owned(cache_file_path)));
@@ -356,7 +354,7 @@ void FileCache::MarkAsUnmountedOnUIThread(
callback);
}
-void FileCache::MarkDirtyOnUIThread(const std::string& resource_id,
+void FileCache::MarkDirtyOnUIThread(const std::string& id,
const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
@@ -364,20 +362,19 @@ void FileCache::MarkDirtyOnUIThread(const std::string& resource_id,
base::PostTaskAndReplyWithResult(
blocking_task_runner_.get(),
FROM_HERE,
- base::Bind(&FileCache::MarkDirty, base::Unretained(this), resource_id),
+ base::Bind(&FileCache::MarkDirty, base::Unretained(this), id),
callback);
}
-FileError FileCache::MarkDirty(const std::string& resource_id) {
+FileError FileCache::MarkDirty(const std::string& id) {
AssertOnSequencedWorkerPool();
// Marking a file dirty means its entry and actual file blob must exist in
// cache.
FileCacheEntry cache_entry;
- if (!storage_->GetCacheEntry(resource_id, &cache_entry) ||
+ if (!storage_->GetCacheEntry(id, &cache_entry) ||
!cache_entry.is_present()) {
- LOG(WARNING) << "Can't mark dirty a file that wasn't cached: "
- << resource_id;
+ LOG(WARNING) << "Can't mark dirty a file that wasn't cached: " << id;
return FILE_ERROR_NOT_FOUND;
}
@@ -385,39 +382,37 @@ FileError FileCache::MarkDirty(const std::string& resource_id) {
return FILE_ERROR_OK;
cache_entry.set_is_dirty(true);
- return storage_->PutCacheEntry(resource_id, cache_entry) ?
+ return storage_->PutCacheEntry(id, cache_entry) ?
FILE_ERROR_OK : FILE_ERROR_FAILED;
}
-FileError FileCache::ClearDirty(const std::string& resource_id,
- const std::string& md5) {
+FileError FileCache::ClearDirty(const std::string& id, const std::string& md5) {
AssertOnSequencedWorkerPool();
// Clearing a dirty file means its entry and actual file blob must exist in
// cache.
FileCacheEntry cache_entry;
- if (!storage_->GetCacheEntry(resource_id, &cache_entry) ||
+ if (!storage_->GetCacheEntry(id, &cache_entry) ||
!cache_entry.is_present()) {
LOG(WARNING) << "Can't clear dirty state of a file that wasn't cached: "
- << resource_id;
+ << id;
return FILE_ERROR_NOT_FOUND;
}
// If a file is not dirty (it should have been marked dirty via
// MarkDirtyInCache), clearing its dirty state is an invalid operation.
if (!cache_entry.is_dirty()) {
- LOG(WARNING) << "Can't clear dirty state of a non-dirty file: "
- << resource_id;
+ LOG(WARNING) << "Can't clear dirty state of a non-dirty file: " << id;
return FILE_ERROR_INVALID_OPERATION;
}
cache_entry.set_md5(md5);
cache_entry.set_is_dirty(false);
- return storage_->PutCacheEntry(resource_id, cache_entry) ?
+ return storage_->PutCacheEntry(id, cache_entry) ?
FILE_ERROR_OK : FILE_ERROR_FAILED;
}
-void FileCache::RemoveOnUIThread(const std::string& resource_id,
+void FileCache::RemoveOnUIThread(const std::string& id,
const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
@@ -425,31 +420,30 @@ void FileCache::RemoveOnUIThread(const std::string& resource_id,
base::PostTaskAndReplyWithResult(
blocking_task_runner_.get(),
FROM_HERE,
- base::Bind(&FileCache::Remove, base::Unretained(this), resource_id),
+ base::Bind(&FileCache::Remove, base::Unretained(this), id),
callback);
}
-FileError FileCache::Remove(const std::string& resource_id) {
+FileError FileCache::Remove(const std::string& id) {
AssertOnSequencedWorkerPool();
FileCacheEntry cache_entry;
// If entry doesn't exist, nothing to do.
- if (!storage_->GetCacheEntry(resource_id, &cache_entry))
+ if (!storage_->GetCacheEntry(id, &cache_entry))
return FILE_ERROR_OK;
// Cannot delete a mounted file.
- if (mounted_files_.count(resource_id))
+ if (mounted_files_.count(id))
return FILE_ERROR_IN_USE;
// Delete the file.
- base::FilePath path = GetCacheFilePath(resource_id);
+ base::FilePath path = GetCacheFilePath(id);
if (!base::DeleteFile(path, false /* recursive */))
return FILE_ERROR_FAILED;
// Now that all file operations have completed, remove from metadata.
- return storage_->RemoveCacheEntry(resource_id) ?
- FILE_ERROR_OK : FILE_ERROR_FAILED;
+ return storage_->RemoveCacheEntry(id) ? FILE_ERROR_OK : FILE_ERROR_FAILED;
}
void FileCache::ClearAllOnUIThread(const ClearAllCallback& callback) {
@@ -498,7 +492,7 @@ void FileCache::DestroyOnBlockingPool() {
delete this;
}
-FileError FileCache::StoreInternal(const std::string& resource_id,
+FileError FileCache::StoreInternal(const std::string& id,
const std::string& md5,
const base::FilePath& source_path,
FileOperationType file_operation_type) {
@@ -515,13 +509,13 @@ FileError FileCache::StoreInternal(const std::string& resource_id,
return FILE_ERROR_NO_LOCAL_SPACE;
FileCacheEntry cache_entry;
- storage_->GetCacheEntry(resource_id, &cache_entry);
+ storage_->GetCacheEntry(id, &cache_entry);
// If file is dirty or mounted, return error.
- if (cache_entry.is_dirty() || mounted_files_.count(resource_id))
+ if (cache_entry.is_dirty() || mounted_files_.count(id))
return FILE_ERROR_IN_USE;
- base::FilePath dest_path = GetCacheFilePath(resource_id);
+ base::FilePath dest_path = GetCacheFilePath(id);
bool success = false;
switch (file_operation_type) {
case FILE_OPERATION_MOVE:
@@ -546,25 +540,25 @@ FileError FileCache::StoreInternal(const std::string& resource_id,
cache_entry.set_md5(md5);
cache_entry.set_is_present(true);
cache_entry.set_is_dirty(false);
- return storage_->PutCacheEntry(resource_id, cache_entry) ?
+ return storage_->PutCacheEntry(id, cache_entry) ?
FILE_ERROR_OK : FILE_ERROR_FAILED;
}
-FileError FileCache::MarkAsMounted(const std::string& resource_id,
+FileError FileCache::MarkAsMounted(const std::string& id,
base::FilePath* cache_file_path) {
AssertOnSequencedWorkerPool();
DCHECK(cache_file_path);
- // Get cache entry associated with the resource_id and md5
+ // Get cache entry associated with the id and md5
FileCacheEntry cache_entry;
- if (!storage_->GetCacheEntry(resource_id, &cache_entry))
+ if (!storage_->GetCacheEntry(id, &cache_entry))
return FILE_ERROR_NOT_FOUND;
- if (mounted_files_.count(resource_id))
+ if (mounted_files_.count(id))
return FILE_ERROR_INVALID_OPERATION;
// Ensure the file is readable to cros_disks. See crbug.com/236994.
- base::FilePath path = GetCacheFilePath(resource_id);
+ base::FilePath path = GetCacheFilePath(id);
if (!file_util::SetPosixFilePermissions(
path,
file_util::FILE_PERMISSION_READ_BY_USER |
@@ -573,7 +567,7 @@ FileError FileCache::MarkAsMounted(const std::string& resource_id,
file_util::FILE_PERMISSION_READ_BY_OTHERS))
return FILE_ERROR_FAILED;
- mounted_files_.insert(resource_id);
+ mounted_files_.insert(id);
*cache_file_path = path;
return FILE_ERROR_OK;
@@ -583,14 +577,14 @@ FileError FileCache::MarkAsUnmounted(const base::FilePath& file_path) {
AssertOnSequencedWorkerPool();
DCHECK(IsUnderFileCacheDirectory(file_path));
- std::string resource_id = GetResourceIdFromPath(file_path);
+ std::string id = GetIdFromPath(file_path);
- // Get cache entry associated with the resource_id and md5
+ // Get cache entry associated with the id and md5
FileCacheEntry cache_entry;
- if (!storage_->GetCacheEntry(resource_id, &cache_entry))
+ if (!storage_->GetCacheEntry(id, &cache_entry))
return FILE_ERROR_NOT_FOUND;
- std::set<std::string>::iterator it = mounted_files_.find(resource_id);
+ std::set<std::string>::iterator it = mounted_files_.find(id);
if (it == mounted_files_.end())
return FILE_ERROR_INVALID_OPERATION;
diff --git a/chrome/browser/chromeos/drive/file_cache.h b/chrome/browser/chromeos/drive/file_cache.h
index 4adc25e..54b2d21 100644
--- a/chrome/browser/chromeos/drive/file_cache.h
+++ b/chrome/browser/chromeos/drive/file_cache.h
@@ -32,7 +32,7 @@ typedef base::Callback<void(bool success, const FileCacheEntry& cache_entry)>
GetCacheEntryCallback;
// Callback for Iterate().
-typedef base::Callback<void(const std::string& resource_id,
+typedef base::Callback<void(const std::string& id,
const FileCacheEntry& cache_entry)>
CacheIterateCallback;
@@ -90,18 +90,17 @@ class FileCache {
// Can be called on any thread.
bool IsUnderFileCacheDirectory(const base::FilePath& path) const;
- // Gets the cache entry for file corresponding to |resource_id| and runs
+ // Gets the cache entry for file corresponding to |id| and runs
// |callback| with true and the entry found if entry exists in cache map.
// Otherwise, runs |callback| with false.
// |callback| must not be null.
// Must be called on the UI thread.
- void GetCacheEntryOnUIThread(const std::string& resource_id,
+ void GetCacheEntryOnUIThread(const std::string& id,
const GetCacheEntryCallback& callback);
- // Gets the cache entry by the given resource ID.
+ // Gets the cache entry by the given ID.
// See also GetCacheEntryOnUIThread().
- bool GetCacheEntry(const std::string& resource_id,
- FileCacheEntry* entry);
+ bool GetCacheEntry(const std::string& id, FileCacheEntry* entry);
// Runs Iterate() with |iteration_callback| on |blocking_task_runner_| and
// runs |completion_callback| upon completion.
@@ -122,28 +121,27 @@ class FileCache {
// the result asynchronously.
// |callback| must not be null.
// Must be called on the UI thread.
- void GetFileOnUIThread(const std::string& resource_id,
+ void GetFileOnUIThread(const std::string& id,
const GetFileFromCacheCallback& callback);
- // Checks if file corresponding to |resource_id| exists in cache, and returns
+ // Checks if file corresponding to |id| exists in cache, and returns
// FILE_ERROR_OK with |cache_file_path| storing the path to the file.
// |cache_file_path| must not be null.
- FileError GetFile(const std::string& resource_id,
- base::FilePath* cache_file_path);
+ FileError GetFile(const std::string& id, base::FilePath* cache_file_path);
// Runs Store() on |blocking_task_runner_|, and calls |callback| with
// the result asynchronously.
// |callback| must not be null.
// Must be called on the UI thread.
- void StoreOnUIThread(const std::string& resource_id,
+ void StoreOnUIThread(const std::string& id,
const std::string& md5,
const base::FilePath& source_path,
FileOperationType file_operation_type,
const FileOperationCallback& callback);
// Stores |source_path| as a cache of the remote content of the file
- // with |resource_id| and |md5|.
- FileError Store(const std::string& resource_Id,
+ // with |id| and |md5|.
+ FileError Store(const std::string& id,
const std::string& md5,
const base::FilePath& source_path,
FileOperationType file_operation_type);
@@ -152,27 +150,27 @@ class FileCache {
// asynchronously.
// |callback| must not be null.
// Must be called on the UI thread.
- void PinOnUIThread(const std::string& resource_id,
+ void PinOnUIThread(const std::string& id,
const FileOperationCallback& callback);
// Pins the specified entry.
- FileError Pin(const std::string& resource_id);
+ FileError Pin(const std::string& id);
// Runs Unpin() on |blocking_task_runner_|, and calls |callback| with the
// result asynchronously.
// |callback| must not be null.
// Must be called on the UI thread.
- void UnpinOnUIThread(const std::string& resource_id,
+ void UnpinOnUIThread(const std::string& id,
const FileOperationCallback& callback);
// Unpins the specified entry.
- FileError Unpin(const std::string& resource_id);
+ FileError Unpin(const std::string& id);
- // Sets the state of the cache entry corresponding to |resource_id| as
+ // Sets the state of the cache entry corresponding to |id| as
// mounted.
// |callback| must not be null.
// Must be called on the UI thread.
- void MarkAsMountedOnUIThread(const std::string& resource_id,
+ void MarkAsMountedOnUIThread(const std::string& id,
const GetFileFromCacheCallback& callback);
// Set the state of the cache entry corresponding to file_path as unmounted.
@@ -185,25 +183,24 @@ class FileCache {
// result asynchronously.
// |callback| must not be null.
// Must be called on the UI thread.
- void MarkDirtyOnUIThread(const std::string& resource_id,
+ void MarkDirtyOnUIThread(const std::string& id,
const FileOperationCallback& callback);
// Marks the specified entry dirty.
- FileError MarkDirty(const std::string& resource_id);
+ FileError MarkDirty(const std::string& id);
// Clears dirty state of the specified entry and updates its MD5.
- FileError ClearDirty(const std::string& resource_id,
- const std::string& md5);
+ FileError ClearDirty(const std::string& id, const std::string& md5);
// Runs Remove() on |blocking_task_runner_| and runs |callback| with the
// result.
// Must be called on the UI thread.
- void RemoveOnUIThread(const std::string& resource_id,
+ void RemoveOnUIThread(const std::string& id,
const FileOperationCallback& callback);
// Removes the specified cache entry and delete cache files if available.
// Synchronous version of RemoveOnUIThread().
- FileError Remove(const std::string& resource_id);
+ FileError Remove(const std::string& id);
// Does the following:
// - remove all the files in the cache directory.
@@ -229,7 +226,7 @@ class FileCache {
// Returns absolute path of the file if it were cached or to be cached.
//
// Can be called on any thread.
- base::FilePath GetCacheFilePath(const std::string& resource_id) const;
+ base::FilePath GetCacheFilePath(const std::string& id) const;
// Checks whether the current thread is on the right sequenced worker pool
// with the right sequence ID. If not, DCHECK will fail.
@@ -241,13 +238,13 @@ class FileCache {
// Used to implement Store and StoreLocallyModifiedOnUIThread.
// TODO(hidehiko): Merge this method with Store(), after
// StoreLocallyModifiedOnUIThread is removed.
- FileError StoreInternal(const std::string& resource_id,
+ FileError StoreInternal(const std::string& id,
const std::string& md5,
const base::FilePath& source_path,
FileOperationType file_operation_type);
// Used to implement MarkAsMountedOnUIThread.
- FileError MarkAsMounted(const std::string& resource_id,
+ FileError MarkAsMounted(const std::string& id,
base::FilePath* cache_file_path);
// Used to implement MarkAsUnmountedOnUIThread.
@@ -260,7 +257,7 @@ class FileCache {
// bytes, while keeping kMinFreeSpace bytes on the disk.
bool HasEnoughSpaceFor(int64 num_bytes, const base::FilePath& path);
- // Renames cache files from old "resource_id.md5" format to the new format.
+ // Renames cache files from old "id.md5" format to the new format.
// TODO(hashimoto): Remove this method at some point.
void RenameCacheFilesToNewFormat();
@@ -272,7 +269,7 @@ class FileCache {
FreeDiskSpaceGetterInterface* free_disk_space_getter_; // Not owned.
- // Resource IDs of files marked mounted.
+ // IDs of files marked mounted.
std::set<std::string> mounted_files_;
// Note: This should remain the last member so it'll be destroyed and
diff --git a/chrome/browser/chromeos/drive/file_cache_unittest.cc b/chrome/browser/chromeos/drive/file_cache_unittest.cc
index ecd79a1..7c7b947 100644
--- a/chrome/browser/chromeos/drive/file_cache_unittest.cc
+++ b/chrome/browser/chromeos/drive/file_cache_unittest.cc
@@ -36,11 +36,11 @@ enum TestFileCacheState {
};
// Copies results from Iterate().
-void OnIterate(std::vector<std::string>* out_resource_ids,
+void OnIterate(std::vector<std::string>* out_ids,
std::vector<FileCacheEntry>* out_cache_entries,
- const std::string& resource_id,
+ const std::string& id,
const FileCacheEntry& cache_entry) {
- out_resource_ids->push_back(resource_id);
+ out_ids->push_back(id);
out_cache_entries->push_back(cache_entry);
}
@@ -105,11 +105,10 @@ class FileCacheTestOnUIThread : public testing::Test {
ASSERT_TRUE(success);
}
- void TestGetFile(const std::string& resource_id,
- FileError expected_error) {
+ void TestGetFile(const std::string& id, FileError expected_error) {
FileError error = FILE_ERROR_OK;
base::FilePath cache_file_path;
- cache_->GetFileOnUIThread(resource_id,
+ cache_->GetFileOnUIThread(id,
google_apis::test_util::CreateCopyResultCallback(
&error, &cache_file_path));
test_util::RunBlockingPoolTask();
@@ -117,14 +116,14 @@ class FileCacheTestOnUIThread : public testing::Test {
EXPECT_EQ(expected_error, error);
if (error == FILE_ERROR_OK) {
// Verify filename of |cache_file_path|.
- EXPECT_EQ(util::EscapeCacheFileName(resource_id),
+ EXPECT_EQ(util::EscapeCacheFileName(id),
cache_file_path.BaseName().AsUTF8Unsafe());
} else {
EXPECT_TRUE(cache_file_path.empty());
}
}
- void TestStoreToCache(const std::string& resource_id,
+ void TestStoreToCache(const std::string& id,
const std::string& md5,
const base::FilePath& source_path,
FileError expected_error,
@@ -134,45 +133,44 @@ class FileCacheTestOnUIThread : public testing::Test {
FileError error = FILE_ERROR_OK;
cache_->StoreOnUIThread(
- resource_id, md5, source_path,
+ id, md5, source_path,
FileCache::FILE_OPERATION_COPY,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
if (error == FILE_ERROR_OK) {
FileCacheEntry cache_entry;
- EXPECT_TRUE(GetCacheEntryFromOriginThread(resource_id, &cache_entry));
+ EXPECT_TRUE(GetCacheEntryFromOriginThread(id, &cache_entry));
EXPECT_EQ(md5, cache_entry.md5());
}
- VerifyCacheFileState(error, resource_id);
+ VerifyCacheFileState(error, id);
}
- void TestRemoveFromCache(const std::string& resource_id,
- FileError expected_error) {
+ void TestRemoveFromCache(const std::string& id, FileError expected_error) {
expected_error_ = expected_error;
FileError error = FILE_ERROR_OK;
cache_->RemoveOnUIThread(
- resource_id,
+ id,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
- VerifyRemoveFromCache(error, resource_id);
+ VerifyRemoveFromCache(error, id);
}
- void VerifyRemoveFromCache(FileError error, const std::string& resource_id) {
+ void VerifyRemoveFromCache(FileError error, const std::string& id) {
EXPECT_EQ(expected_error_, error);
FileCacheEntry cache_entry;
- if (!GetCacheEntryFromOriginThread(resource_id, &cache_entry)) {
+ if (!GetCacheEntryFromOriginThread(id, &cache_entry)) {
EXPECT_EQ(FILE_ERROR_OK, error);
- const base::FilePath path = cache_->GetCacheFilePath(resource_id);
+ const base::FilePath path = cache_->GetCacheFilePath(id);
EXPECT_FALSE(base::PathExists(path));
}
}
- void TestPin(const std::string& resource_id,
+ void TestPin(const std::string& id,
FileError expected_error,
int expected_cache_state) {
expected_error_ = expected_error;
@@ -180,13 +178,13 @@ class FileCacheTestOnUIThread : public testing::Test {
FileError error = FILE_ERROR_OK;
cache_->PinOnUIThread(
- resource_id,
+ id,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
- VerifyCacheFileState(error, resource_id);
+ VerifyCacheFileState(error, id);
}
- void TestUnpin(const std::string& resource_id,
+ void TestUnpin(const std::string& id,
FileError expected_error,
int expected_cache_state) {
expected_error_ = expected_error;
@@ -194,13 +192,13 @@ class FileCacheTestOnUIThread : public testing::Test {
FileError error = FILE_ERROR_OK;
cache_->UnpinOnUIThread(
- resource_id,
+ id,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
- VerifyCacheFileState(error, resource_id);
+ VerifyCacheFileState(error, id);
}
- void TestMarkDirty(const std::string& resource_id,
+ void TestMarkDirty(const std::string& id,
FileError expected_error,
int expected_cache_state) {
expected_error_ = expected_error;
@@ -208,28 +206,28 @@ class FileCacheTestOnUIThread : public testing::Test {
FileError error = FILE_ERROR_OK;
cache_->MarkDirtyOnUIThread(
- resource_id,
+ id,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
- VerifyCacheFileState(error, resource_id);
+ VerifyCacheFileState(error, id);
// Verify filename.
if (error == FILE_ERROR_OK) {
base::FilePath cache_file_path;
cache_->GetFileOnUIThread(
- resource_id,
+ id,
google_apis::test_util::CreateCopyResultCallback(
&error, &cache_file_path));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
- EXPECT_EQ(util::EscapeCacheFileName(resource_id),
+ EXPECT_EQ(util::EscapeCacheFileName(id),
cache_file_path.BaseName().AsUTF8Unsafe());
}
}
- void TestClearDirty(const std::string& resource_id,
+ void TestClearDirty(const std::string& id,
const std::string& md5,
FileError expected_error,
int expected_cache_state) {
@@ -242,42 +240,42 @@ class FileCacheTestOnUIThread : public testing::Test {
FROM_HERE,
base::Bind(&FileCache::ClearDirty,
base::Unretained(cache_.get()),
- resource_id,
+ id,
md5),
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
if (error == FILE_ERROR_OK) {
FileCacheEntry cache_entry;
- EXPECT_TRUE(GetCacheEntryFromOriginThread(resource_id, &cache_entry));
+ EXPECT_TRUE(GetCacheEntryFromOriginThread(id, &cache_entry));
EXPECT_EQ(md5, cache_entry.md5());
}
- VerifyCacheFileState(error, resource_id);
+ VerifyCacheFileState(error, id);
}
- void TestMarkAsMounted(const std::string& resource_id,
+ void TestMarkAsMounted(const std::string& id,
FileError expected_error,
int expected_cache_state) {
expected_error_ = expected_error;
expected_cache_state_ = expected_cache_state;
FileCacheEntry entry;
- EXPECT_TRUE(GetCacheEntryFromOriginThread(resource_id, &entry));
+ EXPECT_TRUE(GetCacheEntryFromOriginThread(id, &entry));
FileError error = FILE_ERROR_OK;
base::FilePath cache_file_path;
cache_->MarkAsMountedOnUIThread(
- resource_id,
+ id,
google_apis::test_util::CreateCopyResultCallback(
&error, &cache_file_path));
test_util::RunBlockingPoolTask();
EXPECT_TRUE(base::PathExists(cache_file_path));
- EXPECT_EQ(cache_file_path, cache_->GetCacheFilePath(resource_id));
+ EXPECT_EQ(cache_file_path, cache_->GetCacheFilePath(id));
}
- void TestMarkAsUnmounted(const std::string& resource_id,
+ void TestMarkAsUnmounted(const std::string& id,
const base::FilePath& file_path,
FileError expected_error,
int expected_cache_state) {
@@ -292,23 +290,23 @@ class FileCacheTestOnUIThread : public testing::Test {
base::FilePath cache_file_path;
cache_->GetFileOnUIThread(
- resource_id,
+ id,
google_apis::test_util::CreateCopyResultCallback(
&error, &cache_file_path));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_TRUE(base::PathExists(cache_file_path));
- EXPECT_EQ(cache_file_path, cache_->GetCacheFilePath(resource_id));
+ EXPECT_EQ(cache_file_path, cache_->GetCacheFilePath(id));
}
- void VerifyCacheFileState(FileError error, const std::string& resource_id) {
+ void VerifyCacheFileState(FileError error, const std::string& id) {
EXPECT_EQ(expected_error_, error);
// Verify cache map.
FileCacheEntry cache_entry;
const bool cache_entry_found =
- GetCacheEntryFromOriginThread(resource_id, &cache_entry);
+ GetCacheEntryFromOriginThread(id, &cache_entry);
if ((expected_cache_state_ & TEST_CACHE_STATE_PRESENT) ||
(expected_cache_state_ & TEST_CACHE_STATE_PINNED)) {
ASSERT_TRUE(cache_entry_found);
@@ -323,33 +321,32 @@ class FileCacheTestOnUIThread : public testing::Test {
}
// Verify actual cache file.
- base::FilePath dest_path = cache_->GetCacheFilePath(resource_id);
+ base::FilePath dest_path = cache_->GetCacheFilePath(id);
EXPECT_EQ((expected_cache_state_ & TEST_CACHE_STATE_PRESENT) != 0,
base::PathExists(dest_path));
}
// Helper function to call GetCacheEntry from origin thread.
- bool GetCacheEntryFromOriginThread(const std::string& resource_id,
+ bool GetCacheEntryFromOriginThread(const std::string& id,
FileCacheEntry* cache_entry) {
bool result = false;
cache_->GetCacheEntryOnUIThread(
- resource_id,
+ id,
google_apis::test_util::CreateCopyResultCallback(&result, cache_entry));
test_util::RunBlockingPoolTask();
return result;
}
- // Returns true if the cache entry exists for the given resource ID.
- bool CacheEntryExists(const std::string& resource_id) {
+ // Returns true if the cache entry exists for the given ID.
+ bool CacheEntryExists(const std::string& id) {
FileCacheEntry cache_entry;
- return GetCacheEntryFromOriginThread(resource_id, &cache_entry);
+ return GetCacheEntryFromOriginThread(id, &cache_entry);
}
- // Returns the number of the cache files with name <resource_id>, and Confirm
+ // Returns the number of the cache files with name <id>, and Confirm
// that they have the <md5>. This should return 1 or 0.
- size_t CountCacheFiles(const std::string& resource_id,
- const std::string& md5) {
- base::FilePath path = cache_->GetCacheFilePath(resource_id);
+ size_t CountCacheFiles(const std::string& id, const std::string& md5) {
+ base::FilePath path = cache_->GetCacheFilePath(id);
base::FileEnumerator enumerator(path.DirName(),
false, // recursive
base::FileEnumerator::FILES,
@@ -358,7 +355,7 @@ class FileCacheTestOnUIThread : public testing::Test {
for (base::FilePath current = enumerator.Next(); !current.empty();
current = enumerator.Next()) {
++num_files_found;
- EXPECT_EQ(util::EscapeCacheFileName(resource_id),
+ EXPECT_EQ(util::EscapeCacheFileName(id),
current.BaseName().AsUTF8Unsafe());
}
return num_files_found;
@@ -380,221 +377,219 @@ class FileCacheTestOnUIThread : public testing::Test {
};
TEST_F(FileCacheTestOnUIThread, StoreToCacheSimple) {
- std::string resource_id("pdf:1a2b");
+ std::string id("pdf:1a2b");
std::string md5("abcdef0123456789");
// Store an existing file.
- TestStoreToCache(resource_id, md5, dummy_file_path_,
+ TestStoreToCache(id, md5, dummy_file_path_,
FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
- // Store a non-existent file to the same |resource_id| and |md5|.
- TestStoreToCache(resource_id, md5,
+ // Store a non-existent file to the same |id| and |md5|.
+ TestStoreToCache(id, md5,
base::FilePath::FromUTF8Unsafe("non_existent_file"),
FILE_ERROR_FAILED,
TEST_CACHE_STATE_PRESENT);
- // Store a different existing file to the same |resource_id| but different
+ // Store a different existing file to the same |id| but different
// |md5|.
md5 = "new_md5";
- TestStoreToCache(resource_id, md5, dummy_file_path_,
+ TestStoreToCache(id, md5, dummy_file_path_,
FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
- // Verify that there's only one file with name <resource_id>, i.e. previously
+ // Verify that there's only one file with name <id>, i.e. previously
// cached file with the different md5 should be deleted.
- EXPECT_EQ(1U, CountCacheFiles(resource_id, md5));
+ EXPECT_EQ(1U, CountCacheFiles(id, md5));
}
TEST_F(FileCacheTestOnUIThread, GetFromCacheSimple) {
- std::string resource_id("pdf:1a2b");
+ std::string id("pdf:1a2b");
std::string md5("abcdef0123456789");
// First store a file to cache.
- TestStoreToCache(resource_id, md5, dummy_file_path_,
+ TestStoreToCache(id, md5, dummy_file_path_,
FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
// Then try to get the existing file from cache.
- TestGetFile(resource_id, FILE_ERROR_OK);
+ TestGetFile(id, FILE_ERROR_OK);
- // Get file from cache with different resource id.
- resource_id = "document:1a2b";
- TestGetFile(resource_id, FILE_ERROR_NOT_FOUND);
+ // Get file from cache with different ID.
+ id = "document:1a2b";
+ TestGetFile(id, FILE_ERROR_NOT_FOUND);
}
TEST_F(FileCacheTestOnUIThread, RemoveFromCacheSimple) {
- // Use alphanumeric characters for resource id.
- std::string resource_id("pdf:1a2b");
+ std::string id("pdf:1a2b");
std::string md5("abcdef0123456789");
// First store a file to cache.
- TestStoreToCache(resource_id, md5, dummy_file_path_,
+ TestStoreToCache(id, md5, dummy_file_path_,
FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
// Then try to remove existing file from cache.
- TestRemoveFromCache(resource_id, FILE_ERROR_OK);
+ TestRemoveFromCache(id, FILE_ERROR_OK);
- // Repeat using non-alphanumeric characters for resource id, including '.'
+ // Repeat using non-alphanumeric characters for ID, including '.'
// which is an extension separator.
- resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?";
- TestStoreToCache(resource_id, md5, dummy_file_path_,
+ id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?";
+ TestStoreToCache(id, md5, dummy_file_path_,
FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
- TestRemoveFromCache(resource_id, FILE_ERROR_OK);
+ TestRemoveFromCache(id, FILE_ERROR_OK);
}
TEST_F(FileCacheTestOnUIThread, PinAndUnpin) {
- std::string resource_id("pdf:1a2b");
+ std::string id("pdf:1a2b");
std::string md5("abcdef0123456789");
// First store a file to cache.
- TestStoreToCache(resource_id, md5, dummy_file_path_,
+ TestStoreToCache(id, md5, dummy_file_path_,
FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
// Pin the existing file in cache.
- TestPin(resource_id, FILE_ERROR_OK,
+ TestPin(id, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_PINNED);
// Unpin the existing file in cache.
- TestUnpin(resource_id, FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
+ TestUnpin(id, FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
// Pin back the same existing file in cache.
- TestPin(resource_id, FILE_ERROR_OK,
+ TestPin(id, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_PINNED);
// Pin a non-existent file in cache.
- resource_id = "document:1a2b";
+ id = "document:1a2b";
- TestPin(resource_id, FILE_ERROR_OK, TEST_CACHE_STATE_PINNED);
+ TestPin(id, FILE_ERROR_OK, TEST_CACHE_STATE_PINNED);
// Unpin the previously pinned non-existent file in cache.
- TestUnpin(resource_id, FILE_ERROR_OK, TEST_CACHE_STATE_NONE);
+ TestUnpin(id, FILE_ERROR_OK, TEST_CACHE_STATE_NONE);
// Unpin a file that doesn't exist in cache and is not pinned, i.e. cache
// has zero knowledge of the file.
- resource_id = "not-in-cache:1a2b";
+ id = "not-in-cache:1a2b";
- TestUnpin(resource_id, FILE_ERROR_NOT_FOUND, TEST_CACHE_STATE_NONE);
+ TestUnpin(id, FILE_ERROR_NOT_FOUND, TEST_CACHE_STATE_NONE);
}
TEST_F(FileCacheTestOnUIThread, StoreToCachePinned) {
- std::string resource_id("pdf:1a2b");
+ std::string id("pdf:1a2b");
std::string md5("abcdef0123456789");
// Pin a non-existent file.
- TestPin(resource_id, FILE_ERROR_OK, TEST_CACHE_STATE_PINNED);
+ TestPin(id, FILE_ERROR_OK, TEST_CACHE_STATE_PINNED);
// Store an existing file to a previously pinned file.
- TestStoreToCache(resource_id, md5, dummy_file_path_, FILE_ERROR_OK,
+ TestStoreToCache(id, md5, dummy_file_path_, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_PINNED);
// Store a non-existent file to a previously pinned and stored file.
- TestStoreToCache(resource_id, md5,
+ TestStoreToCache(id, md5,
base::FilePath::FromUTF8Unsafe("non_existent_file"),
FILE_ERROR_FAILED,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_PINNED);
}
TEST_F(FileCacheTestOnUIThread, GetFromCachePinned) {
- std::string resource_id("pdf:1a2b");
+ std::string id("pdf:1a2b");
std::string md5("abcdef0123456789");
// Pin a non-existent file.
- TestPin(resource_id, FILE_ERROR_OK, TEST_CACHE_STATE_PINNED);
+ TestPin(id, FILE_ERROR_OK, TEST_CACHE_STATE_PINNED);
// Get the non-existent pinned file from cache.
- TestGetFile(resource_id, FILE_ERROR_NOT_FOUND);
+ TestGetFile(id, FILE_ERROR_NOT_FOUND);
// Store an existing file to the previously pinned non-existent file.
- TestStoreToCache(resource_id, md5, dummy_file_path_, FILE_ERROR_OK,
+ TestStoreToCache(id, md5, dummy_file_path_, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_PINNED);
// Get the previously pinned and stored file from cache.
- TestGetFile(resource_id, FILE_ERROR_OK);
+ TestGetFile(id, FILE_ERROR_OK);
}
TEST_F(FileCacheTestOnUIThread, RemoveFromCachePinned) {
- // Use alphanumeric characters for resource_id.
- std::string resource_id("pdf:1a2b");
+ std::string id("pdf:1a2b");
std::string md5("abcdef0123456789");
// Store a file to cache, and pin it.
- TestStoreToCache(resource_id, md5, dummy_file_path_,
+ TestStoreToCache(id, md5, dummy_file_path_,
FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
- TestPin(resource_id, FILE_ERROR_OK,
+ TestPin(id, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_PINNED);
- // Remove |resource_id| from cache.
- TestRemoveFromCache(resource_id, FILE_ERROR_OK);
+ // Remove |id| from cache.
+ TestRemoveFromCache(id, FILE_ERROR_OK);
- // Repeat using non-alphanumeric characters for resource id, including '.'
+ // Use non-alphanumeric characters for ID, including '.'
// which is an extension separator.
- resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?";
+ id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?";
- TestStoreToCache(resource_id, md5, dummy_file_path_,
+ TestStoreToCache(id, md5, dummy_file_path_,
FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
- TestPin(resource_id, FILE_ERROR_OK,
+ TestPin(id, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_PINNED);
- TestRemoveFromCache(resource_id, FILE_ERROR_OK);
+ TestRemoveFromCache(id, FILE_ERROR_OK);
}
TEST_F(FileCacheTestOnUIThread, DirtyCacheSimple) {
- std::string resource_id("pdf:1a2b");
+ std::string id("pdf:1a2b");
std::string md5("abcdef0123456789");
// First store a file to cache.
- TestStoreToCache(resource_id, md5, dummy_file_path_,
+ TestStoreToCache(id, md5, dummy_file_path_,
FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
// Mark the file dirty.
- TestMarkDirty(resource_id, FILE_ERROR_OK,
+ TestMarkDirty(id, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_DIRTY);
// Clear dirty state of the file.
- TestClearDirty(resource_id, md5, FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
+ TestClearDirty(id, md5, FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
}
TEST_F(FileCacheTestOnUIThread, DirtyCachePinned) {
- std::string resource_id("pdf:1a2b");
+ std::string id("pdf:1a2b");
std::string md5("abcdef0123456789");
// First store a file to cache and pin it.
- TestStoreToCache(resource_id, md5, dummy_file_path_,
+ TestStoreToCache(id, md5, dummy_file_path_,
FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
- TestPin(resource_id, FILE_ERROR_OK,
+ TestPin(id, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_PINNED);
// Mark the file dirty.
- TestMarkDirty(resource_id, FILE_ERROR_OK,
+ TestMarkDirty(id, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT |
TEST_CACHE_STATE_DIRTY |
TEST_CACHE_STATE_PINNED);
// Clear dirty state of the file.
- TestClearDirty(resource_id, md5, FILE_ERROR_OK,
+ TestClearDirty(id, md5, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_PINNED);
}
TEST_F(FileCacheTestOnUIThread, PinAndUnpinDirtyCache) {
- std::string resource_id("pdf:1a2b");
+ std::string id("pdf:1a2b");
std::string md5("abcdef0123456789");
// First store a file to cache and mark it as dirty.
- TestStoreToCache(resource_id, md5, dummy_file_path_,
+ TestStoreToCache(id, md5, dummy_file_path_,
FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
- TestMarkDirty(resource_id, FILE_ERROR_OK,
+ TestMarkDirty(id, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_DIRTY);
// Verifies dirty file exists.
base::FilePath dirty_path;
FileError error = FILE_ERROR_FAILED;
cache_->GetFileOnUIThread(
- resource_id,
+ id,
google_apis::test_util::CreateCopyResultCallback(&error, &dirty_path));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_TRUE(base::PathExists(dirty_path));
// Pin the dirty file.
- TestPin(resource_id, FILE_ERROR_OK,
+ TestPin(id, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT |
TEST_CACHE_STATE_DIRTY |
TEST_CACHE_STATE_PINNED);
@@ -603,7 +598,7 @@ TEST_F(FileCacheTestOnUIThread, PinAndUnpinDirtyCache) {
EXPECT_TRUE(base::PathExists(dirty_path));
// Unpin the dirty file.
- TestUnpin(resource_id, FILE_ERROR_OK,
+ TestUnpin(id, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_DIRTY);
// Verify dirty file still exist at the same pathname.
@@ -611,67 +606,66 @@ TEST_F(FileCacheTestOnUIThread, PinAndUnpinDirtyCache) {
}
TEST_F(FileCacheTestOnUIThread, DirtyCacheRepetitive) {
- std::string resource_id("pdf:1a2b");
+ std::string id("pdf:1a2b");
std::string md5("abcdef0123456789");
// First store a file to cache.
- TestStoreToCache(resource_id, md5, dummy_file_path_,
+ TestStoreToCache(id, md5, dummy_file_path_,
FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
// Mark the file dirty.
- TestMarkDirty(resource_id, FILE_ERROR_OK,
+ TestMarkDirty(id, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_DIRTY);
// Again, mark the file dirty. Nothing should change.
- TestMarkDirty(resource_id, FILE_ERROR_OK,
+ TestMarkDirty(id, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_DIRTY);
// Clear dirty state of the file.
- TestClearDirty(resource_id, md5, FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
+ TestClearDirty(id, md5, FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
// Again, clear dirty state of the file, which is no longer dirty.
- TestClearDirty(resource_id, md5, FILE_ERROR_INVALID_OPERATION,
+ TestClearDirty(id, md5, FILE_ERROR_INVALID_OPERATION,
TEST_CACHE_STATE_PRESENT);
}
TEST_F(FileCacheTestOnUIThread, DirtyCacheInvalid) {
- std::string resource_id("pdf:1a2b");
+ std::string id("pdf:1a2b");
std::string md5("abcdef0123456789");
// Mark a non-existent file dirty.
- TestMarkDirty(resource_id, FILE_ERROR_NOT_FOUND, TEST_CACHE_STATE_NONE);
+ TestMarkDirty(id, FILE_ERROR_NOT_FOUND, TEST_CACHE_STATE_NONE);
// Clear dirty state of a non-existent file.
- TestClearDirty(resource_id, md5, FILE_ERROR_NOT_FOUND, TEST_CACHE_STATE_NONE);
+ TestClearDirty(id, md5, FILE_ERROR_NOT_FOUND, TEST_CACHE_STATE_NONE);
// Store a file to cache.
- TestStoreToCache(resource_id, md5, dummy_file_path_,
+ TestStoreToCache(id, md5, dummy_file_path_,
FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
// Clear dirty state of a non-dirty existing file.
- TestClearDirty(resource_id, md5, FILE_ERROR_INVALID_OPERATION,
+ TestClearDirty(id, md5, FILE_ERROR_INVALID_OPERATION,
TEST_CACHE_STATE_PRESENT);
- // Mark an existing file dirty, then store a new file to the same resource id
+ // Mark an existing file dirty, then store a new file to the same ID
// but different md5, which should fail.
- TestMarkDirty(resource_id, FILE_ERROR_OK,
+ TestMarkDirty(id, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_DIRTY);
md5 = "new_md5";
- TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_IN_USE,
+ TestStoreToCache(id, md5, dummy_file_path_, FILE_ERROR_IN_USE,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_DIRTY);
}
TEST_F(FileCacheTestOnUIThread, RemoveFromDirtyCache) {
- std::string resource_id("pdf:1a2b");
+ std::string id("pdf:1a2b");
std::string md5("abcdef0123456789");
// Store a file to cache, pin it, mark it dirty and commit it.
- TestStoreToCache(resource_id, md5, dummy_file_path_,
+ TestStoreToCache(id, md5, dummy_file_path_,
FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
- TestPin(resource_id, FILE_ERROR_OK,
+ TestPin(id, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_PINNED);
- TestMarkDirty(resource_id, FILE_ERROR_OK,
+ TestMarkDirty(id, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT |
TEST_CACHE_STATE_PINNED |
TEST_CACHE_STATE_DIRTY);
@@ -680,39 +674,38 @@ TEST_F(FileCacheTestOnUIThread, RemoveFromDirtyCache) {
// FileCache::Remove. Upper layer cache clearance functions like
// FreeDiskSpaceIfNeededFor() and RemoveStaleCacheFiles() takes care of
// securing dirty files.
- TestRemoveFromCache(resource_id, FILE_ERROR_OK);
+ TestRemoveFromCache(id, FILE_ERROR_OK);
}
TEST_F(FileCacheTestOnUIThread, MountUnmount) {
- std::string resource_id("pdf:1a2b");
+ std::string id("pdf:1a2b");
std::string md5("abcdef0123456789");
// First store a file to cache.
- TestStoreToCache(resource_id, md5, dummy_file_path_,
+ TestStoreToCache(id, md5, dummy_file_path_,
FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
// Mark the file mounted.
- TestMarkAsMounted(resource_id, FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
- EXPECT_TRUE(CacheEntryExists(resource_id));
+ TestMarkAsMounted(id, FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
+ EXPECT_TRUE(CacheEntryExists(id));
// Try to remove the file.
- TestRemoveFromCache(resource_id, FILE_ERROR_IN_USE);
+ TestRemoveFromCache(id, FILE_ERROR_IN_USE);
// Clear mounted state of the file.
base::FilePath file_path;
FileError error = FILE_ERROR_FAILED;
cache_->GetFileOnUIThread(
- resource_id,
+ id,
google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
- TestMarkAsUnmounted(resource_id, file_path, FILE_ERROR_OK,
- TEST_CACHE_STATE_PRESENT);
- EXPECT_TRUE(CacheEntryExists(resource_id));
+ TestMarkAsUnmounted(id, file_path, FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
+ EXPECT_TRUE(CacheEntryExists(id));
// Try to remove the file.
- TestRemoveFromCache(resource_id, FILE_ERROR_OK);
+ TestRemoveFromCache(id, FILE_ERROR_OK);
}
TEST_F(FileCacheTestOnUIThread, Iterate) {
@@ -721,38 +714,38 @@ TEST_F(FileCacheTestOnUIThread, Iterate) {
ASSERT_TRUE(test_util::PrepareTestCacheResources(cache_.get(),
cache_resources));
- std::vector<std::string> resource_ids;
+ std::vector<std::string> ids;
std::vector<FileCacheEntry> cache_entries;
bool completed = false;
cache_->IterateOnUIThread(
- base::Bind(&OnIterate, &resource_ids, &cache_entries),
+ base::Bind(&OnIterate, &ids, &cache_entries),
base::Bind(&OnIterateCompleted, &completed));
test_util::RunBlockingPoolTask();
ASSERT_TRUE(completed);
- sort(resource_ids.begin(), resource_ids.end());
- ASSERT_EQ(6U, resource_ids.size());
- EXPECT_EQ("dirty:existing", resource_ids[0]);
- EXPECT_EQ("dirty_and_pinned:existing", resource_ids[1]);
- EXPECT_EQ("pinned:existing", resource_ids[2]);
- EXPECT_EQ("pinned:non-existent", resource_ids[3]);
- EXPECT_EQ("tmp:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?", resource_ids[4]);
- EXPECT_EQ("tmp:resource_id", resource_ids[5]);
+ sort(ids.begin(), ids.end());
+ ASSERT_EQ(6U, ids.size());
+ EXPECT_EQ("dirty:existing", ids[0]);
+ EXPECT_EQ("dirty_and_pinned:existing", ids[1]);
+ EXPECT_EQ("pinned:existing", ids[2]);
+ EXPECT_EQ("pinned:non-existent", ids[3]);
+ EXPECT_EQ("tmp:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?", ids[4]);
+ EXPECT_EQ("tmp:resource_id", ids[5]);
ASSERT_EQ(6U, cache_entries.size());
}
TEST_F(FileCacheTestOnUIThread, ClearAll) {
- std::string resource_id("pdf:1a2b");
+ std::string id("pdf:1a2b");
std::string md5("abcdef0123456789");
// Store an existing file.
- TestStoreToCache(resource_id, md5, dummy_file_path_,
+ TestStoreToCache(id, md5, dummy_file_path_,
FILE_ERROR_OK, TEST_CACHE_STATE_PRESENT);
// Verify that there's only one cached file.
- EXPECT_EQ(1U, CountCacheFiles(resource_id, md5));
+ EXPECT_EQ(1U, CountCacheFiles(id, md5));
// Clear cache.
bool success = false;
@@ -763,40 +756,40 @@ TEST_F(FileCacheTestOnUIThread, ClearAll) {
// Verify that all the cache is removed.
expected_error_ = FILE_ERROR_OK;
- VerifyRemoveFromCache(FILE_ERROR_OK, resource_id);
- EXPECT_EQ(0U, CountCacheFiles(resource_id, md5));
+ VerifyRemoveFromCache(FILE_ERROR_OK, id);
+ EXPECT_EQ(0U, CountCacheFiles(id, md5));
}
TEST_F(FileCacheTestOnUIThread, StoreToCacheNoSpace) {
fake_free_disk_space_getter_->set_default_value(0);
- std::string resource_id("pdf:1a2b");
+ std::string id("pdf:1a2b");
std::string md5("abcdef0123456789");
// Try to store an existing file.
- TestStoreToCache(resource_id, md5, dummy_file_path_,
+ TestStoreToCache(id, md5, dummy_file_path_,
FILE_ERROR_NO_LOCAL_SPACE,
TEST_CACHE_STATE_NONE);
// Verify that there's no files added.
- EXPECT_EQ(0U, CountCacheFiles(resource_id, md5));
+ EXPECT_EQ(0U, CountCacheFiles(id, md5));
}
TEST_F(FileCacheTestOnUIThread, UpdatePinnedCache) {
- std::string resource_id("pdf:1a2b");
+ std::string id("pdf:1a2b");
std::string md5("abcdef0123456789");
std::string md5_modified("aaaaaa0000000000");
// Store an existing file.
- TestStoreToCache(resource_id, md5, dummy_file_path_, FILE_ERROR_OK,
+ TestStoreToCache(id, md5, dummy_file_path_, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT);
// Pin the file.
- TestPin(resource_id, FILE_ERROR_OK,
+ TestPin(id, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_PINNED);
// Store the file with a modified content and md5. It should stay pinned.
- TestStoreToCache(resource_id, md5_modified, dummy_file_path_, FILE_ERROR_OK,
+ TestStoreToCache(id, md5_modified, dummy_file_path_, FILE_ERROR_OK,
TEST_CACHE_STATE_PRESENT | TEST_CACHE_STATE_PINNED);
}
@@ -873,21 +866,21 @@ TEST_F(FileCacheTest, FreeDiskSpaceIfNeededFor) {
ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), &src_file));
// Store a file as a 'temporary' file and remember the path.
- const std::string resource_id_tmp = "id_tmp", md5_tmp = "md5_tmp";
+ const std::string id_tmp = "id_tmp", md5_tmp = "md5_tmp";
ASSERT_EQ(FILE_ERROR_OK,
- cache_->Store(resource_id_tmp, md5_tmp, src_file,
+ cache_->Store(id_tmp, md5_tmp, src_file,
FileCache::FILE_OPERATION_COPY));
base::FilePath tmp_path;
- ASSERT_EQ(FILE_ERROR_OK, cache_->GetFile(resource_id_tmp, &tmp_path));
+ ASSERT_EQ(FILE_ERROR_OK, cache_->GetFile(id_tmp, &tmp_path));
// Store a file as a pinned file and remember the path.
- const std::string resource_id_pinned = "id_pinned", md5_pinned = "md5_pinned";
+ const std::string id_pinned = "id_pinned", md5_pinned = "md5_pinned";
ASSERT_EQ(FILE_ERROR_OK,
- cache_->Store(resource_id_pinned, md5_pinned, src_file,
+ cache_->Store(id_pinned, md5_pinned, src_file,
FileCache::FILE_OPERATION_COPY));
- ASSERT_EQ(FILE_ERROR_OK, cache_->Pin(resource_id_pinned));
+ ASSERT_EQ(FILE_ERROR_OK, cache_->Pin(id_pinned));
base::FilePath pinned_path;
- ASSERT_EQ(FILE_ERROR_OK, cache_->GetFile(resource_id_pinned, &pinned_path));
+ ASSERT_EQ(FILE_ERROR_OK, cache_->GetFile(id_pinned, &pinned_path));
// Call FreeDiskSpaceIfNeededFor().
fake_free_disk_space_getter_->set_default_value(test_util::kLotsOfSpace);
@@ -897,10 +890,10 @@ TEST_F(FileCacheTest, FreeDiskSpaceIfNeededFor) {
// Only 'temporary' file gets removed.
FileCacheEntry entry;
- EXPECT_FALSE(cache_->GetCacheEntry(resource_id_tmp, &entry));
+ EXPECT_FALSE(cache_->GetCacheEntry(id_tmp, &entry));
EXPECT_FALSE(base::PathExists(tmp_path));
- EXPECT_TRUE(cache_->GetCacheEntry(resource_id_pinned, &entry));
+ EXPECT_TRUE(cache_->GetCacheEntry(id_pinned, &entry));
EXPECT_TRUE(base::PathExists(pinned_path));
// Returns false when disk space cannot be freed.
@@ -912,7 +905,7 @@ TEST_F(FileCacheTest, RenameCacheFilesToNewFormat) {
const base::FilePath file_directory =
temp_dir_.path().Append(util::kCacheFileDirectory);
- // File with an old style "<resource ID>.<MD5>" name.
+ // File with an old style "<ID>.<MD5>" name.
ASSERT_TRUE(google_apis::test_util::WriteStringToFile(
file_directory.AppendASCII("id_koo.md5"), "koo"));