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

Side by Side Diff: chrome/browser/drive/drive_api_service.cc

Issue 23575004: Refactor CreateDiretoryRequest. (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
« no previous file with comments | « no previous file | chrome/browser/google_apis/drive_api_requests.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/drive/drive_api_service.h" 5 #include "chrome/browser/drive/drive_api_service.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 using google_apis::ProgressCallback; 48 using google_apis::ProgressCallback;
49 using google_apis::RequestSender; 49 using google_apis::RequestSender;
50 using google_apis::ResourceEntry; 50 using google_apis::ResourceEntry;
51 using google_apis::ResourceList; 51 using google_apis::ResourceList;
52 using google_apis::UploadRangeCallback; 52 using google_apis::UploadRangeCallback;
53 using google_apis::UploadRangeResponse; 53 using google_apis::UploadRangeResponse;
54 using google_apis::drive::AboutGetRequest; 54 using google_apis::drive::AboutGetRequest;
55 using google_apis::drive::AppsListRequest; 55 using google_apis::drive::AppsListRequest;
56 using google_apis::drive::ChangesListRequest; 56 using google_apis::drive::ChangesListRequest;
57 using google_apis::drive::ContinueGetFileListRequest; 57 using google_apis::drive::ContinueGetFileListRequest;
58 using google_apis::drive::CreateDirectoryRequest;
59 using google_apis::drive::DeleteResourceRequest; 58 using google_apis::drive::DeleteResourceRequest;
60 using google_apis::drive::DownloadFileRequest; 59 using google_apis::drive::DownloadFileRequest;
61 using google_apis::drive::FilesCopyRequest; 60 using google_apis::drive::FilesCopyRequest;
62 using google_apis::drive::FilesGetRequest; 61 using google_apis::drive::FilesGetRequest;
62 using google_apis::drive::FilesInsertRequest;
63 using google_apis::drive::FilesPatchRequest; 63 using google_apis::drive::FilesPatchRequest;
64 using google_apis::drive::FilesListRequest; 64 using google_apis::drive::FilesListRequest;
65 using google_apis::drive::GetUploadStatusRequest; 65 using google_apis::drive::GetUploadStatusRequest;
66 using google_apis::drive::InitiateUploadExistingFileRequest; 66 using google_apis::drive::InitiateUploadExistingFileRequest;
67 using google_apis::drive::InitiateUploadNewFileRequest; 67 using google_apis::drive::InitiateUploadNewFileRequest;
68 using google_apis::drive::InsertResourceRequest; 68 using google_apis::drive::InsertResourceRequest;
69 using google_apis::drive::ResumeUploadRequest; 69 using google_apis::drive::ResumeUploadRequest;
70 using google_apis::drive::TrashResourceRequest; 70 using google_apis::drive::TrashResourceRequest;
71 71
72 namespace drive { 72 namespace drive {
73 73
74 namespace { 74 namespace {
75 75
76 // OAuth2 scopes for Drive API. 76 // OAuth2 scopes for Drive API.
77 const char kDriveScope[] = "https://www.googleapis.com/auth/drive"; 77 const char kDriveScope[] = "https://www.googleapis.com/auth/drive";
78 const char kDriveAppsReadonlyScope[] = 78 const char kDriveAppsReadonlyScope[] =
79 "https://www.googleapis.com/auth/drive.apps.readonly"; 79 "https://www.googleapis.com/auth/drive.apps.readonly";
80 80
81 // Mime type to create a directory.
82 const char kFolderMimeType[] = "application/vnd.google-apps.folder";
83
81 // Expected max number of files resources in a http request. 84 // Expected max number of files resources in a http request.
82 // Be careful not to use something too small because it might overload the 85 // Be careful not to use something too small because it might overload the
83 // server. Be careful not to use something too large because it takes longer 86 // server. Be careful not to use something too large because it takes longer
84 // time to fetch the result without UI response. 87 // time to fetch the result without UI response.
85 const int kMaxNumFilesResourcePerRequest = 500; 88 const int kMaxNumFilesResourcePerRequest = 500;
86 const int kMaxNumFilesResourcePerRequestForSearch = 50; 89 const int kMaxNumFilesResourcePerRequestForSearch = 50;
87 90
88 scoped_ptr<ResourceList> ParseChangeListJsonToResourceList( 91 scoped_ptr<ResourceList> ParseChangeListJsonToResourceList(
89 scoped_ptr<base::Value> value) { 92 scoped_ptr<base::Value> value) {
90 scoped_ptr<ChangeList> change_list(ChangeList::CreateFrom(*value)); 93 scoped_ptr<ChangeList> change_list(ChangeList::CreateFrom(*value));
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 callback)); 599 callback));
597 } 600 }
598 601
599 CancelCallback DriveAPIService::AddNewDirectory( 602 CancelCallback DriveAPIService::AddNewDirectory(
600 const std::string& parent_resource_id, 603 const std::string& parent_resource_id,
601 const std::string& directory_title, 604 const std::string& directory_title,
602 const GetResourceEntryCallback& callback) { 605 const GetResourceEntryCallback& callback) {
603 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 606 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
604 DCHECK(!callback.is_null()); 607 DCHECK(!callback.is_null());
605 608
606 return sender_->StartRequestWithRetry( 609 FilesInsertRequest* request = new FilesInsertRequest(
607 new CreateDirectoryRequest( 610 sender_.get(), url_generator_,
608 sender_.get(), 611 base::Bind(&ConvertFileEntryToResourceEntryAndRun, callback));
609 url_generator_, 612 request->set_mime_type(kFolderMimeType);
610 parent_resource_id, 613 request->add_parent(parent_resource_id);
611 directory_title, 614 request->set_title(directory_title);
612 base::Bind(&ConvertFileEntryToResourceEntryAndRun, callback))); 615 return sender_->StartRequestWithRetry(request);
613 } 616 }
614 617
615 CancelCallback DriveAPIService::CopyResource( 618 CancelCallback DriveAPIService::CopyResource(
616 const std::string& resource_id, 619 const std::string& resource_id,
617 const std::string& parent_resource_id, 620 const std::string& parent_resource_id,
618 const std::string& new_title, 621 const std::string& new_title,
619 const GetResourceEntryCallback& callback) { 622 const GetResourceEntryCallback& callback) {
620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 623 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
621 DCHECK(!callback.is_null()); 624 DCHECK(!callback.is_null());
622 625
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 if (CanSendRequest()) { 869 if (CanSendRequest()) {
867 FOR_EACH_OBSERVER( 870 FOR_EACH_OBSERVER(
868 DriveServiceObserver, observers_, OnReadyToSendRequests()); 871 DriveServiceObserver, observers_, OnReadyToSendRequests());
869 } else if (!HasRefreshToken()) { 872 } else if (!HasRefreshToken()) {
870 FOR_EACH_OBSERVER( 873 FOR_EACH_OBSERVER(
871 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); 874 DriveServiceObserver, observers_, OnRefreshTokenInvalid());
872 } 875 }
873 } 876 }
874 877
875 } // namespace drive 878 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/google_apis/drive_api_requests.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698