summaryrefslogtreecommitdiffstats
path: root/google_apis
diff options
context:
space:
mode:
authorfukino <fukino@chromium.org>2015-08-27 03:11:42 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-27 10:12:12 +0000
commitcaa62e470605fcf99b2ce1b5edca7259af083ea5 (patch)
tree657dd5f8b0537925bcc540df5f8ee6a98340e223 /google_apis
parent71394d35928cd827ba04e7867195903e690e609b (diff)
downloadchromium_src-caa62e470605fcf99b2ce1b5edca7259af083ea5.zip
chromium_src-caa62e470605fcf99b2ce1b5edca7259af083ea5.tar.gz
chromium_src-caa62e470605fcf99b2ce1b5edca7259af083ea5.tar.bz2
Add visibility property to FilesInsertRequest and FilesCopyRequest.
We need to specify new file's visibility explicitly when we want to keeping the file private regardless of the account's sharing policy. https://developers.google.com/drive/v2/reference/files/insert#visibility https://developers.google.com/drive/v2/reference/files/copy#visibility BUG=518750 TEST=run google_apis_unittests Review URL: https://codereview.chromium.org/1316743003 Cr-Commit-Position: refs/heads/master@{#345834}
Diffstat (limited to 'google_apis')
-rw-r--r--google_apis/drive/drive_api_requests.cc4
-rw-r--r--google_apis/drive/drive_api_requests.h14
-rw-r--r--google_apis/drive/drive_api_requests_unittest.cc7
-rw-r--r--google_apis/drive/drive_api_url_generator.cc21
-rw-r--r--google_apis/drive/drive_api_url_generator.h5
-rw-r--r--google_apis/drive/drive_api_url_generator_unittest.cc18
6 files changed, 55 insertions, 14 deletions
diff --git a/google_apis/drive/drive_api_requests.cc b/google_apis/drive/drive_api_requests.cc
index d9089bb..4bf2d08 100644
--- a/google_apis/drive/drive_api_requests.cc
+++ b/google_apis/drive/drive_api_requests.cc
@@ -434,7 +434,7 @@ bool FilesInsertRequest::GetContentData(std::string* upload_content_type,
}
GURL FilesInsertRequest::GetURLInternal() const {
- return url_generator_.GetFilesInsertUrl();
+ return url_generator_.GetFilesInsertUrl(visibility_);
}
//============================== FilesPatchRequest ============================
@@ -526,7 +526,7 @@ net::URLFetcher::RequestType FilesCopyRequest::GetRequestType() const {
}
GURL FilesCopyRequest::GetURLInternal() const {
- return url_generator_.GetFilesCopyUrl(file_id_);
+ return url_generator_.GetFilesCopyUrl(file_id_, visibility_);
}
bool FilesCopyRequest::GetContentData(std::string* upload_content_type,
diff --git a/google_apis/drive/drive_api_requests.h b/google_apis/drive/drive_api_requests.h
index ebef7fd..8ce6ad1 100644
--- a/google_apis/drive/drive_api_requests.h
+++ b/google_apis/drive/drive_api_requests.h
@@ -261,6 +261,12 @@ class FilesInsertRequest : public DriveApiDataRequest<FileResource> {
const FileResourceCallback& callback);
~FilesInsertRequest() override;
+ // Optional parameter
+ const std::string& visibility() const { return visibility_; }
+ void set_visibility(const std::string& visibility) {
+ visibility_ = visibility;
+ }
+
// Optional request body.
const base::Time& last_viewed_by_me_date() const {
return last_viewed_by_me_date_;
@@ -302,6 +308,7 @@ class FilesInsertRequest : public DriveApiDataRequest<FileResource> {
private:
const DriveApiUrlGenerator url_generator_;
+ std::string visibility_;
base::Time last_viewed_by_me_date_;
std::string mime_type_;
base::Time modified_date_;
@@ -409,6 +416,12 @@ class FilesCopyRequest : public DriveApiDataRequest<FileResource> {
const std::string& file_id() const { return file_id_; }
void set_file_id(const std::string& file_id) { file_id_ = file_id; }
+ // Optional parameter
+ const std::string& visibility() const { return visibility_; }
+ void set_visibility(const std::string& visibility) {
+ visibility_ = visibility;
+ }
+
// Optional request body.
const std::vector<std::string>& parents() const { return parents_; }
void add_parent(const std::string& parent) { parents_.push_back(parent); }
@@ -434,6 +447,7 @@ class FilesCopyRequest : public DriveApiDataRequest<FileResource> {
const DriveApiUrlGenerator url_generator_;
std::string file_id_;
+ std::string visibility_;
base::Time modified_date_;
std::vector<std::string> parents_;
std::string title_;
diff --git a/google_apis/drive/drive_api_requests_unittest.cc b/google_apis/drive/drive_api_requests_unittest.cc
index 8ca6e17..237b7f0 100644
--- a/google_apis/drive/drive_api_requests_unittest.cc
+++ b/google_apis/drive/drive_api_requests_unittest.cc
@@ -558,6 +558,7 @@ TEST_F(DriveApiRequestsTest, FilesInsertRequest) {
test_util::CreateQuitCallback(
&run_loop,
test_util::CreateCopyResultCallback(&error, &file_resource)));
+ request->set_visibility("DEFAULT");
request->set_last_viewed_by_me_date(
base::Time::FromUTCExploded(kLastViewedByMeDate));
request->set_mime_type("application/vnd.google-apps.folder");
@@ -571,7 +572,7 @@ TEST_F(DriveApiRequestsTest, FilesInsertRequest) {
EXPECT_EQ(HTTP_SUCCESS, error);
EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
- EXPECT_EQ("/drive/v2/files", http_request_.relative_url);
+ EXPECT_EQ("/drive/v2/files?visibility=DEFAULT", http_request_.relative_url);
EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
EXPECT_TRUE(http_request_.has_content);
@@ -819,6 +820,7 @@ TEST_F(DriveApiRequestsTest, FilesCopyRequest) {
test_util::CreateQuitCallback(
&run_loop,
test_util::CreateCopyResultCallback(&error, &file_resource)));
+ request->set_visibility("PRIVATE");
request->set_file_id("resource_id");
request->set_modified_date(base::Time::FromUTCExploded(kModifiedDate));
request->add_parent("parent_resource_id");
@@ -829,7 +831,8 @@ TEST_F(DriveApiRequestsTest, FilesCopyRequest) {
EXPECT_EQ(HTTP_SUCCESS, error);
EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
- EXPECT_EQ("/drive/v2/files/resource_id/copy", http_request_.relative_url);
+ EXPECT_EQ("/drive/v2/files/resource_id/copy?visibility=PRIVATE",
+ http_request_.relative_url);
EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
EXPECT_TRUE(http_request_.has_content);
diff --git a/google_apis/drive/drive_api_url_generator.cc b/google_apis/drive/drive_api_url_generator.cc
index b6632d7..14da8a3 100644
--- a/google_apis/drive/drive_api_url_generator.cc
+++ b/google_apis/drive/drive_api_url_generator.cc
@@ -116,8 +116,14 @@ GURL DriveApiUrlGenerator::GetFilesAuthorizeUrl(
net::EscapePath(app_id).c_str()));
}
-GURL DriveApiUrlGenerator::GetFilesInsertUrl() const {
- return base_url_.Resolve(kDriveV2FilesUrl);
+GURL DriveApiUrlGenerator::GetFilesInsertUrl(
+ const std::string& visibility) const {
+ GURL url = base_url_.Resolve(kDriveV2FilesUrl);
+
+ if (!visibility.empty())
+ url = net::AppendOrReplaceQueryParameter(url, "visibility", visibility);
+
+ return url;
}
GURL DriveApiUrlGenerator::GetFilesPatchUrl(const std::string& file_id,
@@ -137,9 +143,16 @@ GURL DriveApiUrlGenerator::GetFilesPatchUrl(const std::string& file_id,
return url;
}
-GURL DriveApiUrlGenerator::GetFilesCopyUrl(const std::string& file_id) const {
- return base_url_.Resolve(base::StringPrintf(
+GURL DriveApiUrlGenerator::GetFilesCopyUrl(
+ const std::string& file_id,
+ const std::string& visibility) const {
+ GURL url = base_url_.Resolve(base::StringPrintf(
kDriveV2FileCopyUrlFormat, net::EscapePath(file_id).c_str()));
+
+ if (!visibility.empty())
+ url = net::AppendOrReplaceQueryParameter(url, "visibility", visibility);
+
+ return url;
}
GURL DriveApiUrlGenerator::GetFilesListUrl(int max_results,
diff --git a/google_apis/drive/drive_api_url_generator.h b/google_apis/drive/drive_api_url_generator.h
index a1ec3c1..7e498fb 100644
--- a/google_apis/drive/drive_api_url_generator.h
+++ b/google_apis/drive/drive_api_url_generator.h
@@ -47,7 +47,7 @@ class DriveApiUrlGenerator {
const std::string& app_id) const;
// Returns a URL to create a resource.
- GURL GetFilesInsertUrl() const;
+ GURL GetFilesInsertUrl(const std::string& visibility) const;
// Returns a URL to patch file metadata.
GURL GetFilesPatchUrl(const std::string& file_id,
@@ -55,7 +55,8 @@ class DriveApiUrlGenerator {
bool update_viewed_date) const;
// Returns a URL to copy a resource specified by |file_id|.
- GURL GetFilesCopyUrl(const std::string& file_id) const;
+ GURL GetFilesCopyUrl(const std::string& file_id,
+ const std::string& visibility) const;
// Returns a URL to fetch file list.
GURL GetFilesListUrl(int max_results,
diff --git a/google_apis/drive/drive_api_url_generator_unittest.cc b/google_apis/drive/drive_api_url_generator_unittest.cc
index 9643dea..28e79c4 100644
--- a/google_apis/drive/drive_api_url_generator_unittest.cc
+++ b/google_apis/drive/drive_api_url_generator_unittest.cc
@@ -83,7 +83,11 @@ TEST_F(DriveApiUrlGeneratorTest, GetFilesAuthorizeUrl) {
TEST_F(DriveApiUrlGeneratorTest, GetFilesInsertUrl) {
EXPECT_EQ("https://www.example.com/drive/v2/files",
- url_generator_.GetFilesInsertUrl().spec());
+ url_generator_.GetFilesInsertUrl("").spec());
+ EXPECT_EQ("https://www.example.com/drive/v2/files?visibility=DEFAULT",
+ url_generator_.GetFilesInsertUrl("DEFAULT").spec());
+ EXPECT_EQ("https://www.example.com/drive/v2/files?visibility=PRIVATE",
+ url_generator_.GetFilesInsertUrl("PRIVATE").spec());
}
TEST_F(DriveApiUrlGeneratorTest, GetFilePatchUrl) {
@@ -126,11 +130,17 @@ TEST_F(DriveApiUrlGeneratorTest, GetFilePatchUrl) {
TEST_F(DriveApiUrlGeneratorTest, GetFilesCopyUrl) {
// |file_id| should be embedded into the url.
EXPECT_EQ("https://www.example.com/drive/v2/files/0ADK06pfg/copy",
- url_generator_.GetFilesCopyUrl("0ADK06pfg").spec());
+ url_generator_.GetFilesCopyUrl("0ADK06pfg", "").spec());
EXPECT_EQ("https://www.example.com/drive/v2/files/0Bz0bd074/copy",
- url_generator_.GetFilesCopyUrl("0Bz0bd074").spec());
+ url_generator_.GetFilesCopyUrl("0Bz0bd074", "").spec());
EXPECT_EQ("https://www.example.com/drive/v2/files/file%3Afile_id/copy",
- url_generator_.GetFilesCopyUrl("file:file_id").spec());
+ url_generator_.GetFilesCopyUrl("file:file_id", "").spec());
+ EXPECT_EQ("https://www.example.com/drive/v2/files/0Bz0bd074/copy"
+ "?visibility=DEFAULT",
+ url_generator_.GetFilesCopyUrl("0Bz0bd074", "DEFAULT").spec());
+ EXPECT_EQ("https://www.example.com/drive/v2/files/file%3Afile_id/copy"
+ "?visibility=PRIVATE",
+ url_generator_.GetFilesCopyUrl("file:file_id", "PRIVATE").spec());
}
TEST_F(DriveApiUrlGeneratorTest, GetFilesListUrl) {