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; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) | 230 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) |
229 return false; | 231 return false; |
230 } | 232 } |
231 | 233 |
232 return OnDemandUpdateInternal(id); | 234 return OnDemandUpdateInternal(id); |
233 } | 235 } |
234 | 236 |
235 bool CrxUpdateService::OnDemandUpdateInternal(const std::string& id) { | 237 bool CrxUpdateService::OnDemandUpdateInternal(const std::string& id) { |
236 DCHECK(thread_checker_.CalledOnValidThread()); | 238 DCHECK(thread_checker_.CalledOnValidThread()); |
237 | 239 |
240 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.Calls.Count", 0, 2); | |
241 | |
238 update_client_->Install( | 242 update_client_->Install( |
239 id, base::Bind(&CrxUpdateService::OnUpdate, base::Unretained(this)), | 243 id, base::Bind(&CrxUpdateService::OnUpdate, base::Unretained(this)), |
240 base::Bind(&CrxUpdateService::OnUpdateComplete, base::Unretained(this))); | 244 base::Bind(&CrxUpdateService::OnUpdateComplete, base::Unretained(this), |
245 base::TimeTicks::Now())); | |
241 | 246 |
242 return true; | 247 return true; |
243 } | 248 } |
244 | 249 |
245 bool CrxUpdateService::CheckForUpdates() { | 250 bool CrxUpdateService::CheckForUpdates() { |
246 DCHECK(thread_checker_.CalledOnValidThread()); | 251 DCHECK(thread_checker_.CalledOnValidThread()); |
252 | |
253 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.Calls.Count", 1, 2); | |
Ilya Sherman
2016/03/09 20:13:50
nit: I'd recommend defining a C++ enum, and emitti
Ilya Sherman
2016/03/09 20:13:50
nit: I'd recommend having a wrapper function aroun
Sorin Jianu
2016/03/09 22:26:21
Done.
Sorin Jianu
2016/03/09 22:26:21
Acknowledged.
| |
254 | |
247 std::vector<std::string> ids; | 255 std::vector<std::string> ids; |
248 for (const auto id : components_order_) { | 256 for (const auto id : components_order_) { |
249 DCHECK(components_.find(id) != components_.end()); | 257 DCHECK(components_.find(id) != components_.end()); |
250 ids.push_back(id); | 258 ids.push_back(id); |
251 } | 259 } |
252 | 260 |
253 update_client_->Update( | 261 update_client_->Update( |
254 ids, base::Bind(&CrxUpdateService::OnUpdate, base::Unretained(this)), | 262 ids, base::Bind(&CrxUpdateService::OnUpdate, base::Unretained(this)), |
255 base::Bind(&CrxUpdateService::OnUpdateComplete, base::Unretained(this))); | 263 base::Bind(&CrxUpdateService::OnUpdateComplete, base::Unretained(this), |
264 base::TimeTicks::Now())); | |
256 | 265 |
257 return true; | 266 return true; |
258 } | 267 } |
259 | 268 |
260 scoped_refptr<base::SequencedTaskRunner> | 269 scoped_refptr<base::SequencedTaskRunner> |
261 CrxUpdateService::GetSequencedTaskRunner() { | 270 CrxUpdateService::GetSequencedTaskRunner() { |
262 DCHECK(thread_checker_.CalledOnValidThread()); | 271 DCHECK(thread_checker_.CalledOnValidThread()); |
263 return blocking_task_runner_; | 272 return blocking_task_runner_; |
264 } | 273 } |
265 | 274 |
(...skipping 23 matching lines...) Expand all Loading... | |
289 DCHECK(components->empty()); | 298 DCHECK(components->empty()); |
290 | 299 |
291 for (const auto& id : ids) { | 300 for (const auto& id : ids) { |
292 const auto registered_component(GetComponent(id)); | 301 const auto registered_component(GetComponent(id)); |
293 if (registered_component) { | 302 if (registered_component) { |
294 components->push_back(*registered_component); | 303 components->push_back(*registered_component); |
295 } | 304 } |
296 } | 305 } |
297 } | 306 } |
298 | 307 |
299 void CrxUpdateService::OnUpdateComplete(int error) { | 308 void CrxUpdateService::OnUpdateComplete(const base::TimeTicks& start_time, |
309 int error) { | |
300 DCHECK(thread_checker_.CalledOnValidThread()); | 310 DCHECK(thread_checker_.CalledOnValidThread()); |
301 VLOG(1) << "Update completed with error " << error; | 311 VLOG(1) << "Update completed with error " << error; |
302 | 312 |
313 UMA_HISTOGRAM_BOOLEAN("ComponentUpdater.UpdateCompleteResult", error != 0); | |
314 UMA_HISTOGRAM_TIMES("ComponentUpdater.UpdateCompleteTime", | |
315 base::TimeTicks::Now() - start_time); | |
316 | |
303 for (const auto id : components_pending_unregistration_) { | 317 for (const auto id : components_pending_unregistration_) { |
304 if (!update_client_->IsUpdating(id)) { | 318 if (!update_client_->IsUpdating(id)) { |
305 const auto component = GetComponent(id); | 319 const auto component = GetComponent(id); |
306 if (component) | 320 if (component) |
307 DoUnregisterComponent(*component); | 321 DoUnregisterComponent(*component); |
308 } | 322 } |
309 } | 323 } |
310 } | 324 } |
311 | 325 |
312 void CrxUpdateService::OnEvent(Events event, const std::string& id) { | 326 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. | 362 // TODO(sorin): consider making this a singleton. |
349 scoped_ptr<ComponentUpdateService> ComponentUpdateServiceFactory( | 363 scoped_ptr<ComponentUpdateService> ComponentUpdateServiceFactory( |
350 const scoped_refptr<Configurator>& config) { | 364 const scoped_refptr<Configurator>& config) { |
351 DCHECK(config); | 365 DCHECK(config); |
352 auto update_client = update_client::UpdateClientFactory(config); | 366 auto update_client = update_client::UpdateClientFactory(config); |
353 return scoped_ptr<ComponentUpdateService>( | 367 return scoped_ptr<ComponentUpdateService>( |
354 new CrxUpdateService(config, std::move(update_client))); | 368 new CrxUpdateService(config, std::move(update_client))); |
355 } | 369 } |
356 | 370 |
357 } // namespace component_updater | 371 } // namespace component_updater |
OLD | NEW |