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

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

Issue 16175003: google_apis: Rename OperationRunner to RequestSender (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 6 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 issue HTTP requests for Google 5 // This file provides base classes used to issue HTTP requests for Google
6 // APIs. 6 // APIs.
7 7
8 #ifndef CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_ 8 #ifndef CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_
9 #define CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_ 9 #define CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_
10 10
(...skipping 11 matching lines...) Expand all
22 namespace base { 22 namespace base {
23 class Value; 23 class Value;
24 } // namespace base 24 } // namespace base
25 25
26 namespace net { 26 namespace net {
27 class URLRequestContextGetter; 27 class URLRequestContextGetter;
28 } // namespace net 28 } // namespace net
29 29
30 namespace google_apis { 30 namespace google_apis {
31 31
32 class OperationRunner; 32 class RequestSender;
33 33
34 // Callback used to pass parsed JSON from ParseJson(). If parsing error occurs, 34 // Callback used to pass parsed JSON from ParseJson(). If parsing error occurs,
35 // then the passed argument is null. 35 // then the passed argument is null.
36 typedef base::Callback<void(scoped_ptr<base::Value> value)> ParseJsonCallback; 36 typedef base::Callback<void(scoped_ptr<base::Value> value)> ParseJsonCallback;
37 37
38 // Callback used for DownloadFileRequest and ResumeUploadRequestBase. 38 // Callback used for DownloadFileRequest and ResumeUploadRequestBase.
39 typedef base::Callback<void(int64 progress, int64 total)> ProgressCallback; 39 typedef base::Callback<void(int64 progress, int64 total)> ProgressCallback;
40 40
41 // Parses JSON passed in |json| on blocking pool. Runs |callback| on the calling 41 // Parses JSON passed in |json| on blocking pool. Runs |callback| on the calling
42 // thread when finished with either success or failure. 42 // thread when finished with either success or failure.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 public net::URLFetcherDelegate { 86 public net::URLFetcherDelegate {
87 public: 87 public:
88 // AuthenticatedRequestInterface overrides. 88 // AuthenticatedRequestInterface overrides.
89 virtual void Start(const std::string& access_token, 89 virtual void Start(const std::string& access_token,
90 const std::string& custom_user_agent, 90 const std::string& custom_user_agent,
91 const ReAuthenticateCallback& callback) OVERRIDE; 91 const ReAuthenticateCallback& callback) OVERRIDE;
92 virtual base::WeakPtr<AuthenticatedRequestInterface> GetWeakPtr() OVERRIDE; 92 virtual base::WeakPtr<AuthenticatedRequestInterface> GetWeakPtr() OVERRIDE;
93 93
94 protected: 94 protected:
95 UrlFetchRequestBase( 95 UrlFetchRequestBase(
96 OperationRunner* runner, 96 RequestSender* runner,
97 net::URLRequestContextGetter* url_request_context_getter); 97 net::URLRequestContextGetter* url_request_context_getter);
98 // Use this constructor when you need to implement requests that take a 98 // Use this constructor when you need to implement requests that take a
99 // drive file path (ex. for downloading and uploading). 99 // drive file path (ex. for downloading and uploading).
100 // |url_request_context_getter| is used to initialize URLFetcher. 100 // |url_request_context_getter| is used to initialize URLFetcher.
101 // TODO(satorux): Remove the drive file path hack. crbug.com/163296 101 // TODO(satorux): Remove the drive file path hack. crbug.com/163296
102 UrlFetchRequestBase( 102 UrlFetchRequestBase(
103 OperationRunner* runner, 103 RequestSender* runner,
104 net::URLRequestContextGetter* url_request_context_getter, 104 net::URLRequestContextGetter* url_request_context_getter,
105 const base::FilePath& drive_file_path); 105 const base::FilePath& drive_file_path);
106 virtual ~UrlFetchRequestBase(); 106 virtual ~UrlFetchRequestBase();
107 107
108 // Gets URL for the request. 108 // Gets URL for the request.
109 virtual GURL GetURL() const = 0; 109 virtual GURL GetURL() const = 0;
110 110
111 // Returns the request type. A derived class should override this method 111 // Returns the request type. A derived class should override this method
112 // for a request type other than HTTP GET. 112 // for a request type other than HTTP GET.
113 virtual net::URLFetcher::RequestType GetRequestType() const; 113 virtual net::URLFetcher::RequestType GetRequestType() const;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 // Callback type for Delete/Move DocumentServiceInterface calls. 198 // Callback type for Delete/Move DocumentServiceInterface calls.
199 typedef base::Callback<void(GDataErrorCode error)> EntryActionCallback; 199 typedef base::Callback<void(GDataErrorCode error)> EntryActionCallback;
200 200
201 // This class performs a simple action over a given entry (document/file). 201 // This class performs a simple action over a given entry (document/file).
202 // It is meant to be used for requests that return no JSON blobs. 202 // It is meant to be used for requests that return no JSON blobs.
203 class EntryActionRequest : public UrlFetchRequestBase { 203 class EntryActionRequest : public UrlFetchRequestBase {
204 public: 204 public:
205 // |url_request_context_getter| is used to initialize URLFetcher. 205 // |url_request_context_getter| is used to initialize URLFetcher.
206 // |callback| must not be null. 206 // |callback| must not be null.
207 EntryActionRequest( 207 EntryActionRequest(
208 OperationRunner* runner, 208 RequestSender* runner,
209 net::URLRequestContextGetter* url_request_context_getter, 209 net::URLRequestContextGetter* url_request_context_getter,
210 const EntryActionCallback& callback); 210 const EntryActionCallback& callback);
211 virtual ~EntryActionRequest(); 211 virtual ~EntryActionRequest();
212 212
213 protected: 213 protected:
214 // Overridden from UrlFetchRequestBase. 214 // Overridden from UrlFetchRequestBase.
215 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; 215 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE;
216 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; 216 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE;
217 217
218 private: 218 private:
219 const EntryActionCallback callback_; 219 const EntryActionCallback callback_;
220 220
221 DISALLOW_COPY_AND_ASSIGN(EntryActionRequest); 221 DISALLOW_COPY_AND_ASSIGN(EntryActionRequest);
222 }; 222 };
223 223
224 //============================== GetDataRequest ============================== 224 //============================== GetDataRequest ==============================
225 225
226 // Callback type for DocumentServiceInterface::GetResourceList. 226 // Callback type for DocumentServiceInterface::GetResourceList.
227 // Note: json_data argument should be passed using base::Passed(&json_data), not 227 // Note: json_data argument should be passed using base::Passed(&json_data), not
228 // json_data.Pass(). 228 // json_data.Pass().
229 typedef base::Callback<void(GDataErrorCode error, 229 typedef base::Callback<void(GDataErrorCode error,
230 scoped_ptr<base::Value> json_data)> GetDataCallback; 230 scoped_ptr<base::Value> json_data)> GetDataCallback;
231 231
232 // This class performs the request for fetching and converting the fetched 232 // This class performs the request for fetching and converting the fetched
233 // content into a base::Value. 233 // content into a base::Value.
234 class GetDataRequest : public UrlFetchRequestBase { 234 class GetDataRequest : public UrlFetchRequestBase {
235 public: 235 public:
236 // |callback| must not be null. 236 // |callback| must not be null.
237 GetDataRequest(OperationRunner* runner, 237 GetDataRequest(RequestSender* runner,
238 net::URLRequestContextGetter* url_request_context_getter, 238 net::URLRequestContextGetter* url_request_context_getter,
239 const GetDataCallback& callback); 239 const GetDataCallback& callback);
240 virtual ~GetDataRequest(); 240 virtual ~GetDataRequest();
241 241
242 // Parses JSON response. 242 // Parses JSON response.
243 void ParseResponse(GDataErrorCode fetch_error_code, const std::string& data); 243 void ParseResponse(GDataErrorCode fetch_error_code, const std::string& data);
244 244
245 protected: 245 protected:
246 // UrlFetchRequestBase overrides. 246 // UrlFetchRequestBase overrides.
247 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; 247 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // 3) If there is more data to upload, go to 2). 285 // 3) If there is more data to upload, go to 2).
286 // 286 //
287 class InitiateUploadRequestBase : public UrlFetchRequestBase { 287 class InitiateUploadRequestBase : public UrlFetchRequestBase {
288 protected: 288 protected:
289 // |callback| will be called with the upload URL, where upload data is 289 // |callback| will be called with the upload URL, where upload data is
290 // uploaded to with ResumeUploadRequestBase. 290 // uploaded to with ResumeUploadRequestBase.
291 // |callback| must not be null. 291 // |callback| must not be null.
292 // |content_type| and |content_length| should be the attributes of the 292 // |content_type| and |content_length| should be the attributes of the
293 // uploading file. 293 // uploading file.
294 InitiateUploadRequestBase( 294 InitiateUploadRequestBase(
295 OperationRunner* runner, 295 RequestSender* runner,
296 net::URLRequestContextGetter* url_request_context_getter, 296 net::URLRequestContextGetter* url_request_context_getter,
297 const InitiateUploadCallback& callback, 297 const InitiateUploadCallback& callback,
298 const base::FilePath& drive_file_path, 298 const base::FilePath& drive_file_path,
299 const std::string& content_type, 299 const std::string& content_type,
300 int64 content_length); 300 int64 content_length);
301 virtual ~InitiateUploadRequestBase(); 301 virtual ~InitiateUploadRequestBase();
302 302
303 // UrlFetchRequestBase overrides. 303 // UrlFetchRequestBase overrides.
304 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; 304 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE;
305 virtual void NotifySuccessToOperationRegistry() OVERRIDE; 305 virtual void NotifySuccessToOperationRegistry() OVERRIDE;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 // Base class for a URL fetch request expecting the response containing the 339 // Base class for a URL fetch request expecting the response containing the
340 // current uploading range. This class processes the response containing 340 // current uploading range. This class processes the response containing
341 // "Range" header and invoke OnRangeRequestComplete. 341 // "Range" header and invoke OnRangeRequestComplete.
342 class UploadRangeRequestBase : public UrlFetchRequestBase { 342 class UploadRangeRequestBase : public UrlFetchRequestBase {
343 protected: 343 protected:
344 // |upload_location| is the URL of where to upload the file to. 344 // |upload_location| is the URL of where to upload the file to.
345 // |drive_file_path| is the path to the file seen in the UI. Not necessary 345 // |drive_file_path| is the path to the file seen in the UI. Not necessary
346 // for resuming an upload, but used for adding an entry to OperationRegistry. 346 // for resuming an upload, but used for adding an entry to OperationRegistry.
347 // TODO(satorux): Remove the drive file path hack. crbug.com/163296 347 // TODO(satorux): Remove the drive file path hack. crbug.com/163296
348 UploadRangeRequestBase( 348 UploadRangeRequestBase(
349 OperationRunner* runner, 349 RequestSender* runner,
350 net::URLRequestContextGetter* url_request_context_getter, 350 net::URLRequestContextGetter* url_request_context_getter,
351 const base::FilePath& drive_file_path, 351 const base::FilePath& drive_file_path,
352 const GURL& upload_url); 352 const GURL& upload_url);
353 virtual ~UploadRangeRequestBase(); 353 virtual ~UploadRangeRequestBase();
354 354
355 // UrlFetchRequestBase overrides. 355 // UrlFetchRequestBase overrides.
356 virtual GURL GetURL() const OVERRIDE; 356 virtual GURL GetURL() const OVERRIDE;
357 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; 357 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
358 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; 358 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE;
359 virtual void NotifySuccessToOperationRegistry() OVERRIDE; 359 virtual void NotifySuccessToOperationRegistry() OVERRIDE;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 // |start_position| is the start of range of contents currently stored in 407 // |start_position| is the start of range of contents currently stored in
408 // |buf|. |end_position| is the end of range of contents currently stared in 408 // |buf|. |end_position| is the end of range of contents currently stared in
409 // |buf|. This is exclusive. For instance, if you are to upload the first 409 // |buf|. This is exclusive. For instance, if you are to upload the first
410 // 500 bytes of data, |start_position| is 0 and |end_position| is 500. 410 // 500 bytes of data, |start_position| is 0 and |end_position| is 500.
411 // |content_length| and |content_type| are the length and type of the 411 // |content_length| and |content_type| are the length and type of the
412 // file content to be uploaded respectively. 412 // file content to be uploaded respectively.
413 // |buf| holds current content to be uploaded. 413 // |buf| holds current content to be uploaded.
414 // See also UploadRangeRequestBase's comment for remaining parameters 414 // See also UploadRangeRequestBase's comment for remaining parameters
415 // meaining. 415 // meaining.
416 ResumeUploadRequestBase( 416 ResumeUploadRequestBase(
417 OperationRunner* runner, 417 RequestSender* runner,
418 net::URLRequestContextGetter* url_request_context_getter, 418 net::URLRequestContextGetter* url_request_context_getter,
419 const base::FilePath& drive_file_path, 419 const base::FilePath& drive_file_path,
420 const GURL& upload_location, 420 const GURL& upload_location,
421 int64 start_position, 421 int64 start_position,
422 int64 end_position, 422 int64 end_position,
423 int64 content_length, 423 int64 content_length,
424 const std::string& content_type, 424 const std::string& content_type,
425 const base::FilePath& local_file_path); 425 const base::FilePath& local_file_path);
426 virtual ~ResumeUploadRequestBase(); 426 virtual ~ResumeUploadRequestBase();
427 427
(...skipping 25 matching lines...) Expand all
453 // if a file has been partially uploaded. |value| is not used. 453 // if a file has been partially uploaded. |value| is not used.
454 // - HTTP_SUCCESS or HTTP_CREATED (up to the upload mode) and |value| 454 // - HTTP_SUCCESS or HTTP_CREATED (up to the upload mode) and |value|
455 // for the uploaded data, if a file has been completely uploaded. 455 // for the uploaded data, if a file has been completely uploaded.
456 // See also UploadRangeRequestBase. 456 // See also UploadRangeRequestBase.
457 class GetUploadStatusRequestBase : public UploadRangeRequestBase { 457 class GetUploadStatusRequestBase : public UploadRangeRequestBase {
458 public: 458 public:
459 // |content_length| is the whole data size to be uploaded. 459 // |content_length| is the whole data size to be uploaded.
460 // See also UploadRangeRequestBase's constructor comment for other 460 // See also UploadRangeRequestBase's constructor comment for other
461 // parameters. 461 // parameters.
462 GetUploadStatusRequestBase( 462 GetUploadStatusRequestBase(
463 OperationRunner* runner, 463 RequestSender* runner,
464 net::URLRequestContextGetter* url_request_context_getter, 464 net::URLRequestContextGetter* url_request_context_getter,
465 const base::FilePath& drive_file_path, 465 const base::FilePath& drive_file_path,
466 const GURL& upload_url, 466 const GURL& upload_url,
467 int64 content_length); 467 int64 content_length);
468 virtual ~GetUploadStatusRequestBase(); 468 virtual ~GetUploadStatusRequestBase();
469 469
470 protected: 470 protected:
471 // UrlFetchRequestBase overrides. 471 // UrlFetchRequestBase overrides.
472 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; 472 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE;
473 473
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 // Specifies the target file to download. 507 // Specifies the target file to download.
508 // 508 //
509 // drive_file_path: 509 // drive_file_path:
510 // Specifies the drive path of the target file. Shown in UI. 510 // Specifies the drive path of the target file. Shown in UI.
511 // TODO(satorux): Remove the drive file path hack. crbug.com/163296 511 // TODO(satorux): Remove the drive file path hack. crbug.com/163296
512 // 512 //
513 // output_file_path: 513 // output_file_path:
514 // Specifies the file path to save the downloaded file. 514 // Specifies the file path to save the downloaded file.
515 // 515 //
516 DownloadFileRequest( 516 DownloadFileRequest(
517 OperationRunner* runner, 517 RequestSender* runner,
518 net::URLRequestContextGetter* url_request_context_getter, 518 net::URLRequestContextGetter* url_request_context_getter,
519 const DownloadActionCallback& download_action_callback, 519 const DownloadActionCallback& download_action_callback,
520 const GetContentCallback& get_content_callback, 520 const GetContentCallback& get_content_callback,
521 const ProgressCallback& progress_callback, 521 const ProgressCallback& progress_callback,
522 const GURL& download_url, 522 const GURL& download_url,
523 const base::FilePath& drive_file_path, 523 const base::FilePath& drive_file_path,
524 const base::FilePath& output_file_path); 524 const base::FilePath& output_file_path);
525 virtual ~DownloadFileRequest(); 525 virtual ~DownloadFileRequest();
526 526
527 protected: 527 protected:
(...skipping 15 matching lines...) Expand all
543 const GetContentCallback get_content_callback_; 543 const GetContentCallback get_content_callback_;
544 const ProgressCallback progress_callback_; 544 const ProgressCallback progress_callback_;
545 const GURL download_url_; 545 const GURL download_url_;
546 546
547 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequest); 547 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequest);
548 }; 548 };
549 549
550 } // namespace google_apis 550 } // namespace google_apis
551 551
552 #endif // CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_ 552 #endif // CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/contacts/gdata_contacts_service.cc ('k') | chrome/browser/google_apis/base_requests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698