Commit aa172edf authored by satorux@chromium.org's avatar satorux@chromium.org

gdata: Change callback type of GDataDirectoryService::GetEntryInfoByResourceId()

This function should take  GetEntryInfoWithFilePathCallback instead of
GetEntryInfoCallback so that the callers can get the drive file path.
The new signature matches GDataFileSystem::GetEntryInfoByResourceId()

Along the way, add CopyResultsFromGetEntryInfoWithFilePathCallback() to
gdata_test_util.h.

BUG=143517
TEST=out/Release/unit_tests --gtest_filter='GDataDirectoryServiceTest.*'

Review URL: https://chromiumcodereview.appspot.com/10823427

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152442 0039d316-1c4b-4281-b951-d872f2087c98
parent f92543ad
......@@ -331,25 +331,30 @@ void GDataDirectoryService::GetEntryByResourceIdAsync(
void GDataDirectoryService::GetEntryInfoByResourceId(
const std::string& resource_id,
const GetEntryInfoCallback& callback) {
const GetEntryInfoWithFilePathCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
scoped_ptr<GDataEntryProto> entry_proto;
GDataFileError error = GDATA_FILE_ERROR_FAILED;
FilePath drive_file_path;
GDataEntry* entry = GetEntryByResourceId(resource_id);
if (entry) {
entry_proto.reset(new GDataEntryProto);
entry->ToProtoFull(entry_proto.get());
error = GDATA_FILE_OK;
drive_file_path = entry->GetFilePath();
} else {
error = GDATA_FILE_ERROR_NOT_FOUND;
}
base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
base::Bind(callback, error, base::Passed(&entry_proto)));
base::Bind(callback,
error,
drive_file_path,
base::Passed(&entry_proto)));
}
void GDataDirectoryService::GetEntryInfoByPath(
......
......@@ -89,6 +89,17 @@ typedef base::Callback<void(GDataFileError error,
scoped_ptr<GDataEntryProtoVector> entries)>
ReadDirectoryCallback;
// Used to get entry info from the file system, with the Drive file path.
// If |error| is not GDATA_FILE_OK, |entry_proto| is set to NULL.
//
// |drive_file_path| parameter is provided as GDataEntryProto does not contain
// the Drive file path (i.e. only contains the base name without parent
// directory names).
typedef base::Callback<void(GDataFileError error,
const FilePath& drive_file_path,
scoped_ptr<GDataEntryProto> entry_proto)>
GetEntryInfoWithFilePathCallback;
// This is a part of EntryInfoPairResult.
struct EntryInfoResult {
EntryInfoResult();
......@@ -202,8 +213,9 @@ class GDataDirectoryService {
//
// Must be called from UI thread. |callback| is run on UI thread.
// |callback| must not be null.
void GetEntryInfoByResourceId(const std::string& resource_id,
const GetEntryInfoCallback& callback);
void GetEntryInfoByResourceId(
const std::string& resource_id,
const GetEntryInfoWithFilePathCallback& callback);
// Finds an entry (a file or a directory) by |file_path|.
//
......
......@@ -324,13 +324,15 @@ TEST(GDataDirectoryServiceTest, GetEntryInfoByResourceId) {
// Confirm that an existing file is found.
GDataFileError error = GDATA_FILE_ERROR_FAILED;
FilePath drive_file_path;
scoped_ptr<GDataEntryProto> entry_proto;
directory_service.GetEntryInfoByResourceId(
"file_resource_id:file4",
base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback,
&error, &entry_proto));
base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback,
&error, &drive_file_path, &entry_proto));
test_util::RunBlockingPoolTask();
EXPECT_EQ(GDATA_FILE_OK, error);
EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file4"), drive_file_path);
ASSERT_TRUE(entry_proto.get());
EXPECT_EQ("file4", entry_proto->base_name());
......@@ -339,8 +341,8 @@ TEST(GDataDirectoryServiceTest, GetEntryInfoByResourceId) {
entry_proto.reset();
directory_service.GetEntryInfoByResourceId(
"file:non_existing",
base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback,
&error, &entry_proto));
base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback,
&error, &drive_file_path, &entry_proto));
test_util::RunBlockingPoolTask();
EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, error);
EXPECT_FALSE(entry_proto.get());
......
......@@ -40,17 +40,6 @@ typedef base::Callback<void(GDataFileError error,
const std::string& mime_type,
GDataFileType file_type)> GetFileCallback;
// Used to get entry info from the file system, with the gdata file path.
// If |error| is not GDATA_FILE_OK, |file_info| is set to NULL.
//
// |gdata_file_path| parameter is provided as GDataEntryProto does not contain
// the gdata file path (i.e. only contains the base name without parent
// directory names).
typedef base::Callback<void(GDataFileError error,
const FilePath& gdata_file_path,
scoped_ptr<GDataEntryProto> file_proto)>
GetEntryInfoWithFilePathCallback;
// Used to read a directory from the file system.
// Similar to ReadDirectoryCallback but this one provides
// |hide_hosted_documents|
......
......@@ -105,6 +105,22 @@ void CopyResultsFromReadDirectoryCallback(
*out_entries = entries.Pass();
}
void CopyResultsFromGetEntryInfoWithFilePathCallback(
GDataFileError* out_error,
FilePath* out_drive_file_path,
scoped_ptr<GDataEntryProto>* out_entry_proto,
GDataFileError error,
const FilePath& drive_file_path,
scoped_ptr<GDataEntryProto> entry_proto) {
DCHECK(out_error);
DCHECK(out_drive_file_path);
DCHECK(out_entry_proto);
*out_error = error;
*out_drive_file_path = drive_file_path;
*out_entry_proto = entry_proto.Pass();
}
void CopyResultsFromGetEntryInfoPairCallback(
scoped_ptr<EntryInfoPairResult>* out_result,
scoped_ptr<EntryInfoPairResult> result) {
......
......@@ -74,8 +74,20 @@ void CopyResultsFromReadDirectoryCallback(
GDataFileError error,
scoped_ptr<GDataEntryProtoVector> entries);
// Copies |result| |out_result|. Used to run asynchronous functions that take
// GetEntryInfoPairCallback from tests.
// Copies |error|, |drive_file_path|, and |entry_proto| to |out_error|,
// |out_drive_file_path|, and |out_entry_proto| respectively. Used to run
// asynchronous functions that take GetEntryInfoWithFilePathCallback from
// tests.
void CopyResultsFromGetEntryInfoWithFilePathCallback(
GDataFileError* out_error,
FilePath* out_drive_file_path,
scoped_ptr<GDataEntryProto>* out_entry_proto,
GDataFileError error,
const FilePath& drive_file_path,
scoped_ptr<GDataEntryProto> entry_proto);
// Copies |result| to |out_result|. Used to run asynchronous functions
// that take GetEntryInfoPairCallback from tests.
void CopyResultsFromGetEntryInfoPairCallback(
scoped_ptr<EntryInfoPairResult>* out_result,
scoped_ptr<EntryInfoPairResult> result);
......
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