OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/component_updater_configurator.h" | 5 #include "chrome/browser/component_updater/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/strings/stringprintf.h" | |
15 #include "base/sys_info.h" | |
16 #include "base/win/windows_version.h" | |
14 #include "build/build_config.h" | 17 #include "build/build_config.h" |
18 #include "chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.h " | |
19 #include "chrome/common/chrome_version_info.h" | |
15 #include "components/component_updater/component_updater_switches.h" | 20 #include "components/component_updater/component_updater_switches.h" |
21 #include "components/omaha_query_params/omaha_query_params.h" | |
16 #include "net/url_request/url_request_context_getter.h" | 22 #include "net/url_request/url_request_context_getter.h" |
17 #include "url/gurl.h" | 23 #include "url/gurl.h" |
18 | 24 |
25 using omaha_query_params::OmahaQueryParams; | |
26 | |
19 namespace component_updater { | 27 namespace component_updater { |
20 | 28 |
21 namespace { | 29 namespace { |
22 | 30 |
23 // Default time constants. | 31 // Default time constants. |
24 const int kDelayOneMinute = 60; | 32 const int kDelayOneMinute = 60; |
25 const int kDelayOneHour = kDelayOneMinute * 60; | 33 const int kDelayOneHour = kDelayOneMinute * 60; |
26 | 34 |
27 // Debug values you can pass to --component-updater=value1,value2. | 35 // Debug values you can pass to --component-updater=value1,value2. |
28 // Speed up component checking. | 36 // Speed up component checking. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 virtual ~ChromeConfigurator() {} | 102 virtual ~ChromeConfigurator() {} |
95 | 103 |
96 virtual int InitialDelay() const OVERRIDE; | 104 virtual int InitialDelay() const OVERRIDE; |
97 virtual int NextCheckDelay() OVERRIDE; | 105 virtual int NextCheckDelay() OVERRIDE; |
98 virtual int StepDelay() const OVERRIDE; | 106 virtual int StepDelay() const OVERRIDE; |
99 virtual int StepDelayMedium() OVERRIDE; | 107 virtual int StepDelayMedium() OVERRIDE; |
100 virtual int MinimumReCheckWait() const OVERRIDE; | 108 virtual int MinimumReCheckWait() const OVERRIDE; |
101 virtual int OnDemandDelay() const OVERRIDE; | 109 virtual int OnDemandDelay() const OVERRIDE; |
102 virtual GURL UpdateUrl() const OVERRIDE; | 110 virtual GURL UpdateUrl() const OVERRIDE; |
103 virtual GURL PingUrl() const OVERRIDE; | 111 virtual GURL PingUrl() const OVERRIDE; |
112 virtual base::Version ApplicationVersion() const OVERRIDE; | |
113 virtual std::string PlatformRequestParams() const OVERRIDE; | |
104 virtual std::string ExtraRequestParams() const OVERRIDE; | 114 virtual std::string ExtraRequestParams() const OVERRIDE; |
115 virtual std::string RequestOSTag() const OVERRIDE; | |
105 virtual size_t UrlSizeLimit() const OVERRIDE; | 116 virtual size_t UrlSizeLimit() const OVERRIDE; |
106 virtual net::URLRequestContextGetter* RequestContext() const OVERRIDE; | 117 virtual net::URLRequestContextGetter* RequestContext() const OVERRIDE; |
107 virtual bool InProcess() const OVERRIDE; | 118 virtual bool InProcess() const OVERRIDE; |
108 virtual bool DeltasEnabled() const OVERRIDE; | 119 virtual bool DeltasEnabled() const OVERRIDE; |
109 virtual bool UseBackgroundDownloader() const OVERRIDE; | 120 virtual bool UseBackgroundDownloader() const OVERRIDE; |
110 | 121 |
111 private: | 122 private: |
112 net::URLRequestContextGetter* url_request_getter_; | 123 net::URLRequestContextGetter* url_request_getter_; |
124 std::string platform_request_params_; | |
113 std::string extra_info_; | 125 std::string extra_info_; |
114 std::string url_source_; | 126 std::string url_source_; |
115 bool fast_update_; | 127 bool fast_update_; |
116 bool pings_enabled_; | 128 bool pings_enabled_; |
117 bool deltas_enabled_; | 129 bool deltas_enabled_; |
118 bool background_downloads_enabled_; | 130 bool background_downloads_enabled_; |
119 }; | 131 }; |
120 | 132 |
121 ChromeConfigurator::ChromeConfigurator( | 133 ChromeConfigurator::ChromeConfigurator( |
122 const CommandLine* cmdline, | 134 const CommandLine* cmdline, |
(...skipping 17 matching lines...) Expand all Loading... | |
140 !HasSwitchValue(switch_values, kSwitchDisableBackgroundDownloads); | 152 !HasSwitchValue(switch_values, kSwitchDisableBackgroundDownloads); |
141 #else | 153 #else |
142 background_downloads_enabled_ = false; | 154 background_downloads_enabled_ = false; |
143 #endif | 155 #endif |
144 | 156 |
145 url_source_ = GetSwitchArgument(switch_values, kSwitchUrlSource); | 157 url_source_ = GetSwitchArgument(switch_values, kSwitchUrlSource); |
146 if (url_source_.empty()) { | 158 if (url_source_.empty()) { |
147 url_source_ = kDefaultUrlSource; | 159 url_source_ = kDefaultUrlSource; |
148 } | 160 } |
149 | 161 |
162 const std::string prod_id( | |
163 OmahaQueryParams::GetProdIdString(OmahaQueryParams::CHROME)); | |
164 const chrome::VersionInfo chrome_version_info; | |
165 const std::string chrome_version(chrome_version_info.Version()); | |
166 const std::string channel(ChromeOmahaQueryParamsDelegate::GetChannelString()); | |
167 const std::string lang(ChromeOmahaQueryParamsDelegate::GetLang()); | |
168 platform_request_params_ = base::StringPrintf( | |
169 "version=\"%s-%s\" prodversion=\"%s\" " | |
170 "lang=\"%s\" updaterchannel=\"%s\" prodchannel=\"%s\" " | |
171 "os=\"%s\" arch=\"%s\" nacl_arch=\"%s\"", | |
172 prod_id.c_str(), | |
173 chrome_version.c_str(), // "version" | |
174 chrome_version.c_str(), // "prodversion" | |
175 lang.c_str(), // "lang", | |
176 channel.c_str(), // "updaterchannel" | |
177 channel.c_str(), // "prodchannel" | |
178 OmahaQueryParams::GetOS(), // "os" | |
179 OmahaQueryParams::GetArch(), // "arch" | |
180 OmahaQueryParams::GetNaclArch()); // "nacl_arch" | |
181 #if defined(OS_WIN) | |
182 if (base::win::OSInfo::GetInstance()->wow64_status() == | |
183 base::win::OSInfo::WOW64_ENABLED) { | |
184 base::StringAppendF(&platform_request_params, " wow64=\"1\""); | |
185 } | |
186 #endif | |
187 | |
150 if (HasSwitchValue(switch_values, kSwitchRequestParam)) | 188 if (HasSwitchValue(switch_values, kSwitchRequestParam)) |
151 extra_info_ += "testrequest=\"1\""; | 189 extra_info_ += "testrequest=\"1\""; |
152 } | 190 } |
153 | 191 |
154 int ChromeConfigurator::InitialDelay() const { | 192 int ChromeConfigurator::InitialDelay() const { |
155 return fast_update_ ? 1 : (6 * kDelayOneMinute); | 193 return fast_update_ ? 1 : (6 * kDelayOneMinute); |
156 } | 194 } |
157 | 195 |
158 int ChromeConfigurator::NextCheckDelay() { | 196 int ChromeConfigurator::NextCheckDelay() { |
159 return fast_update_ ? 3 : (6 * kDelayOneHour); | 197 return fast_update_ ? 3 : (6 * kDelayOneHour); |
(...skipping 16 matching lines...) Expand all Loading... | |
176 } | 214 } |
177 | 215 |
178 GURL ChromeConfigurator::UpdateUrl() const { | 216 GURL ChromeConfigurator::UpdateUrl() const { |
179 return GURL(url_source_); | 217 return GURL(url_source_); |
180 } | 218 } |
181 | 219 |
182 GURL ChromeConfigurator::PingUrl() const { | 220 GURL ChromeConfigurator::PingUrl() const { |
183 return pings_enabled_ ? GURL(kPingUrl) : GURL(); | 221 return pings_enabled_ ? GURL(kPingUrl) : GURL(); |
184 } | 222 } |
185 | 223 |
224 base::Version ChromeConfigurator::ApplicationVersion() const { | |
225 return base::Version(chrome::VersionInfo().Version()); | |
226 } | |
227 | |
228 std::string ChromeConfigurator::PlatformRequestParams() const { | |
229 return platform_request_params_; | |
230 } | |
231 | |
186 std::string ChromeConfigurator::ExtraRequestParams() const { | 232 std::string ChromeConfigurator::ExtraRequestParams() const { |
187 return extra_info_; | 233 return extra_info_; |
188 } | 234 } |
189 | 235 |
236 std::string ChromeConfigurator::RequestOSTag() const { | |
Sorin Jianu
2014/07/09 08:29:16
I'll say up front I don't know of a good design he
tommycli
2014/07/09 19:48:10
Done.
| |
237 return base::StringPrintf( | |
238 "<os platform=\"%s\" version=\"%s\" arch=\"%s\"/>", | |
239 chrome::VersionInfo().OSType().c_str(), // "platform" | |
240 base::SysInfo().OperatingSystemVersion().c_str(), // "version" | |
241 base::SysInfo().OperatingSystemArchitecture().c_str()); // "arch" | |
242 } | |
243 | |
190 size_t ChromeConfigurator::UrlSizeLimit() const { | 244 size_t ChromeConfigurator::UrlSizeLimit() const { |
191 return 1024ul; | 245 return 1024ul; |
192 } | 246 } |
193 | 247 |
194 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() const { | 248 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() const { |
195 return url_request_getter_; | 249 return url_request_getter_; |
196 } | 250 } |
197 | 251 |
198 bool ChromeConfigurator::InProcess() const { | 252 bool ChromeConfigurator::InProcess() const { |
199 return false; | 253 return false; |
200 } | 254 } |
201 | 255 |
202 bool ChromeConfigurator::DeltasEnabled() const { | 256 bool ChromeConfigurator::DeltasEnabled() const { |
203 return deltas_enabled_; | 257 return deltas_enabled_; |
204 } | 258 } |
205 | 259 |
206 bool ChromeConfigurator::UseBackgroundDownloader() const { | 260 bool ChromeConfigurator::UseBackgroundDownloader() const { |
207 return background_downloads_enabled_; | 261 return background_downloads_enabled_; |
208 } | 262 } |
209 | 263 |
210 Configurator* MakeChromeComponentUpdaterConfigurator( | 264 Configurator* MakeChromeComponentUpdaterConfigurator( |
211 const base::CommandLine* cmdline, | 265 const base::CommandLine* cmdline, |
212 net::URLRequestContextGetter* context_getter) { | 266 net::URLRequestContextGetter* context_getter) { |
213 return new ChromeConfigurator(cmdline, context_getter); | 267 return new ChromeConfigurator(cmdline, context_getter); |
214 } | 268 } |
215 | 269 |
216 } // namespace component_updater | 270 } // namespace component_updater |
OLD | NEW |