drive: Create cache directories in DriveIntegrationService
'meta' directory is hosting both DBs for FileCache and ResourceMetadata.
Since these DBs are going to be merged into one, this directory should be created outside FileCache to initialize
the shared unified DB.
Create directories in DriveIntegrationService.
Remove directory related code from FileCache.
Move directory name constants to file_system_util.h
Pass temporary directory path as an argument, instead of using GetCacheDirectory() from DownloadOperation.
BUG=234487
TEST=unit_tests
Review URL: https://chromiumcodereview.appspot.com/17236002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207160 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/chromeos/drive/change_list_loader_unittest.cc b/chrome/browser/chromeos/drive/change_list_loader_unittest.cc
index 39b6b3f..d7c635b 100644
--- a/chrome/browser/chromeos/drive/change_list_loader_unittest.cc
+++ b/chrome/browser/chromeos/drive/change_list_loader_unittest.cc
@@ -38,6 +38,7 @@
ASSERT_EQ(FILE_ERROR_OK, metadata_->Initialize());
cache_.reset(new FileCache(temp_dir_.path(),
+ temp_dir_.path(),
base::MessageLoopProxy::current(),
NULL /* free_disk_space_getter */));
ASSERT_TRUE(cache_->Initialize());
diff --git a/chrome/browser/chromeos/drive/drive_integration_service.cc b/chrome/browser/chromeos/drive/drive_integration_service.cc
index 57881378..b9f6b57 100644
--- a/chrome/browser/chromeos/drive/drive_integration_service.cc
+++ b/chrome/browser/chromeos/drive/drive_integration_service.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "base/bind.h"
+#include "base/file_util.h"
#include "base/prefs/pref_service.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/browser_process.h"
@@ -90,8 +91,29 @@
// Initializes FileCache and ResourceMetadata.
// Must be run on the same task runner used by |cache| and |resource_metadata|.
-FileError InitializeMetadata(internal::FileCache* cache,
+FileError InitializeMetadata(const base::FilePath& cache_root_directory,
+ internal::FileCache* cache,
internal::ResourceMetadata* resource_metadata) {
+ if (!file_util::CreateDirectory(cache_root_directory.Append(
+ util::kMetadataDirectory)) ||
+ !file_util::CreateDirectory(cache_root_directory.Append(
+ util::kCacheFileDirectory)) ||
+ !file_util::CreateDirectory(cache_root_directory.Append(
+ util::kTemporaryFileDirectory))) {
+ LOG(WARNING) << "Failed to create directories.";
+ return FILE_ERROR_FAILED;
+ }
+
+ // 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_root_directory.Append(util::kCacheFileDirectory),
+ file_util::FILE_PERMISSION_USER_MASK |
+ file_util::FILE_PERMISSION_EXECUTE_BY_GROUP |
+ file_util::FILE_PERMISSION_EXECUTE_BY_OTHERS);
+
+ util::MigrateCacheFilesFromOldDirectories(cache_root_directory);
+
if (!cache->Initialize()) {
LOG(WARNING) << "Failed to initialize the cache.";
return FILE_ERROR_FAILED;
@@ -112,8 +134,11 @@
FileSystemInterface* test_file_system)
: profile_(profile),
drive_disabled_(false),
+ cache_root_directory_(!test_cache_root.empty() ?
+ test_cache_root : util::GetCacheRootPath(profile)),
weak_ptr_factory_(this) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool();
blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner(
blocking_pool->GetSequenceToken());
@@ -133,26 +158,25 @@
}
scheduler_.reset(new JobScheduler(profile_, drive_service_.get()));
cache_.reset(new internal::FileCache(
- !test_cache_root.empty() ? test_cache_root
- : util::GetCacheRootPath(profile),
+ cache_root_directory_.Append(util::kMetadataDirectory),
+ cache_root_directory_.Append(util::kCacheFileDirectory),
blocking_task_runner_.get(),
NULL /* free_disk_space_getter */));
drive_app_registry_.reset(new DriveAppRegistry(scheduler_.get()));
- // We can call FileCache::GetCacheDirectoryPath safely even before the cache
- // gets initialized.
resource_metadata_.reset(new internal::ResourceMetadata(
- cache_->GetCacheDirectoryPath(internal::FileCache::CACHE_TYPE_META),
+ cache_root_directory_.Append(util::kMetadataDirectory),
blocking_task_runner_));
- file_system_.reset(test_file_system
- ? test_file_system
- : new FileSystem(profile_,
- cache_.get(),
- drive_service_.get(),
- scheduler_.get(),
- resource_metadata_.get(),
- blocking_task_runner_.get()));
+ file_system_.reset(
+ test_file_system ? test_file_system : new FileSystem(
+ profile_,
+ cache_.get(),
+ drive_service_.get(),
+ scheduler_.get(),
+ resource_metadata_.get(),
+ blocking_task_runner_.get(),
+ cache_root_directory_.Append(util::kTemporaryFileDirectory)));
file_write_helper_.reset(new FileWriteHelper(file_system()));
download_handler_.reset(new DownloadHandler(file_write_helper(),
file_system()));
@@ -173,6 +197,7 @@
blocking_task_runner_,
FROM_HERE,
base::Bind(&InitializeMetadata,
+ cache_root_directory_,
cache_.get(),
resource_metadata_.get()),
base::Bind(&DriveIntegrationService::InitializeAfterMetadataInitialized,
@@ -328,7 +353,7 @@
BrowserContext::GetDownloadManager(profile_) : NULL;
download_handler_->Initialize(
download_manager,
- cache_->GetCacheDirectoryPath(internal::FileCache::CACHE_TYPE_TMP));
+ cache_root_directory_.Append(util::kTemporaryFileDirectory));
// Register for Google Drive invalidation notifications.
google_apis::DriveNotificationManager* drive_notification_manager =
diff --git a/chrome/browser/chromeos/drive/drive_integration_service.h b/chrome/browser/chromeos/drive/drive_integration_service.h
index 14e2b17..c302467 100644
--- a/chrome/browser/chromeos/drive/drive_integration_service.h
+++ b/chrome/browser/chromeos/drive/drive_integration_service.h
@@ -147,6 +147,7 @@
// True if Drive is disabled due to initialization errors.
bool drive_disabled_;
+ base::FilePath cache_root_directory_;
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
scoped_ptr<internal::FileCache, util::DestroyHelper> cache_;
scoped_ptr<google_apis::DriveServiceInterface> drive_service_;
diff --git a/chrome/browser/chromeos/drive/file_cache.cc b/chrome/browser/chromeos/drive/file_cache.cc
index 42f0f4d..1894aa6 100644
--- a/chrome/browser/chromeos/drive/file_cache.cc
+++ b/chrome/browser/chromeos/drive/file_cache.cc
@@ -28,11 +28,6 @@
typedef std::map<std::string, FileCacheEntry> CacheMap;
-const base::FilePath::CharType kFileCacheMetaDir[] = FILE_PATH_LITERAL("meta");
-const base::FilePath::CharType kFileCacheFilesDir[] =
- FILE_PATH_LITERAL("files");
-const base::FilePath::CharType kFileCacheTmpDir[] = FILE_PATH_LITERAL("tmp");
-
// Returns true if |md5| matches the one in |cache_entry| with some
// exceptions. See the function definition for details.
bool CheckIfMd5Matches(const std::string& md5,
@@ -82,28 +77,6 @@
}
}
-// Create cache directory paths and set permissions.
-bool InitCachePaths(const std::vector<base::FilePath>& cache_paths) {
- if (cache_paths.size() < FileCache::NUM_CACHE_TYPES) {
- NOTREACHED();
- LOG(ERROR) << "Size of cache_paths is invalid.";
- return false;
- }
-
- if (!FileCache::CreateCacheDirectories(cache_paths))
- return false;
-
- // 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_FILES],
- file_util::FILE_PERMISSION_USER_MASK |
- file_util::FILE_PERMISSION_EXECUTE_BY_GROUP |
- file_util::FILE_PERMISSION_EXECUTE_BY_OTHERS);
-
- return true;
-}
-
// Moves the file.
bool MoveFile(const base::FilePath& source_path,
const base::FilePath& dest_path) {
@@ -157,19 +130,6 @@
}
}
-// 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(
@@ -195,11 +155,12 @@
} // namespace
-FileCache::FileCache(const base::FilePath& cache_root_path,
+FileCache::FileCache(const base::FilePath& metadata_directory,
+ const base::FilePath& cache_file_directory,
base::SequencedTaskRunner* blocking_task_runner,
FreeDiskSpaceGetterInterface* free_disk_space_getter)
- : cache_root_path_(cache_root_path),
- cache_paths_(GetCachePaths(cache_root_path_)),
+ : metadata_directory_(metadata_directory),
+ cache_file_directory_(cache_file_directory),
blocking_task_runner_(blocking_task_runner),
free_disk_space_getter_(free_disk_space_getter),
weak_ptr_factory_(this) {
@@ -213,13 +174,6 @@
AssertOnSequencedWorkerPool();
}
-base::FilePath FileCache::GetCacheDirectoryPath(
- CacheSubDirectoryType sub_dir_type) const {
- DCHECK_LE(0, sub_dir_type);
- DCHECK_GT(NUM_CACHE_TYPES, sub_dir_type);
- return cache_paths_[sub_dir_type];
-}
-
base::FilePath FileCache::GetCacheFilePath(const std::string& resource_id,
const std::string& md5,
CachedFileOrigin file_origin) const {
@@ -234,7 +188,7 @@
base_name += base::FilePath::kExtensionSeparator;
base_name += util::EscapeCacheFileName(md5);
}
- return GetCacheDirectoryPath(CACHE_TYPE_FILES).Append(
+ return cache_file_directory_.Append(
base::FilePath::FromUTF8Unsafe(base_name));
}
@@ -244,7 +198,7 @@
}
bool FileCache::IsUnderFileCacheDirectory(const base::FilePath& path) const {
- return cache_root_path_ == path || cache_root_path_.IsParent(path);
+ return cache_file_directory_.IsParent(path);
}
void FileCache::GetCacheEntryOnUIThread(const std::string& resource_id,
@@ -319,7 +273,7 @@
AssertOnSequencedWorkerPool();
// Do nothing and return if we have enough space.
- if (HasEnoughSpaceFor(num_bytes, cache_root_path_))
+ if (HasEnoughSpaceFor(num_bytes, cache_file_directory_))
return true;
// Otherwise, try to free up the disk space.
@@ -337,7 +291,7 @@
DCHECK(!it->HasError());
// Remove all files which have no corresponding cache entries.
- base::FileEnumerator enumerator(cache_paths_[CACHE_TYPE_FILES],
+ base::FileEnumerator enumerator(cache_file_directory_,
false, // not recursive
base::FileEnumerator::FILES);
std::string resource_id;
@@ -351,7 +305,7 @@
}
// Check the disk space again.
- return HasEnoughSpaceFor(num_bytes, cache_root_path_);
+ return HasEnoughSpaceFor(num_bytes, cache_file_directory_);
}
void FileCache::GetFileOnUIThread(const std::string& resource_id,
@@ -657,14 +611,9 @@
bool FileCache::Initialize() {
AssertOnSequencedWorkerPool();
- if (!InitCachePaths(cache_paths_))
- return false;
-
- MigrateFilesFromOldDirectories();
-
metadata_.reset(new FileCacheMetadata(blocking_task_runner_.get()));
- switch (metadata_->Initialize(cache_paths_[CACHE_TYPE_META])) {
+ switch (metadata_->Initialize(metadata_directory_)) {
case FileCacheMetadata::INITIALIZE_FAILED:
return false;
@@ -673,7 +622,7 @@
case FileCacheMetadata::INITIALIZE_CREATED: {
CacheMap cache_map;
- ScanCacheDirectory(cache_paths_[CACHE_TYPE_FILES], &cache_map);
+ ScanCacheDirectory(cache_file_directory_, &cache_map);
for (CacheMap::const_iterator it = cache_map.begin();
it != cache_map.end(); ++it) {
metadata_->AddOrUpdateCacheEntry(it->first, it->second);
@@ -703,22 +652,6 @@
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,
@@ -843,15 +776,22 @@
bool FileCache::ClearAll() {
AssertOnSequencedWorkerPool();
- if (!file_util::Delete(cache_root_path_, true)) {
- LOG(WARNING) << "Failed to delete the cache directory";
- return false;
- }
+ // Remove entries on the metadata.
+ scoped_ptr<FileCacheMetadata::Iterator> it = metadata_->GetIterator();
+ for (; !it->IsAtEnd(); it->Advance())
+ metadata_->RemoveCacheEntry(it->GetKey());
- if (!Initialize()) {
- LOG(WARNING) << "Failed to initialize the cache";
+ if (it->HasError())
return false;
- }
+
+ // Remove files.
+ base::FileEnumerator enumerator(cache_file_directory_,
+ false, // not recursive
+ base::FileEnumerator::FILES);
+ for (base::FilePath file = enumerator.Next(); !file.empty();
+ file = enumerator.Next())
+ file_util::Delete(file, false /* recursive */);
+
return true;
}
@@ -868,36 +808,5 @@
return (free_space >= num_bytes);
}
-// static
-std::vector<base::FilePath> FileCache::GetCachePaths(
- const base::FilePath& cache_root_path) {
- 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(kFileCacheFilesDir));
- cache_paths.push_back(cache_root_path.Append(kFileCacheTmpDir));
- return cache_paths;
-}
-
-// static
-bool FileCache::CreateCacheDirectories(
- const std::vector<base::FilePath>& paths_to_create) {
- bool success = true;
-
- for (size_t i = 0; i < paths_to_create.size(); ++i) {
- if (file_util::DirectoryExists(paths_to_create[i]))
- continue;
-
- if (!file_util::CreateDirectory(paths_to_create[i])) {
- // Error creating this directory, record error and proceed with next one.
- success = false;
- PLOG(ERROR) << "Error creating directory " << paths_to_create[i].value();
- } else {
- DVLOG(1) << "Created directory " << paths_to_create[i].value();
- }
- }
- return success;
-}
-
} // namespace internal
} // namespace drive
diff --git a/chrome/browser/chromeos/drive/file_cache.h b/chrome/browser/chromeos/drive/file_cache.h
index 6399977..be0ccff 100644
--- a/chrome/browser/chromeos/drive/file_cache.h
+++ b/chrome/browser/chromeos/drive/file_cache.h
@@ -68,23 +68,14 @@
// GetCacheFilePath() for example), should be run with |blocking_task_runner|.
class FileCache {
public:
- // Enum defining GCache subdirectory location.
- // This indexes into |FileCache::cache_paths_| vector.
- enum CacheSubDirectoryType {
- CACHE_TYPE_META = 0, // Resource metadata.
- CACHE_TYPE_FILES, // Cached files.
- CACHE_TYPE_TMP, // Temporary files.
- NUM_CACHE_TYPES, // This must be at the end.
- };
-
// Enum defining type of file operation e.g. copy or move, etc.
enum FileOperationType {
FILE_OPERATION_MOVE = 0,
FILE_OPERATION_COPY,
};
- // |cache_root_path| specifies the root directory for the cache. Sub
- // directories will be created under the root directory.
+ // |metadata_directory| stores the metadata and |cache_file_directory| stores
+ // cached files.
//
// |blocking_task_runner| is used to post a task to the blocking worker
// pool for file operations. Must not be null.
@@ -93,17 +84,11 @@
// getter for testing. NULL must be passed for production code.
//
// Must be called on the UI thread.
- FileCache(const base::FilePath& cache_root_path,
+ FileCache(const base::FilePath& metadata_directory,
+ const base::FilePath& cache_file_directory,
base::SequencedTaskRunner* blocking_task_runner,
FreeDiskSpaceGetterInterface* free_disk_space_getter);
- // Returns the sub-directory under drive cache directory for the given sub
- // directory type. Example: <user_profile_dir>/GCache/v1/files
- //
- // Can be called on any thread.
- base::FilePath GetCacheDirectoryPath(
- CacheSubDirectoryType sub_dir_type) const;
-
// Returns true if the given path is under drive cache directory, i.e.
// <user_profile_dir>/GCache/v1
//
@@ -259,18 +244,6 @@
// Must be called on the UI thread.
void Destroy();
- // Returns file paths for all the cache sub directories under
- // |cache_root_path|.
- static std::vector<base::FilePath> GetCachePaths(
- const base::FilePath& cache_root_path);
-
- // Creates cache directory and its sub-directories if they don't exist.
- // TODO(glotov): take care of this when the setup and cleanup part is
- // landed, noting that these directories need to be created for development
- // in linux box and unittest. (http://crosbug.com/27577)
- static bool CreateCacheDirectories(
- const std::vector<base::FilePath>& paths_to_create);
-
private:
friend class FileCacheTest;
friend class FileCacheTestOnUIThread;
@@ -298,11 +271,6 @@
// 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.
@@ -325,11 +293,9 @@
// bytes, while keeping kMinFreeSpace bytes on the disk.
bool HasEnoughSpaceFor(int64 num_bytes, const base::FilePath& path);
- // The root directory of the cache (i.e. <user_profile_dir>/GCache/v1).
- const base::FilePath cache_root_path_;
- // Paths for all subdirectories of GCache, one for each
- // FileCache::CacheSubDirectoryType enum.
- const std::vector<base::FilePath> cache_paths_;
+ const base::FilePath metadata_directory_;
+ const base::FilePath cache_file_directory_;
+
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
// The cache state data. This member must be access only on the blocking pool.
diff --git a/chrome/browser/chromeos/drive/file_cache_unittest.cc b/chrome/browser/chromeos/drive/file_cache_unittest.cc
index ff5716f..c28d20e 100644
--- a/chrome/browser/chromeos/drive/file_cache_unittest.cc
+++ b/chrome/browser/chromeos/drive/file_cache_unittest.cc
@@ -60,6 +60,11 @@
virtual void SetUp() OVERRIDE {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ ASSERT_TRUE(file_util::CreateDirectory(
+ temp_dir_.path().Append(util::kMetadataDirectory)));
+ ASSERT_TRUE(file_util::CreateDirectory(
+ temp_dir_.path().Append(util::kCacheFileDirectory)));
+
ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(),
&dummy_file_path_));
fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter);
@@ -68,9 +73,11 @@
content::BrowserThread::GetBlockingPool();
blocking_task_runner_ =
pool->GetSequencedTaskRunner(pool->GetSequenceToken());
- cache_.reset(new FileCache(temp_dir_.path(),
- blocking_task_runner_.get(),
- fake_free_disk_space_getter_.get()));
+ cache_.reset(new FileCache(
+ temp_dir_.path().Append(util::kMetadataDirectory),
+ temp_dir_.path().Append(util::kCacheFileDirectory),
+ blocking_task_runner_.get(),
+ fake_free_disk_space_getter_.get()));
bool success = false;
base::PostTaskAndReplyWithResult(
@@ -369,7 +376,7 @@
base::FilePath actual_path = cache_->GetCacheFilePath(
resource_id, md5, FileCache::CACHED_FILE_FROM_SERVER);
base::FilePath expected_path =
- cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_FILES);
+ temp_dir_.path().Append(util::kCacheFileDirectory);
expected_path = expected_path.Append(
base::FilePath::FromUTF8Unsafe(expected_filename));
EXPECT_EQ(expected_path, actual_path);
@@ -851,7 +858,8 @@
// Set the cache root to a non existent path, so the initialization fails.
scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache(new FileCache(
- base::FilePath::FromUTF8Unsafe("/somewhere/nonexistent/blah/blah"),
+ base::FilePath::FromUTF8Unsafe("/somewhere/nonexistent/blah/meta"),
+ base::FilePath::FromUTF8Unsafe("/somewhere/nonexistent/blah/files"),
base::MessageLoopProxy::current(),
NULL /* free_disk_space_getter */));
@@ -881,11 +889,18 @@
protected:
virtual void SetUp() OVERRIDE {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ ASSERT_TRUE(file_util::CreateDirectory(
+ temp_dir_.path().Append(util::kMetadataDirectory)));
+ ASSERT_TRUE(file_util::CreateDirectory(
+ temp_dir_.path().Append(util::kCacheFileDirectory)));
+
fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter);
- cache_.reset(new FileCache(temp_dir_.path(),
- base::MessageLoopProxy::current(),
- fake_free_disk_space_getter_.get()));
+ cache_.reset(new FileCache(
+ temp_dir_.path().Append(util::kMetadataDirectory),
+ temp_dir_.path().Append(util::kCacheFileDirectory),
+ base::MessageLoopProxy::current(),
+ fake_free_disk_space_getter_.get()));
ASSERT_TRUE(cache_->Initialize());
}
@@ -894,10 +909,6 @@
cache_.reset();
}
- static void MigrateFilesFromOldDirectories(FileCache* cache) {
- cache->MigrateFilesFromOldDirectories();
- }
-
content::TestBrowserThreadBundle thread_bundle_;
base::ScopedTempDir temp_dir_;
@@ -905,35 +916,10 @@
scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_;
};
-TEST_F(FileCacheTest, MigrateFilesFromOldDirectories) {
- const base::FilePath persistent_directory =
- 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("foo.abc"), "foo"));
- ASSERT_TRUE(google_apis::test_util::WriteStringToFile(
- tmp_directory.AppendASCII("bar.123"), "bar"));
-
- // Migrate.
- MigrateFilesFromOldDirectories(cache_.get());
-
- 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);
+ temp_dir_.path().Append(util::kCacheFileDirectory);
ASSERT_TRUE(google_apis::test_util::WriteStringToFile(
directory.AppendASCII("id_foo.md5foo"), "foo"));
ASSERT_TRUE(google_apis::test_util::WriteStringToFile(
@@ -941,11 +927,11 @@
// Remove the existing DB.
ASSERT_TRUE(file_util::Delete(
- cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_META),
- true /* recursive */));
+ temp_dir_.path().Append(util::kMetadataDirectory), true /* recursive */));
// Create a new cache and initialize it.
- cache_.reset(new FileCache(temp_dir_.path(),
+ cache_.reset(new FileCache(temp_dir_.path().Append(util::kMetadataDirectory),
+ temp_dir_.path().Append(util::kCacheFileDirectory),
base::MessageLoopProxy::current(),
fake_free_disk_space_getter_.get()));
ASSERT_TRUE(cache_->Initialize());
diff --git a/chrome/browser/chromeos/drive/file_system.cc b/chrome/browser/chromeos/drive/file_system.cc
index 14f89bd..d24fbf6 100644
--- a/chrome/browser/chromeos/drive/file_system.cc
+++ b/chrome/browser/chromeos/drive/file_system.cc
@@ -75,7 +75,8 @@
google_apis::DriveServiceInterface* drive_service,
JobScheduler* scheduler,
internal::ResourceMetadata* resource_metadata,
- base::SequencedTaskRunner* blocking_task_runner)
+ base::SequencedTaskRunner* blocking_task_runner,
+ const base::FilePath& temporary_file_directory)
: profile_(profile),
cache_(cache),
drive_service_(drive_service),
@@ -84,6 +85,7 @@
last_update_check_error_(FILE_ERROR_OK),
hide_hosted_docs_(false),
blocking_task_runner_(blocking_task_runner),
+ temporary_file_directory_(temporary_file_directory),
weak_ptr_factory_(this) {
// Should be created from the file browser extension API on UI thread.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -107,7 +109,8 @@
scheduler_,
resource_metadata_,
cache_,
- drive_service_));
+ drive_service_,
+ temporary_file_directory_));
create_directory_operation_.reset(new file_system::CreateDirectoryOperation(
blocking_task_runner_.get(), observer, scheduler_, resource_metadata_));
create_file_operation_.reset(
@@ -131,7 +134,8 @@
observer,
scheduler_,
resource_metadata_,
- cache_));
+ cache_,
+ temporary_file_directory_));
update_operation_.reset(
new file_system::UpdateOperation(blocking_task_runner_.get(),
observer,
@@ -144,7 +148,8 @@
observer,
scheduler_,
resource_metadata_,
- cache_));
+ cache_,
+ temporary_file_directory_));
PrefService* pref_service = profile_->GetPrefs();
hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableDriveHostedFiles);
diff --git a/chrome/browser/chromeos/drive/file_system.h b/chrome/browser/chromeos/drive/file_system.h
index a9f422e..d3f7c8d 100644
--- a/chrome/browser/chromeos/drive/file_system.h
+++ b/chrome/browser/chromeos/drive/file_system.h
@@ -65,7 +65,8 @@
google_apis::DriveServiceInterface* drive_service,
JobScheduler* scheduler,
internal::ResourceMetadata* resource_metadata,
- base::SequencedTaskRunner* blocking_task_runner);
+ base::SequencedTaskRunner* blocking_task_runner,
+ const base::FilePath& temporary_file_directory);
virtual ~FileSystem();
// FileSystemInterface overrides.
@@ -384,6 +385,8 @@
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
+ base::FilePath temporary_file_directory_;
+
// Implementation of each file system operation.
scoped_ptr<file_system::CopyOperation> copy_operation_;
scoped_ptr<file_system::CreateDirectoryOperation> create_directory_operation_;
diff --git a/chrome/browser/chromeos/drive/file_system/copy_operation.cc b/chrome/browser/chromeos/drive/file_system/copy_operation.cc
index 3a4c561..3c16ab1 100644
--- a/chrome/browser/chromeos/drive/file_system/copy_operation.cc
+++ b/chrome/browser/chromeos/drive/file_system/copy_operation.cc
@@ -56,7 +56,8 @@
JobScheduler* scheduler,
internal::ResourceMetadata* metadata,
internal::FileCache* cache,
- google_apis::DriveServiceInterface* drive_service)
+ google_apis::DriveServiceInterface* drive_service,
+ const base::FilePath& temporary_file_directory)
: blocking_task_runner_(blocking_task_runner),
observer_(observer),
scheduler_(scheduler),
@@ -72,7 +73,8 @@
observer,
scheduler,
metadata,
- cache)),
+ cache,
+ temporary_file_directory)),
move_operation_(new MoveOperation(observer, scheduler, metadata)),
weak_ptr_factory_(this) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
diff --git a/chrome/browser/chromeos/drive/file_system/copy_operation.h b/chrome/browser/chromeos/drive/file_system/copy_operation.h
index bbda1af..b8db1c3 100644
--- a/chrome/browser/chromeos/drive/file_system/copy_operation.h
+++ b/chrome/browser/chromeos/drive/file_system/copy_operation.h
@@ -48,7 +48,8 @@
JobScheduler* scheduler,
internal::ResourceMetadata* metadata,
internal::FileCache* cache,
- google_apis::DriveServiceInterface* drive_service);
+ google_apis::DriveServiceInterface* drive_service,
+ const base::FilePath& temporary_file_directory);
~CopyOperation();
// Performs the copy operation on the file at drive path |src_file_path|
diff --git a/chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc b/chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc
index 5f1a9051..0bf9e6d08 100644
--- a/chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc
+++ b/chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc
@@ -23,7 +23,8 @@
scheduler(),
metadata(),
cache(),
- fake_service()));
+ fake_service(),
+ temp_dir()));
}
scoped_ptr<CopyOperation> operation_;
diff --git a/chrome/browser/chromeos/drive/file_system/download_operation.cc b/chrome/browser/chromeos/drive/file_system/download_operation.cc
index a0af591..e787ec0 100644
--- a/chrome/browser/chromeos/drive/file_system/download_operation.cc
+++ b/chrome/browser/chromeos/drive/file_system/download_operation.cc
@@ -37,6 +37,7 @@
FileError CheckPreConditionForEnsureFileDownloaded(
internal::ResourceMetadata* metadata,
internal::FileCache* cache,
+ const base::FilePath& temporary_file_directory,
ResourceEntry* entry,
base::FilePath* cache_file_path) {
DCHECK(metadata);
@@ -55,9 +56,8 @@
// document.
if (entry->file_specific_info().is_hosted_document()) {
base::FilePath gdoc_file_path;
- if (!file_util::CreateTemporaryFileInDir(
- cache->GetCacheDirectoryPath(internal::FileCache::CACHE_TYPE_TMP),
- &gdoc_file_path) ||
+ if (!file_util::CreateTemporaryFileInDir(temporary_file_directory,
+ &gdoc_file_path) ||
!util::CreateGDocFile(gdoc_file_path,
GURL(entry->file_specific_info().alternate_url()),
entry->resource_id()))
@@ -102,13 +102,14 @@
internal::ResourceMetadata* metadata,
internal::FileCache* cache,
const std::string& resource_id,
+ const base::FilePath& temporary_file_directory,
base::FilePath* cache_file_path,
ResourceEntry* entry) {
FileError error = metadata->GetResourceEntryById(resource_id, entry);
if (error != FILE_ERROR_OK)
return error;
return CheckPreConditionForEnsureFileDownloaded(
- metadata, cache, entry, cache_file_path);
+ metadata, cache, temporary_file_directory, entry, cache_file_path);
}
// Calls CheckPreConditionForEnsureFileDownloaded() with the entry specified by
@@ -117,13 +118,14 @@
internal::ResourceMetadata* metadata,
internal::FileCache* cache,
const base::FilePath& file_path,
+ const base::FilePath& temporary_file_directory,
base::FilePath* cache_file_path,
ResourceEntry* entry) {
FileError error = metadata->GetResourceEntryByPath(file_path, entry);
if (error != FILE_ERROR_OK)
return error;
return CheckPreConditionForEnsureFileDownloaded(
- metadata, cache, entry, cache_file_path);
+ metadata, cache, temporary_file_directory, entry, cache_file_path);
}
// Creates a file with unique name in |dir| and stores the path to |temp_file|.
@@ -152,6 +154,7 @@
internal::ResourceMetadata* metadata,
internal::FileCache* cache,
scoped_ptr<google_apis::ResourceEntry> gdata_entry,
+ const base::FilePath& temporary_file_directory,
ResourceEntry* entry,
base::FilePath* drive_file_path,
base::FilePath* temp_download_file) {
@@ -181,7 +184,7 @@
// Create the temporary file which will store the donwloaded content.
return CreateTemporaryReadableFileInDir(
- cache->GetCacheDirectoryPath(internal::FileCache::CACHE_TYPE_TMP),
+ temporary_file_directory,
temp_download_file) ? FILE_ERROR_OK : FILE_ERROR_FAILED;
}
@@ -292,12 +295,14 @@
OperationObserver* observer,
JobScheduler* scheduler,
internal::ResourceMetadata* metadata,
- internal::FileCache* cache)
+ internal::FileCache* cache,
+ const base::FilePath& temporary_file_directory)
: blocking_task_runner_(blocking_task_runner),
observer_(observer),
scheduler_(scheduler),
metadata_(metadata),
cache_(cache),
+ temporary_file_directory_(temporary_file_directory),
weak_ptr_factory_(this) {
}
@@ -325,6 +330,7 @@
base::Unretained(metadata_),
base::Unretained(cache_),
resource_id,
+ temporary_file_directory_,
cache_file_path,
entry),
base::Bind(&DownloadOperation::EnsureFileDownloadedAfterCheckPreCondition,
@@ -356,6 +362,7 @@
base::Unretained(metadata_),
base::Unretained(cache_),
file_path,
+ temporary_file_directory_,
cache_file_path,
entry),
base::Bind(&DownloadOperation::EnsureFileDownloadedAfterCheckPreCondition,
@@ -445,6 +452,7 @@
base::Unretained(metadata_),
base::Unretained(cache_),
base::Passed(&resource_entry),
+ temporary_file_directory_,
params->entry.get(),
¶ms->drive_file_path,
¶ms->temp_download_file_path),
diff --git a/chrome/browser/chromeos/drive/file_system/download_operation.h b/chrome/browser/chromeos/drive/file_system/download_operation.h
index 954716d..d102221 100644
--- a/chrome/browser/chromeos/drive/file_system/download_operation.h
+++ b/chrome/browser/chromeos/drive/file_system/download_operation.h
@@ -41,7 +41,8 @@
OperationObserver* observer,
JobScheduler* scheduler,
internal::ResourceMetadata* metadata,
- internal::FileCache* cache);
+ internal::FileCache* cache,
+ const base::FilePath& temporary_file_directory);
~DownloadOperation();
// Ensures that the file content specified by |resource_id| is locally
@@ -132,6 +133,7 @@
JobScheduler* scheduler_;
internal::ResourceMetadata* metadata_;
internal::FileCache* cache_;
+ const base::FilePath temporary_file_directory_;
// Note: This should remain the last member so it'll be destroyed and
// invalidate its weak pointers before any other members are destroyed.
diff --git a/chrome/browser/chromeos/drive/file_system/download_operation_unittest.cc b/chrome/browser/chromeos/drive/file_system/download_operation_unittest.cc
index 5aee974..40a2648 100644
--- a/chrome/browser/chromeos/drive/file_system/download_operation_unittest.cc
+++ b/chrome/browser/chromeos/drive/file_system/download_operation_unittest.cc
@@ -22,7 +22,8 @@
OperationTestBase::SetUp();
operation_.reset(new DownloadOperation(
- blocking_task_runner(), observer(), scheduler(), metadata(), cache()));
+ blocking_task_runner(), observer(), scheduler(), metadata(), cache(),
+ temp_dir()));
}
scoped_ptr<DownloadOperation> operation_;
diff --git a/chrome/browser/chromeos/drive/file_system/operation_test_base.cc b/chrome/browser/chromeos/drive/file_system/operation_test_base.cc
index ab5d73cd..43f2aae 100644
--- a/chrome/browser/chromeos/drive/file_system/operation_test_base.cc
+++ b/chrome/browser/chromeos/drive/file_system/operation_test_base.cc
@@ -75,6 +75,7 @@
fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter);
cache_.reset(new internal::FileCache(temp_dir_.path(),
+ temp_dir_.path(),
blocking_task_runner_.get(),
fake_free_disk_space_getter_.get()));
bool success = false;
diff --git a/chrome/browser/chromeos/drive/file_system_unittest.cc b/chrome/browser/chromeos/drive/file_system_unittest.cc
index 6ad7ace..ca97f02 100644
--- a/chrome/browser/chromeos/drive/file_system_unittest.cc
+++ b/chrome/browser/chromeos/drive/file_system_unittest.cc
@@ -80,9 +80,19 @@
scheduler_.reset(new JobScheduler(profile_.get(),
fake_drive_service_.get()));
- cache_.reset(new internal::FileCache(util::GetCacheRootPath(profile_.get()),
- blocking_task_runner_.get(),
- fake_free_disk_space_getter_.get()));
+ ASSERT_TRUE(file_util::CreateDirectory(util::GetCacheRootPath(
+ profile_.get()).Append(util::kMetadataDirectory)));
+ ASSERT_TRUE(file_util::CreateDirectory(util::GetCacheRootPath(
+ profile_.get()).Append(util::kCacheFileDirectory)));
+ ASSERT_TRUE(file_util::CreateDirectory(util::GetCacheRootPath(
+ profile_.get()).Append(util::kTemporaryFileDirectory)));
+
+ cache_.reset(new internal::FileCache(
+ util::GetCacheRootPath(profile_.get()).Append(util::kMetadataDirectory),
+ util::GetCacheRootPath(profile_.get()).Append(
+ util::kCacheFileDirectory),
+ blocking_task_runner_.get(),
+ fake_free_disk_space_getter_.get()));
mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>);
@@ -101,15 +111,18 @@
void SetUpResourceMetadataAndFileSystem() {
resource_metadata_.reset(new internal::ResourceMetadata(
- cache_->GetCacheDirectoryPath(internal::FileCache::CACHE_TYPE_META),
+ util::GetCacheRootPath(profile_.get()).Append(util::kMetadataDirectory),
blocking_task_runner_));
- file_system_.reset(new FileSystem(profile_.get(),
- cache_.get(),
- fake_drive_service_.get(),
- scheduler_.get(),
- resource_metadata_.get(),
- blocking_task_runner_.get()));
+ file_system_.reset(new FileSystem(
+ profile_.get(),
+ cache_.get(),
+ fake_drive_service_.get(),
+ scheduler_.get(),
+ resource_metadata_.get(),
+ blocking_task_runner_.get(),
+ util::GetCacheRootPath(profile_.get()).Append(
+ util::kTemporaryFileDirectory)));
file_system_->AddObserver(mock_directory_observer_.get());
file_system_->Initialize();
@@ -221,7 +234,8 @@
fake_drive_service_->GetRootResourceId();
scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests>
resource_metadata(new internal::ResourceMetadata(
- cache_->GetCacheDirectoryPath(internal::FileCache::CACHE_TYPE_META),
+ util::GetCacheRootPath(profile_.get()).Append(
+ util::kMetadataDirectory),
blocking_task_runner_));
FileError error = FILE_ERROR_FAILED;
diff --git a/chrome/browser/chromeos/drive/file_system_util.cc b/chrome/browser/chromeos/drive/file_system_util.cc
index 6a2e61c4d..9d3ebd2 100644
--- a/chrome/browser/chromeos/drive/file_system_util.cc
+++ b/chrome/browser/chromeos/drive/file_system_util.cc
@@ -10,6 +10,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/file_util.h"
+#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/i18n/icu_string_conversions.h"
#include "base/json/json_file_value_serializer.h"
@@ -104,6 +105,19 @@
return result;
}
+// 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);
+ }
+}
+
} // namespace
const base::FilePath& GetDriveGrandRootPath() {
@@ -295,6 +309,26 @@
*md5 = extension;
}
+void MigrateCacheFilesFromOldDirectories(
+ const base::FilePath& cache_root_directory) {
+ const base::FilePath persistent_directory =
+ cache_root_directory.AppendASCII("persistent");
+ const base::FilePath tmp_directory =
+ cache_root_directory.AppendASCII("tmp");
+ if (!file_util::PathExists(persistent_directory))
+ return;
+
+ const base::FilePath cache_file_directory =
+ cache_root_directory.Append(kCacheFileDirectory);
+
+ // Move all files inside "persistent" to "files".
+ MoveAllFilesFromDirectory(persistent_directory, cache_file_directory);
+ file_util::Delete(persistent_directory, true /* recursive */);
+
+ // Move all files inside "tmp" to "files".
+ MoveAllFilesFromDirectory(tmp_directory, cache_file_directory);
+}
+
void PrepareWritableFileAndRun(Profile* profile,
const base::FilePath& path,
const OpenFileCallback& callback) {
diff --git a/chrome/browser/chromeos/drive/file_system_util.h b/chrome/browser/chromeos/drive/file_system_util.h
index df1e3fe4..ffde7bc6 100644
--- a/chrome/browser/chromeos/drive/file_system_util.h
+++ b/chrome/browser/chromeos/drive/file_system_util.h
@@ -32,6 +32,17 @@
// Path constants.
+// Name of the directory used to store metadata.
+const base::FilePath::CharType kMetadataDirectory[] = FILE_PATH_LITERAL("meta");
+
+// Name of the directory used to store cached files.
+const base::FilePath::CharType kCacheFileDirectory[] =
+ FILE_PATH_LITERAL("files");
+
+// Name of the directory used to store temporary files.
+const base::FilePath::CharType kTemporaryFileDirectory[] =
+ FILE_PATH_LITERAL("tmp");
+
// The extension for dirty files. The file names look like
// "<resource-id>.local".
const base::FilePath::CharType kLocallyModifiedFileExtension[] =
@@ -137,6 +148,12 @@
std::string* resource_id,
std::string* md5);
+// Migrates cache files from old "persistent" and "tmp" directories to the new
+// "files" directory (see crbug.com/248905).
+// TODO(hashimoto): Remove this function at some point.
+void MigrateCacheFilesFromOldDirectories(
+ const base::FilePath& cache_root_directory);
+
// Callback type for PrepareWritableFileAndRun.
typedef base::Callback<void (FileError, const base::FilePath& path)>
OpenFileCallback;
diff --git a/chrome/browser/chromeos/drive/file_system_util_unittest.cc b/chrome/browser/chromeos/drive/file_system_util_unittest.cc
index 4a54efb..3ff445d 100644
--- a/chrome/browser/chromeos/drive/file_system_util_unittest.cc
+++ b/chrome/browser/chromeos/drive/file_system_util_unittest.cc
@@ -9,6 +9,7 @@
#include "base/files/scoped_temp_dir.h"
#include "base/message_loop.h"
#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/google_apis/test_util.h"
#include "chrome/test/base/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/browser/fileapi/external_mount_points.h"
@@ -199,6 +200,35 @@
EXPECT_EQ(md5, "");
}
+TEST(FileSystemUtilTest, MigrateCacheFilesFromOldDirectories) {
+ base::ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+
+ const base::FilePath persistent_directory =
+ temp_dir.path().AppendASCII("persistent");
+ const base::FilePath tmp_directory = temp_dir.path().AppendASCII("tmp");
+ const base::FilePath files_directory =
+ temp_dir.path().Append(kCacheFileDirectory);
+
+ // Prepare directories.
+ ASSERT_TRUE(file_util::CreateDirectory(persistent_directory));
+ ASSERT_TRUE(file_util::CreateDirectory(tmp_directory));
+ ASSERT_TRUE(file_util::CreateDirectory(files_directory));
+
+ // Put some files.
+ ASSERT_TRUE(google_apis::test_util::WriteStringToFile(
+ persistent_directory.AppendASCII("foo.abc"), "foo"));
+ ASSERT_TRUE(google_apis::test_util::WriteStringToFile(
+ tmp_directory.AppendASCII("bar.123"), "bar"));
+
+ // Migrate.
+ MigrateCacheFilesFromOldDirectories(temp_dir.path());
+
+ 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(FileSystemUtilTest, NeedsNamespaceMigration) {
// Not Drive cases.
EXPECT_FALSE(NeedsNamespaceMigration(
diff --git a/chrome/browser/chromeos/drive/remove_stale_cache_files_unittest.cc b/chrome/browser/chromeos/drive/remove_stale_cache_files_unittest.cc
index 080b77c..a0e4c89 100644
--- a/chrome/browser/chromeos/drive/remove_stale_cache_files_unittest.cc
+++ b/chrome/browser/chromeos/drive/remove_stale_cache_files_unittest.cc
@@ -29,12 +29,12 @@
fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter);
cache_.reset(new FileCache(temp_dir_.path(),
+ temp_dir_.path(),
base::MessageLoopProxy::current(),
fake_free_disk_space_getter_.get()));
resource_metadata_.reset(new ResourceMetadata(
- cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_META),
- base::MessageLoopProxy::current()));
+ temp_dir_.path(), base::MessageLoopProxy::current()));
ASSERT_TRUE(cache_->Initialize());
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->Initialize());
diff --git a/chrome/browser/chromeos/drive/search_metadata_unittest.cc b/chrome/browser/chromeos/drive/search_metadata_unittest.cc
index 182caaf..a5a4819 100644
--- a/chrome/browser/chromeos/drive/search_metadata_unittest.cc
+++ b/chrome/browser/chromeos/drive/search_metadata_unittest.cc
@@ -70,6 +70,7 @@
fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter);
cache_.reset(new internal::FileCache(temp_dir_.path(),
+ temp_dir_.path(),
blocking_task_runner_.get(),
fake_free_disk_space_getter_.get()));
diff --git a/chrome/browser/chromeos/drive/sync_client.cc b/chrome/browser/chromeos/drive/sync_client.cc
index afcc7592..4d12ff3 100644
--- a/chrome/browser/chromeos/drive/sync_client.cc
+++ b/chrome/browser/chromeos/drive/sync_client.cc
@@ -61,7 +61,8 @@
file_system::OperationObserver* observer,
JobScheduler* scheduler,
ResourceMetadata* metadata,
- FileCache* cache)
+ FileCache* cache,
+ const base::FilePath& temporary_file_directory)
: metadata_(metadata),
cache_(cache),
download_operation_(new file_system::DownloadOperation(
@@ -69,7 +70,8 @@
observer,
scheduler,
metadata,
- cache)),
+ cache,
+ temporary_file_directory)),
update_operation_(new file_system::UpdateOperation(blocking_task_runner,
observer,
scheduler,
diff --git a/chrome/browser/chromeos/drive/sync_client.h b/chrome/browser/chromeos/drive/sync_client.h
index bbc53af..a5a66e8 100644
--- a/chrome/browser/chromeos/drive/sync_client.h
+++ b/chrome/browser/chromeos/drive/sync_client.h
@@ -53,7 +53,8 @@
file_system::OperationObserver* observer,
JobScheduler* scheduler,
ResourceMetadata* metadata,
- FileCache* cache);
+ FileCache* cache,
+ const base::FilePath& temporary_file_directory);
virtual ~SyncClient();
// Adds a fetch task to the queue.
diff --git a/chrome/browser/chromeos/drive/sync_client_unittest.cc b/chrome/browser/chromeos/drive/sync_client_unittest.cc
index 37ec8e2a..4aae5203 100644
--- a/chrome/browser/chromeos/drive/sync_client_unittest.cc
+++ b/chrome/browser/chromeos/drive/sync_client_unittest.cc
@@ -91,6 +91,7 @@
ASSERT_EQ(FILE_ERROR_OK, metadata_->Initialize());
cache_.reset(new FileCache(temp_dir_.path(),
+ temp_dir_.path(),
base::MessageLoopProxy::current(),
NULL /* free_disk_space_getter */));
ASSERT_TRUE(cache_->Initialize());
@@ -101,7 +102,8 @@
&observer_,
scheduler_.get(),
metadata_.get(),
- cache_.get()));
+ cache_.get(),
+ temp_dir_.path()));
// Disable delaying so that DoSyncLoop() starts immediately.
sync_client_->set_delay_for_testing(base::TimeDelta::FromSeconds(0));