| 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 <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.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/message_loop/message_loop_proxy.h" | 21 #include "base/message_loop/message_loop_proxy.h" |
| 22 #include "base/observer_list.h" | 22 #include "base/observer_list.h" |
| 23 #include "base/sequenced_task_runner.h" | 23 #include "base/sequenced_task_runner.h" |
| 24 #include "base/stl_util.h" | 24 #include "base/stl_util.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/timer/timer.h" | 27 #include "base/timer/timer.h" |
| 28 #include "components/component_updater/component_patcher_operation.h" | 28 #include "components/update_client/component_patcher_operation.h" |
| 29 #include "components/component_updater/component_unpacker.h" | 29 #include "components/update_client/component_unpacker.h" |
| 30 #include "components/component_updater/component_updater_configurator.h" | 30 #include "components/update_client/configurator.h" |
| 31 #include "components/component_updater/component_updater_ping_manager.h" | 31 #include "components/update_client/crx_downloader.h" |
| 32 #include "components/component_updater/component_updater_utils.h" | 32 #include "components/update_client/crx_update_item.h" |
| 33 #include "components/component_updater/crx_downloader.h" | 33 #include "components/update_client/ping_manager.h" |
| 34 #include "components/component_updater/crx_update_item.h" | 34 #include "components/update_client/update_checker.h" |
| 35 #include "components/component_updater/update_checker.h" | 35 #include "components/update_client/update_client.h" |
| 36 #include "components/component_updater/update_response.h" | 36 #include "components/update_client/update_response.h" |
| 37 #include "components/update_client/utils.h" |
| 37 #include "url/gurl.h" | 38 #include "url/gurl.h" |
| 38 | 39 |
| 40 using update_client::ComponentInstaller; |
| 41 using update_client::ComponentUnpacker; |
| 42 using update_client::Configurator; |
| 43 using update_client::CrxComponent; |
| 44 using update_client::CrxDownloader; |
| 45 using update_client::CrxUpdateItem; |
| 46 using update_client::PingManager; |
| 47 using update_client::UpdateChecker; |
| 48 using update_client::UpdateResponse; |
| 49 |
| 39 namespace component_updater { | 50 namespace component_updater { |
| 40 | 51 |
| 41 // The component updater is designed to live until process shutdown, so | 52 // The component updater is designed to live until process shutdown, so |
| 42 // base::Bind() calls are not refcounted. | 53 // base::Bind() calls are not refcounted. |
| 43 | 54 |
| 44 namespace { | 55 namespace { |
| 45 | 56 |
| 46 // Returns true if the |proposed| version is newer than |current| version. | 57 // Returns true if the |proposed| version is newer than |current| version. |
| 47 bool IsVersionNewer(const Version& current, const std::string& proposed) { | 58 bool IsVersionNewer(const Version& current, const std::string& proposed) { |
| 48 Version proposed_ver(proposed); | 59 Version proposed_ver(proposed); |
| 49 return proposed_ver.IsValid() && current.CompareTo(proposed_ver) < 0; | 60 return proposed_ver.IsValid() && current.CompareTo(proposed_ver) < 0; |
| 50 } | 61 } |
| 51 | 62 |
| 52 // Returns true if a differential update is available, it has not failed yet, | 63 // Returns true if a differential update is available, it has not failed yet, |
| 53 // and the configuration allows it. | 64 // and the configuration allows it. |
| 54 bool CanTryDiffUpdate(const CrxUpdateItem* update_item, | 65 bool CanTryDiffUpdate(const CrxUpdateItem* update_item, |
| 55 const Configurator& config) { | 66 const Configurator& config) { |
| 56 return HasDiffUpdate(update_item) && !update_item->diff_update_failed && | 67 return HasDiffUpdate(update_item) && !update_item->diff_update_failed && |
| 57 config.DeltasEnabled(); | 68 config.DeltasEnabled(); |
| 58 } | 69 } |
| 59 | 70 |
| 60 void AppendDownloadMetrics( | 71 void AppendDownloadMetrics( |
| 61 const std::vector<CrxDownloader::DownloadMetrics>& source, | 72 const std::vector<CrxDownloader::DownloadMetrics>& source, |
| 62 std::vector<CrxDownloader::DownloadMetrics>* destination) { | 73 std::vector<CrxDownloader::DownloadMetrics>* destination) { |
| 63 destination->insert(destination->end(), source.begin(), source.end()); | 74 destination->insert(destination->end(), source.begin(), source.end()); |
| 64 } | 75 } |
| 65 | 76 |
| 66 } // namespace | 77 } // namespace |
| 67 | 78 |
| 68 CrxUpdateItem::CrxUpdateItem() | |
| 69 : status(kNew), | |
| 70 on_demand(false), | |
| 71 diff_update_failed(false), | |
| 72 error_category(0), | |
| 73 error_code(0), | |
| 74 extra_code1(0), | |
| 75 diff_error_category(0), | |
| 76 diff_error_code(0), | |
| 77 diff_extra_code1(0) { | |
| 78 } | |
| 79 | |
| 80 CrxUpdateItem::~CrxUpdateItem() { | |
| 81 } | |
| 82 | |
| 83 CrxComponent::CrxComponent() | |
| 84 : installer(NULL), allow_background_download(true) { | |
| 85 } | |
| 86 | |
| 87 CrxComponent::~CrxComponent() { | |
| 88 } | |
| 89 | |
| 90 ////////////////////////////////////////////////////////////////////////////// | 79 ////////////////////////////////////////////////////////////////////////////// |
| 91 // The one and only implementation of the ComponentUpdateService interface. In | 80 // The one and only implementation of the ComponentUpdateService interface. In |
| 92 // charge of running the show. The main method is ProcessPendingItems() which | 81 // charge of running the show. The main method is ProcessPendingItems() which |
| 93 // is called periodically to do the upgrades/installs or the update checks. | 82 // is called periodically to do the upgrades/installs or the update checks. |
| 94 // An important consideration here is to be as "low impact" as we can to the | 83 // An important consideration here is to be as "low impact" as we can to the |
| 95 // rest of the browser, so even if we have many components registered and | 84 // rest of the browser, so even if we have many components registered and |
| 96 // eligible for update, we only do one thing at a time with pauses in between | 85 // eligible for update, we only do one thing at a time with pauses in between |
| 97 // the tasks. Also when we do network requests there is only one |url_fetcher_| | 86 // the tasks. Also when we do network requests there is only one |url_fetcher_| |
| 98 // in flight at a time. | 87 // in flight at a time. |
| 99 // There are no locks in this code, the main structure |work_items_| is mutated | 88 // There are no locks in this code, the main structure |work_items_| is mutated |
| (...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 unpacker_->Unpack(base::Bind(&CrxUpdateService::EndUnpacking, | 851 unpacker_->Unpack(base::Bind(&CrxUpdateService::EndUnpacking, |
| 863 base::Unretained(this), | 852 base::Unretained(this), |
| 864 context->id, | 853 context->id, |
| 865 crx_path)); | 854 crx_path)); |
| 866 } | 855 } |
| 867 | 856 |
| 868 void CrxUpdateService::EndUnpacking(const std::string& component_id, | 857 void CrxUpdateService::EndUnpacking(const std::string& component_id, |
| 869 const base::FilePath& crx_path, | 858 const base::FilePath& crx_path, |
| 870 ComponentUnpacker::Error error, | 859 ComponentUnpacker::Error error, |
| 871 int extended_error) { | 860 int extended_error) { |
| 872 if (!DeleteFileAndEmptyParentDirectory(crx_path)) | 861 if (!update_client::DeleteFileAndEmptyParentDirectory(crx_path)) |
| 873 NOTREACHED() << crx_path.value(); | 862 NOTREACHED() << crx_path.value(); |
| 874 main_task_runner_->PostDelayedTask( | 863 main_task_runner_->PostDelayedTask( |
| 875 FROM_HERE, | 864 FROM_HERE, |
| 876 base::Bind(&CrxUpdateService::DoneInstalling, | 865 base::Bind(&CrxUpdateService::DoneInstalling, |
| 877 base::Unretained(this), | 866 base::Unretained(this), |
| 878 component_id, | 867 component_id, |
| 879 error, | 868 error, |
| 880 extended_error), | 869 extended_error), |
| 881 base::TimeDelta::FromMilliseconds(config_->StepDelay())); | 870 base::TimeDelta::FromMilliseconds(config_->StepDelay())); |
| 882 // Reset the unpacker last, otherwise we free our own arguments. | 871 // Reset the unpacker last, otherwise we free our own arguments. |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 /////////////////////////////////////////////////////////////////////////////// | 1002 /////////////////////////////////////////////////////////////////////////////// |
| 1014 | 1003 |
| 1015 // The component update factory. Using the component updater as a singleton | 1004 // The component update factory. Using the component updater as a singleton |
| 1016 // is the job of the browser process. | 1005 // is the job of the browser process. |
| 1017 ComponentUpdateService* ComponentUpdateServiceFactory(Configurator* config) { | 1006 ComponentUpdateService* ComponentUpdateServiceFactory(Configurator* config) { |
| 1018 DCHECK(config); | 1007 DCHECK(config); |
| 1019 return new CrxUpdateService(config); | 1008 return new CrxUpdateService(config); |
| 1020 } | 1009 } |
| 1021 | 1010 |
| 1022 } // namespace component_updater | 1011 } // namespace component_updater |
| OLD | NEW |