1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_DRIVE_SERVICE_ON_WORKER_H_ 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_DRIVE_SERVICE_ON_WORKER_H_ 7 8 #include "base/memory/ref_counted.h" 9 #include "base/memory/weak_ptr.h" 10 #include "base/sequence_checker.h" 11 #include "chrome/browser/drive/drive_service_interface.h" 12 13 namespace base { 14 class SingleThreadTaskRunner; 15 class SequencedTaskRunner; 16 } 17 18 namespace sync_file_system { 19 namespace drive_backend { 20 21 class DriveServiceWrapper; 22 23 // This class wraps a part of DriveServiceInterface class to post actual 24 // tasks to DriveServiceWrapper which lives in another thread. 25 // Each method wraps corresponding name method of DriveServiceInterface. 26 // See comments in drive_service_interface.h for details. 27 class DriveServiceOnWorker : public drive::DriveServiceInterface { 28 public: 29 DriveServiceOnWorker( 30 const base::WeakPtr<DriveServiceWrapper>& wrapper, 31 base::SingleThreadTaskRunner* ui_task_runner, 32 base::SequencedTaskRunner* worker_task_runner); 33 virtual ~DriveServiceOnWorker(); 34 35 virtual google_apis::CancelCallback AddNewDirectory( 36 const std::string& parent_resource_id, 37 const std::string& directory_title, 38 const AddNewDirectoryOptions& options, 39 const google_apis::FileResourceCallback& callback) OVERRIDE; 40 41 virtual google_apis::CancelCallback DeleteResource( 42 const std::string& resource_id, 43 const std::string& etag, 44 const google_apis::EntryActionCallback& callback) OVERRIDE; 45 46 virtual google_apis::CancelCallback DownloadFile( 47 const base::FilePath& local_cache_path, 48 const std::string& resource_id, 49 const google_apis::DownloadActionCallback& download_action_callback, 50 const google_apis::GetContentCallback& get_content_callback, 51 const google_apis::ProgressCallback& progress_callback) OVERRIDE; 52 53 virtual google_apis::CancelCallback GetAboutResource( 54 const google_apis::AboutResourceCallback& callback) OVERRIDE; 55 56 virtual google_apis::CancelCallback GetChangeList( 57 int64 start_changestamp, 58 const google_apis::ChangeListCallback& callback) OVERRIDE; 59 60 virtual google_apis::CancelCallback GetRemainingChangeList( 61 const GURL& next_link, 62 const google_apis::ChangeListCallback& callback) OVERRIDE; 63 64 virtual std::string GetRootResourceId() const OVERRIDE; 65 66 virtual google_apis::CancelCallback GetRemainingFileList( 67 const GURL& next_link, 68 const google_apis::FileListCallback& callback) OVERRIDE; 69 70 virtual google_apis::CancelCallback GetFileResource( 71 const std::string& resource_id, 72 const google_apis::FileResourceCallback& callback) OVERRIDE; 73 74 virtual google_apis::CancelCallback GetFileListInDirectory( 75 const std::string& directory_resource_id, 76 const google_apis::FileListCallback& callback) OVERRIDE; 77 78 virtual google_apis::CancelCallback RemoveResourceFromDirectory( 79 const std::string& parent_resource_id, 80 const std::string& resource_id, 81 const google_apis::EntryActionCallback& callback) OVERRIDE; 82 83 virtual google_apis::CancelCallback SearchByTitle( 84 const std::string& title, 85 const std::string& directory_resource_id, 86 const google_apis::FileListCallback& callback) OVERRIDE; 87 88 virtual bool HasRefreshToken() const OVERRIDE; 89 90 // Following virtual methods are expected not to be accessed at all. 91 virtual void Initialize(const std::string& account_id) OVERRIDE; 92 virtual void AddObserver(drive::DriveServiceObserver* observer) OVERRIDE; 93 virtual void RemoveObserver(drive::DriveServiceObserver* observer) OVERRIDE; 94 virtual bool CanSendRequest() const OVERRIDE; 95 virtual bool HasAccessToken() const OVERRIDE; 96 virtual void RequestAccessToken( 97 const google_apis::AuthStatusCallback& callback) OVERRIDE; 98 virtual void ClearAccessToken() OVERRIDE; 99 virtual void ClearRefreshToken() OVERRIDE; 100 virtual google_apis::CancelCallback GetAllFileList( 101 const google_apis::FileListCallback& callback) OVERRIDE; 102 virtual google_apis::CancelCallback Search( 103 const std::string& search_query, 104 const google_apis::FileListCallback& callback) OVERRIDE; 105 virtual google_apis::CancelCallback GetShareUrl( 106 const std::string& resource_id, 107 const GURL& embed_origin, 108 const google_apis::GetShareUrlCallback& callback) OVERRIDE; 109 virtual google_apis::CancelCallback GetAppList( 110 const google_apis::AppListCallback& callback) OVERRIDE; 111 virtual google_apis::CancelCallback TrashResource( 112 const std::string& resource_id, 113 const google_apis::EntryActionCallback& callback) OVERRIDE; 114 virtual google_apis::CancelCallback CopyResource( 115 const std::string& resource_id, 116 const std::string& parent_resource_id, 117 const std::string& new_title, 118 const base::Time& last_modified, 119 const google_apis::FileResourceCallback& callback) OVERRIDE; 120 virtual google_apis::CancelCallback UpdateResource( 121 const std::string& resource_id, 122 const std::string& parent_resource_id, 123 const std::string& new_title, 124 const base::Time& last_modified, 125 const base::Time& last_viewed_by_me, 126 const google_apis::FileResourceCallback& callback) OVERRIDE; 127 virtual google_apis::CancelCallback AddResourceToDirectory( 128 const std::string& parent_resource_id, 129 const std::string& resource_id, 130 const google_apis::EntryActionCallback& callback) OVERRIDE; 131 virtual google_apis::CancelCallback InitiateUploadNewFile( 132 const std::string& content_type, 133 int64 content_length, 134 const std::string& parent_resource_id, 135 const std::string& title, 136 const InitiateUploadNewFileOptions& options, 137 const google_apis::InitiateUploadCallback& callback) OVERRIDE; 138 virtual google_apis::CancelCallback InitiateUploadExistingFile( 139 const std::string& content_type, 140 int64 content_length, 141 const std::string& resource_id, 142 const InitiateUploadExistingFileOptions& options, 143 const google_apis::InitiateUploadCallback& callback) OVERRIDE; 144 virtual google_apis::CancelCallback ResumeUpload( 145 const GURL& upload_url, 146 int64 start_position, 147 int64 end_position, 148 int64 content_length, 149 const std::string& content_type, 150 const base::FilePath& local_file_path, 151 const google_apis::drive::UploadRangeCallback& callback, 152 const google_apis::ProgressCallback& progress_callback) OVERRIDE; 153 virtual google_apis::CancelCallback GetUploadStatus( 154 const GURL& upload_url, 155 int64 content_length, 156 const google_apis::drive::UploadRangeCallback& callback) OVERRIDE; 157 virtual google_apis::CancelCallback AuthorizeApp( 158 const std::string& resource_id, 159 const std::string& app_id, 160 const google_apis::AuthorizeAppCallback& callback) OVERRIDE; 161 virtual google_apis::CancelCallback UninstallApp( 162 const std::string& app_id, 163 const google_apis::EntryActionCallback& callback) OVERRIDE; 164 virtual google_apis::CancelCallback AddPermission( 165 const std::string& resource_id, 166 const std::string& email, 167 google_apis::drive::PermissionRole role, 168 const google_apis::EntryActionCallback& callback) OVERRIDE; 169 170 private: 171 base::WeakPtr<DriveServiceWrapper> wrapper_; 172 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 173 scoped_refptr<base::SequencedTaskRunner> worker_task_runner_; 174 175 base::SequenceChecker sequence_checker_; 176 177 DISALLOW_COPY_AND_ASSIGN(DriveServiceOnWorker); 178 }; 179 180 } // namespace drive_backend 181 } // namespace sync_file_system 182 183 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_DRIVE_SERVICE_ON_WORKER_H_ 184