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

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

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 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/fake_drive_service.h" 5 #include "chrome/browser/google_apis/fake_drive_service.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 } 363 }
364 364
365 void FakeDriveService::GetResourceEntry( 365 void FakeDriveService::GetResourceEntry(
366 const std::string& resource_id, 366 const std::string& resource_id,
367 const GetResourceEntryCallback& callback) { 367 const GetResourceEntryCallback& callback) {
368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
369 DCHECK(!callback.is_null()); 369 DCHECK(!callback.is_null());
370 370
371 if (offline_) { 371 if (offline_) {
372 scoped_ptr<ResourceEntry> null; 372 scoped_ptr<ResourceEntry> null;
373 MessageLoop::current()->PostTask( 373 base::MessageLoop::current()->PostTask(
374 FROM_HERE, 374 FROM_HERE,
375 base::Bind(callback, 375 base::Bind(callback,
376 GDATA_NO_CONNECTION, 376 GDATA_NO_CONNECTION,
377 base::Passed(&null))); 377 base::Passed(&null)));
378 return; 378 return;
379 } 379 }
380 380
381 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); 381 base::DictionaryValue* entry = FindEntryByResourceId(resource_id);
382 if (entry) { 382 if (entry) {
383 scoped_ptr<ResourceEntry> resource_entry = 383 scoped_ptr<ResourceEntry> resource_entry =
384 ResourceEntry::CreateFrom(*entry); 384 ResourceEntry::CreateFrom(*entry);
385 MessageLoop::current()->PostTask( 385 base::MessageLoop::current()->PostTask(
386 FROM_HERE, 386 FROM_HERE,
387 base::Bind(callback, HTTP_SUCCESS, base::Passed(&resource_entry))); 387 base::Bind(callback, HTTP_SUCCESS, base::Passed(&resource_entry)));
388 return; 388 return;
389 } 389 }
390 390
391 scoped_ptr<ResourceEntry> null; 391 scoped_ptr<ResourceEntry> null;
392 MessageLoop::current()->PostTask( 392 base::MessageLoop::current()->PostTask(
393 FROM_HERE, 393 FROM_HERE,
394 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); 394 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null)));
395 } 395 }
396 396
397 void FakeDriveService::GetAboutResource( 397 void FakeDriveService::GetAboutResource(
398 const GetAboutResourceCallback& callback) { 398 const GetAboutResourceCallback& callback) {
399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
400 DCHECK(!callback.is_null()); 400 DCHECK(!callback.is_null());
401 401
402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
403 DCHECK(!callback.is_null()); 403 DCHECK(!callback.is_null());
404 404
405 if (offline_) { 405 if (offline_) {
406 scoped_ptr<AboutResource> null; 406 scoped_ptr<AboutResource> null;
407 MessageLoop::current()->PostTask( 407 base::MessageLoop::current()->PostTask(
408 FROM_HERE, 408 FROM_HERE,
409 base::Bind(callback, 409 base::Bind(callback,
410 GDATA_NO_CONNECTION, base::Passed(&null))); 410 GDATA_NO_CONNECTION, base::Passed(&null)));
411 return; 411 return;
412 } 412 }
413 413
414 ++about_resource_load_count_; 414 ++about_resource_load_count_;
415 scoped_ptr<AboutResource> about_resource( 415 scoped_ptr<AboutResource> about_resource(
416 AboutResource::CreateFromAccountMetadata( 416 AboutResource::CreateFromAccountMetadata(
417 *AccountMetadata::CreateFrom(*account_metadata_value_), 417 *AccountMetadata::CreateFrom(*account_metadata_value_),
418 GetRootResourceId())); 418 GetRootResourceId()));
419 // Overwrite the change id. 419 // Overwrite the change id.
420 about_resource->set_largest_change_id(largest_changestamp_); 420 about_resource->set_largest_change_id(largest_changestamp_);
421 MessageLoop::current()->PostTask( 421 base::MessageLoop::current()->PostTask(
422 FROM_HERE, 422 FROM_HERE,
423 base::Bind(callback, 423 base::Bind(callback,
424 HTTP_SUCCESS, base::Passed(&about_resource))); 424 HTTP_SUCCESS, base::Passed(&about_resource)));
425 } 425 }
426 426
427 void FakeDriveService::GetAppList(const GetAppListCallback& callback) { 427 void FakeDriveService::GetAppList(const GetAppListCallback& callback) {
428 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 428 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
429 DCHECK(!callback.is_null()); 429 DCHECK(!callback.is_null());
430 DCHECK(app_info_value_); 430 DCHECK(app_info_value_);
431 431
432 if (offline_) { 432 if (offline_) {
433 scoped_ptr<AppList> null; 433 scoped_ptr<AppList> null;
434 MessageLoop::current()->PostTask( 434 base::MessageLoop::current()->PostTask(
435 FROM_HERE, 435 FROM_HERE,
436 base::Bind(callback, 436 base::Bind(callback,
437 GDATA_NO_CONNECTION, 437 GDATA_NO_CONNECTION,
438 base::Passed(&null))); 438 base::Passed(&null)));
439 return; 439 return;
440 } 440 }
441 441
442 scoped_ptr<AppList> app_list(AppList::CreateFrom(*app_info_value_)); 442 scoped_ptr<AppList> app_list(AppList::CreateFrom(*app_info_value_));
443 MessageLoop::current()->PostTask( 443 base::MessageLoop::current()->PostTask(
444 FROM_HERE, 444 FROM_HERE,
445 base::Bind(callback, HTTP_SUCCESS, base::Passed(&app_list))); 445 base::Bind(callback, HTTP_SUCCESS, base::Passed(&app_list)));
446 } 446 }
447 447
448 void FakeDriveService::DeleteResource( 448 void FakeDriveService::DeleteResource(
449 const std::string& resource_id, 449 const std::string& resource_id,
450 const std::string& etag, 450 const std::string& etag,
451 const EntryActionCallback& callback) { 451 const EntryActionCallback& callback) {
452 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 452 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
453 DCHECK(!callback.is_null()); 453 DCHECK(!callback.is_null());
454 454
455 if (offline_) { 455 if (offline_) {
456 MessageLoop::current()->PostTask( 456 base::MessageLoop::current()->PostTask(
457 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); 457 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION));
458 return; 458 return;
459 } 459 }
460 460
461 base::DictionaryValue* resource_list_dict = NULL; 461 base::DictionaryValue* resource_list_dict = NULL;
462 base::ListValue* entries = NULL; 462 base::ListValue* entries = NULL;
463 // Go through entries and remove the one that matches |resource_id|. 463 // Go through entries and remove the one that matches |resource_id|.
464 if (resource_list_value_->GetAsDictionary(&resource_list_dict) && 464 if (resource_list_value_->GetAsDictionary(&resource_list_dict) &&
465 resource_list_dict->GetList("entry", &entries)) { 465 resource_list_dict->GetList("entry", &entries)) {
466 for (size_t i = 0; i < entries->GetSize(); ++i) { 466 for (size_t i = 0; i < entries->GetSize(); ++i) {
467 base::DictionaryValue* entry = NULL; 467 base::DictionaryValue* entry = NULL;
468 std::string current_resource_id; 468 std::string current_resource_id;
469 if (entries->GetDictionary(i, &entry) && 469 if (entries->GetDictionary(i, &entry) &&
470 entry->GetString("gd$resourceId.$t", &current_resource_id) && 470 entry->GetString("gd$resourceId.$t", &current_resource_id) &&
471 resource_id == current_resource_id) { 471 resource_id == current_resource_id) {
472 entries->Remove(i, NULL); 472 entries->Remove(i, NULL);
473 MessageLoop::current()->PostTask( 473 base::MessageLoop::current()->PostTask(
474 FROM_HERE, base::Bind(callback, HTTP_SUCCESS)); 474 FROM_HERE, base::Bind(callback, HTTP_SUCCESS));
475 return; 475 return;
476 } 476 }
477 } 477 }
478 } 478 }
479 479
480 // TODO(satorux): Add support for returning "deleted" entries in 480 // TODO(satorux): Add support for returning "deleted" entries in
481 // changelists from GetResourceList(). 481 // changelists from GetResourceList().
482 MessageLoop::current()->PostTask( 482 base::MessageLoop::current()->PostTask(
483 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); 483 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND));
484 } 484 }
485 485
486 void FakeDriveService::DownloadFile( 486 void FakeDriveService::DownloadFile(
487 const base::FilePath& virtual_path, 487 const base::FilePath& virtual_path,
488 const base::FilePath& local_cache_path, 488 const base::FilePath& local_cache_path,
489 const GURL& download_url, 489 const GURL& download_url,
490 const DownloadActionCallback& download_action_callback, 490 const DownloadActionCallback& download_action_callback,
491 const GetContentCallback& get_content_callback, 491 const GetContentCallback& get_content_callback,
492 const ProgressCallback& progress_callback) { 492 const ProgressCallback& progress_callback) {
493 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 493 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
494 DCHECK(!download_action_callback.is_null()); 494 DCHECK(!download_action_callback.is_null());
495 495
496 if (offline_) { 496 if (offline_) {
497 MessageLoop::current()->PostTask( 497 base::MessageLoop::current()->PostTask(
498 FROM_HERE, 498 FROM_HERE,
499 base::Bind(download_action_callback, 499 base::Bind(download_action_callback,
500 GDATA_NO_CONNECTION, 500 GDATA_NO_CONNECTION,
501 base::FilePath())); 501 base::FilePath()));
502 return; 502 return;
503 } 503 }
504 504
505 // The field content.src is the URL to download the file. 505 // The field content.src is the URL to download the file.
506 base::DictionaryValue* entry = FindEntryByContentUrl(download_url); 506 base::DictionaryValue* entry = FindEntryByContentUrl(download_url);
507 if (!entry) { 507 if (!entry) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 void FakeDriveService::CopyResource( 568 void FakeDriveService::CopyResource(
569 const std::string& resource_id, 569 const std::string& resource_id,
570 const std::string& in_parent_resource_id, 570 const std::string& in_parent_resource_id,
571 const std::string& new_name, 571 const std::string& new_name,
572 const GetResourceEntryCallback& callback) { 572 const GetResourceEntryCallback& callback) {
573 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 573 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
574 DCHECK(!callback.is_null()); 574 DCHECK(!callback.is_null());
575 575
576 if (offline_) { 576 if (offline_) {
577 scoped_ptr<ResourceEntry> null; 577 scoped_ptr<ResourceEntry> null;
578 MessageLoop::current()->PostTask( 578 base::MessageLoop::current()->PostTask(
579 FROM_HERE, 579 FROM_HERE,
580 base::Bind(callback, 580 base::Bind(callback,
581 GDATA_NO_CONNECTION, 581 GDATA_NO_CONNECTION,
582 base::Passed(&null))); 582 base::Passed(&null)));
583 return; 583 return;
584 } 584 }
585 585
586 const std::string& parent_resource_id = in_parent_resource_id.empty() ? 586 const std::string& parent_resource_id = in_parent_resource_id.empty() ?
587 GetRootResourceId() : in_parent_resource_id; 587 GetRootResourceId() : in_parent_resource_id;
588 588
(...skipping 29 matching lines...) Expand all
618 links->Append(link); 618 links->Append(link);
619 619
620 AddNewChangestamp(copied_entry.get()); 620 AddNewChangestamp(copied_entry.get());
621 621
622 // Parse the new entry. 622 // Parse the new entry.
623 scoped_ptr<ResourceEntry> resource_entry = 623 scoped_ptr<ResourceEntry> resource_entry =
624 ResourceEntry::CreateFrom(*copied_entry); 624 ResourceEntry::CreateFrom(*copied_entry);
625 // Add it to the resource list. 625 // Add it to the resource list.
626 entries->Append(copied_entry.release()); 626 entries->Append(copied_entry.release());
627 627
628 MessageLoop::current()->PostTask( 628 base::MessageLoop::current()->PostTask(
629 FROM_HERE, 629 FROM_HERE,
630 base::Bind(callback, 630 base::Bind(callback,
631 HTTP_SUCCESS, 631 HTTP_SUCCESS,
632 base::Passed(&resource_entry))); 632 base::Passed(&resource_entry)));
633 return; 633 return;
634 } 634 }
635 } 635 }
636 } 636 }
637 637
638 scoped_ptr<ResourceEntry> null; 638 scoped_ptr<ResourceEntry> null;
639 MessageLoop::current()->PostTask( 639 base::MessageLoop::current()->PostTask(
640 FROM_HERE, 640 FROM_HERE,
641 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); 641 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null)));
642 } 642 }
643 643
644 void FakeDriveService::CopyHostedDocument( 644 void FakeDriveService::CopyHostedDocument(
645 const std::string& resource_id, 645 const std::string& resource_id,
646 const std::string& new_name, 646 const std::string& new_name,
647 const GetResourceEntryCallback& callback) { 647 const GetResourceEntryCallback& callback) {
648 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 648 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
649 DCHECK(!callback.is_null()); 649 DCHECK(!callback.is_null());
650 650
651 CopyResource(resource_id, std::string(), new_name, callback); 651 CopyResource(resource_id, std::string(), new_name, callback);
652 } 652 }
653 653
654 void FakeDriveService::RenameResource( 654 void FakeDriveService::RenameResource(
655 const std::string& resource_id, 655 const std::string& resource_id,
656 const std::string& new_name, 656 const std::string& new_name,
657 const EntryActionCallback& callback) { 657 const EntryActionCallback& callback) {
658 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 658 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
659 DCHECK(!callback.is_null()); 659 DCHECK(!callback.is_null());
660 660
661 if (offline_) { 661 if (offline_) {
662 MessageLoop::current()->PostTask( 662 base::MessageLoop::current()->PostTask(
663 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); 663 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION));
664 return; 664 return;
665 } 665 }
666 666
667 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); 667 base::DictionaryValue* entry = FindEntryByResourceId(resource_id);
668 if (entry) { 668 if (entry) {
669 entry->SetString("title.$t", new_name); 669 entry->SetString("title.$t", new_name);
670 AddNewChangestamp(entry); 670 AddNewChangestamp(entry);
671 MessageLoop::current()->PostTask( 671 base::MessageLoop::current()->PostTask(
672 FROM_HERE, base::Bind(callback, HTTP_SUCCESS)); 672 FROM_HERE, base::Bind(callback, HTTP_SUCCESS));
673 return; 673 return;
674 } 674 }
675 675
676 MessageLoop::current()->PostTask( 676 base::MessageLoop::current()->PostTask(
677 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); 677 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND));
678 } 678 }
679 679
680 void FakeDriveService::TouchResource( 680 void FakeDriveService::TouchResource(
681 const std::string& resource_id, 681 const std::string& resource_id,
682 const base::Time& modified_date, 682 const base::Time& modified_date,
683 const base::Time& last_viewed_by_me_date, 683 const base::Time& last_viewed_by_me_date,
684 const GetResourceEntryCallback& callback) { 684 const GetResourceEntryCallback& callback) {
685 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 685 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
686 DCHECK(!modified_date.is_null()); 686 DCHECK(!modified_date.is_null());
687 DCHECK(!last_viewed_by_me_date.is_null()); 687 DCHECK(!last_viewed_by_me_date.is_null());
688 DCHECK(!callback.is_null()); 688 DCHECK(!callback.is_null());
689 689
690 if (offline_) { 690 if (offline_) {
691 MessageLoop::current()->PostTask( 691 base::MessageLoop::current()->PostTask(
692 FROM_HERE, 692 FROM_HERE,
693 base::Bind(callback, GDATA_NO_CONNECTION, 693 base::Bind(callback, GDATA_NO_CONNECTION,
694 base::Passed(scoped_ptr<ResourceEntry>()))); 694 base::Passed(scoped_ptr<ResourceEntry>())));
695 return; 695 return;
696 } 696 }
697 697
698 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); 698 base::DictionaryValue* entry = FindEntryByResourceId(resource_id);
699 if (!entry) { 699 if (!entry) {
700 MessageLoop::current()->PostTask( 700 base::MessageLoop::current()->PostTask(
701 FROM_HERE, 701 FROM_HERE,
702 base::Bind(callback, HTTP_NOT_FOUND, 702 base::Bind(callback, HTTP_NOT_FOUND,
703 base::Passed(scoped_ptr<ResourceEntry>()))); 703 base::Passed(scoped_ptr<ResourceEntry>())));
704 return; 704 return;
705 } 705 }
706 706
707 entry->SetString("updated.$t", 707 entry->SetString("updated.$t",
708 util::FormatTimeAsString(modified_date)); 708 util::FormatTimeAsString(modified_date));
709 entry->SetString("gd$lastViewed.$t", 709 entry->SetString("gd$lastViewed.$t",
710 util::FormatTimeAsString(last_viewed_by_me_date)); 710 util::FormatTimeAsString(last_viewed_by_me_date));
711 AddNewChangestamp(entry); 711 AddNewChangestamp(entry);
712 712
713 scoped_ptr<ResourceEntry> parsed_entry(ResourceEntry::CreateFrom(*entry)); 713 scoped_ptr<ResourceEntry> parsed_entry(ResourceEntry::CreateFrom(*entry));
714 MessageLoop::current()->PostTask( 714 base::MessageLoop::current()->PostTask(
715 FROM_HERE, 715 FROM_HERE,
716 base::Bind(callback, HTTP_SUCCESS, base::Passed(&parsed_entry))); 716 base::Bind(callback, HTTP_SUCCESS, base::Passed(&parsed_entry)));
717 } 717 }
718 718
719 void FakeDriveService::AddResourceToDirectory( 719 void FakeDriveService::AddResourceToDirectory(
720 const std::string& parent_resource_id, 720 const std::string& parent_resource_id,
721 const std::string& resource_id, 721 const std::string& resource_id,
722 const EntryActionCallback& callback) { 722 const EntryActionCallback& callback) {
723 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 723 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
724 DCHECK(!callback.is_null()); 724 DCHECK(!callback.is_null());
725 725
726 if (offline_) { 726 if (offline_) {
727 MessageLoop::current()->PostTask( 727 base::MessageLoop::current()->PostTask(
728 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); 728 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION));
729 return; 729 return;
730 } 730 }
731 731
732 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); 732 base::DictionaryValue* entry = FindEntryByResourceId(resource_id);
733 if (entry) { 733 if (entry) {
734 base::ListValue* links = NULL; 734 base::ListValue* links = NULL;
735 if (!entry->GetList("link", &links)) { 735 if (!entry->GetList("link", &links)) {
736 links = new base::ListValue; 736 links = new base::ListValue;
737 entry->Set("link", links); 737 entry->Set("link", links);
738 } 738 }
739 739
740 // On the real Drive server, resources do not necessary shape a tree 740 // On the real Drive server, resources do not necessary shape a tree
741 // structure. That is, each resource can have multiple parent. 741 // structure. That is, each resource can have multiple parent.
742 // We mimic the behavior here; AddResourceToDirectoy just adds 742 // We mimic the behavior here; AddResourceToDirectoy just adds
743 // one more parent link, not overwriting old links. 743 // one more parent link, not overwriting old links.
744 base::DictionaryValue* link = new base::DictionaryValue; 744 base::DictionaryValue* link = new base::DictionaryValue;
745 link->SetString("rel", "http://schemas.google.com/docs/2007#parent"); 745 link->SetString("rel", "http://schemas.google.com/docs/2007#parent");
746 link->SetString( 746 link->SetString(
747 "href", GetFakeLinkUrl(parent_resource_id).spec()); 747 "href", GetFakeLinkUrl(parent_resource_id).spec());
748 links->Append(link); 748 links->Append(link);
749 749
750 AddNewChangestamp(entry); 750 AddNewChangestamp(entry);
751 MessageLoop::current()->PostTask( 751 base::MessageLoop::current()->PostTask(
752 FROM_HERE, base::Bind(callback, HTTP_SUCCESS)); 752 FROM_HERE, base::Bind(callback, HTTP_SUCCESS));
753 return; 753 return;
754 } 754 }
755 755
756 MessageLoop::current()->PostTask( 756 base::MessageLoop::current()->PostTask(
757 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); 757 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND));
758 } 758 }
759 759
760 void FakeDriveService::RemoveResourceFromDirectory( 760 void FakeDriveService::RemoveResourceFromDirectory(
761 const std::string& parent_resource_id, 761 const std::string& parent_resource_id,
762 const std::string& resource_id, 762 const std::string& resource_id,
763 const EntryActionCallback& callback) { 763 const EntryActionCallback& callback) {
764 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 764 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
765 DCHECK(!callback.is_null()); 765 DCHECK(!callback.is_null());
766 766
767 if (offline_) { 767 if (offline_) {
768 MessageLoop::current()->PostTask( 768 base::MessageLoop::current()->PostTask(
769 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); 769 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION));
770 return; 770 return;
771 } 771 }
772 772
773 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); 773 base::DictionaryValue* entry = FindEntryByResourceId(resource_id);
774 if (entry) { 774 if (entry) {
775 base::ListValue* links = NULL; 775 base::ListValue* links = NULL;
776 if (entry->GetList("link", &links)) { 776 if (entry->GetList("link", &links)) {
777 GURL parent_content_url = GetFakeLinkUrl(parent_resource_id); 777 GURL parent_content_url = GetFakeLinkUrl(parent_resource_id);
778 for (size_t i = 0; i < links->GetSize(); ++i) { 778 for (size_t i = 0; i < links->GetSize(); ++i) {
779 base::DictionaryValue* link = NULL; 779 base::DictionaryValue* link = NULL;
780 std::string rel; 780 std::string rel;
781 std::string href; 781 std::string href;
782 if (links->GetDictionary(i, &link) && 782 if (links->GetDictionary(i, &link) &&
783 link->GetString("rel", &rel) && 783 link->GetString("rel", &rel) &&
784 link->GetString("href", &href) && 784 link->GetString("href", &href) &&
785 rel == "http://schemas.google.com/docs/2007#parent" && 785 rel == "http://schemas.google.com/docs/2007#parent" &&
786 GURL(href) == parent_content_url) { 786 GURL(href) == parent_content_url) {
787 links->Remove(i, NULL); 787 links->Remove(i, NULL);
788 AddNewChangestamp(entry); 788 AddNewChangestamp(entry);
789 MessageLoop::current()->PostTask( 789 base::MessageLoop::current()->PostTask(
790 FROM_HERE, base::Bind(callback, HTTP_SUCCESS)); 790 FROM_HERE, base::Bind(callback, HTTP_SUCCESS));
791 return; 791 return;
792 } 792 }
793 } 793 }
794 } 794 }
795 } 795 }
796 796
797 MessageLoop::current()->PostTask( 797 base::MessageLoop::current()->PostTask(
798 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); 798 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND));
799 } 799 }
800 800
801 void FakeDriveService::AddNewDirectory( 801 void FakeDriveService::AddNewDirectory(
802 const std::string& parent_resource_id, 802 const std::string& parent_resource_id,
803 const std::string& directory_name, 803 const std::string& directory_name,
804 const GetResourceEntryCallback& callback) { 804 const GetResourceEntryCallback& callback) {
805 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 805 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
806 DCHECK(!callback.is_null()); 806 DCHECK(!callback.is_null());
807 807
808 if (offline_) { 808 if (offline_) {
809 scoped_ptr<ResourceEntry> null; 809 scoped_ptr<ResourceEntry> null;
810 MessageLoop::current()->PostTask( 810 base::MessageLoop::current()->PostTask(
811 FROM_HERE, 811 FROM_HERE,
812 base::Bind(callback, 812 base::Bind(callback,
813 GDATA_NO_CONNECTION, 813 GDATA_NO_CONNECTION,
814 base::Passed(&null))); 814 base::Passed(&null)));
815 return; 815 return;
816 } 816 }
817 817
818 const char kContentType[] = "application/atom+xml;type=feed"; 818 const char kContentType[] = "application/atom+xml;type=feed";
819 const base::DictionaryValue* new_entry = AddNewEntry(kContentType, 819 const base::DictionaryValue* new_entry = AddNewEntry(kContentType,
820 "", // content_data 820 "", // content_data
821 parent_resource_id, 821 parent_resource_id,
822 directory_name, 822 directory_name,
823 false, // shared_with_me 823 false, // shared_with_me
824 "folder"); 824 "folder");
825 if (!new_entry) { 825 if (!new_entry) {
826 scoped_ptr<ResourceEntry> null; 826 scoped_ptr<ResourceEntry> null;
827 MessageLoop::current()->PostTask( 827 base::MessageLoop::current()->PostTask(
828 FROM_HERE, 828 FROM_HERE,
829 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); 829 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null)));
830 return; 830 return;
831 } 831 }
832 832
833 scoped_ptr<ResourceEntry> parsed_entry(ResourceEntry::CreateFrom(*new_entry)); 833 scoped_ptr<ResourceEntry> parsed_entry(ResourceEntry::CreateFrom(*new_entry));
834 MessageLoop::current()->PostTask( 834 base::MessageLoop::current()->PostTask(
835 FROM_HERE, 835 FROM_HERE,
836 base::Bind(callback, HTTP_CREATED, base::Passed(&parsed_entry))); 836 base::Bind(callback, HTTP_CREATED, base::Passed(&parsed_entry)));
837 } 837 }
838 838
839 void FakeDriveService::InitiateUploadNewFile( 839 void FakeDriveService::InitiateUploadNewFile(
840 const base::FilePath& drive_file_path, 840 const base::FilePath& drive_file_path,
841 const std::string& content_type, 841 const std::string& content_type,
842 int64 content_length, 842 int64 content_length,
843 const std::string& parent_resource_id, 843 const std::string& parent_resource_id,
844 const std::string& title, 844 const std::string& title,
845 const InitiateUploadCallback& callback) { 845 const InitiateUploadCallback& callback) {
846 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 846 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
847 DCHECK(!callback.is_null()); 847 DCHECK(!callback.is_null());
848 848
849 if (offline_) { 849 if (offline_) {
850 MessageLoop::current()->PostTask( 850 base::MessageLoop::current()->PostTask(
851 FROM_HERE, 851 FROM_HERE,
852 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); 852 base::Bind(callback, GDATA_NO_CONNECTION, GURL()));
853 return; 853 return;
854 } 854 }
855 855
856 // Content length should be zero, as we'll create an empty file first. The 856 // Content length should be zero, as we'll create an empty file first. The
857 // content will be added in ResumeUpload(). 857 // content will be added in ResumeUpload().
858 const base::DictionaryValue* new_entry = AddNewEntry(content_type, 858 const base::DictionaryValue* new_entry = AddNewEntry(content_type,
859 "", // content_data 859 "", // content_data
860 parent_resource_id, 860 parent_resource_id,
861 title, 861 title,
862 false, // shared_with_me 862 false, // shared_with_me
863 "file"); 863 "file");
864 if (!new_entry) { 864 if (!new_entry) {
865 MessageLoop::current()->PostTask( 865 base::MessageLoop::current()->PostTask(
866 FROM_HERE, 866 FROM_HERE,
867 base::Bind(callback, HTTP_NOT_FOUND, GURL())); 867 base::Bind(callback, HTTP_NOT_FOUND, GURL()));
868 return; 868 return;
869 } 869 }
870 const GURL upload_url = GetUploadUrl(*new_entry); 870 const GURL upload_url = GetUploadUrl(*new_entry);
871 DCHECK(upload_url.is_valid()); 871 DCHECK(upload_url.is_valid());
872 872
873 MessageLoop::current()->PostTask( 873 base::MessageLoop::current()->PostTask(
874 FROM_HERE, 874 FROM_HERE,
875 base::Bind(callback, HTTP_SUCCESS, 875 base::Bind(callback, HTTP_SUCCESS,
876 net::AppendQueryParameter(upload_url, "mode", "newfile"))); 876 net::AppendQueryParameter(upload_url, "mode", "newfile")));
877 877
878 } 878 }
879 879
880 void FakeDriveService::InitiateUploadExistingFile( 880 void FakeDriveService::InitiateUploadExistingFile(
881 const base::FilePath& drive_file_path, 881 const base::FilePath& drive_file_path,
882 const std::string& content_type, 882 const std::string& content_type,
883 int64 content_length, 883 int64 content_length,
884 const std::string& resource_id, 884 const std::string& resource_id,
885 const std::string& etag, 885 const std::string& etag,
886 const InitiateUploadCallback& callback) { 886 const InitiateUploadCallback& callback) {
887 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 887 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
888 DCHECK(!callback.is_null()); 888 DCHECK(!callback.is_null());
889 889
890 if (offline_) { 890 if (offline_) {
891 MessageLoop::current()->PostTask( 891 base::MessageLoop::current()->PostTask(
892 FROM_HERE, 892 FROM_HERE,
893 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); 893 base::Bind(callback, GDATA_NO_CONNECTION, GURL()));
894 return; 894 return;
895 } 895 }
896 896
897 DictionaryValue* entry = FindEntryByResourceId(resource_id); 897 DictionaryValue* entry = FindEntryByResourceId(resource_id);
898 if (!entry) { 898 if (!entry) {
899 MessageLoop::current()->PostTask( 899 base::MessageLoop::current()->PostTask(
900 FROM_HERE, 900 FROM_HERE,
901 base::Bind(callback, HTTP_NOT_FOUND, GURL())); 901 base::Bind(callback, HTTP_NOT_FOUND, GURL()));
902 return; 902 return;
903 } 903 }
904 904
905 std::string entry_etag; 905 std::string entry_etag;
906 entry->GetString("gd$etag", &entry_etag); 906 entry->GetString("gd$etag", &entry_etag);
907 if (!etag.empty() && etag != entry_etag) { 907 if (!etag.empty() && etag != entry_etag) {
908 MessageLoop::current()->PostTask( 908 base::MessageLoop::current()->PostTask(
909 FROM_HERE, 909 FROM_HERE,
910 base::Bind(callback, HTTP_PRECONDITION, GURL())); 910 base::Bind(callback, HTTP_PRECONDITION, GURL()));
911 return; 911 return;
912 } 912 }
913 entry->SetString("docs$size.$t", "0"); 913 entry->SetString("docs$size.$t", "0");
914 914
915 const GURL upload_url = GetUploadUrl(*entry); 915 const GURL upload_url = GetUploadUrl(*entry);
916 DCHECK(upload_url.is_valid()); 916 DCHECK(upload_url.is_valid());
917 917
918 MessageLoop::current()->PostTask( 918 base::MessageLoop::current()->PostTask(
919 FROM_HERE, 919 FROM_HERE,
920 base::Bind(callback, HTTP_SUCCESS, 920 base::Bind(callback, HTTP_SUCCESS,
921 net::AppendQueryParameter(upload_url, "mode", "existing"))); 921 net::AppendQueryParameter(upload_url, "mode", "existing")));
922 } 922 }
923 923
924 void FakeDriveService::GetUploadStatus( 924 void FakeDriveService::GetUploadStatus(
925 const base::FilePath& drive_file_path, 925 const base::FilePath& drive_file_path,
926 const GURL& upload_url, 926 const GURL& upload_url,
927 int64 content_length, 927 int64 content_length,
928 const UploadRangeCallback& callback) { 928 const UploadRangeCallback& callback) {
(...skipping 10 matching lines...) Expand all
939 const std::string& content_type, 939 const std::string& content_type,
940 const base::FilePath& local_file_path, 940 const base::FilePath& local_file_path,
941 const UploadRangeCallback& callback, 941 const UploadRangeCallback& callback,
942 const ProgressCallback& progress_callback) { 942 const ProgressCallback& progress_callback) {
943 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 943 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
944 DCHECK(!callback.is_null()); 944 DCHECK(!callback.is_null());
945 945
946 scoped_ptr<ResourceEntry> result_entry; 946 scoped_ptr<ResourceEntry> result_entry;
947 947
948 if (offline_) { 948 if (offline_) {
949 MessageLoop::current()->PostTask( 949 base::MessageLoop::current()->PostTask(
950 FROM_HERE, 950 FROM_HERE,
951 base::Bind(callback, 951 base::Bind(callback,
952 UploadRangeResponse(GDATA_NO_CONNECTION, 952 UploadRangeResponse(GDATA_NO_CONNECTION,
953 start_position, 953 start_position,
954 end_position), 954 end_position),
955 base::Passed(&result_entry))); 955 base::Passed(&result_entry)));
956 return; 956 return;
957 } 957 }
958 958
959 DictionaryValue* entry = NULL; 959 DictionaryValue* entry = NULL;
960 entry = FindEntryByUploadUrl(RemoveQueryParameter(upload_url)); 960 entry = FindEntryByUploadUrl(RemoveQueryParameter(upload_url));
961 if (!entry) { 961 if (!entry) {
962 MessageLoop::current()->PostTask( 962 base::MessageLoop::current()->PostTask(
963 FROM_HERE, 963 FROM_HERE,
964 base::Bind(callback, 964 base::Bind(callback,
965 UploadRangeResponse(HTTP_NOT_FOUND, 965 UploadRangeResponse(HTTP_NOT_FOUND,
966 start_position, 966 start_position,
967 end_position), 967 end_position),
968 base::Passed(&result_entry))); 968 base::Passed(&result_entry)));
969 return; 969 return;
970 } 970 }
971 971
972 // Chunks are required to be sent in such a ways that they fill from the start 972 // Chunks are required to be sent in such a ways that they fill from the start
973 // of the not-yet-uploaded part with no gaps nor overlaps. 973 // of the not-yet-uploaded part with no gaps nor overlaps.
974 std::string current_size_string; 974 std::string current_size_string;
975 int64 current_size; 975 int64 current_size;
976 if (!entry->GetString("docs$size.$t", &current_size_string) || 976 if (!entry->GetString("docs$size.$t", &current_size_string) ||
977 !base::StringToInt64(current_size_string, &current_size) || 977 !base::StringToInt64(current_size_string, &current_size) ||
978 current_size != start_position) { 978 current_size != start_position) {
979 MessageLoop::current()->PostTask( 979 base::MessageLoop::current()->PostTask(
980 FROM_HERE, 980 FROM_HERE,
981 base::Bind(callback, 981 base::Bind(callback,
982 UploadRangeResponse(HTTP_BAD_REQUEST, 982 UploadRangeResponse(HTTP_BAD_REQUEST,
983 start_position, 983 start_position,
984 end_position), 984 end_position),
985 base::Passed(&result_entry))); 985 base::Passed(&result_entry)));
986 return; 986 return;
987 } 987 }
988 988
989 entry->SetString("docs$size.$t", base::Int64ToString(end_position)); 989 entry->SetString("docs$size.$t", base::Int64ToString(end_position));
990 990
991 if (!progress_callback.is_null()) { 991 if (!progress_callback.is_null()) {
992 // In the real GDataWapi/Drive DriveService, progress is reported in 992 // In the real GDataWapi/Drive DriveService, progress is reported in
993 // nondeterministic timing. In this fake implementation, we choose to call 993 // nondeterministic timing. In this fake implementation, we choose to call
994 // it twice per one ResumeUpload. This is for making sure that client code 994 // it twice per one ResumeUpload. This is for making sure that client code
995 // works fine even if the callback is invoked more than once; it is the 995 // works fine even if the callback is invoked more than once; it is the
996 // crucial difference of the progress callback from others. 996 // crucial difference of the progress callback from others.
997 // Note that progress is notified in the relative offset in each chunk. 997 // Note that progress is notified in the relative offset in each chunk.
998 const int64 chunk_size = end_position - start_position; 998 const int64 chunk_size = end_position - start_position;
999 MessageLoop::current()->PostTask( 999 base::MessageLoop::current()->PostTask(
1000 FROM_HERE, base::Bind(progress_callback, chunk_size / 2, chunk_size)); 1000 FROM_HERE, base::Bind(progress_callback, chunk_size / 2, chunk_size));
1001 MessageLoop::current()->PostTask( 1001 base::MessageLoop::current()->PostTask(
1002 FROM_HERE, base::Bind(progress_callback, chunk_size, chunk_size)); 1002 FROM_HERE, base::Bind(progress_callback, chunk_size, chunk_size));
1003 } 1003 }
1004 1004
1005 if (content_length != end_position) { 1005 if (content_length != end_position) {
1006 MessageLoop::current()->PostTask( 1006 base::MessageLoop::current()->PostTask(
1007 FROM_HERE, 1007 FROM_HERE,
1008 base::Bind(callback, 1008 base::Bind(callback,
1009 UploadRangeResponse(HTTP_RESUME_INCOMPLETE, 1009 UploadRangeResponse(HTTP_RESUME_INCOMPLETE,
1010 start_position, 1010 start_position,
1011 end_position), 1011 end_position),
1012 base::Passed(&result_entry))); 1012 base::Passed(&result_entry)));
1013 return; 1013 return;
1014 } 1014 }
1015 1015
1016 AddNewChangestamp(entry); 1016 AddNewChangestamp(entry);
1017 result_entry = ResourceEntry::CreateFrom(*entry).Pass(); 1017 result_entry = ResourceEntry::CreateFrom(*entry).Pass();
1018 1018
1019 std::string upload_mode; 1019 std::string upload_mode;
1020 bool upload_mode_found = 1020 bool upload_mode_found =
1021 net::GetValueForKeyInQuery(upload_url, "mode", &upload_mode); 1021 net::GetValueForKeyInQuery(upload_url, "mode", &upload_mode);
1022 DCHECK(upload_mode_found && 1022 DCHECK(upload_mode_found &&
1023 (upload_mode == "newfile" || upload_mode == "existing")); 1023 (upload_mode == "newfile" || upload_mode == "existing"));
1024 1024
1025 GDataErrorCode return_code = 1025 GDataErrorCode return_code =
1026 upload_mode == "newfile" ? HTTP_CREATED : HTTP_SUCCESS; 1026 upload_mode == "newfile" ? HTTP_CREATED : HTTP_SUCCESS;
1027 1027
1028 MessageLoop::current()->PostTask( 1028 base::MessageLoop::current()->PostTask(
1029 FROM_HERE, 1029 FROM_HERE,
1030 base::Bind(callback, 1030 base::Bind(callback,
1031 UploadRangeResponse(return_code, 1031 UploadRangeResponse(return_code,
1032 start_position, 1032 start_position,
1033 end_position), 1033 end_position),
1034 base::Passed(&result_entry))); 1034 base::Passed(&result_entry)));
1035 } 1035 }
1036 1036
1037 void FakeDriveService::AuthorizeApp(const std::string& resource_id, 1037 void FakeDriveService::AuthorizeApp(const std::string& resource_id,
1038 const std::string& app_id, 1038 const std::string& app_id,
1039 const AuthorizeAppCallback& callback) { 1039 const AuthorizeAppCallback& callback) {
1040 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1040 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1041 DCHECK(!callback.is_null()); 1041 DCHECK(!callback.is_null());
1042 } 1042 }
1043 1043
1044 void FakeDriveService::AddNewFile(const std::string& content_type, 1044 void FakeDriveService::AddNewFile(const std::string& content_type,
1045 const std::string& content_data, 1045 const std::string& content_data,
1046 const std::string& parent_resource_id, 1046 const std::string& parent_resource_id,
1047 const std::string& title, 1047 const std::string& title,
1048 bool shared_with_me, 1048 bool shared_with_me,
1049 const GetResourceEntryCallback& callback) { 1049 const GetResourceEntryCallback& callback) {
1050 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1050 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1051 DCHECK(!callback.is_null()); 1051 DCHECK(!callback.is_null());
1052 1052
1053 if (offline_) { 1053 if (offline_) {
1054 scoped_ptr<ResourceEntry> null; 1054 scoped_ptr<ResourceEntry> null;
1055 MessageLoop::current()->PostTask( 1055 base::MessageLoop::current()->PostTask(
1056 FROM_HERE, 1056 FROM_HERE,
1057 base::Bind(callback, 1057 base::Bind(callback,
1058 GDATA_NO_CONNECTION, 1058 GDATA_NO_CONNECTION,
1059 base::Passed(&null))); 1059 base::Passed(&null)));
1060 return; 1060 return;
1061 } 1061 }
1062 1062
1063 // Prepare "kind" for hosted documents. This only supports Google Document. 1063 // Prepare "kind" for hosted documents. This only supports Google Document.
1064 std::string entry_kind; 1064 std::string entry_kind;
1065 if (content_type == "application/vnd.google-apps.document") 1065 if (content_type == "application/vnd.google-apps.document")
1066 entry_kind = "document"; 1066 entry_kind = "document";
1067 else 1067 else
1068 entry_kind = "file"; 1068 entry_kind = "file";
1069 1069
1070 const base::DictionaryValue* new_entry = AddNewEntry(content_type, 1070 const base::DictionaryValue* new_entry = AddNewEntry(content_type,
1071 content_data, 1071 content_data,
1072 parent_resource_id, 1072 parent_resource_id,
1073 title, 1073 title,
1074 shared_with_me, 1074 shared_with_me,
1075 entry_kind); 1075 entry_kind);
1076 if (!new_entry) { 1076 if (!new_entry) {
1077 scoped_ptr<ResourceEntry> null; 1077 scoped_ptr<ResourceEntry> null;
1078 MessageLoop::current()->PostTask( 1078 base::MessageLoop::current()->PostTask(
1079 FROM_HERE, 1079 FROM_HERE,
1080 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); 1080 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null)));
1081 return; 1081 return;
1082 } 1082 }
1083 1083
1084 scoped_ptr<ResourceEntry> parsed_entry( 1084 scoped_ptr<ResourceEntry> parsed_entry(
1085 ResourceEntry::CreateFrom(*new_entry)); 1085 ResourceEntry::CreateFrom(*new_entry));
1086 MessageLoop::current()->PostTask( 1086 base::MessageLoop::current()->PostTask(
1087 FROM_HERE, 1087 FROM_HERE,
1088 base::Bind(callback, HTTP_CREATED, base::Passed(&parsed_entry))); 1088 base::Bind(callback, HTTP_CREATED, base::Passed(&parsed_entry)));
1089 } 1089 }
1090 1090
1091 void FakeDriveService::SetLastModifiedTime( 1091 void FakeDriveService::SetLastModifiedTime(
1092 const std::string& resource_id, 1092 const std::string& resource_id,
1093 const base::Time& last_modified_time, 1093 const base::Time& last_modified_time,
1094 const GetResourceEntryCallback& callback) { 1094 const GetResourceEntryCallback& callback) {
1095 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1095 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1096 DCHECK(!callback.is_null()); 1096 DCHECK(!callback.is_null());
1097 1097
1098 if (offline_) { 1098 if (offline_) {
1099 scoped_ptr<ResourceEntry> null; 1099 scoped_ptr<ResourceEntry> null;
1100 MessageLoop::current()->PostTask( 1100 base::MessageLoop::current()->PostTask(
1101 FROM_HERE, 1101 FROM_HERE,
1102 base::Bind(callback, 1102 base::Bind(callback,
1103 GDATA_NO_CONNECTION, 1103 GDATA_NO_CONNECTION,
1104 base::Passed(&null))); 1104 base::Passed(&null)));
1105 return; 1105 return;
1106 } 1106 }
1107 1107
1108 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); 1108 base::DictionaryValue* entry = FindEntryByResourceId(resource_id);
1109 if (!entry) { 1109 if (!entry) {
1110 scoped_ptr<ResourceEntry> null; 1110 scoped_ptr<ResourceEntry> null;
1111 MessageLoop::current()->PostTask( 1111 base::MessageLoop::current()->PostTask(
1112 FROM_HERE, 1112 FROM_HERE,
1113 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); 1113 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null)));
1114 return; 1114 return;
1115 } 1115 }
1116 1116
1117 if (last_modified_time.is_null()) { 1117 if (last_modified_time.is_null()) {
1118 entry->Remove("updated.$t", NULL); 1118 entry->Remove("updated.$t", NULL);
1119 } else { 1119 } else {
1120 entry->SetString("updated.$t", 1120 entry->SetString("updated.$t",
1121 util::FormatTimeAsString(last_modified_time)); 1121 util::FormatTimeAsString(last_modified_time));
1122 } 1122 }
1123 1123
1124 scoped_ptr<ResourceEntry> parsed_entry( 1124 scoped_ptr<ResourceEntry> parsed_entry(
1125 ResourceEntry::CreateFrom(*entry)); 1125 ResourceEntry::CreateFrom(*entry));
1126 MessageLoop::current()->PostTask( 1126 base::MessageLoop::current()->PostTask(
1127 FROM_HERE, 1127 FROM_HERE,
1128 base::Bind(callback, HTTP_SUCCESS, base::Passed(&parsed_entry))); 1128 base::Bind(callback, HTTP_SUCCESS, base::Passed(&parsed_entry)));
1129 } 1129 }
1130 1130
1131 base::DictionaryValue* FakeDriveService::FindEntryByResourceId( 1131 base::DictionaryValue* FakeDriveService::FindEntryByResourceId(
1132 const std::string& resource_id) { 1132 const std::string& resource_id) {
1133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1134 1134
1135 base::DictionaryValue* resource_list_dict = NULL; 1135 base::DictionaryValue* resource_list_dict = NULL;
1136 base::ListValue* entries = NULL; 1136 base::ListValue* entries = NULL;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 void FakeDriveService::GetResourceListInternal( 1322 void FakeDriveService::GetResourceListInternal(
1323 int64 start_changestamp, 1323 int64 start_changestamp,
1324 const std::string& search_query, 1324 const std::string& search_query,
1325 const std::string& directory_resource_id, 1325 const std::string& directory_resource_id,
1326 int start_offset, 1326 int start_offset,
1327 int max_results, 1327 int max_results,
1328 int* load_counter, 1328 int* load_counter,
1329 const GetResourceListCallback& callback) { 1329 const GetResourceListCallback& callback) {
1330 if (offline_) { 1330 if (offline_) {
1331 scoped_ptr<ResourceList> null; 1331 scoped_ptr<ResourceList> null;
1332 MessageLoop::current()->PostTask( 1332 base::MessageLoop::current()->PostTask(
1333 FROM_HERE, 1333 FROM_HERE,
1334 base::Bind(callback, 1334 base::Bind(callback,
1335 GDATA_NO_CONNECTION, 1335 GDATA_NO_CONNECTION,
1336 base::Passed(&null))); 1336 base::Passed(&null)));
1337 return; 1337 return;
1338 } 1338 }
1339 1339
1340 scoped_ptr<ResourceList> resource_list = 1340 scoped_ptr<ResourceList> resource_list =
1341 ResourceList::CreateFrom(*resource_list_value_); 1341 ResourceList::CreateFrom(*resource_list_value_);
1342 1342
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 } 1422 }
1423 1423
1424 Link* link = new Link; 1424 Link* link = new Link;
1425 link->set_type(Link::LINK_NEXT); 1425 link->set_type(Link::LINK_NEXT);
1426 link->set_href(next_url); 1426 link->set_href(next_url);
1427 resource_list->mutable_links()->push_back(link); 1427 resource_list->mutable_links()->push_back(link);
1428 } 1428 }
1429 1429
1430 if (load_counter) 1430 if (load_counter)
1431 *load_counter += 1; 1431 *load_counter += 1;
1432 MessageLoop::current()->PostTask( 1432 base::MessageLoop::current()->PostTask(
1433 FROM_HERE, 1433 FROM_HERE,
1434 base::Bind(callback, 1434 base::Bind(callback,
1435 HTTP_SUCCESS, 1435 HTTP_SUCCESS,
1436 base::Passed(&resource_list))); 1436 base::Passed(&resource_list)));
1437 } 1437 }
1438 1438
1439 } // namespace google_apis 1439 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/drive_uploader_unittest.cc ('k') | chrome/browser/google_apis/fake_drive_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698