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 "components/component_updater/component_updater_service.h" | 5 #include "components/component_updater/component_updater_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
18 #include "base/logging.h" | 18 #include "base/logging.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 21 #include "base/metrics/histogram_macros.h" |
21 #include "base/sequenced_task_runner.h" | 22 #include "base/sequenced_task_runner.h" |
22 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
23 #include "base/thread_task_runner_handle.h" | 24 #include "base/thread_task_runner_handle.h" |
24 #include "base/threading/sequenced_worker_pool.h" | 25 #include "base/threading/sequenced_worker_pool.h" |
25 #include "base/threading/thread_checker.h" | 26 #include "base/threading/thread_checker.h" |
| 27 #include "base/time/time.h" |
26 #include "base/timer/timer.h" | 28 #include "base/timer/timer.h" |
27 #include "components/component_updater/component_updater_service_internal.h" | 29 #include "components/component_updater/component_updater_service_internal.h" |
28 #include "components/component_updater/timer.h" | 30 #include "components/component_updater/timer.h" |
29 #include "components/update_client/configurator.h" | 31 #include "components/update_client/configurator.h" |
30 #include "components/update_client/crx_update_item.h" | 32 #include "components/update_client/crx_update_item.h" |
31 #include "components/update_client/update_client.h" | 33 #include "components/update_client/update_client.h" |
32 #include "components/update_client/utils.h" | 34 #include "components/update_client/utils.h" |
33 #include "url/gurl.h" | 35 #include "url/gurl.h" |
34 | 36 |
35 using CrxInstaller = update_client::CrxInstaller; | 37 using CrxInstaller = update_client::CrxInstaller; |
36 using UpdateClient = update_client::UpdateClient; | 38 using UpdateClient = update_client::UpdateClient; |
37 | 39 |
| 40 namespace { |
| 41 |
| 42 enum UpdateType { |
| 43 UPDATE_TYPE_MANUAL = 0, |
| 44 UPDATE_TYPE_AUTOMATIC, |
| 45 UPDATE_TYPE_COUNT, |
| 46 }; |
| 47 |
| 48 } // namespace |
| 49 |
38 namespace component_updater { | 50 namespace component_updater { |
39 | 51 |
40 CrxUpdateService::CrxUpdateService( | 52 CrxUpdateService::CrxUpdateService( |
41 const scoped_refptr<Configurator>& config, | 53 const scoped_refptr<Configurator>& config, |
42 const scoped_refptr<UpdateClient>& update_client) | 54 const scoped_refptr<UpdateClient>& update_client) |
43 : config_(config), | 55 : config_(config), |
44 update_client_(update_client), | 56 update_client_(update_client), |
45 blocking_task_runner_(config->GetSequencedTaskRunner()) { | 57 blocking_task_runner_(config->GetSequencedTaskRunner()) { |
46 AddObserver(this); | 58 AddObserver(this); |
47 } | 59 } |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) | 240 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) |
229 return false; | 241 return false; |
230 } | 242 } |
231 | 243 |
232 return OnDemandUpdateInternal(id); | 244 return OnDemandUpdateInternal(id); |
233 } | 245 } |
234 | 246 |
235 bool CrxUpdateService::OnDemandUpdateInternal(const std::string& id) { | 247 bool CrxUpdateService::OnDemandUpdateInternal(const std::string& id) { |
236 DCHECK(thread_checker_.CalledOnValidThread()); | 248 DCHECK(thread_checker_.CalledOnValidThread()); |
237 | 249 |
| 250 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.Calls", UPDATE_TYPE_MANUAL, |
| 251 UPDATE_TYPE_COUNT); |
| 252 |
238 update_client_->Install( | 253 update_client_->Install( |
239 id, base::Bind(&CrxUpdateService::OnUpdate, base::Unretained(this)), | 254 id, base::Bind(&CrxUpdateService::OnUpdate, base::Unretained(this)), |
240 base::Bind(&CrxUpdateService::OnUpdateComplete, base::Unretained(this))); | 255 base::Bind(&CrxUpdateService::OnUpdateComplete, base::Unretained(this), |
| 256 base::TimeTicks::Now())); |
241 | 257 |
242 return true; | 258 return true; |
243 } | 259 } |
244 | 260 |
245 bool CrxUpdateService::CheckForUpdates() { | 261 bool CrxUpdateService::CheckForUpdates() { |
246 DCHECK(thread_checker_.CalledOnValidThread()); | 262 DCHECK(thread_checker_.CalledOnValidThread()); |
| 263 |
| 264 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.Calls", UPDATE_TYPE_AUTOMATIC, |
| 265 UPDATE_TYPE_COUNT); |
| 266 |
247 std::vector<std::string> ids; | 267 std::vector<std::string> ids; |
248 for (const auto id : components_order_) { | 268 for (const auto id : components_order_) { |
249 DCHECK(components_.find(id) != components_.end()); | 269 DCHECK(components_.find(id) != components_.end()); |
250 ids.push_back(id); | 270 ids.push_back(id); |
251 } | 271 } |
252 | 272 |
253 update_client_->Update( | 273 update_client_->Update( |
254 ids, base::Bind(&CrxUpdateService::OnUpdate, base::Unretained(this)), | 274 ids, base::Bind(&CrxUpdateService::OnUpdate, base::Unretained(this)), |
255 base::Bind(&CrxUpdateService::OnUpdateComplete, base::Unretained(this))); | 275 base::Bind(&CrxUpdateService::OnUpdateComplete, base::Unretained(this), |
| 276 base::TimeTicks::Now())); |
256 | 277 |
257 return true; | 278 return true; |
258 } | 279 } |
259 | 280 |
260 scoped_refptr<base::SequencedTaskRunner> | 281 scoped_refptr<base::SequencedTaskRunner> |
261 CrxUpdateService::GetSequencedTaskRunner() { | 282 CrxUpdateService::GetSequencedTaskRunner() { |
262 DCHECK(thread_checker_.CalledOnValidThread()); | 283 DCHECK(thread_checker_.CalledOnValidThread()); |
263 return blocking_task_runner_; | 284 return blocking_task_runner_; |
264 } | 285 } |
265 | 286 |
(...skipping 23 matching lines...) Expand all Loading... |
289 DCHECK(components->empty()); | 310 DCHECK(components->empty()); |
290 | 311 |
291 for (const auto& id : ids) { | 312 for (const auto& id : ids) { |
292 const auto registered_component(GetComponent(id)); | 313 const auto registered_component(GetComponent(id)); |
293 if (registered_component) { | 314 if (registered_component) { |
294 components->push_back(*registered_component); | 315 components->push_back(*registered_component); |
295 } | 316 } |
296 } | 317 } |
297 } | 318 } |
298 | 319 |
299 void CrxUpdateService::OnUpdateComplete(int error) { | 320 void CrxUpdateService::OnUpdateComplete(const base::TimeTicks& start_time, |
| 321 int error) { |
300 DCHECK(thread_checker_.CalledOnValidThread()); | 322 DCHECK(thread_checker_.CalledOnValidThread()); |
301 VLOG(1) << "Update completed with error " << error; | 323 VLOG(1) << "Update completed with error " << error; |
302 | 324 |
| 325 UMA_HISTOGRAM_BOOLEAN("ComponentUpdater.UpdateCompleteResult", error != 0); |
| 326 UMA_HISTOGRAM_LONG_TIMES_100("ComponentUpdater.UpdateCompleteTime", |
| 327 base::TimeTicks::Now() - start_time); |
| 328 |
303 for (const auto id : components_pending_unregistration_) { | 329 for (const auto id : components_pending_unregistration_) { |
304 if (!update_client_->IsUpdating(id)) { | 330 if (!update_client_->IsUpdating(id)) { |
305 const auto component = GetComponent(id); | 331 const auto component = GetComponent(id); |
306 if (component) | 332 if (component) |
307 DoUnregisterComponent(*component); | 333 DoUnregisterComponent(*component); |
308 } | 334 } |
309 } | 335 } |
310 } | 336 } |
311 | 337 |
312 void CrxUpdateService::OnEvent(Events event, const std::string& id) { | 338 void CrxUpdateService::OnEvent(Events event, const std::string& id) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 // TODO(sorin): consider making this a singleton. | 374 // TODO(sorin): consider making this a singleton. |
349 scoped_ptr<ComponentUpdateService> ComponentUpdateServiceFactory( | 375 scoped_ptr<ComponentUpdateService> ComponentUpdateServiceFactory( |
350 const scoped_refptr<Configurator>& config) { | 376 const scoped_refptr<Configurator>& config) { |
351 DCHECK(config); | 377 DCHECK(config); |
352 auto update_client = update_client::UpdateClientFactory(config); | 378 auto update_client = update_client::UpdateClientFactory(config); |
353 return scoped_ptr<ComponentUpdateService>( | 379 return scoped_ptr<ComponentUpdateService>( |
354 new CrxUpdateService(config, std::move(update_client))); | 380 new CrxUpdateService(config, std::move(update_client))); |
355 } | 381 } |
356 | 382 |
357 } // namespace component_updater | 383 } // namespace component_updater |
OLD | NEW |