diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-13 04:28:18 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-13 04:28:18 +0000 |
commit | dedd11a1706e63fed812b5ffa67756402c99fc42 (patch) | |
tree | a7983559d0c99e311fee1fce0ba8cdf463492f0a | |
parent | 4d82eb7acb18a37400c4703ff196ad94092040e5 (diff) | |
download | chromium_src-dedd11a1706e63fed812b5ffa67756402c99fc42.zip chromium_src-dedd11a1706e63fed812b5ffa67756402c99fc42.tar.gz chromium_src-dedd11a1706e63fed812b5ffa67756402c99fc42.tar.bz2 |
google_apis: DriveServiceInterface::CopyHostedDocument() returns ResourceEntry
This way, client code doesn't have to convert base::Value to ResourceEntry
BUG=165390
TEST=none
Review URL: https://codereview.chromium.org/11564004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@172815 0039d316-1c4b-4281-b951-d872f2087c98
12 files changed, 41 insertions, 31 deletions
diff --git a/chrome/browser/chromeos/drive/drive_api_service.cc b/chrome/browser/chromeos/drive/drive_api_service.cc index 7b62055..b728f7a 100644 --- a/chrome/browser/chromeos/drive/drive_api_service.cc +++ b/chrome/browser/chromeos/drive/drive_api_service.cc @@ -326,7 +326,7 @@ void DriveAPIService::AddNewDirectory( void DriveAPIService::CopyHostedDocument( const std::string& resource_id, const FilePath::StringType& new_name, - const google_apis::GetDataCallback& callback) { + const google_apis::GetResourceEntryCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(!callback.is_null()); diff --git a/chrome/browser/chromeos/drive/drive_api_service.h b/chrome/browser/chromeos/drive/drive_api_service.h index 0b54302..7ed7949 100644 --- a/chrome/browser/chromeos/drive/drive_api_service.h +++ b/chrome/browser/chromeos/drive/drive_api_service.h @@ -91,7 +91,7 @@ class DriveAPIService : public google_apis::DriveServiceInterface, virtual void CopyHostedDocument( const std::string& resource_id, const FilePath::StringType& new_name, - const google_apis::GetDataCallback& callback) OVERRIDE; + const google_apis::GetResourceEntryCallback& callback) OVERRIDE; virtual void RenameResource( const GURL& edit_url, const FilePath::StringType& new_name, diff --git a/chrome/browser/chromeos/drive/drive_file_system_unittest.cc b/chrome/browser/chromeos/drive/drive_file_system_unittest.cc index 77d8237..102597b 100644 --- a/chrome/browser/chromeos/drive/drive_file_system_unittest.cc +++ b/chrome/browser/chromeos/drive/drive_file_system_unittest.cc @@ -1349,13 +1349,16 @@ TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_HostedDocument) { // We'll copy a hosted document using CopyHostedDocument. // ".gdoc" suffix should be stripped when copying. - scoped_ptr<base::Value> document = + scoped_ptr<base::Value> value = google_apis::test_util::LoadJSONFile("gdata/uploaded_document.json"); + scoped_ptr<google_apis::ResourceEntry> resource_entry = + google_apis::ResourceEntry::ExtractAndParse(*value); EXPECT_CALL(*mock_drive_service_, CopyHostedDocument(kResourceId, FILE_PATH_LITERAL("Document 1"), _)) - .WillOnce(MockCopyHostedDocument(google_apis::HTTP_SUCCESS, &document)); + .WillOnce(MockCopyHostedDocument(google_apis::HTTP_SUCCESS, + &resource_entry)); // We'll then add the hosted document to the destination directory. EXPECT_CALL(*mock_drive_service_, AddResourceToDirectory(_, _, _)).Times(1); diff --git a/chrome/browser/chromeos/drive/drive_scheduler_unittest.cc b/chrome/browser/chromeos/drive/drive_scheduler_unittest.cc index 7bbe954..71b7254 100644 --- a/chrome/browser/chromeos/drive/drive_scheduler_unittest.cc +++ b/chrome/browser/chromeos/drive/drive_scheduler_unittest.cc @@ -129,7 +129,7 @@ class FakeDriveService : public DriveServiceInterface { virtual void CopyHostedDocument(const std::string& resource_id, const FilePath::StringType& new_name, - const GetDataCallback& callback) { + const GetResourceEntryCallback& callback) { } virtual void RenameResource(const GURL& edit_url, diff --git a/chrome/browser/chromeos/drive/file_system/copy_operation.cc b/chrome/browser/chromeos/drive/file_system/copy_operation.cc index 2e650db..5389114 100644 --- a/chrome/browser/chromeos/drive/file_system/copy_operation.cc +++ b/chrome/browser/chromeos/drive/file_system/copy_operation.cc @@ -233,7 +233,7 @@ void CopyOperation::OnCopyHostedDocumentCompleted( const FilePath& dir_path, const FileOperationCallback& callback, GDataErrorCode status, - scoped_ptr<base::Value> data) { + scoped_ptr<google_apis::ResourceEntry> resource_entry) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(!callback.is_null()); @@ -242,13 +242,14 @@ void CopyOperation::OnCopyHostedDocumentCompleted( callback.Run(error); return; } + DCHECK(resource_entry); // |entry| was added in the root directory on the server, so we should // first add it to |root_| to mirror the state and then move it to the // destination directory by MoveEntryFromRootDirectory(). metadata_->AddEntryToDirectory( FilePath(kDriveRootDirectory), - scoped_ptr<ResourceEntry>(ResourceEntry::ExtractAndParse(*data)), + resource_entry.Pass(), base::Bind(&CopyOperation::MoveEntryFromRootDirectory, weak_ptr_factory_.GetWeakPtr(), dir_path, diff --git a/chrome/browser/chromeos/drive/file_system/copy_operation.h b/chrome/browser/chromeos/drive/file_system/copy_operation.h index 8fe36a2..2f1756f 100644 --- a/chrome/browser/chromeos/drive/file_system/copy_operation.h +++ b/chrome/browser/chromeos/drive/file_system/copy_operation.h @@ -116,10 +116,11 @@ class CopyOperation { // Callback for handling document copy attempt. // |callback| must not be null. - void OnCopyHostedDocumentCompleted(const FilePath& dir_path, - const FileOperationCallback& callback, - google_apis::GDataErrorCode status, - scoped_ptr<base::Value> data); + void OnCopyHostedDocumentCompleted( + const FilePath& dir_path, + const FileOperationCallback& callback, + google_apis::GDataErrorCode status, + scoped_ptr<google_apis::ResourceEntry> resource_entry); // Moves a file or directory at |file_path| in the root directory to // another directory at |dir_path|. This function does nothing if diff --git a/chrome/browser/google_apis/drive_service_interface.h b/chrome/browser/google_apis/drive_service_interface.h index 4d75c36..ff1d188 100644 --- a/chrome/browser/google_apis/drive_service_interface.h +++ b/chrome/browser/google_apis/drive_service_interface.h @@ -182,9 +182,10 @@ class DriveServiceInterface { // when needed. Upon completion, invokes |callback| with results on the // calling thread. // |callback| must not be null. - virtual void CopyHostedDocument(const std::string& resource_id, - const FilePath::StringType& new_name, - const GetDataCallback& callback) = 0; + virtual void CopyHostedDocument( + const std::string& resource_id, + const FilePath::StringType& new_name, + const GetResourceEntryCallback& callback) = 0; // Renames a document or collection identified by its |edit_url| // to the UTF-8 encoded |new_name|. Upon completion, diff --git a/chrome/browser/google_apis/drive_uploader_unittest.cc b/chrome/browser/google_apis/drive_uploader_unittest.cc index 972923f..36bc4b7 100644 --- a/chrome/browser/google_apis/drive_uploader_unittest.cc +++ b/chrome/browser/google_apis/drive_uploader_unittest.cc @@ -116,9 +116,10 @@ class MockDriveServiceBase : public DriveServiceInterface { const DownloadActionCallback& callback) OVERRIDE { NOTREACHED(); } - virtual void CopyHostedDocument(const std::string& resource_id, - const FilePath::StringType& new_name, - const GetDataCallback& callback) OVERRIDE { + virtual void CopyHostedDocument( + const std::string& resource_id, + const FilePath::StringType& new_name, + const GetResourceEntryCallback& callback) OVERRIDE { NOTREACHED(); } virtual void RenameResource(const GURL& edit_url, diff --git a/chrome/browser/google_apis/gdata_wapi_service.cc b/chrome/browser/google_apis/gdata_wapi_service.cc index 4fffa69..4e10a18 100644 --- a/chrome/browser/google_apis/gdata_wapi_service.cc +++ b/chrome/browser/google_apis/gdata_wapi_service.cc @@ -363,17 +363,18 @@ void GDataWapiService::AddNewDirectory( void GDataWapiService::CopyHostedDocument( const std::string& resource_id, const FilePath::StringType& new_name, - const GetDataCallback& callback) { + const GetResourceEntryCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(!callback.is_null()); runner_->StartOperationWithRetry( - new CopyHostedDocumentOperation(operation_registry(), - url_request_context_getter_, - url_generator_, - callback, - resource_id, - new_name)); + new CopyHostedDocumentOperation( + operation_registry(), + url_request_context_getter_, + url_generator_, + base::Bind(&ParseResourceEntryAndRun, callback), + resource_id, + new_name)); } void GDataWapiService::RenameResource( diff --git a/chrome/browser/google_apis/gdata_wapi_service.h b/chrome/browser/google_apis/gdata_wapi_service.h index 7578e24..5051fdf 100644 --- a/chrome/browser/google_apis/gdata_wapi_service.h +++ b/chrome/browser/google_apis/gdata_wapi_service.h @@ -89,7 +89,7 @@ class GDataWapiService : public DriveServiceInterface, virtual void CopyHostedDocument( const std::string& resource_id, const FilePath::StringType& new_name, - const GetDataCallback& callback) OVERRIDE; + const GetResourceEntryCallback& callback) OVERRIDE; virtual void RenameResource( const GURL& edit_url, const FilePath::StringType& new_name, diff --git a/chrome/browser/google_apis/mock_drive_service.cc b/chrome/browser/google_apis/mock_drive_service.cc index 222770d..ae2ab3a 100644 --- a/chrome/browser/google_apis/mock_drive_service.cc +++ b/chrome/browser/google_apis/mock_drive_service.cc @@ -73,14 +73,14 @@ void MockDriveService::GetResourceListStub( const GetResourceListCallback& callback) { if (search_string.empty()) { scoped_ptr<ResourceList> resource_list = - google_apis::ResourceList::ExtractAndParse(*feed_data_); + ResourceList::ExtractAndParse(*feed_data_); base::MessageLoopProxy::current()->PostTask( FROM_HERE, base::Bind(callback, HTTP_SUCCESS, base::Passed(&resource_list))); } else { scoped_ptr<ResourceList> resource_list = - google_apis::ResourceList::ExtractAndParse(*search_result_); + ResourceList::ExtractAndParse(*search_result_); base::MessageLoopProxy::current()->PostTask( FROM_HERE, base::Bind(callback, HTTP_SUCCESS, @@ -120,11 +120,13 @@ void MockDriveService::DownloadHostedDocumentStub( void MockDriveService::CopyHostedDocumentStub( const std::string& resource_id, const FilePath::StringType& new_name, - const GetDataCallback& callback) { + const GetResourceEntryCallback& callback) { + scoped_ptr<ResourceEntry> resource_entry = + ResourceEntry::ExtractAndParse(*document_data_); base::MessageLoopProxy::current()->PostTask( FROM_HERE, base::Bind(callback, HTTP_SUCCESS, - base::Passed(&document_data_))); + base::Passed(&resource_entry))); } void MockDriveService::RenameResourceStub( diff --git a/chrome/browser/google_apis/mock_drive_service.h b/chrome/browser/google_apis/mock_drive_service.h index 6cbfd81..c2e8879 100644 --- a/chrome/browser/google_apis/mock_drive_service.h +++ b/chrome/browser/google_apis/mock_drive_service.h @@ -59,7 +59,7 @@ class MockDriveService : public DriveServiceInterface { MOCK_METHOD3(CopyHostedDocument, void(const std::string& resource_id, const FilePath::StringType& new_name, - const GetDataCallback& callback)); + const GetResourceEntryCallback& callback)); MOCK_METHOD3(RenameResource, void(const GURL& edit_url, const FilePath::StringType& new_name, @@ -149,7 +149,7 @@ class MockDriveService : public DriveServiceInterface { // |document_data_|. void CopyHostedDocumentStub(const std::string& resource_id, const FilePath::StringType& new_name, - const GetDataCallback& callback); + const GetResourceEntryCallback& callback); // Will call |callback| with HTTP_SUCCESS. void RenameResourceStub(const GURL& edit_url, |