Roll src/third_party/WebKit 8b42d1d:744641d (svn 186770:186771)
[chromium-blink-merge.git] / chrome / browser / drive / drive_api_service.h
blob569d89aa1810ae5b712d0b13576ded925985ecde
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/observer_list.h"
13 #include "chrome/browser/drive/drive_service_interface.h"
14 #include "google_apis/drive/auth_service_interface.h"
15 #include "google_apis/drive/auth_service_observer.h"
16 #include "google_apis/drive/drive_api_url_generator.h"
17 #include "google_apis/drive/gdata_wapi_url_generator.h"
19 class GURL;
20 class OAuth2TokenService;
22 namespace base {
23 class FilePath;
24 class SequencedTaskRunner;
27 namespace google_apis {
28 class RequestSender;
31 namespace net {
32 class URLRequestContextGetter;
33 } // namespace net
35 namespace drive {
37 // This class provides Drive request calls using Drive V2 API.
38 // Details of API call are abstracted in each request class and this class
39 // works as a thin wrapper for the API.
40 class DriveAPIService : public DriveServiceInterface,
41 public google_apis::AuthServiceObserver {
42 public:
43 // |oauth2_token_service| is used for obtaining OAuth2 access tokens.
44 // |url_request_context_getter| is used to initialize URLFetcher.
45 // |blocking_task_runner| is used to run blocking tasks (like parsing JSON).
46 // |base_url| is used to generate URLs for communication with the drive API.
47 // |base_download_url| is used to generate URLs for downloading file from the
48 // drive API.
49 // |wapi_base_url| is used to generate URLs for shared_url. Unfortunately,
50 // the share_url is not yet supported on Drive API v2, so as a fallback,
51 // we use GData WAPI.
52 // |custom_user_agent| will be used for the User-Agent header in HTTP
53 // requests issues through the service if the value is not empty.
54 DriveAPIService(
55 OAuth2TokenService* oauth2_token_service,
56 net::URLRequestContextGetter* url_request_context_getter,
57 base::SequencedTaskRunner* blocking_task_runner,
58 const GURL& base_url,
59 const GURL& base_download_url,
60 const GURL& wapi_base_url,
61 const std::string& custom_user_agent);
62 ~DriveAPIService() override;
64 // DriveServiceInterface Overrides
65 void Initialize(const std::string& account_id) override;
66 void AddObserver(DriveServiceObserver* observer) override;
67 void RemoveObserver(DriveServiceObserver* observer) override;
68 bool CanSendRequest() const override;
69 bool HasAccessToken() const override;
70 void RequestAccessToken(
71 const google_apis::AuthStatusCallback& callback) override;
72 bool HasRefreshToken() const override;
73 void ClearAccessToken() override;
74 void ClearRefreshToken() override;
75 std::string GetRootResourceId() const override;
76 google_apis::CancelCallback GetAllFileList(
77 const google_apis::FileListCallback& callback) override;
78 google_apis::CancelCallback GetFileListInDirectory(
79 const std::string& directory_resource_id,
80 const google_apis::FileListCallback& callback) override;
81 google_apis::CancelCallback Search(
82 const std::string& search_query,
83 const google_apis::FileListCallback& callback) override;
84 google_apis::CancelCallback SearchByTitle(
85 const std::string& title,
86 const std::string& directory_resource_id,
87 const google_apis::FileListCallback& callback) override;
88 google_apis::CancelCallback GetChangeList(
89 int64 start_changestamp,
90 const google_apis::ChangeListCallback& callback) override;
91 google_apis::CancelCallback GetRemainingChangeList(
92 const GURL& next_link,
93 const google_apis::ChangeListCallback& callback) override;
94 google_apis::CancelCallback GetRemainingFileList(
95 const GURL& next_link,
96 const google_apis::FileListCallback& callback) override;
97 google_apis::CancelCallback GetFileResource(
98 const std::string& resource_id,
99 const google_apis::FileResourceCallback& callback) override;
100 google_apis::CancelCallback GetShareUrl(
101 const std::string& resource_id,
102 const GURL& embed_origin,
103 const google_apis::GetShareUrlCallback& callback) override;
104 google_apis::CancelCallback GetAboutResource(
105 const google_apis::AboutResourceCallback& callback) override;
106 google_apis::CancelCallback GetAppList(
107 const google_apis::AppListCallback& callback) override;
108 google_apis::CancelCallback DeleteResource(
109 const std::string& resource_id,
110 const std::string& etag,
111 const google_apis::EntryActionCallback& callback) override;
112 google_apis::CancelCallback TrashResource(
113 const std::string& resource_id,
114 const google_apis::EntryActionCallback& callback) override;
115 google_apis::CancelCallback DownloadFile(
116 const base::FilePath& local_cache_path,
117 const std::string& resource_id,
118 const google_apis::DownloadActionCallback& download_action_callback,
119 const google_apis::GetContentCallback& get_content_callback,
120 const google_apis::ProgressCallback& progress_callback) override;
121 google_apis::CancelCallback CopyResource(
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 google_apis::FileResourceCallback& callback) override;
127 google_apis::CancelCallback UpdateResource(
128 const std::string& resource_id,
129 const std::string& parent_resource_id,
130 const std::string& new_title,
131 const base::Time& last_modified,
132 const base::Time& last_viewed_by_me,
133 const google_apis::FileResourceCallback& callback) override;
134 google_apis::CancelCallback AddResourceToDirectory(
135 const std::string& parent_resource_id,
136 const std::string& resource_id,
137 const google_apis::EntryActionCallback& callback) override;
138 google_apis::CancelCallback RemoveResourceFromDirectory(
139 const std::string& parent_resource_id,
140 const std::string& resource_id,
141 const google_apis::EntryActionCallback& callback) override;
142 google_apis::CancelCallback AddNewDirectory(
143 const std::string& parent_resource_id,
144 const std::string& directory_title,
145 const AddNewDirectoryOptions& options,
146 const google_apis::FileResourceCallback& callback) override;
147 google_apis::CancelCallback InitiateUploadNewFile(
148 const std::string& content_type,
149 int64 content_length,
150 const std::string& parent_resource_id,
151 const std::string& title,
152 const InitiateUploadNewFileOptions& options,
153 const google_apis::InitiateUploadCallback& callback) override;
154 google_apis::CancelCallback InitiateUploadExistingFile(
155 const std::string& content_type,
156 int64 content_length,
157 const std::string& resource_id,
158 const InitiateUploadExistingFileOptions& options,
159 const google_apis::InitiateUploadCallback& callback) override;
160 google_apis::CancelCallback ResumeUpload(
161 const GURL& upload_url,
162 int64 start_position,
163 int64 end_position,
164 int64 content_length,
165 const std::string& content_type,
166 const base::FilePath& local_file_path,
167 const google_apis::drive::UploadRangeCallback& callback,
168 const google_apis::ProgressCallback& progress_callback) override;
169 google_apis::CancelCallback GetUploadStatus(
170 const GURL& upload_url,
171 int64 content_length,
172 const google_apis::drive::UploadRangeCallback& callback) override;
173 google_apis::CancelCallback AuthorizeApp(
174 const std::string& resource_id,
175 const std::string& app_id,
176 const google_apis::AuthorizeAppCallback& callback) override;
177 google_apis::CancelCallback UninstallApp(
178 const std::string& app_id,
179 const google_apis::EntryActionCallback& callback) override;
180 google_apis::CancelCallback AddPermission(
181 const std::string& resource_id,
182 const std::string& email,
183 google_apis::drive::PermissionRole role,
184 const google_apis::EntryActionCallback& callback) override;
186 private:
187 // AuthServiceObserver override.
188 void OnOAuth2RefreshTokenChanged() override;
190 OAuth2TokenService* oauth2_token_service_;
191 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
192 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
193 scoped_ptr<google_apis::RequestSender> sender_;
194 ObserverList<DriveServiceObserver> observers_;
195 google_apis::DriveApiUrlGenerator url_generator_;
196 google_apis::GDataWapiUrlGenerator wapi_url_generator_;
197 const std::string custom_user_agent_;
199 DISALLOW_COPY_AND_ASSIGN(DriveAPIService);
202 } // namespace drive
204 #endif // CHROME_BROWSER_DRIVE_DRIVE_API_SERVICE_H_