| 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 #include "chrome/browser/google_apis/base_operations.h" | 5 #include "chrome/browser/google_apis/base_operations.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } else { | 62 } else { |
| 63 url_fetcher->GetResponseHeaders()->GetNormalizedHeaders(&headers); | 63 url_fetcher->GetResponseHeaders()->GetNormalizedHeaders(&headers); |
| 64 } | 64 } |
| 65 return headers; | 65 return headers; |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 namespace google_apis { | 70 namespace google_apis { |
| 71 | 71 |
| 72 void ParseJson(const std::string& data, const ParseJsonCallback& callback) { |
| 73 base::PostTaskAndReplyWithResult( |
| 74 BrowserThread::GetBlockingPool(), |
| 75 FROM_HERE, |
| 76 base::Bind(&ParseJsonOnBlockingPool, data), |
| 77 callback); |
| 78 } |
| 79 |
| 72 //============================ UrlFetchOperationBase =========================== | 80 //============================ UrlFetchOperationBase =========================== |
| 73 | 81 |
| 74 UrlFetchOperationBase::UrlFetchOperationBase( | 82 UrlFetchOperationBase::UrlFetchOperationBase( |
| 75 OperationRegistry* registry, | 83 OperationRegistry* registry, |
| 76 net::URLRequestContextGetter* url_request_context_getter) | 84 net::URLRequestContextGetter* url_request_context_getter) |
| 77 : OperationRegistry::Operation(registry), | 85 : OperationRegistry::Operation(registry), |
| 78 url_request_context_getter_(url_request_context_getter), | 86 url_request_context_getter_(url_request_context_getter), |
| 79 re_authenticate_count_(0), | 87 re_authenticate_count_(0), |
| 80 started_(false), | 88 started_(false), |
| 81 save_temp_file_(false), | 89 save_temp_file_(false), |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 290 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 283 DCHECK(!callback_.is_null()); | 291 DCHECK(!callback_.is_null()); |
| 284 } | 292 } |
| 285 | 293 |
| 286 GetDataOperation::~GetDataOperation() {} | 294 GetDataOperation::~GetDataOperation() {} |
| 287 | 295 |
| 288 void GetDataOperation::ParseResponse(GDataErrorCode fetch_error_code, | 296 void GetDataOperation::ParseResponse(GDataErrorCode fetch_error_code, |
| 289 const std::string& data) { | 297 const std::string& data) { |
| 290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 291 | 299 |
| 292 base::PostTaskAndReplyWithResult( | 300 ParseJson(data, |
| 293 BrowserThread::GetBlockingPool(), | 301 base::Bind(&GetDataOperation::OnDataParsed, |
| 294 FROM_HERE, | 302 weak_ptr_factory_.GetWeakPtr(), |
| 295 base::Bind(&ParseJsonOnBlockingPool, data), | 303 fetch_error_code)); |
| 296 base::Bind(&GetDataOperation::OnDataParsed, | |
| 297 weak_ptr_factory_.GetWeakPtr(), | |
| 298 fetch_error_code)); | |
| 299 } | 304 } |
| 300 | 305 |
| 301 void GetDataOperation::ProcessURLFetchResults(const URLFetcher* source) { | 306 void GetDataOperation::ProcessURLFetchResults(const URLFetcher* source) { |
| 302 std::string data; | 307 std::string data; |
| 303 source->GetResponseAsString(&data); | 308 source->GetResponseAsString(&data); |
| 304 scoped_ptr<base::Value> root_value; | 309 scoped_ptr<base::Value> root_value; |
| 305 GDataErrorCode fetch_error_code = GetErrorCode(source); | 310 GDataErrorCode fetch_error_code = GetErrorCode(source); |
| 306 | 311 |
| 307 switch (fetch_error_code) { | 312 switch (fetch_error_code) { |
| 308 case HTTP_SUCCESS: | 313 case HTTP_SUCCESS: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 339 OnProcessURLFetchResultsComplete(success); | 344 OnProcessURLFetchResultsComplete(success); |
| 340 } | 345 } |
| 341 | 346 |
| 342 void GetDataOperation::RunCallbackOnSuccess(GDataErrorCode fetch_error_code, | 347 void GetDataOperation::RunCallbackOnSuccess(GDataErrorCode fetch_error_code, |
| 343 scoped_ptr<base::Value> value) { | 348 scoped_ptr<base::Value> value) { |
| 344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 345 callback_.Run(fetch_error_code, value.Pass()); | 350 callback_.Run(fetch_error_code, value.Pass()); |
| 346 } | 351 } |
| 347 | 352 |
| 348 } // namespace google_apis | 353 } // namespace google_apis |
| OLD | NEW |