Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: chrome/browser/google_apis/drive_api_operations.cc

Issue 12090015: Implement CreateDirectoryOperation on Drive API v2. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add an empty line. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/google_apis/drive_api_operations.h" 5 #include "chrome/browser/google_apis/drive_api_operations.h"
6 6
7 #include "base/json/json_writer.h"
8 #include "base/values.h"
9
7 namespace google_apis { 10 namespace google_apis {
11 namespace {
12
13 const char kContentTypeApplicationJson[] = "application/json";
14 const char kDirectoryMimeType[] = "application/vnd.google-apps.folder";
15
16 } // namespace
8 17
9 //============================== GetAboutOperation ============================= 18 //============================== GetAboutOperation =============================
10 19
11 GetAboutOperation::GetAboutOperation( 20 GetAboutOperation::GetAboutOperation(
12 OperationRegistry* registry, 21 OperationRegistry* registry,
13 net::URLRequestContextGetter* url_request_context_getter, 22 net::URLRequestContextGetter* url_request_context_getter,
14 const DriveApiUrlGenerator& url_generator, 23 const DriveApiUrlGenerator& url_generator,
15 const GetDataCallback& callback) 24 const GetDataCallback& callback)
16 : GetDataOperation(registry, url_request_context_getter, callback), 25 : GetDataOperation(registry, url_request_context_getter, callback),
17 url_generator_(url_generator) { 26 url_generator_(url_generator) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 file_id_(file_id) { 108 file_id_(file_id) {
100 DCHECK(!callback.is_null()); 109 DCHECK(!callback.is_null());
101 } 110 }
102 111
103 GetFileOperation::~GetFileOperation() {} 112 GetFileOperation::~GetFileOperation() {}
104 113
105 GURL GetFileOperation::GetURL() const { 114 GURL GetFileOperation::GetURL() const {
106 return url_generator_.GetFileUrl(file_id_); 115 return url_generator_.GetFileUrl(file_id_);
107 } 116 }
108 117
118 namespace drive {
119
120 //========================== CreateDirectoryOperation ==========================
121
122 CreateDirectoryOperation::CreateDirectoryOperation(
123 OperationRegistry* registry,
124 net::URLRequestContextGetter* url_request_context_getter,
125 const DriveApiUrlGenerator& url_generator,
126 const std::string& parent_resource_id,
127 const std::string& directory_name,
128 const GetDataCallback& callback)
129 : GetDataOperation(registry, url_request_context_getter, callback),
130 url_generator_(url_generator),
131 parent_resource_id_(parent_resource_id),
132 directory_name_(directory_name) {
133 DCHECK(!callback.is_null());
134 }
135
136 CreateDirectoryOperation::~CreateDirectoryOperation() {}
137
138 GURL CreateDirectoryOperation::GetURL() const {
139 if (parent_resource_id_.empty() || directory_name_.empty()) {
140 return GURL();
141 }
142 return url_generator_.GetFilelistUrl(GURL(), "");
143 }
144
145 net::URLFetcher::RequestType CreateDirectoryOperation::GetRequestType() const {
146 return net::URLFetcher::POST;
147 }
148
149 bool CreateDirectoryOperation::GetContentData(std::string* upload_content_type,
150 std::string* upload_content) {
151 *upload_content_type = kContentTypeApplicationJson;
152
153 base::DictionaryValue root;
154 root.SetString("title", directory_name_);
155 {
156 base::DictionaryValue* parent_value = new base::DictionaryValue;
157 parent_value->SetString("id", parent_resource_id_);
158 base::ListValue* parent_list_value = new base::ListValue;
159 parent_list_value->Append(parent_value);
160 root.Set("parents", parent_list_value);
161 }
162 root.SetString("mimeType", kDirectoryMimeType);
163
164 base::JSONWriter::Write(&root, upload_content);
165
166 DVLOG(1) << "CreateDirectory data: " << *upload_content_type << ", ["
167 << *upload_content << "]";
168 return true;
169 }
170
171 } // namespace drive
109 } // namespace google_apis 172 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/drive_api_operations.h ('k') | chrome/browser/google_apis/drive_api_operations_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698