droger | f8a8814 | 2015-08-19 07:48:36 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "components/component_updater/configurator_impl.h" |
| 6 | |
avi | bc5337b | 2015-12-25 23:16:33 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
droger | f8a8814 | 2015-08-19 07:48:36 | [diff] [blame] | 9 | #include <algorithm> |
| 10 | |
Sorin Jianu | 75e6bf2 | 2019-02-12 16:07:12 | [diff] [blame] | 11 | #include "base/callback.h" |
Sorin Jianu | 5017f22c | 2018-11-15 18:05:13 | [diff] [blame] | 12 | #include "base/feature_list.h" |
djmix.kim | a8283ee | 2017-07-11 08:48:53 | [diff] [blame] | 13 | #include "base/stl_util.h" |
droger | f8a8814 | 2015-08-19 07:48:36 | [diff] [blame] | 14 | #include "base/strings/string_split.h" |
| 15 | #include "base/strings/string_util.h" |
| 16 | #include "base/version.h" |
| 17 | #include "build/build_config.h" |
| 18 | #include "components/component_updater/component_updater_switches.h" |
| 19 | #include "components/component_updater/component_updater_url_constants.h" |
Minh X. Nguyen | 55afbe4 | 2018-05-18 22:04:26 | [diff] [blame] | 20 | #include "components/update_client/command_line_config_policy.h" |
Sorin Jianu | 47a4dd8c | 2018-10-19 16:34:54 | [diff] [blame] | 21 | #include "components/update_client/protocol_handler.h" |
sorin | fccbf2d | 2016-04-04 20:34:34 | [diff] [blame] | 22 | #include "components/update_client/utils.h" |
droger | f8a8814 | 2015-08-19 07:48:36 | [diff] [blame] | 23 | #include "components/version_info/version_info.h" |
| 24 | |
| 25 | #if defined(OS_WIN) |
| 26 | #include "base/win/win_util.h" |
| 27 | #endif // OS_WIN |
| 28 | |
| 29 | namespace component_updater { |
| 30 | |
| 31 | namespace { |
sorin | 3dd028dc | 2016-07-26 00:06:34 | [diff] [blame] | 32 | |
droger | f8a8814 | 2015-08-19 07:48:36 | [diff] [blame] | 33 | // Default time constants. |
| 34 | const int kDelayOneMinute = 60; |
| 35 | const int kDelayOneHour = kDelayOneMinute * 60; |
| 36 | |
droger | f8a8814 | 2015-08-19 07:48:36 | [diff] [blame] | 37 | } // namespace |
| 38 | |
Minh X. Nguyen | 55afbe4 | 2018-05-18 22:04:26 | [diff] [blame] | 39 | ConfiguratorImpl::ConfiguratorImpl( |
| 40 | const update_client::CommandLineConfigPolicy& config_policy, |
| 41 | bool require_encryption) |
| 42 | : background_downloads_enabled_(config_policy.BackgroundDownloadsEnabled()), |
| 43 | deltas_enabled_(config_policy.DeltaUpdatesEnabled()), |
| 44 | fast_update_(config_policy.FastUpdate()), |
| 45 | pings_enabled_(config_policy.PingsEnabled()), |
| 46 | require_encryption_(require_encryption), |
Sorin Jianu | c27ef6f | 2018-06-19 14:42:55 | [diff] [blame] | 47 | url_source_override_(config_policy.UrlSourceOverride()), |
| 48 | initial_delay_(config_policy.InitialDelay()) { |
Sorin Jianu | 704c72ee | 2018-11-19 23:24:53 | [diff] [blame] | 49 | if (config_policy.TestRequest()) { |
Sorin Jianu | c303bf4 | 2018-09-07 16:19:33 | [diff] [blame] | 50 | extra_info_["testrequest"] = "1"; |
Sorin Jianu | 704c72ee | 2018-11-19 23:24:53 | [diff] [blame] | 51 | extra_info_["testsource"] = "dev"; |
| 52 | } |
droger | f8a8814 | 2015-08-19 07:48:36 | [diff] [blame] | 53 | } |
| 54 | |
Sorin Jianu | 3088115 | 2020-03-16 14:31:19 | [diff] [blame] | 55 | ConfiguratorImpl::~ConfiguratorImpl() = default; |
droger | f8a8814 | 2015-08-19 07:48:36 | [diff] [blame] | 56 | |
| 57 | int ConfiguratorImpl::InitialDelay() const { |
Sorin Jianu | c27ef6f | 2018-06-19 14:42:55 | [diff] [blame] | 58 | if (initial_delay_) |
| 59 | return initial_delay_; |
Joshua Pawlicki | 7b801e0b | 2019-11-01 13:15:21 | [diff] [blame] | 60 | return fast_update_ ? 10 : kDelayOneMinute; |
droger | f8a8814 | 2015-08-19 07:48:36 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | int ConfiguratorImpl::NextCheckDelay() const { |
mxnguyen | 96a65626 | 2017-02-28 17:51:43 | [diff] [blame] | 64 | return 5 * kDelayOneHour; |
droger | f8a8814 | 2015-08-19 07:48:36 | [diff] [blame] | 65 | } |
| 66 | |
droger | f8a8814 | 2015-08-19 07:48:36 | [diff] [blame] | 67 | int ConfiguratorImpl::OnDemandDelay() const { |
| 68 | return fast_update_ ? 2 : (30 * kDelayOneMinute); |
| 69 | } |
| 70 | |
| 71 | int ConfiguratorImpl::UpdateDelay() const { |
| 72 | return fast_update_ ? 10 : (15 * kDelayOneMinute); |
| 73 | } |
| 74 | |
| 75 | std::vector<GURL> ConfiguratorImpl::UpdateUrl() const { |
Sorin Jianu | 5017f22c | 2018-11-15 18:05:13 | [diff] [blame] | 76 | if (url_source_override_.is_valid()) |
Sorin Jianu | f659885 | 2018-05-15 18:08:04 | [diff] [blame] | 77 | return {GURL(url_source_override_)}; |
sorin | fccbf2d | 2016-04-04 20:34:34 | [diff] [blame] | 78 | |
Joshua Pawlicki | 705087b | 2019-03-12 15:40:57 | [diff] [blame] | 79 | std::vector<GURL> urls{GURL(kUpdaterJSONDefaultUrl), |
| 80 | GURL(kUpdaterJSONFallbackUrl)}; |
sorin | fccbf2d | 2016-04-04 20:34:34 | [diff] [blame] | 81 | if (require_encryption_) |
| 82 | update_client::RemoveUnsecureUrls(&urls); |
| 83 | |
droger | f8a8814 | 2015-08-19 07:48:36 | [diff] [blame] | 84 | return urls; |
| 85 | } |
| 86 | |
| 87 | std::vector<GURL> ConfiguratorImpl::PingUrl() const { |
| 88 | return pings_enabled_ ? UpdateUrl() : std::vector<GURL>(); |
| 89 | } |
| 90 | |
Lei Zhang | 8dbfcb6 | 2018-04-05 00:41:08 | [diff] [blame] | 91 | const base::Version& ConfiguratorImpl::GetBrowserVersion() const { |
| 92 | return version_info::GetVersion(); |
droger | f8a8814 | 2015-08-19 07:48:36 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | std::string ConfiguratorImpl::GetOSLongName() const { |
| 96 | return version_info::GetOSType(); |
| 97 | } |
| 98 | |
Sorin Jianu | c303bf4 | 2018-09-07 16:19:33 | [diff] [blame] | 99 | base::flat_map<std::string, std::string> ConfiguratorImpl::ExtraRequestParams() |
| 100 | const { |
droger | f8a8814 | 2015-08-19 07:48:36 | [diff] [blame] | 101 | return extra_info_; |
| 102 | } |
| 103 | |
sorin | 590586c | 2016-01-26 20:09:40 | [diff] [blame] | 104 | std::string ConfiguratorImpl::GetDownloadPreference() const { |
| 105 | return std::string(); |
| 106 | } |
| 107 | |
sorin | cb4e5e9 | 2016-08-02 21:48:40 | [diff] [blame] | 108 | bool ConfiguratorImpl::EnabledDeltas() const { |
droger | f8a8814 | 2015-08-19 07:48:36 | [diff] [blame] | 109 | return deltas_enabled_; |
| 110 | } |
| 111 | |
sorin | cb4e5e9 | 2016-08-02 21:48:40 | [diff] [blame] | 112 | bool ConfiguratorImpl::EnabledComponentUpdates() const { |
| 113 | return true; |
| 114 | } |
| 115 | |
| 116 | bool ConfiguratorImpl::EnabledBackgroundDownloader() const { |
droger | f8a8814 | 2015-08-19 07:48:36 | [diff] [blame] | 117 | return background_downloads_enabled_; |
| 118 | } |
| 119 | |
sorin | cb4e5e9 | 2016-08-02 21:48:40 | [diff] [blame] | 120 | bool ConfiguratorImpl::EnabledCupSigning() const { |
sorin | 1bc5eff | 2016-02-17 18:45:17 | [diff] [blame] | 121 | return true; |
| 122 | } |
| 123 | |
Sorin Jianu | dbbd2c2c | 2018-06-11 18:16:27 | [diff] [blame] | 124 | // The default implementation for most embedders returns an empty string. |
| 125 | // Desktop embedders, such as the Windows component updater can provide a |
| 126 | // meaningful implementation for this function. |
| 127 | std::string ConfiguratorImpl::GetAppGuid() const { |
| 128 | return {}; |
| 129 | } |
| 130 | |
Sorin Jianu | 47a4dd8c | 2018-10-19 16:34:54 | [diff] [blame] | 131 | std::unique_ptr<update_client::ProtocolHandlerFactory> |
| 132 | ConfiguratorImpl::GetProtocolHandlerFactory() const { |
Joshua Pawlicki | 705087b | 2019-03-12 15:40:57 | [diff] [blame] | 133 | return std::make_unique<update_client::ProtocolHandlerFactoryJSON>(); |
Sorin Jianu | 47a4dd8c | 2018-10-19 16:34:54 | [diff] [blame] | 134 | } |
| 135 | |
droger | f8a8814 | 2015-08-19 07:48:36 | [diff] [blame] | 136 | } // namespace component_updater |