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

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

Issue 23757004: Refactor InsertResourceRequest and DeleteResourceRequest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 3 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/location.h" 10 #include "base/location.h"
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 parent_value->SetString("id", parent_resource_id_); 533 parent_value->SetString("id", parent_resource_id_);
534 } 534 }
535 535
536 base::JSONWriter::Write(&root, upload_content); 536 base::JSONWriter::Write(&root, upload_content);
537 537
538 DVLOG(1) << "MoveResource data: " << *upload_content_type << ", [" 538 DVLOG(1) << "MoveResource data: " << *upload_content_type << ", ["
539 << *upload_content << "]"; 539 << *upload_content << "]";
540 return true; 540 return true;
541 } 541 }
542 542
543 //========================== InsertResourceRequest =========================== 543 //========================== ChildrenInsertRequest ============================
544 544
545 InsertResourceRequest::InsertResourceRequest( 545 ChildrenInsertRequest::ChildrenInsertRequest(
546 RequestSender* sender, 546 RequestSender* sender,
547 const DriveApiUrlGenerator& url_generator, 547 const DriveApiUrlGenerator& url_generator,
548 const std::string& parent_resource_id,
549 const std::string& resource_id,
550 const EntryActionCallback& callback) 548 const EntryActionCallback& callback)
551 : EntryActionRequest(sender, callback), 549 : EntryActionRequest(sender, callback),
552 url_generator_(url_generator), 550 url_generator_(url_generator) {
553 parent_resource_id_(parent_resource_id),
554 resource_id_(resource_id) {
555 DCHECK(!callback.is_null()); 551 DCHECK(!callback.is_null());
556 } 552 }
557 553
558 InsertResourceRequest::~InsertResourceRequest() {} 554 ChildrenInsertRequest::~ChildrenInsertRequest() {}
559 555
560 GURL InsertResourceRequest::GetURL() const { 556 net::URLFetcher::RequestType ChildrenInsertRequest::GetRequestType() const {
561 return url_generator_.GetChildrenUrl(parent_resource_id_);
562 }
563
564 net::URLFetcher::RequestType InsertResourceRequest::GetRequestType() const {
565 return net::URLFetcher::POST; 557 return net::URLFetcher::POST;
566 } 558 }
567 559
568 bool InsertResourceRequest::GetContentData(std::string* upload_content_type, 560 GURL ChildrenInsertRequest::GetURL() const {
561 return url_generator_.GetChildrenInsertUrl(folder_id_);
562 }
563
564 bool ChildrenInsertRequest::GetContentData(std::string* upload_content_type,
569 std::string* upload_content) { 565 std::string* upload_content) {
570 *upload_content_type = kContentTypeApplicationJson; 566 *upload_content_type = kContentTypeApplicationJson;
571 567
572 base::DictionaryValue root; 568 base::DictionaryValue root;
573 root.SetString("id", resource_id_); 569 root.SetString("id", id_);
570
574 base::JSONWriter::Write(&root, upload_content); 571 base::JSONWriter::Write(&root, upload_content);
575
576 DVLOG(1) << "InsertResource data: " << *upload_content_type << ", [" 572 DVLOG(1) << "InsertResource data: " << *upload_content_type << ", ["
577 << *upload_content << "]"; 573 << *upload_content << "]";
578 return true; 574 return true;
579 } 575 }
580 576
581 //========================== DeleteResourceRequest =========================== 577 //========================== ChildrenDeleteRequest ============================
582 578
583 DeleteResourceRequest::DeleteResourceRequest( 579 ChildrenDeleteRequest::ChildrenDeleteRequest(
584 RequestSender* sender, 580 RequestSender* sender,
585 const DriveApiUrlGenerator& url_generator, 581 const DriveApiUrlGenerator& url_generator,
586 const std::string& parent_resource_id,
587 const std::string& resource_id,
588 const EntryActionCallback& callback) 582 const EntryActionCallback& callback)
589 : EntryActionRequest(sender, callback), 583 : EntryActionRequest(sender, callback),
590 url_generator_(url_generator), 584 url_generator_(url_generator) {
591 parent_resource_id_(parent_resource_id),
592 resource_id_(resource_id) {
593 DCHECK(!callback.is_null()); 585 DCHECK(!callback.is_null());
594 } 586 }
595 587
596 DeleteResourceRequest::~DeleteResourceRequest() {} 588 ChildrenDeleteRequest::~ChildrenDeleteRequest() {}
597 589
598 GURL DeleteResourceRequest::GetURL() const { 590 net::URLFetcher::RequestType ChildrenDeleteRequest::GetRequestType() const {
599 return url_generator_.GetChildrenUrlForRemoval(
600 parent_resource_id_, resource_id_);
601 }
602
603 net::URLFetcher::RequestType DeleteResourceRequest::GetRequestType() const {
604 return net::URLFetcher::DELETE_REQUEST; 591 return net::URLFetcher::DELETE_REQUEST;
605 } 592 }
606 593
594 GURL ChildrenDeleteRequest::GetURL() const {
595 return url_generator_.GetChildrenDeleteUrl(child_id_, folder_id_);
596 }
597
607 //======================= InitiateUploadNewFileRequest ======================= 598 //======================= InitiateUploadNewFileRequest =======================
608 599
609 InitiateUploadNewFileRequest::InitiateUploadNewFileRequest( 600 InitiateUploadNewFileRequest::InitiateUploadNewFileRequest(
610 RequestSender* sender, 601 RequestSender* sender,
611 const DriveApiUrlGenerator& url_generator, 602 const DriveApiUrlGenerator& url_generator,
612 const std::string& content_type, 603 const std::string& content_type,
613 int64 content_length, 604 int64 content_length,
614 const std::string& parent_resource_id, 605 const std::string& parent_resource_id,
615 const std::string& title, 606 const std::string& title,
616 const InitiateUploadCallback& callback) 607 const InitiateUploadCallback& callback)
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 progress_callback, 769 progress_callback,
779 url_generator.GenerateDownloadFileUrl(resource_id), 770 url_generator.GenerateDownloadFileUrl(resource_id),
780 output_file_path) { 771 output_file_path) {
781 } 772 }
782 773
783 DownloadFileRequest::~DownloadFileRequest() { 774 DownloadFileRequest::~DownloadFileRequest() {
784 } 775 }
785 776
786 } // namespace drive 777 } // namespace drive
787 } // namespace google_apis 778 } // 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