Chromium Code Reviews| 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/profile_resetter/brandcode_config_fetcher.h" | 5 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string> | |
|
engedy
2017/06/03 08:02:49
nit: Looks like <string> should already be include
waffles
2017/06/07 17:23:13
Done.
| |
| 9 #include <vector> | |
| 8 | 10 |
| 9 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h" | 15 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h" |
| 14 #include "libxml/parser.h" | 16 #include "libxml/parser.h" |
| 15 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
| 16 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
| 17 #include "net/traffic_annotation/network_traffic_annotation.h" | 19 #include "net/traffic_annotation/network_traffic_annotation.h" |
| 18 #include "net/url_request/url_fetcher.h" | 20 #include "net/url_request/url_fetcher.h" |
| 19 #include "net/url_request/url_request_status.h" | 21 #include "net/url_request/url_request_status.h" |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 const int kDownloadTimeoutSec = 10; | 25 const int kDownloadTimeoutSec = 10; |
| 24 const char kPostXml[] = | 26 const char kPostXml[] = |
| 25 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | 27 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 26 "<request version=\"1.3.17.0\" protocol=\"3.0\" testsource=\"dev\" " | 28 "<request" |
| 27 "shell_version=\"1.2.3.5\">\n" | 29 " version=\"chromeprofilereset-1.1\"" |
| 28 " <os platform=\"win\" version=\"6.1\" sp=\"\" arch=\"x86\" />\n" | 30 " protocol=\"3.0\"" |
| 29 " <app\n" | 31 " installsource=\"profilereset\">" |
| 30 " appid=\"{8A69D345-D564-463C-AFF1-A69D9E530F96}\"\n" | 32 " <app appid=\"{8A69D345-D564-463C-AFF1-A69D9E530F96}\">" |
| 31 " version=\"0.0.0.0\"\n" | 33 " <data name=\"install\" index=\"__BRANDCODE_PLACEHOLDER__\"/>" |
| 32 " >\n" | 34 " </app>" |
| 33 " <data name=\"install\" " | 35 "</request>"; |
| 34 "index=\"__BRANDCODE_PLACEHOLDER__\" />\n" | |
| 35 " </app>\n" | |
| 36 "</request>"; | |
| 37 | 36 |
| 38 // Returns the query to the server which can be used to retrieve the config. | 37 // Returns the query to the server which can be used to retrieve the config. |
| 39 // |brand| is a brand code, it mustn't be empty. | 38 // |brand| is a brand code, it mustn't be empty. |
| 40 std::string GetUploadData(const std::string& brand) { | 39 std::string GetUploadData(const std::string& brand) { |
| 41 DCHECK(!brand.empty()); | 40 DCHECK(!brand.empty()); |
| 42 std::string data(kPostXml); | 41 std::string data(kPostXml); |
| 43 const std::string placeholder("__BRANDCODE_PLACEHOLDER__"); | 42 const std::string placeholder("__BRANDCODE_PLACEHOLDER__"); |
| 44 size_t placeholder_pos = data.find(placeholder); | 43 size_t placeholder_pos = data.find(placeholder); |
| 45 DCHECK(placeholder_pos != std::string::npos); | 44 DCHECK(placeholder_pos != std::string::npos); |
| 46 data.replace(placeholder_pos, placeholder.size(), brand); | 45 data.replace(placeholder_pos, placeholder.size(), brand); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 std::string(reinterpret_cast<const char*>(ch), len); | 131 std::string(reinterpret_cast<const char*>(ch), len); |
| 133 } | 132 } |
| 134 } | 133 } |
| 135 | 134 |
| 136 bool XmlConfigParser::IsParsingData() const { | 135 bool XmlConfigParser::IsParsingData() const { |
| 137 const std::string data_path[] = {"response", "app", "data"}; | 136 const std::string data_path[] = {"response", "app", "data"}; |
| 138 return elements_.size() == arraysize(data_path) && | 137 return elements_.size() == arraysize(data_path) && |
| 139 std::equal(elements_.begin(), elements_.end(), data_path); | 138 std::equal(elements_.begin(), elements_.end(), data_path); |
| 140 } | 139 } |
| 141 | 140 |
| 142 } // namespace | 141 } // namespace |
| 143 | 142 |
| 144 BrandcodeConfigFetcher::BrandcodeConfigFetcher(const FetchCallback& callback, | 143 BrandcodeConfigFetcher::BrandcodeConfigFetcher(const FetchCallback& callback, |
| 145 const GURL& url, | 144 const GURL& url, |
| 146 const std::string& brandcode) | 145 const std::string& brandcode) |
| 147 : fetch_callback_(callback) { | 146 : fetch_callback_(callback) { |
| 148 DCHECK(!brandcode.empty()); | 147 DCHECK(!brandcode.empty()); |
| 149 net::NetworkTrafficAnnotationTag traffic_annotation = | 148 net::NetworkTrafficAnnotationTag traffic_annotation = |
| 150 net::DefineNetworkTrafficAnnotation("brandcode_config", R"( | 149 net::DefineNetworkTrafficAnnotation("brandcode_config", R"( |
| 151 semantics { | 150 semantics { |
| 152 sender: "Brandcode Configuration Fetcher" | 151 sender: "Brandcode Configuration Fetcher" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 download_timer_.Stop(); | 212 download_timer_.Stop(); |
| 214 base::ResetAndReturn(&fetch_callback_).Run(); | 213 base::ResetAndReturn(&fetch_callback_).Run(); |
| 215 } | 214 } |
| 216 | 215 |
| 217 void BrandcodeConfigFetcher::OnDownloadTimeout() { | 216 void BrandcodeConfigFetcher::OnDownloadTimeout() { |
| 218 if (config_fetcher_) { | 217 if (config_fetcher_) { |
| 219 config_fetcher_.reset(); | 218 config_fetcher_.reset(); |
| 220 base::ResetAndReturn(&fetch_callback_).Run(); | 219 base::ResetAndReturn(&fetch_callback_).Run(); |
| 221 } | 220 } |
| 222 } | 221 } |
| OLD | NEW |