OLD | NEW |
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/win_util.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 Loading... |
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 some of the pre-Windows Vista versions not including |
| 80 // Windows XP SP3. As a side note, pings could be sent to the alternate URL too. |
| 81 bool CanUseAltUrlSource() { |
| 82 #if defined(OS_WIN) |
| 83 return !base::win::MaybeHasSHA256Support(); |
| 84 #else |
| 85 return false; |
| 86 #endif // OS_WIN |
| 87 } |
| 88 |
70 // If there is an element of |vec| of the form |test|=.*, returns the right- | 89 // 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. | 90 // hand side of that assignment. Otherwise, returns an empty string. |
72 // The right-hand side may contain additional '=' characters, allowing for | 91 // The right-hand side may contain additional '=' characters, allowing for |
73 // further nesting of switch arguments. | 92 // further nesting of switch arguments. |
74 std::string GetSwitchArgument(const std::vector<std::string>& vec, | 93 std::string GetSwitchArgument(const std::vector<std::string>& vec, |
75 const char* test) { | 94 const char* test) { |
76 if (vec.empty()) | 95 if (vec.empty()) |
77 return std::string(); | 96 return std::string(); |
78 for (std::vector<std::string>::const_iterator it = vec.begin(); | 97 for (std::vector<std::string>::const_iterator it = vec.begin(); |
79 it != vec.end(); | 98 it != vec.end(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 GetSingleThreadTaskRunner() const OVERRIDE; | 139 GetSingleThreadTaskRunner() const OVERRIDE; |
121 | 140 |
122 private: | 141 private: |
123 net::URLRequestContextGetter* url_request_getter_; | 142 net::URLRequestContextGetter* url_request_getter_; |
124 std::string extra_info_; | 143 std::string extra_info_; |
125 GURL url_source_override_; | 144 GURL url_source_override_; |
126 bool fast_update_; | 145 bool fast_update_; |
127 bool pings_enabled_; | 146 bool pings_enabled_; |
128 bool deltas_enabled_; | 147 bool deltas_enabled_; |
129 bool background_downloads_enabled_; | 148 bool background_downloads_enabled_; |
| 149 bool fallback_to_alt_source_url_enabled_; |
130 }; | 150 }; |
131 | 151 |
132 ChromeConfigurator::ChromeConfigurator( | 152 ChromeConfigurator::ChromeConfigurator( |
133 const CommandLine* cmdline, | 153 const CommandLine* cmdline, |
134 net::URLRequestContextGetter* url_request_getter) | 154 net::URLRequestContextGetter* url_request_getter) |
135 : url_request_getter_(url_request_getter), | 155 : url_request_getter_(url_request_getter), |
136 fast_update_(false), | 156 fast_update_(false), |
137 pings_enabled_(false), | 157 pings_enabled_(false), |
138 deltas_enabled_(false), | 158 deltas_enabled_(false), |
139 background_downloads_enabled_(false) { | 159 background_downloads_enabled_(false), |
| 160 fallback_to_alt_source_url_enabled_(false) { |
140 // Parse comma-delimited debug flags. | 161 // Parse comma-delimited debug flags. |
141 std::vector<std::string> switch_values; | 162 std::vector<std::string> switch_values; |
142 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdater), | 163 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdater), |
143 ",", | 164 ",", |
144 &switch_values); | 165 &switch_values); |
145 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate); | 166 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate); |
146 pings_enabled_ = !HasSwitchValue(switch_values, kSwitchDisablePings); | 167 pings_enabled_ = !HasSwitchValue(switch_values, kSwitchDisablePings); |
147 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates); | 168 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates); |
148 | 169 |
149 #if defined(OS_WIN) | 170 #if defined(OS_WIN) |
150 background_downloads_enabled_ = | 171 background_downloads_enabled_ = |
151 !HasSwitchValue(switch_values, kSwitchDisableBackgroundDownloads); | 172 !HasSwitchValue(switch_values, kSwitchDisableBackgroundDownloads); |
152 #else | 173 #else |
153 background_downloads_enabled_ = false; | 174 background_downloads_enabled_ = false; |
154 #endif | 175 #endif |
155 | 176 |
156 const std::string switch_url_source = | 177 const std::string switch_url_source = |
157 GetSwitchArgument(switch_values, kSwitchUrlSource); | 178 GetSwitchArgument(switch_values, kSwitchUrlSource); |
158 if (!switch_url_source.empty()) { | 179 if (!switch_url_source.empty()) { |
159 url_source_override_ = GURL(switch_url_source); | 180 url_source_override_ = GURL(switch_url_source); |
160 DCHECK(url_source_override_.is_valid()); | 181 DCHECK(url_source_override_.is_valid()); |
161 } | 182 } |
162 | 183 |
163 if (HasSwitchValue(switch_values, kSwitchRequestParam)) | 184 if (HasSwitchValue(switch_values, kSwitchRequestParam)) |
164 extra_info_ += "testrequest=\"1\""; | 185 extra_info_ += "testrequest=\"1\""; |
| 186 |
| 187 fallback_to_alt_source_url_enabled_ = CanUseAltUrlSource(); |
165 } | 188 } |
166 | 189 |
167 int ChromeConfigurator::InitialDelay() const { | 190 int ChromeConfigurator::InitialDelay() const { |
168 return fast_update_ ? 1 : (6 * kDelayOneMinute); | 191 return fast_update_ ? 1 : (6 * kDelayOneMinute); |
169 } | 192 } |
170 | 193 |
171 int ChromeConfigurator::NextCheckDelay() { | 194 int ChromeConfigurator::NextCheckDelay() { |
172 return fast_update_ ? 3 : (6 * kDelayOneHour); | 195 return fast_update_ ? 3 : (6 * kDelayOneHour); |
173 } | 196 } |
174 | 197 |
(...skipping 12 matching lines...) Expand all Loading... |
187 int ChromeConfigurator::OnDemandDelay() const { | 210 int ChromeConfigurator::OnDemandDelay() const { |
188 return fast_update_ ? 2 : (30 * kDelayOneMinute); | 211 return fast_update_ ? 2 : (30 * kDelayOneMinute); |
189 } | 212 } |
190 | 213 |
191 std::vector<GURL> ChromeConfigurator::UpdateUrl() const { | 214 std::vector<GURL> ChromeConfigurator::UpdateUrl() const { |
192 std::vector<GURL> urls; | 215 std::vector<GURL> urls; |
193 if (url_source_override_.is_valid()) { | 216 if (url_source_override_.is_valid()) { |
194 urls.push_back(GURL(url_source_override_)); | 217 urls.push_back(GURL(url_source_override_)); |
195 } else { | 218 } else { |
196 urls.push_back(GURL(kDefaultUrlSource)); | 219 urls.push_back(GURL(kDefaultUrlSource)); |
| 220 if (fallback_to_alt_source_url_enabled_) { |
| 221 urls.push_back(GURL(kAltUrlSource)); |
| 222 } |
197 } | 223 } |
198 return urls; | 224 return urls; |
199 } | 225 } |
200 | 226 |
201 std::vector<GURL> ChromeConfigurator::PingUrl() const { | 227 std::vector<GURL> ChromeConfigurator::PingUrl() const { |
202 return pings_enabled_ ? UpdateUrl() : std::vector<GURL>(); | 228 return pings_enabled_ ? UpdateUrl() : std::vector<GURL>(); |
203 } | 229 } |
204 | 230 |
205 base::Version ChromeConfigurator::GetBrowserVersion() const { | 231 base::Version ChromeConfigurator::GetBrowserVersion() const { |
206 return base::Version(chrome::VersionInfo().Version()); | 232 return base::Version(chrome::VersionInfo().Version()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 285 |
260 } // namespace | 286 } // namespace |
261 | 287 |
262 Configurator* MakeChromeComponentUpdaterConfigurator( | 288 Configurator* MakeChromeComponentUpdaterConfigurator( |
263 const base::CommandLine* cmdline, | 289 const base::CommandLine* cmdline, |
264 net::URLRequestContextGetter* context_getter) { | 290 net::URLRequestContextGetter* context_getter) { |
265 return new ChromeConfigurator(cmdline, context_getter); | 291 return new ChromeConfigurator(cmdline, context_getter); |
266 } | 292 } |
267 | 293 |
268 } // namespace component_updater | 294 } // namespace component_updater |
OLD | NEW |