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

Side by Side Diff: chrome/browser/profile_resetter/brandcode_config_fetcher.cc

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

Powered by Google App Engine
This is Rietveld 408576698