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 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 virtual bool GetOutputFilePath(base::FilePath* local_file_path); | 131 virtual bool GetOutputFilePath(base::FilePath* local_file_path); |
132 | 132 |
133 // Invoked by OnURLFetchComplete when the request completes without an | 133 // Invoked by OnURLFetchComplete when the request completes without an |
134 // authentication error. Must be implemented by a derived class. | 134 // authentication error. Must be implemented by a derived class. |
135 virtual void ProcessURLFetchResults(const net::URLFetcher* source) = 0; | 135 virtual void ProcessURLFetchResults(const net::URLFetcher* source) = 0; |
136 | 136 |
137 // Invoked by this base class upon an authentication error or cancel by | 137 // Invoked by this base class upon an authentication error or cancel by |
138 // a user request. Must be implemented by a derived class. | 138 // a user request. Must be implemented by a derived class. |
139 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) = 0; | 139 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) = 0; |
140 | 140 |
141 // Invoked when ProcessURLFetchResults() is completed. | 141 // Invoked from derived classes when ProcessURLFetchResults() is completed. |
142 void OnProcessURLFetchResultsComplete(bool result); | 142 void OnProcessURLFetchResultsComplete(); |
143 | 143 |
144 // Returns an appropriate GDataErrorCode based on the HTTP response code and | 144 // Returns an appropriate GDataErrorCode based on the HTTP response code and |
145 // the status of the URLFetcher. | 145 // the status of the URLFetcher. |
146 static GDataErrorCode GetErrorCode(const net::URLFetcher* source); | 146 static GDataErrorCode GetErrorCode(const net::URLFetcher* source); |
147 | 147 |
148 // Returns true if called on the thread where the constructor was called. | 148 // Returns true if called on the thread where the constructor was called. |
149 bool CalledOnValidThread(); | 149 bool CalledOnValidThread(); |
150 | 150 |
151 // Returns the task runner that should be used for blocking tasks. | 151 // Returns the task runner that should be used for blocking tasks. |
152 base::TaskRunner* blocking_task_runner() const; | 152 base::TaskRunner* blocking_task_runner() const; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 // Parses JSON response. | 216 // Parses JSON response. |
217 void ParseResponse(GDataErrorCode fetch_error_code, const std::string& data); | 217 void ParseResponse(GDataErrorCode fetch_error_code, const std::string& data); |
218 | 218 |
219 protected: | 219 protected: |
220 // UrlFetchRequestBase overrides. | 220 // UrlFetchRequestBase overrides. |
221 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 221 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; |
222 virtual void RunCallbackOnPrematureFailure( | 222 virtual void RunCallbackOnPrematureFailure( |
223 GDataErrorCode fetch_error_code) OVERRIDE; | 223 GDataErrorCode fetch_error_code) OVERRIDE; |
224 | 224 |
225 private: | 225 private: |
226 // Runs |callback_| with the given parameters. | |
227 void RunCallbackOnSuccess(GDataErrorCode fetch_error_code, | |
228 scoped_ptr<base::Value> value); | |
229 | |
230 | |
231 // Called when ParseJsonOnBlockingPool() is completed. | 226 // Called when ParseJsonOnBlockingPool() is completed. |
232 void OnDataParsed(GDataErrorCode fetch_error_code, | 227 void OnDataParsed(GDataErrorCode fetch_error_code, |
233 scoped_ptr<base::Value> value); | 228 scoped_ptr<base::Value> value); |
234 | 229 |
235 const GetDataCallback callback_; | 230 const GetDataCallback callback_; |
236 | 231 |
237 // Note: This should remain the last member so it'll be destroyed and | 232 // Note: This should remain the last member so it'll be destroyed and |
238 // invalidate its weak pointers before any other members are destroyed. | 233 // invalidate its weak pointers before any other members are destroyed. |
239 base::WeakPtrFactory<GetDataRequest> weak_ptr_factory_; | 234 base::WeakPtrFactory<GetDataRequest> weak_ptr_factory_; |
240 | 235 |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 const ProgressCallback progress_callback_; | 486 const ProgressCallback progress_callback_; |
492 const GURL download_url_; | 487 const GURL download_url_; |
493 const base::FilePath output_file_path_; | 488 const base::FilePath output_file_path_; |
494 | 489 |
495 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequestBase); | 490 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequestBase); |
496 }; | 491 }; |
497 | 492 |
498 } // namespace google_apis | 493 } // namespace google_apis |
499 | 494 |
500 #endif // CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_ | 495 #endif // CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_ |
OLD | NEW |