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

Side by Side Diff: google_apis/drive/base_requests.h

Issue 442193002: Parse Drive API responses all at once in the blocking pool. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix the cause of the regression. Created 6 years, 4 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
« no previous file with comments | « chrome/browser/drive/drive_api_util.cc ('k') | google_apis/drive/base_requests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 11 matching lines...) Expand all
22 #include "url/gurl.h" 22 #include "url/gurl.h"
23 23
24 namespace base { 24 namespace base {
25 class Value; 25 class Value;
26 } // namespace base 26 } // namespace base
27 27
28 namespace google_apis { 28 namespace google_apis {
29 29
30 class RequestSender; 30 class RequestSender;
31 31
32 // Callback used to pass parsed JSON from ParseJson(). If parsing error occurs,
33 // then the passed argument is null.
34 typedef base::Callback<void(scoped_ptr<base::Value> value)> ParseJsonCallback;
35
36 // Callback used for DownloadFileRequest and ResumeUploadRequestBase. 32 // Callback used for DownloadFileRequest and ResumeUploadRequestBase.
37 typedef base::Callback<void(int64 progress, int64 total)> ProgressCallback; 33 typedef base::Callback<void(int64 progress, int64 total)> ProgressCallback;
38 34
39 // Callback used to get the content from DownloadFileRequest. 35 // Callback used to get the content from DownloadFileRequest.
40 typedef base::Callback<void( 36 typedef base::Callback<void(
41 GDataErrorCode error, 37 GDataErrorCode error,
42 scoped_ptr<std::string> content)> GetContentCallback; 38 scoped_ptr<std::string> content)> GetContentCallback;
43 39
44 // Parses JSON passed in |json| on |blocking_task_runner|. Runs |callback| on 40 // Parses JSON passed in |json|. Returns NULL on failure.
45 // the calling thread when finished with either success or failure. 41 scoped_ptr<base::Value> ParseJson(const std::string& json);
46 // The callback must not be null.
47 void ParseJson(base::TaskRunner* blocking_task_runner,
48 const std::string& json,
49 const ParseJsonCallback& callback);
50 42
51 //======================= AuthenticatedRequestInterface ====================== 43 //======================= AuthenticatedRequestInterface ======================
52 44
53 // An interface class for implementing a request which requires OAuth2 45 // An interface class for implementing a request which requires OAuth2
54 // authentication. 46 // authentication.
55 class AuthenticatedRequestInterface { 47 class AuthenticatedRequestInterface {
56 public: 48 public:
57 // Called when re-authentication is required. See Start() for details. 49 // Called when re-authentication is required. See Start() for details.
58 typedef base::Callback<void(AuthenticatedRequestInterface* request)> 50 typedef base::Callback<void(AuthenticatedRequestInterface* request)>
59 ReAuthenticateCallback; 51 ReAuthenticateCallback;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // Overridden from UrlFetchRequestBase. 234 // Overridden from UrlFetchRequestBase.
243 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; 235 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE;
244 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; 236 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE;
245 237
246 private: 238 private:
247 const EntryActionCallback callback_; 239 const EntryActionCallback callback_;
248 240
249 DISALLOW_COPY_AND_ASSIGN(EntryActionRequest); 241 DISALLOW_COPY_AND_ASSIGN(EntryActionRequest);
250 }; 242 };
251 243
252 //============================== GetDataRequest ==============================
253
254 // Callback type for requests that returns JSON data.
255 typedef base::Callback<void(GDataErrorCode error,
256 scoped_ptr<base::Value> json_data)> GetDataCallback;
257
258 // This class performs the request for fetching and converting the fetched
259 // content into a base::Value.
260 class GetDataRequest : public UrlFetchRequestBase {
261 public:
262 // |callback| is called when the request finishes either by success or by
263 // failure. On success, a JSON Value object is passed. It must not be null.
264 GetDataRequest(RequestSender* sender, const GetDataCallback& callback);
265 virtual ~GetDataRequest();
266
267 protected:
268 // UrlFetchRequestBase overrides.
269 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE;
270 virtual void RunCallbackOnPrematureFailure(
271 GDataErrorCode fetch_error_code) OVERRIDE;
272
273 private:
274 // Parses JSON response.
275 void ParseResponse(GDataErrorCode fetch_error_code, const std::string& data);
276
277 // Called when ParseJsonOnBlockingPool() is completed.
278 void OnDataParsed(GDataErrorCode fetch_error_code,
279 scoped_ptr<base::Value> value);
280
281 const GetDataCallback callback_;
282
283 // Note: This should remain the last member so it'll be destroyed and
284 // invalidate its weak pointers before any other members are destroyed.
285 base::WeakPtrFactory<GetDataRequest> weak_ptr_factory_;
286
287 DISALLOW_COPY_AND_ASSIGN(GetDataRequest);
288 };
289
290
291 //=========================== InitiateUploadRequestBase======================= 244 //=========================== InitiateUploadRequestBase=======================
292 245
293 // Callback type for DriveServiceInterface::InitiateUpload. 246 // Callback type for DriveServiceInterface::InitiateUpload.
294 typedef base::Callback<void(GDataErrorCode error, 247 typedef base::Callback<void(GDataErrorCode error,
295 const GURL& upload_url)> InitiateUploadCallback; 248 const GURL& upload_url)> InitiateUploadCallback;
296 249
297 // This class provides base implementation for performing the request for 250 // This class provides base implementation for performing the request for
298 // initiating the upload of a file. 251 // initiating the upload of a file.
299 // |callback| will be called with the obtained upload URL. The URL will be 252 // |callback| will be called with the obtained upload URL. The URL will be
300 // used with requests for resuming the file uploading. 253 // used with requests for resuming the file uploading.
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 const ProgressCallback progress_callback_; 483 const ProgressCallback progress_callback_;
531 const GURL download_url_; 484 const GURL download_url_;
532 const base::FilePath output_file_path_; 485 const base::FilePath output_file_path_;
533 486
534 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequestBase); 487 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequestBase);
535 }; 488 };
536 489
537 } // namespace google_apis 490 } // namespace google_apis
538 491
539 #endif // GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ 492 #endif // GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_
OLDNEW
« no previous file with comments | « chrome/browser/drive/drive_api_util.cc ('k') | google_apis/drive/base_requests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698