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

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

Issue 443303003: Random cleanup around google_apis/drive and c/b/drive. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
« no previous file with comments | « no previous file | chrome/browser/drive/drive_api_util.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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 using google_apis::drive::UploadRangeCallback; 71 using google_apis::drive::UploadRangeCallback;
72 72
73 namespace drive { 73 namespace drive {
74 74
75 namespace { 75 namespace {
76 76
77 // OAuth2 scopes for Drive API. 77 // OAuth2 scopes for Drive API.
78 const char kDriveScope[] = "https://www.googleapis.com/auth/drive"; 78 const char kDriveScope[] = "https://www.googleapis.com/auth/drive";
79 const char kDriveAppsReadonlyScope[] = 79 const char kDriveAppsReadonlyScope[] =
80 "https://www.googleapis.com/auth/drive.apps.readonly"; 80 "https://www.googleapis.com/auth/drive.apps.readonly";
81 const char kDriveAppsScope[] = "https://www.googleapis.com/auth/drive.apps";
82 const char kDocsListScope[] = "https://docs.google.com/feeds/";
81 83
82 // Mime type to create a directory. 84 // Mime type to create a directory.
83 const char kFolderMimeType[] = "application/vnd.google-apps.folder"; 85 const char kFolderMimeType[] = "application/vnd.google-apps.folder";
84 86
85 // Max number of file entries to be fetched in a single http request. 87 // Max number of file entries to be fetched in a single http request.
86 // 88 //
87 // The larger the number is, 89 // The larger the number is,
88 // - The total running time to fetch the whole file list will become shorter. 90 // - The total running time to fetch the whole file list will become shorter.
89 // - The running time for a single request tends to become longer. 91 // - The running time for a single request tends to become longer.
90 // Since the file list fetching is a completely background task, for our side, 92 // Since the file list fetching is a completely background task, for our side,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 if (sender_.get()) 191 if (sender_.get())
190 sender_->auth_service()->RemoveObserver(this); 192 sender_->auth_service()->RemoveObserver(this);
191 } 193 }
192 194
193 void DriveAPIService::Initialize(const std::string& account_id) { 195 void DriveAPIService::Initialize(const std::string& account_id) {
194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
195 197
196 std::vector<std::string> scopes; 198 std::vector<std::string> scopes;
197 scopes.push_back(kDriveScope); 199 scopes.push_back(kDriveScope);
198 scopes.push_back(kDriveAppsReadonlyScope); 200 scopes.push_back(kDriveAppsReadonlyScope);
199 scopes.push_back(util::kDriveAppsScope); 201 scopes.push_back(kDriveAppsScope);
200 202
201 // GData WAPI token for GetShareUrl(). 203 // Note: The following scope is used to support GetShareUrl on Drive API v2.
202 scopes.push_back(util::kDocsListScope); 204 // Unfortunately, there is no support on Drive API v2, so we need to fall back
205 // to GData WAPI for the GetShareUrl.
206 scopes.push_back(kDocsListScope);
203 207
204 sender_.reset(new RequestSender( 208 sender_.reset(new RequestSender(
205 new google_apis::AuthService(oauth2_token_service_, 209 new google_apis::AuthService(oauth2_token_service_,
206 account_id, 210 account_id,
207 url_request_context_getter_.get(), 211 url_request_context_getter_.get(),
208 scopes), 212 scopes),
209 url_request_context_getter_.get(), 213 url_request_context_getter_.get(),
210 blocking_task_runner_.get(), 214 blocking_task_runner_.get(),
211 custom_user_agent_)); 215 custom_user_agent_));
212 sender_->auth_service()->AddObserver(this); 216 sender_->auth_service()->AddObserver(this);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // So, here we use files.list method instead, with setting parents query. 259 // So, here we use files.list method instead, with setting parents query.
256 // After the migration from GData WAPI to Drive API v2, we should clean the 260 // After the migration from GData WAPI to Drive API v2, we should clean the
257 // code up by moving the responsibility to include "parents" in the query 261 // code up by moving the responsibility to include "parents" in the query
258 // to client side. 262 // to client side.
259 // We aren't interested in files in trash in this context, neither. 263 // We aren't interested in files in trash in this context, neither.
260 FilesListRequest* request = new FilesListRequest( 264 FilesListRequest* request = new FilesListRequest(
261 sender_.get(), url_generator_, callback); 265 sender_.get(), url_generator_, callback);
262 request->set_max_results(kMaxNumFilesResourcePerRequest); 266 request->set_max_results(kMaxNumFilesResourcePerRequest);
263 request->set_q(base::StringPrintf( 267 request->set_q(base::StringPrintf(
264 "'%s' in parents and trashed = false", 268 "'%s' in parents and trashed = false",
265 drive::util::EscapeQueryStringValue(directory_resource_id).c_str())); 269 util::EscapeQueryStringValue(directory_resource_id).c_str()));
266 request->set_fields(kFileListFields); 270 request->set_fields(kFileListFields);
267 return sender_->StartRequestWithRetry(request); 271 return sender_->StartRequestWithRetry(request);
268 } 272 }
269 273
270 CancelCallback DriveAPIService::Search( 274 CancelCallback DriveAPIService::Search(
271 const std::string& search_query, 275 const std::string& search_query,
272 const FileListCallback& callback) { 276 const FileListCallback& callback) {
273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
274 DCHECK(!search_query.empty()); 278 DCHECK(!search_query.empty());
275 DCHECK(!callback.is_null()); 279 DCHECK(!callback.is_null());
276 280
277 FilesListRequest* request = new FilesListRequest( 281 FilesListRequest* request = new FilesListRequest(
278 sender_.get(), url_generator_, callback); 282 sender_.get(), url_generator_, callback);
279 request->set_max_results(kMaxNumFilesResourcePerRequestForSearch); 283 request->set_max_results(kMaxNumFilesResourcePerRequestForSearch);
280 request->set_q(drive::util::TranslateQuery(search_query)); 284 request->set_q(util::TranslateQuery(search_query));
281 request->set_fields(kFileListFields); 285 request->set_fields(kFileListFields);
282 return sender_->StartRequestWithRetry(request); 286 return sender_->StartRequestWithRetry(request);
283 } 287 }
284 288
285 CancelCallback DriveAPIService::SearchByTitle( 289 CancelCallback DriveAPIService::SearchByTitle(
286 const std::string& title, 290 const std::string& title,
287 const std::string& directory_resource_id, 291 const std::string& directory_resource_id,
288 const FileListCallback& callback) { 292 const FileListCallback& callback) {
289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
290 DCHECK(!title.empty()); 294 DCHECK(!title.empty());
291 DCHECK(!callback.is_null()); 295 DCHECK(!callback.is_null());
292 296
293 std::string query; 297 std::string query;
294 base::StringAppendF(&query, "title = '%s'", 298 base::StringAppendF(&query, "title = '%s'",
295 drive::util::EscapeQueryStringValue(title).c_str()); 299 util::EscapeQueryStringValue(title).c_str());
296 if (!directory_resource_id.empty()) { 300 if (!directory_resource_id.empty()) {
297 base::StringAppendF( 301 base::StringAppendF(
298 &query, " and '%s' in parents", 302 &query, " and '%s' in parents",
299 drive::util::EscapeQueryStringValue(directory_resource_id).c_str()); 303 util::EscapeQueryStringValue(directory_resource_id).c_str());
300 } 304 }
301 query += " and trashed = false"; 305 query += " and trashed = false";
302 306
303 FilesListRequest* request = new FilesListRequest( 307 FilesListRequest* request = new FilesListRequest(
304 sender_.get(), url_generator_, callback); 308 sender_.get(), url_generator_, callback);
305 request->set_max_results(kMaxNumFilesResourcePerRequest); 309 request->set_max_results(kMaxNumFilesResourcePerRequest);
306 request->set_q(query); 310 request->set_q(query);
307 request->set_fields(kFileListFields); 311 request->set_fields(kFileListFields);
308 return sender_->StartRequestWithRetry(request); 312 return sender_->StartRequestWithRetry(request);
309 } 313 }
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 if (CanSendRequest()) { 757 if (CanSendRequest()) {
754 FOR_EACH_OBSERVER( 758 FOR_EACH_OBSERVER(
755 DriveServiceObserver, observers_, OnReadyToSendRequests()); 759 DriveServiceObserver, observers_, OnReadyToSendRequests());
756 } else if (!HasRefreshToken()) { 760 } else if (!HasRefreshToken()) {
757 FOR_EACH_OBSERVER( 761 FOR_EACH_OBSERVER(
758 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); 762 DriveServiceObserver, observers_, OnRefreshTokenInvalid());
759 } 763 }
760 } 764 }
761 765
762 } // namespace drive 766 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/drive/drive_api_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698