1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/component_updater/configurator_impl.h"
11 #include "base/containers/flat_map.h"
12 #include "base/enterprise_util.h"
13 #include "base/feature_list.h"
14 #include "base/functional/callback.h"
15 #include "base/strings/string_split.h"
16 #include "base/strings/string_util.h"
17 #include "base/time/time.h"
18 #include "base/version.h"
19 #include "build/build_config.h"
20 #include "components/component_updater/component_updater_switches.h"
21 #include "components/component_updater/component_updater_url_constants.h"
22 #include "components/update_client/command_line_config_policy.h"
23 #include "components/update_client/protocol_handler.h"
24 #include "components/update_client/utils.h"
25 #include "components/version_info/version_info.h"
26 #include "third_party/abseil-cpp/absl/types/optional.h"
30 #include "base/win/win_util.h"
33 namespace component_updater {
35 ConfiguratorImpl::ConfiguratorImpl(
36 const update_client::CommandLineConfigPolicy& config_policy,
37 bool require_encryption)
38 : background_downloads_enabled_(config_policy.BackgroundDownloadsEnabled()),
39 deltas_enabled_(config_policy.DeltaUpdatesEnabled()),
40 fast_update_(config_policy.FastUpdate()),
41 pings_enabled_(config_policy.PingsEnabled()),
42 require_encryption_(require_encryption),
43 url_source_override_(config_policy.UrlSourceOverride()),
44 initial_delay_(config_policy.InitialDelay()) {
45 if (config_policy.TestRequest()) {
46 extra_info_["testrequest"] = "1";
47 extra_info_["testsource"] = "dev";
51 ConfiguratorImpl::~ConfiguratorImpl() = default;
53 base::TimeDelta ConfiguratorImpl::InitialDelay() const {
54 if (!initial_delay_.is_zero())
55 return initial_delay_;
56 return fast_update_ ? base::Seconds(10) : base::Minutes(1);
59 base::TimeDelta ConfiguratorImpl::NextCheckDelay() const {
60 return base::Hours(5);
63 base::TimeDelta ConfiguratorImpl::OnDemandDelay() const {
64 return fast_update_ ? base::Seconds(2) : base::Minutes(30);
67 base::TimeDelta ConfiguratorImpl::UpdateDelay() const {
68 return fast_update_ ? base::Seconds(10) : base::Minutes(15);
71 std::vector<GURL> ConfiguratorImpl::UpdateUrl() const {
72 if (url_source_override_.is_valid())
73 return {GURL(url_source_override_)};
75 std::vector<GURL> urls{GURL(kUpdaterJSONDefaultUrl),
76 GURL(kUpdaterJSONFallbackUrl)};
77 if (require_encryption_)
78 update_client::RemoveUnsecureUrls(&urls);
83 std::vector<GURL> ConfiguratorImpl::PingUrl() const {
84 return pings_enabled_ ? UpdateUrl() : std::vector<GURL>();
87 const base::Version& ConfiguratorImpl::GetBrowserVersion() const {
88 return version_info::GetVersion();
91 std::string ConfiguratorImpl::GetOSLongName() const {
92 return std::string(version_info::GetOSType());
95 base::flat_map<std::string, std::string> ConfiguratorImpl::ExtraRequestParams()
100 std::string ConfiguratorImpl::GetDownloadPreference() const {
101 return std::string();
104 bool ConfiguratorImpl::EnabledDeltas() const {
105 return deltas_enabled_;
108 bool ConfiguratorImpl::EnabledComponentUpdates() const {
112 bool ConfiguratorImpl::EnabledBackgroundDownloader() const {
113 return background_downloads_enabled_;
116 bool ConfiguratorImpl::EnabledCupSigning() const {
120 // The default implementation for most embedders returns an empty string.
121 // Desktop embedders, such as the Windows component updater can provide a
122 // meaningful implementation for this function.
123 std::string ConfiguratorImpl::GetAppGuid() const {
127 std::unique_ptr<update_client::ProtocolHandlerFactory>
128 ConfiguratorImpl::GetProtocolHandlerFactory() const {
129 return std::make_unique<update_client::ProtocolHandlerFactoryJSON>();
132 // Returns a "do nothing" callback which returns an empty updater state.
133 // This is the correct default for all the embedders except the component
134 // updater for Chrome on macOS and Windows, which includes a recovery
136 update_client::UpdaterStateProvider ConfiguratorImpl::GetUpdaterStateProvider()
138 return base::BindRepeating([](bool /*is_machine*/) {
139 return base::flat_map<std::string, std::string>();
143 absl::optional<bool> ConfiguratorImpl::IsMachineExternallyManaged() const {
144 #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
145 // TODO(crbug.com/1320776): For legacy compatibility, this uses
146 // IsEnterpriseDevice() which effectively equates to a domain join check.
147 // Consider whether this should use IsManagedDevice() instead.
148 return base::IsEnterpriseDevice();
150 return absl::nullopt;
154 } // namespace component_updater