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

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

Issue 1281913002: Componentize ComponentUpdaterConfigurator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix iOS compile Created 5 years, 4 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
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>
8 #include <string> 7 #include <string>
9 #include <vector>
10 8
11 #include "base/command_line.h" 9 #include "base/threading/sequenced_worker_pool.h"
12 #include "base/compiler_specific.h"
13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h"
15 #include "base/version.h"
16 #include "build/build_config.h"
17 #include "chrome/browser/component_updater/component_patcher_operation_out_of_pr ocess.h" 10 #include "chrome/browser/component_updater/component_patcher_operation_out_of_pr ocess.h"
18 #include "chrome/browser/component_updater/component_updater_url_constants.h"
19 #include "chrome/browser/update_client/chrome_update_query_params_delegate.h" 11 #include "chrome/browser/update_client/chrome_update_query_params_delegate.h"
20 #include "components/component_updater/component_updater_switches.h" 12 #include "components/component_updater/configurator_impl.h"
21 #include "components/update_client/configurator.h"
22 #include "components/version_info/version_info.h"
23 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
24 #include "net/url_request/url_request_context_getter.h"
25 #include "url/gurl.h"
26
27 #if defined(OS_WIN)
28 #include "base/win/win_util.h"
29 #endif // OS_WIN
30
31 using update_client::Configurator;
32 using update_client::OutOfProcessPatcher;
33 14
34 namespace component_updater { 15 namespace component_updater {
35 16
36 namespace { 17 namespace {
37 18
38 // Default time constants. 19 class ChromeConfigurator : public update_client::Configurator {
39 const int kDelayOneMinute = 60;
40 const int kDelayOneHour = kDelayOneMinute * 60;
41
42 // Debug values you can pass to --component-updater=value1,value2.
43 // Speed up component checking.
44 const char kSwitchFastUpdate[] = "fast-update";
45
46 // Add "testrequest=1" attribute to the update check request.
47 const char kSwitchRequestParam[] = "test-request";
48
49 // Disables pings. Pings are the requests sent to the update server that report
50 // the success or the failure of component install or update attempts.
51 extern const char kSwitchDisablePings[] = "disable-pings";
52
53 // Sets the URL for updates.
54 const char kSwitchUrlSource[] = "url-source";
55
56 // Disables differential updates.
57 const char kSwitchDisableDeltaUpdates[] = "disable-delta-updates";
58
59 #if defined(OS_WIN)
60 // Disables background downloads.
61 const char kSwitchDisableBackgroundDownloads[] = "disable-background-downloads";
62 #endif // defined(OS_WIN)
63
64 // Returns true if and only if |test| is contained in |vec|.
65 bool HasSwitchValue(const std::vector<std::string>& vec, const char* test) {
66 if (vec.empty())
67 return 0;
68 return (std::find(vec.begin(), vec.end(), test) != vec.end());
69 }
70
71 // Returns true if falling back on an alternate, unsafe, service URL is
72 // allowed. In the fallback case, the security of the component update relies
73 // only on the integrity of the CRX payloads, which is self-validating.
74 // This is allowed only for some of the pre-Windows Vista versions not including
75 // Windows XP SP3. As a side note, pings could be sent to the alternate URL too.
76 bool CanUseAltUrlSource() {
77 #if defined(OS_WIN)
78 return !base::win::MaybeHasSHA256Support();
79 #else
80 return false;
81 #endif // OS_WIN
82 }
83
84 // If there is an element of |vec| of the form |test|=.*, returns the right-
85 // hand side of that assignment. Otherwise, returns an empty string.
86 // The right-hand side may contain additional '=' characters, allowing for
87 // further nesting of switch arguments.
88 std::string GetSwitchArgument(const std::vector<std::string>& vec,
89 const char* test) {
90 if (vec.empty())
91 return std::string();
92 for (std::vector<std::string>::const_iterator it = vec.begin();
93 it != vec.end();
94 ++it) {
95 const std::size_t found = it->find("=");
96 if (found != std::string::npos) {
97 if (it->substr(0, found) == test) {
98 return it->substr(found + 1);
99 }
100 }
101 }
102 return std::string();
103 }
104
105 class ChromeConfigurator : public Configurator {
106 public: 20 public:
107 ChromeConfigurator(const base::CommandLine* cmdline, 21 ChromeConfigurator(const base::CommandLine* cmdline,
108 net::URLRequestContextGetter* url_request_getter); 22 net::URLRequestContextGetter* url_request_getter);
109 23
24 // update_client::Configurator:
Sorin Jianu 2015/08/12 02:27:51 I think this comment should be // update_client::C
droger 2015/08/12 08:43:41 Done.
110 int InitialDelay() const override; 25 int InitialDelay() const override;
111 int NextCheckDelay() const override; 26 int NextCheckDelay() const override;
112 int StepDelay() const override; 27 int StepDelay() const override;
113 int OnDemandDelay() const override; 28 int OnDemandDelay() const override;
114 int UpdateDelay() const override; 29 int UpdateDelay() const override;
115 std::vector<GURL> UpdateUrl() const override; 30 std::vector<GURL> UpdateUrl() const override;
116 std::vector<GURL> PingUrl() const override; 31 std::vector<GURL> PingUrl() const override;
117 base::Version GetBrowserVersion() const override; 32 base::Version GetBrowserVersion() const override;
118 std::string GetChannel() const override; 33 std::string GetChannel() const override;
119 std::string GetLang() const override; 34 std::string GetLang() const override;
120 std::string GetOSLongName() const override; 35 std::string GetOSLongName() const override;
121 std::string ExtraRequestParams() const override; 36 std::string ExtraRequestParams() const override;
122 net::URLRequestContextGetter* RequestContext() const override; 37 net::URLRequestContextGetter* RequestContext() const override;
123 scoped_refptr<OutOfProcessPatcher> CreateOutOfProcessPatcher() const override; 38 scoped_refptr<update_client::OutOfProcessPatcher> CreateOutOfProcessPatcher()
39 const override;
124 bool DeltasEnabled() const override; 40 bool DeltasEnabled() const override;
125 bool UseBackgroundDownloader() const override; 41 bool UseBackgroundDownloader() const override;
126 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() 42 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner()
127 const override; 43 const override;
128 scoped_refptr<base::SingleThreadTaskRunner> GetSingleThreadTaskRunner() 44 scoped_refptr<base::SingleThreadTaskRunner> GetSingleThreadTaskRunner()
129 const override; 45 const override;
130 46
131 private: 47 private:
132 friend class base::RefCountedThreadSafe<ChromeConfigurator>; 48 friend class base::RefCountedThreadSafe<ChromeConfigurator>;
133 49
50 ConfiguratorImpl configurator_impl_;
51
134 ~ChromeConfigurator() override {} 52 ~ChromeConfigurator() override {}
135
136 net::URLRequestContextGetter* url_request_getter_;
137 std::string extra_info_;
138 GURL url_source_override_;
139 bool fast_update_;
140 bool pings_enabled_;
141 bool deltas_enabled_;
142 bool background_downloads_enabled_;
143 bool fallback_to_alt_source_url_enabled_;
144 }; 53 };
145 54
146 ChromeConfigurator::ChromeConfigurator( 55 ChromeConfigurator::ChromeConfigurator(
147 const base::CommandLine* cmdline, 56 const base::CommandLine* cmdline,
148 net::URLRequestContextGetter* url_request_getter) 57 net::URLRequestContextGetter* url_request_getter)
149 : url_request_getter_(url_request_getter), 58 : configurator_impl_(cmdline, url_request_getter) {}
150 fast_update_(false),
151 pings_enabled_(false),
152 deltas_enabled_(false),
153 background_downloads_enabled_(false),
154 fallback_to_alt_source_url_enabled_(false) {
155 // Parse comma-delimited debug flags.
156 std::vector<std::string> switch_values = base::SplitString(
157 cmdline->GetSwitchValueASCII(switches::kComponentUpdater),
158 ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
159 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate);
160 pings_enabled_ = !HasSwitchValue(switch_values, kSwitchDisablePings);
161 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates);
162
163 #if defined(OS_WIN)
164 background_downloads_enabled_ =
165 !HasSwitchValue(switch_values, kSwitchDisableBackgroundDownloads);
166 #else
167 background_downloads_enabled_ = false;
168 #endif
169
170 const std::string switch_url_source =
171 GetSwitchArgument(switch_values, kSwitchUrlSource);
172 if (!switch_url_source.empty()) {
173 url_source_override_ = GURL(switch_url_source);
174 DCHECK(url_source_override_.is_valid());
175 }
176
177 if (HasSwitchValue(switch_values, kSwitchRequestParam))
178 extra_info_ += "testrequest=\"1\"";
179
180 fallback_to_alt_source_url_enabled_ = CanUseAltUrlSource();
181 }
182 59
183 int ChromeConfigurator::InitialDelay() const { 60 int ChromeConfigurator::InitialDelay() const {
184 return fast_update_ ? 10 : (6 * kDelayOneMinute); 61 return configurator_impl_.InitialDelay();
185 } 62 }
186 63
187 int ChromeConfigurator::NextCheckDelay() const { 64 int ChromeConfigurator::NextCheckDelay() const {
188 return fast_update_ ? 60 : (6 * kDelayOneHour); 65 return configurator_impl_.NextCheckDelay();
189 } 66 }
190 67
191 int ChromeConfigurator::StepDelay() const { 68 int ChromeConfigurator::StepDelay() const {
192 return fast_update_ ? 1 : 1; 69 return configurator_impl_.StepDelay();
193 } 70 }
194 71
195 int ChromeConfigurator::OnDemandDelay() const { 72 int ChromeConfigurator::OnDemandDelay() const {
196 return fast_update_ ? 2 : (30 * kDelayOneMinute); 73 return configurator_impl_.OnDemandDelay();
197 } 74 }
198 75
199 int ChromeConfigurator::UpdateDelay() const { 76 int ChromeConfigurator::UpdateDelay() const {
200 return fast_update_ ? 10 : (15 * kDelayOneMinute); 77 return configurator_impl_.UpdateDelay();
201 } 78 }
202 79
203 std::vector<GURL> ChromeConfigurator::UpdateUrl() const { 80 std::vector<GURL> ChromeConfigurator::UpdateUrl() const {
204 std::vector<GURL> urls; 81 return configurator_impl_.UpdateUrl();
205 if (url_source_override_.is_valid()) {
206 urls.push_back(GURL(url_source_override_));
207 } else {
208 urls.push_back(GURL(kUpdaterDefaultUrl));
209 if (fallback_to_alt_source_url_enabled_) {
210 urls.push_back(GURL(kUpdaterAltUrl));
211 }
212 }
213 return urls;
214 } 82 }
215 83
216 std::vector<GURL> ChromeConfigurator::PingUrl() const { 84 std::vector<GURL> ChromeConfigurator::PingUrl() const {
217 return pings_enabled_ ? UpdateUrl() : std::vector<GURL>(); 85 return configurator_impl_.PingUrl();
218 } 86 }
219 87
220 base::Version ChromeConfigurator::GetBrowserVersion() const { 88 base::Version ChromeConfigurator::GetBrowserVersion() const {
221 return base::Version(version_info::GetVersionNumber()); 89 return configurator_impl_.GetBrowserVersion();
222 } 90 }
223 91
224 std::string ChromeConfigurator::GetChannel() const { 92 std::string ChromeConfigurator::GetChannel() const {
225 return ChromeUpdateQueryParamsDelegate::GetChannelString(); 93 return ChromeUpdateQueryParamsDelegate::GetChannelString();
226 } 94 }
227 95
228 std::string ChromeConfigurator::GetLang() const { 96 std::string ChromeConfigurator::GetLang() const {
229 return ChromeUpdateQueryParamsDelegate::GetLang(); 97 return ChromeUpdateQueryParamsDelegate::GetLang();
230 } 98 }
231 99
232 std::string ChromeConfigurator::GetOSLongName() const { 100 std::string ChromeConfigurator::GetOSLongName() const {
233 return version_info::GetOSType(); 101 return configurator_impl_.GetOSLongName();
234 } 102 }
235 103
236 std::string ChromeConfigurator::ExtraRequestParams() const { 104 std::string ChromeConfigurator::ExtraRequestParams() const {
237 return extra_info_; 105 return configurator_impl_.ExtraRequestParams();
238 } 106 }
239 107
240 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() const { 108 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() const {
241 return url_request_getter_; 109 return configurator_impl_.RequestContext();
242 } 110 }
243 111
244 scoped_refptr<OutOfProcessPatcher> 112 scoped_refptr<update_client::OutOfProcessPatcher>
245 ChromeConfigurator::CreateOutOfProcessPatcher() const { 113 ChromeConfigurator::CreateOutOfProcessPatcher() const {
246 return make_scoped_refptr(new ChromeOutOfProcessPatcher); 114 return make_scoped_refptr(new ChromeOutOfProcessPatcher);
247 } 115 }
248 116
249 bool ChromeConfigurator::DeltasEnabled() const { 117 bool ChromeConfigurator::DeltasEnabled() const {
250 return deltas_enabled_; 118 return configurator_impl_.DeltasEnabled();
251 } 119 }
252 120
253 bool ChromeConfigurator::UseBackgroundDownloader() const { 121 bool ChromeConfigurator::UseBackgroundDownloader() const {
254 return background_downloads_enabled_; 122 return configurator_impl_.UseBackgroundDownloader();
255 } 123 }
256 124
257 scoped_refptr<base::SequencedTaskRunner> 125 scoped_refptr<base::SequencedTaskRunner>
258 ChromeConfigurator::GetSequencedTaskRunner() const { 126 ChromeConfigurator::GetSequencedTaskRunner() const {
259 return content::BrowserThread::GetBlockingPool() 127 return content::BrowserThread::GetBlockingPool()
260 ->GetSequencedTaskRunnerWithShutdownBehavior( 128 ->GetSequencedTaskRunnerWithShutdownBehavior(
261 content::BrowserThread::GetBlockingPool()->GetSequenceToken(), 129 content::BrowserThread::GetBlockingPool()->GetSequenceToken(),
262 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 130 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
263 } 131 }
264 132
265 scoped_refptr<base::SingleThreadTaskRunner> 133 scoped_refptr<base::SingleThreadTaskRunner>
266 ChromeConfigurator::GetSingleThreadTaskRunner() const { 134 ChromeConfigurator::GetSingleThreadTaskRunner() const {
267 return content::BrowserThread::GetMessageLoopProxyForThread( 135 return content::BrowserThread::GetMessageLoopProxyForThread(
268 content::BrowserThread::FILE); 136 content::BrowserThread::FILE);
269 } 137 }
270 138
271 } // namespace 139 } // namespace
272 140
273 scoped_refptr<update_client::Configurator> 141 scoped_refptr<update_client::Configurator>
274 MakeChromeComponentUpdaterConfigurator( 142 MakeChromeComponentUpdaterConfigurator(
275 const base::CommandLine* cmdline, 143 const base::CommandLine* cmdline,
276 net::URLRequestContextGetter* context_getter) { 144 net::URLRequestContextGetter* context_getter) {
277 return new ChromeConfigurator(cmdline, context_getter); 145 return new ChromeConfigurator(cmdline, context_getter);
278 } 146 }
279 147
280 } // namespace component_updater 148 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698