| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extensions/webstore_data_fetcher.h" | 5 #include "chrome/browser/extensions/webstore_data_fetcher.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/values.h" | 10 #include "base/values.h" |
| 9 #include "chrome/browser/extensions/webstore_data_fetcher_delegate.h" | 11 #include "chrome/browser/extensions/webstore_data_fetcher_delegate.h" |
| 10 #include "components/safe_json/safe_json_parser.h" | 12 #include "components/safe_json/safe_json_parser.h" |
| 11 #include "extensions/common/extension_urls.h" | 13 #include "extensions/common/extension_urls.h" |
| 12 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 13 #include "net/url_request/url_fetcher.h" | 15 #include "net/url_request/url_fetcher.h" |
| 14 #include "net/url_request/url_request_status.h" | 16 #include "net/url_request/url_request_status.h" |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } | 66 } |
| 65 | 67 |
| 66 void WebstoreDataFetcher::OnJsonParseFailure( | 68 void WebstoreDataFetcher::OnJsonParseFailure( |
| 67 const std::string& error) { | 69 const std::string& error) { |
| 68 delegate_->OnWebstoreResponseParseFailure(error); | 70 delegate_->OnWebstoreResponseParseFailure(error); |
| 69 } | 71 } |
| 70 | 72 |
| 71 void WebstoreDataFetcher::OnURLFetchComplete(const net::URLFetcher* source) { | 73 void WebstoreDataFetcher::OnURLFetchComplete(const net::URLFetcher* source) { |
| 72 CHECK_EQ(webstore_data_url_fetcher_.get(), source); | 74 CHECK_EQ(webstore_data_url_fetcher_.get(), source); |
| 73 | 75 |
| 74 scoped_ptr<net::URLFetcher> fetcher(webstore_data_url_fetcher_.Pass()); | 76 scoped_ptr<net::URLFetcher> fetcher(std::move(webstore_data_url_fetcher_)); |
| 75 | 77 |
| 76 if (!fetcher->GetStatus().is_success() || | 78 if (!fetcher->GetStatus().is_success() || |
| 77 fetcher->GetResponseCode() != 200) { | 79 fetcher->GetResponseCode() != 200) { |
| 78 delegate_->OnWebstoreRequestFailure(); | 80 delegate_->OnWebstoreRequestFailure(); |
| 79 return; | 81 return; |
| 80 } | 82 } |
| 81 | 83 |
| 82 std::string webstore_json_data; | 84 std::string webstore_json_data; |
| 83 fetcher->GetResponseAsString(&webstore_json_data); | 85 fetcher->GetResponseAsString(&webstore_json_data); |
| 84 | 86 |
| 85 // The parser will call us back via one of the callbacks. | 87 // The parser will call us back via one of the callbacks. |
| 86 safe_json::SafeJsonParser::Parse( | 88 safe_json::SafeJsonParser::Parse( |
| 87 webstore_json_data, | 89 webstore_json_data, |
| 88 base::Bind(&WebstoreDataFetcher::OnJsonParseSuccess, AsWeakPtr()), | 90 base::Bind(&WebstoreDataFetcher::OnJsonParseSuccess, AsWeakPtr()), |
| 89 base::Bind(&WebstoreDataFetcher::OnJsonParseFailure, AsWeakPtr())); | 91 base::Bind(&WebstoreDataFetcher::OnJsonParseFailure, AsWeakPtr())); |
| 90 } | 92 } |
| 91 | 93 |
| 92 } // namespace extensions | 94 } // namespace extensions |
| OLD | NEW |