drive_service_on_worker.h revision 010d83a9304c5a91596085d917d248abff47903a
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  virtual bool HasRefreshToken() const OVERRIDE;
88
89  // Following virtual methods are expected not to be accessed at all.
90  virtual void Initialize(const std::string& account_id) OVERRIDE;
91  virtual void AddObserver(drive::DriveServiceObserver* observer) OVERRIDE;
92  virtual void RemoveObserver(drive::DriveServiceObserver* observer) OVERRIDE;
93  virtual bool CanSendRequest() const OVERRIDE;
94  virtual drive::ResourceIdCanonicalizer GetResourceIdCanonicalizer()
95      const OVERRIDE;
96  virtual bool HasAccessToken() const OVERRIDE;
97  virtual void RequestAccessToken(
98      const google_apis::AuthStatusCallback& callback) OVERRIDE;
99  virtual void ClearAccessToken() OVERRIDE;
100  virtual void ClearRefreshToken() OVERRIDE;
101  virtual google_apis::CancelCallback GetAllResourceList(
102      const google_apis::GetResourceListCallback& callback) OVERRIDE;
103  virtual google_apis::CancelCallback Search(
104      const std::string& search_query,
105      const google_apis::GetResourceListCallback& callback) OVERRIDE;
106  virtual google_apis::CancelCallback GetShareUrl(
107      const std::string& resource_id,
108      const GURL& embed_origin,
109      const google_apis::GetShareUrlCallback& callback) OVERRIDE;
110  virtual google_apis::CancelCallback GetAppList(
111      const google_apis::AppListCallback& callback) OVERRIDE;
112  virtual google_apis::CancelCallback TrashResource(
113      const std::string& resource_id,
114      const google_apis::EntryActionCallback& callback) OVERRIDE;
115  virtual google_apis::CancelCallback CopyResource(
116      const std::string& resource_id,
117      const std::string& parent_resource_id,
118      const std::string& new_title,
119      const base::Time& last_modified,
120      const google_apis::GetResourceEntryCallback& callback) OVERRIDE;
121  virtual google_apis::CancelCallback UpdateResource(
122      const std::string& resource_id,
123      const std::string& parent_resource_id,
124      const std::string& new_title,
125      const base::Time& last_modified,
126      const base::Time& last_viewed_by_me,
127      const google_apis::GetResourceEntryCallback& callback) OVERRIDE;
128  virtual google_apis::CancelCallback RenameResource(
129      const std::string& resource_id,
130      const std::string& new_title,
131      const google_apis::EntryActionCallback& callback) OVERRIDE;
132  virtual google_apis::CancelCallback AddResourceToDirectory(
133      const std::string& parent_resource_id,
134      const std::string& resource_id,
135      const google_apis::EntryActionCallback& callback) OVERRIDE;
136  virtual google_apis::CancelCallback InitiateUploadNewFile(
137      const std::string& content_type,
138      int64 content_length,
139      const std::string& parent_resource_id,
140      const std::string& title,
141      const InitiateUploadNewFileOptions& options,
142      const google_apis::InitiateUploadCallback& callback) OVERRIDE;
143  virtual google_apis::CancelCallback InitiateUploadExistingFile(
144      const std::string& content_type,
145      int64 content_length,
146      const std::string& resource_id,
147      const InitiateUploadExistingFileOptions& options,
148      const google_apis::InitiateUploadCallback& callback) OVERRIDE;
149  virtual google_apis::CancelCallback ResumeUpload(
150      const GURL& upload_url,
151      int64 start_position,
152      int64 end_position,
153      int64 content_length,
154      const std::string& content_type,
155      const base::FilePath& local_file_path,
156      const google_apis::UploadRangeCallback& callback,
157      const google_apis::ProgressCallback& progress_callback) OVERRIDE;
158  virtual google_apis::CancelCallback GetUploadStatus(
159      const GURL& upload_url,
160      int64 content_length,
161      const google_apis::UploadRangeCallback& callback) OVERRIDE;
162  virtual google_apis::CancelCallback AuthorizeApp(
163      const std::string& resource_id,
164      const std::string& app_id,
165      const google_apis::AuthorizeAppCallback& callback) OVERRIDE;
166  virtual google_apis::CancelCallback UninstallApp(
167      const std::string& app_id,
168      const google_apis::EntryActionCallback& callback) OVERRIDE;
169  virtual google_apis::CancelCallback AddPermission(
170      const std::string& resource_id,
171      const std::string& email,
172      google_apis::drive::PermissionRole role,
173      const google_apis::EntryActionCallback& callback) OVERRIDE;
174
175 private:
176  base::WeakPtr<DriveServiceWrapper> wrapper_;
177  scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
178  scoped_refptr<base::SequencedTaskRunner> worker_task_runner_;
179
180  DISALLOW_COPY_AND_ASSIGN(DriveServiceOnWorker);
181};
182
183}  // namespace drive_backend
184}  // namespace sync_file_system
185
186#endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_DRIVE_SERVICE_ON_WORKER_H_
187