Commit 97e92e51 authored by satorux@chromium.org's avatar satorux@chromium.org

gdata: Add GDataDirectoryService::GetEntryInfoByResourceId()

Similar to GDataDirectoryService::GetEntryByResourceIdAsync() but this
one returns a proto instead of GDataEntry*.  This function will be used to
replace use of GDataDirectoryService::GetEntryByResourceIdAsync() in
gdata_file_system.cc

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

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152397 0039d316-1c4b-4281-b951-d872f2087c98
parent 4d50036b
...@@ -326,6 +326,29 @@ void GDataDirectoryService::GetEntryByResourceIdAsync( ...@@ -326,6 +326,29 @@ void GDataDirectoryService::GetEntryByResourceIdAsync(
callback.Run(entry); callback.Run(entry);
} }
void GDataDirectoryService::GetEntryInfoByResourceId(
const std::string& resource_id,
const GetEntryInfoCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
scoped_ptr<GDataEntryProto> entry_proto;
GDataFileError error = GDATA_FILE_ERROR_FAILED;
GDataEntry* entry = GetEntryByResourceId(resource_id);
if (entry) {
entry_proto.reset(new GDataEntryProto);
entry->ToProtoFull(entry_proto.get());
error = GDATA_FILE_OK;
} else {
error = GDATA_FILE_ERROR_NOT_FOUND;
}
base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
base::Bind(callback, error, base::Passed(&entry_proto)));
}
void GDataDirectoryService::GetEntryInfoByPath( void GDataDirectoryService::GetEntryInfoByPath(
const FilePath& path, const FilePath& path,
const GetEntryInfoCallback& callback) { const GetEntryInfoCallback& callback) {
......
...@@ -188,23 +188,34 @@ class GDataDirectoryService { ...@@ -188,23 +188,34 @@ class GDataDirectoryService {
GDataEntry* FindEntryByPathSync(const FilePath& file_path); GDataEntry* FindEntryByPathSync(const FilePath& file_path);
// Returns the GDataEntry* with the corresponding |resource_id|. // Returns the GDataEntry* with the corresponding |resource_id|.
// TODO(achuith): Get rid of this in favor of async version crbug.com/13957. // TODO(satorux): Remove this in favor of GetEntryInfoByResourceId()
// but can be difficult. See crbug.com/137374
GDataEntry* GetEntryByResourceId(const std::string& resource_id); GDataEntry* GetEntryByResourceId(const std::string& resource_id);
// Returns the GDataEntry* in the callback with the corresponding // Returns the GDataEntry* in the callback with the corresponding
// |resource_id|. TODO(achuith): Rename this to GetEntryByResourceId. // |resource_id|. TODO(satorux): Remove this in favor of
// GetEntryInfoByResourceId(). crbug.com/137512
void GetEntryByResourceIdAsync(const std::string& resource_id, void GetEntryByResourceIdAsync(const std::string& resource_id,
const GetEntryByResourceIdCallback& callback); const GetEntryByResourceIdCallback& callback);
// Finds an entry (a file or a directory) by |resource_id|.
//
// 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);
// Finds an entry (a file or a directory) by |file_path|. // Finds an entry (a file or a directory) by |file_path|.
// //
// Must be called from UI thread. |callback| is run on UI thread. // Must be called from UI thread. |callback| is run on UI thread.
// |callback| must not be null.
void GetEntryInfoByPath(const FilePath& file_path, void GetEntryInfoByPath(const FilePath& file_path,
const GetEntryInfoCallback& callback); const GetEntryInfoCallback& callback);
// Finds and reads a directory by |file_path|. // Finds and reads a directory by |file_path|.
// //
// Must be called from UI thread. |callback| is run on UI thread. // Must be called from UI thread. |callback| is run on UI thread.
// |callback| must not be null.
void ReadDirectoryByPath(const FilePath& file_path, void ReadDirectoryByPath(const FilePath& file_path,
const ReadDirectoryCallback& callback); const ReadDirectoryCallback& callback);
...@@ -214,6 +225,7 @@ class GDataDirectoryService { ...@@ -214,6 +225,7 @@ class GDataDirectoryService {
// entry of |second_path|. // entry of |second_path|.
// //
// Must be called from UI thread. |callback| is run on UI thread. // Must be called from UI thread. |callback| is run on UI thread.
// |callback| must not be null.
void GetEntryInfoPairByPaths( void GetEntryInfoPairByPaths(
const FilePath& first_path, const FilePath& first_path,
const FilePath& second_path, const FilePath& second_path,
......
...@@ -315,6 +315,37 @@ TEST(GDataDirectoryServiceTest, GetEntryByResourceId_RootDirectory) { ...@@ -315,6 +315,37 @@ TEST(GDataDirectoryServiceTest, GetEntryByResourceId_RootDirectory) {
EXPECT_EQ(kGDataRootDirectoryResourceId, entry->resource_id()); EXPECT_EQ(kGDataRootDirectoryResourceId, entry->resource_id());
} }
TEST(GDataDirectoryServiceTest, GetEntryInfoByResourceId) {
MessageLoopForUI message_loop;
content::TestBrowserThread ui_thread(content::BrowserThread::UI,
&message_loop);
GDataDirectoryService directory_service;
InitDirectoryService(&directory_service);
// Confirm that an existing file is found.
GDataFileError error = GDATA_FILE_ERROR_FAILED;
scoped_ptr<GDataEntryProto> entry_proto;
directory_service.GetEntryInfoByResourceId(
"file_resource_id:file4",
base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback,
&error, &entry_proto));
test_util::RunBlockingPoolTask();
EXPECT_EQ(GDATA_FILE_OK, error);
ASSERT_TRUE(entry_proto.get());
EXPECT_EQ("file4", entry_proto->base_name());
// Confirm that a non existing file is not found.
error = GDATA_FILE_ERROR_FAILED;
entry_proto.reset();
directory_service.GetEntryInfoByResourceId(
"file:non_existing",
base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback,
&error, &entry_proto));
test_util::RunBlockingPoolTask();
EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, error);
EXPECT_FALSE(entry_proto.get());
}
TEST(GDataDirectoryServiceTest, GetEntryInfoByPath) { TEST(GDataDirectoryServiceTest, GetEntryInfoByPath) {
MessageLoopForUI message_loop; MessageLoopForUI message_loop;
content::TestBrowserThread ui_thread(content::BrowserThread::UI, content::TestBrowserThread ui_thread(content::BrowserThread::UI,
......
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