summaryrefslogtreecommitdiffstats
path: root/google_apis
diff options
context:
space:
mode:
authormtomasz <mtomasz@chromium.org>2015-02-20 01:49:56 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-20 09:50:19 +0000
commitfe3e27bcf3a3458865075bcab72807bc70a96d09 (patch)
tree37b78939e347f230dbc192b65fadc1cb74abbeae /google_apis
parent0206f4d63cd34010b16eb87992d9ea4ab4d12ee5 (diff)
downloadchromium_src-fe3e27bcf3a3458865075bcab72807bc70a96d09.zip
chromium_src-fe3e27bcf3a3458865075bcab72807bc70a96d09.tar.gz
chromium_src-fe3e27bcf3a3458865075bcab72807bc70a96d09.tar.bz2
Add support for adding properties to files on Drive.
Adding properties is done via a patch http request, which merges arrays. Note, that we do not fetch properties via Drive API, as they are never used in Chromium code. The new method is not wired to chrome.fileManagerPrivate yet. It will be done in a separate CL. TEST=googleapi_unittests: *FilesPatchRequest* BUG=451113 Review URL: https://codereview.chromium.org/928803003 Cr-Commit-Position: refs/heads/master@{#317276}
Diffstat (limited to 'google_apis')
-rw-r--r--google_apis/drive/drive_api_parser.h1
-rw-r--r--google_apis/drive/drive_api_requests.cc27
-rw-r--r--google_apis/drive/drive_api_requests.h39
-rw-r--r--google_apis/drive/drive_api_requests_unittest.cc28
4 files changed, 89 insertions, 6 deletions
diff --git a/google_apis/drive/drive_api_parser.h b/google_apis/drive/drive_api_parser.h
index 450aa36..482d749 100644
--- a/google_apis/drive/drive_api_parser.h
+++ b/google_apis/drive/drive_api_parser.h
@@ -419,7 +419,6 @@ class ImageMediaMetadata {
int rotation_;
};
-
// FileResource represents a file or folder metadata in Drive.
// https://developers.google.com/drive/v2/reference/files
class FileResource {
diff --git a/google_apis/drive/drive_api_requests.cc b/google_apis/drive/drive_api_requests.cc
index 3691a9e..8e32915 100644
--- a/google_apis/drive/drive_api_requests.cc
+++ b/google_apis/drive/drive_api_requests.cc
@@ -49,6 +49,12 @@ void ParseFileResourceWithUploadRangeAndRun(
namespace drive {
+Property::Property() : visibility_(VISIBILITY_PRIVATE) {
+}
+
+Property::~Property() {
+}
+
//============================ DriveApiPartialFieldRequest ====================
DriveApiPartialFieldRequest::DriveApiPartialFieldRequest(
@@ -226,6 +232,27 @@ bool FilesPatchRequest::GetContentData(std::string* upload_content_type,
root.Set("parents", parents_value);
}
+ if (!properties_.empty()) {
+ base::ListValue* properties_value = new base::ListValue;
+ for (const auto& property : properties_) {
+ base::DictionaryValue* const property_value = new base::DictionaryValue;
+ std::string visibility_as_string;
+ switch (property.visibility()) {
+ case Property::VISIBILITY_PRIVATE:
+ visibility_as_string = "PRIVATE";
+ break;
+ case Property::VISIBILITY_PUBLIC:
+ visibility_as_string = "PUBLIC";
+ break;
+ }
+ property_value->SetString("visibility", visibility_as_string);
+ property_value->SetString("key", property.key());
+ property_value->SetString("value", property.value());
+ properties_value->Append(property_value);
+ }
+ root.Set("properties", properties_value);
+ }
+
base::JSONWriter::Write(&root, upload_content);
DVLOG(1) << "FilesPatch data: " << *upload_content_type << ", ["
<< *upload_content << "]";
diff --git a/google_apis/drive/drive_api_requests.h b/google_apis/drive/drive_api_requests.h
index 4fa6eaf..33f74a8 100644
--- a/google_apis/drive/drive_api_requests.h
+++ b/google_apis/drive/drive_api_requests.h
@@ -6,6 +6,7 @@
#define GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_
#include <string>
+#include <vector>
#include "base/callback_forward.h"
#include "base/location.h"
@@ -32,6 +33,38 @@ typedef base::Callback<void(DriveApiErrorCode error,
namespace drive {
+// Represents a property for a file or a directory.
+// https://developers.google.com/drive/v2/reference/properties
+class Property {
+ public:
+ Property();
+ ~Property();
+
+ // Visibility of the property. Either limited to the same client, or to any.
+ enum Visibility { VISIBILITY_PRIVATE, VISIBILITY_PUBLIC };
+
+ // Whether the property is public or private.
+ Visibility visibility() const { return visibility_; }
+
+ // Name of the property.
+ const std::string& key() const { return key_; }
+
+ // Value of the property.
+ const std::string& value() const { return value_; }
+
+ void set_visibility(Visibility visibility) { visibility_ = visibility; }
+ void set_key(const std::string& key) { key_ = key; }
+ void set_value(const std::string& value) { value_ = value; }
+
+ private:
+ Visibility visibility_;
+ std::string key_;
+ std::string value_;
+};
+
+// List of properties for a single file or a directory.
+typedef std::vector<Property> Properties;
+
//============================ DriveApiPartialFieldRequest ====================
// This is base class of the Drive API related requests. All Drive API requests
@@ -306,6 +339,11 @@ class FilesPatchRequest : public DriveApiDataRequest<FileResource> {
const std::vector<std::string>& parents() const { return parents_; }
void add_parent(const std::string& parent) { parents_.push_back(parent); }
+ const Properties& properties() const { return properties_; }
+ void set_properties(const Properties& properties) {
+ properties_ = properties;
+ }
+
protected:
// Overridden from URLFetchRequestBase.
net::URLFetcher::RequestType GetRequestType() const override;
@@ -327,6 +365,7 @@ class FilesPatchRequest : public DriveApiDataRequest<FileResource> {
base::Time modified_date_;
base::Time last_viewed_by_me_date_;
std::vector<std::string> parents_;
+ Properties properties_;
DISALLOW_COPY_AND_ASSIGN(FilesPatchRequest);
};
diff --git a/google_apis/drive/drive_api_requests_unittest.cc b/google_apis/drive/drive_api_requests_unittest.cc
index c4cab5b..deb2845 100644
--- a/google_apis/drive/drive_api_requests_unittest.cc
+++ b/google_apis/drive/drive_api_requests_unittest.cc
@@ -511,6 +511,20 @@ TEST_F(DriveApiRequestsTest, FilesPatchRequest) {
base::Time::FromUTCExploded(kLastViewedByMeDate));
request->add_parent("parent_resource_id");
+ drive::Property private_property;
+ private_property.set_key("key1");
+ private_property.set_value("value1");
+
+ drive::Property public_property;
+ public_property.set_visibility(drive::Property::VISIBILITY_PUBLIC);
+ public_property.set_key("key2");
+ public_property.set_value("value2");
+
+ drive::Properties properties;
+ properties.push_back(private_property);
+ properties.push_back(public_property);
+ request->set_properties(properties);
+
request_sender_->StartRequestWithRetry(request);
run_loop.Run();
}
@@ -523,11 +537,15 @@ TEST_F(DriveApiRequestsTest, FilesPatchRequest) {
EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
EXPECT_TRUE(http_request_.has_content);
- EXPECT_EQ("{\"lastViewedByMeDate\":\"2013-07-19T15:59:13.123Z\","
- "\"modifiedDate\":\"2012-07-19T15:59:13.123Z\","
- "\"parents\":[{\"id\":\"parent_resource_id\"}],"
- "\"title\":\"new title\"}",
- http_request_.content);
+ EXPECT_EQ(
+ "{\"lastViewedByMeDate\":\"2013-07-19T15:59:13.123Z\","
+ "\"modifiedDate\":\"2012-07-19T15:59:13.123Z\","
+ "\"parents\":[{\"id\":\"parent_resource_id\"}],"
+ "\"properties\":["
+ "{\"key\":\"key1\",\"value\":\"value1\",\"visibility\":\"PRIVATE\"},"
+ "{\"key\":\"key2\",\"value\":\"value2\",\"visibility\":\"PUBLIC\"}],"
+ "\"title\":\"new title\"}",
+ http_request_.content);
EXPECT_TRUE(file_resource);
}