Add more checks to investigate SupervisedUserPrefStore crash at startup.
[chromium-blink-merge.git] / chrome / browser / drive / drive_api_service.h
blobc0d1502a790c4924e41961b635e23cdfa62656e6
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 "base/threading/thread_checker.h"
14 #include "chrome/browser/drive/drive_service_interface.h"
15 #include "google_apis/drive/auth_service_interface.h"
16 #include "google_apis/drive/auth_service_observer.h"
17 #include "google_apis/drive/drive_api_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 // |custom_user_agent| will be used for the User-Agent header in HTTP
50 // requests issues through the service if the value is not empty.
51 DriveAPIService(
52 OAuth2TokenService* oauth2_token_service,
53 net::URLRequestContextGetter* url_request_context_getter,
54 base::SequencedTaskRunner* blocking_task_runner,
55 const GURL& base_url,
56 const GURL& base_download_url,
57 const std::string& custom_user_agent);
58 ~DriveAPIService() override;
60 // DriveServiceInterface Overrides
61 void Initialize(const std::string& account_id) override;
62 void AddObserver(DriveServiceObserver* observer) override;
63 void RemoveObserver(DriveServiceObserver* observer) override;
64 bool CanSendRequest() const override;
65 bool HasAccessToken() const override;
66 void RequestAccessToken(
67 const google_apis::AuthStatusCallback& callback) override;
68 bool HasRefreshToken() const override;
69 void ClearAccessToken() override;
70 void ClearRefreshToken() override;
71 std::string GetRootResourceId() const override;
72 google_apis::CancelCallback GetAllFileList(
73 const google_apis::FileListCallback& callback) override;
74 google_apis::CancelCallback GetFileListInDirectory(
75 const std::string& directory_resource_id,
76 const google_apis::FileListCallback& callback) override;
77 google_apis::CancelCallback Search(
78 const std::string& search_query,
79 const google_apis::FileListCallback& callback) override;
80 google_apis::CancelCallback SearchByTitle(
81 const std::string& title,
82 const std::string& directory_resource_id,
83 const google_apis::FileListCallback& callback) override;
84 google_apis::CancelCallback GetChangeList(
85 int64 start_changestamp,
86 const google_apis::ChangeListCallback& callback) override;
87 google_apis::CancelCallback GetRemainingChangeList(
88 const GURL& next_link,
89 const google_apis::ChangeListCallback& callback) override;
90 google_apis::CancelCallback GetRemainingFileList(
91 const GURL& next_link,
92 const google_apis::FileListCallback& callback) override;
93 google_apis::CancelCallback GetFileResource(
94 const std::string& resource_id,
95 const google_apis::FileResourceCallback& callback) override;
96 google_apis::CancelCallback GetShareUrl(
97 const std::string& resource_id,
98 const GURL& embed_origin,
99 const google_apis::GetShareUrlCallback& callback) override;
100 google_apis::CancelCallback GetAboutResource(
101 const google_apis::AboutResourceCallback& callback) override;
102 google_apis::CancelCallback GetAppList(
103 const google_apis::AppListCallback& callback) override;
104 google_apis::CancelCallback DeleteResource(
105 const std::string& resource_id,
106 const std::string& etag,
107 const google_apis::EntryActionCallback& callback) override;
108 google_apis::CancelCallback TrashResource(
109 const std::string& resource_id,
110 const google_apis::EntryActionCallback& callback) override;
111 google_apis::CancelCallback DownloadFile(
112 const base::FilePath& local_cache_path,
113 const std::string& resource_id,
114 const google_apis::DownloadActionCallback& download_action_callback,
115 const google_apis::GetContentCallback& get_content_callback,
116 const google_apis::ProgressCallback& progress_callback) override;
117 google_apis::CancelCallback CopyResource(
118 const std::string& resource_id,
119 const std::string& parent_resource_id,
120 const std::string& new_title,
121 const base::Time& last_modified,
122 const google_apis::FileResourceCallback& callback) override;
123 google_apis::CancelCallback UpdateResource(
124 const std::string& resource_id,
125 const std::string& parent_resource_id,
126 const std::string& new_title,
127 const base::Time& last_modified,
128 const base::Time& last_viewed_by_me,
129 const google_apis::drive::Properties& properties,
130 const google_apis::FileResourceCallback& callback) override;
131 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 google_apis::CancelCallback RemoveResourceFromDirectory(
136 const std::string& parent_resource_id,
137 const std::string& resource_id,
138 const google_apis::EntryActionCallback& callback) override;
139 google_apis::CancelCallback AddNewDirectory(
140 const std::string& parent_resource_id,
141 const std::string& directory_title,
142 const AddNewDirectoryOptions& options,
143 const google_apis::FileResourceCallback& callback) override;
144 google_apis::CancelCallback InitiateUploadNewFile(
145 const std::string& content_type,
146 int64 content_length,
147 const std::string& parent_resource_id,
148 const std::string& title,
149 const UploadNewFileOptions& options,
150 const google_apis::InitiateUploadCallback& callback) override;
151 google_apis::CancelCallback InitiateUploadExistingFile(
152 const std::string& content_type,
153 int64 content_length,
154 const std::string& resource_id,
155 const UploadExistingFileOptions& options,
156 const google_apis::InitiateUploadCallback& callback) override;
157 google_apis::CancelCallback ResumeUpload(
158 const GURL& upload_url,
159 int64 start_position,
160 int64 end_position,
161 int64 content_length,
162 const std::string& content_type,
163 const base::FilePath& local_file_path,
164 const google_apis::drive::UploadRangeCallback& callback,
165 const google_apis::ProgressCallback& progress_callback) override;
166 google_apis::CancelCallback GetUploadStatus(
167 const GURL& upload_url,
168 int64 content_length,
169 const google_apis::drive::UploadRangeCallback& callback) override;
170 google_apis::CancelCallback MultipartUploadNewFile(
171 const std::string& content_type,
172 int64 content_length,
173 const std::string& parent_resource_id,
174 const std::string& title,
175 const base::FilePath& local_file_path,
176 const UploadNewFileOptions& options,
177 const google_apis::FileResourceCallback& callback,
178 const google_apis::ProgressCallback& progress_callback) override;
179 google_apis::CancelCallback MultipartUploadExistingFile(
180 const std::string& content_type,
181 int64 content_length,
182 const std::string& resource_id,
183 const base::FilePath& local_file_path,
184 const UploadExistingFileOptions& options,
185 const google_apis::FileResourceCallback& callback,
186 const google_apis::ProgressCallback& progress_callback) override;
187 google_apis::CancelCallback AuthorizeApp(
188 const std::string& resource_id,
189 const std::string& app_id,
190 const google_apis::AuthorizeAppCallback& callback) override;
191 google_apis::CancelCallback UninstallApp(
192 const std::string& app_id,
193 const google_apis::EntryActionCallback& callback) override;
194 google_apis::CancelCallback AddPermission(
195 const std::string& resource_id,
196 const std::string& email,
197 google_apis::drive::PermissionRole role,
198 const google_apis::EntryActionCallback& callback) override;
200 private:
201 // AuthServiceObserver override.
202 void OnOAuth2RefreshTokenChanged() override;
204 // The class is expected to run on UI thread.
205 base::ThreadChecker thread_checker_;
207 OAuth2TokenService* oauth2_token_service_;
208 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
209 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
210 scoped_ptr<google_apis::RequestSender> sender_;
211 ObserverList<DriveServiceObserver> observers_;
212 google_apis::DriveApiUrlGenerator url_generator_;
213 const std::string custom_user_agent_;
215 DISALLOW_COPY_AND_ASSIGN(DriveAPIService);
218 } // namespace drive
220 #endif // CHROME_BROWSER_DRIVE_DRIVE_API_SERVICE_H_