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

Side by Side Diff: chrome/browser/component_updater/chrome_component_updater_configurator.cc

Issue 581803002: Component updater must fallback on using HTTP on Windows XPSP2 and below (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 6 years, 3 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 | « no previous file | 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/component_updater/chrome_component_updater_configurator .h" 5 #include "chrome/browser/component_updater/chrome_component_updater_configurator .h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/version.h" 14 #include "base/version.h"
15 #if defined(OS_WIN)
16 #include "base/win/windows_version.h"
17 #endif // OS_WIN
15 #include "build/build_config.h" 18 #include "build/build_config.h"
16 #include "chrome/browser/component_updater/component_patcher_operation_out_of_pr ocess.h" 19 #include "chrome/browser/component_updater/component_patcher_operation_out_of_pr ocess.h"
17 #include "chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.h " 20 #include "chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.h "
18 #include "chrome/common/chrome_version_info.h" 21 #include "chrome/common/chrome_version_info.h"
19 #include "components/component_updater/component_updater_configurator.h" 22 #include "components/component_updater/component_updater_configurator.h"
20 #include "components/component_updater/component_updater_switches.h" 23 #include "components/component_updater/component_updater_switches.h"
21 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
22 #include "net/url_request/url_request_context_getter.h" 25 #include "net/url_request/url_request_context_getter.h"
23 #include "url/gurl.h" 26 #include "url/gurl.h"
24 27
(...skipping 15 matching lines...) Expand all
40 // Disables pings. Pings are the requests sent to the update server that report 43 // Disables pings. Pings are the requests sent to the update server that report
41 // the success or the failure of component install or update attempts. 44 // the success or the failure of component install or update attempts.
42 extern const char kSwitchDisablePings[] = "disable-pings"; 45 extern const char kSwitchDisablePings[] = "disable-pings";
43 46
44 // Sets the URL for updates. 47 // Sets the URL for updates.
45 const char kSwitchUrlSource[] = "url-source"; 48 const char kSwitchUrlSource[] = "url-source";
46 49
47 #define COMPONENT_UPDATER_SERVICE_ENDPOINT \ 50 #define COMPONENT_UPDATER_SERVICE_ENDPOINT \
48 "//clients2.google.com/service/update2" 51 "//clients2.google.com/service/update2"
49 52
50 // The default url for the v3 protocol service endpoint. 53 // The default URL for the v3 protocol service endpoint. In some cases, the
54 // component updater is allowed to fall back to and alternate URL source, if
55 // the request to the default URL source fails.
51 // The value of |kDefaultUrlSource| can be overridden with 56 // The value of |kDefaultUrlSource| can be overridden with
52 // --component-updater=url-source=someurl. 57 // --component-updater=url-source=someurl.
53 const char kDefaultUrlSource[] = "https:" COMPONENT_UPDATER_SERVICE_ENDPOINT; 58 const char kDefaultUrlSource[] = "https:" COMPONENT_UPDATER_SERVICE_ENDPOINT;
59 const char kAltUrlSource[] = "http:" COMPONENT_UPDATER_SERVICE_ENDPOINT;
54 60
55 // Disables differential updates. 61 // Disables differential updates.
56 const char kSwitchDisableDeltaUpdates[] = "disable-delta-updates"; 62 const char kSwitchDisableDeltaUpdates[] = "disable-delta-updates";
57 63
58 #if defined(OS_WIN) 64 #if defined(OS_WIN)
59 // Disables background downloads. 65 // Disables background downloads.
60 const char kSwitchDisableBackgroundDownloads[] = "disable-background-downloads"; 66 const char kSwitchDisableBackgroundDownloads[] = "disable-background-downloads";
61 #endif // defined(OS_WIN) 67 #endif // defined(OS_WIN)
62 68
63 // Returns true if and only if |test| is contained in |vec|. 69 // Returns true if and only if |test| is contained in |vec|.
64 bool HasSwitchValue(const std::vector<std::string>& vec, const char* test) { 70 bool HasSwitchValue(const std::vector<std::string>& vec, const char* test) {
65 if (vec.empty()) 71 if (vec.empty())
66 return 0; 72 return 0;
67 return (std::find(vec.begin(), vec.end(), test) != vec.end()); 73 return (std::find(vec.begin(), vec.end(), test) != vec.end());
68 } 74 }
69 75
76 // Returns true if falling back on an alternate, unsafe, service URL is
77 // allowed. In the fallback case, the security of the component update relies
78 // only on the integrity of the CRX payloads, which is self-validating.
79 // This is allowed only for Windows XP systems up to and including SP2. As a
80 // side note, pings could be sent to the alternate URL too.
81 bool CanUseAltUrlSource() {
Will Harris 2014/09/17 23:29:16 This code is also in SSLErrorClassification::IsWin
82 #if defined(OS_WIN)
83 if (base::win::OSInfo::GetInstance()->version() != base::win::VERSION_XP)
84 return false;
85 if (base::win::OSInfo::GetInstance()->service_pack().major >= 3)
86 return false;
87 return true;
88 #else
89 return false;
90 #endif // OS_WIN
91 }
92
70 // If there is an element of |vec| of the form |test|=.*, returns the right- 93 // If there is an element of |vec| of the form |test|=.*, returns the right-
71 // hand side of that assignment. Otherwise, returns an empty string. 94 // hand side of that assignment. Otherwise, returns an empty string.
72 // The right-hand side may contain additional '=' characters, allowing for 95 // The right-hand side may contain additional '=' characters, allowing for
73 // further nesting of switch arguments. 96 // further nesting of switch arguments.
74 std::string GetSwitchArgument(const std::vector<std::string>& vec, 97 std::string GetSwitchArgument(const std::vector<std::string>& vec,
75 const char* test) { 98 const char* test) {
76 if (vec.empty()) 99 if (vec.empty())
77 return std::string(); 100 return std::string();
78 for (std::vector<std::string>::const_iterator it = vec.begin(); 101 for (std::vector<std::string>::const_iterator it = vec.begin();
79 it != vec.end(); 102 it != vec.end();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 GetSingleThreadTaskRunner() const OVERRIDE; 143 GetSingleThreadTaskRunner() const OVERRIDE;
121 144
122 private: 145 private:
123 net::URLRequestContextGetter* url_request_getter_; 146 net::URLRequestContextGetter* url_request_getter_;
124 std::string extra_info_; 147 std::string extra_info_;
125 GURL url_source_override_; 148 GURL url_source_override_;
126 bool fast_update_; 149 bool fast_update_;
127 bool pings_enabled_; 150 bool pings_enabled_;
128 bool deltas_enabled_; 151 bool deltas_enabled_;
129 bool background_downloads_enabled_; 152 bool background_downloads_enabled_;
153 bool fallback_to_alt_source_url_enabled_;
130 }; 154 };
131 155
132 ChromeConfigurator::ChromeConfigurator( 156 ChromeConfigurator::ChromeConfigurator(
133 const CommandLine* cmdline, 157 const CommandLine* cmdline,
134 net::URLRequestContextGetter* url_request_getter) 158 net::URLRequestContextGetter* url_request_getter)
135 : url_request_getter_(url_request_getter), 159 : url_request_getter_(url_request_getter),
136 fast_update_(false), 160 fast_update_(false),
137 pings_enabled_(false), 161 pings_enabled_(false),
138 deltas_enabled_(false), 162 deltas_enabled_(false),
139 background_downloads_enabled_(false) { 163 background_downloads_enabled_(false),
164 fallback_to_alt_source_url_enabled_(false) {
140 // Parse comma-delimited debug flags. 165 // Parse comma-delimited debug flags.
141 std::vector<std::string> switch_values; 166 std::vector<std::string> switch_values;
142 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdater), 167 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdater),
143 ",", 168 ",",
144 &switch_values); 169 &switch_values);
145 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate); 170 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate);
146 pings_enabled_ = !HasSwitchValue(switch_values, kSwitchDisablePings); 171 pings_enabled_ = !HasSwitchValue(switch_values, kSwitchDisablePings);
147 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates); 172 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates);
148 173
149 #if defined(OS_WIN) 174 #if defined(OS_WIN)
150 background_downloads_enabled_ = 175 background_downloads_enabled_ =
151 !HasSwitchValue(switch_values, kSwitchDisableBackgroundDownloads); 176 !HasSwitchValue(switch_values, kSwitchDisableBackgroundDownloads);
152 #else 177 #else
153 background_downloads_enabled_ = false; 178 background_downloads_enabled_ = false;
154 #endif 179 #endif
155 180
156 const std::string switch_url_source = 181 const std::string switch_url_source =
157 GetSwitchArgument(switch_values, kSwitchUrlSource); 182 GetSwitchArgument(switch_values, kSwitchUrlSource);
158 if (!switch_url_source.empty()) { 183 if (!switch_url_source.empty()) {
159 url_source_override_ = GURL(switch_url_source); 184 url_source_override_ = GURL(switch_url_source);
160 DCHECK(url_source_override_.is_valid()); 185 DCHECK(url_source_override_.is_valid());
161 } 186 }
162 187
163 if (HasSwitchValue(switch_values, kSwitchRequestParam)) 188 if (HasSwitchValue(switch_values, kSwitchRequestParam))
164 extra_info_ += "testrequest=\"1\""; 189 extra_info_ += "testrequest=\"1\"";
190
191 fallback_to_alt_source_url_enabled_ = CanUseAltUrlSource();
165 } 192 }
166 193
167 int ChromeConfigurator::InitialDelay() const { 194 int ChromeConfigurator::InitialDelay() const {
168 return fast_update_ ? 1 : (6 * kDelayOneMinute); 195 return fast_update_ ? 1 : (6 * kDelayOneMinute);
169 } 196 }
170 197
171 int ChromeConfigurator::NextCheckDelay() { 198 int ChromeConfigurator::NextCheckDelay() {
172 return fast_update_ ? 3 : (6 * kDelayOneHour); 199 return fast_update_ ? 3 : (6 * kDelayOneHour);
173 } 200 }
174 201
(...skipping 12 matching lines...) Expand all
187 int ChromeConfigurator::OnDemandDelay() const { 214 int ChromeConfigurator::OnDemandDelay() const {
188 return fast_update_ ? 2 : (30 * kDelayOneMinute); 215 return fast_update_ ? 2 : (30 * kDelayOneMinute);
189 } 216 }
190 217
191 std::vector<GURL> ChromeConfigurator::UpdateUrl() const { 218 std::vector<GURL> ChromeConfigurator::UpdateUrl() const {
192 std::vector<GURL> urls; 219 std::vector<GURL> urls;
193 if (url_source_override_.is_valid()) { 220 if (url_source_override_.is_valid()) {
194 urls.push_back(GURL(url_source_override_)); 221 urls.push_back(GURL(url_source_override_));
195 } else { 222 } else {
196 urls.push_back(GURL(kDefaultUrlSource)); 223 urls.push_back(GURL(kDefaultUrlSource));
224 if (fallback_to_alt_source_url_enabled_) {
225 urls.push_back(GURL(kAltUrlSource));
226 }
197 } 227 }
198 return urls; 228 return urls;
199 } 229 }
200 230
201 std::vector<GURL> ChromeConfigurator::PingUrl() const { 231 std::vector<GURL> ChromeConfigurator::PingUrl() const {
202 return pings_enabled_ ? UpdateUrl() : std::vector<GURL>(); 232 return pings_enabled_ ? UpdateUrl() : std::vector<GURL>();
203 } 233 }
204 234
205 base::Version ChromeConfigurator::GetBrowserVersion() const { 235 base::Version ChromeConfigurator::GetBrowserVersion() const {
206 return base::Version(chrome::VersionInfo().Version()); 236 return base::Version(chrome::VersionInfo().Version());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 289
260 } // namespace 290 } // namespace
261 291
262 Configurator* MakeChromeComponentUpdaterConfigurator( 292 Configurator* MakeChromeComponentUpdaterConfigurator(
263 const base::CommandLine* cmdline, 293 const base::CommandLine* cmdline,
264 net::URLRequestContextGetter* context_getter) { 294 net::URLRequestContextGetter* context_getter) {
265 return new ChromeConfigurator(cmdline, context_getter); 295 return new ChromeConfigurator(cmdline, context_getter);
266 } 296 }
267 297
268 } // namespace component_updater 298 } // namespace component_updater
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698