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