| 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> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "base/sequenced_task_runner.h" | 22 #include "base/sequenced_task_runner.h" |
| 23 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
| 24 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
| 25 #include "base/threading/sequenced_worker_pool.h" | 25 #include "base/threading/sequenced_worker_pool.h" |
| 26 #include "base/threading/thread_checker.h" | 26 #include "base/threading/thread_checker.h" |
| 27 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
| 28 #include "base/time/time.h" | 28 #include "base/time/time.h" |
| 29 #include "base/timer/timer.h" | 29 #include "base/timer/timer.h" |
| 30 #include "components/component_updater/component_updater_service_internal.h" | 30 #include "components/component_updater/component_updater_service_internal.h" |
| 31 #include "components/component_updater/timer.h" | 31 #include "components/component_updater/timer.h" |
| 32 #if defined(OS_WIN) | |
| 33 #include "components/component_updater/updater_state_win.h" | |
| 34 #endif | |
| 35 #include "components/update_client/configurator.h" | 32 #include "components/update_client/configurator.h" |
| 36 #include "components/update_client/crx_update_item.h" | 33 #include "components/update_client/crx_update_item.h" |
| 37 #include "components/update_client/update_client.h" | 34 #include "components/update_client/update_client.h" |
| 38 #include "components/update_client/update_client_errors.h" | 35 #include "components/update_client/update_client_errors.h" |
| 39 #include "components/update_client/utils.h" | 36 #include "components/update_client/utils.h" |
| 40 #include "url/gurl.h" | 37 #include "url/gurl.h" |
| 41 | 38 |
| 42 using CrxInstaller = update_client::CrxInstaller; | 39 using CrxInstaller = update_client::CrxInstaller; |
| 43 using UpdateClient = update_client::UpdateClient; | 40 using UpdateClient = update_client::UpdateClient; |
| 44 | 41 |
| 45 namespace { | 42 namespace { |
| 46 | 43 |
| 47 enum UpdateType { | 44 enum UpdateType { |
| 48 UPDATE_TYPE_MANUAL = 0, | 45 UPDATE_TYPE_MANUAL = 0, |
| 49 UPDATE_TYPE_AUTOMATIC, | 46 UPDATE_TYPE_AUTOMATIC, |
| 50 UPDATE_TYPE_COUNT, | 47 UPDATE_TYPE_COUNT, |
| 51 }; | 48 }; |
| 52 | 49 |
| 53 const char kRecoveryComponentId[] = "npdjjkjlcidkjlamlmmdelcjbcpdjocm"; | |
| 54 | |
| 55 } // namespace | 50 } // namespace |
| 56 | 51 |
| 57 namespace component_updater { | 52 namespace component_updater { |
| 58 | 53 |
| 59 ComponentInfo::ComponentInfo(const std::string& id, const base::string16& name, | 54 ComponentInfo::ComponentInfo(const std::string& id, const base::string16& name, |
| 60 const base::Version& version) | 55 const base::Version& version) |
| 61 : id(id), name(name), version(version) {} | 56 : id(id), name(name), version(version) {} |
| 62 ComponentInfo::~ComponentInfo() {} | 57 ComponentInfo::~ComponentInfo() {} |
| 63 | 58 |
| 64 CrxUpdateService::CrxUpdateService( | 59 CrxUpdateService::CrxUpdateService( |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 return false; | 349 return false; |
| 355 } | 350 } |
| 356 | 351 |
| 357 void CrxUpdateService::OnUpdate(const std::vector<std::string>& ids, | 352 void CrxUpdateService::OnUpdate(const std::vector<std::string>& ids, |
| 358 std::vector<CrxComponent>* components) { | 353 std::vector<CrxComponent>* components) { |
| 359 DCHECK(thread_checker_.CalledOnValidThread()); | 354 DCHECK(thread_checker_.CalledOnValidThread()); |
| 360 DCHECK(components->empty()); | 355 DCHECK(components->empty()); |
| 361 | 356 |
| 362 for (const auto& id : ids) { | 357 for (const auto& id : ids) { |
| 363 const update_client::CrxComponent* registered_component(GetComponent(id)); | 358 const update_client::CrxComponent* registered_component(GetComponent(id)); |
| 364 if (registered_component) { | 359 if (registered_component) |
| 365 components->push_back(*registered_component); | 360 components->push_back(*registered_component); |
| 366 if (id == kRecoveryComponentId) { | |
| 367 // Override the installer attributes for the recovery component in the | |
| 368 // components which will be checked for updates. | |
| 369 update_client::CrxComponent& recovery_component(components->back()); | |
| 370 recovery_component.installer_attributes = | |
| 371 GetInstallerAttributesForRecoveryComponentInstaller( | |
| 372 recovery_component); | |
| 373 } | |
| 374 } | |
| 375 } | 361 } |
| 376 } | 362 } |
| 377 | 363 |
| 378 void CrxUpdateService::OnUpdateComplete(Callback callback, | 364 void CrxUpdateService::OnUpdateComplete(Callback callback, |
| 379 const base::TimeTicks& start_time, | 365 const base::TimeTicks& start_time, |
| 380 update_client::Error error) { | 366 update_client::Error error) { |
| 381 DCHECK(thread_checker_.CalledOnValidThread()); | 367 DCHECK(thread_checker_.CalledOnValidThread()); |
| 382 VLOG(1) << "Update completed with error " << static_cast<int>(error); | 368 VLOG(1) << "Update completed with error " << static_cast<int>(error); |
| 383 | 369 |
| 384 UMA_HISTOGRAM_BOOLEAN("ComponentUpdater.UpdateCompleteResult", | 370 UMA_HISTOGRAM_BOOLEAN("ComponentUpdater.UpdateCompleteResult", |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 // Update the component registration with the new version. | 411 // Update the component registration with the new version. |
| 426 if (event == Observer::Events::COMPONENT_UPDATED) { | 412 if (event == Observer::Events::COMPONENT_UPDATED) { |
| 427 auto* component(const_cast<CrxComponent*>(GetComponent(id))); | 413 auto* component(const_cast<CrxComponent*>(GetComponent(id))); |
| 428 if (component) { | 414 if (component) { |
| 429 component->version = update_item.next_version; | 415 component->version = update_item.next_version; |
| 430 component->fingerprint = update_item.next_fp; | 416 component->fingerprint = update_item.next_fp; |
| 431 } | 417 } |
| 432 } | 418 } |
| 433 } | 419 } |
| 434 | 420 |
| 435 update_client::InstallerAttributes | |
| 436 CrxUpdateService::GetInstallerAttributesForRecoveryComponentInstaller( | |
| 437 const CrxComponent& crx_component) const { | |
| 438 update_client::InstallerAttributes installer_attributes; | |
| 439 #if defined(OS_WIN) | |
| 440 DCHECK_EQ("recovery", crx_component.name); | |
| 441 | |
| 442 const bool is_machine = | |
| 443 crx_component.installer_attributes.count("ismachine") && | |
| 444 crx_component.installer_attributes.at("ismachine") == "1"; | |
| 445 | |
| 446 auto updater_state(UpdaterState::Create(is_machine)); | |
| 447 if (updater_state) { | |
| 448 installer_attributes = updater_state->MakeInstallerAttributes(); | |
| 449 } | |
| 450 #endif | |
| 451 return installer_attributes; | |
| 452 } | |
| 453 | |
| 454 /////////////////////////////////////////////////////////////////////////////// | 421 /////////////////////////////////////////////////////////////////////////////// |
| 455 | 422 |
| 456 // The component update factory. Using the component updater as a singleton | 423 // The component update factory. Using the component updater as a singleton |
| 457 // is the job of the browser process. | 424 // is the job of the browser process. |
| 458 // TODO(sorin): consider making this a singleton. | 425 // TODO(sorin): consider making this a singleton. |
| 459 std::unique_ptr<ComponentUpdateService> ComponentUpdateServiceFactory( | 426 std::unique_ptr<ComponentUpdateService> ComponentUpdateServiceFactory( |
| 460 const scoped_refptr<Configurator>& config) { | 427 const scoped_refptr<Configurator>& config) { |
| 461 DCHECK(config); | 428 DCHECK(config); |
| 462 auto update_client = update_client::UpdateClientFactory(config); | 429 auto update_client = update_client::UpdateClientFactory(config); |
| 463 return base::MakeUnique<CrxUpdateService>(config, std::move(update_client)); | 430 return base::MakeUnique<CrxUpdateService>(config, std::move(update_client)); |
| 464 } | 431 } |
| 465 | 432 |
| 466 } // namespace component_updater | 433 } // namespace component_updater |
| OLD | NEW |