[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / components / component_updater / configurator_impl.cc
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.
4
5 #include "components/component_updater/configurator_impl.h"
6
7 #include <algorithm>
8 #include <string>
9 #include <vector>
10
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"
27 #include "url/gurl.h"
28
29 #if BUILDFLAG(IS_WIN)
30 #include "base/win/win_util.h"
31 #endif
32
33 namespace component_updater {
34
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";
48   }
49 }
50
51 ConfiguratorImpl::~ConfiguratorImpl() = default;
52
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);
57 }
58
59 base::TimeDelta ConfiguratorImpl::NextCheckDelay() const {
60   return base::Hours(5);
61 }
62
63 base::TimeDelta ConfiguratorImpl::OnDemandDelay() const {
64   return fast_update_ ? base::Seconds(2) : base::Minutes(30);
65 }
66
67 base::TimeDelta ConfiguratorImpl::UpdateDelay() const {
68   return fast_update_ ? base::Seconds(10) : base::Minutes(15);
69 }
70
71 std::vector<GURL> ConfiguratorImpl::UpdateUrl() const {
72   if (url_source_override_.is_valid())
73     return {GURL(url_source_override_)};
74
75   std::vector<GURL> urls{GURL(kUpdaterJSONDefaultUrl),
76                          GURL(kUpdaterJSONFallbackUrl)};
77   if (require_encryption_)
78     update_client::RemoveUnsecureUrls(&urls);
79
80   return urls;
81 }
82
83 std::vector<GURL> ConfiguratorImpl::PingUrl() const {
84   return pings_enabled_ ? UpdateUrl() : std::vector<GURL>();
85 }
86
87 const base::Version& ConfiguratorImpl::GetBrowserVersion() const {
88   return version_info::GetVersion();
89 }
90
91 std::string ConfiguratorImpl::GetOSLongName() const {
92   return std::string(version_info::GetOSType());
93 }
94
95 base::flat_map<std::string, std::string> ConfiguratorImpl::ExtraRequestParams()
96     const {
97   return extra_info_;
98 }
99
100 std::string ConfiguratorImpl::GetDownloadPreference() const {
101   return std::string();
102 }
103
104 bool ConfiguratorImpl::EnabledDeltas() const {
105   return deltas_enabled_;
106 }
107
108 bool ConfiguratorImpl::EnabledComponentUpdates() const {
109   return true;
110 }
111
112 bool ConfiguratorImpl::EnabledBackgroundDownloader() const {
113   return background_downloads_enabled_;
114 }
115
116 bool ConfiguratorImpl::EnabledCupSigning() const {
117   return true;
118 }
119
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 {
124   return {};
125 }
126
127 std::unique_ptr<update_client::ProtocolHandlerFactory>
128 ConfiguratorImpl::GetProtocolHandlerFactory() const {
129   return std::make_unique<update_client::ProtocolHandlerFactoryJSON>();
130 }
131
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
135 // component.
136 update_client::UpdaterStateProvider ConfiguratorImpl::GetUpdaterStateProvider()
137     const {
138   return base::BindRepeating([](bool /*is_machine*/) {
139     return base::flat_map<std::string, std::string>();
140   });
141 }
142
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();
149 #else
150   return absl::nullopt;
151 #endif
152 }
153
154 }  // namespace component_updater