drive: Stop returning FilePath from GetResourceEntryById

ResourceMetadata::GetResourceEntryById no longer returns FilePath.
FileSystemInterface::GetResourceEntryById no longer returns FilePath.
Remove GetFilePath related code from FakeFileSystem.

BUG=244135
TEST=unit_tests
R=satorux@chromium.org

Review URL: https://codereview.chromium.org/16107004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203075 0039d316-1c4b-4281-b951-d872f2087c98
parent b3ae2db1
...@@ -163,8 +163,9 @@ void ChangeListProcessor::ApplyEntryMap( ...@@ -163,8 +163,9 @@ void ChangeListProcessor::ApplyEntryMap(
void ChangeListProcessor::ApplyEntry(const ResourceEntry& entry) { void ChangeListProcessor::ApplyEntry(const ResourceEntry& entry) {
// Lookup the entry. // Lookup the entry.
FileError error = ResourceEntry existing_entry;
resource_metadata_->GetResourceEntryById(entry.resource_id(), NULL, NULL); FileError error = resource_metadata_->GetResourceEntryById(
entry.resource_id(), &existing_entry);
if (error == FILE_ERROR_OK) { if (error == FILE_ERROR_OK) {
if (entry.deleted()) { if (entry.deleted()) {
......
...@@ -19,7 +19,7 @@ class DummyFileSystem : public FileSystemInterface { ...@@ -19,7 +19,7 @@ class DummyFileSystem : public FileSystemInterface {
virtual void CheckForUpdates() OVERRIDE {} virtual void CheckForUpdates() OVERRIDE {}
virtual void GetResourceEntryById( virtual void GetResourceEntryById(
const std::string& resource_id, const std::string& resource_id,
const GetResourceEntryWithFilePathCallback& callback) OVERRIDE {} const GetResourceEntryCallback& callback) OVERRIDE {}
virtual void TransferFileFromRemoteToLocal( virtual void TransferFileFromRemoteToLocal(
const base::FilePath& remote_src_file_path, const base::FilePath& remote_src_file_path,
const base::FilePath& local_dest_file_path, const base::FilePath& local_dest_file_path,
......
...@@ -56,7 +56,7 @@ void FakeFileSystem::CheckForUpdates() { ...@@ -56,7 +56,7 @@ void FakeFileSystem::CheckForUpdates() {
void FakeFileSystem::GetResourceEntryById( void FakeFileSystem::GetResourceEntryById(
const std::string& resource_id, const std::string& resource_id,
const GetResourceEntryWithFilePathCallback& callback) { const GetResourceEntryCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
drive_service_->GetResourceEntry( drive_service_->GetResourceEntry(
...@@ -256,109 +256,20 @@ void FakeFileSystem::GetCacheEntryByResourceId( ...@@ -256,109 +256,20 @@ void FakeFileSystem::GetCacheEntryByResourceId(
void FakeFileSystem::Reload() { void FakeFileSystem::Reload() {
} }
// Implementation of GetFilePath.
void FakeFileSystem::GetFilePath(const std::string& resource_id,
const GetFilePathCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
drive_service_->GetAboutResource(
base::Bind(
&FakeFileSystem::GetFilePathAfterGetAboutResource,
weak_ptr_factory_.GetWeakPtr(), resource_id, callback));
}
void FakeFileSystem::GetFilePathAfterGetAboutResource(
const std::string& resource_id,
const GetFilePathCallback& callback,
google_apis::GDataErrorCode error,
scoped_ptr<google_apis::AboutResource> about_resource) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// We assume the call always success for test.
DCHECK_EQ(util::GDataToFileError(error), FILE_ERROR_OK);
DCHECK(about_resource);
GetFilePathInternal(about_resource->root_folder_id(), resource_id,
base::FilePath(), callback);
}
void FakeFileSystem::GetFilePathInternal(
const std::string& root_resource_id,
const std::string& resource_id,
const base::FilePath& file_path,
const GetFilePathCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (resource_id == root_resource_id) {
// Reached to the root. Append the drive root path, and run |callback|.
callback.Run(util::GetDriveMyDriveRootPath().Append(file_path));
return;
}
drive_service_->GetResourceEntry(
resource_id,
base::Bind(
&FakeFileSystem::GetFilePathAfterGetResourceEntry,
weak_ptr_factory_.GetWeakPtr(),
root_resource_id, file_path, callback));
}
void FakeFileSystem::GetFilePathAfterGetResourceEntry(
const std::string& root_resource_id,
const base::FilePath& remaining_file_path,
const GetFilePathCallback& callback,
google_apis::GDataErrorCode error_in,
scoped_ptr<google_apis::ResourceEntry> resource_entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// We assume the call always success for test.
DCHECK_EQ(util::GDataToFileError(error_in), FILE_ERROR_OK);
DCHECK(resource_entry);
ResourceEntry entry = ConvertToResourceEntry(*resource_entry);
base::FilePath file_path =
base::FilePath::FromUTF8Unsafe(entry.base_name()).Append(
remaining_file_path);
GetFilePathInternal(root_resource_id, entry.parent_resource_id(),
file_path, callback);
}
// Implementation of GetResourceEntryById. // Implementation of GetResourceEntryById.
void FakeFileSystem::GetResourceEntryByIdAfterGetResourceEntry( void FakeFileSystem::GetResourceEntryByIdAfterGetResourceEntry(
const GetResourceEntryWithFilePathCallback& callback, const GetResourceEntryCallback& callback,
google_apis::GDataErrorCode error_in, google_apis::GDataErrorCode error_in,
scoped_ptr<google_apis::ResourceEntry> resource_entry) { scoped_ptr<google_apis::ResourceEntry> resource_entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
FileError error = util::GDataToFileError(error_in); FileError error = util::GDataToFileError(error_in);
if (error != FILE_ERROR_OK) { scoped_ptr<ResourceEntry> entry;
callback.Run(error, base::FilePath(), scoped_ptr<ResourceEntry>()); if (error == FILE_ERROR_OK) {
return; DCHECK(resource_entry);
entry.reset(new ResourceEntry(ConvertToResourceEntry(*resource_entry)));
} }
callback.Run(error, entry.Pass());
DCHECK(resource_entry);
scoped_ptr<ResourceEntry> entry(new ResourceEntry(
ConvertToResourceEntry(*resource_entry)));
const std::string parent_resource_id = entry->parent_resource_id();
GetFilePath(
parent_resource_id,
base::Bind(
&FakeFileSystem::GetResourceEntryByIdAfterGetFilePath,
weak_ptr_factory_.GetWeakPtr(),
callback, error, base::Passed(&entry)));
}
void FakeFileSystem::GetResourceEntryByIdAfterGetFilePath(
const GetResourceEntryWithFilePathCallback& callback,
FileError error,
scoped_ptr<ResourceEntry> entry,
const base::FilePath& parent_file_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
base::FilePath file_path = parent_file_path.Append(
base::FilePath::FromUTF8Unsafe(entry->base_name()));
callback.Run(error, file_path, entry.Pass());
} }
// Implementation of GetFileContentByPath. // Implementation of GetFileContentByPath.
......
...@@ -53,7 +53,7 @@ class FakeFileSystem : public FileSystemInterface { ...@@ -53,7 +53,7 @@ class FakeFileSystem : public FileSystemInterface {
virtual void CheckForUpdates() OVERRIDE; virtual void CheckForUpdates() OVERRIDE;
virtual void GetResourceEntryById( virtual void GetResourceEntryById(
const std::string& resource_id, const std::string& resource_id,
const GetResourceEntryWithFilePathCallback& callback) OVERRIDE; const GetResourceEntryCallback& callback) OVERRIDE;
virtual void TransferFileFromRemoteToLocal( virtual void TransferFileFromRemoteToLocal(
const base::FilePath& remote_src_file_path, const base::FilePath& remote_src_file_path,
const base::FilePath& local_dest_file_path, const base::FilePath& local_dest_file_path,
...@@ -139,49 +139,11 @@ class FakeFileSystem : public FileSystemInterface { ...@@ -139,49 +139,11 @@ class FakeFileSystem : public FileSystemInterface {
virtual void Reload() OVERRIDE; virtual void Reload() OVERRIDE;
private: private:
// Callback to return the result of GetFilePath. // Helper of GetResourceEntryById.
typedef base::Callback<void(const base::FilePath& file_path)>
GetFilePathCallback;
// Returns the path for the |resource_id| via |callback|.
// How the method works:
// 1) Gets AboutResource from the drive service to obtain root resource id.
// 2) Gets ResourceEntry from the drive service to get the base name,
// prepends it to the |file_path|. Unless it is root, also tries for
// the parent recursively.
void GetFilePath(const std::string& resource_id,
const GetFilePathCallback& callback);
void GetFilePathAfterGetAboutResource(
const std::string& resource_id,
const GetFilePathCallback& callback,
google_apis::GDataErrorCode error,
scoped_ptr<google_apis::AboutResource> about_resource);
void GetFilePathInternal(
const std::string& root_resource_id,
const std::string& resource_id,
const base::FilePath& file_path,
const GetFilePathCallback& callback);
void GetFilePathAfterGetResourceEntry(
const std::string& root_resource_id,
const base::FilePath& remaining_file_path,
const GetFilePathCallback& callback,
google_apis::GDataErrorCode error_in,
scoped_ptr<google_apis::ResourceEntry> resource_entry);
// Helpers of GetResourceEntryById.
// How the method works:
// 1) Gets ResourceEntry from the drive service.
// 2) Gets the file path of the resource.
// 3) Runs the |callback|.
void GetResourceEntryByIdAfterGetResourceEntry( void GetResourceEntryByIdAfterGetResourceEntry(
const GetResourceEntryWithFilePathCallback& callback, const GetResourceEntryCallback& callback,
google_apis::GDataErrorCode error_in, google_apis::GDataErrorCode error_in,
scoped_ptr<google_apis::ResourceEntry> resource_entry); scoped_ptr<google_apis::ResourceEntry> resource_entry);
void GetResourceEntryByIdAfterGetFilePath(
const GetResourceEntryWithFilePathCallback& callback,
FileError error,
scoped_ptr<ResourceEntry> entry,
const base::FilePath& parent_file_path);
// Helpers of GetFileContentByPath. // Helpers of GetFileContentByPath.
// How the method works: // How the method works:
......
...@@ -46,52 +46,15 @@ class FakeFileSystemTest : public ::testing::Test { ...@@ -46,52 +46,15 @@ class FakeFileSystemTest : public ::testing::Test {
TEST_F(FakeFileSystemTest, GetResourceEntryById) { TEST_F(FakeFileSystemTest, GetResourceEntryById) {
FileError error = FILE_ERROR_FAILED; FileError error = FILE_ERROR_FAILED;
scoped_ptr<ResourceEntry> entry; scoped_ptr<ResourceEntry> entry;
base::FilePath file_path; const std::string resource_id = "folder:sub_dir_folder_resource_id";
fake_file_system_->GetResourceEntryById( fake_file_system_->GetResourceEntryById(
"folder:sub_dir_folder_resource_id", resource_id,
google_apis::test_util::CreateCopyResultCallback(
&error, &file_path, &entry));
google_apis::test_util::RunBlockingPoolTask();
ASSERT_EQ(FILE_ERROR_OK, error);
EXPECT_EQ(
util::GetDriveMyDriveRootPath().AppendASCII(
"Directory 1/Sub Directory Folder"),
file_path);
EXPECT_TRUE(entry); // Just make sure something is returned.
}
TEST_F(FakeFileSystemTest,
GetResourceEntryById_PathCompatibleWithGetResourceEntryByPath) {
const std::string document_resource_id = "document:5_document_resource_id";
FileError error = FILE_ERROR_FAILED;
scoped_ptr<ResourceEntry> entry;
base::FilePath file_path;
// Get resource entry by resource id.
fake_file_system_->GetResourceEntryById(
document_resource_id,
google_apis::test_util::CreateCopyResultCallback(
&error, &file_path, &entry));
google_apis::test_util::RunBlockingPoolTask();
ASSERT_EQ(FILE_ERROR_OK, error);
ASSERT_TRUE(entry);
EXPECT_TRUE(entry->file_specific_info().is_hosted_document());
// Get resource entry by path given by GetResourceEntryById.
error = FILE_ERROR_FAILED;
entry.reset();
fake_file_system_->GetResourceEntryByPath(
file_path,
google_apis::test_util::CreateCopyResultCallback(&error, &entry)); google_apis::test_util::CreateCopyResultCallback(&error, &entry));
google_apis::test_util::RunBlockingPoolTask(); google_apis::test_util::RunBlockingPoolTask();
ASSERT_EQ(FILE_ERROR_OK, error); ASSERT_EQ(FILE_ERROR_OK, error);
ASSERT_TRUE(entry); EXPECT_EQ(resource_id, entry->resource_id());
EXPECT_EQ(document_resource_id, entry->resource_id());
} }
TEST_F(FakeFileSystemTest, GetFileContentByPath) { TEST_F(FakeFileSystemTest, GetFileContentByPath) {
......
...@@ -39,17 +39,6 @@ namespace { ...@@ -39,17 +39,6 @@ namespace {
//================================ Helper functions ============================ //================================ Helper functions ============================
// Helper function for binding |path| to GetResourceEntryWithFilePathCallback
// and create GetResourceEntryCallback.
void RunGetResourceEntryWithFilePathCallback(
const GetResourceEntryWithFilePathCallback& callback,
const base::FilePath& path,
FileError error,
scoped_ptr<ResourceEntry> entry) {
DCHECK(!callback.is_null());
callback.Run(error, path, entry.Pass());
}
// Callback for ResourceMetadata::GetLargestChangestamp. // Callback for ResourceMetadata::GetLargestChangestamp.
// |callback| must not be null. // |callback| must not be null.
void OnGetLargestChangestamp( void OnGetLargestChangestamp(
...@@ -179,7 +168,7 @@ void FileSystem::RemoveObserver(FileSystemObserver* observer) { ...@@ -179,7 +168,7 @@ void FileSystem::RemoveObserver(FileSystemObserver* observer) {
void FileSystem::GetResourceEntryById( void FileSystem::GetResourceEntryById(
const std::string& resource_id, const std::string& resource_id,
const GetResourceEntryWithFilePathCallback& callback) { const GetResourceEntryCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!resource_id.empty()); DCHECK(!resource_id.empty());
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
...@@ -192,24 +181,19 @@ void FileSystem::GetResourceEntryById( ...@@ -192,24 +181,19 @@ void FileSystem::GetResourceEntryById(
} }
void FileSystem::GetResourceEntryByIdAfterGetEntry( void FileSystem::GetResourceEntryByIdAfterGetEntry(
const GetResourceEntryWithFilePathCallback& callback, const GetResourceEntryCallback& callback,
FileError error, FileError error,
const base::FilePath& file_path,
scoped_ptr<ResourceEntry> entry) { scoped_ptr<ResourceEntry> entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
if (error != FILE_ERROR_OK) { if (error != FILE_ERROR_OK) {
callback.Run(error, base::FilePath(), scoped_ptr<ResourceEntry>()); callback.Run(error, scoped_ptr<ResourceEntry>());
return; return;
} }
DCHECK(entry.get()); DCHECK(entry.get());
CheckLocalModificationAndRun( CheckLocalModificationAndRun(entry.Pass(), callback);
entry.Pass(),
base::Bind(&RunGetResourceEntryWithFilePathCallback,
callback,
file_path));
} }
void FileSystem::TransferFileFromRemoteToLocal( void FileSystem::TransferFileFromRemoteToLocal(
......
...@@ -64,7 +64,7 @@ class FileSystem : public FileSystemInterface, ...@@ -64,7 +64,7 @@ class FileSystem : public FileSystemInterface,
virtual void CheckForUpdates() OVERRIDE; virtual void CheckForUpdates() OVERRIDE;
virtual void GetResourceEntryById( virtual void GetResourceEntryById(
const std::string& resource_id, const std::string& resource_id,
const GetResourceEntryWithFilePathCallback& callback) OVERRIDE; const GetResourceEntryCallback& callback) OVERRIDE;
virtual void Search(const std::string& search_query, virtual void Search(const std::string& search_query,
const GURL& next_feed, const GURL& next_feed,
const SearchCallback& callback) OVERRIDE; const SearchCallback& callback) OVERRIDE;
...@@ -295,9 +295,8 @@ class FileSystem : public FileSystemInterface, ...@@ -295,9 +295,8 @@ class FileSystem : public FileSystemInterface,
// ResourceMetadata::GetResourceEntryById() is complete. // ResourceMetadata::GetResourceEntryById() is complete.
// |callback| must not be null. // |callback| must not be null.
void GetResourceEntryByIdAfterGetEntry( void GetResourceEntryByIdAfterGetEntry(
const GetResourceEntryWithFilePathCallback& callback, const GetResourceEntryCallback& callback,
FileError error, FileError error,
const base::FilePath& file_path,
scoped_ptr<ResourceEntry> entry); scoped_ptr<ResourceEntry> entry);
// Part of RefreshDirectory(). Called after // Part of RefreshDirectory(). Called after
......
...@@ -105,7 +105,7 @@ base::FilePath CreateDirectoryOperation::GetExistingDeepestDirectory( ...@@ -105,7 +105,7 @@ base::FilePath CreateDirectoryOperation::GetExistingDeepestDirectory(
resource_id = child_resource_id; resource_id = child_resource_id;
} }
FileError error = metadata->GetResourceEntryById(resource_id, NULL, entry); FileError error = metadata->GetResourceEntryById(resource_id, entry);
DCHECK_EQ(FILE_ERROR_OK, error); DCHECK_EQ(FILE_ERROR_OK, error);
if (!entry->file_info().is_directory()) if (!entry->file_info().is_directory())
......
...@@ -83,7 +83,7 @@ FileError CheckPreConditionForEnsureFileDownloadedByResourceId( ...@@ -83,7 +83,7 @@ FileError CheckPreConditionForEnsureFileDownloadedByResourceId(
const std::string& resource_id, const std::string& resource_id,
base::FilePath* cache_file_path, base::FilePath* cache_file_path,
ResourceEntry* entry) { ResourceEntry* entry) {
FileError error = metadata->GetResourceEntryById(resource_id, NULL, entry); FileError error = metadata->GetResourceEntryById(resource_id, entry);
if (error != FILE_ERROR_OK) if (error != FILE_ERROR_OK)
return error; return error;
return CheckPreConditionForEnsureFileDownloaded( return CheckPreConditionForEnsureFileDownloaded(
......
...@@ -27,7 +27,7 @@ FileError GetFileLocalState(internal::ResourceMetadata* metadata, ...@@ -27,7 +27,7 @@ FileError GetFileLocalState(internal::ResourceMetadata* metadata,
ResourceEntry* entry, ResourceEntry* entry,
base::FilePath* drive_file_path, base::FilePath* drive_file_path,
base::FilePath* cache_file_path) { base::FilePath* cache_file_path) {
FileError error = metadata->GetResourceEntryById(resource_id, NULL, entry); FileError error = metadata->GetResourceEntryById(resource_id, entry);
if (error != FILE_ERROR_OK) if (error != FILE_ERROR_OK)
return error; return error;
......
...@@ -169,7 +169,7 @@ class FileSystemInterface { ...@@ -169,7 +169,7 @@ class FileSystemInterface {
// |callback| must not be null. // |callback| must not be null.
virtual void GetResourceEntryById( virtual void GetResourceEntryById(
const std::string& resource_id, const std::string& resource_id,
const GetResourceEntryWithFilePathCallback& callback) = 0; const GetResourceEntryCallback& callback) = 0;
// Initiates transfer of |remote_src_file_path| to |local_dest_file_path|. // Initiates transfer of |remote_src_file_path| to |local_dest_file_path|.
// |remote_src_file_path| is the virtual source path on the Drive file system. // |remote_src_file_path| is the virtual source path on the Drive file system.
......
...@@ -28,7 +28,7 @@ class MockFileSystem : public FileSystemInterface { ...@@ -28,7 +28,7 @@ class MockFileSystem : public FileSystemInterface {
MOCK_METHOD0(CheckForUpdates, void()); MOCK_METHOD0(CheckForUpdates, void());
MOCK_METHOD2(GetResourceEntryById, MOCK_METHOD2(GetResourceEntryById,
void(const std::string& resource_id, void(const std::string& resource_id,
const GetResourceEntryWithFilePathCallback& callback)); const GetResourceEntryCallback& callback));
MOCK_METHOD3(Search, void(const std::string& search_query, MOCK_METHOD3(Search, void(const std::string& search_query,
const GURL& next_feed, const GURL& next_feed,
const SearchCallback& callback)); const SearchCallback& callback));
......
...@@ -26,7 +26,7 @@ void CollectStaleCacheFiles( ...@@ -26,7 +26,7 @@ void CollectStaleCacheFiles(
const FileCacheEntry& cache_entry) { const FileCacheEntry& cache_entry) {
ResourceEntry entry; ResourceEntry entry;
FileError error = resource_metadata->GetResourceEntryById( FileError error = resource_metadata->GetResourceEntryById(
resource_id, NULL, &entry); resource_id, &entry);
// The entry is not found or the MD5 does not match. // The entry is not found or the MD5 does not match.
if (error != FILE_ERROR_OK || if (error != FILE_ERROR_OK ||
......
...@@ -82,9 +82,8 @@ TEST_F(RemoveStaleCacheFilesTest, RemoveStaleCacheFiles) { ...@@ -82,9 +82,8 @@ TEST_F(RemoveStaleCacheFilesTest, RemoveStaleCacheFiles) {
EXPECT_TRUE(cache_->GetCacheEntry(resource_id, md5, &cache_entry)); EXPECT_TRUE(cache_->GetCacheEntry(resource_id, md5, &cache_entry));
ResourceEntry entry; ResourceEntry entry;
EXPECT_EQ( EXPECT_EQ(FILE_ERROR_NOT_FOUND,
FILE_ERROR_NOT_FOUND, resource_metadata_->GetResourceEntryById(resource_id, &entry));
resource_metadata_->GetResourceEntryById(resource_id, NULL, &entry));
// Remove stale cache files. // Remove stale cache files.
RemoveStaleCacheFiles(cache_.get(), resource_metadata_.get()); RemoveStaleCacheFiles(cache_.get(), resource_metadata_.get());
......
...@@ -390,11 +390,10 @@ FileError ResourceMetadata::RemoveEntry(const std::string& resource_id, ...@@ -390,11 +390,10 @@ FileError ResourceMetadata::RemoveEntry(const std::string& resource_id,
void ResourceMetadata::GetResourceEntryByIdOnUIThread( void ResourceMetadata::GetResourceEntryByIdOnUIThread(
const std::string& resource_id, const std::string& resource_id,
const GetResourceEntryWithFilePathCallback& callback) { const GetResourceEntryCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
base::FilePath* file_path = new base::FilePath;
scoped_ptr<ResourceEntry> entry(new ResourceEntry); scoped_ptr<ResourceEntry> entry(new ResourceEntry);
ResourceEntry* entry_ptr = entry.get(); ResourceEntry* entry_ptr = entry.get();
base::PostTaskAndReplyWithResult( base::PostTaskAndReplyWithResult(
...@@ -403,30 +402,24 @@ void ResourceMetadata::GetResourceEntryByIdOnUIThread( ...@@ -403,30 +402,24 @@ void ResourceMetadata::GetResourceEntryByIdOnUIThread(
base::Bind(&ResourceMetadata::GetResourceEntryById, base::Bind(&ResourceMetadata::GetResourceEntryById,
base::Unretained(this), base::Unretained(this),
resource_id, resource_id,
file_path,
entry_ptr), entry_ptr),
base::Bind(&RunGetResourceEntryWithFilePathCallback, base::Bind(&RunGetResourceEntryCallback,
callback, callback,
base::Owned(file_path),
base::Passed(&entry))); base::Passed(&entry)));
} }
FileError ResourceMetadata::GetResourceEntryById( FileError ResourceMetadata::GetResourceEntryById(
const std::string& resource_id, const std::string& resource_id,
base::FilePath* out_file_path,
ResourceEntry* out_entry) { ResourceEntry* out_entry) {
DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
DCHECK(!resource_id.empty()); DCHECK(!resource_id.empty());
DCHECK(out_entry);
scoped_ptr<ResourceEntry> entry = storage_->GetEntry(resource_id); scoped_ptr<ResourceEntry> entry = storage_->GetEntry(resource_id);
if (!entry) if (!entry)
return FILE_ERROR_NOT_FOUND; return FILE_ERROR_NOT_FOUND;
if (out_file_path) out_entry->Swap(entry.get());
*out_file_path = GetFilePath(resource_id);
if (out_entry)
*out_entry = *entry;
return FILE_ERROR_OK; return FILE_ERROR_OK;
} }
......
...@@ -202,13 +202,11 @@ class ResourceMetadata { ...@@ -202,13 +202,11 @@ class ResourceMetadata {
// Finds an entry (a file or a directory) by |resource_id|. // Finds an entry (a file or a directory) by |resource_id|.
// |callback| must not be null. // |callback| must not be null.
// Must be called on the UI thread. // Must be called on the UI thread.
void GetResourceEntryByIdOnUIThread( void GetResourceEntryByIdOnUIThread(const std::string& resource_id,
const std::string& resource_id, const GetResourceEntryCallback& callback);
const GetResourceEntryWithFilePathCallback& callback);
// Synchronous version of GetResourceEntryByIdOnUIThread(). // Synchronous version of GetResourceEntryByIdOnUIThread().
FileError GetResourceEntryById(const std::string& resource_id, FileError GetResourceEntryById(const std::string& resource_id,
base::FilePath* out_file_path,
ResourceEntry* out_entry); ResourceEntry* out_entry);
// Finds an entry (a file or a directory) by |file_path|. // Finds an entry (a file or a directory) by |file_path|.
......
...@@ -254,17 +254,14 @@ TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryById_RootDirectory) { ...@@ -254,17 +254,14 @@ TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryById_RootDirectory) {
google_apis::test_util::RunBlockingPoolTask(); google_apis::test_util::RunBlockingPoolTask();
ASSERT_EQ(FILE_ERROR_OK, error); ASSERT_EQ(FILE_ERROR_OK, error);
base::FilePath drive_file_path;
scoped_ptr<ResourceEntry> entry; scoped_ptr<ResourceEntry> entry;
// Look up the root directory by its resource ID. // Look up the root directory by its resource ID.
resource_metadata->GetResourceEntryByIdOnUIThread( resource_metadata->GetResourceEntryByIdOnUIThread(
util::kDriveGrandRootSpecialResourceId, util::kDriveGrandRootSpecialResourceId,
google_apis::test_util::CreateCopyResultCallback( google_apis::test_util::CreateCopyResultCallback(&error, &entry));
&error, &drive_file_path, &entry));
google_apis::test_util::RunBlockingPoolTask(); google_apis::test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error); EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive"), drive_file_path);
ASSERT_TRUE(entry.get()); ASSERT_TRUE(entry.get());
EXPECT_EQ("drive", entry->base_name()); EXPECT_EQ("drive", entry->base_name());
} }
...@@ -272,16 +269,12 @@ TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryById_RootDirectory) { ...@@ -272,16 +269,12 @@ TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryById_RootDirectory) {
TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryById) { TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryById) {
// Confirm that an existing file is found. // Confirm that an existing file is found.
FileError error = FILE_ERROR_FAILED; FileError error = FILE_ERROR_FAILED;
base::FilePath drive_file_path;
scoped_ptr<ResourceEntry> entry; scoped_ptr<ResourceEntry> entry;
resource_metadata_->GetResourceEntryByIdOnUIThread( resource_metadata_->GetResourceEntryByIdOnUIThread(
"resource_id:file4", "resource_id:file4",
google_apis::test_util::CreateCopyResultCallback( google_apis::test_util::CreateCopyResultCallback(&error, &entry));
&error, &drive_file_path, &entry));
google_apis::test_util::RunBlockingPoolTask(); google_apis::test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error); EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/file4"),
drive_file_path);
ASSERT_TRUE(entry.get()); ASSERT_TRUE(entry.get());
EXPECT_EQ("file4", entry->base_name()); EXPECT_EQ("file4", entry->base_name());
...@@ -290,8 +283,7 @@ TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryById) { ...@@ -290,8 +283,7 @@ TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryById) {
entry.reset(); entry.reset();
resource_metadata_->GetResourceEntryByIdOnUIThread( resource_metadata_->GetResourceEntryByIdOnUIThread(
"file:non_existing", "file:non_existing",
google_apis::test_util::CreateCopyResultCallback( google_apis::test_util::CreateCopyResultCallback(&error, &entry));
&error, &drive_file_path, &entry));
google_apis::test_util::RunBlockingPoolTask(); google_apis::test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
EXPECT_FALSE(entry.get()); EXPECT_FALSE(entry.get());
...@@ -449,21 +441,18 @@ TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryPairByPaths) { ...@@ -449,21 +441,18 @@ TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryPairByPaths) {
TEST_F(ResourceMetadataTestOnUIThread, RemoveEntry) { TEST_F(ResourceMetadataTestOnUIThread, RemoveEntry) {
// Make sure file9 is found. // Make sure file9 is found.
FileError error = FILE_ERROR_FAILED; FileError error = FILE_ERROR_FAILED;
base::FilePath drive_file_path;
const std::string file9_resource_id = "resource_id:file9"; const std::string file9_resource_id = "resource_id:file9";
scoped_ptr<ResourceEntry> entry; scoped_ptr<ResourceEntry> entry;
resource_metadata_->GetResourceEntryByIdOnUIThread( resource_metadata_->GetResourceEntryByIdOnUIThread(
file9_resource_id, file9_resource_id,
google_apis::test_util::CreateCopyResultCallback( google_apis::test_util::CreateCopyResultCallback(&error, &entry));
&error, &drive_file_path, &entry));
google_apis::test_util::RunBlockingPoolTask(); google_apis::test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error); EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3/file9"),
drive_file_path);
ASSERT_TRUE(entry.get()); ASSERT_TRUE(entry.get());
EXPECT_EQ("file9", entry->base_name()); EXPECT_EQ("file9", entry->base_name());
// Remove file9 using RemoveEntry. // Remove file9 using RemoveEntry.
base::FilePath drive_file_path;
resource_metadata_->RemoveEntryOnUIThread( resource_metadata_->RemoveEntryOnUIThread(
file9_resource_id, file9_resource_id,
google_apis::test_util::CreateCopyResultCallback( google_apis::test_util::CreateCopyResultCallback(
...@@ -476,8 +465,7 @@ TEST_F(ResourceMetadataTestOnUIThread, RemoveEntry) { ...@@ -476,8 +465,7 @@ TEST_F(ResourceMetadataTestOnUIThread, RemoveEntry) {
// file9 should no longer exist. // file9 should no longer exist.
resource_metadata_->GetResourceEntryByIdOnUIThread( resource_metadata_->GetResourceEntryByIdOnUIThread(
file9_resource_id, file9_resource_id,
google_apis::test_util::CreateCopyResultCallback( google_apis::test_util::CreateCopyResultCallback(&error, &entry));
&error, &drive_file_path, &entry));
google_apis::test_util::RunBlockingPoolTask(); google_apis::test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
EXPECT_FALSE(entry.get()); EXPECT_FALSE(entry.get());
...@@ -486,12 +474,9 @@ TEST_F(ResourceMetadataTestOnUIThread, RemoveEntry) { ...@@ -486,12 +474,9 @@ TEST_F(ResourceMetadataTestOnUIThread, RemoveEntry) {
const std::string dir3_resource_id = "resource_id:dir3"; const std::string dir3_resource_id = "resource_id:dir3";
resource_metadata_->GetResourceEntryByIdOnUIThread( resource_metadata_->GetResourceEntryByIdOnUIThread(
dir3_resource_id, dir3_resource_id,
google_apis::test_util::CreateCopyResultCallback( google_apis::test_util::CreateCopyResultCallback(&error, &entry));
&error, &drive_file_path, &entry));
google_apis::test_util::RunBlockingPoolTask(); google_apis::test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error); EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3"),
drive_file_path);
ASSERT_TRUE(entry.get()); ASSERT_TRUE(entry.get());
EXPECT_EQ("dir3", entry->base_name()); EXPECT_EQ("dir3", entry->base_name());
...@@ -507,8 +492,7 @@ TEST_F(ResourceMetadataTestOnUIThread, RemoveEntry) { ...@@ -507,8 +492,7 @@ TEST_F(ResourceMetadataTestOnUIThread, RemoveEntry) {
// dir3 should no longer exist. // dir3 should no longer exist.
resource_metadata_->GetResourceEntryByIdOnUIThread( resource_metadata_->GetResourceEntryByIdOnUIThread(
dir3_resource_id, dir3_resource_id,
google_apis::test_util::CreateCopyResultCallback( google_apis::test_util::CreateCopyResultCallback(&error, &entry));
&error, &drive_file_path, &entry));
google_apis::test_util::RunBlockingPoolTask(); google_apis::test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
EXPECT_FALSE(entry.get()); EXPECT_FALSE(entry.get());
...@@ -549,12 +533,9 @@ TEST_F(ResourceMetadataTestOnUIThread, MoveEntryToDirectory) { ...@@ -549,12 +533,9 @@ TEST_F(ResourceMetadataTestOnUIThread, MoveEntryToDirectory) {
// Look up the entry by its resource id and make sure it really moved. // Look up the entry by its resource id and make sure it really moved.
resource_metadata_->GetResourceEntryByIdOnUIThread( resource_metadata_->GetResourceEntryByIdOnUIThread(
"resource_id:file8", "resource_id:file8",
google_apis::test_util::CreateCopyResultCallback( google_apis::test_util::CreateCopyResultCallback(&error, &entry));
&error, &drive_file_path, &entry));
google_apis::test_util::RunBlockingPoolTask(); google_apis::test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error); EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/file8"),
drive_file_path);
// Move non-existent file to drive/dir1. This should fail. // Move non-existent file to drive/dir1. This should fail.
resource_metadata_->MoveEntryToDirectoryOnUIThread( resource_metadata_->MoveEntryToDirectoryOnUIThread(
...@@ -611,12 +592,9 @@ TEST_F(ResourceMetadataTestOnUIThread, MoveEntryToDirectory) { ...@@ -611,12 +592,9 @@ TEST_F(ResourceMetadataTestOnUIThread, MoveEntryToDirectory) {
// Make sure file is still ok. // Make sure file is still ok.
resource_metadata_->GetResourceEntryByIdOnUIThread( resource_metadata_->GetResourceEntryByIdOnUIThread(
"resource_id:file8", "resource_id:file8",
google_apis::test_util::CreateCopyResultCallback( google_apis::test_util::CreateCopyResultCallback(&error, &entry));
&error, &drive_file_path, &entry));
google_apis::test_util::RunBlockingPoolTask(); google_apis::test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error); EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir2/file8"),
drive_file_path);
} }
TEST_F(ResourceMetadataTestOnUIThread, RenameEntry) { TEST_F(ResourceMetadataTestOnUIThread, RenameEntry) {
...@@ -638,12 +616,9 @@ TEST_F(ResourceMetadataTestOnUIThread, RenameEntry) { ...@@ -638,12 +616,9 @@ TEST_F(ResourceMetadataTestOnUIThread, RenameEntry) {
// Lookup the file by resource id to make sure the file actually got renamed. // Lookup the file by resource id to make sure the file actually got renamed.
resource_metadata_->GetResourceEntryByIdOnUIThread( resource_metadata_->GetResourceEntryByIdOnUIThread(
"resource_id:file8", "resource_id:file8",
google_apis::test_util::CreateCopyResultCallback( google_apis::test_util::CreateCopyResultCallback(&error, &entry));
&error, &drive_file_path, &entry));
google_apis::test_util::RunBlockingPoolTask(); google_apis::test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error); EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir2/file11"),
drive_file_path);
// Rename to file7 to force a duplicate name. // Rename to file7 to force a duplicate name.
resource_metadata_->RenameEntryOnUIThread( resource_metadata_->RenameEntryOnUIThread(
......
...@@ -245,7 +245,6 @@ void SyncClient::OnGetResourceEntryById( ...@@ -245,7 +245,6 @@ void SyncClient::OnGetResourceEntryById(
const std::string& resource_id, const std::string& resource_id,
const FileCacheEntry& cache_entry, const FileCacheEntry& cache_entry,
FileError error, FileError error,
const base::FilePath& /* drive_file_path */,
scoped_ptr<ResourceEntry> entry) { scoped_ptr<ResourceEntry> entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
......
...@@ -110,7 +110,6 @@ class SyncClient : public FileSystemObserver, public FileCacheObserver { ...@@ -110,7 +110,6 @@ class SyncClient : public FileSystemObserver, public FileCacheObserver {
void OnGetResourceEntryById(const std::string& resource_id, void OnGetResourceEntryById(const std::string& resource_id,
const FileCacheEntry& cache_entry, const FileCacheEntry& cache_entry,
FileError error, FileError error,
const base::FilePath& file_path,
scoped_ptr<ResourceEntry> entry); scoped_ptr<ResourceEntry> entry);
// Called when a cache entry is obtained. // Called when a cache entry is obtained.
......
...@@ -41,11 +41,11 @@ ACTION_P(MockUpdateFileByResourceId, error) { ...@@ -41,11 +41,11 @@ ACTION_P(MockUpdateFileByResourceId, error) {
arg2.Run(error); arg2.Run(error);
} }
// Action used to set mock expectations for GetFileInfoByResourceId(). // Action used to set mock expectations for GetResourceEntryById().
ACTION_P2(MockUpdateFileByResourceId, error, md5) { ACTION_P2(MockGetResourceEntryById, error, md5) {
scoped_ptr<ResourceEntry> entry(new ResourceEntry); scoped_ptr<ResourceEntry> entry(new ResourceEntry);
entry->mutable_file_specific_info()->set_file_md5(md5); entry->mutable_file_specific_info()->set_file_md5(md5);
arg1.Run(error, base::FilePath(), entry.Pass()); arg1.Run(error, entry.Pass());
} }
} // namespace } // namespace
...@@ -161,8 +161,7 @@ class SyncClientTest : public testing::Test { ...@@ -161,8 +161,7 @@ class SyncClientTest : public testing::Test {
// Sets the expectation for MockFileSystem::GetFileByResourceId(), // Sets the expectation for MockFileSystem::GetFileByResourceId(),
// that simulates successful retrieval of a file for the given resource ID. // that simulates successful retrieval of a file for the given resource ID.
void SetExpectationForGetFileByResourceId(const std::string& resource_id) { void SetExpectationForGetFileByResourceId(const std::string& resource_id) {
EXPECT_CALL(*mock_file_system_, EXPECT_CALL(*mock_file_system_, GetFileByResourceId(resource_id, _, _, _))
GetFileByResourceId(resource_id, _, _, _))
.WillOnce( .WillOnce(
MockGetFileByResourceId( MockGetFileByResourceId(
FILE_ERROR_OK, FILE_ERROR_OK,
...@@ -171,27 +170,21 @@ class SyncClientTest : public testing::Test { ...@@ -171,27 +170,21 @@ class SyncClientTest : public testing::Test {
// Sets the expectation for MockFileSystem::UpdateFileByResourceId(), // Sets the expectation for MockFileSystem::UpdateFileByResourceId(),
// that simulates successful uploading of a file for the given resource ID. // that simulates successful uploading of a file for the given resource ID.
void SetExpectationForUpdateFileByResourceId( void SetExpectationForUpdateFileByResourceId(const std::string& resource_id) {
const std::string& resource_id) { EXPECT_CALL(*mock_file_system_, UpdateFileByResourceId(resource_id, _, _))
EXPECT_CALL(*mock_file_system_,
UpdateFileByResourceId(resource_id, _, _))
.WillOnce(MockUpdateFileByResourceId(FILE_ERROR_OK)); .WillOnce(MockUpdateFileByResourceId(FILE_ERROR_OK));
} }
// Sets the expectation for MockFileSystem::GetFileInfoByResourceId(), // Sets the expectation for MockFileSystem::GetResourceEntryById(),
// that simulates successful retrieval of file info for the given resource // that simulates successful retrieval of file info for the given resource
// ID. // ID.
// //
// This is used for testing StartCheckingExistingPinnedFiles(), hence we // This is used for testing StartCheckingExistingPinnedFiles(), hence we
// are only interested in the MD5 value in ResourceEntry. // are only interested in the MD5 value in ResourceEntry.
void SetExpectationForGetFileInfoByResourceId( void SetExpectationForGetFileInfoByResourceId(const std::string& resource_id,
const std::string& resource_id, const std::string& new_md5) {
const std::string& new_md5) { EXPECT_CALL(*mock_file_system_, GetResourceEntryById(resource_id, _))
EXPECT_CALL(*mock_file_system_, .WillOnce(MockGetResourceEntryById(FILE_ERROR_OK, new_md5));
GetResourceEntryById(resource_id, _))
.WillOnce(MockUpdateFileByResourceId(
FILE_ERROR_OK,
new_md5));
} }
// Returns the resource IDs in the queue to be fetched. // Returns the resource IDs in the queue to be fetched.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment