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

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

Issue 23042004: Implement MoveResourceRequest on Drive API v2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
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_requests.h" 5 #include "chrome/browser/google_apis/drive_api_requests.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 231 }
232 root.SetString("mimeType", kDirectoryMimeType); 232 root.SetString("mimeType", kDirectoryMimeType);
233 233
234 base::JSONWriter::Write(&root, upload_content); 234 base::JSONWriter::Write(&root, upload_content);
235 235
236 DVLOG(1) << "CreateDirectory data: " << *upload_content_type << ", [" 236 DVLOG(1) << "CreateDirectory data: " << *upload_content_type << ", ["
237 << *upload_content << "]"; 237 << *upload_content << "]";
238 return true; 238 return true;
239 } 239 }
240 240
241 //=========================== RenameResourceRequest ==========================
242
243 RenameResourceRequest::RenameResourceRequest(
244 RequestSender* sender,
245 const DriveApiUrlGenerator& url_generator,
246 const std::string& resource_id,
247 const std::string& new_title,
248 const EntryActionCallback& callback)
249 : EntryActionRequest(sender, callback),
250 url_generator_(url_generator),
251 resource_id_(resource_id),
252 new_title_(new_title) {
253 DCHECK(!callback.is_null());
254 }
255
256 RenameResourceRequest::~RenameResourceRequest() {}
257
258 net::URLFetcher::RequestType RenameResourceRequest::GetRequestType() const {
259 return net::URLFetcher::PATCH;
260 }
261
262 std::vector<std::string>
263 RenameResourceRequest::GetExtraRequestHeaders() const {
264 std::vector<std::string> headers;
265 headers.push_back(util::kIfMatchAllHeader);
266 return headers;
267 }
268
269 GURL RenameResourceRequest::GetURL() const {
270 return url_generator_.GetFileUrl(resource_id_);
271 }
272
273 bool RenameResourceRequest::GetContentData(std::string* upload_content_type,
274 std::string* upload_content) {
275 *upload_content_type = kContentTypeApplicationJson;
276
277 base::DictionaryValue root;
278 root.SetString("title", new_title_);
279 base::JSONWriter::Write(&root, upload_content);
280
281 DVLOG(1) << "RenameResource data: " << *upload_content_type << ", ["
282 << *upload_content << "]";
283 return true;
284 }
285
286 //=========================== TouchResourceRequest =========================== 241 //=========================== TouchResourceRequest ===========================
287 242
288 TouchResourceRequest::TouchResourceRequest( 243 TouchResourceRequest::TouchResourceRequest(
289 RequestSender* sender, 244 RequestSender* sender,
290 const DriveApiUrlGenerator& url_generator, 245 const DriveApiUrlGenerator& url_generator,
291 const std::string& resource_id, 246 const std::string& resource_id,
292 const base::Time& modified_date, 247 const base::Time& modified_date,
293 const base::Time& last_viewed_by_me_date, 248 const base::Time& last_viewed_by_me_date,
294 const FileResourceCallback& callback) 249 const FileResourceCallback& callback)
295 : GetDataRequest(sender, 250 : GetDataRequest(sender,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 parent_value->SetString("id", parent_resource_id_); 335 parent_value->SetString("id", parent_resource_id_);
381 } 336 }
382 337
383 base::JSONWriter::Write(&root, upload_content); 338 base::JSONWriter::Write(&root, upload_content);
384 339
385 DVLOG(1) << "CopyResource data: " << *upload_content_type << ", [" 340 DVLOG(1) << "CopyResource data: " << *upload_content_type << ", ["
386 << *upload_content << "]"; 341 << *upload_content << "]";
387 return true; 342 return true;
388 } 343 }
389 344
345 //=========================== MoveResourceRequest ============================
346
347 MoveResourceRequest::MoveResourceRequest(
348 RequestSender* sender,
349 const DriveApiUrlGenerator& url_generator,
350 const std::string& resource_id,
351 const std::string& parent_resource_id,
352 const std::string& new_title,
353 const FileResourceCallback& callback)
354 : GetDataRequest(sender,
355 base::Bind(&ParseJsonAndRun<FileResource>, callback)),
356 url_generator_(url_generator),
357 resource_id_(resource_id),
358 parent_resource_id_(parent_resource_id),
359 new_title_(new_title) {
360 DCHECK(!callback.is_null());
361 }
362
363 MoveResourceRequest::~MoveResourceRequest() {
364 }
365
366 net::URLFetcher::RequestType MoveResourceRequest::GetRequestType() const {
367 return net::URLFetcher::PATCH;
368 }
369
370 std::vector<std::string> MoveResourceRequest::GetExtraRequestHeaders() const {
371 std::vector<std::string> headers;
372 headers.push_back(util::kIfMatchAllHeader);
373 return headers;
374 }
375
376 GURL MoveResourceRequest::GetURL() const {
377 return url_generator_.GetFileUrl(resource_id_);
378 }
379
380 bool MoveResourceRequest::GetContentData(std::string* upload_content_type,
381 std::string* upload_content) {
382 *upload_content_type = kContentTypeApplicationJson;
383
384 base::DictionaryValue root;
385 root.SetString("title", new_title_);
386
387 if (!parent_resource_id_.empty()) {
388 // Set the parent resource (destination directory) of the new resource.
389 base::ListValue* parents = new base::ListValue;
390 root.Set("parents", parents);
391 base::DictionaryValue* parent_value = new base::DictionaryValue;
392 parents->Append(parent_value);
393 parent_value->SetString("id", parent_resource_id_);
394 }
395
396 base::JSONWriter::Write(&root, upload_content);
397
398 DVLOG(1) << "MoveResource data: " << *upload_content_type << ", ["
399 << *upload_content << "]";
400 return true;
401 }
402
390 //=========================== TrashResourceRequest =========================== 403 //=========================== TrashResourceRequest ===========================
391 404
392 TrashResourceRequest::TrashResourceRequest( 405 TrashResourceRequest::TrashResourceRequest(
393 RequestSender* sender, 406 RequestSender* sender,
394 const DriveApiUrlGenerator& url_generator, 407 const DriveApiUrlGenerator& url_generator,
395 const std::string& resource_id, 408 const std::string& resource_id,
396 const EntryActionCallback& callback) 409 const EntryActionCallback& callback)
397 : EntryActionRequest(sender, callback), 410 : EntryActionRequest(sender, callback),
398 url_generator_(url_generator), 411 url_generator_(url_generator),
399 resource_id_(resource_id) { 412 resource_id_(resource_id) {
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 progress_callback, 661 progress_callback,
649 url_generator.GenerateDownloadFileUrl(resource_id), 662 url_generator.GenerateDownloadFileUrl(resource_id),
650 output_file_path) { 663 output_file_path) {
651 } 664 }
652 665
653 DownloadFileRequest::~DownloadFileRequest() { 666 DownloadFileRequest::~DownloadFileRequest() {
654 } 667 }
655 668
656 } // namespace drive 669 } // namespace drive
657 } // namespace google_apis 670 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/drive_api_requests.h ('k') | chrome/browser/google_apis/drive_api_requests_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698