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/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 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 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() { | |
82 #if defined(OS_WIN) | |
83 const base::win::OSInfo* os_info = base::win::OSInfo::GetInstance(); | |
cpu_(ooo_6.6-7.5)
2014/09/17 21:28:18
no need to cache with os_info. GetInstance has it
Sorin Jianu
2014/09/17 21:45:35
Agreed on caching.
The local variable is to make
| |
84 if (os_info->version() != base::win::VERSION_XP) | |
waffles
2014/09/17 21:26:45
Do we need to do anything for VERSION_SERVER_2003
cpu_(ooo_6.6-7.5)
2014/09/17 21:28:18
use (version() < base::win::VERSION_VISTA)
Sorin Jianu
2014/09/17 21:29:06
We could, I hope cpu@ helps me clarify the conditi
Sorin Jianu
2014/09/17 21:45:36
Will it be possible that catches some other previo
| |
85 return false; | |
86 if (os_info->service_pack().major >= 3) | |
87 return false; | |
88 return true; | |
89 #else | |
90 return false; | |
91 #endif // OS_WIN | |
92 } | |
93 | |
70 // If there is an element of |vec| of the form |test|=.*, returns the right- | 94 // 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. | 95 // hand side of that assignment. Otherwise, returns an empty string. |
72 // The right-hand side may contain additional '=' characters, allowing for | 96 // The right-hand side may contain additional '=' characters, allowing for |
73 // further nesting of switch arguments. | 97 // further nesting of switch arguments. |
74 std::string GetSwitchArgument(const std::vector<std::string>& vec, | 98 std::string GetSwitchArgument(const std::vector<std::string>& vec, |
75 const char* test) { | 99 const char* test) { |
76 if (vec.empty()) | 100 if (vec.empty()) |
77 return std::string(); | 101 return std::string(); |
78 for (std::vector<std::string>::const_iterator it = vec.begin(); | 102 for (std::vector<std::string>::const_iterator it = vec.begin(); |
79 it != vec.end(); | 103 it != vec.end(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 GetSingleThreadTaskRunner() const OVERRIDE; | 144 GetSingleThreadTaskRunner() const OVERRIDE; |
121 | 145 |
122 private: | 146 private: |
123 net::URLRequestContextGetter* url_request_getter_; | 147 net::URLRequestContextGetter* url_request_getter_; |
124 std::string extra_info_; | 148 std::string extra_info_; |
125 GURL url_source_override_; | 149 GURL url_source_override_; |
126 bool fast_update_; | 150 bool fast_update_; |
127 bool pings_enabled_; | 151 bool pings_enabled_; |
128 bool deltas_enabled_; | 152 bool deltas_enabled_; |
129 bool background_downloads_enabled_; | 153 bool background_downloads_enabled_; |
154 bool fallback_to_alt_source_url_enabled_; | |
130 }; | 155 }; |
131 | 156 |
132 ChromeConfigurator::ChromeConfigurator( | 157 ChromeConfigurator::ChromeConfigurator( |
133 const CommandLine* cmdline, | 158 const CommandLine* cmdline, |
134 net::URLRequestContextGetter* url_request_getter) | 159 net::URLRequestContextGetter* url_request_getter) |
135 : url_request_getter_(url_request_getter), | 160 : url_request_getter_(url_request_getter), |
136 fast_update_(false), | 161 fast_update_(false), |
137 pings_enabled_(false), | 162 pings_enabled_(false), |
138 deltas_enabled_(false), | 163 deltas_enabled_(false), |
139 background_downloads_enabled_(false) { | 164 background_downloads_enabled_(false), |
165 fallback_to_alt_source_url_enabled_(false) { | |
140 // Parse comma-delimited debug flags. | 166 // Parse comma-delimited debug flags. |
141 std::vector<std::string> switch_values; | 167 std::vector<std::string> switch_values; |
142 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdater), | 168 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdater), |
143 ",", | 169 ",", |
144 &switch_values); | 170 &switch_values); |
145 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate); | 171 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate); |
146 pings_enabled_ = !HasSwitchValue(switch_values, kSwitchDisablePings); | 172 pings_enabled_ = !HasSwitchValue(switch_values, kSwitchDisablePings); |
147 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates); | 173 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates); |
148 | 174 |
149 #if defined(OS_WIN) | 175 #if defined(OS_WIN) |
150 background_downloads_enabled_ = | 176 background_downloads_enabled_ = |
151 !HasSwitchValue(switch_values, kSwitchDisableBackgroundDownloads); | 177 !HasSwitchValue(switch_values, kSwitchDisableBackgroundDownloads); |
152 #else | 178 #else |
153 background_downloads_enabled_ = false; | 179 background_downloads_enabled_ = false; |
154 #endif | 180 #endif |
155 | 181 |
156 const std::string switch_url_source = | 182 const std::string switch_url_source = |
157 GetSwitchArgument(switch_values, kSwitchUrlSource); | 183 GetSwitchArgument(switch_values, kSwitchUrlSource); |
158 if (!switch_url_source.empty()) { | 184 if (!switch_url_source.empty()) { |
159 url_source_override_ = GURL(switch_url_source); | 185 url_source_override_ = GURL(switch_url_source); |
160 DCHECK(url_source_override_.is_valid()); | 186 DCHECK(url_source_override_.is_valid()); |
161 } | 187 } |
162 | 188 |
163 if (HasSwitchValue(switch_values, kSwitchRequestParam)) | 189 if (HasSwitchValue(switch_values, kSwitchRequestParam)) |
164 extra_info_ += "testrequest=\"1\""; | 190 extra_info_ += "testrequest=\"1\""; |
191 | |
192 fallback_to_alt_source_url_enabled_ = CanUseAltUrlSource(); | |
165 } | 193 } |
166 | 194 |
167 int ChromeConfigurator::InitialDelay() const { | 195 int ChromeConfigurator::InitialDelay() const { |
168 return fast_update_ ? 1 : (6 * kDelayOneMinute); | 196 return fast_update_ ? 1 : (6 * kDelayOneMinute); |
169 } | 197 } |
170 | 198 |
171 int ChromeConfigurator::NextCheckDelay() { | 199 int ChromeConfigurator::NextCheckDelay() { |
172 return fast_update_ ? 3 : (6 * kDelayOneHour); | 200 return fast_update_ ? 3 : (6 * kDelayOneHour); |
173 } | 201 } |
174 | 202 |
(...skipping 12 matching lines...) Expand all Loading... | |
187 int ChromeConfigurator::OnDemandDelay() const { | 215 int ChromeConfigurator::OnDemandDelay() const { |
188 return fast_update_ ? 2 : (30 * kDelayOneMinute); | 216 return fast_update_ ? 2 : (30 * kDelayOneMinute); |
189 } | 217 } |
190 | 218 |
191 std::vector<GURL> ChromeConfigurator::UpdateUrl() const { | 219 std::vector<GURL> ChromeConfigurator::UpdateUrl() const { |
192 std::vector<GURL> urls; | 220 std::vector<GURL> urls; |
193 if (url_source_override_.is_valid()) { | 221 if (url_source_override_.is_valid()) { |
194 urls.push_back(GURL(url_source_override_)); | 222 urls.push_back(GURL(url_source_override_)); |
195 } else { | 223 } else { |
196 urls.push_back(GURL(kDefaultUrlSource)); | 224 urls.push_back(GURL(kDefaultUrlSource)); |
225 if (fallback_to_alt_source_url_enabled_) { | |
226 urls.push_back(GURL(kAltUrlSource)); | |
227 } | |
197 } | 228 } |
198 return urls; | 229 return urls; |
199 } | 230 } |
200 | 231 |
201 std::vector<GURL> ChromeConfigurator::PingUrl() const { | 232 std::vector<GURL> ChromeConfigurator::PingUrl() const { |
202 return pings_enabled_ ? UpdateUrl() : std::vector<GURL>(); | 233 return pings_enabled_ ? UpdateUrl() : std::vector<GURL>(); |
203 } | 234 } |
204 | 235 |
205 base::Version ChromeConfigurator::GetBrowserVersion() const { | 236 base::Version ChromeConfigurator::GetBrowserVersion() const { |
206 return base::Version(chrome::VersionInfo().Version()); | 237 return base::Version(chrome::VersionInfo().Version()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 | 290 |
260 } // namespace | 291 } // namespace |
261 | 292 |
262 Configurator* MakeChromeComponentUpdaterConfigurator( | 293 Configurator* MakeChromeComponentUpdaterConfigurator( |
263 const base::CommandLine* cmdline, | 294 const base::CommandLine* cmdline, |
264 net::URLRequestContextGetter* context_getter) { | 295 net::URLRequestContextGetter* context_getter) { |
265 return new ChromeConfigurator(cmdline, context_getter); | 296 return new ChromeConfigurator(cmdline, context_getter); |
266 } | 297 } |
267 | 298 |
268 } // namespace component_updater | 299 } // namespace component_updater |
OLD | NEW |