| 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> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 const std::string webstore_item_id) | 30 const std::string webstore_item_id) |
| 31 : delegate_(delegate), | 31 : delegate_(delegate), |
| 32 request_context_(request_context), | 32 request_context_(request_context), |
| 33 referrer_url_(referrer_url), | 33 referrer_url_(referrer_url), |
| 34 id_(webstore_item_id), | 34 id_(webstore_item_id), |
| 35 max_auto_retries_(0) { | 35 max_auto_retries_(0) { |
| 36 } | 36 } |
| 37 | 37 |
| 38 WebstoreDataFetcher::~WebstoreDataFetcher() {} | 38 WebstoreDataFetcher::~WebstoreDataFetcher() {} |
| 39 | 39 |
| 40 void WebstoreDataFetcher::SetJsonPostData(const std::string& json) { |
| 41 json_post_data_ = json; |
| 42 } |
| 43 |
| 40 void WebstoreDataFetcher::Start() { | 44 void WebstoreDataFetcher::Start() { |
| 41 GURL webstore_data_url(extension_urls::GetWebstoreItemJsonDataURL(id_)); | 45 GURL webstore_data_url(extension_urls::GetWebstoreItemJsonDataURL(id_)); |
| 42 | 46 net::URLFetcher::RequestType request_type = |
| 47 json_post_data_.empty() ? net::URLFetcher::GET : net::URLFetcher::POST; |
| 43 webstore_data_url_fetcher_ = | 48 webstore_data_url_fetcher_ = |
| 44 net::URLFetcher::Create(webstore_data_url, net::URLFetcher::GET, this); | 49 net::URLFetcher::Create(webstore_data_url, request_type, this); |
| 45 webstore_data_url_fetcher_->SetRequestContext(request_context_); | 50 webstore_data_url_fetcher_->SetRequestContext(request_context_); |
| 46 webstore_data_url_fetcher_->SetReferrer(referrer_url_.spec()); | 51 webstore_data_url_fetcher_->SetReferrer(referrer_url_.spec()); |
| 47 webstore_data_url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 52 webstore_data_url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | |
| 48 net::LOAD_DISABLE_CACHE); | 53 net::LOAD_DISABLE_CACHE); |
| 54 |
| 55 if (!json_post_data_.empty()) { |
| 56 webstore_data_url_fetcher_->SetUploadData("application/json", |
| 57 json_post_data_); |
| 58 } |
| 59 |
| 49 if (max_auto_retries_ > 0) { | 60 if (max_auto_retries_ > 0) { |
| 50 webstore_data_url_fetcher_->SetMaxRetriesOn5xx(max_auto_retries_); | 61 webstore_data_url_fetcher_->SetMaxRetriesOn5xx(max_auto_retries_); |
| 51 webstore_data_url_fetcher_->SetAutomaticallyRetryOnNetworkChanges( | 62 webstore_data_url_fetcher_->SetAutomaticallyRetryOnNetworkChanges( |
| 52 max_auto_retries_); | 63 max_auto_retries_); |
| 53 } | 64 } |
| 54 webstore_data_url_fetcher_->Start(); | 65 webstore_data_url_fetcher_->Start(); |
| 55 } | 66 } |
| 56 | 67 |
| 57 void WebstoreDataFetcher::OnJsonParseSuccess( | 68 void WebstoreDataFetcher::OnJsonParseSuccess( |
| 58 std::unique_ptr<base::Value> parsed_json) { | 69 std::unique_ptr<base::Value> parsed_json) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 87 fetcher->GetResponseAsString(&webstore_json_data); | 98 fetcher->GetResponseAsString(&webstore_json_data); |
| 88 | 99 |
| 89 // The parser will call us back via one of the callbacks. | 100 // The parser will call us back via one of the callbacks. |
| 90 safe_json::SafeJsonParser::Parse( | 101 safe_json::SafeJsonParser::Parse( |
| 91 webstore_json_data, | 102 webstore_json_data, |
| 92 base::Bind(&WebstoreDataFetcher::OnJsonParseSuccess, AsWeakPtr()), | 103 base::Bind(&WebstoreDataFetcher::OnJsonParseSuccess, AsWeakPtr()), |
| 93 base::Bind(&WebstoreDataFetcher::OnJsonParseFailure, AsWeakPtr())); | 104 base::Bind(&WebstoreDataFetcher::OnJsonParseFailure, AsWeakPtr())); |
| 94 } | 105 } |
| 95 | 106 |
| 96 } // namespace extensions | 107 } // namespace extensions |
| OLD | NEW |