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.
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_
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"
14 class SingleThreadTaskRunner;
15 class SequencedTaskRunner;
18 namespace sync_file_system {
19 namespace drive_backend {
21 class DriveServiceWrapper;
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 {
30 const base::WeakPtr<DriveServiceWrapper>& wrapper,
31 base::SingleThreadTaskRunner* ui_task_runner,
32 base::SequencedTaskRunner* worker_task_runner);
33 virtual ~DriveServiceOnWorker();
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;
41 virtual google_apis::CancelCallback DeleteResource(
42 const std::string& resource_id,
43 const std::string& etag,
44 const google_apis::EntryActionCallback& callback) OVERRIDE;
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;
53 virtual google_apis::CancelCallback GetAboutResource(
54 const google_apis::AboutResourceCallback& callback) OVERRIDE;
56 virtual google_apis::CancelCallback GetChangeList(
57 int64 start_changestamp,
58 const google_apis::ChangeListCallback& callback) OVERRIDE;
60 virtual google_apis::CancelCallback GetRemainingChangeList(
61 const GURL& next_link,
62 const google_apis::ChangeListCallback& callback) OVERRIDE;
64 virtual std::string GetRootResourceId() const OVERRIDE;
66 virtual google_apis::CancelCallback GetRemainingFileList(
67 const GURL& next_link,
68 const google_apis::FileListCallback& callback) OVERRIDE;
70 virtual google_apis::CancelCallback GetFileResource(
71 const std::string& resource_id,
72 const google_apis::FileResourceCallback& callback) OVERRIDE;
74 virtual google_apis::CancelCallback GetFileListInDirectory(
75 const std::string& directory_resource_id,
76 const google_apis::FileListCallback& callback) OVERRIDE;
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;
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;
88 virtual bool HasRefreshToken() const OVERRIDE;
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,
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;
171 base::WeakPtr<DriveServiceWrapper> wrapper_;
172 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
173 scoped_refptr<base::SequencedTaskRunner> worker_task_runner_;
175 base::SequenceChecker sequence_checker_;
177 DISALLOW_COPY_AND_ASSIGN(DriveServiceOnWorker);
180 } // namespace drive_backend
181 } // namespace sync_file_system
183 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_DRIVE_SERVICE_ON_WORKER_H_