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/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 #include "chrome/browser/component_updater/component_patcher.h" | 16 #include "chrome/browser/component_updater/component_patcher.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/omaha_query_params/omaha_query_params.h" | |
19 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
20 | 19 |
21 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
22 #include "chrome/browser/component_updater/component_patcher_win.h" | 21 #include "chrome/browser/component_updater/component_patcher_win.h" |
23 #endif | 22 #endif |
24 | 23 |
25 namespace { | 24 namespace { |
26 | 25 |
27 // Default time constants. | 26 // Default time constants. |
28 const int kDelayOneMinute = 60; | 27 const int kDelayOneMinute = 60; |
29 const int kDelayOneHour = kDelayOneMinute * 60; | 28 const int kDelayOneHour = kDelayOneMinute * 60; |
30 | 29 |
31 // Debug values you can pass to --component-updater=value1,value2. | 30 // Debug values you can pass to --component-updater=value1,value2. |
32 // Speed up component checking. | 31 // Speed up component checking. |
33 const char kSwitchFastUpdate[] = "fast-update"; | 32 const char kSwitchFastUpdate[] = "fast-update"; |
34 // Add "testrequest=1" parameter to the update check query. | 33 |
| 34 // Add "testrequest=1" attribute to the update check request. |
35 const char kSwitchRequestParam[] = "test-request"; | 35 const char kSwitchRequestParam[] = "test-request"; |
| 36 |
36 // Disables pings. Pings are the requests sent to the update server that report | 37 // Disables pings. Pings are the requests sent to the update server that report |
37 // the success or the failure of component install or update attempts. | 38 // the success or the failure of component install or update attempts. |
38 extern const char kSwitchDisablePings[] = "disable-pings"; | 39 extern const char kSwitchDisablePings[] = "disable-pings"; |
39 | 40 |
40 // Sets the URL for updates. | 41 // Sets the URL for updates. |
41 const char kSwitchUrlSource[] = "url-source"; | 42 const char kSwitchUrlSource[] = "url-source"; |
42 | 43 |
43 #define COMPONENT_UPDATER_SERVICE_ENDPOINT \ | 44 #define COMPONENT_UPDATER_SERVICE_ENDPOINT \ |
44 "//clients2.google.com/service/update2" | 45 "//clients2.google.com/service/update2" |
45 | 46 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 virtual ~ChromeConfigurator() {} | 96 virtual ~ChromeConfigurator() {} |
96 | 97 |
97 virtual int InitialDelay() OVERRIDE; | 98 virtual int InitialDelay() OVERRIDE; |
98 virtual int NextCheckDelay() OVERRIDE; | 99 virtual int NextCheckDelay() OVERRIDE; |
99 virtual int StepDelay() OVERRIDE; | 100 virtual int StepDelay() OVERRIDE; |
100 virtual int StepDelayMedium() OVERRIDE; | 101 virtual int StepDelayMedium() OVERRIDE; |
101 virtual int MinimumReCheckWait() OVERRIDE; | 102 virtual int MinimumReCheckWait() OVERRIDE; |
102 virtual int OnDemandDelay() OVERRIDE; | 103 virtual int OnDemandDelay() OVERRIDE; |
103 virtual GURL UpdateUrl() OVERRIDE; | 104 virtual GURL UpdateUrl() OVERRIDE; |
104 virtual GURL PingUrl() OVERRIDE; | 105 virtual GURL PingUrl() OVERRIDE; |
105 virtual const char* ExtraRequestParams() OVERRIDE; | 106 virtual std::string ExtraRequestParams() OVERRIDE; |
106 virtual size_t UrlSizeLimit() OVERRIDE; | 107 virtual size_t UrlSizeLimit() OVERRIDE; |
107 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; | 108 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; |
108 virtual bool InProcess() OVERRIDE; | 109 virtual bool InProcess() OVERRIDE; |
109 virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE; | 110 virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE; |
110 virtual bool DeltasEnabled() const OVERRIDE; | 111 virtual bool DeltasEnabled() const OVERRIDE; |
111 virtual bool UseBackgroundDownloader() const OVERRIDE; | 112 virtual bool UseBackgroundDownloader() const OVERRIDE; |
112 | 113 |
113 private: | 114 private: |
114 net::URLRequestContextGetter* url_request_getter_; | 115 net::URLRequestContextGetter* url_request_getter_; |
115 std::string extra_info_; | 116 std::string extra_info_; |
116 std::string url_source_; | 117 std::string url_source_; |
117 bool fast_update_; | 118 bool fast_update_; |
118 bool pings_enabled_; | 119 bool pings_enabled_; |
119 bool deltas_enabled_; | 120 bool deltas_enabled_; |
120 bool background_downloads_enabled_; | 121 bool background_downloads_enabled_; |
121 }; | 122 }; |
122 | 123 |
123 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, | 124 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, |
124 net::URLRequestContextGetter* url_request_getter) | 125 net::URLRequestContextGetter* url_request_getter) |
125 : url_request_getter_(url_request_getter), | 126 : url_request_getter_(url_request_getter), |
126 extra_info_(chrome::OmahaQueryParams::Get( | |
127 chrome::OmahaQueryParams::CHROME)), | |
128 fast_update_(false), | 127 fast_update_(false), |
129 pings_enabled_(false), | 128 pings_enabled_(false), |
130 deltas_enabled_(false), | 129 deltas_enabled_(false), |
131 background_downloads_enabled_(false) { | 130 background_downloads_enabled_(false) { |
132 // Parse comma-delimited debug flags. | 131 // Parse comma-delimited debug flags. |
133 std::vector<std::string> switch_values; | 132 std::vector<std::string> switch_values; |
134 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdater), | 133 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdater), |
135 ",", &switch_values); | 134 ",", &switch_values); |
136 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate); | 135 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate); |
137 pings_enabled_ = !HasSwitchValue(switch_values, kSwitchDisablePings); | 136 pings_enabled_ = !HasSwitchValue(switch_values, kSwitchDisablePings); |
138 #if defined(OS_WIN) | 137 #if defined(OS_WIN) |
139 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates); | 138 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates); |
140 background_downloads_enabled_ = | 139 background_downloads_enabled_ = |
141 !HasSwitchValue(switch_values, kSwitchDisableBackgroundDownloads); | 140 !HasSwitchValue(switch_values, kSwitchDisableBackgroundDownloads); |
142 #else | 141 #else |
143 deltas_enabled_ = false; | 142 deltas_enabled_ = false; |
144 background_downloads_enabled_ = false; | 143 background_downloads_enabled_ = false; |
145 #endif | 144 #endif |
146 | 145 |
147 url_source_ = GetSwitchArgument(switch_values, kSwitchUrlSource); | 146 url_source_ = GetSwitchArgument(switch_values, kSwitchUrlSource); |
148 if (url_source_.empty()) { | 147 if (url_source_.empty()) { |
149 url_source_ = kDefaultUrlSource; | 148 url_source_ = kDefaultUrlSource; |
150 } | 149 } |
151 | 150 |
152 // Make the extra request params, they are necessary so omaha does | |
153 // not deliver components that are going to be rejected at install time. | |
154 #if defined(OS_WIN) | |
155 if (base::win::OSInfo::GetInstance()->wow64_status() == | |
156 base::win::OSInfo::WOW64_ENABLED) | |
157 extra_info_ += "&wow64=1"; | |
158 #endif | |
159 if (HasSwitchValue(switch_values, kSwitchRequestParam)) | 151 if (HasSwitchValue(switch_values, kSwitchRequestParam)) |
160 extra_info_ += "&testrequest=1"; | 152 extra_info_ += "testrequest=\"1\""; |
161 } | 153 } |
162 | 154 |
163 int ChromeConfigurator::InitialDelay() { | 155 int ChromeConfigurator::InitialDelay() { |
164 return fast_update_ ? 1 : (6 * kDelayOneMinute); | 156 return fast_update_ ? 1 : (6 * kDelayOneMinute); |
165 } | 157 } |
166 | 158 |
167 int ChromeConfigurator::NextCheckDelay() { | 159 int ChromeConfigurator::NextCheckDelay() { |
168 return fast_update_ ? 3 : (2 * kDelayOneHour); | 160 return fast_update_ ? 3 : (2 * kDelayOneHour); |
169 } | 161 } |
170 | 162 |
(...skipping 14 matching lines...) Expand all Loading... |
185 } | 177 } |
186 | 178 |
187 GURL ChromeConfigurator::UpdateUrl() { | 179 GURL ChromeConfigurator::UpdateUrl() { |
188 return GURL(url_source_); | 180 return GURL(url_source_); |
189 } | 181 } |
190 | 182 |
191 GURL ChromeConfigurator::PingUrl() { | 183 GURL ChromeConfigurator::PingUrl() { |
192 return pings_enabled_ ? GURL(kPingUrl) : GURL(); | 184 return pings_enabled_ ? GURL(kPingUrl) : GURL(); |
193 } | 185 } |
194 | 186 |
195 const char* ChromeConfigurator::ExtraRequestParams() { | 187 std::string ChromeConfigurator::ExtraRequestParams() { |
196 return extra_info_.c_str(); | 188 return extra_info_; |
197 } | 189 } |
198 | 190 |
199 size_t ChromeConfigurator::UrlSizeLimit() { | 191 size_t ChromeConfigurator::UrlSizeLimit() { |
200 return 1024ul; | 192 return 1024ul; |
201 } | 193 } |
202 | 194 |
203 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() { | 195 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() { |
204 return url_request_getter_; | 196 return url_request_getter_; |
205 } | 197 } |
206 | 198 |
(...skipping 14 matching lines...) Expand all Loading... |
221 } | 213 } |
222 | 214 |
223 bool ChromeConfigurator::UseBackgroundDownloader() const { | 215 bool ChromeConfigurator::UseBackgroundDownloader() const { |
224 return background_downloads_enabled_; | 216 return background_downloads_enabled_; |
225 } | 217 } |
226 | 218 |
227 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( | 219 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( |
228 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { | 220 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { |
229 return new ChromeConfigurator(cmdline, context_getter); | 221 return new ChromeConfigurator(cmdline, context_getter); |
230 } | 222 } |
OLD | NEW |