Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata.h

Issue 9582037: Make document service an interface (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Review changes Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_H_
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_H_ 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 std::string refresh_token_; 176 std::string refresh_token_;
177 std::string auth_token_; 177 std::string auth_token_;
178 ObserverList<Observer> observers_; 178 ObserverList<Observer> observers_;
179 179
180 content::NotificationRegistrar registrar_; 180 content::NotificationRegistrar registrar_;
181 base::WeakPtrFactory<GDataAuthService> weak_ptr_factory_; 181 base::WeakPtrFactory<GDataAuthService> weak_ptr_factory_;
182 182
183 DISALLOW_COPY_AND_ASSIGN(GDataAuthService); 183 DISALLOW_COPY_AND_ASSIGN(GDataAuthService);
184 }; 184 };
185 185
186 // This class provides documents feed service calls. 186 // This defines an interface for sharing by DocumentService and
187 class DocumentsService : public GDataAuthService::Observer { 187 // MockDocumentService so that we can do testing of clients of DocumentService.
188 class DocumentsServiceInterface {
188 public: 189 public:
189 // DocumentsService is usually owned and created by GDataFileSystem. 190 DocumentsServiceInterface();
Ben Chan 2012/03/08 02:01:19 nit: per style guide, the empty default constructo
Greg Spencer (Chromium) 2012/03/08 19:06:35 Done.
190 DocumentsService(); 191 virtual ~DocumentsServiceInterface();
satorux1 2012/03/08 01:48:37 you could inline {} for pure virtual interface cla
Greg Spencer (Chromium) 2012/03/08 19:06:35 Done.
191 virtual ~DocumentsService();
192 192
193 // Initializes the documents service tied with |profile|. 193 // Initializes the documents service tied with |profile|.
194 void Initialize(Profile* profile); 194 virtual void Initialize(Profile* profile) = 0;
195 195
196 // Cancels all in-flight operations. 196 // Cancels all in-flight operations.
197 void CancelAll(); 197 virtual void CancelAll() = 0;
198 198
199 // Authenticates the user by fetching the auth token as 199 // Authenticates the user by fetching the auth token as
200 // needed. |callback| will be run with the error code and the auth 200 // needed. |callback| will be run with the error code and the auth
201 // token, on the thread this function is run. 201 // token, on the thread this function is run.
202 // 202 //
203 // Must be called on UI thread. 203 // Must be called on UI thread.
204 void Authenticate(const AuthStatusCallback& callback); 204 virtual void Authenticate(const AuthStatusCallback& callback) = 0;
205 205
206 // Gets the document feed from |feed_url|. If this URL is empty, the call 206 // Gets the document feed from |feed_url|. If this URL is empty, the call
207 // will fetch the default ('root') document feed. Upon completion, 207 // will fetch the default ('root') document feed. Upon completion,
208 // invokes |callback| with results on the calling thread. 208 // invokes |callback| with results on the calling thread.
209 // 209 //
210 // Can be called on any thread. 210 // Can be called on any thread.
211 void GetDocuments(const GURL& feed_url, const GetDataCallback& callback); 211 virtual void GetDocuments(const GURL& feed_url,
212 const GetDataCallback& callback) = 0;
212 213
213 // Delete a document identified by its 'self' |url| and |etag|. 214 // Delete a document identified by its 'self' |url| and |etag|.
Ben Chan 2012/03/08 02:01:19 nit: for consistency, Delete -> Deletes
Greg Spencer (Chromium) 2012/03/08 19:06:35 Done.
214 // Upon completion, invokes |callback| with results on the calling thread. 215 // Upon completion, invokes |callback| with results on the calling thread.
215 // 216 //
216 // Can be called on any thread. 217 // Can be called on any thread.
217 void DeleteDocument(const GURL& document_url, 218 virtual void DeleteDocument(const GURL& document_url,
218 const EntryActionCallback& callback); 219 const EntryActionCallback& callback) = 0;
219 220
220 // Downloads a document identified by its |content_url| in a given |format|. 221 // Downloads a document identified by its |content_url| in a given |format|.
221 // Upon completion, invokes |callback| with results on the calling thread. 222 // Upon completion, invokes |callback| with results on the calling thread.
222 // 223 //
223 // Can be called on any thread. 224 // Can be called on any thread.
224 void DownloadDocument(const GURL& content_url, 225 virtual void DownloadDocument(const GURL& content_url,
225 DocumentExportFormat format, 226 DocumentExportFormat format,
226 const DownloadActionCallback& callback); 227 const DownloadActionCallback& callback) = 0;
227 228
228 // Creates new collection with |directory_name| under parent directory 229 // Creates new collection with |directory_name| under parent directory
229 // identified with |parent_content_url|. If |parent_content_url| is empty, 230 // identified with |parent_content_url|. If |parent_content_url| is empty,
230 // the new collection will be created in the root. Upon completion, 231 // the new collection will be created in the root. Upon completion,
231 // invokes |callback| and passes newly created entry on the calling thread. 232 // invokes |callback| and passes newly created entry on the calling thread.
232 // 233 //
233 // Can be called on any thread. 234 // Can be called on any thread.
234 void CreateDirectory(const GURL& parent_content_url, 235 virtual void CreateDirectory(const GURL& parent_content_url,
235 const FilePath::StringType& directory_name, 236 const FilePath::StringType& directory_name,
236 const GetDataCallback& callback); 237 const GetDataCallback& callback) = 0;
237 238
238 // Downloads a file identified by its |content_url|. Upon completion, invokes 239 // Downloads a file identified by its |content_url|. Upon completion, invokes
239 // |callback| with results on the calling thread. 240 // |callback| with results on the calling thread.
240 // 241 //
241 // Can be called on any thread. 242 // Can be called on any thread.
242 void DownloadFile(const GURL& content_url, 243 virtual void DownloadFile(const GURL& content_url,
243 const DownloadActionCallback& callback); 244 const DownloadActionCallback& callback) = 0;
244 245
245 // Initiate uploading of a document/file. 246 // Initiate uploading of a document/file.
Ben Chan 2012/03/08 02:01:19 nit: for consistency, Initiate -> Initiates
Greg Spencer (Chromium) 2012/03/08 19:06:35 Done.
246 // 247 //
247 // Can be called on any thread. 248 // Can be called on any thread.
248 void InitiateUpload(const InitiateUploadParams& params, 249 virtual void InitiateUpload(const InitiateUploadParams& upload_file_info,
satorux1 2012/03/08 01:48:37 upload_file_info -> params
Greg Spencer (Chromium) 2012/03/08 19:06:35 Done. Didn't mean to change this.
249 const InitiateUploadCallback& callback); 250 const InitiateUploadCallback& callback) = 0;
250 251
251 // Resume uploading of a document/file on the calling thread. 252 // Resume uploading of a document/file on the calling thread.
Ben Chan 2012/03/08 02:01:19 nit: for consistency, Resume -> Resumes
Greg Spencer (Chromium) 2012/03/08 19:06:35 Done.
252 // 253 //
253 // Can be called on any thread. 254 // Can be called on any thread.
255 virtual void ResumeUpload(const ResumeUploadParams& upload_file_info,
satorux1 2012/03/08 01:48:37 ditto. params
Greg Spencer (Chromium) 2012/03/08 19:06:35 Done.
256 const ResumeUploadCallback& callback) = 0;
257 };
258
259 // This class provides documents feed service calls.
260 class DocumentsService
261 : public DocumentsServiceInterface,
262 public GDataAuthService::Observer {
263 public:
264 // DocumentsService is usually owned and created by GDataFileSystem.
265 DocumentsService();
266 virtual ~DocumentsService();
267
268 // DocumentsServiceInterface Overrides
269 void Initialize(Profile* profile) OVERRIDE;
satorux1 2012/03/08 01:48:37 Please add 'virtual' to these.
Greg Spencer (Chromium) 2012/03/08 19:06:35 Done. Another casualty of that one bad merge.
270 void CancelAll() OVERRIDE;
271 void Authenticate(const AuthStatusCallback& callback) OVERRIDE;
272 void GetDocuments(const GURL& feed_url,
273 const GetDataCallback& callback) OVERRIDE;
274 void DeleteDocument(const GURL& document_url,
275 const EntryActionCallback& callback) OVERRIDE;
276 void DownloadDocument(const GURL& content_url,
277 DocumentExportFormat format,
278 const DownloadActionCallback& callback) OVERRIDE;
279 void CreateDirectory(const GURL& parent_content_url,
280 const FilePath::StringType& directory_name,
281 const GetDataCallback& callback) OVERRIDE;
282 void DownloadFile(const GURL& content_url,
283 const DownloadActionCallback& callback) OVERRIDE;
284 void InitiateUpload(const InitiateUploadParams& params,
285 const InitiateUploadCallback& callback) OVERRIDE;
254 void ResumeUpload(const ResumeUploadParams& params, 286 void ResumeUpload(const ResumeUploadParams& params,
255 const ResumeUploadCallback& callback); 287 const ResumeUploadCallback& callback) OVERRIDE;
256 288
257 GDataAuthService* gdata_auth_service() { return gdata_auth_service_.get(); } 289 GDataAuthService* gdata_auth_service() { return gdata_auth_service_.get(); }
258 290
259 private: 291 private:
260 // GDataAuthService::Observer override. 292 // GDataAuthService::Observer override.
261 virtual void OnOAuth2RefreshTokenChanged() OVERRIDE; 293 virtual void OnOAuth2RefreshTokenChanged() OVERRIDE;
262 294
263 // Submits an operation implementing the GDataOperationInterface interface 295 // Submits an operation implementing the GDataOperationInterface interface
264 // to run on the UI thread, and makes the operation retry upon authentication 296 // to run on the UI thread, and makes the operation retry upon authentication
265 // failures by calling back to DocumentsService::RetryOperation. 297 // failures by calling back to DocumentsService::RetryOperation.
(...skipping 26 matching lines...) Expand all
292 scoped_ptr<GDataOperationRegistry> operation_registry_; 324 scoped_ptr<GDataOperationRegistry> operation_registry_;
293 base::WeakPtrFactory<DocumentsService> weak_ptr_factory_; 325 base::WeakPtrFactory<DocumentsService> weak_ptr_factory_;
294 base::WeakPtr<DocumentsService> weak_ptr_bound_to_ui_thread_; 326 base::WeakPtr<DocumentsService> weak_ptr_bound_to_ui_thread_;
295 327
296 DISALLOW_COPY_AND_ASSIGN(DocumentsService); 328 DISALLOW_COPY_AND_ASSIGN(DocumentsService);
297 }; 329 };
298 330
299 } // namespace gdata 331 } // namespace gdata
300 332
301 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_H_ 333 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/gdata/gdata.cc » ('j') | chrome/browser/chromeos/gdata/gdata.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698