Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / drive / gdata_wapi_service.h
blob1de521ff0163a5fae124bae3e4f9dba7759b0488
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_GDATA_WAPI_SERVICE_H_
6 #define CHROME_BROWSER_DRIVE_GDATA_WAPI_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 "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/gdata_wapi_requests.h"
18 #include "google_apis/drive/gdata_wapi_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;
32 namespace net {
33 class URLRequestContextGetter;
34 } // namespace net
36 namespace drive {
38 // This class provides documents feed service calls for WAPI (codename for
39 // DocumentsList API).
40 // Details of API call are abstracted in each request class and this class
41 // works as a thin wrapper for the API.
42 class GDataWapiService : public DriveServiceInterface,
43 public google_apis::AuthServiceObserver {
44 public:
45 // |oauth2_token_service| is used for obtaining OAuth2 access tokens.
46 // |url_request_context_getter| is used to initialize URLFetcher.
47 // |blocking_task_runner| is used to run blocking tasks (like parsing JSON).
48 // |base_url| is used to generate URLs for communicating with the WAPI
49 // |base_download_url| is used to generate URLs for downloading file with WAPI
50 // |custom_user_agent| is used for the User-Agent header in HTTP
51 // requests issued through the service if the value is not empty.
52 GDataWapiService(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 virtual ~GDataWapiService();
60 // DriveServiceInterface Overrides
61 virtual void Initialize(const std::string& account_id) OVERRIDE;
62 virtual void AddObserver(DriveServiceObserver* observer) OVERRIDE;
63 virtual void RemoveObserver(DriveServiceObserver* observer) OVERRIDE;
64 virtual bool CanSendRequest() const OVERRIDE;
65 virtual ResourceIdCanonicalizer GetResourceIdCanonicalizer() const OVERRIDE;
66 virtual bool HasAccessToken() const OVERRIDE;
67 virtual void RequestAccessToken(
68 const google_apis::AuthStatusCallback& callback) OVERRIDE;
69 virtual bool HasRefreshToken() const OVERRIDE;
70 virtual void ClearAccessToken() OVERRIDE;
71 virtual void ClearRefreshToken() OVERRIDE;
72 virtual std::string GetRootResourceId() const OVERRIDE;
73 virtual google_apis::CancelCallback GetAllResourceList(
74 const google_apis::GetResourceListCallback& callback) OVERRIDE;
75 virtual google_apis::CancelCallback GetResourceListInDirectory(
76 const std::string& directory_resource_id,
77 const google_apis::GetResourceListCallback& callback) OVERRIDE;
78 virtual google_apis::CancelCallback Search(
79 const std::string& search_query,
80 const google_apis::GetResourceListCallback& callback) OVERRIDE;
81 virtual google_apis::CancelCallback SearchByTitle(
82 const std::string& title,
83 const std::string& directory_resource_id,
84 const google_apis::GetResourceListCallback& callback) OVERRIDE;
85 virtual google_apis::CancelCallback GetChangeList(
86 int64 start_changestamp,
87 const google_apis::GetResourceListCallback& callback) OVERRIDE;
88 virtual google_apis::CancelCallback GetRemainingChangeList(
89 const GURL& next_link,
90 const google_apis::GetResourceListCallback& callback) OVERRIDE;
91 virtual google_apis::CancelCallback GetRemainingFileList(
92 const GURL& next_link,
93 const google_apis::GetResourceListCallback& callback) OVERRIDE;
94 virtual google_apis::CancelCallback GetResourceEntry(
95 const std::string& resource_id,
96 const google_apis::GetResourceEntryCallback& callback) OVERRIDE;
97 virtual google_apis::CancelCallback GetShareUrl(
98 const std::string& resource_id,
99 const GURL& embed_origin,
100 const google_apis::GetShareUrlCallback& callback) OVERRIDE;
101 virtual google_apis::CancelCallback GetAboutResource(
102 const google_apis::AboutResourceCallback& callback) OVERRIDE;
103 virtual google_apis::CancelCallback GetAppList(
104 const google_apis::AppListCallback& callback) OVERRIDE;
105 virtual google_apis::CancelCallback DeleteResource(
106 const std::string& resource_id,
107 const std::string& etag,
108 const google_apis::EntryActionCallback& callback) OVERRIDE;
109 virtual google_apis::CancelCallback TrashResource(
110 const std::string& resource_id,
111 const google_apis::EntryActionCallback& callback) OVERRIDE;
112 virtual google_apis::CancelCallback DownloadFile(
113 const base::FilePath& local_cache_path,
114 const std::string& resource_id,
115 const google_apis::DownloadActionCallback& download_action_callback,
116 const google_apis::GetContentCallback& get_content_callback,
117 const google_apis::ProgressCallback& progress_callback) OVERRIDE;
118 virtual google_apis::CancelCallback CopyResource(
119 const std::string& resource_id,
120 const std::string& parent_resource_id,
121 const std::string& new_title,
122 const base::Time& last_modified,
123 const google_apis::GetResourceEntryCallback& callback) OVERRIDE;
124 virtual google_apis::CancelCallback UpdateResource(
125 const std::string& resource_id,
126 const std::string& parent_resource_id,
127 const std::string& new_title,
128 const base::Time& last_modified,
129 const base::Time& last_viewed_by_me,
130 const google_apis::GetResourceEntryCallback& callback) OVERRIDE;
131 virtual google_apis::CancelCallback RenameResource(
132 const std::string& resource_id,
133 const std::string& new_title,
134 const google_apis::EntryActionCallback& callback) OVERRIDE;
135 virtual google_apis::CancelCallback AddResourceToDirectory(
136 const std::string& parent_resource_id,
137 const std::string& resource_id,
138 const google_apis::EntryActionCallback& callback) OVERRIDE;
139 virtual google_apis::CancelCallback RemoveResourceFromDirectory(
140 const std::string& parent_resource_id,
141 const std::string& resource_id,
142 const google_apis::EntryActionCallback& callback) OVERRIDE;
143 virtual google_apis::CancelCallback AddNewDirectory(
144 const std::string& parent_resource_id,
145 const std::string& directory_title,
146 const google_apis::GetResourceEntryCallback& callback) OVERRIDE;
147 virtual 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 google_apis::InitiateUploadCallback& callback) OVERRIDE;
153 virtual google_apis::CancelCallback InitiateUploadExistingFile(
154 const std::string& content_type,
155 int64 content_length,
156 const std::string& resource_id,
157 const std::string& etag,
158 const google_apis::InitiateUploadCallback& callback) OVERRIDE;
159 virtual google_apis::CancelCallback ResumeUpload(
160 const GURL& upload_url,
161 int64 start_position,
162 int64 end_position,
163 int64 content_length,
164 const std::string& content_type,
165 const base::FilePath& local_file_path,
166 const google_apis::UploadRangeCallback& callback,
167 const google_apis::ProgressCallback& progress_callback) OVERRIDE;
168 virtual google_apis::CancelCallback GetUploadStatus(
169 const GURL& upload_url,
170 int64 content_length,
171 const google_apis::UploadRangeCallback& callback) OVERRIDE;
172 virtual google_apis::CancelCallback AuthorizeApp(
173 const std::string& resource_id,
174 const std::string& app_id,
175 const google_apis::AuthorizeAppCallback& callback) OVERRIDE;
176 virtual google_apis::CancelCallback UninstallApp(
177 const std::string& app_id,
178 const google_apis::EntryActionCallback& callback) OVERRIDE;
179 virtual google_apis::CancelCallback GetResourceListInDirectoryByWapi(
180 const std::string& directory_resource_id,
181 const google_apis::GetResourceListCallback& callback) OVERRIDE;
182 virtual google_apis::CancelCallback GetRemainingResourceList(
183 const GURL& next_link,
184 const google_apis::GetResourceListCallback& callback) OVERRIDE;
186 private:
187 // AuthService::Observer override.
188 virtual void OnOAuth2RefreshTokenChanged() OVERRIDE;
190 OAuth2TokenService* oauth2_token_service_; // Not owned.
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 // Request objects should hold a copy of this, rather than a const
196 // reference, as they may outlive this object.
197 const google_apis::GDataWapiUrlGenerator url_generator_;
198 const std::string custom_user_agent_;
200 DISALLOW_COPY_AND_ASSIGN(GDataWapiService);
203 } // namespace drive
205 #endif // CHROME_BROWSER_DRIVE_GDATA_WAPI_SERVICE_H_