OLD | NEW |
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 GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ | 8 #ifndef GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ |
9 #define GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ | 9 #define GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ |
10 | 10 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 const base::FilePath& file_path, | 90 const base::FilePath& file_path, |
91 const GetContentCallback& get_content_callback); | 91 const GetContentCallback& get_content_callback); |
92 virtual ~ResponseWriter(); | 92 virtual ~ResponseWriter(); |
93 | 93 |
94 const std::string& data() const { return data_; } | 94 const std::string& data() const { return data_; } |
95 | 95 |
96 // Disowns the output file. | 96 // Disowns the output file. |
97 void DisownFile(); | 97 void DisownFile(); |
98 | 98 |
99 // URLFetcherResponseWriter overrides: | 99 // URLFetcherResponseWriter overrides: |
100 virtual int Initialize(const net::CompletionCallback& callback) OVERRIDE; | 100 virtual int Initialize(const net::CompletionCallback& callback) override; |
101 virtual int Write(net::IOBuffer* buffer, | 101 virtual int Write(net::IOBuffer* buffer, |
102 int num_bytes, | 102 int num_bytes, |
103 const net::CompletionCallback& callback) OVERRIDE; | 103 const net::CompletionCallback& callback) override; |
104 virtual int Finish(const net::CompletionCallback& callback) OVERRIDE; | 104 virtual int Finish(const net::CompletionCallback& callback) override; |
105 | 105 |
106 private: | 106 private: |
107 void DidWrite(scoped_refptr<net::IOBuffer> buffer, | 107 void DidWrite(scoped_refptr<net::IOBuffer> buffer, |
108 const net::CompletionCallback& callback, | 108 const net::CompletionCallback& callback, |
109 int result); | 109 int result); |
110 | 110 |
111 const GetContentCallback get_content_callback_; | 111 const GetContentCallback get_content_callback_; |
112 std::string data_; | 112 std::string data_; |
113 scoped_ptr<net::URLFetcherFileWriter> file_writer_; | 113 scoped_ptr<net::URLFetcherFileWriter> file_writer_; |
114 base::WeakPtrFactory<ResponseWriter> weak_ptr_factory_; | 114 base::WeakPtrFactory<ResponseWriter> weak_ptr_factory_; |
115 | 115 |
116 DISALLOW_COPY_AND_ASSIGN(ResponseWriter); | 116 DISALLOW_COPY_AND_ASSIGN(ResponseWriter); |
117 }; | 117 }; |
118 | 118 |
119 //============================ UrlFetchRequestBase =========================== | 119 //============================ UrlFetchRequestBase =========================== |
120 | 120 |
121 // Base class for requests that are fetching URLs. | 121 // Base class for requests that are fetching URLs. |
122 class UrlFetchRequestBase : public AuthenticatedRequestInterface, | 122 class UrlFetchRequestBase : public AuthenticatedRequestInterface, |
123 public net::URLFetcherDelegate { | 123 public net::URLFetcherDelegate { |
124 public: | 124 public: |
125 // AuthenticatedRequestInterface overrides. | 125 // AuthenticatedRequestInterface overrides. |
126 virtual void Start(const std::string& access_token, | 126 virtual void Start(const std::string& access_token, |
127 const std::string& custom_user_agent, | 127 const std::string& custom_user_agent, |
128 const ReAuthenticateCallback& callback) OVERRIDE; | 128 const ReAuthenticateCallback& callback) override; |
129 virtual base::WeakPtr<AuthenticatedRequestInterface> GetWeakPtr() OVERRIDE; | 129 virtual base::WeakPtr<AuthenticatedRequestInterface> GetWeakPtr() override; |
130 virtual void Cancel() OVERRIDE; | 130 virtual void Cancel() override; |
131 | 131 |
132 protected: | 132 protected: |
133 explicit UrlFetchRequestBase(RequestSender* sender); | 133 explicit UrlFetchRequestBase(RequestSender* sender); |
134 virtual ~UrlFetchRequestBase(); | 134 virtual ~UrlFetchRequestBase(); |
135 | 135 |
136 // Gets URL for the request. | 136 // Gets URL for the request. |
137 virtual GURL GetURL() const = 0; | 137 virtual GURL GetURL() const = 0; |
138 | 138 |
139 // Returns the request type. A derived class should override this method | 139 // Returns the request type. A derived class should override this method |
140 // for a request type other than HTTP GET. | 140 // for a request type other than HTTP GET. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 bool CalledOnValidThread(); | 187 bool CalledOnValidThread(); |
188 | 188 |
189 // Returns the writer which is used to save the response for the request. | 189 // Returns the writer which is used to save the response for the request. |
190 ResponseWriter* response_writer() const { return response_writer_; } | 190 ResponseWriter* response_writer() const { return response_writer_; } |
191 | 191 |
192 // Returns the task runner that should be used for blocking tasks. | 192 // Returns the task runner that should be used for blocking tasks. |
193 base::SequencedTaskRunner* blocking_task_runner() const; | 193 base::SequencedTaskRunner* blocking_task_runner() const; |
194 | 194 |
195 private: | 195 private: |
196 // URLFetcherDelegate overrides. | 196 // URLFetcherDelegate overrides. |
197 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 197 virtual void OnURLFetchComplete(const net::URLFetcher* source) override; |
198 | 198 |
199 // AuthenticatedRequestInterface overrides. | 199 // AuthenticatedRequestInterface overrides. |
200 virtual void OnAuthFailed(GDataErrorCode code) OVERRIDE; | 200 virtual void OnAuthFailed(GDataErrorCode code) override; |
201 | 201 |
202 ReAuthenticateCallback re_authenticate_callback_; | 202 ReAuthenticateCallback re_authenticate_callback_; |
203 int re_authenticate_count_; | 203 int re_authenticate_count_; |
204 scoped_ptr<net::URLFetcher> url_fetcher_; | 204 scoped_ptr<net::URLFetcher> url_fetcher_; |
205 ResponseWriter* response_writer_; // Owned by |url_fetcher_|. | 205 ResponseWriter* response_writer_; // Owned by |url_fetcher_|. |
206 RequestSender* sender_; | 206 RequestSender* sender_; |
207 GDataErrorCode error_code_; | 207 GDataErrorCode error_code_; |
208 | 208 |
209 base::ThreadChecker thread_checker_; | 209 base::ThreadChecker thread_checker_; |
210 | 210 |
(...skipping 14 matching lines...) Expand all Loading... |
225 class EntryActionRequest : public UrlFetchRequestBase { | 225 class EntryActionRequest : public UrlFetchRequestBase { |
226 public: | 226 public: |
227 // |callback| is called when the request is finished either by success or by | 227 // |callback| is called when the request is finished either by success or by |
228 // failure. It must not be null. | 228 // failure. It must not be null. |
229 EntryActionRequest(RequestSender* sender, | 229 EntryActionRequest(RequestSender* sender, |
230 const EntryActionCallback& callback); | 230 const EntryActionCallback& callback); |
231 virtual ~EntryActionRequest(); | 231 virtual ~EntryActionRequest(); |
232 | 232 |
233 protected: | 233 protected: |
234 // Overridden from UrlFetchRequestBase. | 234 // Overridden from UrlFetchRequestBase. |
235 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 235 virtual void ProcessURLFetchResults(const net::URLFetcher* source) override; |
236 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 236 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) override; |
237 | 237 |
238 private: | 238 private: |
239 const EntryActionCallback callback_; | 239 const EntryActionCallback callback_; |
240 | 240 |
241 DISALLOW_COPY_AND_ASSIGN(EntryActionRequest); | 241 DISALLOW_COPY_AND_ASSIGN(EntryActionRequest); |
242 }; | 242 }; |
243 | 243 |
244 //=========================== InitiateUploadRequestBase======================= | 244 //=========================== InitiateUploadRequestBase======================= |
245 | 245 |
246 // Callback type for DriveServiceInterface::InitiateUpload. | 246 // Callback type for DriveServiceInterface::InitiateUpload. |
(...skipping 17 matching lines...) Expand all Loading... |
264 // uploaded to with ResumeUploadRequestBase. It must not be null. | 264 // uploaded to with ResumeUploadRequestBase. It must not be null. |
265 // |content_type| and |content_length| should be the attributes of the | 265 // |content_type| and |content_length| should be the attributes of the |
266 // uploading file. | 266 // uploading file. |
267 InitiateUploadRequestBase(RequestSender* sender, | 267 InitiateUploadRequestBase(RequestSender* sender, |
268 const InitiateUploadCallback& callback, | 268 const InitiateUploadCallback& callback, |
269 const std::string& content_type, | 269 const std::string& content_type, |
270 int64 content_length); | 270 int64 content_length); |
271 virtual ~InitiateUploadRequestBase(); | 271 virtual ~InitiateUploadRequestBase(); |
272 | 272 |
273 // UrlFetchRequestBase overrides. | 273 // UrlFetchRequestBase overrides. |
274 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 274 virtual void ProcessURLFetchResults(const net::URLFetcher* source) override; |
275 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 275 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) override; |
276 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | 276 virtual std::vector<std::string> GetExtraRequestHeaders() const override; |
277 | 277 |
278 private: | 278 private: |
279 const InitiateUploadCallback callback_; | 279 const InitiateUploadCallback callback_; |
280 const std::string content_type_; | 280 const std::string content_type_; |
281 const int64 content_length_; | 281 const int64 content_length_; |
282 | 282 |
283 DISALLOW_COPY_AND_ASSIGN(InitiateUploadRequestBase); | 283 DISALLOW_COPY_AND_ASSIGN(InitiateUploadRequestBase); |
284 }; | 284 }; |
285 | 285 |
286 //========================== UploadRangeRequestBase ========================== | 286 //========================== UploadRangeRequestBase ========================== |
(...skipping 20 matching lines...) Expand all Loading... |
307 // Base class for a URL fetch request expecting the response containing the | 307 // Base class for a URL fetch request expecting the response containing the |
308 // current uploading range. This class processes the response containing | 308 // current uploading range. This class processes the response containing |
309 // "Range" header and invoke OnRangeRequestComplete. | 309 // "Range" header and invoke OnRangeRequestComplete. |
310 class UploadRangeRequestBase : public UrlFetchRequestBase { | 310 class UploadRangeRequestBase : public UrlFetchRequestBase { |
311 protected: | 311 protected: |
312 // |upload_url| is the URL of where to upload the file to. | 312 // |upload_url| is the URL of where to upload the file to. |
313 UploadRangeRequestBase(RequestSender* sender, const GURL& upload_url); | 313 UploadRangeRequestBase(RequestSender* sender, const GURL& upload_url); |
314 virtual ~UploadRangeRequestBase(); | 314 virtual ~UploadRangeRequestBase(); |
315 | 315 |
316 // UrlFetchRequestBase overrides. | 316 // UrlFetchRequestBase overrides. |
317 virtual GURL GetURL() const OVERRIDE; | 317 virtual GURL GetURL() const override; |
318 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 318 virtual net::URLFetcher::RequestType GetRequestType() const override; |
319 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 319 virtual void ProcessURLFetchResults(const net::URLFetcher* source) override; |
320 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 320 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) override; |
321 | 321 |
322 // This method will be called when the request is done, regardless of | 322 // This method will be called when the request is done, regardless of |
323 // whether it is succeeded or failed. | 323 // whether it is succeeded or failed. |
324 // | 324 // |
325 // 1) If there is more data to upload, |code| of |response| is set to | 325 // 1) If there is more data to upload, |code| of |response| is set to |
326 // HTTP_RESUME_INCOMPLETE, and positions are set appropriately. Also, |value| | 326 // HTTP_RESUME_INCOMPLETE, and positions are set appropriately. Also, |value| |
327 // will be set to NULL. | 327 // will be set to NULL. |
328 // 2) If the upload is complete, |code| is set to HTTP_CREATED for a new file | 328 // 2) If the upload is complete, |code| is set to HTTP_CREATED for a new file |
329 // or HTTP_SUCCESS for an existing file. Positions are set to -1, and |value| | 329 // or HTTP_SUCCESS for an existing file. Positions are set to -1, and |value| |
330 // is set to a parsed JSON value representing the uploaded file. | 330 // is set to a parsed JSON value representing the uploaded file. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 ResumeUploadRequestBase(RequestSender* sender, | 374 ResumeUploadRequestBase(RequestSender* sender, |
375 const GURL& upload_location, | 375 const GURL& upload_location, |
376 int64 start_position, | 376 int64 start_position, |
377 int64 end_position, | 377 int64 end_position, |
378 int64 content_length, | 378 int64 content_length, |
379 const std::string& content_type, | 379 const std::string& content_type, |
380 const base::FilePath& local_file_path); | 380 const base::FilePath& local_file_path); |
381 virtual ~ResumeUploadRequestBase(); | 381 virtual ~ResumeUploadRequestBase(); |
382 | 382 |
383 // UrlFetchRequestBase overrides. | 383 // UrlFetchRequestBase overrides. |
384 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | 384 virtual std::vector<std::string> GetExtraRequestHeaders() const override; |
385 virtual bool GetContentFile(base::FilePath* local_file_path, | 385 virtual bool GetContentFile(base::FilePath* local_file_path, |
386 int64* range_offset, | 386 int64* range_offset, |
387 int64* range_length, | 387 int64* range_length, |
388 std::string* upload_content_type) OVERRIDE; | 388 std::string* upload_content_type) override; |
389 | 389 |
390 private: | 390 private: |
391 // The parameters for the request. See ResumeUploadParams for the details. | 391 // The parameters for the request. See ResumeUploadParams for the details. |
392 const int64 start_position_; | 392 const int64 start_position_; |
393 const int64 end_position_; | 393 const int64 end_position_; |
394 const int64 content_length_; | 394 const int64 content_length_; |
395 const std::string content_type_; | 395 const std::string content_type_; |
396 const base::FilePath local_file_path_; | 396 const base::FilePath local_file_path_; |
397 | 397 |
398 DISALLOW_COPY_AND_ASSIGN(ResumeUploadRequestBase); | 398 DISALLOW_COPY_AND_ASSIGN(ResumeUploadRequestBase); |
(...skipping 14 matching lines...) Expand all Loading... |
413 // |content_length| is the whole data size to be uploaded. | 413 // |content_length| is the whole data size to be uploaded. |
414 // See also UploadRangeRequestBase's constructor comment for other | 414 // See also UploadRangeRequestBase's constructor comment for other |
415 // parameters. | 415 // parameters. |
416 GetUploadStatusRequestBase(RequestSender* sender, | 416 GetUploadStatusRequestBase(RequestSender* sender, |
417 const GURL& upload_url, | 417 const GURL& upload_url, |
418 int64 content_length); | 418 int64 content_length); |
419 virtual ~GetUploadStatusRequestBase(); | 419 virtual ~GetUploadStatusRequestBase(); |
420 | 420 |
421 protected: | 421 protected: |
422 // UrlFetchRequestBase overrides. | 422 // UrlFetchRequestBase overrides. |
423 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | 423 virtual std::vector<std::string> GetExtraRequestHeaders() const override; |
424 | 424 |
425 private: | 425 private: |
426 const int64 content_length_; | 426 const int64 content_length_; |
427 | 427 |
428 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusRequestBase); | 428 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusRequestBase); |
429 }; | 429 }; |
430 | 430 |
431 //============================ DownloadFileRequest =========================== | 431 //============================ DownloadFileRequest =========================== |
432 | 432 |
433 // Callback type for receiving the completion of DownloadFileRequest. | 433 // Callback type for receiving the completion of DownloadFileRequest. |
(...skipping 25 matching lines...) Expand all Loading... |
459 RequestSender* sender, | 459 RequestSender* sender, |
460 const DownloadActionCallback& download_action_callback, | 460 const DownloadActionCallback& download_action_callback, |
461 const GetContentCallback& get_content_callback, | 461 const GetContentCallback& get_content_callback, |
462 const ProgressCallback& progress_callback, | 462 const ProgressCallback& progress_callback, |
463 const GURL& download_url, | 463 const GURL& download_url, |
464 const base::FilePath& output_file_path); | 464 const base::FilePath& output_file_path); |
465 virtual ~DownloadFileRequestBase(); | 465 virtual ~DownloadFileRequestBase(); |
466 | 466 |
467 protected: | 467 protected: |
468 // UrlFetchRequestBase overrides. | 468 // UrlFetchRequestBase overrides. |
469 virtual GURL GetURL() const OVERRIDE; | 469 virtual GURL GetURL() const override; |
470 virtual void GetOutputFilePath( | 470 virtual void GetOutputFilePath( |
471 base::FilePath* local_file_path, | 471 base::FilePath* local_file_path, |
472 GetContentCallback* get_content_callback) OVERRIDE; | 472 GetContentCallback* get_content_callback) override; |
473 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 473 virtual void ProcessURLFetchResults(const net::URLFetcher* source) override; |
474 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 474 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) override; |
475 | 475 |
476 // net::URLFetcherDelegate overrides. | 476 // net::URLFetcherDelegate overrides. |
477 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, | 477 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
478 int64 current, int64 total) OVERRIDE; | 478 int64 current, int64 total) override; |
479 | 479 |
480 private: | 480 private: |
481 const DownloadActionCallback download_action_callback_; | 481 const DownloadActionCallback download_action_callback_; |
482 const GetContentCallback get_content_callback_; | 482 const GetContentCallback get_content_callback_; |
483 const ProgressCallback progress_callback_; | 483 const ProgressCallback progress_callback_; |
484 const GURL download_url_; | 484 const GURL download_url_; |
485 const base::FilePath output_file_path_; | 485 const base::FilePath output_file_path_; |
486 | 486 |
487 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequestBase); | 487 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequestBase); |
488 }; | 488 }; |
489 | 489 |
490 } // namespace google_apis | 490 } // namespace google_apis |
491 | 491 |
492 #endif // GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ | 492 #endif // GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ |
OLD | NEW |