summaryrefslogtreecommitdiffstats
path: root/chrome/browser/google_apis
diff options
context:
space:
mode:
authorhidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-01 10:22:34 +0000
committerhidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-01 10:22:34 +0000
commit25b71c8ba55ec1819c4eee15226a3eb01b10c680 (patch)
tree0c7d7d9f4ef034ab06fb36126e5b1a95afc06dec /chrome/browser/google_apis
parent8c1df562be660bae05237111d6bc0a7a0cd7a908 (diff)
downloadchromium_src-25b71c8ba55ec1819c4eee15226a3eb01b10c680.zip
chromium_src-25b71c8ba55ec1819c4eee15226a3eb01b10c680.tar.gz
chromium_src-25b71c8ba55ec1819c4eee15226a3eb01b10c680.tar.bz2
Implement InitiateUploadExistingFile on Drive API v2.
This is a part of implementing an upload function on Drive API v2. BUG=148632 TEST=Ran unit_tests Review URL: https://chromiumcodereview.appspot.com/12389019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@185517 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/google_apis')
-rw-r--r--chrome/browser/google_apis/drive_api_operations.cc42
-rw-r--r--chrome/browser/google_apis/drive_api_operations.h38
-rw-r--r--chrome/browser/google_apis/drive_api_operations_unittest.cc44
-rw-r--r--chrome/browser/google_apis/drive_api_service.cc13
4 files changed, 135 insertions, 2 deletions
diff --git a/chrome/browser/google_apis/drive_api_operations.cc b/chrome/browser/google_apis/drive_api_operations.cc
index 4fcef01..56044c1 100644
--- a/chrome/browser/google_apis/drive_api_operations.cc
+++ b/chrome/browser/google_apis/drive_api_operations.cc
@@ -399,5 +399,47 @@ bool InitiateUploadNewFileOperation::GetContentData(
return true;
}
+//===================== InitiateUploadExistingFileOperation ====================
+
+InitiateUploadExistingFileOperation::InitiateUploadExistingFileOperation(
+ OperationRegistry* registry,
+ net::URLRequestContextGetter* url_request_context_getter,
+ const DriveApiUrlGenerator& url_generator,
+ const base::FilePath& drive_file_path,
+ const std::string& content_type,
+ int64 content_length,
+ const std::string& resource_id,
+ const std::string& etag,
+ const InitiateUploadCallback& callback)
+ : InitiateUploadOperationBase(registry,
+ url_request_context_getter,
+ callback,
+ drive_file_path,
+ content_type,
+ content_length),
+ url_generator_(url_generator),
+ resource_id_(resource_id),
+ etag_(etag) {
+}
+
+InitiateUploadExistingFileOperation::~InitiateUploadExistingFileOperation() {}
+
+GURL InitiateUploadExistingFileOperation::GetURL() const {
+ return url_generator_.GetInitiateUploadExistingFileUrl(resource_id_);
+}
+
+net::URLFetcher::RequestType
+InitiateUploadExistingFileOperation::GetRequestType() const {
+ return net::URLFetcher::PUT;
+}
+
+std::vector<std::string>
+InitiateUploadExistingFileOperation::GetExtraRequestHeaders() const {
+ std::vector<std::string> headers(
+ InitiateUploadOperationBase::GetExtraRequestHeaders());
+ headers.push_back(util::GenerateIfMatchHeader(etag_));
+ return headers;
+}
+
} // namespace drive
} // namespace google_apis
diff --git a/chrome/browser/google_apis/drive_api_operations.h b/chrome/browser/google_apis/drive_api_operations.h
index ad8e532..504371c 100644
--- a/chrome/browser/google_apis/drive_api_operations.h
+++ b/chrome/browser/google_apis/drive_api_operations.h
@@ -354,6 +354,44 @@ class InitiateUploadNewFileOperation : public InitiateUploadOperationBase {
DISALLOW_COPY_AND_ASSIGN(InitiateUploadNewFileOperation);
};
+//==================== InitiateUploadExistingFileOperation =====================
+
+// This class performs the operation for initiating the upload of an existing
+// file.
+class InitiateUploadExistingFileOperation
+ : public InitiateUploadOperationBase {
+ public:
+ // |upload_url| should be the upload_url() of the file
+ // (resumable-create-media URL)
+ // |etag| should be set if it is available to detect the upload confliction.
+ // See also the comments of InitiateUploadOperationBase for more details
+ // about the other parameters.
+ InitiateUploadExistingFileOperation(
+ OperationRegistry* registry,
+ net::URLRequestContextGetter* url_request_context_getter,
+ const DriveApiUrlGenerator& url_generator,
+ const base::FilePath& drive_file_path,
+ const std::string& content_type,
+ int64 content_length,
+ const std::string& resource_id,
+ const std::string& etag,
+ const InitiateUploadCallback& callback);
+ virtual ~InitiateUploadExistingFileOperation();
+
+ protected:
+ // UrlFetchOperationBase overrides.
+ virtual GURL GetURL() const OVERRIDE;
+ virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
+ virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE;
+
+ private:
+ const DriveApiUrlGenerator url_generator_;
+ const std::string resource_id_;
+ const std::string etag_;
+
+ DISALLOW_COPY_AND_ASSIGN(InitiateUploadExistingFileOperation);
+};
+
} // namespace drive
} // namespace google_apis
diff --git a/chrome/browser/google_apis/drive_api_operations_unittest.cc b/chrome/browser/google_apis/drive_api_operations_unittest.cc
index cc94574..4f0ab52 100644
--- a/chrome/browser/google_apis/drive_api_operations_unittest.cc
+++ b/chrome/browser/google_apis/drive_api_operations_unittest.cc
@@ -479,4 +479,48 @@ TEST_F(DriveApiOperationsTest, InitiateUploadNewFileOperation) {
operation_registry_.CancelAll();
}
+TEST_F(DriveApiOperationsTest, InitiateUploadExistingFileOperation) {
+ // Set an expected url for uploading.
+ expected_upload_url_ = kTestUploadUrl;
+
+ const char kTestContentType[] = "text/plain";
+ const int64 kTestContentLength = 100;
+
+ GDataErrorCode error = GDATA_OTHER_ERROR;
+ GURL url;
+
+ // Initiate uploading a new file to the directory with "parent_resource_id".
+ drive::InitiateUploadExistingFileOperation* operation =
+ new drive::InitiateUploadExistingFileOperation(
+ &operation_registry_,
+ request_context_getter_.get(),
+ *url_generator_,
+ base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
+ kTestContentType,
+ kTestContentLength,
+ "resource_id", // The resource id of the file to be overwritten.
+ "dummy-etag",
+ base::Bind(&test_util::CopyResultsFromInitiateUploadCallbackAndQuit,
+ &error, &url));
+ operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
+ base::Bind(&test_util::DoNothingForReAuthenticateCallback));
+ MessageLoop::current()->Run();
+
+ EXPECT_EQ(HTTP_SUCCESS, error);
+ EXPECT_EQ(kTestUploadUrl, url.spec());
+ EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
+ EXPECT_EQ(base::Int64ToString(kTestContentLength),
+ http_request_.headers["X-Upload-Content-Length"]);
+ EXPECT_EQ("dummy-etag", http_request_.headers["If-Match"]);
+
+ EXPECT_EQ(test_server::METHOD_PUT, http_request_.method);
+ EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable",
+ http_request_.relative_url);
+ EXPECT_TRUE(http_request_.has_content);
+ EXPECT_TRUE(http_request_.content.empty());
+
+ // Clean the operation remaining in |operation_registry_|.
+ operation_registry_.CancelAll();
+}
+
} // namespace google_apis
diff --git a/chrome/browser/google_apis/drive_api_service.cc b/chrome/browser/google_apis/drive_api_service.cc
index 43f8456..57e48f7 100644
--- a/chrome/browser/google_apis/drive_api_service.cc
+++ b/chrome/browser/google_apis/drive_api_service.cc
@@ -483,8 +483,17 @@ void DriveAPIService::InitiateUploadExistingFile(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
- // TODO(hidehiko): Implement this.
- NOTREACHED();
+ runner_->StartOperationWithRetry(
+ new drive::InitiateUploadExistingFileOperation(
+ operation_registry(),
+ url_request_context_getter_,
+ url_generator_,
+ drive_file_path,
+ content_type,
+ content_length,
+ resource_id,
+ etag,
+ callback));
}
void DriveAPIService::ResumeUpload(