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

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

Issue 1218773003: Implement a DRIVE_REQUEST_TOO_LARGE backoff. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 5 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/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"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "chrome/browser/drive/drive_api_util.h" 12 #include "chrome/browser/drive/drive_api_util.h"
13 #include "google_apis/drive/auth_service.h" 13 #include "google_apis/drive/auth_service.h"
14 #include "google_apis/drive/base_requests.h" 14 #include "google_apis/drive/base_requests.h"
15 #include "google_apis/drive/drive_api_parser.h" 15 #include "google_apis/drive/drive_api_parser.h"
16 #include "google_apis/drive/drive_api_requests.h" 16 #include "google_apis/drive/drive_api_requests.h"
17 #include "google_apis/drive/files_list_request_runner.h"
17 #include "google_apis/drive/request_sender.h" 18 #include "google_apis/drive/request_sender.h"
18 #include "google_apis/google_api_keys.h" 19 #include "google_apis/google_api_keys.h"
19 #include "net/url_request/url_request_context_getter.h" 20 #include "net/url_request/url_request_context_getter.h"
20 21
21 using google_apis::AboutResourceCallback; 22 using google_apis::AboutResourceCallback;
22 using google_apis::AppList; 23 using google_apis::AppList;
23 using google_apis::AppListCallback; 24 using google_apis::AppListCallback;
24 using google_apis::AuthStatusCallback; 25 using google_apis::AuthStatusCallback;
25 using google_apis::AuthorizeAppCallback; 26 using google_apis::AuthorizeAppCallback;
26 using google_apis::CancelCallback; 27 using google_apis::CancelCallback;
27 using google_apis::ChangeList; 28 using google_apis::ChangeList;
28 using google_apis::ChangeListCallback; 29 using google_apis::ChangeListCallback;
29 using google_apis::DownloadActionCallback; 30 using google_apis::DownloadActionCallback;
30 using google_apis::EntryActionCallback; 31 using google_apis::EntryActionCallback;
31 using google_apis::FileList; 32 using google_apis::FileList;
32 using google_apis::FileListCallback; 33 using google_apis::FileListCallback;
33 using google_apis::FileResource; 34 using google_apis::FileResource;
34 using google_apis::FileResourceCallback; 35 using google_apis::FileResourceCallback;
35 using google_apis::DRIVE_OTHER_ERROR; 36 using google_apis::DRIVE_OTHER_ERROR;
36 using google_apis::DRIVE_PARSE_ERROR; 37 using google_apis::DRIVE_PARSE_ERROR;
37 using google_apis::DriveApiErrorCode; 38 using google_apis::DriveApiErrorCode;
38 using google_apis::GetContentCallback; 39 using google_apis::GetContentCallback;
39 using google_apis::GetShareUrlCallback; 40 using google_apis::GetShareUrlCallback;
40 using google_apis::HTTP_NOT_IMPLEMENTED; 41 using google_apis::HTTP_NOT_IMPLEMENTED;
41 using google_apis::HTTP_SUCCESS; 42 using google_apis::HTTP_SUCCESS;
42 using google_apis::InitiateUploadCallback; 43 using google_apis::InitiateUploadCallback;
43 using google_apis::ProgressCallback; 44 using google_apis::ProgressCallback;
44 using google_apis::RequestSender; 45 using google_apis::RequestSender;
46 using google_apis::FilesListRequestRunner;
45 using google_apis::UploadRangeResponse; 47 using google_apis::UploadRangeResponse;
46 using google_apis::drive::AboutGetRequest; 48 using google_apis::drive::AboutGetRequest;
47 using google_apis::drive::AppsListRequest; 49 using google_apis::drive::AppsListRequest;
48 using google_apis::drive::ChangesListRequest; 50 using google_apis::drive::ChangesListRequest;
49 using google_apis::drive::ChangesListNextPageRequest; 51 using google_apis::drive::ChangesListNextPageRequest;
50 using google_apis::drive::ChildrenDeleteRequest; 52 using google_apis::drive::ChildrenDeleteRequest;
51 using google_apis::drive::ChildrenInsertRequest; 53 using google_apis::drive::ChildrenInsertRequest;
52 using google_apis::drive::DownloadFileRequest; 54 using google_apis::drive::DownloadFileRequest;
53 using google_apis::drive::FilesCopyRequest; 55 using google_apis::drive::FilesCopyRequest;
54 using google_apis::drive::FilesGetRequest; 56 using google_apis::drive::FilesGetRequest;
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 277
276 sender_.reset(new RequestSender( 278 sender_.reset(new RequestSender(
277 new google_apis::AuthService(oauth2_token_service_, 279 new google_apis::AuthService(oauth2_token_service_,
278 account_id, 280 account_id,
279 url_request_context_getter_.get(), 281 url_request_context_getter_.get(),
280 scopes), 282 scopes),
281 url_request_context_getter_.get(), 283 url_request_context_getter_.get(),
282 blocking_task_runner_.get(), 284 blocking_task_runner_.get(),
283 custom_user_agent_)); 285 custom_user_agent_));
284 sender_->auth_service()->AddObserver(this); 286 sender_->auth_service()->AddObserver(this);
287
288 files_list_request_runner_.reset(
289 new FilesListRequestRunner(sender_.get(), url_generator_));
285 } 290 }
286 291
287 void DriveAPIService::AddObserver(DriveServiceObserver* observer) { 292 void DriveAPIService::AddObserver(DriveServiceObserver* observer) {
288 observers_.AddObserver(observer); 293 observers_.AddObserver(observer);
289 } 294 }
290 295
291 void DriveAPIService::RemoveObserver(DriveServiceObserver* observer) { 296 void DriveAPIService::RemoveObserver(DriveServiceObserver* observer) {
292 observers_.RemoveObserver(observer); 297 observers_.RemoveObserver(observer);
293 } 298 }
294 299
(...skipping 10 matching lines...) Expand all
305 CancelCallback DriveAPIService::GetAllFileList( 310 CancelCallback DriveAPIService::GetAllFileList(
306 const FileListCallback& callback) { 311 const FileListCallback& callback) {
307 DCHECK(thread_checker_.CalledOnValidThread()); 312 DCHECK(thread_checker_.CalledOnValidThread());
308 DCHECK(!callback.is_null()); 313 DCHECK(!callback.is_null());
309 314
310 FilesListRequest* request = new FilesListRequest( 315 FilesListRequest* request = new FilesListRequest(
311 sender_.get(), url_generator_, callback); 316 sender_.get(), url_generator_, callback);
312 request->set_max_results(kMaxNumFilesResourcePerRequest); 317 request->set_max_results(kMaxNumFilesResourcePerRequest);
313 request->set_q("trashed = false"); // Exclude trashed files. 318 request->set_q("trashed = false"); // Exclude trashed files.
314 request->set_fields(kFileListFields); 319 request->set_fields(kFileListFields);
315 return sender_->StartRequestWithRetry(request); 320 return sender_->StartRequestWithAuthRetry(request);
316 } 321 }
317 322
318 CancelCallback DriveAPIService::GetFileListInDirectory( 323 CancelCallback DriveAPIService::GetFileListInDirectory(
319 const std::string& directory_resource_id, 324 const std::string& directory_resource_id,
320 const FileListCallback& callback) { 325 const FileListCallback& callback) {
321 DCHECK(thread_checker_.CalledOnValidThread()); 326 DCHECK(thread_checker_.CalledOnValidThread());
322 DCHECK(!directory_resource_id.empty()); 327 DCHECK(!directory_resource_id.empty());
323 DCHECK(!callback.is_null()); 328 DCHECK(!callback.is_null());
324 329
325 // Because children.list method on Drive API v2 returns only the list of 330 // Because children.list method on Drive API v2 returns only the list of
326 // children's references, but we need all file resource list. 331 // children's references, but we need all file resource list.
327 // So, here we use files.list method instead, with setting parents query. 332 // So, here we use files.list method instead, with setting parents query.
328 // After the migration from GData WAPI to Drive API v2, we should clean the 333 // After the migration from GData WAPI to Drive API v2, we should clean the
329 // code up by moving the responsibility to include "parents" in the query 334 // code up by moving the responsibility to include "parents" in the query
330 // to client side. 335 // to client side.
331 // We aren't interested in files in trash in this context, neither. 336 // We aren't interested in files in trash in this context, neither.
332 FilesListRequest* request = new FilesListRequest( 337 return files_list_request_runner_->CreateAndStartWithSizeBackoff(
333 sender_.get(), url_generator_, callback); 338 kMaxNumFilesResourcePerRequest,
334 request->set_max_results(kMaxNumFilesResourcePerRequest); 339 base::StringPrintf(
335 request->set_q(base::StringPrintf( 340 "'%s' in parents and trashed = false",
336 "'%s' in parents and trashed = false", 341 util::EscapeQueryStringValue(directory_resource_id).c_str()),
337 util::EscapeQueryStringValue(directory_resource_id).c_str())); 342 kFileListFields, callback);
338 request->set_fields(kFileListFields);
339 return sender_->StartRequestWithRetry(request);
340 } 343 }
341 344
342 CancelCallback DriveAPIService::Search( 345 CancelCallback DriveAPIService::Search(
343 const std::string& search_query, 346 const std::string& search_query,
344 const FileListCallback& callback) { 347 const FileListCallback& callback) {
345 DCHECK(thread_checker_.CalledOnValidThread()); 348 DCHECK(thread_checker_.CalledOnValidThread());
346 DCHECK(!search_query.empty()); 349 DCHECK(!search_query.empty());
347 DCHECK(!callback.is_null()); 350 DCHECK(!callback.is_null());
348 351
349 FilesListRequest* request = new FilesListRequest( 352 return files_list_request_runner_->CreateAndStartWithSizeBackoff(
350 sender_.get(), url_generator_, callback); 353 kMaxNumFilesResourcePerRequestForSearch,
351 request->set_max_results(kMaxNumFilesResourcePerRequestForSearch); 354 util::TranslateQuery(search_query), kFileListFields, callback);
352 request->set_q(util::TranslateQuery(search_query));
353 request->set_fields(kFileListFields);
354 return sender_->StartRequestWithRetry(request);
355 } 355 }
356 356
357 CancelCallback DriveAPIService::SearchByTitle( 357 CancelCallback DriveAPIService::SearchByTitle(
358 const std::string& title, 358 const std::string& title,
359 const std::string& directory_resource_id, 359 const std::string& directory_resource_id,
360 const FileListCallback& callback) { 360 const FileListCallback& callback) {
361 DCHECK(thread_checker_.CalledOnValidThread()); 361 DCHECK(thread_checker_.CalledOnValidThread());
362 DCHECK(!title.empty()); 362 DCHECK(!title.empty());
363 DCHECK(!callback.is_null()); 363 DCHECK(!callback.is_null());
364 364
365 std::string query; 365 std::string query;
366 base::StringAppendF(&query, "title = '%s'", 366 base::StringAppendF(&query, "title = '%s'",
367 util::EscapeQueryStringValue(title).c_str()); 367 util::EscapeQueryStringValue(title).c_str());
368 if (!directory_resource_id.empty()) { 368 if (!directory_resource_id.empty()) {
369 base::StringAppendF( 369 base::StringAppendF(
370 &query, " and '%s' in parents", 370 &query, " and '%s' in parents",
371 util::EscapeQueryStringValue(directory_resource_id).c_str()); 371 util::EscapeQueryStringValue(directory_resource_id).c_str());
372 } 372 }
373 query += " and trashed = false"; 373 query += " and trashed = false";
374 374
375 FilesListRequest* request = new FilesListRequest( 375 FilesListRequest* request = new FilesListRequest(
376 sender_.get(), url_generator_, callback); 376 sender_.get(), url_generator_, callback);
377 request->set_max_results(kMaxNumFilesResourcePerRequest); 377 request->set_max_results(kMaxNumFilesResourcePerRequest);
378 request->set_q(query); 378 request->set_q(query);
379 request->set_fields(kFileListFields); 379 request->set_fields(kFileListFields);
380 return sender_->StartRequestWithRetry(request); 380 return sender_->StartRequestWithAuthRetry(request);
381 } 381 }
382 382
383 CancelCallback DriveAPIService::GetChangeList( 383 CancelCallback DriveAPIService::GetChangeList(
384 int64 start_changestamp, 384 int64 start_changestamp,
385 const ChangeListCallback& callback) { 385 const ChangeListCallback& callback) {
386 DCHECK(thread_checker_.CalledOnValidThread()); 386 DCHECK(thread_checker_.CalledOnValidThread());
387 DCHECK(!callback.is_null()); 387 DCHECK(!callback.is_null());
388 388
389 ChangesListRequest* request = new ChangesListRequest( 389 ChangesListRequest* request = new ChangesListRequest(
390 sender_.get(), url_generator_, callback); 390 sender_.get(), url_generator_, callback);
391 request->set_max_results(kMaxNumFilesResourcePerRequest); 391 request->set_max_results(kMaxNumFilesResourcePerRequest);
392 request->set_start_change_id(start_changestamp); 392 request->set_start_change_id(start_changestamp);
393 request->set_fields(kChangeListFields); 393 request->set_fields(kChangeListFields);
394 return sender_->StartRequestWithRetry(request); 394 return sender_->StartRequestWithAuthRetry(request);
395 } 395 }
396 396
397 CancelCallback DriveAPIService::GetRemainingChangeList( 397 CancelCallback DriveAPIService::GetRemainingChangeList(
398 const GURL& next_link, 398 const GURL& next_link,
399 const ChangeListCallback& callback) { 399 const ChangeListCallback& callback) {
400 DCHECK(thread_checker_.CalledOnValidThread()); 400 DCHECK(thread_checker_.CalledOnValidThread());
401 DCHECK(!next_link.is_empty()); 401 DCHECK(!next_link.is_empty());
402 DCHECK(!callback.is_null()); 402 DCHECK(!callback.is_null());
403 403
404 ChangesListNextPageRequest* request = new ChangesListNextPageRequest( 404 ChangesListNextPageRequest* request = new ChangesListNextPageRequest(
405 sender_.get(), callback); 405 sender_.get(), callback);
406 request->set_next_link(next_link); 406 request->set_next_link(next_link);
407 request->set_fields(kChangeListFields); 407 request->set_fields(kChangeListFields);
408 return sender_->StartRequestWithRetry(request); 408 return sender_->StartRequestWithAuthRetry(request);
409 } 409 }
410 410
411 CancelCallback DriveAPIService::GetRemainingFileList( 411 CancelCallback DriveAPIService::GetRemainingFileList(
412 const GURL& next_link, 412 const GURL& next_link,
413 const FileListCallback& callback) { 413 const FileListCallback& callback) {
414 DCHECK(thread_checker_.CalledOnValidThread()); 414 DCHECK(thread_checker_.CalledOnValidThread());
415 DCHECK(!next_link.is_empty()); 415 DCHECK(!next_link.is_empty());
416 DCHECK(!callback.is_null()); 416 DCHECK(!callback.is_null());
417 417
418 FilesListNextPageRequest* request = new FilesListNextPageRequest( 418 FilesListNextPageRequest* request = new FilesListNextPageRequest(
419 sender_.get(), callback); 419 sender_.get(), callback);
420 request->set_next_link(next_link); 420 request->set_next_link(next_link);
421 request->set_fields(kFileListFields); 421 request->set_fields(kFileListFields);
422 return sender_->StartRequestWithRetry(request); 422 return sender_->StartRequestWithAuthRetry(request);
423 } 423 }
424 424
425 CancelCallback DriveAPIService::GetFileResource( 425 CancelCallback DriveAPIService::GetFileResource(
426 const std::string& resource_id, 426 const std::string& resource_id,
427 const FileResourceCallback& callback) { 427 const FileResourceCallback& callback) {
428 DCHECK(thread_checker_.CalledOnValidThread()); 428 DCHECK(thread_checker_.CalledOnValidThread());
429 DCHECK(!callback.is_null()); 429 DCHECK(!callback.is_null());
430 430
431 FilesGetRequest* request = new FilesGetRequest( 431 FilesGetRequest* request = new FilesGetRequest(
432 sender_.get(), url_generator_, google_apis::IsGoogleChromeAPIKeyUsed(), 432 sender_.get(), url_generator_, google_apis::IsGoogleChromeAPIKeyUsed(),
433 callback); 433 callback);
434 request->set_file_id(resource_id); 434 request->set_file_id(resource_id);
435 request->set_fields(kFileResourceFields); 435 request->set_fields(kFileResourceFields);
436 return sender_->StartRequestWithRetry(request); 436 return sender_->StartRequestWithAuthRetry(request);
437 } 437 }
438 438
439 CancelCallback DriveAPIService::GetShareUrl( 439 CancelCallback DriveAPIService::GetShareUrl(
440 const std::string& resource_id, 440 const std::string& resource_id,
441 const GURL& embed_origin, 441 const GURL& embed_origin,
442 const GetShareUrlCallback& callback) { 442 const GetShareUrlCallback& callback) {
443 DCHECK(thread_checker_.CalledOnValidThread()); 443 DCHECK(thread_checker_.CalledOnValidThread());
444 DCHECK(!callback.is_null()); 444 DCHECK(!callback.is_null());
445 445
446 if (!google_apis::IsGoogleChromeAPIKeyUsed()) { 446 if (!google_apis::IsGoogleChromeAPIKeyUsed()) {
447 LOG(ERROR) << "Only the official build of Chrome OS can open share dialogs " 447 LOG(ERROR) << "Only the official build of Chrome OS can open share dialogs "
448 << "from the file manager."; 448 << "from the file manager.";
449 } 449 }
450 450
451 FilesGetRequest* request = new FilesGetRequest( 451 FilesGetRequest* request = new FilesGetRequest(
452 sender_.get(), url_generator_, google_apis::IsGoogleChromeAPIKeyUsed(), 452 sender_.get(), url_generator_, google_apis::IsGoogleChromeAPIKeyUsed(),
453 base::Bind(&ExtractShareUrlAndRun, callback)); 453 base::Bind(&ExtractShareUrlAndRun, callback));
454 request->set_file_id(resource_id); 454 request->set_file_id(resource_id);
455 request->set_fields(kFileResourceShareLinkFields); 455 request->set_fields(kFileResourceShareLinkFields);
456 request->set_embed_origin(embed_origin); 456 request->set_embed_origin(embed_origin);
457 return sender_->StartRequestWithRetry(request); 457 return sender_->StartRequestWithAuthRetry(request);
458 } 458 }
459 459
460 CancelCallback DriveAPIService::GetAboutResource( 460 CancelCallback DriveAPIService::GetAboutResource(
461 const AboutResourceCallback& callback) { 461 const AboutResourceCallback& callback) {
462 DCHECK(thread_checker_.CalledOnValidThread()); 462 DCHECK(thread_checker_.CalledOnValidThread());
463 DCHECK(!callback.is_null()); 463 DCHECK(!callback.is_null());
464 464
465 AboutGetRequest* request = 465 AboutGetRequest* request =
466 new AboutGetRequest(sender_.get(), url_generator_, callback); 466 new AboutGetRequest(sender_.get(), url_generator_, callback);
467 request->set_fields(kAboutResourceFields); 467 request->set_fields(kAboutResourceFields);
468 return sender_->StartRequestWithRetry(request); 468 return sender_->StartRequestWithAuthRetry(request);
469 } 469 }
470 470
471 CancelCallback DriveAPIService::GetAppList(const AppListCallback& callback) { 471 CancelCallback DriveAPIService::GetAppList(const AppListCallback& callback) {
472 DCHECK(thread_checker_.CalledOnValidThread()); 472 DCHECK(thread_checker_.CalledOnValidThread());
473 DCHECK(!callback.is_null()); 473 DCHECK(!callback.is_null());
474 474
475 return sender_->StartRequestWithRetry( 475 return sender_->StartRequestWithAuthRetry(
476 new AppsListRequest(sender_.get(), url_generator_, 476 new AppsListRequest(sender_.get(), url_generator_,
477 google_apis::IsGoogleChromeAPIKeyUsed(), 477 google_apis::IsGoogleChromeAPIKeyUsed(), callback));
478 callback));
479 } 478 }
480 479
481 CancelCallback DriveAPIService::DownloadFile( 480 CancelCallback DriveAPIService::DownloadFile(
482 const base::FilePath& local_cache_path, 481 const base::FilePath& local_cache_path,
483 const std::string& resource_id, 482 const std::string& resource_id,
484 const DownloadActionCallback& download_action_callback, 483 const DownloadActionCallback& download_action_callback,
485 const GetContentCallback& get_content_callback, 484 const GetContentCallback& get_content_callback,
486 const ProgressCallback& progress_callback) { 485 const ProgressCallback& progress_callback) {
487 DCHECK(thread_checker_.CalledOnValidThread()); 486 DCHECK(thread_checker_.CalledOnValidThread());
488 DCHECK(!download_action_callback.is_null()); 487 DCHECK(!download_action_callback.is_null());
489 // get_content_callback may be null. 488 // get_content_callback may be null.
490 489
491 return sender_->StartRequestWithRetry( 490 return sender_->StartRequestWithAuthRetry(new DownloadFileRequest(
492 new DownloadFileRequest(sender_.get(), 491 sender_.get(), url_generator_, resource_id, local_cache_path,
493 url_generator_, 492 download_action_callback, get_content_callback, progress_callback));
494 resource_id,
495 local_cache_path,
496 download_action_callback,
497 get_content_callback,
498 progress_callback));
499 } 493 }
500 494
501 CancelCallback DriveAPIService::DeleteResource( 495 CancelCallback DriveAPIService::DeleteResource(
502 const std::string& resource_id, 496 const std::string& resource_id,
503 const std::string& etag, 497 const std::string& etag,
504 const EntryActionCallback& callback) { 498 const EntryActionCallback& callback) {
505 DCHECK(thread_checker_.CalledOnValidThread()); 499 DCHECK(thread_checker_.CalledOnValidThread());
506 DCHECK(!callback.is_null()); 500 DCHECK(!callback.is_null());
507 501
508 FilesDeleteRequest* request = new FilesDeleteRequest( 502 FilesDeleteRequest* request = new FilesDeleteRequest(
509 sender_.get(), url_generator_, callback); 503 sender_.get(), url_generator_, callback);
510 request->set_file_id(resource_id); 504 request->set_file_id(resource_id);
511 request->set_etag(etag); 505 request->set_etag(etag);
512 return sender_->StartRequestWithRetry(request); 506 return sender_->StartRequestWithAuthRetry(request);
513 } 507 }
514 508
515 CancelCallback DriveAPIService::TrashResource( 509 CancelCallback DriveAPIService::TrashResource(
516 const std::string& resource_id, 510 const std::string& resource_id,
517 const EntryActionCallback& callback) { 511 const EntryActionCallback& callback) {
518 DCHECK(thread_checker_.CalledOnValidThread()); 512 DCHECK(thread_checker_.CalledOnValidThread());
519 DCHECK(!callback.is_null()); 513 DCHECK(!callback.is_null());
520 514
521 FilesTrashRequest* request = new FilesTrashRequest( 515 FilesTrashRequest* request = new FilesTrashRequest(
522 sender_.get(), url_generator_, 516 sender_.get(), url_generator_,
523 base::Bind(&EntryActionCallbackAdapter, callback)); 517 base::Bind(&EntryActionCallbackAdapter, callback));
524 request->set_file_id(resource_id); 518 request->set_file_id(resource_id);
525 request->set_fields(kFileResourceFields); 519 request->set_fields(kFileResourceFields);
526 return sender_->StartRequestWithRetry(request); 520 return sender_->StartRequestWithAuthRetry(request);
527 } 521 }
528 522
529 CancelCallback DriveAPIService::AddNewDirectory( 523 CancelCallback DriveAPIService::AddNewDirectory(
530 const std::string& parent_resource_id, 524 const std::string& parent_resource_id,
531 const std::string& directory_title, 525 const std::string& directory_title,
532 const AddNewDirectoryOptions& options, 526 const AddNewDirectoryOptions& options,
533 const FileResourceCallback& callback) { 527 const FileResourceCallback& callback) {
534 DCHECK(thread_checker_.CalledOnValidThread()); 528 DCHECK(thread_checker_.CalledOnValidThread());
535 DCHECK(!callback.is_null()); 529 DCHECK(!callback.is_null());
536 530
537 FilesInsertRequest* request = new FilesInsertRequest( 531 FilesInsertRequest* request = new FilesInsertRequest(
538 sender_.get(), url_generator_, callback); 532 sender_.get(), url_generator_, callback);
539 request->set_last_viewed_by_me_date(options.last_viewed_by_me_date); 533 request->set_last_viewed_by_me_date(options.last_viewed_by_me_date);
540 request->set_mime_type(kFolderMimeType); 534 request->set_mime_type(kFolderMimeType);
541 request->set_modified_date(options.modified_date); 535 request->set_modified_date(options.modified_date);
542 request->add_parent(parent_resource_id); 536 request->add_parent(parent_resource_id);
543 request->set_title(directory_title); 537 request->set_title(directory_title);
544 request->set_properties(options.properties); 538 request->set_properties(options.properties);
545 request->set_fields(kFileResourceFields); 539 request->set_fields(kFileResourceFields);
546 return sender_->StartRequestWithRetry(request); 540 return sender_->StartRequestWithAuthRetry(request);
547 } 541 }
548 542
549 CancelCallback DriveAPIService::CopyResource( 543 CancelCallback DriveAPIService::CopyResource(
550 const std::string& resource_id, 544 const std::string& resource_id,
551 const std::string& parent_resource_id, 545 const std::string& parent_resource_id,
552 const std::string& new_title, 546 const std::string& new_title,
553 const base::Time& last_modified, 547 const base::Time& last_modified,
554 const FileResourceCallback& callback) { 548 const FileResourceCallback& callback) {
555 DCHECK(thread_checker_.CalledOnValidThread()); 549 DCHECK(thread_checker_.CalledOnValidThread());
556 DCHECK(!callback.is_null()); 550 DCHECK(!callback.is_null());
557 551
558 FilesCopyRequest* request = new FilesCopyRequest( 552 FilesCopyRequest* request = new FilesCopyRequest(
559 sender_.get(), url_generator_, callback); 553 sender_.get(), url_generator_, callback);
560 request->set_file_id(resource_id); 554 request->set_file_id(resource_id);
561 request->add_parent(parent_resource_id); 555 request->add_parent(parent_resource_id);
562 request->set_title(new_title); 556 request->set_title(new_title);
563 request->set_modified_date(last_modified); 557 request->set_modified_date(last_modified);
564 request->set_fields(kFileResourceFields); 558 request->set_fields(kFileResourceFields);
565 return sender_->StartRequestWithRetry(request); 559 return sender_->StartRequestWithAuthRetry(request);
566 } 560 }
567 561
568 CancelCallback DriveAPIService::UpdateResource( 562 CancelCallback DriveAPIService::UpdateResource(
569 const std::string& resource_id, 563 const std::string& resource_id,
570 const std::string& parent_resource_id, 564 const std::string& parent_resource_id,
571 const std::string& new_title, 565 const std::string& new_title,
572 const base::Time& last_modified, 566 const base::Time& last_modified,
573 const base::Time& last_viewed_by_me, 567 const base::Time& last_viewed_by_me,
574 const google_apis::drive::Properties& properties, 568 const google_apis::drive::Properties& properties,
575 const FileResourceCallback& callback) { 569 const FileResourceCallback& callback) {
(...skipping 12 matching lines...) Expand all
588 request->set_modified_date(last_modified); 582 request->set_modified_date(last_modified);
589 } 583 }
590 if (!last_viewed_by_me.is_null()) { 584 if (!last_viewed_by_me.is_null()) {
591 // Need to set updateViewedDate to false, otherwise the lastViewedByMeDate 585 // Need to set updateViewedDate to false, otherwise the lastViewedByMeDate
592 // will be set to the request time (not the specified time via request). 586 // will be set to the request time (not the specified time via request).
593 request->set_update_viewed_date(false); 587 request->set_update_viewed_date(false);
594 request->set_last_viewed_by_me_date(last_viewed_by_me); 588 request->set_last_viewed_by_me_date(last_viewed_by_me);
595 } 589 }
596 request->set_fields(kFileResourceFields); 590 request->set_fields(kFileResourceFields);
597 request->set_properties(properties); 591 request->set_properties(properties);
598 return sender_->StartRequestWithRetry(request); 592 return sender_->StartRequestWithAuthRetry(request);
599 } 593 }
600 594
601 CancelCallback DriveAPIService::AddResourceToDirectory( 595 CancelCallback DriveAPIService::AddResourceToDirectory(
602 const std::string& parent_resource_id, 596 const std::string& parent_resource_id,
603 const std::string& resource_id, 597 const std::string& resource_id,
604 const EntryActionCallback& callback) { 598 const EntryActionCallback& callback) {
605 DCHECK(thread_checker_.CalledOnValidThread()); 599 DCHECK(thread_checker_.CalledOnValidThread());
606 DCHECK(!callback.is_null()); 600 DCHECK(!callback.is_null());
607 601
608 ChildrenInsertRequest* request = 602 ChildrenInsertRequest* request =
609 new ChildrenInsertRequest(sender_.get(), url_generator_, callback); 603 new ChildrenInsertRequest(sender_.get(), url_generator_, callback);
610 request->set_folder_id(parent_resource_id); 604 request->set_folder_id(parent_resource_id);
611 request->set_id(resource_id); 605 request->set_id(resource_id);
612 return sender_->StartRequestWithRetry(request); 606 return sender_->StartRequestWithAuthRetry(request);
613 } 607 }
614 608
615 CancelCallback DriveAPIService::RemoveResourceFromDirectory( 609 CancelCallback DriveAPIService::RemoveResourceFromDirectory(
616 const std::string& parent_resource_id, 610 const std::string& parent_resource_id,
617 const std::string& resource_id, 611 const std::string& resource_id,
618 const EntryActionCallback& callback) { 612 const EntryActionCallback& callback) {
619 DCHECK(thread_checker_.CalledOnValidThread()); 613 DCHECK(thread_checker_.CalledOnValidThread());
620 DCHECK(!callback.is_null()); 614 DCHECK(!callback.is_null());
621 615
622 ChildrenDeleteRequest* request = 616 ChildrenDeleteRequest* request =
623 new ChildrenDeleteRequest(sender_.get(), url_generator_, callback); 617 new ChildrenDeleteRequest(sender_.get(), url_generator_, callback);
624 request->set_child_id(resource_id); 618 request->set_child_id(resource_id);
625 request->set_folder_id(parent_resource_id); 619 request->set_folder_id(parent_resource_id);
626 return sender_->StartRequestWithRetry(request); 620 return sender_->StartRequestWithAuthRetry(request);
627 } 621 }
628 622
629 CancelCallback DriveAPIService::InitiateUploadNewFile( 623 CancelCallback DriveAPIService::InitiateUploadNewFile(
630 const std::string& content_type, 624 const std::string& content_type,
631 int64 content_length, 625 int64 content_length,
632 const std::string& parent_resource_id, 626 const std::string& parent_resource_id,
633 const std::string& title, 627 const std::string& title,
634 const UploadNewFileOptions& options, 628 const UploadNewFileOptions& options,
635 const InitiateUploadCallback& callback) { 629 const InitiateUploadCallback& callback) {
636 DCHECK(thread_checker_.CalledOnValidThread()); 630 DCHECK(thread_checker_.CalledOnValidThread());
637 DCHECK(!callback.is_null()); 631 DCHECK(!callback.is_null());
638 632
639 InitiateUploadNewFileRequest* request = 633 InitiateUploadNewFileRequest* request =
640 new InitiateUploadNewFileRequest(sender_.get(), 634 new InitiateUploadNewFileRequest(sender_.get(),
641 url_generator_, 635 url_generator_,
642 content_type, 636 content_type,
643 content_length, 637 content_length,
644 parent_resource_id, 638 parent_resource_id,
645 title, 639 title,
646 callback); 640 callback);
647 request->set_modified_date(options.modified_date); 641 request->set_modified_date(options.modified_date);
648 request->set_last_viewed_by_me_date(options.last_viewed_by_me_date); 642 request->set_last_viewed_by_me_date(options.last_viewed_by_me_date);
649 request->set_properties(options.properties); 643 request->set_properties(options.properties);
650 return sender_->StartRequestWithRetry(request); 644 return sender_->StartRequestWithAuthRetry(request);
651 } 645 }
652 646
653 CancelCallback DriveAPIService::InitiateUploadExistingFile( 647 CancelCallback DriveAPIService::InitiateUploadExistingFile(
654 const std::string& content_type, 648 const std::string& content_type,
655 int64 content_length, 649 int64 content_length,
656 const std::string& resource_id, 650 const std::string& resource_id,
657 const UploadExistingFileOptions& options, 651 const UploadExistingFileOptions& options,
658 const InitiateUploadCallback& callback) { 652 const InitiateUploadCallback& callback) {
659 DCHECK(thread_checker_.CalledOnValidThread()); 653 DCHECK(thread_checker_.CalledOnValidThread());
660 DCHECK(!callback.is_null()); 654 DCHECK(!callback.is_null());
661 655
662 InitiateUploadExistingFileRequest* request = 656 InitiateUploadExistingFileRequest* request =
663 new InitiateUploadExistingFileRequest(sender_.get(), 657 new InitiateUploadExistingFileRequest(sender_.get(),
664 url_generator_, 658 url_generator_,
665 content_type, 659 content_type,
666 content_length, 660 content_length,
667 resource_id, 661 resource_id,
668 options.etag, 662 options.etag,
669 callback); 663 callback);
670 request->set_parent_resource_id(options.parent_resource_id); 664 request->set_parent_resource_id(options.parent_resource_id);
671 request->set_title(options.title); 665 request->set_title(options.title);
672 request->set_modified_date(options.modified_date); 666 request->set_modified_date(options.modified_date);
673 request->set_last_viewed_by_me_date(options.last_viewed_by_me_date); 667 request->set_last_viewed_by_me_date(options.last_viewed_by_me_date);
674 request->set_properties(options.properties); 668 request->set_properties(options.properties);
675 return sender_->StartRequestWithRetry(request); 669 return sender_->StartRequestWithAuthRetry(request);
676 } 670 }
677 671
678 CancelCallback DriveAPIService::ResumeUpload( 672 CancelCallback DriveAPIService::ResumeUpload(
679 const GURL& upload_url, 673 const GURL& upload_url,
680 int64 start_position, 674 int64 start_position,
681 int64 end_position, 675 int64 end_position,
682 int64 content_length, 676 int64 content_length,
683 const std::string& content_type, 677 const std::string& content_type,
684 const base::FilePath& local_file_path, 678 const base::FilePath& local_file_path,
685 const UploadRangeCallback& callback, 679 const UploadRangeCallback& callback,
686 const ProgressCallback& progress_callback) { 680 const ProgressCallback& progress_callback) {
687 DCHECK(thread_checker_.CalledOnValidThread()); 681 DCHECK(thread_checker_.CalledOnValidThread());
688 DCHECK(!callback.is_null()); 682 DCHECK(!callback.is_null());
689 683
690 return sender_->StartRequestWithRetry( 684 return sender_->StartRequestWithAuthRetry(new ResumeUploadRequest(
691 new ResumeUploadRequest( 685 sender_.get(), upload_url, start_position, end_position, content_length,
692 sender_.get(), 686 content_type, local_file_path, callback, progress_callback));
693 upload_url,
694 start_position,
695 end_position,
696 content_length,
697 content_type,
698 local_file_path,
699 callback,
700 progress_callback));
701 } 687 }
702 688
703 CancelCallback DriveAPIService::GetUploadStatus( 689 CancelCallback DriveAPIService::GetUploadStatus(
704 const GURL& upload_url, 690 const GURL& upload_url,
705 int64 content_length, 691 int64 content_length,
706 const UploadRangeCallback& callback) { 692 const UploadRangeCallback& callback) {
707 DCHECK(thread_checker_.CalledOnValidThread()); 693 DCHECK(thread_checker_.CalledOnValidThread());
708 DCHECK(!callback.is_null()); 694 DCHECK(!callback.is_null());
709 695
710 return sender_->StartRequestWithRetry(new GetUploadStatusRequest( 696 return sender_->StartRequestWithAuthRetry(new GetUploadStatusRequest(
711 sender_.get(), 697 sender_.get(), upload_url, content_length, callback));
712 upload_url,
713 content_length,
714 callback));
715 } 698 }
716 699
717 CancelCallback DriveAPIService::MultipartUploadNewFile( 700 CancelCallback DriveAPIService::MultipartUploadNewFile(
718 const std::string& content_type, 701 const std::string& content_type,
719 int64 content_length, 702 int64 content_length,
720 const std::string& parent_resource_id, 703 const std::string& parent_resource_id,
721 const std::string& title, 704 const std::string& title,
722 const base::FilePath& local_file_path, 705 const base::FilePath& local_file_path,
723 const drive::UploadNewFileOptions& options, 706 const drive::UploadNewFileOptions& options,
724 const FileResourceCallback& callback, 707 const FileResourceCallback& callback,
725 const google_apis::ProgressCallback& progress_callback) { 708 const google_apis::ProgressCallback& progress_callback) {
726 DCHECK(thread_checker_.CalledOnValidThread()); 709 DCHECK(thread_checker_.CalledOnValidThread());
727 DCHECK(!callback.is_null()); 710 DCHECK(!callback.is_null());
728 711
729 return sender_->StartRequestWithRetry( 712 return sender_->StartRequestWithAuthRetry(
730 new google_apis::drive::SingleBatchableDelegateRequest( 713 new google_apis::drive::SingleBatchableDelegateRequest(
731 sender_.get(), 714 sender_.get(),
732 new google_apis::drive::MultipartUploadNewFileDelegate( 715 new google_apis::drive::MultipartUploadNewFileDelegate(
733 sender_->blocking_task_runner(), title, parent_resource_id, 716 sender_->blocking_task_runner(), title, parent_resource_id,
734 content_type, content_length, options.modified_date, 717 content_type, content_length, options.modified_date,
735 options.last_viewed_by_me_date, local_file_path, 718 options.last_viewed_by_me_date, local_file_path,
736 options.properties, url_generator_, callback, 719 options.properties, url_generator_, callback,
737 progress_callback))); 720 progress_callback)));
738 } 721 }
739 722
740 CancelCallback DriveAPIService::MultipartUploadExistingFile( 723 CancelCallback DriveAPIService::MultipartUploadExistingFile(
741 const std::string& content_type, 724 const std::string& content_type,
742 int64 content_length, 725 int64 content_length,
743 const std::string& resource_id, 726 const std::string& resource_id,
744 const base::FilePath& local_file_path, 727 const base::FilePath& local_file_path,
745 const drive::UploadExistingFileOptions& options, 728 const drive::UploadExistingFileOptions& options,
746 const FileResourceCallback& callback, 729 const FileResourceCallback& callback,
747 const google_apis::ProgressCallback& progress_callback) { 730 const google_apis::ProgressCallback& progress_callback) {
748 DCHECK(thread_checker_.CalledOnValidThread()); 731 DCHECK(thread_checker_.CalledOnValidThread());
749 DCHECK(!callback.is_null()); 732 DCHECK(!callback.is_null());
750 733
751 return sender_->StartRequestWithRetry( 734 return sender_->StartRequestWithAuthRetry(
752 new google_apis::drive::SingleBatchableDelegateRequest( 735 new google_apis::drive::SingleBatchableDelegateRequest(
753 sender_.get(), 736 sender_.get(),
754 new google_apis::drive::MultipartUploadExistingFileDelegate( 737 new google_apis::drive::MultipartUploadExistingFileDelegate(
755 sender_->blocking_task_runner(), options.title, resource_id, 738 sender_->blocking_task_runner(), options.title, resource_id,
756 options.parent_resource_id, content_type, content_length, 739 options.parent_resource_id, content_type, content_length,
757 options.modified_date, options.last_viewed_by_me_date, 740 options.modified_date, options.last_viewed_by_me_date,
758 local_file_path, options.etag, options.properties, url_generator_, 741 local_file_path, options.etag, options.properties, url_generator_,
759 callback, progress_callback))); 742 callback, progress_callback)));
760 } 743 }
761 744
(...skipping 10 matching lines...) Expand all
772 // the app can open if it was authorized by other means (from whitelisted 755 // the app can open if it was authorized by other means (from whitelisted
773 // clients or drive.google.com web UI.) 756 // clients or drive.google.com web UI.)
774 if (google_apis::IsGoogleChromeAPIKeyUsed()) { 757 if (google_apis::IsGoogleChromeAPIKeyUsed()) {
775 google_apis::drive::FilesAuthorizeRequest* request = 758 google_apis::drive::FilesAuthorizeRequest* request =
776 new google_apis::drive::FilesAuthorizeRequest( 759 new google_apis::drive::FilesAuthorizeRequest(
777 sender_.get(), url_generator_, 760 sender_.get(), url_generator_,
778 base::Bind(&ExtractOpenUrlAndRun, app_id, callback)); 761 base::Bind(&ExtractOpenUrlAndRun, app_id, callback));
779 request->set_app_id(app_id); 762 request->set_app_id(app_id);
780 request->set_file_id(resource_id); 763 request->set_file_id(resource_id);
781 request->set_fields(kFileResourceOpenWithLinksFields); 764 request->set_fields(kFileResourceOpenWithLinksFields);
782 return sender_->StartRequestWithRetry(request); 765 return sender_->StartRequestWithAuthRetry(request);
783 } else { 766 } else {
784 FilesGetRequest* request = new FilesGetRequest( 767 FilesGetRequest* request = new FilesGetRequest(
785 sender_.get(), url_generator_, google_apis::IsGoogleChromeAPIKeyUsed(), 768 sender_.get(), url_generator_, google_apis::IsGoogleChromeAPIKeyUsed(),
786 base::Bind(&ExtractOpenUrlAndRun, app_id, callback)); 769 base::Bind(&ExtractOpenUrlAndRun, app_id, callback));
787 request->set_file_id(resource_id); 770 request->set_file_id(resource_id);
788 request->set_fields(kFileResourceOpenWithLinksFields); 771 request->set_fields(kFileResourceOpenWithLinksFields);
789 return sender_->StartRequestWithRetry(request); 772 return sender_->StartRequestWithAuthRetry(request);
790 } 773 }
791 } 774 }
792 775
793 CancelCallback DriveAPIService::UninstallApp( 776 CancelCallback DriveAPIService::UninstallApp(
794 const std::string& app_id, 777 const std::string& app_id,
795 const google_apis::EntryActionCallback& callback) { 778 const google_apis::EntryActionCallback& callback) {
796 DCHECK(thread_checker_.CalledOnValidThread()); 779 DCHECK(thread_checker_.CalledOnValidThread());
797 DCHECK(!callback.is_null()); 780 DCHECK(!callback.is_null());
798 781
799 google_apis::drive::AppsDeleteRequest* request = 782 google_apis::drive::AppsDeleteRequest* request =
800 new google_apis::drive::AppsDeleteRequest(sender_.get(), url_generator_, 783 new google_apis::drive::AppsDeleteRequest(sender_.get(), url_generator_,
801 callback); 784 callback);
802 request->set_app_id(app_id); 785 request->set_app_id(app_id);
803 return sender_->StartRequestWithRetry(request); 786 return sender_->StartRequestWithAuthRetry(request);
804 } 787 }
805 788
806 google_apis::CancelCallback DriveAPIService::AddPermission( 789 google_apis::CancelCallback DriveAPIService::AddPermission(
807 const std::string& resource_id, 790 const std::string& resource_id,
808 const std::string& email, 791 const std::string& email,
809 google_apis::drive::PermissionRole role, 792 google_apis::drive::PermissionRole role,
810 const google_apis::EntryActionCallback& callback) { 793 const google_apis::EntryActionCallback& callback) {
811 DCHECK(thread_checker_.CalledOnValidThread()); 794 DCHECK(thread_checker_.CalledOnValidThread());
812 DCHECK(!callback.is_null()); 795 DCHECK(!callback.is_null());
813 796
814 google_apis::drive::PermissionsInsertRequest* request = 797 google_apis::drive::PermissionsInsertRequest* request =
815 new google_apis::drive::PermissionsInsertRequest(sender_.get(), 798 new google_apis::drive::PermissionsInsertRequest(sender_.get(),
816 url_generator_, 799 url_generator_,
817 callback); 800 callback);
818 request->set_id(resource_id); 801 request->set_id(resource_id);
819 request->set_role(role); 802 request->set_role(role);
820 request->set_type(google_apis::drive::PERMISSION_TYPE_USER); 803 request->set_type(google_apis::drive::PERMISSION_TYPE_USER);
821 request->set_value(email); 804 request->set_value(email);
822 return sender_->StartRequestWithRetry(request); 805 return sender_->StartRequestWithAuthRetry(request);
823 } 806 }
824 807
825 bool DriveAPIService::HasAccessToken() const { 808 bool DriveAPIService::HasAccessToken() const {
826 DCHECK(thread_checker_.CalledOnValidThread()); 809 DCHECK(thread_checker_.CalledOnValidThread());
827 return sender_->auth_service()->HasAccessToken(); 810 return sender_->auth_service()->HasAccessToken();
828 } 811 }
829 812
830 void DriveAPIService::RequestAccessToken(const AuthStatusCallback& callback) { 813 void DriveAPIService::RequestAccessToken(const AuthStatusCallback& callback) {
831 DCHECK(thread_checker_.CalledOnValidThread()); 814 DCHECK(thread_checker_.CalledOnValidThread());
832 DCHECK(!callback.is_null()); 815 DCHECK(!callback.is_null());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 new google_apis::drive::BatchUploadRequest(sender_.get(), 856 new google_apis::drive::BatchUploadRequest(sender_.get(),
874 url_generator_)); 857 url_generator_));
875 const base::WeakPtr<google_apis::drive::BatchUploadRequest> weak_ref = 858 const base::WeakPtr<google_apis::drive::BatchUploadRequest> weak_ref =
876 request->GetWeakPtrAsBatchUploadRequest(); 859 request->GetWeakPtrAsBatchUploadRequest();
877 // Have sender_ manage the lifetime of the request. 860 // Have sender_ manage the lifetime of the request.
878 // TODO(hirono): Currently we need to pass the ownership of the request to 861 // TODO(hirono): Currently we need to pass the ownership of the request to
879 // RequestSender before the request is committed because the request has a 862 // RequestSender before the request is committed because the request has a
880 // reference to RequestSender and we should ensure to delete the request when 863 // reference to RequestSender and we should ensure to delete the request when
881 // the sender is deleted. Resolve the circulating dependency and fix it. 864 // the sender is deleted. Resolve the circulating dependency and fix it.
882 const google_apis::CancelCallback callback = 865 const google_apis::CancelCallback callback =
883 sender_->StartRequestWithRetry(request.release()); 866 sender_->StartRequestWithAuthRetry(request.release());
884 return make_scoped_ptr<BatchRequestConfiguratorInterface>( 867 return make_scoped_ptr<BatchRequestConfiguratorInterface>(
885 new BatchRequestConfigurator(weak_ref, sender_->blocking_task_runner(), 868 new BatchRequestConfigurator(weak_ref, sender_->blocking_task_runner(),
886 url_generator_, callback)); 869 url_generator_, callback));
887 } 870 }
888 871
889 } // namespace drive 872 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698