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

Side by Side Diff: chrome/browser/google_apis/base_operations.h

Issue 15333013: Replace most of the occurrence of OperationRegistry with OperationRunner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
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 // This file provides base classes used to implement operations for Google APIs. 5 // This file provides base classes used to implement operations for Google APIs.
6 6
7 #ifndef CHROME_BROWSER_GOOGLE_APIS_BASE_OPERATIONS_H_ 7 #ifndef CHROME_BROWSER_GOOGLE_APIS_BASE_OPERATIONS_H_
8 #define CHROME_BROWSER_GOOGLE_APIS_BASE_OPERATIONS_H_ 8 #define CHROME_BROWSER_GOOGLE_APIS_BASE_OPERATIONS_H_
9 9
10 #include <string> 10 #include <string>
(...skipping 10 matching lines...) Expand all
21 namespace base { 21 namespace base {
22 class Value; 22 class Value;
23 } // namespace base 23 } // namespace base
24 24
25 namespace net { 25 namespace net {
26 class URLRequestContextGetter; 26 class URLRequestContextGetter;
27 } // namespace net 27 } // namespace net
28 28
29 namespace google_apis { 29 namespace google_apis {
30 30
31 class OperationRunner;
32
31 // Callback used to pass parsed JSON from ParseJson(). If parsing error occurs, 33 // Callback used to pass parsed JSON from ParseJson(). If parsing error occurs,
32 // then the passed argument is null. 34 // then the passed argument is null.
33 typedef base::Callback<void(scoped_ptr<base::Value> value)> ParseJsonCallback; 35 typedef base::Callback<void(scoped_ptr<base::Value> value)> ParseJsonCallback;
34 36
35 // Callback used for DownloadOperation and ResumeUploadOperation. 37 // Callback used for DownloadOperation and ResumeUploadOperation.
36 typedef base::Callback<void(int64 progress, int64 total)> ProgressCallback; 38 typedef base::Callback<void(int64 progress, int64 total)> ProgressCallback;
37 39
38 // Parses JSON passed in |json| on blocking pool. Runs |callback| on the calling 40 // Parses JSON passed in |json| on blocking pool. Runs |callback| on the calling
39 // thread when finished with either success or failure. 41 // thread when finished with either success or failure.
40 // The callback must not be null. 42 // The callback must not be null.
(...skipping 29 matching lines...) Expand all
70 // Gets a weak pointer to this operation object. Since operations may be 72 // Gets a weak pointer to this operation object. Since operations may be
71 // deleted when it is canceled by user action, for posting asynchronous tasks 73 // deleted when it is canceled by user action, for posting asynchronous tasks
72 // on the authentication operation object, weak pointers have to be used. 74 // on the authentication operation object, weak pointers have to be used.
73 // TODO(kinaba): crbug.com/134814 use more clean life time management than 75 // TODO(kinaba): crbug.com/134814 use more clean life time management than
74 // using weak pointers, while deprecating OperationRegistry. 76 // using weak pointers, while deprecating OperationRegistry.
75 virtual base::WeakPtr<AuthenticatedOperationInterface> GetWeakPtr() = 0; 77 virtual base::WeakPtr<AuthenticatedOperationInterface> GetWeakPtr() = 0;
76 }; 78 };
77 79
78 //============================ UrlFetchOperationBase =========================== 80 //============================ UrlFetchOperationBase ===========================
79 81
80 // Callback type for getting the content from URLFetcher::GetResponseAsString().
81 typedef base::Callback<void(
82 GDataErrorCode error,
83 scoped_ptr<std::string> content)> GetContentCallback;
84
85 // Base class for operations that are fetching URLs. 82 // Base class for operations that are fetching URLs.
86 class UrlFetchOperationBase : public AuthenticatedOperationInterface, 83 class UrlFetchOperationBase : public AuthenticatedOperationInterface,
87 public OperationRegistry::Operation, 84 public OperationRegistry::Operation,
88 public net::URLFetcherDelegate { 85 public net::URLFetcherDelegate {
89 public: 86 public:
90 // AuthenticatedOperationInterface overrides. 87 // AuthenticatedOperationInterface overrides.
91 virtual void Start(const std::string& access_token, 88 virtual void Start(const std::string& access_token,
92 const std::string& custom_user_agent, 89 const std::string& custom_user_agent,
93 const ReAuthenticateCallback& callback) OVERRIDE; 90 const ReAuthenticateCallback& callback) OVERRIDE;
94 virtual base::WeakPtr<AuthenticatedOperationInterface> GetWeakPtr() OVERRIDE; 91 virtual base::WeakPtr<AuthenticatedOperationInterface> GetWeakPtr() OVERRIDE;
95 92
96 protected: 93 protected:
97 explicit UrlFetchOperationBase( 94 UrlFetchOperationBase(
98 OperationRegistry* registry, 95 OperationRunner* runner,
99 net::URLRequestContextGetter* url_request_context_getter); 96 net::URLRequestContextGetter* url_request_context_getter);
100 // Use this constructor when you need to implement operations that take a 97 // Use this constructor when you need to implement operations that take a
101 // drive file path (ex. for downloading and uploading). 98 // drive file path (ex. for downloading and uploading).
102 // |url_request_context_getter| is used to initialize URLFetcher. 99 // |url_request_context_getter| is used to initialize URLFetcher.
103 // TODO(satorux): Remove the drive file path hack. crbug.com/163296 100 // TODO(satorux): Remove the drive file path hack. crbug.com/163296
104 UrlFetchOperationBase( 101 UrlFetchOperationBase(
105 OperationRegistry* registry, 102 OperationRunner* runner,
106 net::URLRequestContextGetter* url_request_context_getter, 103 net::URLRequestContextGetter* url_request_context_getter,
107 const base::FilePath& drive_file_path); 104 const base::FilePath& drive_file_path);
108 virtual ~UrlFetchOperationBase(); 105 virtual ~UrlFetchOperationBase();
109 106
110 // Gets URL for the request. 107 // Gets URL for the request.
111 virtual GURL GetURL() const = 0; 108 virtual GURL GetURL() const = 0;
112 109
113 // Returns the request type. A derived class should override this method 110 // Returns the request type. A derived class should override this method
114 // for a request type other than HTTP GET. 111 // for a request type other than HTTP GET.
115 virtual net::URLFetcher::RequestType GetRequestType() const; 112 virtual net::URLFetcher::RequestType GetRequestType() const;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 // Callback type for Delete/Move DocumentServiceInterface calls. 197 // Callback type for Delete/Move DocumentServiceInterface calls.
201 typedef base::Callback<void(GDataErrorCode error)> EntryActionCallback; 198 typedef base::Callback<void(GDataErrorCode error)> EntryActionCallback;
202 199
203 // This class performs a simple action over a given entry (document/file). 200 // This class performs a simple action over a given entry (document/file).
204 // It is meant to be used for operations that return no JSON blobs. 201 // It is meant to be used for operations that return no JSON blobs.
205 class EntryActionOperation : public UrlFetchOperationBase { 202 class EntryActionOperation : public UrlFetchOperationBase {
206 public: 203 public:
207 // |url_request_context_getter| is used to initialize URLFetcher. 204 // |url_request_context_getter| is used to initialize URLFetcher.
208 // |callback| must not be null. 205 // |callback| must not be null.
209 EntryActionOperation( 206 EntryActionOperation(
210 OperationRegistry* registry, 207 OperationRunner* runner,
211 net::URLRequestContextGetter* url_request_context_getter, 208 net::URLRequestContextGetter* url_request_context_getter,
212 const EntryActionCallback& callback); 209 const EntryActionCallback& callback);
213 virtual ~EntryActionOperation(); 210 virtual ~EntryActionOperation();
214 211
215 protected: 212 protected:
216 // Overridden from UrlFetchOperationBase. 213 // Overridden from UrlFetchOperationBase.
217 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; 214 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE;
218 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; 215 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE;
219 216
220 private: 217 private:
221 const EntryActionCallback callback_; 218 const EntryActionCallback callback_;
222 219
223 DISALLOW_COPY_AND_ASSIGN(EntryActionOperation); 220 DISALLOW_COPY_AND_ASSIGN(EntryActionOperation);
224 }; 221 };
225 222
226 //============================== GetDataOperation ============================== 223 //============================== GetDataOperation ==============================
227 224
228 // Callback type for DocumentServiceInterface::GetResourceList. 225 // Callback type for DocumentServiceInterface::GetResourceList.
229 // Note: json_data argument should be passed using base::Passed(&json_data), not 226 // Note: json_data argument should be passed using base::Passed(&json_data), not
230 // json_data.Pass(). 227 // json_data.Pass().
231 typedef base::Callback<void(GDataErrorCode error, 228 typedef base::Callback<void(GDataErrorCode error,
232 scoped_ptr<base::Value> json_data)> GetDataCallback; 229 scoped_ptr<base::Value> json_data)> GetDataCallback;
233 230
234 // This class performs the operation for fetching and converting the fetched 231 // This class performs the operation for fetching and converting the fetched
235 // content into a base::Value. 232 // content into a base::Value.
236 class GetDataOperation : public UrlFetchOperationBase { 233 class GetDataOperation : public UrlFetchOperationBase {
237 public: 234 public:
238 // |callback| must not be null. 235 // |callback| must not be null.
239 GetDataOperation(OperationRegistry* registry, 236 GetDataOperation(OperationRunner* runner,
240 net::URLRequestContextGetter* url_request_context_getter, 237 net::URLRequestContextGetter* url_request_context_getter,
241 const GetDataCallback& callback); 238 const GetDataCallback& callback);
242 virtual ~GetDataOperation(); 239 virtual ~GetDataOperation();
243 240
244 // Parses JSON response. 241 // Parses JSON response.
245 void ParseResponse(GDataErrorCode fetch_error_code, const std::string& data); 242 void ParseResponse(GDataErrorCode fetch_error_code, const std::string& data);
246 243
247 protected: 244 protected:
248 // UrlFetchOperationBase overrides. 245 // UrlFetchOperationBase overrides.
249 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; 246 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // 3) If there is more data to upload, go to 2). 284 // 3) If there is more data to upload, go to 2).
288 // 285 //
289 class InitiateUploadOperationBase : public UrlFetchOperationBase { 286 class InitiateUploadOperationBase : public UrlFetchOperationBase {
290 protected: 287 protected:
291 // |callback| will be called with the upload URL, where upload data is 288 // |callback| will be called with the upload URL, where upload data is
292 // uploaded to with ResumeUploadOperation. 289 // uploaded to with ResumeUploadOperation.
293 // |callback| must not be null. 290 // |callback| must not be null.
294 // |content_type| and |content_length| should be the attributes of the 291 // |content_type| and |content_length| should be the attributes of the
295 // uploading file. 292 // uploading file.
296 InitiateUploadOperationBase( 293 InitiateUploadOperationBase(
297 OperationRegistry* registry, 294 OperationRunner* runner,
298 net::URLRequestContextGetter* url_request_context_getter, 295 net::URLRequestContextGetter* url_request_context_getter,
299 const InitiateUploadCallback& callback, 296 const InitiateUploadCallback& callback,
300 const base::FilePath& drive_file_path, 297 const base::FilePath& drive_file_path,
301 const std::string& content_type, 298 const std::string& content_type,
302 int64 content_length); 299 int64 content_length);
303 virtual ~InitiateUploadOperationBase(); 300 virtual ~InitiateUploadOperationBase();
304 301
305 // UrlFetchOperationBase overrides. 302 // UrlFetchOperationBase overrides.
306 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; 303 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE;
307 virtual void NotifySuccessToOperationRegistry() OVERRIDE; 304 virtual void NotifySuccessToOperationRegistry() OVERRIDE;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 // Base class for a URL fetch request expecting the response containing the 338 // Base class for a URL fetch request expecting the response containing the
342 // current uploading range. This class processes the response containing 339 // current uploading range. This class processes the response containing
343 // "Range" header and invoke OnRangeOperationComplete. 340 // "Range" header and invoke OnRangeOperationComplete.
344 class UploadRangeOperationBase : public UrlFetchOperationBase { 341 class UploadRangeOperationBase : public UrlFetchOperationBase {
345 protected: 342 protected:
346 // |upload_location| is the URL of where to upload the file to. 343 // |upload_location| is the URL of where to upload the file to.
347 // |drive_file_path| is the path to the file seen in the UI. Not necessary 344 // |drive_file_path| is the path to the file seen in the UI. Not necessary
348 // for resuming an upload, but used for adding an entry to OperationRegistry. 345 // for resuming an upload, but used for adding an entry to OperationRegistry.
349 // TODO(satorux): Remove the drive file path hack. crbug.com/163296 346 // TODO(satorux): Remove the drive file path hack. crbug.com/163296
350 UploadRangeOperationBase( 347 UploadRangeOperationBase(
351 OperationRegistry* registry, 348 OperationRunner* runner,
352 net::URLRequestContextGetter* url_request_context_getter, 349 net::URLRequestContextGetter* url_request_context_getter,
353 const base::FilePath& drive_file_path, 350 const base::FilePath& drive_file_path,
354 const GURL& upload_url); 351 const GURL& upload_url);
355 virtual ~UploadRangeOperationBase(); 352 virtual ~UploadRangeOperationBase();
356 353
357 // UrlFetchOperationBase overrides. 354 // UrlFetchOperationBase overrides.
358 virtual GURL GetURL() const OVERRIDE; 355 virtual GURL GetURL() const OVERRIDE;
359 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; 356 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
360 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; 357 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE;
361 virtual void NotifySuccessToOperationRegistry() OVERRIDE; 358 virtual void NotifySuccessToOperationRegistry() OVERRIDE;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 // |start_position| is the start of range of contents currently stored in 406 // |start_position| is the start of range of contents currently stored in
410 // |buf|. |end_position| is the end of range of contents currently stared in 407 // |buf|. |end_position| is the end of range of contents currently stared in
411 // |buf|. This is exclusive. For instance, if you are to upload the first 408 // |buf|. This is exclusive. For instance, if you are to upload the first
412 // 500 bytes of data, |start_position| is 0 and |end_position| is 500. 409 // 500 bytes of data, |start_position| is 0 and |end_position| is 500.
413 // |content_length| and |content_type| are the length and type of the 410 // |content_length| and |content_type| are the length and type of the
414 // file content to be uploaded respectively. 411 // file content to be uploaded respectively.
415 // |buf| holds current content to be uploaded. 412 // |buf| holds current content to be uploaded.
416 // See also UploadRangeOperationBase's comment for remaining parameters 413 // See also UploadRangeOperationBase's comment for remaining parameters
417 // meaining. 414 // meaining.
418 ResumeUploadOperationBase( 415 ResumeUploadOperationBase(
419 OperationRegistry* registry, 416 OperationRunner* runner,
420 net::URLRequestContextGetter* url_request_context_getter, 417 net::URLRequestContextGetter* url_request_context_getter,
421 const base::FilePath& drive_file_path, 418 const base::FilePath& drive_file_path,
422 const GURL& upload_location, 419 const GURL& upload_location,
423 int64 start_position, 420 int64 start_position,
424 int64 end_position, 421 int64 end_position,
425 int64 content_length, 422 int64 content_length,
426 const std::string& content_type, 423 const std::string& content_type,
427 const base::FilePath& local_file_path); 424 const base::FilePath& local_file_path);
428 virtual ~ResumeUploadOperationBase(); 425 virtual ~ResumeUploadOperationBase();
429 426
(...skipping 25 matching lines...) Expand all
455 // if a file has been partially uploaded. |value| is not used. 452 // if a file has been partially uploaded. |value| is not used.
456 // - HTTP_SUCCESS or HTTP_CREATED (up to the upload mode) and |value| 453 // - HTTP_SUCCESS or HTTP_CREATED (up to the upload mode) and |value|
457 // for the uploaded data, if a file has been completely uploaded. 454 // for the uploaded data, if a file has been completely uploaded.
458 // See also UploadRangeOperationBase. 455 // See also UploadRangeOperationBase.
459 class GetUploadStatusOperationBase : public UploadRangeOperationBase { 456 class GetUploadStatusOperationBase : public UploadRangeOperationBase {
460 public: 457 public:
461 // |content_length| is the whole data size to be uploaded. 458 // |content_length| is the whole data size to be uploaded.
462 // See also UploadRangeOperationBase's constructor comment for other 459 // See also UploadRangeOperationBase's constructor comment for other
463 // parameters. 460 // parameters.
464 GetUploadStatusOperationBase( 461 GetUploadStatusOperationBase(
465 OperationRegistry* registry, 462 OperationRunner* runner,
466 net::URLRequestContextGetter* url_request_context_getter, 463 net::URLRequestContextGetter* url_request_context_getter,
467 const base::FilePath& drive_file_path, 464 const base::FilePath& drive_file_path,
468 const GURL& upload_url, 465 const GURL& upload_url,
469 int64 content_length); 466 int64 content_length);
470 virtual ~GetUploadStatusOperationBase(); 467 virtual ~GetUploadStatusOperationBase();
471 468
472 protected: 469 protected:
473 // UrlFetchOperationBase overrides. 470 // UrlFetchOperationBase overrides.
474 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; 471 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE;
475 472
476 private: 473 private:
477 const int64 content_length_; 474 const int64 content_length_;
478 475
479 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusOperationBase); 476 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusOperationBase);
480 }; 477 };
481 478
482 //============================ DownloadFileOperation =========================== 479 //============================ DownloadFileOperation ===========================
483 480
484 // Callback type for DownloadHostedDocument/DownloadFile 481 // Callback type for getting the content from DownloadFileOperation.
485 // DocumentServiceInterface calls. 482 typedef base::Callback<void(
483 GDataErrorCode error,
484 scoped_ptr<std::string> content)> GetContentCallback;
485
486 // Callback type for receiving the completion of DownloadFileOperation.
486 typedef base::Callback<void(GDataErrorCode error, 487 typedef base::Callback<void(GDataErrorCode error,
487 const base::FilePath& temp_file)> 488 const base::FilePath& temp_file)>
488 DownloadActionCallback; 489 DownloadActionCallback;
489 490
490 // This class performs the operation for downloading of a given document/file. 491 // This class performs the operation for downloading of a given document/file.
491 class DownloadFileOperation : public UrlFetchOperationBase { 492 class DownloadFileOperation : public UrlFetchOperationBase {
492 public: 493 public:
493 // download_action_callback: 494 // download_action_callback:
494 // This callback is called when the download is complete. Must not be null. 495 // This callback is called when the download is complete. Must not be null.
495 // 496 //
496 // get_content_callback: 497 // get_content_callback:
497 // This callback is called when some part of the content is 498 // This callback is called when some part of the content is
498 // read. Used to read the download content progressively. May be null. 499 // read. Used to read the download content progressively. May be null.
499 // 500 //
500 // progress_callback: 501 // progress_callback:
501 // This callback is called for periodically reporting the number of bytes 502 // This callback is called for periodically reporting the number of bytes
502 // downloaded so far. May be null. 503 // downloaded so far. May be null.
503 // 504 //
504 // download_url: 505 // download_url:
505 // Specifies the target file to download. 506 // Specifies the target file to download.
506 // 507 //
507 // drive_file_path: 508 // drive_file_path:
508 // Specifies the drive path of the target file. Shown in UI. 509 // Specifies the drive path of the target file. Shown in UI.
509 // TODO(satorux): Remove the drive file path hack. crbug.com/163296 510 // TODO(satorux): Remove the drive file path hack. crbug.com/163296
510 // 511 //
511 // output_file_path: 512 // output_file_path:
512 // Specifies the file path to save the downloaded file. 513 // Specifies the file path to save the downloaded file.
513 // 514 //
514 DownloadFileOperation( 515 DownloadFileOperation(
515 OperationRegistry* registry, 516 OperationRunner* runner,
516 net::URLRequestContextGetter* url_request_context_getter, 517 net::URLRequestContextGetter* url_request_context_getter,
517 const DownloadActionCallback& download_action_callback, 518 const DownloadActionCallback& download_action_callback,
518 const GetContentCallback& get_content_callback, 519 const GetContentCallback& get_content_callback,
519 const ProgressCallback& progress_callback, 520 const ProgressCallback& progress_callback,
520 const GURL& download_url, 521 const GURL& download_url,
521 const base::FilePath& drive_file_path, 522 const base::FilePath& drive_file_path,
522 const base::FilePath& output_file_path); 523 const base::FilePath& output_file_path);
523 virtual ~DownloadFileOperation(); 524 virtual ~DownloadFileOperation();
524 525
525 protected: 526 protected:
(...skipping 15 matching lines...) Expand all
541 const GetContentCallback get_content_callback_; 542 const GetContentCallback get_content_callback_;
542 const ProgressCallback progress_callback_; 543 const ProgressCallback progress_callback_;
543 const GURL download_url_; 544 const GURL download_url_;
544 545
545 DISALLOW_COPY_AND_ASSIGN(DownloadFileOperation); 546 DISALLOW_COPY_AND_ASSIGN(DownloadFileOperation);
546 }; 547 };
547 548
548 } // namespace google_apis 549 } // namespace google_apis
549 550
550 #endif // CHROME_BROWSER_GOOGLE_APIS_BASE_OPERATIONS_H_ 551 #endif // CHROME_BROWSER_GOOGLE_APIS_BASE_OPERATIONS_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/contacts/gdata_contacts_service.cc ('k') | chrome/browser/google_apis/base_operations.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698