1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/updater/configurator.h"
#include <algorithm>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "base/containers/flat_map.h"
#include "base/enterprise_util.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/memory/scoped_refptr.h"
#include "base/rand_util.h"
#include "base/sequence_checker.h"
#include "base/strings/to_string.h"
#include "base/time/time.h"
#include "base/version.h"
#include "build/build_config.h"
#include "chrome/updater/activity.h"
#include "chrome/updater/constants.h"
#include "chrome/updater/crx_downloader_factory.h"
#include "chrome/updater/external_constants.h"
#include "chrome/updater/net/network.h"
#include "chrome/updater/persisted_data.h"
#include "chrome/updater/policy/service.h"
#include "chrome/updater/prefs.h"
#include "chrome/updater/updater_scope.h"
#include "chrome/updater/util/util.h"
#include "components/crash/core/common/crash_key.h"
#include "components/crx_file/crx_verifier.h"
#include "components/prefs/pref_service.h"
#include "components/update_client/crx_cache.h"
#include "components/update_client/network.h"
#include "components/update_client/patch/in_process_patcher.h"
#include "components/update_client/patcher.h"
#include "components/update_client/protocol_handler.h"
#include "components/update_client/unzip/in_process_unzipper.h"
#include "components/update_client/unzipper.h"
#include "components/version_info/version_info.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_WIN)
#include "base/win/win_util.h"
#endif
namespace updater {
namespace {
// Allow internal symbolic links in zip files on macOS.
#if BUILDFLAG(IS_POSIX)
update_client::InProcessUnzipperFactory::SymlinkOption unzipper_symlink_option =
update_client::InProcessUnzipperFactory::SymlinkOption::PRESERVE;
#else
update_client::InProcessUnzipperFactory::SymlinkOption unzipper_symlink_option =
update_client::InProcessUnzipperFactory::SymlinkOption::DONT_PRESERVE;
#endif
} // namespace
Configurator::Configurator(scoped_refptr<UpdaterPrefs> prefs,
scoped_refptr<ExternalConstants> external_constants,
UpdaterScope scope,
bool is_ceca_experiment_enabled)
: prefs_(prefs),
external_constants_(external_constants),
persisted_data_(base::MakeRefCounted<PersistedData>(
scope,
prefs->GetPrefService(),
std::make_unique<ActivityDataService>(scope))),
policy_service_(
base::MakeRefCounted<PolicyService>(external_constants,
persisted_data_,
is_ceca_experiment_enabled)),
unzip_factory_(
base::MakeRefCounted<update_client::InProcessUnzipperFactory>(
unzipper_symlink_option)),
patch_factory_(
base::MakeRefCounted<update_client::InProcessPatcherFactory>()),
crx_cache_(base::MakeRefCounted<update_client::CrxCache>(
GetCrxCacheDirectory(scope))),
is_managed_device_([] {
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
return base::IsManagedOrEnterpriseDevice();
#else
return std::nullopt;
#endif // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
}()) {
#if BUILDFLAG(IS_LINUX)
// On Linux creating the NetworkFetcherFactory requires performing blocking IO
// to load an external library. This should be done when the configurator is
// created.
GetNetworkFetcherFactory();
#endif
static crash_reporter::CrashKeyString<6> crash_key_managed("managed");
crash_key_managed.Set(is_managed_device_ ? base::ToString(*is_managed_device_)
: "n/a");
}
Configurator::~Configurator() = default;
base::TimeDelta Configurator::InitialDelay() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return base::RandDouble() * external_constants_->InitialDelay();
}
base::TimeDelta Configurator::ServerKeepAliveTime() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return std::clamp(external_constants_->ServerKeepAliveTime(),
base::Seconds(1), kServerKeepAliveTime);
}
base::TimeDelta Configurator::NextCheckDelay() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
PolicyStatus<base::TimeDelta> delay = policy_service_->GetLastCheckPeriod();
CHECK(delay);
return delay.policy();
}
base::TimeDelta Configurator::OnDemandDelay() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return base::Seconds(0);
}
base::TimeDelta Configurator::UpdateDelay() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return base::Seconds(0);
}
std::vector<GURL> Configurator::UpdateUrl() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return external_constants_->UpdateURL();
}
std::vector<GURL> Configurator::PingUrl() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return UpdateUrl();
}
GURL Configurator::CrashUploadURL() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return external_constants_->CrashUploadURL();
}
GURL Configurator::DeviceManagementURL() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return external_constants_->DeviceManagementURL();
}
std::string Configurator::GetProdId() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return "updater";
}
base::Version Configurator::GetBrowserVersion() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return version_info::GetVersion();
}
std::string Configurator::GetChannel() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return {};
}
std::string Configurator::GetLang() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return "";
}
std::string Configurator::GetOSLongName() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return std::string(version_info::GetOSType());
}
base::flat_map<std::string, std::string> Configurator::ExtraRequestParams()
const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return {};
}
std::string Configurator::GetDownloadPreference() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
PolicyStatus<std::string> preference =
policy_service_->GetDownloadPreference();
return preference ? preference.policy() : std::string();
}
scoped_refptr<update_client::NetworkFetcherFactory>
Configurator::GetNetworkFetcherFactory() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!network_fetcher_factory_) {
network_fetcher_factory_ = base::MakeRefCounted<NetworkFetcherFactory>(
PolicyServiceProxyConfiguration::Get(policy_service_));
}
return network_fetcher_factory_;
}
scoped_refptr<update_client::CrxDownloaderFactory>
Configurator::GetCrxDownloaderFactory() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!crx_downloader_factory_) {
crx_downloader_factory_ =
updater::MakeCrxDownloaderFactory(GetNetworkFetcherFactory());
}
return crx_downloader_factory_;
}
scoped_refptr<update_client::UnzipperFactory>
Configurator::GetUnzipperFactory() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return unzip_factory_;
}
scoped_refptr<update_client::PatcherFactory> Configurator::GetPatcherFactory() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return patch_factory_;
}
bool Configurator::EnabledBackgroundDownloader() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return false;
}
bool Configurator::EnabledCupSigning() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return external_constants_->UseCUP();
}
PrefService* Configurator::GetPrefService() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return prefs_->GetPrefService();
}
update_client::PersistedData* Configurator::GetPersistedData() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return persisted_data_.get();
}
scoped_refptr<PersistedData> Configurator::GetUpdaterPersistedData() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return persisted_data_;
}
bool Configurator::IsPerUserInstall() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return !IsSystemInstall();
}
std::unique_ptr<update_client::ProtocolHandlerFactory>
Configurator::GetProtocolHandlerFactory() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return std::make_unique<update_client::ProtocolHandlerFactoryJSON>();
}
std::optional<bool> Configurator::IsMachineExternallyManaged() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const std::optional<bool> is_managed_overridden =
external_constants_->IsMachineManaged();
return is_managed_overridden.has_value() ? is_managed_overridden
: is_managed_device_;
}
scoped_refptr<PolicyService> Configurator::GetPolicyService() const {
// The policy service is accessed by RPC on a different sequence and this
// function can't enforce the sequence check for now: crbug.com/1517079.
return policy_service_;
}
crx_file::VerifierFormat Configurator::GetCrxVerifierFormat() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return external_constants_->CrxVerifierFormat();
}
update_client::UpdaterStateProvider Configurator::GetUpdaterStateProvider()
const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return base::BindRepeating([](bool /*is_machine*/) {
return update_client::UpdaterStateAttributes();
});
}
scoped_refptr<update_client::CrxCache> Configurator::GetCrxCache() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return crx_cache_;
}
bool Configurator::IsConnectionMetered() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return false;
}
} // namespace updater
|