diff options
Diffstat (limited to 'chrome/browser/google_apis')
19 files changed, 200 insertions, 142 deletions
diff --git a/chrome/browser/google_apis/base_operations.cc b/chrome/browser/google_apis/base_operations.cc index 067a663..37e7581 100644 --- a/chrome/browser/google_apis/base_operations.cc +++ b/chrome/browser/google_apis/base_operations.cc @@ -119,7 +119,13 @@ void UrlFetchOperationBase::Start(const std::string& access_token, re_authenticate_callback_ = callback; GURL url = GetURL(); - DCHECK(!url.is_empty()); + if (url.is_empty()) { + // Error is found on generating the url. Send the error message to the + // callback, and then return immediately without trying to connect + // to the server. + RunCallbackOnPrematureFailure(GDATA_OTHER_ERROR); + return; + } DVLOG(1) << "URL: " << url.spec(); url_fetcher_.reset( diff --git a/chrome/browser/google_apis/drive_api_service.cc b/chrome/browser/google_apis/drive_api_service.cc index ce2d1b0..de23d5c 100644 --- a/chrome/browser/google_apis/drive_api_service.cc +++ b/chrome/browser/google_apis/drive_api_service.cc @@ -371,7 +371,7 @@ void DriveAPIService::DeleteResource( } void DriveAPIService::AddNewDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& directory_name, const GetResourceEntryCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -404,7 +404,7 @@ void DriveAPIService::RenameResource( } void DriveAPIService::AddResourceToDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const GURL& edit_url, const EntryActionCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -415,7 +415,7 @@ void DriveAPIService::AddResourceToDirectory( } void DriveAPIService::RemoveResourceFromDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& resource_id, const EntryActionCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); diff --git a/chrome/browser/google_apis/drive_api_service.h b/chrome/browser/google_apis/drive_api_service.h index 14bb4ac..d23c4dc 100644 --- a/chrome/browser/google_apis/drive_api_service.h +++ b/chrome/browser/google_apis/drive_api_service.h @@ -94,15 +94,15 @@ class DriveAPIService : public DriveServiceInterface, const std::string& new_name, const EntryActionCallback& callback) OVERRIDE; virtual void AddResourceToDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const GURL& edit_url, const EntryActionCallback& callback) OVERRIDE; virtual void RemoveResourceFromDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& resource_id, const EntryActionCallback& callback) OVERRIDE; virtual void AddNewDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& directory_name, const GetResourceEntryCallback& callback) OVERRIDE; virtual void InitiateUpload( diff --git a/chrome/browser/google_apis/drive_service_interface.h b/chrome/browser/google_apis/drive_service_interface.h index 3493961..533c2cc 100644 --- a/chrome/browser/google_apis/drive_service_interface.h +++ b/chrome/browser/google_apis/drive_service_interface.h @@ -211,31 +211,31 @@ class DriveServiceInterface { const EntryActionCallback& callback) = 0; // Adds a resource (document, file, or collection) identified by its - // |edit_url| to a collection with a content link |parent_content_url|. + // |edit_url| to a collection represented by the |parent_resource_id|. // Upon completion, invokes |callback| with results on the calling thread. // |callback| must not be null. - virtual void AddResourceToDirectory(const GURL& parent_content_url, + virtual void AddResourceToDirectory(const std::string& parent_resource_id, const GURL& edit_url, const EntryActionCallback& callback) = 0; // Removes a resource (document, file, collection) identified by its - // |resource_id| from a collection with a content link - // |parent_content_url|. Upon completion, invokes |callback| with - // results on the calling thread. + // |resource_id| from a collection represented by the |parent_resource_id|. + // Upon completion, invokes |callback| with results on the calling thread. // |callback| must not be null. virtual void RemoveResourceFromDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& resource_id, const EntryActionCallback& callback) = 0; // Adds new collection with |directory_name| under parent directory - // identified with |parent_content_url|. If |parent_content_url| is empty, - // the new collection will be created in the root. Upon completion, - // invokes |callback| and passes newly created entry on the calling thread. + // identified with |parent_resource_id|. |parent_resource_id| can be the + // value returned by GetRootResourceId to represent the root directory. + // Upon completion, invokes |callback| and passes newly created entry on + // the calling thread. // This function cannot be named as "CreateDirectory" as it conflicts with // a macro on Windows. // |callback| must not be null. - virtual void AddNewDirectory(const GURL& parent_content_url, + virtual void AddNewDirectory(const std::string& parent_resource_id, const std::string& directory_name, const GetResourceEntryCallback& callback) = 0; diff --git a/chrome/browser/google_apis/dummy_drive_service.cc b/chrome/browser/google_apis/dummy_drive_service.cc index d51cd10..ab34a9b 100644 --- a/chrome/browser/google_apis/dummy_drive_service.cc +++ b/chrome/browser/google_apis/dummy_drive_service.cc @@ -80,17 +80,17 @@ void DummyDriveService::RenameResource(const GURL& edit_url, const EntryActionCallback& callback) {} void DummyDriveService::AddResourceToDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const GURL& edit_url, const EntryActionCallback& callback) {} void DummyDriveService::RemoveResourceFromDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& resource_id, const EntryActionCallback& callback) {} void DummyDriveService::AddNewDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& directory_name, const GetResourceEntryCallback& callback) {} diff --git a/chrome/browser/google_apis/dummy_drive_service.h b/chrome/browser/google_apis/dummy_drive_service.h index 8f19c8f..c8952db 100644 --- a/chrome/browser/google_apis/dummy_drive_service.h +++ b/chrome/browser/google_apis/dummy_drive_service.h @@ -62,15 +62,15 @@ class DummyDriveService : public DriveServiceInterface { const std::string& new_name, const EntryActionCallback& callback) OVERRIDE; virtual void AddResourceToDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const GURL& edit_url, const EntryActionCallback& callback) OVERRIDE; virtual void RemoveResourceFromDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& resource_id, const EntryActionCallback& callback) OVERRIDE; virtual void AddNewDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& directory_name, const GetResourceEntryCallback& callback) OVERRIDE; virtual void InitiateUpload(const InitiateUploadParams& params, diff --git a/chrome/browser/google_apis/fake_drive_service.cc b/chrome/browser/google_apis/fake_drive_service.cc index af4db0b..ba106f0 100644 --- a/chrome/browser/google_apis/fake_drive_service.cc +++ b/chrome/browser/google_apis/fake_drive_service.cc @@ -131,6 +131,10 @@ bool FakeDriveService::LoadAppListForDriveApi( return app_info_value_; } +GURL FakeDriveService::GetFakeLinkUrl(const std::string& resource_id) { + return GURL("https://fake_server/" + resource_id); +} + void FakeDriveService::Initialize(Profile* profile) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } @@ -583,7 +587,7 @@ void FakeDriveService::RenameResource( } void FakeDriveService::AddResourceToDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const GURL& edit_url, const EntryActionCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -606,7 +610,8 @@ void FakeDriveService::AddResourceToDirectory( if (links->GetDictionary(i, &link) && link->GetString("rel", &rel) && rel == "http://schemas.google.com/docs/2007#parent") { - link->SetString("href", parent_content_url.spec()); + link->SetString( + "href", GetFakeLinkUrl(parent_resource_id).spec()); parent_link_found = true; } } @@ -615,7 +620,8 @@ void FakeDriveService::AddResourceToDirectory( if (!parent_link_found) { base::DictionaryValue* link = new base::DictionaryValue; link->SetString("rel", "http://schemas.google.com/docs/2007#parent"); - link->SetString("href", parent_content_url.spec()); + link->SetString( + "href", GetFakeLinkUrl(parent_resource_id).spec()); links->Append(link); } @@ -631,7 +637,7 @@ void FakeDriveService::AddResourceToDirectory( } void FakeDriveService::RemoveResourceFromDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& resource_id, const EntryActionCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -647,6 +653,7 @@ void FakeDriveService::RemoveResourceFromDirectory( if (entry) { base::ListValue* links = NULL; if (entry->GetList("link", &links)) { + GURL parent_content_url = GetFakeLinkUrl(parent_resource_id); for (size_t i = 0; i < links->GetSize(); ++i) { base::DictionaryValue* link = NULL; std::string rel; @@ -665,7 +672,7 @@ void FakeDriveService::RemoveResourceFromDirectory( } // We are dealing with a no-"parent"-link file as in the root directory. - if (parent_content_url.is_empty()) { + if (parent_resource_id == GetRootResourceId()) { AddNewChangestamp(entry); MessageLoop::current()->PostTask( FROM_HERE, base::Bind(callback, HTTP_SUCCESS)); @@ -679,7 +686,7 @@ void FakeDriveService::RemoveResourceFromDirectory( } void FakeDriveService::AddNewDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& directory_name, const GetResourceEntryCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -695,10 +702,11 @@ void FakeDriveService::AddNewDirectory( return; } - // If the parent content URL is not empty, the parent should exist. - if (!parent_content_url.is_empty()) { + // If the parent content URL is not matched to the root resource id, + // the parent should exist. + if (parent_resource_id != GetRootResourceId()) { base::DictionaryValue* parent_entry = - FindEntryByContentUrl(parent_content_url); + FindEntryByResourceId(parent_resource_id); if (!parent_entry) { scoped_ptr<ResourceEntry> null; MessageLoop::current()->PostTask( @@ -731,9 +739,10 @@ void FakeDriveService::AddNewDirectory( // Add "link" which sets the parent URL and the edit URL. base::ListValue* links = new base::ListValue; - if (!parent_content_url.is_empty()) { + if (parent_resource_id != GetRootResourceId()) { base::DictionaryValue* parent_link = new base::DictionaryValue; - parent_link->SetString("href", parent_content_url.spec()); + parent_link->SetString( + "href", GetFakeLinkUrl(parent_resource_id).spec()); parent_link->SetString("rel", "http://schemas.google.com/docs/2007#parent"); links->Append(parent_link); diff --git a/chrome/browser/google_apis/fake_drive_service.h b/chrome/browser/google_apis/fake_drive_service.h index db803c7..f15e228 100644 --- a/chrome/browser/google_apis/fake_drive_service.h +++ b/chrome/browser/google_apis/fake_drive_service.h @@ -58,6 +58,9 @@ class FakeDriveService : public DriveServiceInterface { return account_metadata_load_count_; } + // Returns the (fake) URL for the link. + static GURL GetFakeLinkUrl(const std::string& resource_id); + // DriveServiceInterface Overrides virtual void Initialize(Profile* profile) OVERRIDE; virtual void AddObserver(DriveServiceObserver* observer) OVERRIDE; @@ -108,15 +111,15 @@ class FakeDriveService : public DriveServiceInterface { const std::string& new_name, const EntryActionCallback& callback) OVERRIDE; virtual void AddResourceToDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const GURL& edit_url, const EntryActionCallback& callback) OVERRIDE; virtual void RemoveResourceFromDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& resource_id, const EntryActionCallback& callback) OVERRIDE; virtual void AddNewDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& directory_name, const GetResourceEntryCallback& callback) OVERRIDE; virtual void InitiateUpload(const InitiateUploadParams& params, diff --git a/chrome/browser/google_apis/fake_drive_service_unittest.cc b/chrome/browser/google_apis/fake_drive_service_unittest.cc index 7df65ce..db48de4 100644 --- a/chrome/browser/google_apis/fake_drive_service_unittest.cc +++ b/chrome/browser/google_apis/fake_drive_service_unittest.cc @@ -42,14 +42,14 @@ class FakeDriveServiceTest : public testing::Test { return resource_entry; } - // Adds a new directory at |parent_content_url| (root if empty) with the - // given name. Returns true on success. - bool AddNewDirectory(const GURL& parent_content_url, + // Adds a new directory at |parent_resource_id| with the given name. + // Returns true on success. + bool AddNewDirectory(const std::string& parent_resource_id, const std::string& directory_name) { GDataErrorCode error = GDATA_OTHER_ERROR; scoped_ptr<ResourceEntry> resource_entry; fake_service_.AddNewDirectory( - parent_content_url, + parent_resource_id, directory_name, base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback, &error, @@ -318,7 +318,8 @@ TEST_F(FakeDriveServiceTest, GetResourceList_WithNewEntry) { "gdata/account_metadata.json")); // Add a new directory in the root directory. The new directory will have // the changestamp of 654322. - ASSERT_TRUE(AddNewDirectory(GURL(), "new directory")); + ASSERT_TRUE(AddNewDirectory( + fake_service_.GetRootResourceId(), "new directory")); // Get the resource list newer than 654321. GDataErrorCode error = GDATA_OTHER_ERROR; @@ -749,7 +750,7 @@ TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInRootDirectory) { const std::string kResourceId = "file:2_file_resource_id"; const GURL kEditUrl("https://file1_link_self/file:2_file_resource_id"); - const GURL kNewParentContentUrl("https://new_url"); + const std::string kNewParentResourceId = "folder:1_folder_resource_id"; scoped_ptr<ResourceEntry> resource_entry = FindEntry(kResourceId); ASSERT_TRUE(resource_entry); @@ -760,7 +761,7 @@ TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInRootDirectory) { GDataErrorCode error = GDATA_OTHER_ERROR; fake_service_.AddResourceToDirectory( - kNewParentContentUrl, + kNewParentResourceId, kEditUrl, base::Bind(&test_util::CopyResultsFromEntryActionCallback, &error)); @@ -773,7 +774,8 @@ TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInRootDirectory) { // The parent link should now exist as the parent directory is changed. parent_link = resource_entry->GetLinkByType(Link::LINK_PARENT); ASSERT_TRUE(parent_link); - EXPECT_EQ(kNewParentContentUrl, parent_link->href()); + EXPECT_EQ(FakeDriveService::GetFakeLinkUrl(kNewParentResourceId), + parent_link->href()); // Should be incremented as a file was moved. EXPECT_EQ(1, fake_service_.largest_changestamp()); } @@ -784,7 +786,7 @@ TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInNonRootDirectory) { const std::string kResourceId = "file:subdirectory_file_1_id"; const GURL kEditUrl( "https://dir1_file_link_self/file:subdirectory_file_1_id"); - const GURL kNewParentContentUrl("https://new_url"); + const std::string kNewParentResourceId = "folder:2_folder_resource_id"; scoped_ptr<ResourceEntry> resource_entry = FindEntry(kResourceId); ASSERT_TRUE(resource_entry); @@ -792,12 +794,12 @@ TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInNonRootDirectory) { const google_apis::Link* parent_link = resource_entry->GetLinkByType(Link::LINK_PARENT); ASSERT_TRUE(parent_link); - EXPECT_EQ("https://dir_1_self_link/folder:1_folder_resource_id", - parent_link->href().spec()); + EXPECT_EQ(FakeDriveService::GetFakeLinkUrl("folder:1_folder_resource_id"), + parent_link->href()); GDataErrorCode error = GDATA_OTHER_ERROR; fake_service_.AddResourceToDirectory( - kNewParentContentUrl, + kNewParentResourceId, kEditUrl, base::Bind(&test_util::CopyResultsFromEntryActionCallback, &error)); @@ -810,7 +812,8 @@ TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInNonRootDirectory) { // The parent link should now be changed. parent_link = resource_entry->GetLinkByType(Link::LINK_PARENT); ASSERT_TRUE(parent_link); - EXPECT_EQ(kNewParentContentUrl, parent_link->href()); + EXPECT_EQ(FakeDriveService::GetFakeLinkUrl(kNewParentResourceId), + parent_link->href()); // Should be incremented as a file was moved. EXPECT_EQ(1, fake_service_.largest_changestamp()); } @@ -819,11 +822,11 @@ TEST_F(FakeDriveServiceTest, AddResourceToDirectory_NonexistingFile) { ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json")); const GURL kEditUrl("https://file1_link_self/file:nonexisting_file"); - const GURL kNewParentContentUrl("https://new_url"); + const std::string kNewParentResourceId = "folder:1_folder_resource_id"; GDataErrorCode error = GDATA_OTHER_ERROR; fake_service_.AddResourceToDirectory( - kNewParentContentUrl, + kNewParentResourceId, kEditUrl, base::Bind(&test_util::CopyResultsFromEntryActionCallback, &error)); @@ -838,11 +841,11 @@ TEST_F(FakeDriveServiceTest, AddResourceToDirectory_Offline) { const std::string kResourceId = "file:2_file_resource_id"; const GURL kEditUrl("https://file1_link_self/file:2_file_resource_id"); - const GURL kNewParentContentUrl("https://new_url"); + const std::string kNewParentResourceId = "folder:1_folder_resource_id"; GDataErrorCode error = GDATA_OTHER_ERROR; fake_service_.AddResourceToDirectory( - kNewParentContentUrl, + kNewParentResourceId, kEditUrl, base::Bind(&test_util::CopyResultsFromEntryActionCallback, &error)); @@ -854,9 +857,8 @@ TEST_F(FakeDriveServiceTest, AddResourceToDirectory_Offline) { TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_ExistingFile) { ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json")); - const std::string kResourceId("file:subdirectory_file_1_id"); - const GURL kParentContentUrl( - "https://dir_1_self_link/folder:1_folder_resource_id"); + const std::string kResourceId = "file:subdirectory_file_1_id"; + const std::string kParentResourceId = "folder:1_folder_resource_id"; scoped_ptr<ResourceEntry> resource_entry = FindEntry(kResourceId); ASSERT_TRUE(resource_entry); @@ -867,7 +869,7 @@ TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_ExistingFile) { GDataErrorCode error = GDATA_OTHER_ERROR; fake_service_.RemoveResourceFromDirectory( - kParentContentUrl, + kParentResourceId, kResourceId, base::Bind(&test_util::CopyResultsFromEntryActionCallback, &error)); @@ -887,13 +889,12 @@ TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_ExistingFile) { TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_NonexistingFile) { ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json")); - const std::string kResourceId("file:nonexisting_file"); - const GURL kParentContentUrl( - "https://dir_1_self_link/folder:1_folder_resource_id"); + const std::string kResourceId = "file:nonexisting_file"; + const std::string kParentResourceId = "folder:1_folder_resource_id"; GDataErrorCode error = GDATA_OTHER_ERROR; fake_service_.RemoveResourceFromDirectory( - kParentContentUrl, + kParentResourceId, kResourceId, base::Bind(&test_util::CopyResultsFromEntryActionCallback, &error)); @@ -906,13 +907,12 @@ TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_Offline) { ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json")); fake_service_.set_offline(true); - const std::string kResourceId("file:subdirectory_file_1_id"); - const GURL kParentContentUrl( - "https://dir_1_self_link/folder:1_folder_resource_id"); + const std::string kResourceId = "file:subdirectory_file_1_id"; + const std::string kParentResourceId = "folder:1_folder_resource_id"; GDataErrorCode error = GDATA_OTHER_ERROR; fake_service_.RemoveResourceFromDirectory( - kParentContentUrl, + kParentResourceId, kResourceId, base::Bind(&test_util::CopyResultsFromEntryActionCallback, &error)); @@ -927,7 +927,7 @@ TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectory) { GDataErrorCode error = GDATA_OTHER_ERROR; scoped_ptr<ResourceEntry> resource_entry; fake_service_.AddNewDirectory( - GURL(), // Empty means add it to the root directory. + fake_service_.GetRootResourceId(), "new directory", base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback, &error, @@ -950,13 +950,12 @@ TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectory) { TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonRootDirectory) { ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json")); - const GURL kParentContentUrl( - "https://dir_1_self_link/folder:1_folder_resource_id"); + const std::string kParentResourceId = "folder:1_folder_resource_id"; GDataErrorCode error = GDATA_OTHER_ERROR; scoped_ptr<ResourceEntry> resource_entry; fake_service_.AddNewDirectory( - kParentContentUrl, + kParentResourceId, "new directory", base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback, &error, @@ -970,7 +969,8 @@ TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonRootDirectory) { const google_apis::Link* parent_link = resource_entry->GetLinkByType(Link::LINK_PARENT); ASSERT_TRUE(parent_link); - EXPECT_EQ(kParentContentUrl, parent_link->href()); + EXPECT_EQ(FakeDriveService::GetFakeLinkUrl(kParentResourceId), + parent_link->href()); // Should be incremented as a new directory was created. EXPECT_EQ(1, fake_service_.largest_changestamp()); } @@ -978,13 +978,12 @@ TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonRootDirectory) { TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonexistingDirectory) { ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json")); - const GURL kParentContentUrl( - "https://dir_1_self_link/folder:nonexisting_resource_id"); + const std::string kParentResourceId = "folder:nonexisting_resource_id"; GDataErrorCode error = GDATA_OTHER_ERROR; scoped_ptr<ResourceEntry> resource_entry; fake_service_.AddNewDirectory( - kParentContentUrl, + kParentResourceId, "new directory", base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback, &error, @@ -1002,7 +1001,7 @@ TEST_F(FakeDriveServiceTest, AddNewDirectory_Offline) { GDataErrorCode error = GDATA_OTHER_ERROR; scoped_ptr<ResourceEntry> resource_entry; fake_service_.AddNewDirectory( - GURL(), // Empty means add it to the root directory. + fake_service_.GetRootResourceId(), "new directory", base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback, &error, diff --git a/chrome/browser/google_apis/gdata_wapi_operations.cc b/chrome/browser/google_apis/gdata_wapi_operations.cc index 2c865f7..70d7639 100644 --- a/chrome/browser/google_apis/gdata_wapi_operations.cc +++ b/chrome/browser/google_apis/gdata_wapi_operations.cc @@ -278,11 +278,11 @@ CreateDirectoryOperation::CreateDirectoryOperation( net::URLRequestContextGetter* url_request_context_getter, const GDataWapiUrlGenerator& url_generator, const GetDataCallback& callback, - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& directory_name) : GetDataOperation(registry, url_request_context_getter, callback), url_generator_(url_generator), - parent_content_url_(parent_content_url), + parent_resource_id_(parent_resource_id), directory_name_(directory_name) { DCHECK(!callback.is_null()); } @@ -290,10 +290,7 @@ CreateDirectoryOperation::CreateDirectoryOperation( CreateDirectoryOperation::~CreateDirectoryOperation() {} GURL CreateDirectoryOperation::GetURL() const { - if (!parent_content_url_.is_empty()) - return GDataWapiUrlGenerator::AddStandardUrlParams(parent_content_url_); - - return url_generator_.GenerateResourceListRootUrl(); + return url_generator_.GenerateContentUrl(parent_resource_id_); } URLFetcher::RequestType @@ -477,11 +474,11 @@ AddResourceToDirectoryOperation::AddResourceToDirectoryOperation( net::URLRequestContextGetter* url_request_context_getter, const GDataWapiUrlGenerator& url_generator, const EntryActionCallback& callback, - const GURL& parent_content_url, + const std::string& parent_resource_id, const GURL& edit_url) : EntryActionOperation(registry, url_request_context_getter, callback), url_generator_(url_generator), - parent_content_url_(parent_content_url), + parent_resource_id_(parent_resource_id), edit_url_(edit_url) { DCHECK(!callback.is_null()); } @@ -489,9 +486,7 @@ AddResourceToDirectoryOperation::AddResourceToDirectoryOperation( AddResourceToDirectoryOperation::~AddResourceToDirectoryOperation() {} GURL AddResourceToDirectoryOperation::GetURL() const { - GURL parent = parent_content_url_.is_empty() ? - url_generator_.GenerateRootContentUrl() : parent_content_url_; - return GDataWapiUrlGenerator::AddStandardUrlParams(parent); + return url_generator_.GenerateContentUrl(parent_resource_id_); } URLFetcher::RequestType @@ -524,12 +519,12 @@ RemoveResourceFromDirectoryOperation::RemoveResourceFromDirectoryOperation( net::URLRequestContextGetter* url_request_context_getter, const GDataWapiUrlGenerator& url_generator, const EntryActionCallback& callback, - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& document_resource_id) : EntryActionOperation(registry, url_request_context_getter, callback), url_generator_(url_generator), resource_id_(document_resource_id), - parent_content_url_(parent_content_url) { + parent_resource_id_(parent_resource_id) { DCHECK(!callback.is_null()); } @@ -537,14 +532,8 @@ RemoveResourceFromDirectoryOperation::~RemoveResourceFromDirectoryOperation() { } GURL RemoveResourceFromDirectoryOperation::GetURL() const { - GURL parent = parent_content_url_.is_empty() ? - url_generator_.GenerateRootContentUrl() : parent_content_url_; - - std::string escaped_resource_id = net::EscapePath(resource_id_); - GURL edit_url(base::StringPrintf("%s/%s", - parent.spec().c_str(), - escaped_resource_id.c_str())); - return GDataWapiUrlGenerator::AddStandardUrlParams(edit_url); + return url_generator_.GenerateResourceUrlForRemoval( + parent_resource_id_, resource_id_); } URLFetcher::RequestType diff --git a/chrome/browser/google_apis/gdata_wapi_operations.h b/chrome/browser/google_apis/gdata_wapi_operations.h index 13e2c2d..f4708c8 100644 --- a/chrome/browser/google_apis/gdata_wapi_operations.h +++ b/chrome/browser/google_apis/gdata_wapi_operations.h @@ -219,7 +219,7 @@ class DeleteResourceOperation : public EntryActionOperation { class CreateDirectoryOperation : public GetDataOperation { public: // A new directory will be created under a directory specified by - // |parent_content_url|. If this parameter is empty, a new directory will + // |parent_resource_id|. If this parameter is empty, a new directory will // be created in the root directory. // |callback| must not be null. CreateDirectoryOperation( @@ -227,7 +227,7 @@ class CreateDirectoryOperation : public GetDataOperation { net::URLRequestContextGetter* url_request_context_getter, const GDataWapiUrlGenerator& url_generator, const GetDataCallback& callback, - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& directory_name); virtual ~CreateDirectoryOperation(); @@ -240,7 +240,7 @@ class CreateDirectoryOperation : public GetDataOperation { private: const GDataWapiUrlGenerator url_generator_; - const GURL parent_content_url_; + const std::string parent_resource_id_; const std::string directory_name_; DISALLOW_COPY_AND_ASSIGN(CreateDirectoryOperation); @@ -349,7 +349,7 @@ class AddResourceToDirectoryOperation : public EntryActionOperation { net::URLRequestContextGetter* url_request_context_getter, const GDataWapiUrlGenerator& url_generator, const EntryActionCallback& callback, - const GURL& parent_content_url, + const std::string& parent_resource_id, const GURL& edit_url); virtual ~AddResourceToDirectoryOperation(); @@ -362,7 +362,7 @@ class AddResourceToDirectoryOperation : public EntryActionOperation { private: const GDataWapiUrlGenerator url_generator_; - const GURL parent_content_url_; + const std::string parent_resource_id_; const GURL edit_url_; DISALLOW_COPY_AND_ASSIGN(AddResourceToDirectoryOperation); @@ -380,7 +380,7 @@ class RemoveResourceFromDirectoryOperation : public EntryActionOperation { net::URLRequestContextGetter* url_request_context_getter, const GDataWapiUrlGenerator& url_generator, const EntryActionCallback& callback, - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& resource_id); virtual ~RemoveResourceFromDirectoryOperation(); @@ -393,7 +393,7 @@ class RemoveResourceFromDirectoryOperation : public EntryActionOperation { private: const GDataWapiUrlGenerator url_generator_; const std::string resource_id_; - const GURL parent_content_url_; + const std::string parent_resource_id_; DISALLOW_COPY_AND_ASSIGN(RemoveResourceFromDirectoryOperation); }; diff --git a/chrome/browser/google_apis/gdata_wapi_operations_unittest.cc b/chrome/browser/google_apis/gdata_wapi_operations_unittest.cc index 0e11e30..ffd2eb8 100644 --- a/chrome/browser/google_apis/gdata_wapi_operations_unittest.cc +++ b/chrome/browser/google_apis/gdata_wapi_operations_unittest.cc @@ -228,14 +228,15 @@ class GDataWapiOperationsTest : public testing::Test { return test_util::CreateHttpResponseFromFile( test_util::GetTestFilePath("gdata/file_entry.json")); - } else if (resource_id == "folder:root" && + } else if (resource_id == "folder:root/contents" && request.method == test_server::METHOD_POST) { // This is a request for creating a directory in the root directory. // TODO(satorux): we should generate valid JSON data for the newly // created directory but for now, just return "directory_entry.json" return test_util::CreateHttpResponseFromFile( test_util::GetTestFilePath("gdata/directory_entry.json")); - } else if (resource_id == "folder:root/file:2_file_resource_id" && + } else if (resource_id == + "folder:root/contents/file:2_file_resource_id" && request.method == test_server::METHOD_DELETE) { // This is a request for deleting a file from the root directory. // TODO(satorux): Investigate what's returned from the server, and @@ -626,7 +627,7 @@ TEST_F(GDataWapiOperationsTest, CreateDirectoryOperation) { base::Bind(&test_util::CopyResultsFromGetDataCallbackAndQuit, &result_code, &result_data), - test_server_.GetURL("/feeds/default/private/full/folder%3Aroot"), + "folder:root", "new directory"); operation->Start(kTestGDataAuthToken, kTestUserAgent, @@ -635,7 +636,7 @@ TEST_F(GDataWapiOperationsTest, CreateDirectoryOperation) { EXPECT_EQ(HTTP_SUCCESS, result_code); EXPECT_EQ(test_server::METHOD_POST, http_request_.method); - EXPECT_EQ("/feeds/default/private/full/folder%3Aroot?v=3&alt=json", + EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents?v=3&alt=json", http_request_.relative_url); EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); @@ -795,7 +796,7 @@ TEST_F(GDataWapiOperationsTest, AddResourceToDirectoryOperation) { *url_generator_, base::Bind(&CopyResultFromEntryActionCallbackAndQuit, &result_code), - test_server_.GetURL("/feeds/default/private/full/folder%3Aroot"), + "folder:root", test_server_.GetURL( "/feeds/default/private/full/file:2_file_resource_id")); @@ -805,7 +806,7 @@ TEST_F(GDataWapiOperationsTest, AddResourceToDirectoryOperation) { EXPECT_EQ(HTTP_SUCCESS, result_code); EXPECT_EQ(test_server::METHOD_POST, http_request_.method); - EXPECT_EQ("/feeds/default/private/full/folder%3Aroot?v=3&alt=json", + EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents?v=3&alt=json", http_request_.relative_url); EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); @@ -829,7 +830,7 @@ TEST_F(GDataWapiOperationsTest, RemoveResourceFromDirectoryOperation) { *url_generator_, base::Bind(&CopyResultFromEntryActionCallbackAndQuit, &result_code), - test_server_.GetURL("/feeds/default/private/full/folder%3Aroot"), + "folder:root", "file:2_file_resource_id"); operation->Start(kTestGDataAuthToken, kTestUserAgent, @@ -839,7 +840,7 @@ TEST_F(GDataWapiOperationsTest, RemoveResourceFromDirectoryOperation) { EXPECT_EQ(HTTP_SUCCESS, result_code); // DELETE method should be used, without the body content. EXPECT_EQ(test_server::METHOD_DELETE, http_request_.method); - EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/" + EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents/" "file%3A2_file_resource_id?v=3&alt=json", http_request_.relative_url); EXPECT_EQ("*", http_request_.headers["If-Match"]); diff --git a/chrome/browser/google_apis/gdata_wapi_service.cc b/chrome/browser/google_apis/gdata_wapi_service.cc index 3d4346e..b2263a9 100644 --- a/chrome/browser/google_apis/gdata_wapi_service.cc +++ b/chrome/browser/google_apis/gdata_wapi_service.cc @@ -378,7 +378,7 @@ void GDataWapiService::DeleteResource( } void GDataWapiService::AddNewDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& directory_name, const GetResourceEntryCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -390,7 +390,7 @@ void GDataWapiService::AddNewDirectory( url_generator_, base::Bind(&ParseResourceEntryAndRun, callback), - parent_content_url, + parent_resource_id, directory_name)); } @@ -427,7 +427,7 @@ void GDataWapiService::RenameResource( } void GDataWapiService::AddResourceToDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const GURL& edit_url, const EntryActionCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -438,12 +438,12 @@ void GDataWapiService::AddResourceToDirectory( url_request_context_getter_, url_generator_, callback, - parent_content_url, + parent_resource_id, edit_url)); } void GDataWapiService::RemoveResourceFromDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& resource_id, const EntryActionCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -454,7 +454,7 @@ void GDataWapiService::RemoveResourceFromDirectory( url_request_context_getter_, url_generator_, callback, - parent_content_url, + parent_resource_id, resource_id)); } diff --git a/chrome/browser/google_apis/gdata_wapi_service.h b/chrome/browser/google_apis/gdata_wapi_service.h index 5b67f84..5f43341 100644 --- a/chrome/browser/google_apis/gdata_wapi_service.h +++ b/chrome/browser/google_apis/gdata_wapi_service.h @@ -96,15 +96,15 @@ class GDataWapiService : public DriveServiceInterface, const std::string& new_name, const EntryActionCallback& callback) OVERRIDE; virtual void AddResourceToDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const GURL& edit_url, const EntryActionCallback& callback) OVERRIDE; virtual void RemoveResourceFromDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& resource_id, const EntryActionCallback& callback) OVERRIDE; virtual void AddNewDirectory( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& directory_name, const GetResourceEntryCallback& callback) OVERRIDE; virtual void InitiateUpload( diff --git a/chrome/browser/google_apis/gdata_wapi_url_generator.cc b/chrome/browser/google_apis/gdata_wapi_url_generator.cc index 527ec49..020f8ed 100644 --- a/chrome/browser/google_apis/gdata_wapi_url_generator.cc +++ b/chrome/browser/google_apis/gdata_wapi_url_generator.cc @@ -23,6 +23,15 @@ const char kGetResourceListURLForAllDocuments[] = const char kGetResourceListURLForDirectoryFormat[] = "/feeds/default/private/full/%s/contents/-/mine"; +// Content URL for modification in a particular directory specifyied by "%s" +// which will be replaced with its resource id. +const char kContentURLFormat[] = "/feeds/default/private/full/%s/contents"; + +// Content URL for removing a resource specified by the latter "%s" from the +// directory specified by the former "%s". +const char kResourceURLForRemovalFormat[] = + "/feeds/default/private/full/%s/contents/%s"; + // URL requesting single resource entry whose resource id is specified by "%s". const char kGetResourceEntryURLFormat[] = "/feeds/default/private/full/%s"; @@ -32,10 +41,6 @@ const char kResourceListRootURL[] = "/feeds/default/private/full"; // Metadata feed with things like user quota. const char kAccountMetadataURL[] = "/feeds/metadata/default"; -// URL for the content_url of the root directory. -const char kRootContentURL[] = - "/feeds/default/private/full/folder%3Aroot/contents"; - #ifndef NDEBUG // Use smaller 'page' size while debugging to ensure we hit feed reload // almost always. Be careful not to use something too small on account that @@ -157,6 +162,35 @@ GURL GDataWapiUrlGenerator::GenerateResourceEntryUrl( return AddStandardUrlParams(result); } +GURL GDataWapiUrlGenerator::GenerateContentUrl( + const std::string& resource_id) const { + if (resource_id.empty()) { + // |resource_id| must not be empty. Return an empty GURL as an error. + return GURL(); + } + + GURL result = base_url_.Resolve( + base::StringPrintf(kContentURLFormat, + net::EscapePath(resource_id).c_str())); + return AddStandardUrlParams(result); +} + +GURL GDataWapiUrlGenerator::GenerateResourceUrlForRemoval( + const std::string& parent_resource_id, + const std::string& resource_id) const { + if (resource_id.empty() || parent_resource_id.empty()) { + // Both |resource_id| and |parent_resource_id| must be non-empty. + // Return an empty GURL as an error. + return GURL(); + } + + GURL result = base_url_.Resolve( + base::StringPrintf(kResourceURLForRemovalFormat, + net::EscapePath(parent_resource_id).c_str(), + net::EscapePath(resource_id).c_str())); + return AddStandardUrlParams(result); +} + GURL GDataWapiUrlGenerator::GenerateResourceListRootUrl() const { return AddStandardUrlParams(base_url_.Resolve(kResourceListRootURL)); } @@ -165,8 +199,4 @@ GURL GDataWapiUrlGenerator::GenerateAccountMetadataUrl() const { return AddMetadataUrlParams(base_url_.Resolve(kAccountMetadataURL)); } -GURL GDataWapiUrlGenerator::GenerateRootContentUrl() const { - return base_url_.Resolve(kRootContentURL); -} - } // namespace google_apis diff --git a/chrome/browser/google_apis/gdata_wapi_url_generator.h b/chrome/browser/google_apis/gdata_wapi_url_generator.h index 0717188..ff3cd91 100644 --- a/chrome/browser/google_apis/gdata_wapi_url_generator.h +++ b/chrome/browser/google_apis/gdata_wapi_url_generator.h @@ -81,6 +81,15 @@ class GDataWapiUrlGenerator { // Generates a URL for getting the resource entry of the given resource ID. GURL GenerateResourceEntryUrl(const std::string& resource_id) const; + // Generates a URL for editing the contents in the directory specified + // by the given resource ID. + GURL GenerateContentUrl(const std::string& resource_id) const; + + // Generates a URL to remove an entry specified by |resource_id| from + // the directory specified by the given |parent_resource_id|. + GURL GenerateResourceUrlForRemoval(const std::string& parent_resource_id, + const std::string& resource_id) const; + // Generates a URL for getting the root resource list feed. // Used to make changes in the root directory (ex. create a directory in the // root directory) @@ -89,9 +98,6 @@ class GDataWapiUrlGenerator { // Generates a URL for getting the account metadata feed. GURL GenerateAccountMetadataUrl() const; - // Generates a URL for getting the root directory's content URL. - GURL GenerateRootContentUrl() const; - private: const GURL base_url_; }; diff --git a/chrome/browser/google_apis/gdata_wapi_url_generator_unittest.cc b/chrome/browser/google_apis/gdata_wapi_url_generator_unittest.cc index 5309079..5b44fe3 100644 --- a/chrome/browser/google_apis/gdata_wapi_url_generator_unittest.cc +++ b/chrome/browser/google_apis/gdata_wapi_url_generator_unittest.cc @@ -166,6 +166,21 @@ TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceEntryUrl) { url_generator_.GenerateResourceEntryUrl("XXX").spec()); } +TEST_F(GDataWapiUrlGeneratorTest, GenerateContentUrl) { + EXPECT_EQ( + "https://docs.google.com/feeds/default/private/full/" + "folder%3Aroot/contents?v=3&alt=json", + url_generator_.GenerateContentUrl("folder:root").spec()); +} + +TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceUrlForRemoval) { + EXPECT_EQ( + "https://docs.google.com/feeds/default/private/full/" + "folder%3Aroot/contents/file%3AABCDE?v=3&alt=json", + url_generator_.GenerateResourceUrlForRemoval( + "folder:root", "file:ABCDE").spec()); +} + TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListRootUrl) { EXPECT_EQ( "https://docs.google.com/feeds/default/private/full?v=3&alt=json", diff --git a/chrome/browser/google_apis/mock_drive_service.cc b/chrome/browser/google_apis/mock_drive_service.cc index 434a9b2..ba2a7d5 100644 --- a/chrome/browser/google_apis/mock_drive_service.cc +++ b/chrome/browser/google_apis/mock_drive_service.cc @@ -139,7 +139,7 @@ void MockDriveService::RenameResourceStub( } void MockDriveService::AddResourceToDirectoryStub( - const GURL& parent_content_url, + const std::string& parent_resource_id, const GURL& edit_url, const EntryActionCallback& callback) { base::MessageLoopProxy::current()->PostTask( @@ -148,7 +148,7 @@ void MockDriveService::AddResourceToDirectoryStub( } void MockDriveService::RemoveResourceFromDirectoryStub( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& resource_id, const EntryActionCallback& callback) { base::MessageLoopProxy::current()->PostTask( @@ -157,7 +157,7 @@ void MockDriveService::RemoveResourceFromDirectoryStub( } void MockDriveService::CreateDirectoryStub( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& directory_name, const GetResourceEntryCallback& callback) { scoped_ptr<ResourceEntry> resource_entry = diff --git a/chrome/browser/google_apis/mock_drive_service.h b/chrome/browser/google_apis/mock_drive_service.h index 3680b4a..4da2fe8 100644 --- a/chrome/browser/google_apis/mock_drive_service.h +++ b/chrome/browser/google_apis/mock_drive_service.h @@ -65,17 +65,17 @@ class MockDriveService : public DriveServiceInterface { const std::string& new_name, const EntryActionCallback& callback)); MOCK_METHOD3(AddResourceToDirectory, - void(const GURL& parent_content_url, + void(const std::string& parent_resource_id, const GURL& edit_url, const EntryActionCallback& callback)); MOCK_METHOD3(RemoveResourceFromDirectory, - void(const GURL& parent_content_url, + void(const std::string& parent_resource_id, const std::string& resource_id, const EntryActionCallback& callback)); MOCK_METHOD3(AddNewDirectory, - void(const GURL& parent_content_url, - const std::string& directory_name, - const GetResourceEntryCallback& callback)); + void(const std::string& parent_resource_id, + const std::string& directory_name, + const GetResourceEntryCallback& callback)); MOCK_METHOD5( DownloadFile, void(const FilePath& virtual_path, @@ -146,19 +146,19 @@ class MockDriveService : public DriveServiceInterface { // Will call |callback| with HTTP_SUCCESS. void AddResourceToDirectoryStub( - const GURL& parent_content_url, + const std::string& parent_resource_id, const GURL& edit_url, const EntryActionCallback& callback); // Will call |callback| with HTTP_SUCCESS. void RemoveResourceFromDirectoryStub( - const GURL& parent_content_url, + const std::string& parent_resource_id, const std::string& resource_id, const EntryActionCallback& callback); // Will call |callback| with HTTP_SUCCESS and the current value of // |directory_data_|. - void CreateDirectoryStub(const GURL& parent_content_url, + void CreateDirectoryStub(const std::string& parent_resource_id, const std::string& directory_name, const GetResourceEntryCallback& callback); |