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_
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 "chrome/browser/google_apis/auth_service_interface.h"
16 #include "chrome/browser/google_apis/auth_service_observer.h"
17 #include "chrome/browser/google_apis/gdata_wapi_requests.h"
18 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h"
21 class OAuth2TokenService;
28 namespace google_apis {
33 class URLRequestContextGetter;
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 {
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::TaskRunner* blocking_task_runner,
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 DownloadFile(
110 const base::FilePath& local_cache_path,
111 const std::string& resource_id,
112 const google_apis::DownloadActionCallback& download_action_callback,
113 const google_apis::GetContentCallback& get_content_callback,
114 const google_apis::ProgressCallback& progress_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 CopyHostedDocument(
122 const std::string& resource_id,
123 const std::string& new_title,
124 const google_apis::GetResourceEntryCallback& callback) OVERRIDE;
125 virtual google_apis::CancelCallback MoveResource(
126 const std::string& resource_id,
127 const std::string& parent_resource_id,
128 const std::string& new_title,
129 const base::Time& last_modified,
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 TouchResource(
136 const std::string& resource_id,
137 const base::Time& modified_date,
138 const base::Time& last_viewed_by_me_date,
139 const google_apis::GetResourceEntryCallback& callback) OVERRIDE;
140 virtual google_apis::CancelCallback AddResourceToDirectory(
141 const std::string& parent_resource_id,
142 const std::string& resource_id,
143 const google_apis::EntryActionCallback& callback) OVERRIDE;
144 virtual google_apis::CancelCallback RemoveResourceFromDirectory(
145 const std::string& parent_resource_id,
146 const std::string& resource_id,
147 const google_apis::EntryActionCallback& callback) OVERRIDE;
148 virtual google_apis::CancelCallback AddNewDirectory(
149 const std::string& parent_resource_id,
150 const std::string& directory_title,
151 const google_apis::GetResourceEntryCallback& callback) OVERRIDE;
152 virtual google_apis::CancelCallback InitiateUploadNewFile(
153 const std::string& content_type,
154 int64 content_length,
155 const std::string& parent_resource_id,
156 const std::string& title,
157 const google_apis::InitiateUploadCallback& callback) OVERRIDE;
158 virtual google_apis::CancelCallback InitiateUploadExistingFile(
159 const std::string& content_type,
160 int64 content_length,
161 const std::string& resource_id,
162 const std::string& etag,
163 const google_apis::InitiateUploadCallback& callback) OVERRIDE;
164 virtual google_apis::CancelCallback ResumeUpload(
165 const GURL& upload_url,
166 int64 start_position,
168 int64 content_length,
169 const std::string& content_type,
170 const base::FilePath& local_file_path,
171 const google_apis::UploadRangeCallback& callback,
172 const google_apis::ProgressCallback& progress_callback) OVERRIDE;
173 virtual google_apis::CancelCallback GetUploadStatus(
174 const GURL& upload_url,
175 int64 content_length,
176 const google_apis::UploadRangeCallback& callback) OVERRIDE;
177 virtual google_apis::CancelCallback AuthorizeApp(
178 const std::string& resource_id,
179 const std::string& app_id,
180 const google_apis::AuthorizeAppCallback& callback) OVERRIDE;
181 virtual google_apis::CancelCallback GetResourceListInDirectoryByWapi(
182 const std::string& directory_resource_id,
183 const google_apis::GetResourceListCallback& callback) OVERRIDE;
184 virtual google_apis::CancelCallback GetRemainingResourceList(
185 const GURL& next_link,
186 const google_apis::GetResourceListCallback& callback) OVERRIDE;
189 // AuthService::Observer override.
190 virtual void OnOAuth2RefreshTokenChanged() OVERRIDE;
192 OAuth2TokenService* oauth2_token_service_; // Not owned.
193 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
194 scoped_refptr<base::TaskRunner> blocking_task_runner_;
195 scoped_ptr<google_apis::RequestSender> sender_;
196 ObserverList<DriveServiceObserver> observers_;
197 // Request objects should hold a copy of this, rather than a const
198 // reference, as they may outlive this object.
199 const google_apis::GDataWapiUrlGenerator url_generator_;
200 const std::string custom_user_agent_;
202 DISALLOW_COPY_AND_ASSIGN(GDataWapiService);
207 #endif // CHROME_BROWSER_DRIVE_GDATA_WAPI_SERVICE_H_