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

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

Issue 881403003: Rename gdata_errorcode.h to drive_api_error_codes.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typos in BUILD.gn Created 5 years, 10 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/fake_drive_service.h" 5 #include "chrome/browser/drive/fake_drive_service.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/json/json_string_value_serializer.h" 10 #include "base/json/json_string_value_serializer.h"
(...skipping 22 matching lines...) Expand all
33 using google_apis::CancelCallback; 33 using google_apis::CancelCallback;
34 using google_apis::ChangeList; 34 using google_apis::ChangeList;
35 using google_apis::ChangeListCallback; 35 using google_apis::ChangeListCallback;
36 using google_apis::ChangeResource; 36 using google_apis::ChangeResource;
37 using google_apis::DownloadActionCallback; 37 using google_apis::DownloadActionCallback;
38 using google_apis::EntryActionCallback; 38 using google_apis::EntryActionCallback;
39 using google_apis::FileList; 39 using google_apis::FileList;
40 using google_apis::FileListCallback; 40 using google_apis::FileListCallback;
41 using google_apis::FileResource; 41 using google_apis::FileResource;
42 using google_apis::FileResourceCallback; 42 using google_apis::FileResourceCallback;
43 using google_apis::GDATA_FILE_ERROR; 43 using google_apis::DRIVE_FILE_ERROR;
mtomasz 2015/01/29 06:18:02 nit: ditto
44 using google_apis::GDATA_NO_CONNECTION; 44 using google_apis::DRIVE_NO_CONNECTION;
45 using google_apis::GDATA_OTHER_ERROR; 45 using google_apis::DRIVE_OTHER_ERROR;
46 using google_apis::GDataErrorCode; 46 using google_apis::DriveApiErrorCode;
47 using google_apis::GetContentCallback; 47 using google_apis::GetContentCallback;
48 using google_apis::GetShareUrlCallback; 48 using google_apis::GetShareUrlCallback;
49 using google_apis::HTTP_BAD_REQUEST; 49 using google_apis::HTTP_BAD_REQUEST;
50 using google_apis::HTTP_CREATED; 50 using google_apis::HTTP_CREATED;
51 using google_apis::HTTP_FORBIDDEN; 51 using google_apis::HTTP_FORBIDDEN;
52 using google_apis::HTTP_NOT_FOUND; 52 using google_apis::HTTP_NOT_FOUND;
53 using google_apis::HTTP_NO_CONTENT; 53 using google_apis::HTTP_NO_CONTENT;
54 using google_apis::HTTP_PRECONDITION; 54 using google_apis::HTTP_PRECONDITION;
55 using google_apis::HTTP_RESUME_INCOMPLETE; 55 using google_apis::HTTP_RESUME_INCOMPLETE;
56 using google_apis::HTTP_SUCCESS; 56 using google_apis::HTTP_SUCCESS;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 if (!entry.file() || 96 if (!entry.file() ||
97 entry.file()->title().find(value) == std::string::npos) 97 entry.file()->title().find(value) == std::string::npos)
98 return false; 98 return false;
99 } 99 }
100 return true; 100 return true;
101 } 101 }
102 102
103 void ScheduleUploadRangeCallback(const UploadRangeCallback& callback, 103 void ScheduleUploadRangeCallback(const UploadRangeCallback& callback,
104 int64 start_position, 104 int64 start_position,
105 int64 end_position, 105 int64 end_position,
106 GDataErrorCode error, 106 DriveApiErrorCode error,
107 scoped_ptr<FileResource> entry) { 107 scoped_ptr<FileResource> entry) {
108 base::MessageLoop::current()->PostTask( 108 base::MessageLoop::current()->PostTask(
109 FROM_HERE, 109 FROM_HERE,
110 base::Bind(callback, 110 base::Bind(callback,
111 UploadRangeResponse(error, 111 UploadRangeResponse(error,
112 start_position, 112 start_position,
113 end_position), 113 end_position),
114 base::Passed(&entry))); 114 base::Passed(&entry)));
115 } 115 }
116 116
117 void FileListCallbackAdapter(const FileListCallback& callback, 117 void FileListCallbackAdapter(const FileListCallback& callback,
118 GDataErrorCode error, 118 DriveApiErrorCode error,
119 scoped_ptr<ChangeList> change_list) { 119 scoped_ptr<ChangeList> change_list) {
120 scoped_ptr<FileList> file_list; 120 scoped_ptr<FileList> file_list;
121 if (!change_list) { 121 if (!change_list) {
122 callback.Run(error, file_list.Pass()); 122 callback.Run(error, file_list.Pass());
123 return; 123 return;
124 } 124 }
125 125
126 file_list.reset(new FileList); 126 file_list.reset(new FileList);
127 file_list->set_next_link(change_list->next_link()); 127 file_list->set_next_link(change_list->next_link());
128 for (size_t i = 0; i < change_list->items().size(); ++i) { 128 for (size_t i = 0; i < change_list->items().size(); ++i) {
(...skipping 19 matching lines...) Expand all
148 void CallFileResouceCallback(const FileResourceCallback& callback, 148 void CallFileResouceCallback(const FileResourceCallback& callback,
149 const UploadRangeResponse& response, 149 const UploadRangeResponse& response,
150 scoped_ptr<FileResource> entry) { 150 scoped_ptr<FileResource> entry) {
151 callback.Run(response.code, entry.Pass()); 151 callback.Run(response.code, entry.Pass());
152 } 152 }
153 153
154 struct CallResumeUpload { 154 struct CallResumeUpload {
155 CallResumeUpload() {} 155 CallResumeUpload() {}
156 ~CallResumeUpload() {} 156 ~CallResumeUpload() {}
157 157
158 void Run(GDataErrorCode code, const GURL& upload_url) { 158 void Run(DriveApiErrorCode code, const GURL& upload_url) {
159 if (service) { 159 if (service) {
160 service->ResumeUpload( 160 service->ResumeUpload(
161 upload_url, 161 upload_url,
162 /* start position */ 0, 162 /* start position */ 0,
163 /* end position */ content_length, 163 /* end position */ content_length,
164 content_length, 164 content_length,
165 content_type, 165 content_type,
166 local_file_path, 166 local_file_path,
167 base::Bind(&CallFileResouceCallback, callback), 167 base::Bind(&CallFileResouceCallback, callback),
168 progress_callback); 168 progress_callback);
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 CancelCallback FakeDriveService::GetFileResource( 530 CancelCallback FakeDriveService::GetFileResource(
531 const std::string& resource_id, 531 const std::string& resource_id,
532 const FileResourceCallback& callback) { 532 const FileResourceCallback& callback) {
533 DCHECK(thread_checker_.CalledOnValidThread()); 533 DCHECK(thread_checker_.CalledOnValidThread());
534 DCHECK(!callback.is_null()); 534 DCHECK(!callback.is_null());
535 535
536 if (offline_) { 536 if (offline_) {
537 base::MessageLoop::current()->PostTask( 537 base::MessageLoop::current()->PostTask(
538 FROM_HERE, 538 FROM_HERE,
539 base::Bind(callback, 539 base::Bind(callback,
540 GDATA_NO_CONNECTION, 540 DRIVE_NO_CONNECTION,
541 base::Passed(scoped_ptr<FileResource>()))); 541 base::Passed(scoped_ptr<FileResource>())));
542 return CancelCallback(); 542 return CancelCallback();
543 } 543 }
544 544
545 EntryInfo* entry = FindEntryByResourceId(resource_id); 545 EntryInfo* entry = FindEntryByResourceId(resource_id);
546 if (entry && entry->change_resource.file()) { 546 if (entry && entry->change_resource.file()) {
547 base::MessageLoop::current()->PostTask( 547 base::MessageLoop::current()->PostTask(
548 FROM_HERE, 548 FROM_HERE,
549 base::Bind(callback, HTTP_SUCCESS, base::Passed(make_scoped_ptr( 549 base::Bind(callback, HTTP_SUCCESS, base::Passed(make_scoped_ptr(
550 new FileResource(*entry->change_resource.file()))))); 550 new FileResource(*entry->change_resource.file())))));
(...skipping 11 matching lines...) Expand all
562 const std::string& resource_id, 562 const std::string& resource_id,
563 const GURL& /* embed_origin */, 563 const GURL& /* embed_origin */,
564 const GetShareUrlCallback& callback) { 564 const GetShareUrlCallback& callback) {
565 DCHECK(thread_checker_.CalledOnValidThread()); 565 DCHECK(thread_checker_.CalledOnValidThread());
566 DCHECK(!callback.is_null()); 566 DCHECK(!callback.is_null());
567 567
568 if (offline_) { 568 if (offline_) {
569 base::MessageLoop::current()->PostTask( 569 base::MessageLoop::current()->PostTask(
570 FROM_HERE, 570 FROM_HERE,
571 base::Bind(callback, 571 base::Bind(callback,
572 GDATA_NO_CONNECTION, 572 DRIVE_NO_CONNECTION,
573 GURL())); 573 GURL()));
574 return CancelCallback(); 574 return CancelCallback();
575 } 575 }
576 576
577 EntryInfo* entry = FindEntryByResourceId(resource_id); 577 EntryInfo* entry = FindEntryByResourceId(resource_id);
578 if (entry) { 578 if (entry) {
579 base::MessageLoop::current()->PostTask( 579 base::MessageLoop::current()->PostTask(
580 FROM_HERE, 580 FROM_HERE,
581 base::Bind(callback, HTTP_SUCCESS, entry->share_url)); 581 base::Bind(callback, HTTP_SUCCESS, entry->share_url));
582 return CancelCallback(); 582 return CancelCallback();
583 } 583 }
584 584
585 base::MessageLoop::current()->PostTask( 585 base::MessageLoop::current()->PostTask(
586 FROM_HERE, 586 FROM_HERE,
587 base::Bind(callback, HTTP_NOT_FOUND, GURL())); 587 base::Bind(callback, HTTP_NOT_FOUND, GURL()));
588 return CancelCallback(); 588 return CancelCallback();
589 } 589 }
590 590
591 CancelCallback FakeDriveService::GetAboutResource( 591 CancelCallback FakeDriveService::GetAboutResource(
592 const AboutResourceCallback& callback) { 592 const AboutResourceCallback& callback) {
593 DCHECK(thread_checker_.CalledOnValidThread()); 593 DCHECK(thread_checker_.CalledOnValidThread());
594 DCHECK(!callback.is_null()); 594 DCHECK(!callback.is_null());
595 595
596 if (offline_) { 596 if (offline_) {
597 scoped_ptr<AboutResource> null; 597 scoped_ptr<AboutResource> null;
598 base::MessageLoop::current()->PostTask( 598 base::MessageLoop::current()->PostTask(
599 FROM_HERE, 599 FROM_HERE,
600 base::Bind(callback, 600 base::Bind(callback,
601 GDATA_NO_CONNECTION, base::Passed(&null))); 601 DRIVE_NO_CONNECTION, base::Passed(&null)));
602 return CancelCallback(); 602 return CancelCallback();
603 } 603 }
604 604
605 ++about_resource_load_count_; 605 ++about_resource_load_count_;
606 scoped_ptr<AboutResource> about_resource(new AboutResource(*about_resource_)); 606 scoped_ptr<AboutResource> about_resource(new AboutResource(*about_resource_));
607 base::MessageLoop::current()->PostTask( 607 base::MessageLoop::current()->PostTask(
608 FROM_HERE, 608 FROM_HERE,
609 base::Bind(callback, 609 base::Bind(callback,
610 HTTP_SUCCESS, base::Passed(&about_resource))); 610 HTTP_SUCCESS, base::Passed(&about_resource)));
611 return CancelCallback(); 611 return CancelCallback();
612 } 612 }
613 613
614 CancelCallback FakeDriveService::GetAppList(const AppListCallback& callback) { 614 CancelCallback FakeDriveService::GetAppList(const AppListCallback& callback) {
615 DCHECK(thread_checker_.CalledOnValidThread()); 615 DCHECK(thread_checker_.CalledOnValidThread());
616 DCHECK(!callback.is_null()); 616 DCHECK(!callback.is_null());
617 DCHECK(app_info_value_); 617 DCHECK(app_info_value_);
618 618
619 if (offline_) { 619 if (offline_) {
620 scoped_ptr<AppList> null; 620 scoped_ptr<AppList> null;
621 base::MessageLoop::current()->PostTask( 621 base::MessageLoop::current()->PostTask(
622 FROM_HERE, 622 FROM_HERE,
623 base::Bind(callback, 623 base::Bind(callback,
624 GDATA_NO_CONNECTION, 624 DRIVE_NO_CONNECTION,
625 base::Passed(&null))); 625 base::Passed(&null)));
626 return CancelCallback(); 626 return CancelCallback();
627 } 627 }
628 628
629 ++app_list_load_count_; 629 ++app_list_load_count_;
630 scoped_ptr<AppList> app_list(AppList::CreateFrom(*app_info_value_)); 630 scoped_ptr<AppList> app_list(AppList::CreateFrom(*app_info_value_));
631 base::MessageLoop::current()->PostTask( 631 base::MessageLoop::current()->PostTask(
632 FROM_HERE, 632 FROM_HERE,
633 base::Bind(callback, HTTP_SUCCESS, base::Passed(&app_list))); 633 base::Bind(callback, HTTP_SUCCESS, base::Passed(&app_list)));
634 return CancelCallback(); 634 return CancelCallback();
635 } 635 }
636 636
637 CancelCallback FakeDriveService::DeleteResource( 637 CancelCallback FakeDriveService::DeleteResource(
638 const std::string& resource_id, 638 const std::string& resource_id,
639 const std::string& etag, 639 const std::string& etag,
640 const EntryActionCallback& callback) { 640 const EntryActionCallback& callback) {
641 DCHECK(thread_checker_.CalledOnValidThread()); 641 DCHECK(thread_checker_.CalledOnValidThread());
642 DCHECK(!callback.is_null()); 642 DCHECK(!callback.is_null());
643 643
644 if (offline_) { 644 if (offline_) {
645 base::MessageLoop::current()->PostTask( 645 base::MessageLoop::current()->PostTask(
646 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); 646 FROM_HERE, base::Bind(callback, DRIVE_NO_CONNECTION));
647 return CancelCallback(); 647 return CancelCallback();
648 } 648 }
649 649
650 EntryInfo* entry = FindEntryByResourceId(resource_id); 650 EntryInfo* entry = FindEntryByResourceId(resource_id);
651 if (!entry) { 651 if (!entry) {
652 base::MessageLoop::current()->PostTask( 652 base::MessageLoop::current()->PostTask(
653 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); 653 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND));
654 return CancelCallback(); 654 return CancelCallback();
655 } 655 }
656 656
(...skipping 30 matching lines...) Expand all
687 } 687 }
688 688
689 CancelCallback FakeDriveService::TrashResource( 689 CancelCallback FakeDriveService::TrashResource(
690 const std::string& resource_id, 690 const std::string& resource_id,
691 const EntryActionCallback& callback) { 691 const EntryActionCallback& callback) {
692 DCHECK(thread_checker_.CalledOnValidThread()); 692 DCHECK(thread_checker_.CalledOnValidThread());
693 DCHECK(!callback.is_null()); 693 DCHECK(!callback.is_null());
694 694
695 if (offline_) { 695 if (offline_) {
696 base::MessageLoop::current()->PostTask( 696 base::MessageLoop::current()->PostTask(
697 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); 697 FROM_HERE, base::Bind(callback, DRIVE_NO_CONNECTION));
698 return CancelCallback(); 698 return CancelCallback();
699 } 699 }
700 700
701 EntryInfo* entry = FindEntryByResourceId(resource_id); 701 EntryInfo* entry = FindEntryByResourceId(resource_id);
702 if (!entry) { 702 if (!entry) {
703 base::MessageLoop::current()->PostTask( 703 base::MessageLoop::current()->PostTask(
704 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); 704 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND));
705 return CancelCallback(); 705 return CancelCallback();
706 } 706 }
707 707
(...skipping 28 matching lines...) Expand all
736 const DownloadActionCallback& download_action_callback, 736 const DownloadActionCallback& download_action_callback,
737 const GetContentCallback& get_content_callback, 737 const GetContentCallback& get_content_callback,
738 const ProgressCallback& progress_callback) { 738 const ProgressCallback& progress_callback) {
739 DCHECK(thread_checker_.CalledOnValidThread()); 739 DCHECK(thread_checker_.CalledOnValidThread());
740 DCHECK(!download_action_callback.is_null()); 740 DCHECK(!download_action_callback.is_null());
741 741
742 if (offline_) { 742 if (offline_) {
743 base::MessageLoop::current()->PostTask( 743 base::MessageLoop::current()->PostTask(
744 FROM_HERE, 744 FROM_HERE,
745 base::Bind(download_action_callback, 745 base::Bind(download_action_callback,
746 GDATA_NO_CONNECTION, 746 DRIVE_NO_CONNECTION,
747 base::FilePath())); 747 base::FilePath()));
748 return CancelCallback(); 748 return CancelCallback();
749 } 749 }
750 750
751 EntryInfo* entry = FindEntryByResourceId(resource_id); 751 EntryInfo* entry = FindEntryByResourceId(resource_id);
752 if (!entry || entry->change_resource.file()->IsHostedDocument()) { 752 if (!entry || entry->change_resource.file()->IsHostedDocument()) {
753 base::MessageLoopProxy::current()->PostTask( 753 base::MessageLoopProxy::current()->PostTask(
754 FROM_HERE, 754 FROM_HERE,
755 base::Bind(download_action_callback, HTTP_NOT_FOUND, base::FilePath())); 755 base::Bind(download_action_callback, HTTP_NOT_FOUND, base::FilePath()));
756 return CancelCallback(); 756 return CancelCallback();
(...skipping 15 matching lines...) Expand all
772 base::Bind(get_content_callback, HTTP_SUCCESS, 772 base::Bind(get_content_callback, HTTP_SUCCESS,
773 base::Passed(&content_for_callback))); 773 base::Passed(&content_for_callback)));
774 } 774 }
775 } 775 }
776 776
777 if (!test_util::WriteStringToFile(local_cache_path, content_data)) { 777 if (!test_util::WriteStringToFile(local_cache_path, content_data)) {
778 // Failed to write the content. 778 // Failed to write the content.
779 base::MessageLoopProxy::current()->PostTask( 779 base::MessageLoopProxy::current()->PostTask(
780 FROM_HERE, 780 FROM_HERE,
781 base::Bind(download_action_callback, 781 base::Bind(download_action_callback,
782 GDATA_FILE_ERROR, base::FilePath())); 782 DRIVE_FILE_ERROR, base::FilePath()));
783 return CancelCallback(); 783 return CancelCallback();
784 } 784 }
785 785
786 if (!progress_callback.is_null()) { 786 if (!progress_callback.is_null()) {
787 // See also the comment in ResumeUpload(). For testing that clients 787 // See also the comment in ResumeUpload(). For testing that clients
788 // can handle the case progress_callback is called multiple times, 788 // can handle the case progress_callback is called multiple times,
789 // here we invoke the callback twice. 789 // here we invoke the callback twice.
790 base::MessageLoopProxy::current()->PostTask( 790 base::MessageLoopProxy::current()->PostTask(
791 FROM_HERE, 791 FROM_HERE,
792 base::Bind(progress_callback, file_size / 2, file_size)); 792 base::Bind(progress_callback, file_size / 2, file_size));
(...skipping 15 matching lines...) Expand all
808 const std::string& new_title, 808 const std::string& new_title,
809 const base::Time& last_modified, 809 const base::Time& last_modified,
810 const FileResourceCallback& callback) { 810 const FileResourceCallback& callback) {
811 DCHECK(thread_checker_.CalledOnValidThread()); 811 DCHECK(thread_checker_.CalledOnValidThread());
812 DCHECK(!callback.is_null()); 812 DCHECK(!callback.is_null());
813 813
814 if (offline_) { 814 if (offline_) {
815 base::MessageLoop::current()->PostTask( 815 base::MessageLoop::current()->PostTask(
816 FROM_HERE, 816 FROM_HERE,
817 base::Bind(callback, 817 base::Bind(callback,
818 GDATA_NO_CONNECTION, 818 DRIVE_NO_CONNECTION,
819 base::Passed(scoped_ptr<FileResource>()))); 819 base::Passed(scoped_ptr<FileResource>())));
820 return CancelCallback(); 820 return CancelCallback();
821 } 821 }
822 822
823 const std::string& parent_resource_id = in_parent_resource_id.empty() ? 823 const std::string& parent_resource_id = in_parent_resource_id.empty() ?
824 GetRootResourceId() : in_parent_resource_id; 824 GetRootResourceId() : in_parent_resource_id;
825 825
826 EntryInfo* entry = FindEntryByResourceId(resource_id); 826 EntryInfo* entry = FindEntryByResourceId(resource_id);
827 if (!entry) { 827 if (!entry) {
828 base::MessageLoop::current()->PostTask( 828 base::MessageLoop::current()->PostTask(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 const std::string& parent_resource_id, 879 const std::string& parent_resource_id,
880 const std::string& new_title, 880 const std::string& new_title,
881 const base::Time& last_modified, 881 const base::Time& last_modified,
882 const base::Time& last_viewed_by_me, 882 const base::Time& last_viewed_by_me,
883 const google_apis::FileResourceCallback& callback) { 883 const google_apis::FileResourceCallback& callback) {
884 DCHECK(thread_checker_.CalledOnValidThread()); 884 DCHECK(thread_checker_.CalledOnValidThread());
885 DCHECK(!callback.is_null()); 885 DCHECK(!callback.is_null());
886 886
887 if (offline_) { 887 if (offline_) {
888 base::MessageLoop::current()->PostTask( 888 base::MessageLoop::current()->PostTask(
889 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION, 889 FROM_HERE, base::Bind(callback, DRIVE_NO_CONNECTION,
890 base::Passed(scoped_ptr<FileResource>()))); 890 base::Passed(scoped_ptr<FileResource>())));
891 return CancelCallback(); 891 return CancelCallback();
892 } 892 }
893 893
894 EntryInfo* entry = FindEntryByResourceId(resource_id); 894 EntryInfo* entry = FindEntryByResourceId(resource_id);
895 if (!entry) { 895 if (!entry) {
896 base::MessageLoop::current()->PostTask( 896 base::MessageLoop::current()->PostTask(
897 FROM_HERE, 897 FROM_HERE,
898 base::Bind(callback, HTTP_NOT_FOUND, 898 base::Bind(callback, HTTP_NOT_FOUND,
899 base::Passed(scoped_ptr<FileResource>()))); 899 base::Passed(scoped_ptr<FileResource>())));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 947
948 CancelCallback FakeDriveService::AddResourceToDirectory( 948 CancelCallback FakeDriveService::AddResourceToDirectory(
949 const std::string& parent_resource_id, 949 const std::string& parent_resource_id,
950 const std::string& resource_id, 950 const std::string& resource_id,
951 const EntryActionCallback& callback) { 951 const EntryActionCallback& callback) {
952 DCHECK(thread_checker_.CalledOnValidThread()); 952 DCHECK(thread_checker_.CalledOnValidThread());
953 DCHECK(!callback.is_null()); 953 DCHECK(!callback.is_null());
954 954
955 if (offline_) { 955 if (offline_) {
956 base::MessageLoop::current()->PostTask( 956 base::MessageLoop::current()->PostTask(
957 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); 957 FROM_HERE, base::Bind(callback, DRIVE_NO_CONNECTION));
958 return CancelCallback(); 958 return CancelCallback();
959 } 959 }
960 960
961 EntryInfo* entry = FindEntryByResourceId(resource_id); 961 EntryInfo* entry = FindEntryByResourceId(resource_id);
962 if (!entry) { 962 if (!entry) {
963 base::MessageLoop::current()->PostTask( 963 base::MessageLoop::current()->PostTask(
964 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); 964 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND));
965 return CancelCallback(); 965 return CancelCallback();
966 } 966 }
967 967
(...skipping 19 matching lines...) Expand all
987 987
988 CancelCallback FakeDriveService::RemoveResourceFromDirectory( 988 CancelCallback FakeDriveService::RemoveResourceFromDirectory(
989 const std::string& parent_resource_id, 989 const std::string& parent_resource_id,
990 const std::string& resource_id, 990 const std::string& resource_id,
991 const EntryActionCallback& callback) { 991 const EntryActionCallback& callback) {
992 DCHECK(thread_checker_.CalledOnValidThread()); 992 DCHECK(thread_checker_.CalledOnValidThread());
993 DCHECK(!callback.is_null()); 993 DCHECK(!callback.is_null());
994 994
995 if (offline_) { 995 if (offline_) {
996 base::MessageLoop::current()->PostTask( 996 base::MessageLoop::current()->PostTask(
997 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); 997 FROM_HERE, base::Bind(callback, DRIVE_NO_CONNECTION));
998 return CancelCallback(); 998 return CancelCallback();
999 } 999 }
1000 1000
1001 EntryInfo* entry = FindEntryByResourceId(resource_id); 1001 EntryInfo* entry = FindEntryByResourceId(resource_id);
1002 if (!entry) { 1002 if (!entry) {
1003 base::MessageLoop::current()->PostTask( 1003 base::MessageLoop::current()->PostTask(
1004 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); 1004 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND));
1005 return CancelCallback(); 1005 return CancelCallback();
1006 } 1006 }
1007 1007
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 const UploadNewFileOptions& options, 1048 const UploadNewFileOptions& options,
1049 const InitiateUploadCallback& callback) { 1049 const InitiateUploadCallback& callback) {
1050 DCHECK(thread_checker_.CalledOnValidThread()); 1050 DCHECK(thread_checker_.CalledOnValidThread());
1051 DCHECK(!callback.is_null()); 1051 DCHECK(!callback.is_null());
1052 1052
1053 if (offline_) { 1053 if (offline_) {
1054 base::MessageLoop::current()->PostTask( 1054 base::MessageLoop::current()->PostTask(
1055 FROM_HERE, 1055 FROM_HERE,
1056 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); 1056 base::Bind(callback, DRIVE_NO_CONNECTION, GURL()));
1057 return CancelCallback(); 1057 return CancelCallback();
1058 } 1058 }
1059 1059
1060 if (parent_resource_id != GetRootResourceId() && 1060 if (parent_resource_id != GetRootResourceId() &&
1061 !entries_.count(parent_resource_id)) { 1061 !entries_.count(parent_resource_id)) {
1062 base::MessageLoop::current()->PostTask( 1062 base::MessageLoop::current()->PostTask(
1063 FROM_HERE, 1063 FROM_HERE,
1064 base::Bind(callback, HTTP_NOT_FOUND, GURL())); 1064 base::Bind(callback, HTTP_NOT_FOUND, GURL()));
1065 return CancelCallback(); 1065 return CancelCallback();
1066 } 1066 }
(...skipping 17 matching lines...) Expand all
1084 int64 content_length, 1084 int64 content_length,
1085 const std::string& resource_id, 1085 const std::string& resource_id,
1086 const UploadExistingFileOptions& options, 1086 const UploadExistingFileOptions& options,
1087 const InitiateUploadCallback& callback) { 1087 const InitiateUploadCallback& callback) {
1088 DCHECK(thread_checker_.CalledOnValidThread()); 1088 DCHECK(thread_checker_.CalledOnValidThread());
1089 DCHECK(!callback.is_null()); 1089 DCHECK(!callback.is_null());
1090 1090
1091 if (offline_) { 1091 if (offline_) {
1092 base::MessageLoop::current()->PostTask( 1092 base::MessageLoop::current()->PostTask(
1093 FROM_HERE, 1093 FROM_HERE,
1094 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); 1094 base::Bind(callback, DRIVE_NO_CONNECTION, GURL()));
1095 return CancelCallback(); 1095 return CancelCallback();
1096 } 1096 }
1097 1097
1098 EntryInfo* entry = FindEntryByResourceId(resource_id); 1098 EntryInfo* entry = FindEntryByResourceId(resource_id);
1099 if (!entry) { 1099 if (!entry) {
1100 base::MessageLoop::current()->PostTask( 1100 base::MessageLoop::current()->PostTask(
1101 FROM_HERE, 1101 FROM_HERE,
1102 base::Bind(callback, HTTP_NOT_FOUND, GURL())); 1102 base::Bind(callback, HTTP_NOT_FOUND, GURL()));
1103 return CancelCallback(); 1103 return CancelCallback();
1104 } 1104 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 const UploadRangeCallback& callback, 1152 const UploadRangeCallback& callback,
1153 const ProgressCallback& progress_callback) { 1153 const ProgressCallback& progress_callback) {
1154 DCHECK(thread_checker_.CalledOnValidThread()); 1154 DCHECK(thread_checker_.CalledOnValidThread());
1155 DCHECK(!callback.is_null()); 1155 DCHECK(!callback.is_null());
1156 1156
1157 FileResourceCallback completion_callback 1157 FileResourceCallback completion_callback
1158 = base::Bind(&ScheduleUploadRangeCallback, 1158 = base::Bind(&ScheduleUploadRangeCallback,
1159 callback, start_position, end_position); 1159 callback, start_position, end_position);
1160 1160
1161 if (offline_) { 1161 if (offline_) {
1162 completion_callback.Run(GDATA_NO_CONNECTION, scoped_ptr<FileResource>()); 1162 completion_callback.Run(DRIVE_NO_CONNECTION, scoped_ptr<FileResource>());
1163 return CancelCallback(); 1163 return CancelCallback();
1164 } 1164 }
1165 1165
1166 if (!upload_sessions_.count(upload_url)) { 1166 if (!upload_sessions_.count(upload_url)) {
1167 completion_callback.Run(HTTP_NOT_FOUND, scoped_ptr<FileResource>()); 1167 completion_callback.Run(HTTP_NOT_FOUND, scoped_ptr<FileResource>());
1168 return CancelCallback(); 1168 return CancelCallback();
1169 } 1169 }
1170 1170
1171 UploadSession* session = &upload_sessions_[upload_url]; 1171 UploadSession* session = &upload_sessions_[upload_url];
1172 1172
(...skipping 20 matching lines...) Expand all
1193 1193
1194 if (content_length != end_position) { 1194 if (content_length != end_position) {
1195 session->uploaded_size = end_position; 1195 session->uploaded_size = end_position;
1196 completion_callback.Run(HTTP_RESUME_INCOMPLETE, scoped_ptr<FileResource>()); 1196 completion_callback.Run(HTTP_RESUME_INCOMPLETE, scoped_ptr<FileResource>());
1197 return CancelCallback(); 1197 return CancelCallback();
1198 } 1198 }
1199 1199
1200 std::string content_data; 1200 std::string content_data;
1201 if (!base::ReadFileToString(local_file_path, &content_data)) { 1201 if (!base::ReadFileToString(local_file_path, &content_data)) {
1202 session->uploaded_size = end_position; 1202 session->uploaded_size = end_position;
1203 completion_callback.Run(GDATA_FILE_ERROR, scoped_ptr<FileResource>()); 1203 completion_callback.Run(DRIVE_FILE_ERROR, scoped_ptr<FileResource>());
1204 return CancelCallback(); 1204 return CancelCallback();
1205 } 1205 }
1206 session->uploaded_size = end_position; 1206 session->uploaded_size = end_position;
1207 1207
1208 // |resource_id| is empty if the upload is for new file. 1208 // |resource_id| is empty if the upload is for new file.
1209 if (session->resource_id.empty()) { 1209 if (session->resource_id.empty()) {
1210 DCHECK(!session->parent_resource_id.empty()); 1210 DCHECK(!session->parent_resource_id.empty());
1211 DCHECK(!session->title.empty()); 1211 DCHECK(!session->title.empty());
1212 const EntryInfo* new_entry = AddNewEntry( 1212 const EntryInfo* new_entry = AddNewEntry(
1213 "", // auto generate resource id. 1213 "", // auto generate resource id.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 1329
1330 CancelCallback FakeDriveService::UninstallApp( 1330 CancelCallback FakeDriveService::UninstallApp(
1331 const std::string& app_id, 1331 const std::string& app_id,
1332 const google_apis::EntryActionCallback& callback) { 1332 const google_apis::EntryActionCallback& callback) {
1333 DCHECK(thread_checker_.CalledOnValidThread()); 1333 DCHECK(thread_checker_.CalledOnValidThread());
1334 DCHECK(!callback.is_null()); 1334 DCHECK(!callback.is_null());
1335 1335
1336 if (offline_) { 1336 if (offline_) {
1337 base::MessageLoop::current()->PostTask( 1337 base::MessageLoop::current()->PostTask(
1338 FROM_HERE, 1338 FROM_HERE,
1339 base::Bind(callback, google_apis::GDATA_NO_CONNECTION)); 1339 base::Bind(callback, google_apis::DRIVE_NO_CONNECTION));
1340 return CancelCallback(); 1340 return CancelCallback();
1341 } 1341 }
1342 1342
1343 // Find app_id from app_info_value_ and delete. 1343 // Find app_id from app_info_value_ and delete.
1344 base::ListValue* items = NULL; 1344 base::ListValue* items = NULL;
1345 if (!app_info_value_->GetList("items", &items)) { 1345 if (!app_info_value_->GetList("items", &items)) {
1346 base::MessageLoop::current()->PostTask( 1346 base::MessageLoop::current()->PostTask(
1347 FROM_HERE, 1347 FROM_HERE,
1348 base::Bind(callback, google_apis::HTTP_NOT_FOUND)); 1348 base::Bind(callback, google_apis::HTTP_NOT_FOUND));
1349 return CancelCallback(); 1349 return CancelCallback();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 const std::string& title, 1387 const std::string& title,
1388 bool shared_with_me, 1388 bool shared_with_me,
1389 const FileResourceCallback& callback) { 1389 const FileResourceCallback& callback) {
1390 DCHECK(thread_checker_.CalledOnValidThread()); 1390 DCHECK(thread_checker_.CalledOnValidThread());
1391 DCHECK(!callback.is_null()); 1391 DCHECK(!callback.is_null());
1392 1392
1393 if (offline_) { 1393 if (offline_) {
1394 base::MessageLoop::current()->PostTask( 1394 base::MessageLoop::current()->PostTask(
1395 FROM_HERE, 1395 FROM_HERE,
1396 base::Bind(callback, 1396 base::Bind(callback,
1397 GDATA_NO_CONNECTION, 1397 DRIVE_NO_CONNECTION,
1398 base::Passed(scoped_ptr<FileResource>()))); 1398 base::Passed(scoped_ptr<FileResource>())));
1399 return; 1399 return;
1400 } 1400 }
1401 1401
1402 const EntryInfo* new_entry = AddNewEntry(resource_id, 1402 const EntryInfo* new_entry = AddNewEntry(resource_id,
1403 content_type, 1403 content_type,
1404 content_data, 1404 content_data,
1405 parent_resource_id, 1405 parent_resource_id,
1406 title, 1406 title,
1407 shared_with_me); 1407 shared_with_me);
(...skipping 22 matching lines...) Expand all
1430 const std::string& directory_title, 1430 const std::string& directory_title,
1431 const AddNewDirectoryOptions& options, 1431 const AddNewDirectoryOptions& options,
1432 const FileResourceCallback& callback) { 1432 const FileResourceCallback& callback) {
1433 DCHECK(thread_checker_.CalledOnValidThread()); 1433 DCHECK(thread_checker_.CalledOnValidThread());
1434 DCHECK(!callback.is_null()); 1434 DCHECK(!callback.is_null());
1435 1435
1436 if (offline_) { 1436 if (offline_) {
1437 base::MessageLoop::current()->PostTask( 1437 base::MessageLoop::current()->PostTask(
1438 FROM_HERE, 1438 FROM_HERE,
1439 base::Bind(callback, 1439 base::Bind(callback,
1440 GDATA_NO_CONNECTION, 1440 DRIVE_NO_CONNECTION,
1441 base::Passed(scoped_ptr<FileResource>()))); 1441 base::Passed(scoped_ptr<FileResource>())));
1442 return CancelCallback(); 1442 return CancelCallback();
1443 } 1443 }
1444 1444
1445 const EntryInfo* new_entry = AddNewEntry(resource_id, 1445 const EntryInfo* new_entry = AddNewEntry(resource_id,
1446 util::kDriveFolderMimeType, 1446 util::kDriveFolderMimeType,
1447 "", // content_data 1447 "", // content_data
1448 parent_resource_id, 1448 parent_resource_id,
1449 directory_title, 1449 directory_title,
1450 false); // shared_with_me 1450 false); // shared_with_me
(...skipping 21 matching lines...) Expand all
1472 const std::string& resource_id, 1472 const std::string& resource_id,
1473 const base::Time& last_modified_time, 1473 const base::Time& last_modified_time,
1474 const FileResourceCallback& callback) { 1474 const FileResourceCallback& callback) {
1475 DCHECK(thread_checker_.CalledOnValidThread()); 1475 DCHECK(thread_checker_.CalledOnValidThread());
1476 DCHECK(!callback.is_null()); 1476 DCHECK(!callback.is_null());
1477 1477
1478 if (offline_) { 1478 if (offline_) {
1479 base::MessageLoop::current()->PostTask( 1479 base::MessageLoop::current()->PostTask(
1480 FROM_HERE, 1480 FROM_HERE,
1481 base::Bind(callback, 1481 base::Bind(callback,
1482 GDATA_NO_CONNECTION, 1482 DRIVE_NO_CONNECTION,
1483 base::Passed(scoped_ptr<FileResource>()))); 1483 base::Passed(scoped_ptr<FileResource>())));
1484 return; 1484 return;
1485 } 1485 }
1486 1486
1487 EntryInfo* entry = FindEntryByResourceId(resource_id); 1487 EntryInfo* entry = FindEntryByResourceId(resource_id);
1488 if (!entry) { 1488 if (!entry) {
1489 base::MessageLoop::current()->PostTask( 1489 base::MessageLoop::current()->PostTask(
1490 FROM_HERE, 1490 FROM_HERE,
1491 base::Bind(callback, HTTP_NOT_FOUND, 1491 base::Bind(callback, HTTP_NOT_FOUND,
1492 base::Passed(scoped_ptr<FileResource>()))); 1492 base::Passed(scoped_ptr<FileResource>())));
1493 return; 1493 return;
1494 } 1494 }
1495 1495
1496 ChangeResource* change = &entry->change_resource; 1496 ChangeResource* change = &entry->change_resource;
1497 FileResource* file = change->mutable_file(); 1497 FileResource* file = change->mutable_file();
1498 file->set_modified_date(last_modified_time); 1498 file->set_modified_date(last_modified_time);
1499 1499
1500 base::MessageLoop::current()->PostTask( 1500 base::MessageLoop::current()->PostTask(
1501 FROM_HERE, 1501 FROM_HERE,
1502 base::Bind(callback, HTTP_SUCCESS, 1502 base::Bind(callback, HTTP_SUCCESS,
1503 base::Passed(make_scoped_ptr(new FileResource(*file))))); 1503 base::Passed(make_scoped_ptr(new FileResource(*file)))));
1504 } 1504 }
1505 1505
1506 google_apis::GDataErrorCode FakeDriveService::SetUserPermission( 1506 google_apis::DriveApiErrorCode FakeDriveService::SetUserPermission(
1507 const std::string& resource_id, 1507 const std::string& resource_id,
1508 google_apis::drive::PermissionRole user_permission) { 1508 google_apis::drive::PermissionRole user_permission) {
1509 DCHECK(thread_checker_.CalledOnValidThread()); 1509 DCHECK(thread_checker_.CalledOnValidThread());
1510 1510
1511 EntryInfo* entry = FindEntryByResourceId(resource_id); 1511 EntryInfo* entry = FindEntryByResourceId(resource_id);
1512 if (!entry) 1512 if (!entry)
1513 return HTTP_NOT_FOUND; 1513 return HTTP_NOT_FOUND;
1514 1514
1515 entry->user_permission = user_permission; 1515 entry->user_permission = user_permission;
1516 return HTTP_SUCCESS; 1516 return HTTP_SUCCESS;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 const std::string& search_query, 1634 const std::string& search_query,
1635 const std::string& directory_resource_id, 1635 const std::string& directory_resource_id,
1636 int start_offset, 1636 int start_offset,
1637 int max_results, 1637 int max_results,
1638 int* load_counter, 1638 int* load_counter,
1639 const ChangeListCallback& callback) { 1639 const ChangeListCallback& callback) {
1640 if (offline_) { 1640 if (offline_) {
1641 base::MessageLoop::current()->PostTask( 1641 base::MessageLoop::current()->PostTask(
1642 FROM_HERE, 1642 FROM_HERE,
1643 base::Bind(callback, 1643 base::Bind(callback,
1644 GDATA_NO_CONNECTION, 1644 DRIVE_NO_CONNECTION,
1645 base::Passed(scoped_ptr<ChangeList>()))); 1645 base::Passed(scoped_ptr<ChangeList>())));
1646 return; 1646 return;
1647 } 1647 }
1648 1648
1649 // Filter out entries per parameters like |directory_resource_id| and 1649 // Filter out entries per parameters like |directory_resource_id| and
1650 // |search_query|. 1650 // |search_query|.
1651 ScopedVector<ChangeResource> entries; 1651 ScopedVector<ChangeResource> entries;
1652 int num_entries_matched = 0; 1652 int num_entries_matched = 0;
1653 for (EntryInfoMap::iterator it = entries_.begin(); it != entries_.end(); 1653 for (EntryInfoMap::iterator it = entries_.begin(); it != entries_.end();
1654 ++it) { 1654 ++it) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 1769
1770 NOTREACHED(); 1770 NOTREACHED();
1771 return CancelCallback(); 1771 return CancelCallback();
1772 } 1772 }
1773 1773
1774 void FakeDriveService::NotifyObservers() { 1774 void FakeDriveService::NotifyObservers() {
1775 FOR_EACH_OBSERVER(ChangeObserver, change_observers_, OnNewChangeAvailable()); 1775 FOR_EACH_OBSERVER(ChangeObserver, change_observers_, OnNewChangeAvailable());
1776 } 1776 }
1777 1777
1778 } // namespace drive 1778 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698