summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-14 06:25:45 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-14 06:25:45 +0000
commit9d147586a54d556e6692141572764646ee09a166 (patch)
tree32478dd59ba994f1fd4c3120593ab06f93122a7b /chrome/browser
parent4d9b083160466cee96855a80318a904b7c89eec7 (diff)
downloadchromium_src-9d147586a54d556e6692141572764646ee09a166.zip
chromium_src-9d147586a54d556e6692141572764646ee09a166.tar.gz
chromium_src-9d147586a54d556e6692141572764646ee09a166.tar.bz2
drive: Merge 'persistent' and 'tmp' directories to 'files'
Remove FileCacheEntry::is_present which can be replaced with "is_pinned() || is_dirty() || is_mounted()". Stop moving files between the two directories when modifying cache states. Add FileCache::MigrateFilesFromOldDirectories(). BUG=248905 TEST=unit_tests R=kinaba@chromium.org, satorux@chromium.org Review URL: https://codereview.chromium.org/15663006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206326 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/chromeos/drive/drive.proto5
-rw-r--r--chrome/browser/chromeos/drive/file_cache.cc406
-rw-r--r--chrome/browser/chromeos/drive/file_cache.h15
-rw-r--r--chrome/browser/chromeos/drive/file_cache_metadata_unittest.cc2
-rw-r--r--chrome/browser/chromeos/drive/file_cache_unittest.cc399
-rw-r--r--chrome/browser/chromeos/drive/file_system_unittest.cc2
-rw-r--r--chrome/browser/chromeos/drive/test_util.cc12
-rw-r--r--chrome/browser/chromeos/drive/test_util.h1
-rw-r--r--chrome/browser/resources/chromeos/drive_internals.js1
-rw-r--r--chrome/browser/ui/webui/chromeos/drive_internals_ui.cc1
10 files changed, 254 insertions, 590 deletions
diff --git a/chrome/browser/chromeos/drive/drive.proto b/chrome/browser/chromeos/drive/drive.proto
index 2f98714..1ea4ce3 100644
--- a/chrome/browser/chromeos/drive/drive.proto
+++ b/chrome/browser/chromeos/drive/drive.proto
@@ -110,8 +110,6 @@ message ResourceMetadataHeader {
}
// Message to store information of an existing cache file.
-// Cache files are stored in 'tmp' or 'persistent' directory under the
-// root cache directory. See FileCache::GetCacheRootPath().
message FileCacheEntry {
// MD5 of the cache file. "local" if the file is locally modified.
optional string md5 = 1;
@@ -128,8 +126,9 @@ message FileCacheEntry {
// True if the file is a mounted archive file.
optional bool is_mounted = 5;
+ // TODO(hashimoto): Remove this block after DB merge. crbug.com/234487
// True if the file is in the persistent directory.
- optional bool is_persistent = 6;
+ // optional bool is_persistent = 6;
// When adding a new state, be sure to update TestFileCacheState and test
// functions defined in drive_test_util.cc.
diff --git a/chrome/browser/chromeos/drive/file_cache.cc b/chrome/browser/chromeos/drive/file_cache.cc
index 36e09b9..e65342d 100644
--- a/chrome/browser/chromeos/drive/file_cache.cc
+++ b/chrome/browser/chromeos/drive/file_cache.cc
@@ -28,12 +28,9 @@ namespace {
typedef std::map<std::string, FileCacheEntry> CacheMap;
-typedef std::map<std::string, base::FilePath> ResourceIdToFilePathMap;
-
const base::FilePath::CharType kFileCacheMetaDir[] = FILE_PATH_LITERAL("meta");
-const base::FilePath::CharType kFileCachePersistentDir[] =
- FILE_PATH_LITERAL("persistent");
-const base::FilePath::CharType kFileCacheTmpDir[] = FILE_PATH_LITERAL("tmp");
+const base::FilePath::CharType kFileCacheFilesDir[] =
+ FILE_PATH_LITERAL("files");
const base::FilePath::CharType kFileCacheTmpDownloadsDir[] =
FILE_PATH_LITERAL("tmp/downloads");
const base::FilePath::CharType kFileCacheTmpDocumentsDir[] =
@@ -49,9 +46,7 @@ bool CheckIfMd5Matches(const std::string& md5,
return true;
} else if (cache_entry.is_pinned() && cache_entry.md5().empty()) {
// If the entry is pinned, it's ok for the entry to have an empty
- // MD5. This can happen if the pinned file is not fetched. MD5 for pinned
- // files are collected from files in "persistent" directory, but the
- // persistent files do not exist if these are not fetched yet.
+ // MD5. This can happen if the pinned file is not fetched.
return true;
} else if (md5.empty()) {
// If the MD5 matching is not requested, don't check MD5.
@@ -63,21 +58,12 @@ bool CheckIfMd5Matches(const std::string& md5,
return false;
}
-// Scans cache subdirectory and build or update |cache_map| with found files.
-//
-// The resource IDs and file paths of discovered files are collected as a
-// ResourceIdToFilePathMap, if these are processed properly.
-void ScanCacheDirectory(const std::vector<base::FilePath>& cache_paths,
- FileCache::CacheSubDirectoryType sub_dir_type,
- CacheMap* cache_map,
- ResourceIdToFilePathMap* processed_file_map) {
- DCHECK(cache_map);
- DCHECK(processed_file_map);
-
- base::FileEnumerator enumerator(cache_paths[sub_dir_type],
+// Scans cache subdirectory and insert found files to |cache_map|.
+void ScanCacheDirectory(const base::FilePath& directory_path,
+ CacheMap* cache_map) {
+ base::FileEnumerator enumerator(directory_path,
false, // not recursive
- base::FileEnumerator::FILES,
- util::kWildCard);
+ base::FileEnumerator::FILES);
for (base::FilePath current = enumerator.Next(); !current.empty();
current = enumerator.Next()) {
// Extract resource_id and md5 from filename.
@@ -86,84 +72,25 @@ void ScanCacheDirectory(const std::vector<base::FilePath>& cache_paths,
std::string extra_extension;
util::ParseCacheFilePath(current, &resource_id, &md5, &extra_extension);
- // Determine cache state.
- FileCacheEntry cache_entry;
- cache_entry.set_md5(md5);
- if (sub_dir_type == FileCache::CACHE_TYPE_PERSISTENT)
- cache_entry.set_is_persistent(true);
-
if (extra_extension == util::kMountedArchiveFileExtension) {
// Mounted archives in cache should be unmounted upon logout/shutdown.
- // But if we encounter a mounted file at start, delete it and create an
- // entry with not PRESENT state.
- DCHECK(sub_dir_type == FileCache::CACHE_TYPE_PERSISTENT);
+ // But if we encounter a mounted file at start, delete it.
file_util::Delete(current, false);
- } else {
- // The cache file is present.
- cache_entry.set_is_present(true);
-
- // Adds the dirty bit if |md5| indicates that the file is dirty, and
- // the file is in the persistent directory.
- if (md5 == util::kLocallyModifiedFileExtension) {
- if (sub_dir_type == FileCache::CACHE_TYPE_PERSISTENT) {
- cache_entry.set_is_dirty(true);
- } else {
- LOG(WARNING) << "Removing a dirty file in tmp directory: "
- << current.value();
- file_util::Delete(current, false);
- continue;
- }
- }
+ continue;
}
+ // Determine cache state.
+ FileCacheEntry cache_entry;
+ cache_entry.set_md5(md5);
+ cache_entry.set_is_present(true);
+
+ // Add the dirty bit if |md5| indicates that the file is dirty.
+ if (md5 == util::kLocallyModifiedFileExtension)
+ cache_entry.set_is_dirty(true);
+
// Create and insert new entry into cache map.
cache_map->insert(std::make_pair(resource_id, cache_entry));
- processed_file_map->insert(std::make_pair(resource_id, current));
- }
-}
-
-void ScanCachePaths(const std::vector<base::FilePath>& cache_paths,
- CacheMap* cache_map) {
- DVLOG(1) << "Scanning directories";
-
- // Scan cache persistent and tmp directories to enumerate all files and create
- // corresponding entries for cache map.
- ResourceIdToFilePathMap persistent_file_map;
- ScanCacheDirectory(cache_paths,
- FileCache::CACHE_TYPE_PERSISTENT,
- cache_map,
- &persistent_file_map);
- ResourceIdToFilePathMap tmp_file_map;
- ScanCacheDirectory(cache_paths,
- FileCache::CACHE_TYPE_TMP,
- cache_map,
- &tmp_file_map);
-
- // On DB corruption, keep only dirty-and-committed files in persistent
- // directory. Other files are deleted or moved to temporary directory.
- for (ResourceIdToFilePathMap::const_iterator iter =
- persistent_file_map.begin();
- iter != persistent_file_map.end(); ++iter) {
- const std::string& resource_id = iter->first;
- const base::FilePath& file_path = iter->second;
-
- CacheMap::iterator cache_map_iter = cache_map->find(resource_id);
- if (cache_map_iter != cache_map->end()) {
- FileCacheEntry* cache_entry = &cache_map_iter->second;
- const bool is_dirty = cache_entry->is_dirty();
- if (!is_dirty) {
- // If the file is not dirty, move to temporary directory.
- base::FilePath new_file_path =
- cache_paths[FileCache::CACHE_TYPE_TMP].Append(
- file_path.BaseName());
- DLOG(WARNING) << "Moving: " << file_path.value()
- << " to: " << new_file_path.value();
- file_util::Move(file_path, new_file_path);
- cache_entry->set_is_persistent(false);
- }
- }
}
- DVLOG(1) << "Directory scan finished";
}
// Create cache directory paths and set permissions.
@@ -177,10 +104,10 @@ bool InitCachePaths(const std::vector<base::FilePath>& cache_paths) {
if (!FileCache::CreateCacheDirectories(cache_paths))
return false;
- // Change permissions of cache persistent directory to u+rwx,og+x (711) in
- // order to allow archive files in that directory to be mounted by cros-disks.
+ // Change permissions of cache file directory to u+rwx,og+x (711) in order to
+ // allow archive files in that directory to be mounted by cros-disks.
file_util::SetPosixFilePermissions(
- cache_paths[FileCache::CACHE_TYPE_PERSISTENT],
+ cache_paths[FileCache::CACHE_TYPE_FILES],
file_util::FILE_PERMISSION_USER_MASK |
file_util::FILE_PERMISSION_EXECUTE_BY_GROUP |
file_util::FILE_PERMISSION_EXECUTE_BY_OTHERS);
@@ -188,20 +115,6 @@ bool InitCachePaths(const std::vector<base::FilePath>& cache_paths) {
return true;
}
-// Remove all files under the given directory, non-recursively.
-// Do not remove recursively as we don't want to touch <gcache>/tmp/downloads,
-// which is used for user initiated downloads like "Save As"
-void RemoveAllFiles(const base::FilePath& directory) {
- base::FileEnumerator enumerator(directory, false /* recursive */,
- base::FileEnumerator::FILES);
- for (base::FilePath file_path = enumerator.Next(); !file_path.empty();
- file_path = enumerator.Next()) {
- DVLOG(1) << "Removing " << file_path.value();
- if (!file_util::Delete(file_path, false /* recursive */))
- LOG(WARNING) << "Failed to delete " << file_path.value();
- }
-}
-
// Moves the file.
bool MoveFile(const base::FilePath& source_path,
const base::FilePath& dest_path) {
@@ -255,6 +168,19 @@ void DeleteFilesSelectively(const base::FilePath& path_to_delete_pattern,
}
}
+// Moves all files under |directory_from| to |directory_to|.
+void MoveAllFilesFromDirectory(const base::FilePath& directory_from,
+ const base::FilePath& directory_to) {
+ base::FileEnumerator enumerator(directory_from, false, // not recursive
+ base::FileEnumerator::FILES);
+ for (base::FilePath file_from = enumerator.Next(); !file_from.empty();
+ file_from = enumerator.Next()) {
+ const base::FilePath file_to = directory_to.Append(file_from.BaseName());
+ if (!file_util::PathExists(file_to)) // Do not overwrite existing files.
+ file_util::Move(file_from, file_to);
+ }
+}
+
// Runs callback with pointers dereferenced.
// Used to implement GetFile, MarkAsMounted.
void RunGetFileFromCacheCallback(
@@ -305,19 +231,14 @@ base::FilePath FileCache::GetCacheDirectoryPath(
return cache_paths_[sub_dir_type];
}
-base::FilePath FileCache::GetCacheFilePath(
- const std::string& resource_id,
- const std::string& md5,
- CacheSubDirectoryType sub_dir_type,
- CachedFileOrigin file_origin) const {
- DCHECK(sub_dir_type != CACHE_TYPE_META);
-
+base::FilePath FileCache::GetCacheFilePath(const std::string& resource_id,
+ const std::string& md5,
+ CachedFileOrigin file_origin) const {
// Runs on any thread.
// Filename is formatted as resource_id.md5, i.e. resource_id is the base
// name and md5 is the extension.
std::string base_name = util::EscapeCacheFileName(resource_id);
if (file_origin == CACHED_FILE_LOCALLY_MODIFIED) {
- DCHECK(sub_dir_type == CACHE_TYPE_PERSISTENT);
base_name += base::FilePath::kExtensionSeparator;
base_name += util::kLocallyModifiedFileExtension;
} else if (!md5.empty()) {
@@ -327,11 +248,10 @@ base::FilePath FileCache::GetCacheFilePath(
// For mounted archives the filename is formatted as resource_id.md5.mounted,
// i.e. resource_id.md5 is the base name and ".mounted" is the extension
if (file_origin == CACHED_FILE_MOUNTED) {
- DCHECK(sub_dir_type == CACHE_TYPE_PERSISTENT);
base_name += base::FilePath::kExtensionSeparator;
base_name += util::kMountedArchiveFileExtension;
}
- return GetCacheDirectoryPath(sub_dir_type).Append(
+ return GetCacheDirectoryPath(CACHE_TYPE_FILES).Append(
base::FilePath::FromUTF8Unsafe(base_name));
}
@@ -419,16 +339,29 @@ bool FileCache::FreeDiskSpaceIfNeededFor(int64 num_bytes) {
// Otherwise, try to free up the disk space.
DVLOG(1) << "Freeing up disk space for " << num_bytes;
- // First remove temporary files from the metadata.
+ // Remove all entries unless specially marked.
scoped_ptr<FileCacheMetadata::Iterator> it = metadata_->GetIterator();
for (; !it->IsAtEnd(); it->Advance()) {
- if (!it->GetValue().is_persistent())
+ const FileCacheEntry& entry = it->GetValue();
+ if (!entry.is_pinned() && !entry.is_dirty() && !entry.is_mounted())
metadata_->RemoveCacheEntry(it->GetKey());
}
DCHECK(!it->HasError());
- // Then remove all files under "tmp" directory.
- RemoveAllFiles(GetCacheDirectoryPath(CACHE_TYPE_TMP));
+ // Remove all files which have no corresponding cache entries.
+ base::FileEnumerator enumerator(cache_paths_[CACHE_TYPE_FILES],
+ false, // not recursive
+ base::FileEnumerator::FILES);
+ std::string resource_id;
+ std::string md5;
+ std::string extra_extension;
+ FileCacheEntry entry;
+ for (base::FilePath current = enumerator.Next(); !current.empty();
+ current = enumerator.Next()) {
+ util::ParseCacheFilePath(current, &resource_id, &md5, &extra_extension);
+ if (!GetCacheEntry(resource_id, md5, &entry))
+ file_util::Delete(current, false /* recursive */);
+ }
// Check the disk space again.
return HasEnoughSpaceFor(num_bytes, cache_root_path_);
@@ -470,9 +403,7 @@ FileError FileCache::GetFile(const std::string& resource_id,
file_origin = CACHED_FILE_FROM_SERVER;
}
- *cache_file_path = GetCacheFilePath(resource_id,
- cache_entry.md5(),
- GetSubDirectoryType(cache_entry),
+ *cache_file_path = GetCacheFilePath(resource_id, cache_entry.md5(),
file_origin);
return FILE_ERROR_OK;
}
@@ -519,42 +450,10 @@ FileError FileCache::Pin(const std::string& resource_id,
const std::string& md5) {
AssertOnSequencedWorkerPool();
- bool is_persistent = true;
FileCacheEntry cache_entry;
- if (!GetCacheEntry(resource_id, md5, &cache_entry)) {
- // The file will be first downloaded in 'tmp', then moved to 'persistent'.
- is_persistent = false;
- } else { // File exists in cache, determines destination path.
- // Determine source and destination paths.
-
- // If file is dirty or mounted, don't move it.
- if (!cache_entry.is_dirty() && !cache_entry.is_mounted()) {
- // If file was pinned before but actual file blob doesn't exist in cache:
- // - don't need to move the file.
- if (!cache_entry.is_present()) {
- DCHECK(cache_entry.is_pinned());
- return FILE_ERROR_OK;
- }
- // File exists, move it to persistent dir.
- // Gets the current path of the file in cache.
- base::FilePath source_path = GetCacheFilePath(
- resource_id,
- md5,
- GetSubDirectoryType(cache_entry),
- CACHED_FILE_FROM_SERVER);
- base::FilePath dest_path = GetCacheFilePath(resource_id,
- md5,
- CACHE_TYPE_PERSISTENT,
- CACHED_FILE_FROM_SERVER);
- if (!MoveFile(source_path, dest_path))
- return FILE_ERROR_FAILED;
- }
- }
-
- // Now that file operations have completed, update metadata.
- cache_entry.set_md5(md5);
+ if (!GetCacheEntry(resource_id, md5, &cache_entry))
+ cache_entry.set_md5(md5);
cache_entry.set_is_pinned(true);
- cache_entry.set_is_persistent(is_persistent);
metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry);
return FILE_ERROR_OK;
}
@@ -585,46 +484,17 @@ FileError FileCache::Unpin(const std::string& resource_id,
return FILE_ERROR_NOT_FOUND;
}
- CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP;
-
- // If file is dirty or mounted, don't move it.
- if (cache_entry.is_dirty() || cache_entry.is_mounted()) {
- sub_dir_type = CACHE_TYPE_PERSISTENT;
- DCHECK(cache_entry.is_persistent());
- } else {
- // If file was pinned but actual file blob still doesn't exist in cache,
- // don't need to move the file.
- if (cache_entry.is_present()) {
- // Gets the current path of the file in cache.
- base::FilePath source_path = GetCacheFilePath(
- resource_id,
- md5,
- GetSubDirectoryType(cache_entry),
- CACHED_FILE_FROM_SERVER);
- // File exists, move it to tmp dir.
- base::FilePath dest_path = GetCacheFilePath(
- resource_id,
- md5,
- CACHE_TYPE_TMP,
- CACHED_FILE_FROM_SERVER);
- if (!MoveFile(source_path, dest_path))
- return FILE_ERROR_FAILED;
- }
- }
-
// Now that file operations have completed, update metadata.
if (cache_entry.is_present()) {
cache_entry.set_md5(md5);
cache_entry.set_is_pinned(false);
- cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry);
} else {
// Remove the existing entry if we are unpinning a non-present file.
metadata_->RemoveCacheEntry(resource_id);
}
- // Now the file is moved from "persistent" to "tmp" directory.
- // It's a chance to free up space if needed.
+ // Now it's a chance to free up space if needed.
FreeDiskSpaceIfNeededFor(0);
return FILE_ERROR_OK;
@@ -694,27 +564,15 @@ FileError FileCache::MarkDirty(const std::string& resource_id,
return FILE_ERROR_NOT_FOUND;
}
- if (cache_entry.is_dirty()) {
- // The file must be in persistent dir.
- DCHECK(cache_entry.is_persistent());
+ if (cache_entry.is_dirty())
return FILE_ERROR_OK;
- }
-
- // Move file to persistent dir with new .local extension.
// Get the current path of the file in cache.
- base::FilePath source_path = GetCacheFilePath(
- resource_id,
- md5,
- GetSubDirectoryType(cache_entry),
- CACHED_FILE_FROM_SERVER);
+ base::FilePath source_path = GetCacheFilePath(resource_id, md5,
+ CACHED_FILE_FROM_SERVER);
// Determine destination path.
- const CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT;
base::FilePath cache_file_path = GetCacheFilePath(
- resource_id,
- md5,
- sub_dir_type,
- CACHED_FILE_LOCALLY_MODIFIED);
+ resource_id, md5, CACHED_FILE_LOCALLY_MODIFIED);
if (!MoveFile(source_path, cache_file_path))
return FILE_ERROR_FAILED;
@@ -722,7 +580,6 @@ FileError FileCache::MarkDirty(const std::string& resource_id,
// Now that file operations have completed, update metadata.
cache_entry.set_md5(md5);
cache_entry.set_is_dirty(true);
- cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry);
return FILE_ERROR_OK;
}
@@ -754,33 +611,16 @@ FileError FileCache::ClearDirty(const std::string& resource_id,
return FILE_ERROR_INVALID_OPERATION;
}
- // File must be dirty and hence in persistent dir.
- DCHECK(cache_entry.is_persistent());
-
- // Get the current path of the file in cache.
- base::FilePath source_path =
- GetCacheFilePath(resource_id,
- md5,
- GetSubDirectoryType(cache_entry),
- CACHED_FILE_LOCALLY_MODIFIED);
-
- // Determine destination path.
- // If file is pinned, move it to persistent dir with .md5 extension;
- // otherwise, move it to tmp dir with .md5 extension.
- const CacheSubDirectoryType sub_dir_type =
- cache_entry.is_pinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP;
- base::FilePath dest_path = GetCacheFilePath(resource_id,
- md5,
- sub_dir_type,
+ base::FilePath source_path = GetCacheFilePath(resource_id, md5,
+ CACHED_FILE_LOCALLY_MODIFIED);
+ base::FilePath dest_path = GetCacheFilePath(resource_id, md5,
CACHED_FILE_FROM_SERVER);
-
if (!MoveFile(source_path, dest_path))
return FILE_ERROR_FAILED;
// Now that file operations have completed, update metadata.
cache_entry.set_md5(md5);
cache_entry.set_is_dirty(false);
- cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry);
return FILE_ERROR_OK;
}
@@ -807,40 +647,17 @@ FileError FileCache::Remove(const std::string& resource_id) {
FileCacheEntry cache_entry;
// If entry doesn't exist or is dirty or mounted in cache, nothing to do.
- const bool entry_found = metadata_->GetCacheEntry(resource_id, &cache_entry);
- if (!entry_found || cache_entry.is_dirty() || cache_entry.is_mounted()) {
- DVLOG(1) << "Entry is "
- << (entry_found ?
- (cache_entry.is_dirty() ? "dirty" : "mounted") :
- "non-existent")
- << " in cache, not removing";
+ if (!metadata_->GetCacheEntry(resource_id, &cache_entry) ||
+ cache_entry.is_dirty() ||
+ cache_entry.is_mounted())
return FILE_ERROR_OK;
- }
- // Determine paths to delete all cache versions of |resource_id| in
- // persistent, tmp and pinned directories.
- std::vector<base::FilePath> paths_to_delete;
-
- // For files in persistent and tmp dirs, delete files that match
- // "<resource_id>.*".
- paths_to_delete.push_back(GetCacheFilePath(resource_id,
- util::kWildCard,
- CACHE_TYPE_PERSISTENT,
- CACHED_FILE_FROM_SERVER));
- paths_to_delete.push_back(GetCacheFilePath(resource_id,
- util::kWildCard,
- CACHE_TYPE_TMP,
- CACHED_FILE_FROM_SERVER));
-
- // Don't delete locally modified files.
- base::FilePath path_to_keep = GetCacheFilePath(resource_id,
- std::string(),
- CACHE_TYPE_PERSISTENT,
+ // Delete files that match "<resource_id>.*" unless modified locally.
+ base::FilePath path_to_delete = GetCacheFilePath(resource_id, util::kWildCard,
+ CACHED_FILE_FROM_SERVER);
+ base::FilePath path_to_keep = GetCacheFilePath(resource_id, std::string(),
CACHED_FILE_LOCALLY_MODIFIED);
-
- for (size_t i = 0; i < paths_to_delete.size(); ++i) {
- DeleteFilesSelectively(paths_to_delete[i], path_to_keep);
- }
+ DeleteFilesSelectively(path_to_delete, path_to_keep);
// Now that all file operations have completed, remove from metadata.
metadata_->RemoveCacheEntry(resource_id);
@@ -890,6 +707,8 @@ bool FileCache::InitializeOnBlockingPool() {
if (!InitCachePaths(cache_paths_))
return false;
+ MigrateFilesFromOldDirectories();
+
metadata_.reset(new FileCacheMetadata(blocking_task_runner_));
switch (metadata_->Initialize(cache_paths_[CACHE_TYPE_META])) {
@@ -901,7 +720,7 @@ bool FileCache::InitializeOnBlockingPool() {
case FileCacheMetadata::INITIALIZE_CREATED: {
CacheMap cache_map;
- ScanCachePaths(cache_paths_, &cache_map);
+ ScanCacheDirectory(cache_paths_[CACHE_TYPE_FILES], &cache_map);
for (CacheMap::const_iterator it = cache_map.begin();
it != cache_map.end(); ++it) {
metadata_->AddOrUpdateCacheEntry(it->first, it->second);
@@ -917,6 +736,22 @@ void FileCache::DestroyOnBlockingPool() {
delete this;
}
+void FileCache::MigrateFilesFromOldDirectories() {
+ const base::FilePath persistent_directory =
+ cache_root_path_.AppendASCII("persistent");
+ const base::FilePath tmp_directory = cache_root_path_.AppendASCII("tmp");
+ if (!file_util::PathExists(persistent_directory))
+ return;
+
+ // Move all files inside "persistent" to "files".
+ MoveAllFilesFromDirectory(persistent_directory,
+ cache_paths_[CACHE_TYPE_FILES]);
+ file_util::Delete(persistent_directory, true /* recursive */);
+
+ // Move all files inside "tmp" to "files".
+ MoveAllFilesFromDirectory(tmp_directory, cache_paths_[CACHE_TYPE_FILES]);
+}
+
FileError FileCache::StoreInternal(const std::string& resource_id,
const std::string& md5,
const base::FilePath& source_path,
@@ -936,21 +771,11 @@ FileError FileCache::StoreInternal(const std::string& resource_id,
FileCacheEntry cache_entry;
metadata_->GetCacheEntry(resource_id, &cache_entry);
- CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP;
// 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 "
- << (cache_entry.is_dirty() ? "dirty" : "mounted")
- << " file: res_id=" << resource_id
- << ", md5=" << md5;
+ if (cache_entry.is_dirty() || cache_entry.is_mounted())
return FILE_ERROR_IN_USE;
- }
- // If file was previously pinned, store it in persistent dir.
- if (cache_entry.is_pinned())
- sub_dir_type = CACHE_TYPE_PERSISTENT;
-
- base::FilePath dest_path = GetCacheFilePath(resource_id, md5, sub_dir_type,
+ base::FilePath dest_path = GetCacheFilePath(resource_id, md5,
CACHED_FILE_FROM_SERVER);
bool success = false;
switch (file_operation_type) {
@@ -990,7 +815,6 @@ FileError FileCache::StoreInternal(const std::string& resource_id,
// Now that file operations have completed, update metadata.
cache_entry.set_md5(md5);
cache_entry.set_is_present(true);
- cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
cache_entry.set_is_dirty(false);
metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry);
}
@@ -1011,19 +835,11 @@ FileError FileCache::MarkAsMounted(const std::string& resource_id,
if (cache_entry.is_mounted())
return FILE_ERROR_INVALID_OPERATION;
- // Get the subdir type and path for the unmounted state.
- CacheSubDirectoryType unmounted_subdir =
- cache_entry.is_pinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP;
+ // Move cache file.
base::FilePath unmounted_path = GetCacheFilePath(
- resource_id, cache_entry.md5(), unmounted_subdir,
- CACHED_FILE_FROM_SERVER);
-
- // Get the subdir type and path for the mounted state.
- CacheSubDirectoryType mounted_subdir = CACHE_TYPE_PERSISTENT;
+ resource_id, cache_entry.md5(), CACHED_FILE_FROM_SERVER);
base::FilePath mounted_path = GetCacheFilePath(
- resource_id, cache_entry.md5(), mounted_subdir, CACHED_FILE_MOUNTED);
-
- // Move cache file.
+ resource_id, cache_entry.md5(), CACHED_FILE_MOUNTED);
if (!MoveFile(unmounted_path, mounted_path))
return FILE_ERROR_FAILED;
@@ -1037,7 +853,6 @@ FileError FileCache::MarkAsMounted(const std::string& resource_id,
// Now that cache operation is complete, update metadata.
cache_entry.set_is_mounted(true);
- cache_entry.set_is_persistent(true);
metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry);
*cache_file_path = mounted_path;
@@ -1064,25 +879,17 @@ FileError FileCache::MarkAsUnmounted(const base::FilePath& file_path) {
if (!cache_entry.is_mounted())
return FILE_ERROR_INVALID_OPERATION;
- // Get the subdir type and path for the unmounted state.
- CacheSubDirectoryType unmounted_subdir =
- cache_entry.is_pinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP;
+ // Move cache file.
base::FilePath unmounted_path = GetCacheFilePath(
- resource_id, md5, unmounted_subdir, CACHED_FILE_FROM_SERVER);
-
- // Get the subdir type and path for the mounted state.
- CacheSubDirectoryType mounted_subdir = CACHE_TYPE_PERSISTENT;
+ resource_id, md5, CACHED_FILE_FROM_SERVER);
base::FilePath mounted_path = GetCacheFilePath(
- resource_id, md5, mounted_subdir, CACHED_FILE_MOUNTED);
-
- // Move cache file.
+ resource_id, md5, CACHED_FILE_MOUNTED);
if (!MoveFile(mounted_path, unmounted_path))
return FILE_ERROR_FAILED;
// Now that cache operation is complete, update metadata.
cache_entry.set_md5(md5);
cache_entry.set_is_mounted(false);
- cache_entry.set_is_persistent(unmounted_subdir == CACHE_TYPE_PERSISTENT);
metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry);
return FILE_ERROR_OK;
}
@@ -1121,8 +928,7 @@ std::vector<base::FilePath> FileCache::GetCachePaths(
std::vector<base::FilePath> cache_paths;
// The order should match FileCache::CacheSubDirectoryType enum.
cache_paths.push_back(cache_root_path.Append(kFileCacheMetaDir));
- cache_paths.push_back(cache_root_path.Append(kFileCachePersistentDir));
- cache_paths.push_back(cache_root_path.Append(kFileCacheTmpDir));
+ cache_paths.push_back(cache_root_path.Append(kFileCacheFilesDir));
cache_paths.push_back(cache_root_path.Append(kFileCacheTmpDownloadsDir));
cache_paths.push_back(cache_root_path.Append(kFileCacheTmpDocumentsDir));
return cache_paths;
@@ -1148,11 +954,5 @@ bool FileCache::CreateCacheDirectories(
return success;
}
-// static
-FileCache::CacheSubDirectoryType FileCache::GetSubDirectoryType(
- const FileCacheEntry& cache_entry) {
- return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP;
-}
-
} // namespace internal
} // namespace drive
diff --git a/chrome/browser/chromeos/drive/file_cache.h b/chrome/browser/chromeos/drive/file_cache.h
index 24b876a..bddeb16 100644
--- a/chrome/browser/chromeos/drive/file_cache.h
+++ b/chrome/browser/chromeos/drive/file_cache.h
@@ -71,10 +71,7 @@ class FileCache {
// This indexes into |FileCache::cache_paths_| vector.
enum CacheSubDirectoryType {
CACHE_TYPE_META = 0, // Resource metadata.
- CACHE_TYPE_PERSISTENT, // Files that are pinned or modified locally,
- // not evictable, hopefully.
- CACHE_TYPE_TMP, // Files that don't meet criteria to be in
- // persistent dir, and hence evictable.
+ CACHE_TYPE_FILES, // Cached files.
CACHE_TYPE_TMP_DOWNLOADS, // Downloaded files.
CACHE_TYPE_TMP_DOCUMENTS, // Temporary JSON files for hosted documents.
NUM_CACHE_TYPES, // This must be at the end.
@@ -279,10 +276,6 @@ class FileCache {
static bool CreateCacheDirectories(
const std::vector<base::FilePath>& paths_to_create);
- // Returns the type of the sub directory where the cache file is stored.
- static CacheSubDirectoryType GetSubDirectoryType(
- const FileCacheEntry& cache_entry);
-
private:
friend class FileCacheTest;
friend class FileCacheTestOnUIThread;
@@ -301,7 +294,6 @@ class FileCache {
// Can be called on any thread.
base::FilePath GetCacheFilePath(const std::string& resource_id,
const std::string& md5,
- CacheSubDirectoryType sub_dir_type,
CachedFileOrigin file_origin) const;
@@ -315,6 +307,11 @@ class FileCache {
// Destroys the cache on the blocking pool.
void DestroyOnBlockingPool();
+ // Migrates files from old "persistent" and "tmp" directories to the new
+ // "files" directory (see crbug.com/248905).
+ // TODO(hashimoto): Remove this method at some point.
+ void MigrateFilesFromOldDirectories();
+
// Used to implement Store and StoreLocallyModifiedOnUIThread.
// TODO(hidehiko): Merge this method with Store(), after
// StoreLocallyModifiedOnUIThread is removed.
diff --git a/chrome/browser/chromeos/drive/file_cache_metadata_unittest.cc b/chrome/browser/chromeos/drive/file_cache_metadata_unittest.cc
index 758d549..4f80668 100644
--- a/chrome/browser/chromeos/drive/file_cache_metadata_unittest.cc
+++ b/chrome/browser/chromeos/drive/file_cache_metadata_unittest.cc
@@ -47,7 +47,6 @@ TEST_F(FileCacheMetadataTest, CacheTest) {
FileCacheEntry new_cache_entry;
new_cache_entry.set_md5(test_md5);
new_cache_entry.set_is_present(true);
- new_cache_entry.set_is_persistent(true);
metadata_->AddOrUpdateCacheEntry(test_resource_id, new_cache_entry);
}
@@ -56,7 +55,6 @@ TEST_F(FileCacheMetadataTest, CacheTest) {
ASSERT_TRUE(metadata_->GetCacheEntry(test_resource_id, &cache_entry));
EXPECT_EQ(test_md5, cache_entry.md5());
EXPECT_TRUE(cache_entry.is_present());
- EXPECT_TRUE(cache_entry.is_persistent());
// resource_id doesn't exist.
EXPECT_FALSE(metadata_->GetCacheEntry("not_found_resource_id", &cache_entry));
diff --git a/chrome/browser/chromeos/drive/file_cache_unittest.cc b/chrome/browser/chromeos/drive/file_cache_unittest.cc
index 63b4701..cf2d15d 100644
--- a/chrome/browser/chromeos/drive/file_cache_unittest.cc
+++ b/chrome/browser/chromeos/drive/file_cache_unittest.cc
@@ -46,11 +46,8 @@ void OnIterateCompleted(bool* out_is_called) {
// TODO(hashimoto): remove this class. crbug.com/231221.
class FileCacheTestOnUIThread : public testing::Test {
protected:
- FileCacheTestOnUIThread()
- : expected_error_(FILE_ERROR_OK),
- expected_cache_state_(0),
- expected_sub_dir_type_(FileCache::CACHE_TYPE_META),
- expected_success_(true) {
+ FileCacheTestOnUIThread() : expected_error_(FILE_ERROR_OK),
+ expected_cache_state_(0) {
}
virtual void SetUp() OVERRIDE {
@@ -105,16 +102,13 @@ class FileCacheTestOnUIThread : public testing::Test {
}
}
- void TestStoreToCache(
- const std::string& resource_id,
- const std::string& md5,
- const base::FilePath& source_path,
- FileError expected_error,
- int expected_cache_state,
- FileCache::CacheSubDirectoryType expected_sub_dir_type) {
+ void TestStoreToCache(const std::string& resource_id,
+ const std::string& md5,
+ const base::FilePath& source_path,
+ FileError expected_error,
+ int expected_cache_state) {
expected_error_ = expected_error;
expected_cache_state_ = expected_cache_state;
- expected_sub_dir_type_ = expected_sub_dir_type;
FileError error = FILE_ERROR_OK;
cache_->StoreOnUIThread(
@@ -163,40 +157,26 @@ class FileCacheTestOnUIThread : public testing::Test {
EXPECT_TRUE(cache_entry.is_dirty());
// If entry doesn't exist, verify that no files with "<resource_id>.*"
- // exist in persistent and tmp dirs.
- const base::FilePath path_pattern_tmp =
- cache_->GetCacheFilePath(resource_id, "*",
- FileCache::CACHE_TYPE_TMP,
- FileCache::CACHED_FILE_FROM_SERVER);
- const base::FilePath path_pattern_persistent =
- cache_->GetCacheFilePath(resource_id, "*",
- FileCache::CACHE_TYPE_PERSISTENT,
- FileCache::CACHED_FILE_FROM_SERVER);
-
- EXPECT_EQ(0, CountFilesWithPathPattern(path_pattern_tmp));
+ // exist.
+ const base::FilePath path_pattern = cache_->GetCacheFilePath(
+ resource_id, util::kWildCard, FileCache::CACHED_FILE_FROM_SERVER);
if (!cache_entry_found) {
- EXPECT_EQ(0, CountFilesWithPathPattern(path_pattern_persistent));
+ EXPECT_EQ(0, CountFilesWithPathPattern(path_pattern));
} else {
- // Entry is dirty, verify that only 1 "<resource_id>.local" exists in
- // persistent dir.
- EXPECT_EQ(1, CountFilesWithPathPattern(path_pattern_persistent));
+ // Entry is dirty, verify that only 1 "<resource_id>.local" exists.
+ EXPECT_EQ(1, CountFilesWithPathPattern(path_pattern));
EXPECT_TRUE(file_util::PathExists(
- GetCacheFilePath(resource_id,
- std::string(),
- FileCache::CACHE_TYPE_PERSISTENT,
+ GetCacheFilePath(resource_id, std::string(),
FileCache::CACHED_FILE_LOCALLY_MODIFIED)));
}
}
- void TestPin(
- const std::string& resource_id,
- const std::string& md5,
- FileError expected_error,
- int expected_cache_state,
- FileCache::CacheSubDirectoryType expected_sub_dir_type) {
+ void TestPin(const std::string& resource_id,
+ const std::string& md5,
+ FileError expected_error,
+ int expected_cache_state) {
expected_error_ = expected_error;
expected_cache_state_ = expected_cache_state;
- expected_sub_dir_type_ = expected_sub_dir_type;
FileError error = FILE_ERROR_OK;
cache_->PinOnUIThread(
@@ -206,15 +186,12 @@ class FileCacheTestOnUIThread : public testing::Test {
VerifyCacheFileState(error, resource_id, md5);
}
- void TestUnpin(
- const std::string& resource_id,
- const std::string& md5,
- FileError expected_error,
- int expected_cache_state,
- FileCache::CacheSubDirectoryType expected_sub_dir_type) {
+ void TestUnpin(const std::string& resource_id,
+ const std::string& md5,
+ FileError expected_error,
+ int expected_cache_state) {
expected_error_ = expected_error;
expected_cache_state_ = expected_cache_state;
- expected_sub_dir_type_ = expected_sub_dir_type;
FileError error = FILE_ERROR_OK;
cache_->UnpinOnUIThread(
@@ -227,11 +204,9 @@ class FileCacheTestOnUIThread : public testing::Test {
void TestMarkDirty(const std::string& resource_id,
const std::string& md5,
FileError expected_error,
- int expected_cache_state,
- FileCache::CacheSubDirectoryType expected_sub_dir_type) {
+ int expected_cache_state) {
expected_error_ = expected_error;
expected_cache_state_ = expected_cache_state;
- expected_sub_dir_type_ = expected_sub_dir_type;
FileError error = FILE_ERROR_OK;
cache_->MarkDirtyOnUIThread(
@@ -259,15 +234,12 @@ class FileCacheTestOnUIThread : public testing::Test {
}
}
- void TestClearDirty(
- const std::string& resource_id,
- const std::string& md5,
- FileError expected_error,
- int expected_cache_state,
- FileCache::CacheSubDirectoryType expected_sub_dir_type) {
+ void TestClearDirty(const std::string& resource_id,
+ const std::string& md5,
+ FileError expected_error,
+ int expected_cache_state) {
expected_error_ = expected_error;
expected_cache_state_ = expected_cache_state;
- expected_sub_dir_type_ = expected_sub_dir_type;
FileError error = FILE_ERROR_OK;
PostTaskAndReplyWithResult(
@@ -281,14 +253,11 @@ class FileCacheTestOnUIThread : public testing::Test {
VerifyCacheFileState(error, resource_id, md5);
}
- void TestMarkAsMounted(
- const std::string& resource_id,
- FileError expected_error,
- int expected_cache_state,
- FileCache::CacheSubDirectoryType expected_sub_dir_type) {
+ void TestMarkAsMounted(const std::string& resource_id,
+ FileError expected_error,
+ int expected_cache_state) {
expected_error_ = expected_error;
expected_cache_state_ = expected_cache_state;
- expected_sub_dir_type_ = expected_sub_dir_type;
FileCacheEntry entry;
EXPECT_TRUE(GetCacheEntryFromOriginThread(resource_id, std::string(),
@@ -304,22 +273,17 @@ class FileCacheTestOnUIThread : public testing::Test {
EXPECT_TRUE(file_util::PathExists(cache_file_path));
EXPECT_EQ(cache_file_path,
- cache_->GetCacheFilePath(resource_id,
- entry.md5(),
- expected_sub_dir_type_,
+ cache_->GetCacheFilePath(resource_id, entry.md5(),
FileCache::CACHED_FILE_MOUNTED));
}
- void TestMarkAsUnmounted(
- const std::string& resource_id,
- const std::string& md5,
- const base::FilePath& file_path,
- FileError expected_error,
- int expected_cache_state,
- FileCache::CacheSubDirectoryType expected_sub_dir_type) {
+ void TestMarkAsUnmounted(const std::string& resource_id,
+ const std::string& md5,
+ const base::FilePath& file_path,
+ FileError expected_error,
+ int expected_cache_state) {
expected_error_ = expected_error;
expected_cache_state_ = expected_cache_state;
- expected_sub_dir_type_ = expected_sub_dir_type;
FileError error = FILE_ERROR_OK;
cache_->MarkAsUnmountedOnUIThread(
@@ -337,9 +301,7 @@ class FileCacheTestOnUIThread : public testing::Test {
EXPECT_TRUE(file_util::PathExists(cache_file_path));
EXPECT_EQ(cache_file_path,
- cache_->GetCacheFilePath(resource_id,
- md5,
- expected_sub_dir_type_,
+ cache_->GetCacheFilePath(resource_id, md5,
FileCache::CACHED_FILE_FROM_SERVER));
}
@@ -356,10 +318,7 @@ class FileCacheTestOnUIThread : public testing::Test {
test_util::ToCacheEntry(expected_cache_state_).is_pinned()) {
ASSERT_TRUE(cache_entry_found);
EXPECT_TRUE(test_util::CacheStatesEqual(
- test_util::ToCacheEntry(expected_cache_state_),
- cache_entry));
- EXPECT_EQ(expected_sub_dir_type_,
- FileCache::GetSubDirectoryType(cache_entry));
+ test_util::ToCacheEntry(expected_cache_state_), cache_entry));
} else {
EXPECT_FALSE(cache_entry_found);
}
@@ -368,13 +327,9 @@ class FileCacheTestOnUIThread : public testing::Test {
base::FilePath dest_path = cache_->GetCacheFilePath(
resource_id,
md5,
- test_util::ToCacheEntry(expected_cache_state_).is_pinned() ||
- test_util::ToCacheEntry(expected_cache_state_).is_dirty() ?
- FileCache::CACHE_TYPE_PERSISTENT :
- FileCache::CACHE_TYPE_TMP,
test_util::ToCacheEntry(expected_cache_state_).is_dirty() ?
FileCache::CACHED_FILE_LOCALLY_MODIFIED :
- FileCache::CACHED_FILE_FROM_SERVER);
+ FileCache::CACHED_FILE_FROM_SERVER);
bool exists = file_util::PathExists(dest_path);
if (test_util::ToCacheEntry(expected_cache_state_).is_present())
EXPECT_TRUE(exists);
@@ -383,11 +338,9 @@ class FileCacheTestOnUIThread : public testing::Test {
}
base::FilePath GetCacheFilePath(const std::string& resource_id,
- const std::string& md5,
- FileCache::CacheSubDirectoryType sub_dir_type,
- FileCache::CachedFileOrigin file_origin) {
- return cache_->GetCacheFilePath(resource_id, md5, sub_dir_type,
- file_origin);
+ const std::string& md5,
+ FileCache::CachedFileOrigin file_origin) {
+ return cache_->GetCacheFilePath(resource_id, md5, file_origin);
}
// Helper function to call GetCacheEntry from origin thread.
@@ -413,12 +366,9 @@ class FileCacheTestOnUIThread : public testing::Test {
const std::string& md5,
const std::string& expected_filename) {
base::FilePath actual_path = cache_->GetCacheFilePath(
- resource_id,
- md5,
- FileCache::CACHE_TYPE_TMP,
- FileCache::CACHED_FILE_FROM_SERVER);
+ resource_id, md5, FileCache::CACHED_FILE_FROM_SERVER);
base::FilePath expected_path =
- cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_TMP);
+ cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_FILES);
expected_path = expected_path.Append(
base::FilePath::FromUTF8Unsafe(expected_filename));
EXPECT_EQ(expected_path, actual_path);
@@ -439,11 +389,7 @@ class FileCacheTestOnUIThread : public testing::Test {
size_t CountCacheFiles(const std::string& resource_id,
const std::string& md5) {
base::FilePath path = GetCacheFilePath(
- resource_id, "*",
- (test_util::ToCacheEntry(expected_cache_state_).is_pinned() ?
- FileCache::CACHE_TYPE_PERSISTENT :
- FileCache::CACHE_TYPE_TMP),
- FileCache::CACHED_FILE_FROM_SERVER);
+ resource_id, util::kWildCard, FileCache::CACHED_FILE_FROM_SERVER);
base::FileEnumerator enumerator(path.DirName(), false,
base::FileEnumerator::FILES,
path.BaseName().value());
@@ -469,8 +415,6 @@ class FileCacheTestOnUIThread : public testing::Test {
FileError expected_error_;
int expected_cache_state_;
- FileCache::CacheSubDirectoryType expected_sub_dir_type_;
- bool expected_success_;
std::string expected_file_extension_;
};
@@ -487,9 +431,8 @@ TEST_F(FileCacheTestOnUIThread, GetCacheFilePath) {
resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?";
std::string escaped_resource_id = util::EscapeCacheFileName(resource_id);
std::string escaped_md5 = util::EscapeCacheFileName(md5);
- TestGetCacheFilePath(
- resource_id, md5, escaped_resource_id +
- base::FilePath::kExtensionSeparator + escaped_md5);
+ TestGetCacheFilePath(resource_id, md5, escaped_resource_id +
+ base::FilePath::kExtensionSeparator + escaped_md5);
}
TEST_F(FileCacheTestOnUIThread, StoreToCacheSimple) {
@@ -498,22 +441,19 @@ TEST_F(FileCacheTestOnUIThread, StoreToCacheSimple) {
// Store an existing file.
TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT);
// Store a non-existent file to the same |resource_id| and |md5|.
TestStoreToCache(resource_id, md5,
base::FilePath::FromUTF8Unsafe("non_existent_file"),
FILE_ERROR_FAILED,
- test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ test_util::TEST_CACHE_STATE_PRESENT);
// Store a different existing file to the same |resource_id| but different
// |md5|.
md5 = "new_md5";
TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT);
// Verify that there's only one file with name <resource_id>, i.e. previously
// cached file with the different md5 should be deleted.
@@ -526,8 +466,7 @@ TEST_F(FileCacheTestOnUIThread, GetFromCacheSimple) {
std::string md5("abcdef0123456789");
// First store a file to cache.
TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT);
// Then try to get the existing file from cache.
TestGetFileFromCacheByResourceIdAndMd5(
@@ -551,8 +490,7 @@ TEST_F(FileCacheTestOnUIThread, RemoveFromCacheSimple) {
std::string md5("abcdef0123456789");
// First store a file to cache.
TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT);
// Then try to remove existing file from cache.
TestRemoveFromCache(resource_id, FILE_ERROR_OK);
@@ -561,8 +499,7 @@ TEST_F(FileCacheTestOnUIThread, RemoveFromCacheSimple) {
// which is an extension separator.
resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?";
TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT);
TestRemoveFromCache(resource_id, FILE_ERROR_OK);
}
@@ -573,47 +510,38 @@ TEST_F(FileCacheTestOnUIThread, PinAndUnpin) {
// First store a file to cache.
TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT);
// Pin the existing file in cache.
TestPin(resource_id, md5, FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_PINNED |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_PINNED);
// Unpin the existing file in cache.
TestUnpin(resource_id, md5, FILE_ERROR_OK,
- test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ test_util::TEST_CACHE_STATE_PRESENT);
// Pin back the same existing file in cache.
TestPin(resource_id, md5, FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_PINNED |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_PINNED);
// Pin a non-existent file in cache.
resource_id = "document:1a2b";
TestPin(resource_id, md5, FILE_ERROR_OK,
- test_util::TEST_CACHE_STATE_PINNED,
- FileCache::CACHE_TYPE_TMP);
+ test_util::TEST_CACHE_STATE_PINNED);
// Unpin the previously pinned non-existent file in cache.
TestUnpin(resource_id, md5, FILE_ERROR_OK,
- test_util::TEST_CACHE_STATE_NONE,
- FileCache::CACHE_TYPE_TMP);
+ test_util::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";
TestUnpin(resource_id, md5, FILE_ERROR_NOT_FOUND,
- test_util::TEST_CACHE_STATE_NONE,
- FileCache::CACHE_TYPE_TMP /* non-applicable */);
+ test_util::TEST_CACHE_STATE_NONE);
}
TEST_F(FileCacheTestOnUIThread, StoreToCachePinned) {
@@ -622,25 +550,20 @@ TEST_F(FileCacheTestOnUIThread, StoreToCachePinned) {
// Pin a non-existent file.
TestPin(resource_id, md5, FILE_ERROR_OK,
- test_util::TEST_CACHE_STATE_PINNED,
- FileCache::CACHE_TYPE_TMP);
+ test_util::TEST_CACHE_STATE_PINNED);
// Store an existing file to a previously pinned file.
TestStoreToCache(resource_id, md5, dummy_file_path_,
FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_PINNED |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_PINNED);
// Store a non-existent file to a previously pinned and stored file.
TestStoreToCache(resource_id, md5,
base::FilePath::FromUTF8Unsafe("non_existent_file"),
FILE_ERROR_FAILED,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_PINNED |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_PINNED);
}
TEST_F(FileCacheTestOnUIThread, GetFromCachePinned) {
@@ -649,8 +572,7 @@ TEST_F(FileCacheTestOnUIThread, GetFromCachePinned) {
// Pin a non-existent file.
TestPin(resource_id, md5, FILE_ERROR_OK,
- test_util::TEST_CACHE_STATE_PINNED,
- FileCache::CACHE_TYPE_TMP);
+ test_util::TEST_CACHE_STATE_PINNED);
// Get the non-existent pinned file from cache.
TestGetFileFromCacheByResourceIdAndMd5(
@@ -660,9 +582,7 @@ TEST_F(FileCacheTestOnUIThread, GetFromCachePinned) {
TestStoreToCache(resource_id, md5, dummy_file_path_,
FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_PINNED |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_PINNED);
// Get the previously pinned and stored file from cache.
TestGetFileFromCacheByResourceIdAndMd5(
@@ -676,13 +596,10 @@ TEST_F(FileCacheTestOnUIThread, RemoveFromCachePinned) {
// Store a file to cache, and pin it.
TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT);
TestPin(resource_id, md5, FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_PINNED |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_PINNED);
// Remove |resource_id| from cache.
TestRemoveFromCache(resource_id, FILE_ERROR_OK);
@@ -692,13 +609,10 @@ TEST_F(FileCacheTestOnUIThread, RemoveFromCachePinned) {
resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?";
TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT);
TestPin(resource_id, md5, FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_PINNED |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_PINNED);
TestRemoveFromCache(resource_id, FILE_ERROR_OK);
}
@@ -709,20 +623,16 @@ TEST_F(FileCacheTestOnUIThread, DirtyCacheSimple) {
// First store a file to cache.
TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT);
// Mark the file dirty.
TestMarkDirty(resource_id, md5, FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_DIRTY |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_DIRTY);
// Clear dirty state of the file.
TestClearDirty(resource_id, md5, FILE_ERROR_OK,
- test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ test_util::TEST_CACHE_STATE_PRESENT);
}
TEST_F(FileCacheTestOnUIThread, DirtyCachePinned) {
@@ -731,28 +641,21 @@ TEST_F(FileCacheTestOnUIThread, DirtyCachePinned) {
// First store a file to cache and pin it.
TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT);
TestPin(resource_id, md5, FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_PINNED |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_PINNED);
// Mark the file dirty.
TestMarkDirty(resource_id, md5, FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
test_util::TEST_CACHE_STATE_DIRTY |
- test_util::TEST_CACHE_STATE_PINNED |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_PINNED);
// Clear dirty state of the file.
TestClearDirty(resource_id, md5, FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_PINNED |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_PINNED);
}
TEST_F(FileCacheTestOnUIThread, PinAndUnpinDirtyCache) {
@@ -761,13 +664,10 @@ TEST_F(FileCacheTestOnUIThread, PinAndUnpinDirtyCache) {
// First store a file to cache and mark it as dirty.
TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT);
TestMarkDirty(resource_id, md5, FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_DIRTY |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_DIRTY);
// Verifies dirty file exists.
base::FilePath dirty_path;
@@ -783,9 +683,7 @@ TEST_F(FileCacheTestOnUIThread, PinAndUnpinDirtyCache) {
TestPin(resource_id, md5, FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
test_util::TEST_CACHE_STATE_DIRTY |
- test_util::TEST_CACHE_STATE_PINNED |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_PINNED);
// Verify dirty file still exist at the same pathname.
EXPECT_TRUE(file_util::PathExists(dirty_path));
@@ -793,9 +691,7 @@ TEST_F(FileCacheTestOnUIThread, PinAndUnpinDirtyCache) {
// Unpin the dirty file.
TestUnpin(resource_id, md5, FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_DIRTY |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_DIRTY);
// Verify dirty file still exist at the same pathname.
EXPECT_TRUE(file_util::PathExists(dirty_path));
@@ -807,32 +703,25 @@ TEST_F(FileCacheTestOnUIThread, DirtyCacheRepetitive) {
// First store a file to cache.
TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT);
// Mark the file dirty.
TestMarkDirty(resource_id, md5, FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_DIRTY |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_DIRTY);
// Again, mark the file dirty. Nothing should change.
TestMarkDirty(resource_id, md5, FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_DIRTY |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_DIRTY);
// Clear dirty state of the file.
TestClearDirty(resource_id, md5, FILE_ERROR_OK,
- test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ test_util::TEST_CACHE_STATE_PRESENT);
// Again, clear dirty state of the file, which is no longer dirty.
TestClearDirty(resource_id, md5, FILE_ERROR_INVALID_OPERATION,
- test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ test_util::TEST_CACHE_STATE_PRESENT);
}
TEST_F(FileCacheTestOnUIThread, DirtyCacheInvalid) {
@@ -841,38 +730,30 @@ TEST_F(FileCacheTestOnUIThread, DirtyCacheInvalid) {
// Mark a non-existent file dirty.
TestMarkDirty(resource_id, md5, FILE_ERROR_NOT_FOUND,
- test_util::TEST_CACHE_STATE_NONE,
- FileCache::CACHE_TYPE_TMP);
+ test_util::TEST_CACHE_STATE_NONE);
// Clear dirty state of a non-existent file.
TestClearDirty(resource_id, md5, FILE_ERROR_NOT_FOUND,
- test_util::TEST_CACHE_STATE_NONE,
- FileCache::CACHE_TYPE_TMP);
+ test_util::TEST_CACHE_STATE_NONE);
// Store a file to cache.
TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT);
// Clear dirty state of a non-dirty existing file.
TestClearDirty(resource_id, md5, FILE_ERROR_INVALID_OPERATION,
- test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ test_util::TEST_CACHE_STATE_PRESENT);
// Mark an existing file dirty, then store a new file to the same resource id
// but different md5, which should fail.
TestMarkDirty(resource_id, md5, FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_DIRTY |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_DIRTY);
md5 = "new_md5";
TestStoreToCache(resource_id, md5, dummy_file_path_,
FILE_ERROR_IN_USE,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_DIRTY |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_DIRTY);
}
TEST_F(FileCacheTestOnUIThread, RemoveFromDirtyCache) {
@@ -881,19 +762,14 @@ TEST_F(FileCacheTestOnUIThread, RemoveFromDirtyCache) {
// Store a file to cache, pin it, mark it dirty and commit it.
TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT);
TestPin(resource_id, md5, FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_PINNED |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_PINNED);
TestMarkDirty(resource_id, md5, FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
test_util::TEST_CACHE_STATE_PINNED |
- test_util::TEST_CACHE_STATE_DIRTY |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_DIRTY);
// Try to remove the file. Since file is dirty, it should not be removed.
TestRemoveFromCache(resource_id, FILE_ERROR_OK);
@@ -903,18 +779,15 @@ TEST_F(FileCacheTestOnUIThread, MountUnmount) {
std::string resource_id("pdf:1a2b");
std::string md5("abcdef0123456789");
- // First store a file to cache in the tmp subdir.
+ // First store a file to cache.
TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT);
// Mark the file mounted.
TestMarkAsMounted(resource_id,
FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_MOUNTED |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_MOUNTED);
EXPECT_TRUE(CacheEntryExists(resource_id, md5));
// Clear mounted state of the file.
@@ -928,8 +801,7 @@ TEST_F(FileCacheTestOnUIThread, MountUnmount) {
TestMarkAsUnmounted(resource_id, md5, file_path,
FILE_ERROR_OK,
- test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ test_util::TEST_CACHE_STATE_PRESENT);
EXPECT_TRUE(CacheEntryExists(resource_id, md5));
// Try to remove the file.
@@ -970,8 +842,7 @@ TEST_F(FileCacheTestOnUIThread, ClearAll) {
// Store an existing file.
TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT);
// Verify that there's only one cached file.
EXPECT_EQ(1U, CountCacheFiles(resource_id, md5));
@@ -996,10 +867,8 @@ TEST_F(FileCacheTestOnUIThread, StoreToCacheNoSpace) {
std::string md5("abcdef0123456789");
// Try to store an existing file.
- TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_NO_SPACE,
- test_util::TEST_CACHE_STATE_NONE,
- FileCache::CACHE_TYPE_TMP);
+ TestStoreToCache(resource_id, md5, dummy_file_path_, FILE_ERROR_NO_SPACE,
+ test_util::TEST_CACHE_STATE_NONE);
// Verify that there's no files added.
EXPECT_EQ(0U, CountCacheFiles(resource_id, md5));
@@ -1028,26 +897,18 @@ TEST_F(FileCacheTestOnUIThread, UpdatePinnedCache) {
std::string md5_modified("aaaaaa0000000000");
// Store an existing file.
- TestStoreToCache(resource_id, md5, dummy_file_path_,
- FILE_ERROR_OK,
- test_util::TEST_CACHE_STATE_PRESENT,
- FileCache::CACHE_TYPE_TMP);
+ TestStoreToCache(resource_id, md5, dummy_file_path_, FILE_ERROR_OK,
+ test_util::TEST_CACHE_STATE_PRESENT);
// Pin the file.
- TestPin(resource_id, md5,
- FILE_ERROR_OK,
+ TestPin(resource_id, md5, FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_PINNED |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::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(resource_id, md5_modified, dummy_file_path_, FILE_ERROR_OK,
test_util::TEST_CACHE_STATE_PRESENT |
- test_util::TEST_CACHE_STATE_PINNED |
- test_util::TEST_CACHE_STATE_PERSISTENT,
- FileCache::CACHE_TYPE_PERSISTENT);
+ test_util::TEST_CACHE_STATE_PINNED);
}
// Tests FileCache methods working with the blocking task runner.
@@ -1072,6 +933,10 @@ class FileCacheTest : public testing::Test {
cache_.reset();
}
+ static void MigrateFilesFromOldDirectories(FileCache* cache) {
+ cache->MigrateFilesFromOldDirectories();
+ }
+
content::TestBrowserThreadBundle thread_bundle_;
base::ScopedTempDir temp_dir_;
@@ -1079,21 +944,39 @@ class FileCacheTest : public testing::Test {
scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_;
};
-TEST_F(FileCacheTest, ScanCacheFile) {
- // Set up files in cache directories.
+TEST_F(FileCacheTest, MigrateFilesFromOldDirectories) {
const base::FilePath persistent_directory =
- cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_PERSISTENT);
+ temp_dir_.path().AppendASCII("persistent");
+ const base::FilePath tmp_directory = temp_dir_.path().AppendASCII("tmp");
+ const base::FilePath files_directory =
+ cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_FILES);
+
+ // Prepare directories with previously used names.
+ ASSERT_TRUE(file_util::CreateDirectory(persistent_directory));
+ ASSERT_TRUE(file_util::CreateDirectory(tmp_directory));
+
+ // Put some files.
ASSERT_TRUE(google_apis::test_util::WriteStringToFile(
- persistent_directory.AppendASCII("id_foo.md5foo"), "foo"));
+ persistent_directory.AppendASCII("foo.abc"), "foo"));
ASSERT_TRUE(google_apis::test_util::WriteStringToFile(
- persistent_directory.AppendASCII("id_bar.local"), "bar"));
+ tmp_directory.AppendASCII("bar.123"), "bar"));
+
+ // Migrate.
+ MigrateFilesFromOldDirectories(cache_.get());
- const base::FilePath tmp_directory =
- cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_TMP);
+ EXPECT_FALSE(file_util::PathExists(persistent_directory));
+ EXPECT_TRUE(file_util::PathExists(files_directory.AppendASCII("foo.abc")));
+ EXPECT_TRUE(file_util::PathExists(files_directory.AppendASCII("bar.123")));
+}
+
+TEST_F(FileCacheTest, ScanCacheFile) {
+ // Set up files in the cache directory.
+ const base::FilePath directory =
+ cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_FILES);
ASSERT_TRUE(google_apis::test_util::WriteStringToFile(
- tmp_directory.AppendASCII("id_qux.md5qux"), "qux"));
+ directory.AppendASCII("id_foo.md5foo"), "foo"));
ASSERT_TRUE(google_apis::test_util::WriteStringToFile(
- tmp_directory.AppendASCII("id_quux.local"), "quux"));
+ directory.AppendASCII("id_bar.local"), "bar"));
// Remove the existing DB.
ASSERT_TRUE(file_util::Delete(
@@ -1119,12 +1002,6 @@ TEST_F(FileCacheTest, ScanCacheFile) {
EXPECT_TRUE(cache_->GetCacheEntry("id_bar", std::string(), &cache_entry));
EXPECT_TRUE(cache_entry.is_present());
EXPECT_TRUE(cache_entry.is_dirty());
-
- EXPECT_TRUE(cache_->GetCacheEntry("id_qux", std::string(), &cache_entry));
- EXPECT_EQ("md5qux", cache_entry.md5());
-
- EXPECT_FALSE(cache_->GetCacheEntry("id_quux", std::string(), &cache_entry));
-
}
TEST_F(FileCacheTest, FreeDiskSpaceIfNeededFor) {
diff --git a/chrome/browser/chromeos/drive/file_system_unittest.cc b/chrome/browser/chromeos/drive/file_system_unittest.cc
index 9cecbd5..12ad415 100644
--- a/chrome/browser/chromeos/drive/file_system_unittest.cc
+++ b/chrome/browser/chromeos/drive/file_system_unittest.cc
@@ -687,7 +687,6 @@ TEST_F(FileSystemTest, PinAndUnpin) {
entry->resource_id(), std::string(), &cache_entry));
EXPECT_TRUE(cache_entry.is_pinned());
EXPECT_TRUE(cache_entry.is_present());
- EXPECT_TRUE(cache_entry.is_persistent());
// Unpin the file.
error = FILE_ERROR_FAILED;
@@ -803,7 +802,6 @@ TEST_F(FileSystemTest, OpenAndCloseFile) {
&cache_entry));
EXPECT_TRUE(cache_entry.is_present());
EXPECT_TRUE(cache_entry.is_dirty());
- EXPECT_TRUE(cache_entry.is_persistent());
base::FilePath cache_file_path;
cache_->GetFileOnUIThread(file_resource_id, md5,
diff --git a/chrome/browser/chromeos/drive/test_util.cc b/chrome/browser/chromeos/drive/test_util.cc
index 9b93748..343180b 100644
--- a/chrome/browser/chromeos/drive/test_util.cc
+++ b/chrome/browser/chromeos/drive/test_util.cc
@@ -42,7 +42,7 @@ std::vector<TestCacheResource> GetDefaultTestCacheResources() {
"md5_tmp_non_alphanumeric",
false,
false),
- // Cache resource that is pinned and persistent.
+ // Cache resource that is pinned and present.
TestCacheResource("pinned/cache.mp3",
"pinned:existing",
"md5_pinned_existing",
@@ -78,16 +78,14 @@ FileCacheEntry ToCacheEntry(int cache_state) {
cache_entry.set_is_pinned(cache_state & TEST_CACHE_STATE_PINNED);
cache_entry.set_is_dirty(cache_state & TEST_CACHE_STATE_DIRTY);
cache_entry.set_is_mounted(cache_state & TEST_CACHE_STATE_MOUNTED);
- cache_entry.set_is_persistent(cache_state & TEST_CACHE_STATE_PERSISTENT);
return cache_entry;
}
bool CacheStatesEqual(const FileCacheEntry& a, const FileCacheEntry& b) {
- return (a.is_present() == b.is_present() &&
- a.is_pinned() == b.is_pinned() &&
- a.is_dirty() == b.is_dirty() &&
- a.is_mounted() == b.is_mounted() &&
- a.is_persistent() == b.is_persistent());
+ return a.is_present() == b.is_present() &&
+ a.is_pinned() == b.is_pinned() &&
+ a.is_dirty() == b.is_dirty() &&
+ a.is_mounted() == b.is_mounted();
}
bool PrepareTestCacheResources(
diff --git a/chrome/browser/chromeos/drive/test_util.h b/chrome/browser/chromeos/drive/test_util.h
index f0554b7..b0ff869 100644
--- a/chrome/browser/chromeos/drive/test_util.h
+++ b/chrome/browser/chromeos/drive/test_util.h
@@ -32,7 +32,6 @@ enum TestFileCacheState {
TEST_CACHE_STATE_PRESENT = 1 << 1,
TEST_CACHE_STATE_DIRTY = 1 << 2,
TEST_CACHE_STATE_MOUNTED = 1 << 3,
- TEST_CACHE_STATE_PERSISTENT = 1 << 4,
};
// Test data type of file cache
diff --git a/chrome/browser/resources/chromeos/drive_internals.js b/chrome/browser/resources/chromeos/drive_internals.js
index 6ef25aa..e6d40db 100644
--- a/chrome/browser/resources/chromeos/drive_internals.js
+++ b/chrome/browser/resources/chromeos/drive_internals.js
@@ -82,7 +82,6 @@ function updateCacheContents(cacheEntry) {
tr.appendChild(createElementFromText('td', cacheEntry.is_pinned));
tr.appendChild(createElementFromText('td', cacheEntry.is_dirty));
tr.appendChild(createElementFromText('td', cacheEntry.is_mounted));
- tr.appendChild(createElementFromText('td', cacheEntry.is_persistent));
$('cache-contents').appendChild(tr);
}
diff --git a/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc b/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc
index c0cc8f0..f49cc5f 100644
--- a/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc
+++ b/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc
@@ -767,7 +767,6 @@ void DriveInternalsWebUIHandler::UpdateCacheEntry(
value.SetBoolean("is_pinned", cache_entry.is_pinned());
value.SetBoolean("is_dirty", cache_entry.is_dirty());
value.SetBoolean("is_mounted", cache_entry.is_mounted());
- value.SetBoolean("is_persistent", cache_entry.is_persistent());
web_ui()->CallJavascriptFunction("updateCacheContents", value);
}