drive_service_on_worker.h revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
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 "chrome/browser/drive/drive_service_interface.h"
11
12namespace base {
13class SingleThreadTaskRunner;
14class SequencedTaskRunner;
15}
16
17namespace sync_file_system {
18namespace drive_backend {
19
20class DriveServiceWrapper;
21
22// This class wraps a part of DriveServiceInterface class to post actual
23// tasks to DriveServiceWrapper which lives in another thread.
24// Each method wraps corresponding name method of DriveServiceInterface.
25// See comments in drive_service_interface.h for details.
26class DriveServiceOnWorker : public drive::DriveServiceInterface {
27 public:
28  DriveServiceOnWorker(
29      const base::WeakPtr<DriveServiceWrapper>& wrapper,
30      base::SingleThreadTaskRunner* ui_task_runner,
31      base::SequencedTaskRunner* worker_task_runner);
32  virtual ~DriveServiceOnWorker();
33
34  virtual google_apis::CancelCallback AddNewDirectory(
35      const std::string& parent_resource_id,
36      const std::string& directory_title,
37      const AddNewDirectoryOptions& options,
38      const google_apis::GetResourceEntryCallback& callback) OVERRIDE;
39
40  virtual google_apis::CancelCallback DeleteResource(
41      const std::string& resource_id,
42      const std::string& etag,
43      const google_apis::EntryActionCallback& callback) OVERRIDE;
44
45  virtual google_apis::CancelCallback DownloadFile(
46      const base::FilePath& local_cache_path,
47      const std::string& resource_id,
48      const google_apis::DownloadActionCallback& download_action_callback,
49      const google_apis::GetContentCallback& get_content_callback,
50      const google_apis::ProgressCallback& progress_callback) OVERRIDE;
51
52  virtual google_apis::CancelCallback GetAboutResource(
53      const google_apis::AboutResourceCallback& callback) OVERRIDE;
54
55  virtual google_apis::CancelCallback GetChangeList(
56      int64 start_changestamp,
57      const google_apis::GetResourceListCallback& callback) OVERRIDE;
58
59  virtual google_apis::CancelCallback GetRemainingChangeList(
60      const GURL& next_link,
61      const google_apis::GetResourceListCallback& callback) OVERRIDE;
62
63  virtual std::string GetRootResourceId() const OVERRIDE;
64
65  virtual google_apis::CancelCallback GetRemainingFileList(
66      const GURL& next_link,
67      const google_apis::GetResourceListCallback& callback) OVERRIDE;
68
69  virtual google_apis::CancelCallback GetResourceEntry(
70      const std::string& resource_id,
71      const google_apis::GetResourceEntryCallback& callback) OVERRIDE;
72
73  virtual google_apis::CancelCallback GetResourceListInDirectory(
74      const std::string& directory_resource_id,
75      const google_apis::GetResourceListCallback& callback) OVERRIDE;
76
77  virtual google_apis::CancelCallback RemoveResourceFromDirectory(
78      const std::string& parent_resource_id,
79      const std::string& resource_id,
80      const google_apis::EntryActionCallback& callback) OVERRIDE;
81
82  virtual google_apis::CancelCallback SearchByTitle(
83      const std::string& title,
84      const std::string& directory_resource_id,
85      const google_apis::GetResourceListCallback& callback) OVERRIDE;
86
87  // Following methods are expected not to be accessed at all.
88  virtual void Initialize(const std::string& account_id) OVERRIDE;
89  virtual void AddObserver(drive::DriveServiceObserver* observer) OVERRIDE;
90  virtual void RemoveObserver(drive::DriveServiceObserver* observer) OVERRIDE;
91  virtual bool CanSendRequest() const OVERRIDE;
92  virtual drive::ResourceIdCanonicalizer GetResourceIdCanonicalizer()
93      const OVERRIDE;
94  virtual bool HasAccessToken() const OVERRIDE;
95  virtual void RequestAccessToken(
96      const google_apis::AuthStatusCallback& callback) OVERRIDE;
97  virtual bool HasRefreshToken() const OVERRIDE;
98  virtual void ClearAccessToken() OVERRIDE;
99  virtual void ClearRefreshToken() OVERRIDE;
100  virtual google_apis::CancelCallback GetAllResourceList(
101      const google_apis::GetResourceListCallback& callback) OVERRIDE;
102  virtual google_apis::CancelCallback Search(
103      const std::string& search_query,
104      const google_apis::GetResourceListCallback& 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::GetResourceEntryCallback& 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::GetResourceEntryCallback& callback) OVERRIDE;
127  virtual google_apis::CancelCallback RenameResource(
128      const std::string& resource_id,
129      const std::string& new_title,
130      const google_apis::EntryActionCallback& callback) OVERRIDE;
131  virtual google_apis::CancelCallback AddResourceToDirectory(
132      const std::string& parent_resource_id,
133      const std::string& resource_id,
134      const google_apis::EntryActionCallback& callback) OVERRIDE;
135  virtual google_apis::CancelCallback InitiateUploadNewFile(
136      const std::string& content_type,
137      int64 content_length,
138      const std::string& parent_resource_id,
139      const std::string& title,
140      const InitiateUploadNewFileOptions& options,
141      const google_apis::InitiateUploadCallback& callback) OVERRIDE;
142  virtual google_apis::CancelCallback InitiateUploadExistingFile(
143      const std::string& content_type,
144      int64 content_length,
145      const std::string& resource_id,
146      const InitiateUploadExistingFileOptions& options,
147      const google_apis::InitiateUploadCallback& callback) OVERRIDE;
148  virtual google_apis::CancelCallback ResumeUpload(
149      const GURL& upload_url,
150      int64 start_position,
151      int64 end_position,
152      int64 content_length,
153      const std::string& content_type,
154      const base::FilePath& local_file_path,
155      const google_apis::UploadRangeCallback& callback,
156      const google_apis::ProgressCallback& progress_callback) OVERRIDE;
157  virtual google_apis::CancelCallback GetUploadStatus(
158      const GURL& upload_url,
159      int64 content_length,
160      const google_apis::UploadRangeCallback& callback) OVERRIDE;
161  virtual google_apis::CancelCallback AuthorizeApp(
162      const std::string& resource_id,
163      const std::string& app_id,
164      const google_apis::AuthorizeAppCallback& callback) OVERRIDE;
165  virtual google_apis::CancelCallback UninstallApp(
166      const std::string& app_id,
167      const google_apis::EntryActionCallback& callback) OVERRIDE;
168  virtual google_apis::CancelCallback AddPermission(
169      const std::string& resource_id,
170      const std::string& email,
171      google_apis::drive::PermissionRole role,
172      const google_apis::EntryActionCallback& callback) OVERRIDE;
173
174 private:
175  base::WeakPtr<DriveServiceWrapper> wrapper_;
176  scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
177  scoped_refptr<base::SequencedTaskRunner> worker_task_runner_;
178
179  DISALLOW_COPY_AND_ASSIGN(DriveServiceOnWorker);
180};
181
182}  // namespace drive_backend
183}  // namespace sync_file_system
184
185#endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_DRIVE_SERVICE_ON_WORKER_H_
186