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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 struct ContentTypeAndData { | 43 struct ContentTypeAndData { |
44 std::string type; | 44 std::string type; |
45 std::string data; | 45 std::string data; |
46 }; | 46 }; |
47 | 47 |
48 typedef base::Callback<void(DriveApiErrorCode)> PrepareCallback; | 48 typedef base::Callback<void(DriveApiErrorCode)> PrepareCallback; |
49 | 49 |
50 // Callback used for requests that the server returns FileResource data | 50 // Callback used for requests that the server returns FileResource data |
51 // formatted into JSON value. | 51 // formatted into JSON value. |
52 typedef base::Callback<void(DriveApiErrorCode error, | 52 typedef base::Callback<void(DriveApiErrorCode error, |
53 scoped_ptr<FileResource> entry)> | 53 std::unique_ptr<FileResource> entry)> |
54 FileResourceCallback; | 54 FileResourceCallback; |
55 | 55 |
56 // Callback used for DownloadFileRequest and ResumeUploadRequestBase. | 56 // Callback used for DownloadFileRequest and ResumeUploadRequestBase. |
57 typedef base::Callback<void(int64_t progress, int64_t total)> ProgressCallback; | 57 typedef base::Callback<void(int64_t progress, int64_t total)> ProgressCallback; |
58 | 58 |
59 // Callback used to get the content from DownloadFileRequest. | 59 // Callback used to get the content from DownloadFileRequest. |
60 typedef base::Callback<void( | 60 typedef base::Callback<void(DriveApiErrorCode error, |
61 DriveApiErrorCode error, | 61 std::unique_ptr<std::string> content)> |
62 scoped_ptr<std::string> content)> GetContentCallback; | 62 GetContentCallback; |
63 | 63 |
64 // Parses JSON passed in |json|. Returns NULL on failure. | 64 // Parses JSON passed in |json|. Returns NULL on failure. |
65 scoped_ptr<base::Value> ParseJson(const std::string& json); | 65 std::unique_ptr<base::Value> ParseJson(const std::string& json); |
66 | 66 |
67 // Generate multipart body. If |predetermined_boundary| is not empty, it uses | 67 // Generate multipart body. If |predetermined_boundary| is not empty, it uses |
68 // the string as boundary. Otherwise it generates random boundary that does not | 68 // the string as boundary. Otherwise it generates random boundary that does not |
69 // conflict with |parts|. If |data_offset| is not nullptr, it stores the | 69 // conflict with |parts|. If |data_offset| is not nullptr, it stores the |
70 // index of first byte of each part in multipart body. | 70 // index of first byte of each part in multipart body. |
71 void GenerateMultipartBody(MultipartType multipart_type, | 71 void GenerateMultipartBody(MultipartType multipart_type, |
72 const std::string& predetermined_boundary, | 72 const std::string& predetermined_boundary, |
73 const std::vector<ContentTypeAndData>& parts, | 73 const std::vector<ContentTypeAndData>& parts, |
74 ContentTypeAndData* output, | 74 ContentTypeAndData* output, |
75 std::vector<uint64_t>* data_offset); | 75 std::vector<uint64_t>* data_offset); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 const net::CompletionCallback& callback) override; | 137 const net::CompletionCallback& callback) override; |
138 int Finish(const net::CompletionCallback& callback) override; | 138 int Finish(const net::CompletionCallback& callback) override; |
139 | 139 |
140 private: | 140 private: |
141 void DidWrite(scoped_refptr<net::IOBuffer> buffer, | 141 void DidWrite(scoped_refptr<net::IOBuffer> buffer, |
142 const net::CompletionCallback& callback, | 142 const net::CompletionCallback& callback, |
143 int result); | 143 int result); |
144 | 144 |
145 const GetContentCallback get_content_callback_; | 145 const GetContentCallback get_content_callback_; |
146 std::string data_; | 146 std::string data_; |
147 scoped_ptr<net::URLFetcherFileWriter> file_writer_; | 147 std::unique_ptr<net::URLFetcherFileWriter> file_writer_; |
148 base::WeakPtrFactory<ResponseWriter> weak_ptr_factory_; | 148 base::WeakPtrFactory<ResponseWriter> weak_ptr_factory_; |
149 | 149 |
150 DISALLOW_COPY_AND_ASSIGN(ResponseWriter); | 150 DISALLOW_COPY_AND_ASSIGN(ResponseWriter); |
151 }; | 151 }; |
152 | 152 |
153 //============================ UrlFetchRequestBase =========================== | 153 //============================ UrlFetchRequestBase =========================== |
154 | 154 |
155 // Base class for requests that are fetching URLs. | 155 // Base class for requests that are fetching URLs. |
156 class UrlFetchRequestBase : public AuthenticatedRequestInterface, | 156 class UrlFetchRequestBase : public AuthenticatedRequestInterface, |
157 public net::URLFetcherDelegate { | 157 public net::URLFetcherDelegate { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 void CompleteRequestWithError(DriveApiErrorCode code); | 242 void CompleteRequestWithError(DriveApiErrorCode code); |
243 | 243 |
244 // URLFetcherDelegate overrides. | 244 // URLFetcherDelegate overrides. |
245 void OnURLFetchComplete(const net::URLFetcher* source) override; | 245 void OnURLFetchComplete(const net::URLFetcher* source) override; |
246 | 246 |
247 // AuthenticatedRequestInterface overrides. | 247 // AuthenticatedRequestInterface overrides. |
248 void OnAuthFailed(DriveApiErrorCode code) override; | 248 void OnAuthFailed(DriveApiErrorCode code) override; |
249 | 249 |
250 ReAuthenticateCallback re_authenticate_callback_; | 250 ReAuthenticateCallback re_authenticate_callback_; |
251 int re_authenticate_count_; | 251 int re_authenticate_count_; |
252 scoped_ptr<net::URLFetcher> url_fetcher_; | 252 std::unique_ptr<net::URLFetcher> url_fetcher_; |
253 ResponseWriter* response_writer_; // Owned by |url_fetcher_|. | 253 ResponseWriter* response_writer_; // Owned by |url_fetcher_|. |
254 RequestSender* sender_; | 254 RequestSender* sender_; |
255 DriveApiErrorCode error_code_; | 255 DriveApiErrorCode error_code_; |
256 | 256 |
257 base::ThreadChecker thread_checker_; | 257 base::ThreadChecker thread_checker_; |
258 | 258 |
259 // Note: This should remain the last member so it'll be destroyed and | 259 // Note: This should remain the last member so it'll be destroyed and |
260 // invalidate its weak pointers before any other members are destroyed. | 260 // invalidate its weak pointers before any other members are destroyed. |
261 base::WeakPtrFactory<UrlFetchRequestBase> weak_ptr_factory_; | 261 base::WeakPtrFactory<UrlFetchRequestBase> weak_ptr_factory_; |
262 | 262 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 // 2) If the upload is complete, |code| is set to HTTP_CREATED for a new file | 412 // 2) If the upload is complete, |code| is set to HTTP_CREATED for a new file |
413 // or HTTP_SUCCESS for an existing file. Positions are set to -1, and |value| | 413 // or HTTP_SUCCESS for an existing file. Positions are set to -1, and |value| |
414 // is set to a parsed JSON value representing the uploaded file. | 414 // is set to a parsed JSON value representing the uploaded file. |
415 // 3) If a premature failure is found, |code| is set to a value representing | 415 // 3) If a premature failure is found, |code| is set to a value representing |
416 // the situation. Positions are set to 0, and |value| is set to NULL. | 416 // the situation. Positions are set to 0, and |value| is set to NULL. |
417 // | 417 // |
418 // See also the comments for UploadRangeResponse. | 418 // See also the comments for UploadRangeResponse. |
419 // Note: Subclasses should have responsibility to run some callback | 419 // Note: Subclasses should have responsibility to run some callback |
420 // in this method to notify the finish status to its clients (or ignore it | 420 // in this method to notify the finish status to its clients (or ignore it |
421 // under its responsibility). | 421 // under its responsibility). |
422 virtual void OnRangeRequestComplete( | 422 virtual void OnRangeRequestComplete(const UploadRangeResponse& response, |
423 const UploadRangeResponse& response, scoped_ptr<base::Value> value) = 0; | 423 std::unique_ptr<base::Value> value) = 0; |
424 | 424 |
425 private: | 425 private: |
426 // Called when ParseJson() is completed. | 426 // Called when ParseJson() is completed. |
427 void OnDataParsed(DriveApiErrorCode code, scoped_ptr<base::Value> value); | 427 void OnDataParsed(DriveApiErrorCode code, std::unique_ptr<base::Value> value); |
428 | 428 |
429 const GURL upload_url_; | 429 const GURL upload_url_; |
430 | 430 |
431 // Note: This should remain the last member so it'll be destroyed and | 431 // Note: This should remain the last member so it'll be destroyed and |
432 // invalidate its weak pointers before any other members are destroyed. | 432 // invalidate its weak pointers before any other members are destroyed. |
433 base::WeakPtrFactory<UploadRangeRequestBase> weak_ptr_factory_; | 433 base::WeakPtrFactory<UploadRangeRequestBase> weak_ptr_factory_; |
434 | 434 |
435 DISALLOW_COPY_AND_ASSIGN(UploadRangeRequestBase); | 435 DISALLOW_COPY_AND_ASSIGN(UploadRangeRequestBase); |
436 }; | 436 }; |
437 | 437 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 void NotifyResult(DriveApiErrorCode code, | 543 void NotifyResult(DriveApiErrorCode code, |
544 const std::string& body, | 544 const std::string& body, |
545 const base::Closure& callback) override; | 545 const base::Closure& callback) override; |
546 void NotifyError(DriveApiErrorCode code) override; | 546 void NotifyError(DriveApiErrorCode code) override; |
547 void NotifyUploadProgress(const net::URLFetcher* source, | 547 void NotifyUploadProgress(const net::URLFetcher* source, |
548 int64_t current, | 548 int64_t current, |
549 int64_t total) override; | 549 int64_t total) override; |
550 // Parses the response value and invokes |callback_| with |FileResource|. | 550 // Parses the response value and invokes |callback_| with |FileResource|. |
551 void OnDataParsed(DriveApiErrorCode code, | 551 void OnDataParsed(DriveApiErrorCode code, |
552 const base::Closure& callback, | 552 const base::Closure& callback, |
553 scoped_ptr<base::Value> value); | 553 std::unique_ptr<base::Value> value); |
554 | 554 |
555 private: | 555 private: |
556 // Continues to rest part of |Start| method after determining boundary string | 556 // Continues to rest part of |Start| method after determining boundary string |
557 // of multipart/related. | 557 // of multipart/related. |
558 void OnPrepareUploadContent(const PrepareCallback& callback, | 558 void OnPrepareUploadContent(const PrepareCallback& callback, |
559 std::string* upload_content_type, | 559 std::string* upload_content_type, |
560 std::string* upload_content_data, | 560 std::string* upload_content_data, |
561 bool result); | 561 bool result); |
562 | 562 |
563 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 563 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 const ProgressCallback progress_callback_; | 638 const ProgressCallback progress_callback_; |
639 const GURL download_url_; | 639 const GURL download_url_; |
640 const base::FilePath output_file_path_; | 640 const base::FilePath output_file_path_; |
641 | 641 |
642 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequestBase); | 642 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequestBase); |
643 }; | 643 }; |
644 | 644 |
645 } // namespace google_apis | 645 } // namespace google_apis |
646 | 646 |
647 #endif // GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ | 647 #endif // GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ |
OLD | NEW |