Give names to all utility processes.
[chromium-blink-merge.git] / chrome / browser / drive / drive_api_service.h
blob61a655009618a29a7d6250380a15a8fd47062664
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_DRIVE_DRIVE_API_SERVICE_H_
6 #define CHROME_BROWSER_DRIVE_DRIVE_API_SERVICE_H_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "base/threading/thread_checker.h"
15 #include "chrome/browser/drive/drive_service_interface.h"
16 #include "google_apis/drive/auth_service_interface.h"
17 #include "google_apis/drive/auth_service_observer.h"
18 #include "google_apis/drive/drive_api_url_generator.h"
20 class GURL;
21 class OAuth2TokenService;
23 namespace base {
24 class FilePath;
25 class SequencedTaskRunner;
28 namespace google_apis {
29 class RequestSender;
30 namespace drive {
31 class BatchUploadRequest;
32 } // namespace drive
33 } // namespace google_apis
35 namespace net {
36 class URLRequestContextGetter;
37 } // namespace net
39 namespace drive {
41 // Builder for batch request returned by |DriveAPIService|.
42 class BatchRequestConfigurator : public BatchRequestConfiguratorInterface,
43 public base::NonThreadSafe {
44 public:
45 BatchRequestConfigurator(
46 const base::WeakPtr<google_apis::drive::BatchUploadRequest>&
47 batch_request,
48 const google_apis::CancelCallback& cancel_callback);
49 ~BatchRequestConfigurator() override;
51 // BatchRequestConfiguratorInterface overrides.
52 google_apis::CancelCallback MultipartUploadNewFile(
53 const std::string& content_type,
54 int64 content_length,
55 const std::string& parent_resource_id,
56 const std::string& title,
57 const base::FilePath& local_file_path,
58 const UploadNewFileOptions& options,
59 const google_apis::FileResourceCallback& callback,
60 const google_apis::ProgressCallback& progress_callback) override;
61 google_apis::CancelCallback MultipartUploadExistingFile(
62 const std::string& content_type,
63 int64 content_length,
64 const std::string& resource_id,
65 const base::FilePath& local_file_path,
66 const UploadExistingFileOptions& options,
67 const google_apis::FileResourceCallback& callback,
68 const google_apis::ProgressCallback& progress_callback) override;
69 void Commit() override;
71 private:
72 // Reference to batch request. It turns to null after committing.
73 base::WeakPtr<google_apis::drive::BatchUploadRequest> batch_request_;
74 google_apis::CancelCallback cancel_callback_;
76 DISALLOW_COPY_AND_ASSIGN(BatchRequestConfigurator);
79 // This class provides Drive request calls using Drive V2 API.
80 // Details of API call are abstracted in each request class and this class
81 // works as a thin wrapper for the API.
82 class DriveAPIService : public DriveServiceInterface,
83 public google_apis::AuthServiceObserver {
84 public:
85 // |oauth2_token_service| is used for obtaining OAuth2 access tokens.
86 // |url_request_context_getter| is used to initialize URLFetcher.
87 // |blocking_task_runner| is used to run blocking tasks (like parsing JSON).
88 // |base_url| is used to generate URLs for communication with the drive API.
89 // |base_download_url| is used to generate URLs for downloading file from the
90 // drive API.
91 // |custom_user_agent| will be used for the User-Agent header in HTTP
92 // requests issues through the service if the value is not empty.
93 DriveAPIService(
94 OAuth2TokenService* oauth2_token_service,
95 net::URLRequestContextGetter* url_request_context_getter,
96 base::SequencedTaskRunner* blocking_task_runner,
97 const GURL& base_url,
98 const GURL& base_download_url,
99 const std::string& custom_user_agent);
100 ~DriveAPIService() override;
102 // DriveServiceInterface Overrides
103 void Initialize(const std::string& account_id) override;
104 void AddObserver(DriveServiceObserver* observer) override;
105 void RemoveObserver(DriveServiceObserver* observer) override;
106 bool CanSendRequest() const override;
107 bool HasAccessToken() const override;
108 void RequestAccessToken(
109 const google_apis::AuthStatusCallback& callback) override;
110 bool HasRefreshToken() const override;
111 void ClearAccessToken() override;
112 void ClearRefreshToken() override;
113 std::string GetRootResourceId() const override;
114 google_apis::CancelCallback GetAllFileList(
115 const google_apis::FileListCallback& callback) override;
116 google_apis::CancelCallback GetFileListInDirectory(
117 const std::string& directory_resource_id,
118 const google_apis::FileListCallback& callback) override;
119 google_apis::CancelCallback Search(
120 const std::string& search_query,
121 const google_apis::FileListCallback& callback) override;
122 google_apis::CancelCallback SearchByTitle(
123 const std::string& title,
124 const std::string& directory_resource_id,
125 const google_apis::FileListCallback& callback) override;
126 google_apis::CancelCallback GetChangeList(
127 int64 start_changestamp,
128 const google_apis::ChangeListCallback& callback) override;
129 google_apis::CancelCallback GetRemainingChangeList(
130 const GURL& next_link,
131 const google_apis::ChangeListCallback& callback) override;
132 google_apis::CancelCallback GetRemainingFileList(
133 const GURL& next_link,
134 const google_apis::FileListCallback& callback) override;
135 google_apis::CancelCallback GetFileResource(
136 const std::string& resource_id,
137 const google_apis::FileResourceCallback& callback) override;
138 google_apis::CancelCallback GetShareUrl(
139 const std::string& resource_id,
140 const GURL& embed_origin,
141 const google_apis::GetShareUrlCallback& callback) override;
142 google_apis::CancelCallback GetAboutResource(
143 const google_apis::AboutResourceCallback& callback) override;
144 google_apis::CancelCallback GetAppList(
145 const google_apis::AppListCallback& callback) override;
146 google_apis::CancelCallback DeleteResource(
147 const std::string& resource_id,
148 const std::string& etag,
149 const google_apis::EntryActionCallback& callback) override;
150 google_apis::CancelCallback TrashResource(
151 const std::string& resource_id,
152 const google_apis::EntryActionCallback& callback) override;
153 google_apis::CancelCallback DownloadFile(
154 const base::FilePath& local_cache_path,
155 const std::string& resource_id,
156 const google_apis::DownloadActionCallback& download_action_callback,
157 const google_apis::GetContentCallback& get_content_callback,
158 const google_apis::ProgressCallback& progress_callback) override;
159 google_apis::CancelCallback CopyResource(
160 const std::string& resource_id,
161 const std::string& parent_resource_id,
162 const std::string& new_title,
163 const base::Time& last_modified,
164 const google_apis::FileResourceCallback& callback) override;
165 google_apis::CancelCallback UpdateResource(
166 const std::string& resource_id,
167 const std::string& parent_resource_id,
168 const std::string& new_title,
169 const base::Time& last_modified,
170 const base::Time& last_viewed_by_me,
171 const google_apis::drive::Properties& properties,
172 const google_apis::FileResourceCallback& callback) override;
173 google_apis::CancelCallback AddResourceToDirectory(
174 const std::string& parent_resource_id,
175 const std::string& resource_id,
176 const google_apis::EntryActionCallback& callback) override;
177 google_apis::CancelCallback RemoveResourceFromDirectory(
178 const std::string& parent_resource_id,
179 const std::string& resource_id,
180 const google_apis::EntryActionCallback& callback) override;
181 google_apis::CancelCallback AddNewDirectory(
182 const std::string& parent_resource_id,
183 const std::string& directory_title,
184 const AddNewDirectoryOptions& options,
185 const google_apis::FileResourceCallback& callback) override;
186 google_apis::CancelCallback InitiateUploadNewFile(
187 const std::string& content_type,
188 int64 content_length,
189 const std::string& parent_resource_id,
190 const std::string& title,
191 const UploadNewFileOptions& options,
192 const google_apis::InitiateUploadCallback& callback) override;
193 google_apis::CancelCallback InitiateUploadExistingFile(
194 const std::string& content_type,
195 int64 content_length,
196 const std::string& resource_id,
197 const UploadExistingFileOptions& options,
198 const google_apis::InitiateUploadCallback& callback) override;
199 google_apis::CancelCallback ResumeUpload(
200 const GURL& upload_url,
201 int64 start_position,
202 int64 end_position,
203 int64 content_length,
204 const std::string& content_type,
205 const base::FilePath& local_file_path,
206 const google_apis::drive::UploadRangeCallback& callback,
207 const google_apis::ProgressCallback& progress_callback) override;
208 google_apis::CancelCallback GetUploadStatus(
209 const GURL& upload_url,
210 int64 content_length,
211 const google_apis::drive::UploadRangeCallback& callback) override;
212 google_apis::CancelCallback MultipartUploadNewFile(
213 const std::string& content_type,
214 int64 content_length,
215 const std::string& parent_resource_id,
216 const std::string& title,
217 const base::FilePath& local_file_path,
218 const drive::UploadNewFileOptions& options,
219 const google_apis::FileResourceCallback& callback,
220 const google_apis::ProgressCallback& progress_callback) override;
221 google_apis::CancelCallback MultipartUploadExistingFile(
222 const std::string& content_type,
223 int64 content_length,
224 const std::string& resource_id,
225 const base::FilePath& local_file_path,
226 const drive::UploadExistingFileOptions& options,
227 const google_apis::FileResourceCallback& callback,
228 const google_apis::ProgressCallback& progress_callback) override;
229 google_apis::CancelCallback AuthorizeApp(
230 const std::string& resource_id,
231 const std::string& app_id,
232 const google_apis::AuthorizeAppCallback& callback) override;
233 google_apis::CancelCallback UninstallApp(
234 const std::string& app_id,
235 const google_apis::EntryActionCallback& callback) override;
236 google_apis::CancelCallback AddPermission(
237 const std::string& resource_id,
238 const std::string& email,
239 google_apis::drive::PermissionRole role,
240 const google_apis::EntryActionCallback& callback) override;
241 scoped_ptr<BatchRequestConfiguratorInterface> StartBatchRequest() override;
243 private:
244 // AuthServiceObserver override.
245 void OnOAuth2RefreshTokenChanged() override;
247 // The class is expected to run on UI thread.
248 base::ThreadChecker thread_checker_;
250 OAuth2TokenService* oauth2_token_service_;
251 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
252 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
253 scoped_ptr<google_apis::RequestSender> sender_;
254 ObserverList<DriveServiceObserver> observers_;
255 google_apis::DriveApiUrlGenerator url_generator_;
256 const std::string custom_user_agent_;
258 DISALLOW_COPY_AND_ASSIGN(DriveAPIService);
261 } // namespace drive
263 #endif // CHROME_BROWSER_DRIVE_DRIVE_API_SERVICE_H_