diff options
author | hidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-21 05:31:01 +0000 |
---|---|---|
committer | hidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-21 05:31:01 +0000 |
commit | 9f202d29c43c96f88a122fcea14f56cf71e0c670 (patch) | |
tree | e5b1e0e659f8fa5ec13aa8452f6be203c0681ed1 /chrome | |
parent | 51f27b3c93ca7c281a43427ed57ddd1e609e94fc (diff) | |
download | chromium_src-9f202d29c43c96f88a122fcea14f56cf71e0c670.zip chromium_src-9f202d29c43c96f88a122fcea14f56cf71e0c670.tar.gz chromium_src-9f202d29c43c96f88a122fcea14f56cf71e0c670.tar.bz2 |
Add GetRootResourceId method to DriveServiceInterface.
The resource id for WAPI is "folder:root" but one for Drive API is "root".
To fill the gap, this CL adds the new method GetRootResourceId, so that clinets
don't need to use hard-coded parameters.
This is preparation to replace content URL with resource id for directory
operations.
BUG=148627, 148628, 148629
TEST=Ran unit_tests.
Review URL: https://chromiumcodereview.appspot.com/11968038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177893 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
15 files changed, 58 insertions, 26 deletions
diff --git a/chrome/browser/chromeos/drive/drive_file_system.cc b/chrome/browser/chromeos/drive/drive_file_system.cc index a7953da..871ab66 100644 --- a/chrome/browser/chromeos/drive/drive_file_system.cc +++ b/chrome/browser/chromeos/drive/drive_file_system.cc @@ -345,7 +345,8 @@ void DriveFileSystem::Initialize() { } void DriveFileSystem::ResetResourceMetadata() { - resource_metadata_.reset(new DriveResourceMetadata); + resource_metadata_.reset( + new DriveResourceMetadata(drive_service_->GetRootResourceId())); feed_loader_.reset(new DriveFeedLoader(resource_metadata_.get(), scheduler_.get(), webapps_registry_, diff --git a/chrome/browser/chromeos/drive/drive_file_system_unittest.cc b/chrome/browser/chromeos/drive/drive_file_system_unittest.cc index fba4657..d71499d 100644 --- a/chrome/browser/chromeos/drive/drive_file_system_unittest.cc +++ b/chrome/browser/chromeos/drive/drive_file_system_unittest.cc @@ -623,7 +623,7 @@ class DriveFileSystemTest : public testing::Test { DriveEntryProto* dir_base = root_dir->mutable_drive_entry(); PlatformFileInfoProto* platform_info = dir_base->mutable_file_info(); dir_base->set_title("drive"); - dir_base->set_resource_id(kWAPIRootDirectoryResourceId); + dir_base->set_resource_id(fake_drive_service_->GetRootResourceId()); dir_base->set_upload_url("http://resumable-create-media/1"); platform_info->set_is_directory(true); @@ -789,7 +789,7 @@ TEST_F(DriveFileSystemTest, SearchRootDirectory) { scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync( FilePath(FILE_PATH_LITERAL(kFilePath))); ASSERT_TRUE(entry.get()); - EXPECT_EQ(kWAPIRootDirectoryResourceId, entry->resource_id()); + EXPECT_EQ(fake_drive_service_->GetRootResourceId(), entry->resource_id()); } TEST_F(DriveFileSystemTest, SearchExistingFile) { diff --git a/chrome/browser/chromeos/drive/drive_resource_metadata.cc b/chrome/browser/chromeos/drive/drive_resource_metadata.cc index 2fbc048..e0d929a 100644 --- a/chrome/browser/chromeos/drive/drive_resource_metadata.cc +++ b/chrome/browser/chromeos/drive/drive_resource_metadata.cc @@ -180,14 +180,15 @@ void ResourceMetadataDB::Clear() { // DriveResourceMetadata class implementation. -DriveResourceMetadata::DriveResourceMetadata() +DriveResourceMetadata::DriveResourceMetadata( + const std::string& root_resource_id) : blocking_task_runner_(NULL), serialized_size_(0), largest_changestamp_(0), loaded_(false), ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { root_ = CreateDriveDirectory().Pass(); - root_->set_resource_id(kWAPIRootDirectoryResourceId); + root_->set_resource_id(root_resource_id); root_->set_title(kDriveRootDirectory); root_->SetBaseNameFromTitle(); @@ -859,7 +860,6 @@ bool DriveResourceMetadata::ParseFromString( } root_->FromProto(proto.drive_directory()); - DCHECK_EQ(kWAPIRootDirectoryResourceId, root_->resource_id()); loaded_ = true; largest_changestamp_ = proto.largest_changestamp(); diff --git a/chrome/browser/chromeos/drive/drive_resource_metadata.h b/chrome/browser/chromeos/drive/drive_resource_metadata.h index a6227c8..d7d8bf0 100644 --- a/chrome/browser/chromeos/drive/drive_resource_metadata.h +++ b/chrome/browser/chromeos/drive/drive_resource_metadata.h @@ -49,12 +49,6 @@ enum DriveFileType { // name is used in URLs for the file manager, hence user-visible. const FilePath::CharType kDriveRootDirectory[] = FILE_PATH_LITERAL("drive"); -// The resource ID for the root directory for WAPI is defined in the spec: -// https://developers.google.com/google-apps/documents-list/ -// Note that this special ID only applies to WAPI. Drive uses a non-constant -// unique ID given in About resource. -const char kWAPIRootDirectoryResourceId[] = "folder:root"; - // This should be incremented when incompatibility change is made in // drive.proto. const int32 kProtoVersion = 2; @@ -215,7 +209,8 @@ class DriveResourceMetadata : public DriveResourceMetadataInterface { // Map of resource id strings to DriveEntry*. typedef std::map<std::string, DriveEntry*> ResourceMap; - DriveResourceMetadata(); + // |root_resource_id| is the resource id for the root directory. + explicit DriveResourceMetadata(const std::string& root_resource_id); virtual ~DriveResourceMetadata(); // Last time when we dumped serialized file system to disk. diff --git a/chrome/browser/chromeos/drive/drive_resource_metadata_unittest.cc b/chrome/browser/chromeos/drive/drive_resource_metadata_unittest.cc index 5ccce25..785fe57 100644 --- a/chrome/browser/chromeos/drive/drive_resource_metadata_unittest.cc +++ b/chrome/browser/chromeos/drive/drive_resource_metadata_unittest.cc @@ -28,6 +28,8 @@ namespace { const char kResumableEditMediaUrl[] = "http://resumable-edit-media/"; const char kResumableCreateMediaUrl[] = "http://resumable-create-media/"; +const char kTestRootResourceId[] = "test_root"; + // Callback for DriveResourceMetadata::InitFromDB. void CopyResultsFromInitFromDBCallback(DriveFileError* expected_error, DriveFileError actual_error) { @@ -85,16 +87,17 @@ class DriveResourceMetadataTest : public testing::Test { }; DriveResourceMetadataTest::DriveResourceMetadataTest() - : ui_thread_(content::BrowserThread::UI, &message_loop_) { + : resource_metadata_(kTestRootResourceId), + ui_thread_(content::BrowserThread::UI, &message_loop_) { Init(); } void DriveResourceMetadataTest::Init() { int sequence_id = 1; ASSERT_TRUE(AddDriveEntryProto( - sequence_id++, true, kWAPIRootDirectoryResourceId)); + sequence_id++, true, kTestRootResourceId)); ASSERT_TRUE(AddDriveEntryProto( - sequence_id++, true, kWAPIRootDirectoryResourceId)); + sequence_id++, true, kTestRootResourceId)); ASSERT_TRUE(AddDriveEntryProto(sequence_id++, true, "resource_id:dir1")); ASSERT_TRUE(AddDriveEntryProto(sequence_id++, false, "resource_id:dir1")); @@ -157,11 +160,11 @@ TEST_F(DriveResourceMetadataTest, VersionCheck) { DriveEntryProto* mutable_entry = proto.mutable_drive_directory()->mutable_drive_entry(); mutable_entry->mutable_file_info()->set_is_directory(true); - mutable_entry->set_resource_id(kWAPIRootDirectoryResourceId); + mutable_entry->set_resource_id(kTestRootResourceId); mutable_entry->set_upload_url(kResumableCreateMediaUrl); mutable_entry->set_title("drive"); - DriveResourceMetadata resource_metadata; + DriveResourceMetadata resource_metadata(kTestRootResourceId); std::string serialized_proto; ASSERT_TRUE(proto.SerializeToString(&serialized_proto)); @@ -188,7 +191,7 @@ TEST_F(DriveResourceMetadataTest, VersionCheck) { } TEST_F(DriveResourceMetadataTest, LargestChangestamp) { - DriveResourceMetadata resource_metadata; + DriveResourceMetadata resource_metadata(kTestRootResourceId); int64 in_changestamp = 123456; DriveFileError error = DRIVE_FILE_ERROR_FAILED; @@ -208,7 +211,7 @@ TEST_F(DriveResourceMetadataTest, LargestChangestamp) { } TEST_F(DriveResourceMetadataTest, GetEntryByResourceId_RootDirectory) { - DriveResourceMetadata resource_metadata; + DriveResourceMetadata resource_metadata(kTestRootResourceId); DriveFileError error = DRIVE_FILE_ERROR_FAILED; FilePath drive_file_path; @@ -216,7 +219,7 @@ TEST_F(DriveResourceMetadataTest, GetEntryByResourceId_RootDirectory) { // Look up the root directory by its resource ID. resource_metadata.GetEntryInfoByResourceId( - kWAPIRootDirectoryResourceId, + kTestRootResourceId, base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, &error, &drive_file_path, &entry_proto)); google_apis::test_util::RunBlockingPoolTask(); @@ -420,7 +423,7 @@ TEST_F(DriveResourceMetadataTest, DBTest) { ASSERT_EQ(DRIVE_FILE_ERROR_IN_USE, db_error); // InitFromDB should succeed. - DriveResourceMetadata test_resource_metadata; + DriveResourceMetadata test_resource_metadata(kTestRootResourceId); test_resource_metadata.InitFromDB( db_path, blocking_task_runner, @@ -515,7 +518,7 @@ TEST_F(DriveResourceMetadataTest, RemoveEntryFromParent) { // Try removing root. This should fail. resource_metadata_.RemoveEntryFromParent( - kWAPIRootDirectoryResourceId, + kTestRootResourceId, base::Bind(&test_util::CopyResultsFromFileMoveCallback, &error, &drive_file_path)); google_apis::test_util::RunBlockingPoolTask(); @@ -777,7 +780,7 @@ TEST_F(DriveResourceMetadataTest, RefreshEntry_Root) { ASSERT_TRUE(entry_proto.get()); EXPECT_EQ("drive", entry_proto->base_name()); ASSERT_TRUE(entry_proto->file_info().is_directory()); - EXPECT_EQ(kWAPIRootDirectoryResourceId, entry_proto->resource_id()); + EXPECT_EQ(kTestRootResourceId, entry_proto->resource_id()); EXPECT_TRUE(entry_proto->upload_url().empty()); // Set upload url and call RefreshEntry on root. @@ -794,7 +797,7 @@ TEST_F(DriveResourceMetadataTest, RefreshEntry_Root) { ASSERT_TRUE(entry_proto.get()); EXPECT_EQ("drive", entry_proto->base_name()); EXPECT_TRUE(entry_proto->file_info().is_directory()); - EXPECT_EQ(kWAPIRootDirectoryResourceId, entry_proto->resource_id()); + EXPECT_EQ(kTestRootResourceId, entry_proto->resource_id()); EXPECT_EQ("http://root.upload.url/", entry_proto->upload_url()); // Make sure the children have moved over. Test file9. @@ -952,7 +955,7 @@ TEST_F(DriveResourceMetadataTest, RemoveAll) { ASSERT_TRUE(entry_proto.get()); EXPECT_EQ("drive", entry_proto->base_name()); ASSERT_TRUE(entry_proto->file_info().is_directory()); - EXPECT_EQ(kWAPIRootDirectoryResourceId, entry_proto->resource_id()); + EXPECT_EQ(kTestRootResourceId, entry_proto->resource_id()); // root should have no children. resource_metadata_.ReadDirectoryByPath( diff --git a/chrome/browser/google_apis/drive_api_service.cc b/chrome/browser/google_apis/drive_api_service.cc index 5a7f9ec..3521ebd 100644 --- a/chrome/browser/google_apis/drive_api_service.cc +++ b/chrome/browser/google_apis/drive_api_service.cc @@ -165,6 +165,10 @@ void ParseAppListAndRun(const google_apis::GetAppListCallback& callback, callback.Run(error, app_list.Pass()); } +// The resource ID for the root directory for Drive API is defined in the spec: +// https://developers.google.com/drive/folder +const char kDriveApiRootDirectoryResourceId[] = "root"; + } // namespace DriveAPIService::DriveAPIService( @@ -233,6 +237,10 @@ OperationProgressStatusList DriveAPIService::GetProgressStatusList() const { return operation_registry()->GetProgressStatusList(); } +std::string DriveAPIService::GetRootResourceId() const { + return kDriveApiRootDirectoryResourceId; +} + void DriveAPIService::GetResourceList( const GURL& url, int64 start_changestamp, diff --git a/chrome/browser/google_apis/drive_api_service.h b/chrome/browser/google_apis/drive_api_service.h index 187a1b4..54d8b30 100644 --- a/chrome/browser/google_apis/drive_api_service.h +++ b/chrome/browser/google_apis/drive_api_service.h @@ -55,6 +55,7 @@ class DriveAPIService : public DriveServiceInterface, virtual OperationProgressStatusList GetProgressStatusList() const OVERRIDE; virtual bool HasAccessToken() const OVERRIDE; virtual bool HasRefreshToken() const OVERRIDE; + virtual std::string GetRootResourceId() const OVERRIDE; virtual void GetResourceList( const GURL& feed_url, int64 start_changestamp, diff --git a/chrome/browser/google_apis/drive_service_interface.h b/chrome/browser/google_apis/drive_service_interface.h index 0355de5e..842d19d 100644 --- a/chrome/browser/google_apis/drive_service_interface.h +++ b/chrome/browser/google_apis/drive_service_interface.h @@ -129,6 +129,9 @@ class DriveServiceInterface { // Document access: + // Returns the resource id for the root directory. + virtual std::string GetRootResourceId() const = 0; + // Fetches a feed from |feed_url|. If this URL is empty, the call will fetch // from the default URL. When |start_changestamp| is 0, the default behavior // is to fetch the resource list feed containing the list of all entries. If diff --git a/chrome/browser/google_apis/dummy_drive_service.cc b/chrome/browser/google_apis/dummy_drive_service.cc index 9277e32..aa104ac 100644 --- a/chrome/browser/google_apis/dummy_drive_service.cc +++ b/chrome/browser/google_apis/dummy_drive_service.cc @@ -32,6 +32,10 @@ bool DummyDriveService::HasAccessToken() const { return true; } bool DummyDriveService::HasRefreshToken() const { return true; } +std::string DummyDriveService::GetRootResourceId() const { + return "dummy_root"; +} + void DummyDriveService::GetResourceList( const GURL& feed_url, int64 start_changestamp, diff --git a/chrome/browser/google_apis/dummy_drive_service.h b/chrome/browser/google_apis/dummy_drive_service.h index 3b0d522..381629f 100644 --- a/chrome/browser/google_apis/dummy_drive_service.h +++ b/chrome/browser/google_apis/dummy_drive_service.h @@ -26,6 +26,7 @@ class DummyDriveService : public DriveServiceInterface { virtual OperationProgressStatusList GetProgressStatusList() const OVERRIDE; virtual bool HasAccessToken() const OVERRIDE; virtual bool HasRefreshToken() const OVERRIDE; + virtual std::string GetRootResourceId() const OVERRIDE; virtual void GetResourceList( const GURL& feed_url, int64 start_changestamp, diff --git a/chrome/browser/google_apis/fake_drive_service.cc b/chrome/browser/google_apis/fake_drive_service.cc index 8c7d086..06ee263 100644 --- a/chrome/browser/google_apis/fake_drive_service.cc +++ b/chrome/browser/google_apis/fake_drive_service.cc @@ -129,6 +129,11 @@ bool FakeDriveService::HasRefreshToken() const { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); return true; } + +std::string FakeDriveService::GetRootResourceId() const { + return "fake_root"; +} + void FakeDriveService::GetResourceList( const GURL& feed_url, int64 start_changestamp, diff --git a/chrome/browser/google_apis/fake_drive_service.h b/chrome/browser/google_apis/fake_drive_service.h index 3faf41c..51739eb 100644 --- a/chrome/browser/google_apis/fake_drive_service.h +++ b/chrome/browser/google_apis/fake_drive_service.h @@ -60,6 +60,7 @@ class FakeDriveService : public DriveServiceInterface { virtual void CancelAll() OVERRIDE; virtual bool CancelForFilePath(const FilePath& file_path) OVERRIDE; virtual OperationProgressStatusList GetProgressStatusList() const OVERRIDE; + virtual std::string GetRootResourceId() const OVERRIDE; virtual bool HasAccessToken() const OVERRIDE; virtual bool HasRefreshToken() const OVERRIDE; virtual void GetResourceList( diff --git a/chrome/browser/google_apis/gdata_wapi_service.cc b/chrome/browser/google_apis/gdata_wapi_service.cc index 2e4e056..0457fc7 100644 --- a/chrome/browser/google_apis/gdata_wapi_service.cc +++ b/chrome/browser/google_apis/gdata_wapi_service.cc @@ -185,6 +185,10 @@ const char kSpreadsheetsScope[] = "https://spreadsheets.google.com/feeds/"; const char kUserContentScope[] = "https://docs.googleusercontent.com/"; const char kDriveAppsScope[] = "https://www.googleapis.com/auth/drive.apps"; +// The resource ID for the root directory for WAPI is defined in the spec: +// https://developers.google.com/google-apps/documents-list/ +const char kWapiRootDirectoryResourceId[] = "folder:root"; + } // namespace GDataWapiService::GDataWapiService( @@ -258,6 +262,10 @@ OperationProgressStatusList GDataWapiService::GetProgressStatusList() const { return operation_registry()->GetProgressStatusList(); } +std::string GDataWapiService::GetRootResourceId() const { + return kWapiRootDirectoryResourceId; +} + void GDataWapiService::GetResourceList( const GURL& url, int64 start_changestamp, diff --git a/chrome/browser/google_apis/gdata_wapi_service.h b/chrome/browser/google_apis/gdata_wapi_service.h index f30ecd1..25611be 100644 --- a/chrome/browser/google_apis/gdata_wapi_service.h +++ b/chrome/browser/google_apis/gdata_wapi_service.h @@ -59,6 +59,7 @@ class GDataWapiService : public DriveServiceInterface, virtual OperationProgressStatusList GetProgressStatusList() const OVERRIDE; virtual bool HasAccessToken() const OVERRIDE; virtual bool HasRefreshToken() const OVERRIDE; + virtual std::string GetRootResourceId() const OVERRIDE; virtual void GetResourceList( const GURL& feed_url, int64 start_changestamp, diff --git a/chrome/browser/google_apis/mock_drive_service.h b/chrome/browser/google_apis/mock_drive_service.h index 1b9cd13..1f28c4f 100644 --- a/chrome/browser/google_apis/mock_drive_service.h +++ b/chrome/browser/google_apis/mock_drive_service.h @@ -33,6 +33,7 @@ class MockDriveService : public DriveServiceInterface { MOCK_METHOD1(CancelForFilePath, bool(const FilePath& file_path)); MOCK_CONST_METHOD0(GetProgressStatusList, OperationProgressStatusList()); + MOCK_CONST_METHOD0(GetRootResourceId, std::string()); MOCK_METHOD6(GetResourceList, void(const GURL& feed_url, int64 start_changestamp, |