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

Side by Side Diff: google_apis/drive/gdata_wapi_requests.cc

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
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 #include "google_apis/drive/gdata_wapi_requests.h" 5 #include "google_apis/drive/gdata_wapi_requests.h"
6 6
7 #include "base/location.h"
8 #include "base/sequenced_task_runner.h"
9 #include "base/task_runner_util.h"
10 #include "base/values.h"
11 #include "google_apis/drive/gdata_wapi_parser.h"
7 #include "google_apis/drive/gdata_wapi_url_generator.h" 12 #include "google_apis/drive/gdata_wapi_url_generator.h"
8 13
9 namespace google_apis { 14 namespace google_apis {
10 15
11 //============================ GetResourceEntryRequest ======================= 16 namespace {
17
18 scoped_ptr<ResourceEntry> ParseResourceEntry(const std::string& json) {
19 scoped_ptr<base::Value> value = ParseJson(json);
20 return value ? ResourceEntry::ExtractAndParse(*value) :
21 scoped_ptr<ResourceEntry>();
22 }
23
24 } // namespace
12 25
13 GetResourceEntryRequest::GetResourceEntryRequest( 26 GetResourceEntryRequest::GetResourceEntryRequest(
14 RequestSender* sender, 27 RequestSender* sender,
15 const GDataWapiUrlGenerator& url_generator, 28 const GDataWapiUrlGenerator& url_generator,
16 const std::string& resource_id, 29 const std::string& resource_id,
17 const GURL& embed_origin, 30 const GURL& embed_origin,
18 const GetDataCallback& callback) 31 const GetResourceEntryCallback& callback)
19 : GetDataRequest(sender, callback), 32 : UrlFetchRequestBase(sender),
20 url_generator_(url_generator), 33 url_generator_(url_generator),
21 resource_id_(resource_id), 34 resource_id_(resource_id),
22 embed_origin_(embed_origin) { 35 embed_origin_(embed_origin),
36 callback_(callback),
37 weak_ptr_factory_(this) {
23 DCHECK(!callback.is_null()); 38 DCHECK(!callback.is_null());
24 } 39 }
25 40
26 GetResourceEntryRequest::~GetResourceEntryRequest() {} 41 GetResourceEntryRequest::~GetResourceEntryRequest() {}
27 42
28 GURL GetResourceEntryRequest::GetURL() const { 43 GURL GetResourceEntryRequest::GetURL() const {
29 return url_generator_.GenerateEditUrlWithEmbedOrigin( 44 return url_generator_.GenerateEditUrlWithEmbedOrigin(
30 resource_id_, embed_origin_); 45 resource_id_, embed_origin_);
31 } 46 }
32 47
48 void GetResourceEntryRequest::ProcessURLFetchResults(
49 const net::URLFetcher* source) {
50 GDataErrorCode error = GetErrorCode();
51 switch (error) {
52 case HTTP_SUCCESS:
53 case HTTP_CREATED:
54 base::PostTaskAndReplyWithResult(
55 blocking_task_runner(),
56 FROM_HERE,
57 base::Bind(&ParseResourceEntry, response_writer()->data()),
58 base::Bind(&GetResourceEntryRequest::OnDataParsed,
59 weak_ptr_factory_.GetWeakPtr(), error));
60 break;
61 default:
62 RunCallbackOnPrematureFailure(error);
63 OnProcessURLFetchResultsComplete();
64 break;
65 }
66 }
67
68 void GetResourceEntryRequest::RunCallbackOnPrematureFailure(
69 GDataErrorCode error) {
70 callback_.Run(error, scoped_ptr<ResourceEntry>());
71 }
72
73 void GetResourceEntryRequest::OnDataParsed(GDataErrorCode error,
74 scoped_ptr<ResourceEntry> entry) {
75 if (!entry)
76 error = GDATA_PARSE_ERROR;
77 callback_.Run(error, entry.Pass());
78 OnProcessURLFetchResultsComplete();
79 }
80
33 } // namespace google_apis 81 } // namespace google_apis
OLDNEW
« no previous file with comments | « google_apis/drive/gdata_wapi_requests.h ('k') | google_apis/drive/gdata_wapi_requests_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698