summaryrefslogtreecommitdiff
path: root/chromium/components/update_client
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/components/update_client')
-rw-r--r--chromium/components/update_client/BUILD.gn8
-rw-r--r--chromium/components/update_client/command_line_config_policy.cc2
-rw-r--r--chromium/components/update_client/component.cc4
-rw-r--r--chromium/components/update_client/component_patcher.cc4
-rw-r--r--chromium/components/update_client/component_patcher_operation.cc32
-rw-r--r--chromium/components/update_client/configurator.h15
-rw-r--r--chromium/components/update_client/crx_downloader.cc2
-rw-r--r--chromium/components/update_client/crx_downloader_factory.cc4
-rw-r--r--chromium/components/update_client/net/network_impl.cc3
-rw-r--r--chromium/components/update_client/ping_manager.cc4
-rw-r--r--chromium/components/update_client/ping_manager_unittest.cc61
-rw-r--r--chromium/components/update_client/protocol_definition.cc3
-rw-r--r--chromium/components/update_client/protocol_definition.h14
-rw-r--r--chromium/components/update_client/protocol_parser_json.cc8
-rw-r--r--chromium/components/update_client/protocol_serializer.cc50
-rw-r--r--chromium/components/update_client/protocol_serializer.h3
-rw-r--r--chromium/components/update_client/protocol_serializer_fuzzer.cc14
-rw-r--r--chromium/components/update_client/protocol_serializer_json.cc8
-rw-r--r--chromium/components/update_client/protocol_serializer_json_unittest.cc56
-rw-r--r--chromium/components/update_client/test_configurator.cc52
-rw-r--r--chromium/components/update_client/test_configurator.h10
-rw-r--r--chromium/components/update_client/update_checker.cc51
-rw-r--r--chromium/components/update_client/update_checker_unittest.cc133
-rw-r--r--chromium/components/update_client/update_client_unittest.cc16
-rw-r--r--chromium/components/update_client/update_engine.h1
-rw-r--r--chromium/components/update_client/update_query_params.cc16
-rw-r--r--chromium/components/update_client/updater_state.cc102
-rw-r--r--chromium/components/update_client/updater_state.h69
-rw-r--r--chromium/components/update_client/updater_state_mac.mm117
-rw-r--r--chromium/components/update_client/updater_state_unittest.cc127
-rw-r--r--chromium/components/update_client/updater_state_win.cc135
-rw-r--r--chromium/components/update_client/utils_unittest.cc1
32 files changed, 364 insertions, 761 deletions
diff --git a/chromium/components/update_client/BUILD.gn b/chromium/components/update_client/BUILD.gn
index 2be2468863d..b334c4c8d36 100644
--- a/chromium/components/update_client/BUILD.gn
+++ b/chromium/components/update_client/BUILD.gn
@@ -142,8 +142,6 @@ static_library("update_client") {
"update_query_params.h",
"update_query_params_delegate.cc",
"update_query_params_delegate.h",
- "updater_state.cc",
- "updater_state.h",
"url_fetcher_downloader.cc",
"url_fetcher_downloader.h",
"utils.cc",
@@ -167,13 +165,8 @@ static_library("update_client") {
sources += [
"background_downloader_win.cc",
"background_downloader_win.h",
- "updater_state_win.cc",
]
}
-
- if (is_mac) {
- sources += [ "updater_state_mac.mm" ]
- }
}
static_library("test_support") {
@@ -255,7 +248,6 @@ source_set("unit_tests") {
"update_checker_unittest.cc",
"update_client_unittest.cc",
"update_query_params_unittest.cc",
- "updater_state_unittest.cc",
"utils_unittest.cc",
]
diff --git a/chromium/components/update_client/command_line_config_policy.cc b/chromium/components/update_client/command_line_config_policy.cc
index fa024978fdd..7a5bd1b879b 100644
--- a/chromium/components/update_client/command_line_config_policy.cc
+++ b/chromium/components/update_client/command_line_config_policy.cc
@@ -10,7 +10,7 @@
namespace update_client {
bool CommandLineConfigPolicy::BackgroundDownloadsEnabled() const {
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
return true;
#else
return false;
diff --git a/chromium/components/update_client/component.cc b/chromium/components/update_client/component.cc
index eb3a7c97422..5e937916c6a 100644
--- a/chromium/components/update_client/component.cc
+++ b/chromium/components/update_client/component.cc
@@ -5,6 +5,7 @@
#include "components/update_client/component.h"
#include <algorithm>
+#include <tuple>
#include <utility>
#include "base/bind.h"
@@ -13,7 +14,6 @@
#include "base/check_op.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
-#include "base/ignore_result.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/notreached.h"
@@ -112,7 +112,7 @@ void InstallOnBlockingTaskRunner(
// Acquire the ownership of the |unpack_path|.
base::ScopedTempDir unpack_path_owner;
- ignore_result(unpack_path_owner.Set(unpack_path));
+ std::ignore = unpack_path_owner.Set(unpack_path);
if (static_cast<int>(fingerprint.size()) !=
base::WriteFile(
diff --git a/chromium/components/update_client/component_patcher.cc b/chromium/components/update_client/component_patcher.cc
index de1106a0c37..fc58e4f930e 100644
--- a/chromium/components/update_client/component_patcher.cc
+++ b/chromium/components/update_client/component_patcher.cc
@@ -66,13 +66,13 @@ void ComponentPatcher::StartPatching() {
if (!commands_) {
DonePatching(UnpackerError::kDeltaBadCommands, 0);
} else {
- next_command_ = commands_->GetList().begin();
+ next_command_ = commands_->GetListDeprecated().begin();
PatchNextFile();
}
}
void ComponentPatcher::PatchNextFile() {
- if (next_command_ == commands_->GetList().end()) {
+ if (next_command_ == commands_->GetListDeprecated().end()) {
DonePatching(UnpackerError::kNone, 0);
return;
}
diff --git a/chromium/components/update_client/component_patcher_operation.cc b/chromium/components/update_client/component_patcher_operation.cc
index 2dd2f7e1797..29f5c9adfa5 100644
--- a/chromium/components/update_client/component_patcher_operation.cc
+++ b/chromium/components/update_client/component_patcher_operation.cc
@@ -64,15 +64,16 @@ void DeltaUpdateOp::Run(const base::DictionaryValue* command_args,
scoped_refptr<CrxInstaller> installer,
ComponentPatcher::Callback callback) {
callback_ = std::move(callback);
- std::string output_rel_path;
- if (!command_args->GetString(kOutput, &output_rel_path) ||
- !command_args->GetString(kSha256, &output_sha256_)) {
+ const std::string* output_rel_path = command_args->FindStringKey(kOutput);
+ const std::string* sha256_value = command_args->FindStringKey(kSha256);
+ if (!output_rel_path || !sha256_value) {
DoneRunning(UnpackerError::kDeltaBadCommands, 0);
return;
}
+ output_sha256_ = *sha256_value;
output_abs_path_ =
- unpack_dir.Append(base::FilePath::FromUTF8Unsafe(output_rel_path));
+ unpack_dir.Append(base::FilePath::FromUTF8Unsafe(*output_rel_path));
UnpackerError parse_result =
DoParseArguments(command_args, input_dir, installer);
if (parse_result != UnpackerError::kNone) {
@@ -115,11 +116,11 @@ UnpackerError DeltaUpdateOpCopy::DoParseArguments(
const base::DictionaryValue* command_args,
const base::FilePath& input_dir,
scoped_refptr<CrxInstaller> installer) {
- std::string input_rel_path;
- if (!command_args->GetString(kInput, &input_rel_path))
+ const std::string* input_rel_path = command_args->FindStringKey(kInput);
+ if (!input_rel_path)
return UnpackerError::kDeltaBadCommands;
- if (!installer->GetInstalledFile(input_rel_path, &input_abs_path_))
+ if (!installer->GetInstalledFile(*input_rel_path, &input_abs_path_))
return UnpackerError::kDeltaMissingExistingFile;
return UnpackerError::kNone;
@@ -140,12 +141,12 @@ UnpackerError DeltaUpdateOpCreate::DoParseArguments(
const base::DictionaryValue* command_args,
const base::FilePath& input_dir,
scoped_refptr<CrxInstaller> installer) {
- std::string patch_rel_path;
- if (!command_args->GetString(kPatch, &patch_rel_path))
+ const std::string* patch_rel_path = command_args->FindStringKey(kPatch);
+ if (!patch_rel_path)
return UnpackerError::kDeltaBadCommands;
patch_abs_path_ =
- input_dir.Append(base::FilePath::FromUTF8Unsafe(patch_rel_path));
+ input_dir.Append(base::FilePath::FromUTF8Unsafe(*patch_rel_path));
return UnpackerError::kNone;
}
@@ -169,17 +170,16 @@ UnpackerError DeltaUpdateOpPatch::DoParseArguments(
const base::DictionaryValue* command_args,
const base::FilePath& input_dir,
scoped_refptr<CrxInstaller> installer) {
- std::string patch_rel_path;
- std::string input_rel_path;
- if (!command_args->GetString(kPatch, &patch_rel_path) ||
- !command_args->GetString(kInput, &input_rel_path))
+ const std::string* patch_rel_path = command_args->FindStringKey(kPatch);
+ const std::string* input_rel_path = command_args->FindStringKey(kInput);
+ if (!patch_rel_path || !input_rel_path)
return UnpackerError::kDeltaBadCommands;
- if (!installer->GetInstalledFile(input_rel_path, &input_abs_path_))
+ if (!installer->GetInstalledFile(*input_rel_path, &input_abs_path_))
return UnpackerError::kDeltaMissingExistingFile;
patch_abs_path_ =
- input_dir.Append(base::FilePath::FromUTF8Unsafe(patch_rel_path));
+ input_dir.Append(base::FilePath::FromUTF8Unsafe(*patch_rel_path));
return UnpackerError::kNone;
}
diff --git a/chromium/components/update_client/configurator.h b/chromium/components/update_client/configurator.h
index 01af489dbd0..657b9e35c03 100644
--- a/chromium/components/update_client/configurator.h
+++ b/chromium/components/update_client/configurator.h
@@ -10,8 +10,10 @@
#include <tuple>
#include <vector>
+#include "base/callback_forward.h"
#include "base/containers/flat_map.h"
#include "base/memory/ref_counted.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
class GURL;
class PrefService;
@@ -29,6 +31,10 @@ class PatcherFactory;
class ProtocolHandlerFactory;
class UnzipperFactory;
+using UpdaterStateAttributes = base::flat_map<std::string, std::string>;
+using UpdaterStateProvider =
+ base::RepeatingCallback<UpdaterStateAttributes(bool is_machine)>;
+
// Controls the component updater behavior.
// TODO(sorin): this class will be split soon in two. One class controls
// the behavior of the update client, and the other class controls the
@@ -134,6 +140,15 @@ class Configurator : public base::RefCountedThreadSafe<Configurator> {
virtual std::unique_ptr<ProtocolHandlerFactory> GetProtocolHandlerFactory()
const = 0;
+ // Returns true if Chrome is installed on a system managed by cloud or
+ // group policies, false if the system is not managed, or nullopt if the
+ // platform does not support client management at all.
+ virtual absl::optional<bool> IsMachineExternallyManaged() const = 0;
+
+ // Returns a callable to get the state of the platform updater, if the
+ // embedder includes an updater. Returns a null callback otherwise.
+ virtual UpdaterStateProvider GetUpdaterStateProvider() const = 0;
+
protected:
friend class base::RefCountedThreadSafe<Configurator>;
diff --git a/chromium/components/update_client/crx_downloader.cc b/chromium/components/update_client/crx_downloader.cc
index 2e08652ba67..787235583c8 100644
--- a/chromium/components/update_client/crx_downloader.cc
+++ b/chromium/components/update_client/crx_downloader.cc
@@ -13,7 +13,7 @@
#include "base/task/thread_pool.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
#include "components/update_client/background_downloader_win.h"
#endif
#include "components/update_client/network.h"
diff --git a/chromium/components/update_client/crx_downloader_factory.cc b/chromium/components/update_client/crx_downloader_factory.cc
index 21fb6a5d7a2..7d0afd9ec67 100644
--- a/chromium/components/update_client/crx_downloader_factory.cc
+++ b/chromium/components/update_client/crx_downloader_factory.cc
@@ -5,7 +5,7 @@
#include "components/update_client/crx_downloader_factory.h"
#include "build/build_config.h"
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
#include "components/update_client/background_downloader_win.h"
#endif
#include "components/update_client/crx_downloader.h"
@@ -36,7 +36,7 @@ scoped_refptr<CrxDownloader> CrxDownloaderFactoryChromium::MakeCrxDownloader(
scoped_refptr<CrxDownloader> url_fetcher_downloader =
base::MakeRefCounted<UrlFetcherDownloader>(nullptr,
network_fetcher_factory_);
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
// If background downloads are allowed, then apply the BITS service
// background downloader first.
if (background_download_enabled) {
diff --git a/chromium/components/update_client/net/network_impl.cc b/chromium/components/update_client/net/network_impl.cc
index 2f3e7f3d9a3..6f33a3d05f3 100644
--- a/chromium/components/update_client/net/network_impl.cc
+++ b/chromium/components/update_client/net/network_impl.cc
@@ -16,6 +16,7 @@
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
+#include "services/network/public/cpp/simple_url_loader_throttle.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "url/gurl.h"
@@ -118,6 +119,8 @@ void NetworkFetcherImpl::PostRequest(
resource_request->headers.SetHeader(header.first, header.second);
simple_url_loader_ = network::SimpleURLLoader::Create(
std::move(resource_request), traffic_annotation);
+ if (network::SimpleURLLoaderThrottle::IsBatchingEnabled(traffic_annotation))
+ simple_url_loader_->SetAllowBatching();
simple_url_loader_->SetRetryOptions(
kMaxRetriesOnNetworkChange,
network::SimpleURLLoader::RETRY_ON_NETWORK_CHANGE);
diff --git a/chromium/components/update_client/ping_manager.cc b/chromium/components/update_client/ping_manager.cc
index d82b1696a7e..ab46b493457 100644
--- a/chromium/components/update_client/ping_manager.cc
+++ b/chromium/components/update_client/ping_manager.cc
@@ -23,6 +23,7 @@
#include "components/update_client/protocol_serializer.h"
#include "components/update_client/request_sender.h"
#include "components/update_client/utils.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"
namespace update_client {
@@ -117,7 +118,8 @@ void PingSender::SendPing(const Component& component,
config_->GetProdId(), config_->GetBrowserVersion().GetString(),
config_->GetLang(), config_->GetChannel(),
config_->GetOSLongName(), config_->GetDownloadPreference(),
- config_->ExtraRequestParams(), nullptr, std::move(apps))),
+ config_->IsMachineExternallyManaged(),
+ config_->ExtraRequestParams(), {}, std::move(apps))),
false, base::BindOnce(&PingSender::SendPingComplete, this));
}
diff --git a/chromium/components/update_client/ping_manager_unittest.cc b/chromium/components/update_client/ping_manager_unittest.cc
index 8adb124f0fb..14ee2510cd6 100644
--- a/chromium/components/update_client/ping_manager_unittest.cc
+++ b/chromium/components/update_client/ping_manager_unittest.cc
@@ -6,6 +6,7 @@
#include <stdint.h>
+#include <initializer_list>
#include <limits>
#include <memory>
#include <string>
@@ -179,7 +180,7 @@ TEST_P(PingManagerTest, SendPing) {
request->FindPath({"os", "platform"})->GetString());
EXPECT_TRUE(request->FindPath({"os", "version"})->is_string());
- const auto& app = request->FindKey("app")->GetList()[0];
+ const auto& app = request->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ("abc", app.FindKey("appid")->GetString());
EXPECT_EQ("ap1", app.FindKey("ap")->GetString());
EXPECT_EQ("BRND", app.FindKey("brand")->GetString());
@@ -187,7 +188,7 @@ TEST_P(PingManagerTest, SendPing) {
EXPECT_EQ("c1", app.FindKey("cohort")->GetString());
EXPECT_EQ("cn1", app.FindKey("cohortname")->GetString());
EXPECT_EQ("ch1", app.FindKey("cohorthint")->GetString());
- const auto& event = app.FindKey("event")->GetList()[0];
+ const auto& event = app.FindKey("event")->GetListDeprecated()[0];
EXPECT_EQ(1, event.FindKey("eventresult")->GetInt());
EXPECT_EQ(3, event.FindKey("eventtype")->GetInt());
EXPECT_EQ("2.0", event.FindKey("nextversion")->GetString());
@@ -221,10 +222,10 @@ TEST_P(PingManagerTest, SendPing) {
const auto root = base::JSONReader::Read(msg);
ASSERT_TRUE(root);
const auto* request = root->FindKey("request");
- const auto& app = request->FindKey("app")->GetList()[0];
+ const auto& app = request->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ("abc", app.FindKey("appid")->GetString());
EXPECT_EQ("1.0", app.FindKey("version")->GetString());
- const auto& event = app.FindKey("event")->GetList()[0];
+ const auto& event = app.FindKey("event")->GetListDeprecated()[0];
EXPECT_EQ(0, event.FindKey("eventresult")->GetInt());
EXPECT_EQ(3, event.FindKey("eventtype")->GetInt());
EXPECT_EQ("2.0", event.FindKey("nextversion")->GetString());
@@ -261,10 +262,10 @@ TEST_P(PingManagerTest, SendPing) {
const auto root = base::JSONReader::Read(msg);
ASSERT_TRUE(root);
const auto* request = root->FindKey("request");
- const auto& app = request->FindKey("app")->GetList()[0];
+ const auto& app = request->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ("abc", app.FindKey("appid")->GetString());
EXPECT_EQ("1.0", app.FindKey("version")->GetString());
- const auto& event = app.FindKey("event")->GetList()[0];
+ const auto& event = app.FindKey("event")->GetListDeprecated()[0];
EXPECT_EQ(0, event.FindKey("eventresult")->GetInt());
EXPECT_EQ(3, event.FindKey("eventtype")->GetInt());
EXPECT_EQ("2.0", event.FindKey("nextversion")->GetString());
@@ -301,10 +302,10 @@ TEST_P(PingManagerTest, SendPing) {
const auto root = base::JSONReader::Read(msg);
ASSERT_TRUE(root);
const auto* request = root->FindKey("request");
- const auto& app = request->FindKey("app")->GetList()[0];
+ const auto& app = request->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ("abc", app.FindKey("appid")->GetString());
EXPECT_EQ("1.0", app.FindKey("version")->GetString());
- const auto& event = app.FindKey("event")->GetList()[0];
+ const auto& event = app.FindKey("event")->GetListDeprecated()[0];
EXPECT_EQ(0, event.FindKey("eventresult")->GetInt());
EXPECT_EQ(3, event.FindKey("eventtype")->GetInt());
EXPECT_EQ("1.0", event.FindKey("previousversion")->GetString());
@@ -329,10 +330,10 @@ TEST_P(PingManagerTest, SendPing) {
const auto root = base::JSONReader::Read(msg);
ASSERT_TRUE(root);
const auto* request = root->FindKey("request");
- const auto& app = request->FindKey("app")->GetList()[0];
+ const auto& app = request->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ("abc", app.FindKey("appid")->GetString());
EXPECT_EQ("1.2.3.4", app.FindKey("version")->GetString());
- const auto& event = app.FindKey("event")->GetList()[0];
+ const auto& event = app.FindKey("event")->GetListDeprecated()[0];
EXPECT_EQ(1, event.FindKey("eventresult")->GetInt());
EXPECT_EQ(4, event.FindKey("eventtype")->GetInt());
EXPECT_EQ("1.2.3.4", event.FindKey("previousversion")->GetString());
@@ -358,10 +359,10 @@ TEST_P(PingManagerTest, SendPing) {
const auto root = base::JSONReader::Read(msg);
ASSERT_TRUE(root);
const auto* request = root->FindKey("request");
- const auto& app = request->FindKey("app")->GetList()[0];
+ const auto& app = request->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ("abc", app.FindKey("appid")->GetString());
EXPECT_EQ("1.2.3.4", app.FindKey("version")->GetString());
- const auto& event = app.FindKey("event")->GetList()[0];
+ const auto& event = app.FindKey("event")->GetListDeprecated()[0];
EXPECT_EQ(1, event.FindKey("eventresult")->GetInt());
EXPECT_EQ(2, event.FindKey("eventtype")->GetInt());
EXPECT_EQ("1.2.3.4", event.FindKey("nextversion")->GetString());
@@ -414,19 +415,19 @@ TEST_P(PingManagerTest, SendPing) {
const auto root = base::JSONReader::Read(msg);
ASSERT_TRUE(root);
const auto* request = root->FindKey("request");
- const auto& app = request->FindKey("app")->GetList()[0];
+ const auto& app = request->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ("abc", app.FindKey("appid")->GetString());
EXPECT_EQ("1.0", app.FindKey("version")->GetString());
- EXPECT_EQ(4u, app.FindKey("event")->GetList().size());
+ EXPECT_EQ(4u, app.FindKey("event")->GetListDeprecated().size());
{
- const auto& event = app.FindKey("event")->GetList()[0];
+ const auto& event = app.FindKey("event")->GetListDeprecated()[0];
EXPECT_EQ(1, event.FindKey("eventresult")->GetInt());
EXPECT_EQ(3, event.FindKey("eventtype")->GetInt());
EXPECT_EQ("2.0", event.FindKey("nextversion")->GetString());
EXPECT_EQ("1.0", event.FindKey("previousversion")->GetString());
}
{
- const auto& event = app.FindKey("event")->GetList()[1];
+ const auto& event = app.FindKey("event")->GetListDeprecated()[1];
EXPECT_EQ(0, event.FindKey("eventresult")->GetInt());
EXPECT_EQ(14, event.FindKey("eventtype")->GetInt());
EXPECT_EQ(987, event.FindKey("download_time_ms")->GetDouble());
@@ -439,7 +440,7 @@ TEST_P(PingManagerTest, SendPing) {
EXPECT_EQ("http://host1/path1", event.FindKey("url")->GetString());
}
{
- const auto& event = app.FindKey("event")->GetList()[2];
+ const auto& event = app.FindKey("event")->GetListDeprecated()[2];
EXPECT_EQ(1, event.FindKey("eventresult")->GetInt());
EXPECT_EQ(14, event.FindKey("eventtype")->GetInt());
EXPECT_EQ(9870, event.FindKey("download_time_ms")->GetDouble());
@@ -451,7 +452,7 @@ TEST_P(PingManagerTest, SendPing) {
EXPECT_EQ("http://host2/path2", event.FindKey("url")->GetString());
}
{
- const auto& event = app.FindKey("event")->GetList()[3];
+ const auto& event = app.FindKey("event")->GetListDeprecated()[3];
EXPECT_EQ(1, event.FindKey("eventresult")->GetInt());
EXPECT_EQ(14, event.FindKey("eventtype")->GetInt());
EXPECT_EQ(9007199254740990,
@@ -465,6 +466,30 @@ TEST_P(PingManagerTest, SendPing) {
}
interceptor->Reset();
}
+
+ // Tests the presence of the `domain joined` in the ping request.
+ {
+ for (const auto is_managed : std::initializer_list<absl::optional<bool>>{
+ absl::nullopt, false, true}) {
+ config_->SetIsMachineExternallyManaged(is_managed);
+ EXPECT_TRUE(interceptor->ExpectRequest(std::make_unique<AnyMatch>()));
+ Component component(*update_context, "abc");
+ component.crx_component_ = CrxComponent();
+ component.previous_version_ = base::Version("1.0");
+ component.AppendEvent(component.MakeEventUpdateComplete());
+ ping_manager_->SendPing(component, *metadata_, MakePingCallback());
+
+ RunThreads();
+
+ ASSERT_EQ(interceptor->GetCount(), 1);
+ const auto root = base::JSONReader::Read(interceptor->GetRequestBody(0));
+ interceptor->Reset();
+
+ ASSERT_TRUE(root);
+ EXPECT_EQ(is_managed, root->FindBoolPath("request.domainjoined"));
+ }
+ }
+ config_->SetIsMachineExternallyManaged(absl::nullopt);
}
// Tests that sending the ping fails when the component requires encryption but
diff --git a/chromium/components/update_client/protocol_definition.cc b/chromium/components/update_client/protocol_definition.cc
index 2dd3cc6b0c8..e5b8da44ffe 100644
--- a/chromium/components/update_client/protocol_definition.cc
+++ b/chromium/components/update_client/protocol_definition.cc
@@ -12,6 +12,7 @@ namespace protocol_request {
OS::OS() = default;
OS::OS(OS&&) = default;
+OS& OS::operator=(OS&&) = default;
OS::~OS() = default;
Updater::Updater() = default;
@@ -27,10 +28,12 @@ Ping::~Ping() = default;
App::App() = default;
App::App(App&&) = default;
+App& App::operator=(App&&) = default;
App::~App() = default;
Request::Request() = default;
Request::Request(Request&&) = default;
+Request& Request::operator=(Request&&) = default;
Request::~Request() = default;
} // namespace protocol_request
diff --git a/chromium/components/update_client/protocol_definition.h b/chromium/components/update_client/protocol_definition.h
index 3fd1766c68a..d0e799ad102 100644
--- a/chromium/components/update_client/protocol_definition.h
+++ b/chromium/components/update_client/protocol_definition.h
@@ -41,12 +41,10 @@ struct HW {
struct OS {
OS();
-
OS(const OS&) = delete;
OS& operator=(const OS&) = delete;
-
OS(OS&&);
-
+ OS& operator=(OS&&);
~OS();
std::string platform;
@@ -98,12 +96,10 @@ struct Ping {
struct App {
App();
-
App(const App&) = delete;
App& operator=(const App&) = delete;
-
App(App&&);
-
+ App& operator=(App&&);
~App();
std::string app_id;
@@ -137,12 +133,10 @@ struct App {
struct Request {
Request();
-
Request(const Request&) = delete;
Request& operator=(const Request&) = delete;
-
Request(Request&&);
-
+ Request& operator=(Request&&);
~Request();
std::string protocol_version;
@@ -167,7 +161,7 @@ struct Request {
std::string arch;
std::string nacl_arch;
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
bool is_wow64 = false;
#endif
diff --git a/chromium/components/update_client/protocol_parser_json.cc b/chromium/components/update_client/protocol_parser_json.cc
index d4756ca3c49..028ca0f3a2e 100644
--- a/chromium/components/update_client/protocol_parser_json.cc
+++ b/chromium/components/update_client/protocol_parser_json.cc
@@ -66,7 +66,7 @@ bool ParseManifest(const base::Value& manifest_node,
return false;
}
- for (const auto& package : package_node->GetList()) {
+ for (const auto& package : package_node->GetListDeprecated()) {
if (!package.is_dict()) {
*error = "'package' is not a dictionary.";
return false;
@@ -113,7 +113,7 @@ void ParseActions(const base::Value& actions_node,
if (!action_node || !action_node->is_list())
return;
- const auto& action_list = action_node->GetList();
+ const auto& action_list = action_node->GetListDeprecated();
if (action_list.empty() || !action_list[0].is_dict())
return;
@@ -133,7 +133,7 @@ bool ParseUrls(const base::Value& urls_node,
return false;
}
- for (const auto& url : url_node->GetList()) {
+ for (const auto& url : url_node->GetListDeprecated()) {
if (!url.is_dict())
continue;
const auto* codebase = url.FindKey("codebase");
@@ -323,7 +323,7 @@ bool ProtocolParserJSON::DoParse(const std::string& response_json,
const auto* app_node = response_node->FindKey("app");
if (app_node && app_node->is_list()) {
- for (const auto& app : app_node->GetList()) {
+ for (const auto& app : app_node->GetListDeprecated()) {
Result result;
std::string error;
if (ParseApp(app, &result, &error))
diff --git a/chromium/components/update_client/protocol_serializer.cc b/chromium/components/update_client/protocol_serializer.cc
index aa2bdac4623..dc9bba9343b 100644
--- a/chromium/components/update_client/protocol_serializer.cc
+++ b/chromium/components/update_client/protocol_serializer.cc
@@ -23,10 +23,10 @@
#include "components/update_client/activity_data_service.h"
#include "components/update_client/persisted_data.h"
#include "components/update_client/update_query_params.h"
-#include "components/update_client/updater_state.h"
#include "components/update_client/utils.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
#include "base/win/windows_version.h"
#endif
@@ -42,7 +42,7 @@ int GetPhysicalMemoryGB() {
}
std::string GetOSVersion() {
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
const auto ver = base::win::OSInfo::GetInstance()->version_number();
return base::StringPrintf("%u.%u.%u.%u", ver.major, ver.minor, ver.build,
ver.patch);
@@ -52,7 +52,7 @@ std::string GetOSVersion() {
}
std::string GetServicePack() {
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
return base::win::OSInfo::GetInstance()->service_pack_str();
#else
return {};
@@ -105,8 +105,9 @@ protocol_request::Request MakeProtocolRequest(
const std::string& channel,
const std::string& os_long_name,
const std::string& download_preference,
+ absl::optional<bool> domain_joined,
const base::flat_map<std::string, std::string>& additional_attributes,
- const std::map<std::string, std::string>* updater_state_attributes,
+ const base::flat_map<std::string, std::string>& updater_state_attributes,
std::vector<protocol_request::App> apps) {
protocol_request::Request request;
request.protocol_version = kProtocolVersion;
@@ -129,19 +130,14 @@ protocol_request::Request MakeProtocolRequest(
request.arch = UpdateQueryParams::GetArch();
request.nacl_arch = UpdateQueryParams::GetNaclArch();
request.dlpref = download_preference;
+ request.domain_joined = domain_joined;
request.additional_attributes = additional_attributes;
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
if (base::win::OSInfo::GetInstance()->IsWowX86OnAMD64())
request.is_wow64 = true;
#endif
- if (updater_state_attributes &&
- updater_state_attributes->count(UpdaterState::kIsEnterpriseManaged)) {
- request.domain_joined =
- updater_state_attributes->at(UpdaterState::kIsEnterpriseManaged) == "1";
- }
-
// HW platform information.
base::CPU cpu;
request.hw.physmemory = GetPhysicalMemoryGB();
@@ -159,38 +155,38 @@ protocol_request::Request MakeProtocolRequest(
request.os.service_pack = GetServicePack();
request.os.arch = base::SysInfo().OperatingSystemArchitecture();
- if (updater_state_attributes) {
+ if (!updater_state_attributes.empty()) {
request.updater = absl::make_optional<protocol_request::Updater>();
- auto it = updater_state_attributes->find("name");
- if (it != updater_state_attributes->end())
+ auto it = updater_state_attributes.find("name");
+ if (it != updater_state_attributes.end())
request.updater->name = it->second;
- it = updater_state_attributes->find("version");
- if (it != updater_state_attributes->end())
+ it = updater_state_attributes.find("version");
+ if (it != updater_state_attributes.end())
request.updater->version = it->second;
- it = updater_state_attributes->find("ismachine");
- if (it != updater_state_attributes->end()) {
+ it = updater_state_attributes.find("ismachine");
+ if (it != updater_state_attributes.end()) {
DCHECK(it->second == "0" || it->second == "1");
request.updater->is_machine = it->second != "0";
}
- it = updater_state_attributes->find("autoupdatecheckenabled");
- if (it != updater_state_attributes->end()) {
+ it = updater_state_attributes.find("autoupdatecheckenabled");
+ if (it != updater_state_attributes.end()) {
DCHECK(it->second == "0" || it->second == "1");
request.updater->autoupdate_check_enabled = it->second != "0";
}
- it = updater_state_attributes->find("laststarted");
- if (it != updater_state_attributes->end()) {
+ it = updater_state_attributes.find("laststarted");
+ if (it != updater_state_attributes.end()) {
int last_started = 0;
if (base::StringToInt(it->second, &last_started))
request.updater->last_started = last_started;
}
- it = updater_state_attributes->find("lastchecked");
- if (it != updater_state_attributes->end()) {
+ it = updater_state_attributes.find("lastchecked");
+ if (it != updater_state_attributes.end()) {
int last_checked = 0;
if (base::StringToInt(it->second, &last_checked))
request.updater->last_checked = last_checked;
}
- it = updater_state_attributes->find("updatepolicy");
- if (it != updater_state_attributes->end()) {
+ it = updater_state_attributes.find("updatepolicy");
+ if (it != updater_state_attributes.end()) {
int update_policy = 0;
if (base::StringToInt(it->second, &update_policy))
request.updater->update_policy = update_policy;
diff --git a/chromium/components/update_client/protocol_serializer.h b/chromium/components/update_client/protocol_serializer.h
index 8e583adcbc7..89f87667016 100644
--- a/chromium/components/update_client/protocol_serializer.h
+++ b/chromium/components/update_client/protocol_serializer.h
@@ -42,8 +42,9 @@ protocol_request::Request MakeProtocolRequest(
const std::string& channel,
const std::string& os_long_name,
const std::string& download_preference,
+ absl::optional<bool> domain_joined,
const base::flat_map<std::string, std::string>& additional_attributes,
- const std::map<std::string, std::string>* updater_state_attributes,
+ const base::flat_map<std::string, std::string>& updater_state_attributes,
std::vector<protocol_request::App> apps);
protocol_request::App MakeProtocolApp(
diff --git a/chromium/components/update_client/protocol_serializer_fuzzer.cc b/chromium/components/update_client/protocol_serializer_fuzzer.cc
index 232e719a1ca..bfca2b6ec98 100644
--- a/chromium/components/update_client/protocol_serializer_fuzzer.cc
+++ b/chromium/components/update_client/protocol_serializer_fuzzer.cc
@@ -5,13 +5,21 @@
#include <stddef.h>
#include <stdint.h>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
#include <fuzzer/FuzzedDataProvider.h>
+#include "base/check.h"
#include "base/command_line.h"
+#include "base/containers/flat_map.h"
#include "base/json/json_reader.h"
#include "base/strings/string_util.h"
#include "components/update_client/protocol_handler.h"
#include "components/update_client/protocol_serializer.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
struct Environment {
Environment() { CHECK(base::CommandLine::Init(0, nullptr)); }
@@ -23,7 +31,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// Independently, try serializing a Request.
base::flat_map<std::string, std::string> additional_attributes;
- std::map<std::string, std::string> updater_state_attributes;
std::vector<protocol_request::App> apps;
// Share |data| between |MakeProtocolRequest| args
@@ -39,8 +46,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
GetUtf8String() /* prod_id */, GetUtf8String() /* browser_version */,
GetUtf8String() /* lang */, GetUtf8String() /* channel */,
GetUtf8String() /* os_long_name */,
- GetUtf8String() /* download_preference */, additional_attributes,
- &updater_state_attributes, std::move(apps));
+ GetUtf8String() /* download_preference */,
+ absl::nullopt /* domain_joined */, additional_attributes,
+ {} /*updater_state_attributes*/, std::move(apps));
update_client::ProtocolHandlerFactoryJSON factory;
std::unique_ptr<ProtocolSerializer> serializer = factory.CreateSerializer();
diff --git a/chromium/components/update_client/protocol_serializer_json.cc b/chromium/components/update_client/protocol_serializer_json.cc
index 06a7e43cb17..38a6a8de7d5 100644
--- a/chromium/components/update_client/protocol_serializer_json.cc
+++ b/chromium/components/update_client/protocol_serializer_json.cc
@@ -12,7 +12,6 @@
#include "base/values.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
-#include "components/update_client/updater_state.h"
namespace update_client {
@@ -40,10 +39,10 @@ std::string ProtocolSerializerJSON::Serialize(
request_node->SetKey("@os", Value(request.operating_system));
request_node->SetKey("arch", Value(request.arch));
request_node->SetKey("nacl_arch", Value(request.nacl_arch));
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
if (request.is_wow64)
request_node->SetKey("wow64", Value(request.is_wow64));
-#endif // OS_WIN
+#endif // BUILDFLAG(IS_WIN)
if (!request.updaterchannel.empty())
request_node->SetKey("updaterchannel", Value(request.updaterchannel));
if (!request.prodchannel.empty())
@@ -51,8 +50,7 @@ std::string ProtocolSerializerJSON::Serialize(
if (!request.dlpref.empty())
request_node->SetKey("dlpref", Value(request.dlpref));
if (request.domain_joined) {
- request_node->SetKey(UpdaterState::kIsEnterpriseManaged,
- Value(*request.domain_joined));
+ request_node->SetKey("domainjoined", Value(*request.domain_joined));
}
// HW platform information.
diff --git a/chromium/components/update_client/protocol_serializer_json_unittest.cc b/chromium/components/update_client/protocol_serializer_json_unittest.cc
index 1d6691c505f..1f5747799ff 100644
--- a/chromium/components/update_client/protocol_serializer_json_unittest.cc
+++ b/chromium/components/update_client/protocol_serializer_json_unittest.cc
@@ -18,7 +18,6 @@
#include "components/update_client/protocol_definition.h"
#include "components/update_client/protocol_serializer.h"
#include "components/update_client/test_activity_data_service.h"
-#include "components/update_client/updater_state.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/re2/src/re2/re2.h"
@@ -58,8 +57,8 @@ TEST(SerializeRequestJSON, Serialize) {
const auto request = std::make_unique<ProtocolSerializerJSON>()->Serialize(
MakeProtocolRequest(false, "{15160585-8ADE-4D3C-839B-1281A6035D1F}",
"prod_id", "1.0", "lang", "channel", "OS",
- "cacheable", {{"extra", "params"}}, nullptr,
- std::move(apps)));
+ "cacheable", absl::nullopt, {{"extra", "params"}},
+ {}, std::move(apps)));
constexpr char regex[] =
R"({"request":{"@os":"\w+","@updater":"prod_id",)"
R"("acceptformat":"crx3",)"
@@ -97,7 +96,8 @@ TEST(SerializeRequestJSON, Serialize) {
const auto request = std::make_unique<ProtocolSerializerJSON>()->Serialize(
MakeProtocolRequest(false, "{15160585-8ADE-4D3C-839B-1281A6035D1F}", "",
- "", "", "", "", "", {}, nullptr, std::move(apps)));
+ "", "", "", "", "", absl::nullopt, {}, {},
+ std::move(apps)));
constexpr char regex[] =
R"("app":\[{"appid":"id1","enabled":true,)"
@@ -113,13 +113,13 @@ TEST(SerializeRequestJSON, DownloadPreference) {
const auto serializer = std::make_unique<ProtocolSerializerJSON>();
auto request = serializer->Serialize(
MakeProtocolRequest(false, "{15160585-8ADE-4D3C-839B-1281A6035D1F}", "",
- "", "", "", "", "", {}, nullptr, {}));
+ "", "", "", "", "", absl::nullopt, {}, {}, {}));
EXPECT_FALSE(RE2::PartialMatch(request, R"("dlpref":)")) << request;
// Verifies that |download_preference| is serialized.
- request = serializer->Serialize(
- MakeProtocolRequest(false, "{15160585-8ADE-4D3C-839B-1281A6035D1F}", "",
- "", "", "", "", "cacheable", {}, nullptr, {}));
+ request = serializer->Serialize(MakeProtocolRequest(
+ false, "{15160585-8ADE-4D3C-839B-1281A6035D1F}", "", "", "", "", "",
+ "cacheable", absl::nullopt, {}, {}, {}));
EXPECT_TRUE(RE2::PartialMatch(request, R"("dlpref":"cacheable")")) << request;
}
@@ -128,18 +128,18 @@ TEST(SerializeRequestJSON, DownloadPreference) {
TEST(SerializeRequestJSON, UpdaterStateAttributes) {
base::test::TaskEnvironment env;
const auto serializer = std::make_unique<ProtocolSerializerJSON>();
- UpdaterState::Attributes attributes;
- attributes["ismachine"] = "1";
- attributes["domainjoined"] = "1";
- attributes["name"] = "Omaha";
- attributes["version"] = "1.2.3.4";
- attributes["laststarted"] = "1";
- attributes["lastchecked"] = "2";
- attributes["autoupdatecheckenabled"] = "0";
- attributes["updatepolicy"] = "-1";
+
const auto request = serializer->Serialize(MakeProtocolRequest(
true, "{15160585-8ADE-4D3C-839B-1281A6035D1F}", "prod_id", "1.0", "lang",
- "channel", "OS", "cacheable", {{"extra", "params"}}, &attributes, {}));
+ "channel", "OS", "cacheable", true, {{"extra", "params"}},
+ {{"ismachine", "1"},
+ {"name", "Omaha"},
+ {"version", "1.2.3.4"},
+ {"laststarted", "1"},
+ {"lastchecked", "2"},
+ {"autoupdatecheckenabled", "0"},
+ {"updatepolicy", "-1"}},
+ {}));
constexpr char regex[] =
R"({"request":{"@os":"\w+","@updater":"prod_id",)"
R"("acceptformat":"crx3","arch":"\w+","dedup":"cr",)"
@@ -162,4 +162,24 @@ TEST(SerializeRequestJSON, UpdaterStateAttributes) {
EXPECT_TRUE(RE2::FullMatch(request, regex)) << request << "\n VS \n" << regex;
}
+TEST(SerializeRequestJSON, DomainJoined) {
+ base::test::TaskEnvironment env;
+
+ const auto serializer = std::make_unique<ProtocolSerializerJSON>();
+ std::string request = serializer->Serialize(
+ MakeProtocolRequest(false, "{15160585-8ADE-4D3C-839B-1281A6035D1F}", "",
+ "", "", "", "", "", absl::nullopt, {}, {}, {}));
+ EXPECT_FALSE(RE2::PartialMatch(request, R"("domainjoined")")) << request;
+
+ request = serializer->Serialize(
+ MakeProtocolRequest(false, "{15160585-8ADE-4D3C-839B-1281A6035D1F}", "",
+ "", "", "", "", "", true, {}, {}, {}));
+ EXPECT_TRUE(RE2::PartialMatch(request, R"("domainjoined":true)")) << request;
+
+ request = serializer->Serialize(
+ MakeProtocolRequest(false, "{15160585-8ADE-4D3C-839B-1281A6035D1F}", "",
+ "", "", "", "", "", false, {}, {}, {}));
+ EXPECT_TRUE(RE2::PartialMatch(request, R"("domainjoined":false)")) << request;
+}
+
} // namespace update_client
diff --git a/chromium/components/update_client/test_configurator.cc b/chromium/components/update_client/test_configurator.cc
index 7c7ee09f540..dfddc4cd73e 100644
--- a/chromium/components/update_client/test_configurator.cc
+++ b/chromium/components/update_client/test_configurator.cc
@@ -4,8 +4,11 @@
#include "components/update_client/test_configurator.h"
+#include <string>
#include <utility>
+#include "base/bind.h"
+#include "base/containers/flat_map.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/version.h"
#include "components/prefs/pref_service.h"
@@ -20,6 +23,7 @@
#include "components/update_client/unzip/unzip_impl.h"
#include "components/update_client/unzipper.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"
namespace update_client {
@@ -48,7 +52,9 @@ TestConfigurator::TestConfigurator(PrefService* pref_service)
network_fetcher_factory_(
base::MakeRefCounted<NetworkFetcherChromiumFactory>(
test_shared_loader_factory_,
- base::BindRepeating([](const GURL& url) { return false; }))) {}
+ base::BindRepeating([](const GURL& url) { return false; }))),
+ updater_state_provider_(base::BindRepeating(
+ [](bool /*is_machine*/) { return UpdaterStateAttributes(); })) {}
TestConfigurator::~TestConfigurator() = default;
@@ -142,6 +148,31 @@ bool TestConfigurator::EnabledCupSigning() const {
return enabled_cup_signing_;
}
+PrefService* TestConfigurator::GetPrefService() const {
+ return pref_service_;
+}
+
+ActivityDataService* TestConfigurator::GetActivityDataService() const {
+ return nullptr;
+}
+
+bool TestConfigurator::IsPerUserInstall() const {
+ return true;
+}
+
+std::unique_ptr<ProtocolHandlerFactory>
+TestConfigurator::GetProtocolHandlerFactory() const {
+ return std::make_unique<ProtocolHandlerFactoryJSON>();
+}
+
+absl::optional<bool> TestConfigurator::IsMachineExternallyManaged() const {
+ return is_machine_externally_managed_;
+}
+
+UpdaterStateProvider TestConfigurator::GetUpdaterStateProvider() const {
+ return updater_state_provider_;
+}
+
void TestConfigurator::SetOnDemandTime(int seconds) {
ondemand_time_ = seconds;
}
@@ -172,21 +203,14 @@ void TestConfigurator::SetCrxDownloaderFactory(
crx_downloader_factory_ = crx_downloader_factory;
}
-PrefService* TestConfigurator::GetPrefService() const {
- return pref_service_;
+void TestConfigurator::SetIsMachineExternallyManaged(
+ absl::optional<bool> is_machine_externally_managed) {
+ is_machine_externally_managed_ = is_machine_externally_managed;
}
-ActivityDataService* TestConfigurator::GetActivityDataService() const {
- return nullptr;
-}
-
-bool TestConfigurator::IsPerUserInstall() const {
- return true;
-}
-
-std::unique_ptr<ProtocolHandlerFactory>
-TestConfigurator::GetProtocolHandlerFactory() const {
- return std::make_unique<ProtocolHandlerFactoryJSON>();
+void TestConfigurator::SetUpdaterStateProvider(
+ UpdaterStateProvider update_state_provider) {
+ updater_state_provider_ = update_state_provider;
}
} // namespace update_client
diff --git a/chromium/components/update_client/test_configurator.h b/chromium/components/update_client/test_configurator.h
index 7f4b1b0fd29..d19fa702256 100644
--- a/chromium/components/update_client/test_configurator.h
+++ b/chromium/components/update_client/test_configurator.h
@@ -17,6 +17,7 @@
#include "base/memory/ref_counted.h"
#include "components/update_client/configurator.h"
#include "services/network/test/test_url_loader_factory.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"
class PrefService;
@@ -100,6 +101,8 @@ class TestConfigurator : public Configurator {
bool IsPerUserInstall() const override;
std::unique_ptr<ProtocolHandlerFactory> GetProtocolHandlerFactory()
const override;
+ absl::optional<bool> IsMachineExternallyManaged() const override;
+ UpdaterStateProvider GetUpdaterStateProvider() const override;
void SetOnDemandTime(int seconds);
void SetInitialDelay(double seconds);
@@ -109,7 +112,9 @@ class TestConfigurator : public Configurator {
void SetPingUrl(const GURL& url);
void SetCrxDownloaderFactory(
scoped_refptr<CrxDownloaderFactory> crx_downloader_factory);
-
+ void SetIsMachineExternallyManaged(
+ absl::optional<bool> is_machine_externally_managed);
+ void SetUpdaterStateProvider(UpdaterStateProvider update_state_provider);
network::TestURLLoaderFactory* test_url_loader_factory() {
return &test_url_loader_factory_;
}
@@ -135,6 +140,9 @@ class TestConfigurator : public Configurator {
network::TestURLLoaderFactory test_url_loader_factory_;
scoped_refptr<NetworkFetcherFactory> network_fetcher_factory_;
scoped_refptr<CrxDownloaderFactory> crx_downloader_factory_;
+ UpdaterStateProvider updater_state_provider_;
+
+ absl::optional<bool> is_machine_externally_managed_;
};
} // namespace update_client
diff --git a/chromium/components/update_client/update_checker.cc b/chromium/components/update_client/update_checker.cc
index a7e6e5e9b96..6cd9f5c7722 100644
--- a/chromium/components/update_client/update_checker.cc
+++ b/chromium/components/update_client/update_checker.cc
@@ -15,6 +15,7 @@
#include "base/bind.h"
#include "base/callback.h"
+#include "base/containers/flat_map.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
@@ -32,7 +33,6 @@
#include "components/update_client/request_sender.h"
#include "components/update_client/task_traits.h"
#include "components/update_client/update_client.h"
-#include "components/update_client/updater_state.h"
#include "components/update_client/utils.h"
#include "url/gurl.h"
@@ -70,11 +70,12 @@ class UpdateCheckerImpl : public UpdateChecker {
UpdateCheckCallback update_check_callback) override;
private:
- void ReadUpdaterStateAttributes();
+ UpdaterStateAttributes ReadUpdaterStateAttributes() const;
void CheckForUpdatesHelper(
const std::string& session_id,
const IdToComponentPtrMap& components,
const base::flat_map<std::string, std::string>& additional_attributes,
+ const UpdaterStateAttributes& updater_state_attributes,
const std::set<std::string>& active_ids);
void OnRequestSenderComplete(int error,
const std::string& response,
@@ -91,7 +92,6 @@ class UpdateCheckerImpl : public UpdateChecker {
raw_ptr<PersistedData> metadata_ = nullptr;
std::vector<std::string> ids_checked_;
UpdateCheckCallback update_check_callback_;
- std::unique_ptr<UpdaterState::Attributes> updater_state_attributes_;
std::unique_ptr<RequestSender> request_sender_;
};
@@ -114,40 +114,45 @@ void UpdateCheckerImpl::CheckForUpdates(
ids_checked_ = ids_checked;
update_check_callback_ = std::move(update_check_callback);
- base::ThreadPool::PostTaskAndReply(
+ auto check_for_updates_invoker = base::BindOnce(
+ &UpdateCheckerImpl::CheckForUpdatesHelper, base::Unretained(this),
+ session_id, std::cref(components), additional_attributes);
+
+ base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE, kTaskTraits,
base::BindOnce(&UpdateCheckerImpl::ReadUpdaterStateAttributes,
base::Unretained(this)),
base::BindOnce(
- [](base::OnceCallback<void(const std::set<std::string>&)>
- checkForUpdatesHelper,
- PersistedData* metadata, std::vector<std::string> ids) {
- metadata->GetActiveBits(ids, std::move(checkForUpdatesHelper));
+ [](base::OnceCallback<void(const UpdaterStateAttributes&,
+ const std::set<std::string>&)>
+ check_for_updates_invoker,
+ PersistedData* metadata, std::vector<std::string> ids,
+ const UpdaterStateAttributes& updater_state_attributes) {
+ metadata->GetActiveBits(
+ ids, base::BindOnce(std::move(check_for_updates_invoker),
+ updater_state_attributes));
},
- base::BindOnce(&UpdateCheckerImpl::CheckForUpdatesHelper,
- base::Unretained(this), session_id,
- std::cref(components), additional_attributes),
- base::Unretained(metadata_), ids_checked));
+ std::move(check_for_updates_invoker), base::Unretained(metadata_),
+ ids_checked));
}
// This function runs on the blocking pool task runner.
-void UpdateCheckerImpl::ReadUpdaterStateAttributes() {
-#if defined(OS_WIN)
+UpdaterStateAttributes UpdateCheckerImpl::ReadUpdaterStateAttributes() const {
+#if BUILDFLAG(IS_WIN)
// On Windows, the Chrome and the updater install modes are matched by design.
- updater_state_attributes_ =
- UpdaterState::GetState(!config_->IsPerUserInstall());
-#elif defined(OS_MAC)
- // MacOS ignores this value in the current implementation but this may change.
- updater_state_attributes_ = UpdaterState::GetState(false);
+ return config_->GetUpdaterStateProvider().Run(!config_->IsPerUserInstall());
+#elif BUILDFLAG(IS_MAC)
+ return config_->GetUpdaterStateProvider().Run(false);
#else
-// Other platforms don't have updaters.
-#endif // OS_WIN
+ return {};
+#endif // BUILDFLAG(IS_WIN)
}
void UpdateCheckerImpl::CheckForUpdatesHelper(
const std::string& session_id,
const IdToComponentPtrMap& components,
const base::flat_map<std::string, std::string>& additional_attributes,
+ const UpdaterStateAttributes& updater_state_attributes,
const std::set<std::string>& active_ids) {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -200,8 +205,8 @@ void UpdateCheckerImpl::CheckForUpdatesHelper(
!config_->IsPerUserInstall(), session_id, config_->GetProdId(),
config_->GetBrowserVersion().GetString(), config_->GetLang(),
config_->GetChannel(), config_->GetOSLongName(),
- config_->GetDownloadPreference(), additional_attributes,
- updater_state_attributes_.get(), std::move(apps));
+ config_->GetDownloadPreference(), config_->IsMachineExternallyManaged(),
+ additional_attributes, updater_state_attributes, std::move(apps));
request_sender_ = std::make_unique<RequestSender>(config_);
request_sender_->Send(
diff --git a/chromium/components/update_client/update_checker_unittest.cc b/chromium/components/update_client/update_checker_unittest.cc
index a52d1eb6dea..8e7d4bb8005 100644
--- a/chromium/components/update_client/update_checker_unittest.cc
+++ b/chromium/components/update_client/update_checker_unittest.cc
@@ -4,8 +4,10 @@
#include "components/update_client/update_checker.h"
+#include <initializer_list>
#include <map>
#include <memory>
+#include <string>
#include <tuple>
#include <utility>
#include <vector>
@@ -210,6 +212,14 @@ TEST_P(UpdateCheckerTest, UpdateCheckSuccess) {
std::make_unique<PartialMatch>("updatecheck"),
test_file("updatecheck_reply_1.json")));
+ config_->SetIsMachineExternallyManaged(true);
+ config_->SetUpdaterStateProvider(base::BindRepeating([](bool /*is_machine*/) {
+ return UpdaterStateAttributes{{"name", "Omaha"},
+ {"ismachine", "1"},
+ {"autoupdatecheckenabled", "1"},
+ {"updatepolicy", "1"}};
+ }));
+
update_checker_ = UpdateChecker::Create(config_, metadata_.get());
IdToComponentPtrMap components;
@@ -255,6 +265,7 @@ TEST_P(UpdateCheckerTest, UpdateCheckSuccess) {
EXPECT_EQ("fake_channel_string",
request->FindKey("updaterchannel")->GetString());
EXPECT_EQ("30.0", request->FindKey("updaterversion")->GetString());
+ EXPECT_TRUE(request->FindKey("domainjoined")->GetBool());
// No "dlpref" is sent by default.
EXPECT_FALSE(request->FindKey("dlpref"));
@@ -264,7 +275,7 @@ TEST_P(UpdateCheckerTest, UpdateCheckSuccess) {
request->FindPath({"os", "platform"})->GetString());
EXPECT_TRUE(request->FindPath({"os", "version"})->is_string());
- const auto& app = request->FindKey("app")->GetList()[0];
+ const auto& app = request->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ(kUpdateItemId, app.FindKey("appid")->GetString());
EXPECT_EQ("0.9", app.FindKey("version")->GetString());
EXPECT_EQ("TEST", app.FindKey("brand")->GetString());
@@ -276,12 +287,10 @@ TEST_P(UpdateCheckerTest, UpdateCheckSuccess) {
EXPECT_TRUE(app.FindKey("ping"));
EXPECT_EQ(-2, app.FindPath({"ping", "r"})->GetInt());
EXPECT_EQ("fp1", app.FindPath({"packages", "package"})
- ->GetList()[0]
+ ->GetListDeprecated()[0]
.FindKey("fp")
->GetString());
-
-#if defined(OS_WIN)
- EXPECT_TRUE(request->FindKey("domainjoined"));
+#if BUILDFLAG(IS_WIN)
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
const auto* updater = request->FindKey("updater");
EXPECT_TRUE(updater);
@@ -290,7 +299,7 @@ TEST_P(UpdateCheckerTest, UpdateCheckSuccess) {
EXPECT_TRUE(updater->FindKey("ismachine")->is_bool());
EXPECT_TRUE(updater->FindKey("updatepolicy")->is_int());
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
-#endif // OS_WIN
+#endif // IS_WIN
// Sanity check the arguments of the callback after parsing.
EXPECT_EQ(ErrorCategory::kNone, error_category_);
@@ -346,7 +355,8 @@ TEST_P(UpdateCheckerTest, UpdateCheckInvalidAp) {
const auto request = post_interceptor_->GetRequestBody(0);
const auto root = base::JSONReader::Read(request);
ASSERT_TRUE(root);
- const auto& app = root->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app =
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ(kUpdateItemId, app.FindKey("appid")->GetString());
EXPECT_EQ("0.9", app.FindKey("version")->GetString());
EXPECT_EQ("TEST", app.FindKey("brand")->GetString());
@@ -358,7 +368,7 @@ TEST_P(UpdateCheckerTest, UpdateCheckInvalidAp) {
EXPECT_TRUE(app.FindKey("ping"));
EXPECT_EQ(-2, app.FindPath({"ping", "r"})->GetInt());
EXPECT_EQ("fp1", app.FindPath({"packages", "package"})
- ->GetList()[0]
+ ->GetListDeprecated()[0]
.FindKey("fp")
->GetString());
}
@@ -384,7 +394,8 @@ TEST_P(UpdateCheckerTest, UpdateCheckSuccessNoBrand) {
const auto root = base::JSONReader::Read(request);
ASSERT_TRUE(root);
- const auto& app = root->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app =
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ(kUpdateItemId, app.FindKey("appid")->GetString());
EXPECT_EQ("0.9", app.FindKey("version")->GetString());
EXPECT_FALSE(app.FindKey("brand"));
@@ -395,7 +406,7 @@ TEST_P(UpdateCheckerTest, UpdateCheckSuccessNoBrand) {
EXPECT_TRUE(app.FindKey("ping"));
EXPECT_EQ(-2, app.FindPath({"ping", "r"})->GetInt());
EXPECT_EQ("fp1", app.FindPath({"packages", "package"})
- ->GetList()[0]
+ ->GetListDeprecated()[0]
.FindKey("fp")
->GetString());
}
@@ -483,7 +494,8 @@ TEST_P(UpdateCheckerTest, UpdateCheckCupError) {
const auto& request = post_interceptor_->GetRequestBody(0);
const auto root = base::JSONReader::Read(request);
ASSERT_TRUE(root);
- const auto& app = root->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app =
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ(kUpdateItemId, app.FindKey("appid")->GetString());
EXPECT_EQ("0.9", app.FindKey("version")->GetString());
EXPECT_EQ("TEST", app.FindKey("brand")->GetString());
@@ -494,7 +506,7 @@ TEST_P(UpdateCheckerTest, UpdateCheckCupError) {
EXPECT_TRUE(app.FindKey("ping"));
EXPECT_EQ(-2, app.FindPath({"ping", "r"})->GetInt());
EXPECT_EQ("fp1", app.FindPath({"packages", "package"})
- ->GetList()[0]
+ ->GetListDeprecated()[0]
.FindKey("fp")
->GetString());
@@ -567,12 +579,14 @@ TEST_P(UpdateCheckerTest, UpdateCheckLastRollCall) {
const auto root1 =
base::JSONReader::Read(post_interceptor_->GetRequestBody(0));
ASSERT_TRUE(root1);
- const auto& app1 = root1->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app1 =
+ root1->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ(5, app1.FindPath({"ping", "r"})->GetInt());
const auto root2 =
base::JSONReader::Read(post_interceptor_->GetRequestBody(1));
ASSERT_TRUE(root2);
- const auto& app2 = root2->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app2 =
+ root2->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ(3383, app2.FindPath({"ping", "rd"})->GetInt());
EXPECT_TRUE(app2.FindPath({"ping", "ping_freshness"})->is_string());
}
@@ -634,7 +648,8 @@ TEST_P(UpdateCheckerTest, UpdateCheckLastActive) {
const auto root =
base::JSONReader::Read(post_interceptor_->GetRequestBody(0));
ASSERT_TRUE(root);
- const auto& app = root->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app =
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ(10, app.FindPath({"ping", "a"})->GetInt());
EXPECT_EQ(-2, app.FindPath({"ping", "r"})->GetInt());
}
@@ -642,7 +657,8 @@ TEST_P(UpdateCheckerTest, UpdateCheckLastActive) {
const auto root =
base::JSONReader::Read(post_interceptor_->GetRequestBody(1));
ASSERT_TRUE(root);
- const auto& app = root->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app =
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ(3383, app.FindPath({"ping", "ad"})->GetInt());
EXPECT_EQ(3383, app.FindPath({"ping", "rd"})->GetInt());
EXPECT_TRUE(app.FindPath({"ping", "ping_freshness"})->is_string());
@@ -651,7 +667,8 @@ TEST_P(UpdateCheckerTest, UpdateCheckLastActive) {
const auto root =
base::JSONReader::Read(post_interceptor_->GetRequestBody(2));
ASSERT_TRUE(root);
- const auto& app = root->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app =
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ(3383, app.FindPath({"ping", "rd"})->GetInt());
EXPECT_TRUE(app.FindPath({"ping", "ping_freshness"})->is_string());
}
@@ -682,7 +699,7 @@ TEST_P(UpdateCheckerTest, UpdateCheckInstallSource) {
const auto root = base::JSONReader::Read(request);
ASSERT_TRUE(root);
const auto& app =
- root->FindKey("request")->FindKey("app")->GetList()[0];
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ("ondemand", app.FindKey("installsource")->GetString());
EXPECT_FALSE(app.FindKey("installedby"));
}
@@ -704,7 +721,7 @@ TEST_P(UpdateCheckerTest, UpdateCheckInstallSource) {
const auto root = base::JSONReader::Read(request);
ASSERT_TRUE(root);
const auto& app =
- root->FindKey("request")->FindKey("app")->GetList()[0];
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ("sideload", app.FindKey("installsource")->GetString());
EXPECT_EQ("policy", app.FindKey("installedby")->GetString());
}
@@ -726,7 +743,8 @@ TEST_P(UpdateCheckerTest, UpdateCheckInstallSource) {
const auto& request = post_interceptor->GetRequestBody(0);
const auto root = base::JSONReader::Read(request);
ASSERT_TRUE(root);
- const auto& app = root->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app =
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_FALSE(app.FindKey("installsource"));
}
{
@@ -746,7 +764,8 @@ TEST_P(UpdateCheckerTest, UpdateCheckInstallSource) {
const auto& request = post_interceptor->GetRequestBody(0);
const auto root = base::JSONReader::Read(request);
ASSERT_TRUE(root);
- const auto& app = root->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app =
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ("webstore", app.FindKey("installsource")->GetString());
EXPECT_EQ("external", app.FindKey("installedby")->GetString());
}
@@ -775,7 +794,8 @@ TEST_P(UpdateCheckerTest, ComponentDisabled) {
const auto& request = post_interceptor->GetRequestBody(0);
const auto root = base::JSONReader::Read(request);
ASSERT_TRUE(root);
- const auto& app = root->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app =
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ(true, app.FindKey("enabled")->GetBool());
EXPECT_FALSE(app.FindKey("disabled"));
}
@@ -796,7 +816,8 @@ TEST_P(UpdateCheckerTest, ComponentDisabled) {
const auto& request = post_interceptor->GetRequestBody(0);
const auto root = base::JSONReader::Read(request);
ASSERT_TRUE(root);
- const auto& app = root->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app =
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ(true, app.FindKey("enabled")->GetBool());
EXPECT_FALSE(app.FindKey("disabled"));
}
@@ -817,9 +838,10 @@ TEST_P(UpdateCheckerTest, ComponentDisabled) {
const auto& request = post_interceptor->GetRequestBody(0);
const auto root = base::JSONReader::Read(request);
ASSERT_TRUE(root);
- const auto& app = root->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app =
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ(false, app.FindKey("enabled")->GetBool());
- const auto& disabled = app.FindKey("disabled")->GetList();
+ const auto& disabled = app.FindKey("disabled")->GetListDeprecated();
EXPECT_EQ(1u, disabled.size());
EXPECT_EQ(0, disabled[0].FindKey("reason")->GetInt());
}
@@ -839,9 +861,10 @@ TEST_P(UpdateCheckerTest, ComponentDisabled) {
const auto& request = post_interceptor->GetRequestBody(0);
const auto root = base::JSONReader::Read(request);
ASSERT_TRUE(root);
- const auto& app = root->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app =
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ(false, app.FindKey("enabled")->GetBool());
- const auto& disabled = app.FindKey("disabled")->GetList();
+ const auto& disabled = app.FindKey("disabled")->GetListDeprecated();
EXPECT_EQ(1u, disabled.size());
EXPECT_EQ(1, disabled[0].FindKey("reason")->GetInt());
}
@@ -862,9 +885,10 @@ TEST_P(UpdateCheckerTest, ComponentDisabled) {
const auto& request = post_interceptor->GetRequestBody(0);
const auto root = base::JSONReader::Read(request);
ASSERT_TRUE(root);
- const auto& app = root->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app =
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ(false, app.FindKey("enabled")->GetBool());
- const auto& disabled = app.FindKey("disabled")->GetList();
+ const auto& disabled = app.FindKey("disabled")->GetListDeprecated();
EXPECT_EQ(3u, disabled.size());
EXPECT_EQ(4, disabled[0].FindKey("reason")->GetInt());
EXPECT_EQ(8, disabled[1].FindKey("reason")->GetInt());
@@ -887,9 +911,10 @@ TEST_P(UpdateCheckerTest, ComponentDisabled) {
const auto& request = post_interceptor->GetRequestBody(0);
const auto root = base::JSONReader::Read(request);
ASSERT_TRUE(root);
- const auto& app = root->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app =
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ(false, app.FindKey("enabled")->GetBool());
- const auto& disabled = app.FindKey("disabled")->GetList();
+ const auto& disabled = app.FindKey("disabled")->GetListDeprecated();
EXPECT_EQ(4u, disabled.size());
EXPECT_EQ(0, disabled[0].FindKey("reason")->GetInt());
EXPECT_EQ(4, disabled[1].FindKey("reason")->GetInt());
@@ -927,7 +952,8 @@ TEST_P(UpdateCheckerTest, UpdateCheckUpdateDisabled) {
const auto& request = post_interceptor->GetRequestBody(0);
const auto root = base::JSONReader::Read(request);
ASSERT_TRUE(root);
- const auto& app = root->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app =
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ(kUpdateItemId, app.FindKey("appid")->GetString());
EXPECT_EQ("0.9", app.FindKey("version")->GetString());
EXPECT_EQ(true, app.FindKey("enabled")->GetBool());
@@ -952,7 +978,8 @@ TEST_P(UpdateCheckerTest, UpdateCheckUpdateDisabled) {
const auto& request = post_interceptor->GetRequestBody(0);
const auto root = base::JSONReader::Read(request);
ASSERT_TRUE(root);
- const auto& app = root->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app =
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ(kUpdateItemId, app.FindKey("appid")->GetString());
EXPECT_EQ("0.9", app.FindKey("version")->GetString());
EXPECT_EQ(true, app.FindKey("enabled")->GetBool());
@@ -985,7 +1012,7 @@ TEST_P(UpdateCheckerTest, SameVersionUpdateAllowed) {
const auto& request = post_interceptor->GetRequestBody(0);
const auto root = base::JSONReader::Read(request);
ASSERT_TRUE(root);
- const auto& app = root->FindPath("request.app")->GetList()[0];
+ const auto& app = root->FindPath("request.app")->GetListDeprecated()[0];
EXPECT_STREQ(kUpdateItemId, app.FindStringPath("appid")->c_str());
EXPECT_TRUE(app.FindDictKey("updatecheck"));
EXPECT_FALSE(app.FindPath("updatecheck.sameversionupdate"));
@@ -1008,11 +1035,12 @@ TEST_P(UpdateCheckerTest, SameVersionUpdateAllowed) {
const auto& request = post_interceptor->GetRequestBody(0);
const auto root = base::JSONReader::Read(request);
ASSERT_TRUE(root);
- const auto& app = root->FindPath("request.app")->GetList()[0];
+ const auto& app = root->FindPath("request.app")->GetListDeprecated()[0];
EXPECT_STREQ(kUpdateItemId, app.FindStringPath("appid")->c_str());
EXPECT_EQ(app.FindBoolPath("updatecheck.sameversionupdate").value(), true);
}
}
+
TEST_P(UpdateCheckerTest, NoUpdateActionRun) {
EXPECT_TRUE(post_interceptor_->ExpectRequest(
std::make_unique<PartialMatch>("updatecheck"),
@@ -1072,7 +1100,8 @@ TEST_P(UpdateCheckerTest, UpdatePauseResume) {
const auto& request = post_interceptor_->GetRequestBody(0);
const auto root = base::JSONReader::Read(request);
ASSERT_TRUE(root);
- const auto& app = root->FindKey("request")->FindKey("app")->GetList()[0];
+ const auto& app =
+ root->FindKey("request")->FindKey("app")->GetListDeprecated()[0];
EXPECT_EQ(kUpdateItemId, app.FindKey("appid")->GetString());
EXPECT_EQ("0.9", app.FindKey("version")->GetString());
EXPECT_EQ("TEST", app.FindKey("brand")->GetString());
@@ -1081,7 +1110,7 @@ TEST_P(UpdateCheckerTest, UpdatePauseResume) {
EXPECT_EQ(-2, app.FindPath({"ping", "r"})->GetInt());
EXPECT_EQ("fp1", app.FindKey("packages")
->FindKey("package")
- ->GetList()[0]
+ ->GetListDeprecated()[0]
.FindKey("fp")
->GetString());
}
@@ -1171,4 +1200,34 @@ TEST_P(UpdateCheckerTest, ParseErrorAppStatusErrorUnknownApplication) {
EXPECT_STREQ("error-unknownApplication", result.status.c_str());
}
+TEST_P(UpdateCheckerTest, DomainJoined) {
+ for (const auto is_managed : std::initializer_list<absl::optional<bool>>{
+ absl::nullopt, false, true}) {
+ EXPECT_TRUE(post_interceptor_->ExpectRequest(
+ std::make_unique<PartialMatch>("updatecheck"),
+ test_file("updatecheck_reply_noupdate.json")));
+ update_checker_ = UpdateChecker::Create(config_, metadata_.get());
+
+ IdToComponentPtrMap components;
+ components[kUpdateItemId] = MakeComponent();
+
+ config_->SetIsMachineExternallyManaged(is_managed);
+ update_checker_->CheckForUpdates(
+ update_context_->session_id, {kUpdateItemId}, components, {},
+ base::BindOnce(&UpdateCheckerTest::UpdateCheckComplete,
+ base::Unretained(this)));
+ RunThreads();
+
+ ASSERT_EQ(post_interceptor_->GetCount(), 1);
+ const auto root =
+ base::JSONReader::Read(post_interceptor_->GetRequestBody(0));
+ post_interceptor_->Reset();
+
+ // What is injected in the update checker by the configurator must
+ // match what is sent in the update check.
+ ASSERT_TRUE(root);
+ EXPECT_EQ(is_managed, root->FindBoolPath("request.domainjoined"));
+ }
+}
+
} // namespace update_client
diff --git a/chromium/components/update_client/update_client_unittest.cc b/chromium/components/update_client/update_client_unittest.cc
index cbdaef815c4..c299941eb8a 100644
--- a/chromium/components/update_client/update_client_unittest.cc
+++ b/chromium/components/update_client/update_client_unittest.cc
@@ -2833,14 +2833,16 @@ TEST_F(UpdateClientTest, OneCrxInstall) {
EXPECT_EQ(ComponentState::kUpdated, items[5].state);
EXPECT_STREQ("jebgalgnebhfojomionfpkfelancnnkf", items[5].id.c_str());
- const base::DictionaryValue* dict =
+ const base::Value* dict =
config()->GetPrefService()->GetDictionary("updateclientdata");
- std::string pv;
- dict->GetString("apps.jebgalgnebhfojomionfpkfelancnnkf.pv", &pv);
- EXPECT_STREQ("1.0", pv.c_str());
- std::string fingerprint;
- dict->GetString("apps.jebgalgnebhfojomionfpkfelancnnkf.fp", &fingerprint);
- EXPECT_STREQ("some-fingerprint", fingerprint.c_str());
+ const std::string* pv =
+ dict->FindStringPath("apps.jebgalgnebhfojomionfpkfelancnnkf.pv");
+ ASSERT_TRUE(pv);
+ EXPECT_STREQ("1.0", pv->c_str());
+ const std::string* fingerprint =
+ dict->FindStringPath("apps.jebgalgnebhfojomionfpkfelancnnkf.fp");
+ ASSERT_TRUE(fingerprint);
+ EXPECT_STREQ("some-fingerprint", fingerprint->c_str());
update_client->RemoveObserver(&observer);
}
diff --git a/chromium/components/update_client/update_engine.h b/chromium/components/update_client/update_engine.h
index 3b409dd48ca..265ada0b0b7 100644
--- a/chromium/components/update_client/update_engine.h
+++ b/chromium/components/update_client/update_engine.h
@@ -5,7 +5,6 @@
#ifndef COMPONENTS_UPDATE_CLIENT_UPDATE_ENGINE_H_
#define COMPONENTS_UPDATE_CLIENT_UPDATE_ENGINE_H_
-#include <list>
#include <map>
#include <memory>
#include <string>
diff --git a/chromium/components/update_client/update_query_params.cc b/chromium/components/update_client/update_query_params.cc
index 6b1d502f3de..6abf11963c8 100644
--- a/chromium/components/update_client/update_query_params.cc
+++ b/chromium/components/update_client/update_query_params.cc
@@ -13,7 +13,7 @@
#include "components/update_client/update_query_params_delegate.h"
#include "components/version_info/version_info.h"
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
#include "base/win/windows_version.h"
#endif
@@ -26,19 +26,19 @@ const char kUnknown[] = "unknown";
// The request extra information is the OS and architecture, this helps
// the server select the right package to be delivered.
const char kOs[] =
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
"mac";
-#elif defined(OS_WIN)
+#elif BUILDFLAG(IS_WIN)
"win";
-#elif defined(OS_ANDROID)
+#elif BUILDFLAG(IS_ANDROID)
"android";
#elif BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
"cros";
-#elif defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
+#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
"linux";
-#elif defined(OS_FUCHSIA)
+#elif BUILDFLAG(IS_FUCHSIA)
"fuchsia";
-#elif defined(OS_OPENBSD)
+#elif BUILDFLAG(IS_OPENBSD)
"openbsd";
#else
#error "unknown os"
@@ -114,7 +114,7 @@ const char* UpdateQueryParams::GetNaclArch() {
#if defined(ARCH_CPU_X86_FAMILY)
#if defined(ARCH_CPU_X86_64)
return "x86-64";
-#elif defined(OS_WIN)
+#elif BUILDFLAG(IS_WIN)
bool x86_64 = base::win::OSInfo::GetInstance()->IsWowX86OnAMD64();
return x86_64 ? "x86-64" : "x86-32";
#else
diff --git a/chromium/components/update_client/updater_state.cc b/chromium/components/update_client/updater_state.cc
deleted file mode 100644
index b44a6258a30..00000000000
--- a/chromium/components/update_client/updater_state.cc
+++ /dev/null
@@ -1,102 +0,0 @@
-
-// Copyright (c) 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/update_client/updater_state.h"
-
-#include <string>
-#include <utility>
-
-#include "base/enterprise_util.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/utf_string_conversions.h"
-#include "build/branding_buildflags.h"
-#include "build/build_config.h"
-
-namespace update_client {
-
-// The value of this constant does not reflect its name (i.e. "domainjoined"
-// vs something like "isenterprisemanaged") because it is used with omaha.
-// After discussion with omaha team it was decided to leave the value as is to
-// keep continuity with previous chrome versions.
-const char UpdaterState::kIsEnterpriseManaged[] = "domainjoined";
-
-UpdaterState::UpdaterState(bool is_machine) : is_machine_(is_machine) {}
-
-UpdaterState::~UpdaterState() = default;
-
-std::unique_ptr<UpdaterState::Attributes> UpdaterState::GetState(
- bool is_machine) {
-#if defined(OS_WIN) || defined(OS_MAC)
- UpdaterState updater_state(is_machine);
- updater_state.ReadState();
- return std::make_unique<Attributes>(updater_state.BuildAttributes());
-#else
- return nullptr;
-#endif // OS_WIN or Mac
-}
-
-#if defined(OS_WIN) || defined(OS_MAC)
-void UpdaterState::ReadState() {
- is_enterprise_managed_ = base::IsMachineExternallyManaged();
-
-#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
- updater_name_ = GetUpdaterName();
- updater_version_ = GetUpdaterVersion(is_machine_);
- last_autoupdate_started_ = GetUpdaterLastStartedAU(is_machine_);
- last_checked_ = GetUpdaterLastChecked(is_machine_);
- is_autoupdate_check_enabled_ = IsAutoupdateCheckEnabled();
- update_policy_ = GetUpdatePolicy();
-#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
-}
-#endif // OS_WIN or Mac
-
-UpdaterState::Attributes UpdaterState::BuildAttributes() const {
- Attributes attributes;
-
-#if defined(OS_WIN)
- // Only Windows implements this attribute in a meaningful way.
- attributes["ismachine"] = is_machine_ ? "1" : "0";
-#endif // OS_WIN
- attributes[kIsEnterpriseManaged] = is_enterprise_managed_ ? "1" : "0";
-
- attributes["name"] = updater_name_;
-
- if (updater_version_.IsValid())
- attributes["version"] = updater_version_.GetString();
-
- const base::Time now = base::Time::NowFromSystemTime();
- if (!last_autoupdate_started_.is_null())
- attributes["laststarted"] =
- NormalizeTimeDelta(now - last_autoupdate_started_);
- if (!last_checked_.is_null())
- attributes["lastchecked"] = NormalizeTimeDelta(now - last_checked_);
-
- attributes["autoupdatecheckenabled"] =
- is_autoupdate_check_enabled_ ? "1" : "0";
-
- DCHECK((update_policy_ >= 0 && update_policy_ <= 3) || update_policy_ == -1);
- attributes["updatepolicy"] = base::NumberToString(update_policy_);
-
- return attributes;
-}
-
-std::string UpdaterState::NormalizeTimeDelta(const base::TimeDelta& delta) {
- const base::TimeDelta two_weeks = base::Days(14);
- const base::TimeDelta two_months = base::Days(56);
-
- std::string val; // Contains the value to return in hours.
- if (delta <= two_weeks) {
- val = "0";
- } else if (two_weeks < delta && delta <= two_months) {
- val = "336"; // 2 weeks in hours.
- } else {
- val = "1344"; // 2*28 days in hours.
- }
-
- DCHECK(!val.empty());
- return val;
-}
-
-} // namespace update_client
diff --git a/chromium/components/update_client/updater_state.h b/chromium/components/update_client/updater_state.h
deleted file mode 100644
index ec11d4a7a49..00000000000
--- a/chromium/components/update_client/updater_state.h
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright (c) 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef COMPONENTS_UPDATE_CLIENT_UPDATER_STATE_H_
-#define COMPONENTS_UPDATE_CLIENT_UPDATER_STATE_H_
-
-#include <map>
-#include <memory>
-#include <string>
-
-#include "base/gtest_prod_util.h"
-#include "base/time/time.h"
-#include "base/version.h"
-
-namespace update_client {
-
-class UpdaterState {
- public:
- using Attributes = std::map<std::string, std::string>;
-
- static const char kIsEnterpriseManaged[];
-
- // Returns a map of items representing the state of an updater.
- // If |is_machine| is true, this indicates that the updater state corresponds
- // to the machine instance of the updater. Returns nullptr on
- // the platforms and builds where this feature is not supported.
- static std::unique_ptr<Attributes> GetState(bool is_machine);
-
- ~UpdaterState();
-
- private:
- FRIEND_TEST_ALL_PREFIXES(UpdaterStateTest, Serialize);
-
- explicit UpdaterState(bool is_machine);
-
- // This function is best-effort. It updates the class members with
- // the relevant values that could be retrieved.
- void ReadState();
-
- // Builds the map of state attributes by serializing this object state.
- Attributes BuildAttributes() const;
-
- static std::string GetUpdaterName();
- static base::Version GetUpdaterVersion(bool is_machine);
- static bool IsAutoupdateCheckEnabled();
- static base::Time GetUpdaterLastStartedAU(bool is_machine);
- static base::Time GetUpdaterLastChecked(bool is_machine);
-
- static int GetUpdatePolicy();
-
- static std::string NormalizeTimeDelta(const base::TimeDelta& delta);
-
- // True if the Omaha updater is installed per-machine.
- // The MacOS implementation ignores the value of this member but this may
- // change in the future.
- bool is_machine_;
- std::string updater_name_;
- base::Version updater_version_;
- base::Time last_autoupdate_started_;
- base::Time last_checked_;
- bool is_enterprise_managed_ = false;
- bool is_autoupdate_check_enabled_ = false;
- int update_policy_ = 0;
-};
-
-} // namespace update_client
-
-#endif // COMPONENTS_UPDATE_CLIENT_UPDATER_STATE_H_
diff --git a/chromium/components/update_client/updater_state_mac.mm b/chromium/components/update_client/updater_state_mac.mm
deleted file mode 100644
index 9ffb980b33b..00000000000
--- a/chromium/components/update_client/updater_state_mac.mm
+++ /dev/null
@@ -1,117 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#import <Foundation/Foundation.h>
-
-#include "base/enterprise_util.h"
-#include "base/files/file_path.h"
-#include "base/files/file_util.h"
-#include "base/mac/foundation_util.h"
-#include "base/mac/scoped_nsobject.h"
-#include "base/strings/sys_string_conversions.h"
-#include "base/version.h"
-#include "components/update_client/updater_state.h"
-
-namespace update_client {
-
-namespace {
-
-const base::FilePath::CharType kKeystonePlist[] = FILE_PATH_LITERAL(
- "Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/"
- "Contents/Info.plist");
-
-// Gets a value from the updater settings. Returns a retained object.
-// T should be a toll-free Foundation framework type. See Apple's
-// documentation for toll-free bridging.
-template<class T>
-base::scoped_nsobject<T> GetUpdaterSettingsValue(NSString* value_name) {
- CFStringRef app_id = CFSTR("com.google.Keystone.Agent");
- base::ScopedCFTypeRef<CFPropertyListRef> plist(
- CFPreferencesCopyAppValue(base::mac::NSToCFCast(value_name), app_id));
- return base::scoped_nsobject<T>(
- base::mac::ObjCCastStrict<T>(static_cast<id>(plist.get())),
- base::scoped_policy::RETAIN);
-}
-
-base::Time GetUpdaterSettingsTime(NSString* value_name) {
- base::scoped_nsobject<NSDate> date =
- GetUpdaterSettingsValue<NSDate>(value_name);
- base::Time result =
- base::Time::FromCFAbsoluteTime([date timeIntervalSinceReferenceDate]);
-
- return result;
-}
-
-base::Version GetVersionFromPlist(const base::FilePath& info_plist) {
- @autoreleasepool {
- NSData* data = [NSData
- dataWithContentsOfFile:base::mac::FilePathToNSString(info_plist)];
- if ([data length] == 0) {
- return base::Version();
- }
- NSDictionary* all_keys =
- base::mac::ObjCCastStrict<NSDictionary>([NSPropertyListSerialization
- propertyListWithData:data
- options:NSPropertyListImmutable
- format:nil
- error:nil]);
- if (all_keys == nil) {
- return base::Version();
- }
- CFStringRef version = base::mac::GetValueFromDictionary<CFStringRef>(
- base::mac::NSToCFCast(all_keys), kCFBundleVersionKey);
- if (version == NULL) {
- return base::Version();
- }
- return base::Version(base::SysCFStringRefToUTF8(version));
- }
-}
-
-} // namespace
-
-std::string UpdaterState::GetUpdaterName() {
- return std::string("Keystone");
-}
-
-base::Version UpdaterState::GetUpdaterVersion(bool /*is_machine*/) {
- // System Keystone trumps user one, so check this one first
- base::FilePath local_library;
- bool success = base::mac::GetLocalDirectory(NSLibraryDirectory,
- &local_library);
- DCHECK(success);
- base::FilePath system_bundle_plist = local_library.Append(kKeystonePlist);
- base::Version system_keystone = GetVersionFromPlist(system_bundle_plist);
- if (system_keystone.IsValid()) {
- return system_keystone;
- }
-
- base::FilePath user_bundle_plist =
- base::mac::GetUserLibraryPath().Append(kKeystonePlist);
- return GetVersionFromPlist(user_bundle_plist);
-}
-
-base::Time UpdaterState::GetUpdaterLastStartedAU(bool /*is_machine*/) {
- return GetUpdaterSettingsTime(@"lastCheckStartDate");
-}
-
-base::Time UpdaterState::GetUpdaterLastChecked(bool /*is_machine*/) {
- return GetUpdaterSettingsTime(@"lastServerCheckDate");
-}
-
-bool UpdaterState::IsAutoupdateCheckEnabled() {
- // Auto-update check period override (in seconds).
- // Applies only to older versions of Keystone.
- base::scoped_nsobject<NSNumber> timeInterval =
- GetUpdaterSettingsValue<NSNumber>(@"checkInterval");
- if (!timeInterval.get()) return true;
- int value = [timeInterval intValue];
-
- return 0 < value && value < (24 * 60 * 60);
-}
-
-int UpdaterState::GetUpdatePolicy() {
- return -1; // Keystone does not support update policies.
-}
-
-} // namespace update_client
diff --git a/chromium/components/update_client/updater_state_unittest.cc b/chromium/components/update_client/updater_state_unittest.cc
deleted file mode 100644
index 298e131bfbd..00000000000
--- a/chromium/components/update_client/updater_state_unittest.cc
+++ /dev/null
@@ -1,127 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/update_client/updater_state.h"
-
-#include "base/time/time.h"
-#include "base/version.h"
-#include "build/branding_buildflags.h"
-#include "build/build_config.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace update_client {
-
-class UpdaterStateTest : public testing::Test {
- public:
- UpdaterStateTest() = default;
-
- UpdaterStateTest(const UpdaterStateTest&) = delete;
- UpdaterStateTest& operator=(const UpdaterStateTest&) = delete;
-
- ~UpdaterStateTest() override = default;
-};
-
-TEST_F(UpdaterStateTest, Serialize) {
- UpdaterState updater_state(false);
-
- updater_state.updater_name_ = "the updater";
- updater_state.updater_version_ = base::Version("1.0");
- updater_state.last_autoupdate_started_ = base::Time::NowFromSystemTime();
- updater_state.last_checked_ = base::Time::NowFromSystemTime();
- updater_state.is_enterprise_managed_ = false;
- updater_state.is_autoupdate_check_enabled_ = true;
- updater_state.update_policy_ = 1;
-
- auto attributes = updater_state.BuildAttributes();
-
- // Sanity check all members.
- EXPECT_STREQ("the updater", attributes.at("name").c_str());
- EXPECT_STREQ("1.0", attributes.at("version").c_str());
- EXPECT_STREQ("0", attributes.at("laststarted").c_str());
- EXPECT_STREQ("0", attributes.at("lastchecked").c_str());
- EXPECT_STREQ("0", attributes.at("domainjoined").c_str());
- EXPECT_STREQ("1", attributes.at("autoupdatecheckenabled").c_str());
- EXPECT_STREQ("1", attributes.at("updatepolicy").c_str());
-
-#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
-#if defined(OS_WIN)
- // The value of "ismachine".
- EXPECT_STREQ("0", UpdaterState::GetState(false)->at("ismachine").c_str());
- EXPECT_STREQ("1", UpdaterState::GetState(true)->at("ismachine").c_str());
-
- // The name of the Windows updater for Chrome.
- EXPECT_STREQ("Omaha", UpdaterState::GetState(false)->at("name").c_str());
-#elif defined(OS_MAC)
- // MacOS does not serialize "ismachine".
- EXPECT_EQ(0UL, UpdaterState::GetState(false)->count("ismachine"));
- EXPECT_EQ(0UL, UpdaterState::GetState(true)->count("ismachine"));
- EXPECT_STREQ("Keystone", UpdaterState::GetState(false)->at("name").c_str());
-#endif // OS_WIN
-#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
-
- // Tests some of the remaining values.
- updater_state = UpdaterState(false);
-
- // Don't serialize an invalid version if it could not be read.
- updater_state.updater_version_ = base::Version();
- attributes = updater_state.BuildAttributes();
- EXPECT_EQ(0u, attributes.count("version"));
-
- updater_state.updater_version_ = base::Version("0.0.0.0");
- attributes = updater_state.BuildAttributes();
- EXPECT_STREQ("0.0.0.0", attributes.at("version").c_str());
-
- updater_state.last_autoupdate_started_ =
- base::Time::NowFromSystemTime() - base::Days(15);
- attributes = updater_state.BuildAttributes();
- EXPECT_STREQ("336", attributes.at("laststarted").c_str());
-
- updater_state.last_autoupdate_started_ =
- base::Time::NowFromSystemTime() - base::Days(58);
- attributes = updater_state.BuildAttributes();
- EXPECT_STREQ("1344", attributes.at("laststarted").c_str());
-
- updater_state.last_autoupdate_started_ =
- base::Time::NowFromSystemTime() - base::Days(90);
- attributes = updater_state.BuildAttributes();
- EXPECT_STREQ("1344", attributes.at("laststarted").c_str());
-
- // Don't serialize the time if it could not be read.
- updater_state.last_autoupdate_started_ = base::Time();
- attributes = updater_state.BuildAttributes();
- EXPECT_EQ(0u, attributes.count("laststarted"));
-
- updater_state.last_checked_ =
- base::Time::NowFromSystemTime() - base::Days(15);
- attributes = updater_state.BuildAttributes();
- EXPECT_STREQ("336", attributes.at("lastchecked").c_str());
-
- updater_state.last_checked_ =
- base::Time::NowFromSystemTime() - base::Days(90);
- attributes = updater_state.BuildAttributes();
- EXPECT_STREQ("1344", attributes.at("lastchecked").c_str());
-
- // Don't serialize the time if it could not be read (the value is invalid).
- updater_state.last_checked_ = base::Time();
- attributes = updater_state.BuildAttributes();
- EXPECT_EQ(0u, attributes.count("lastchecked"));
-
- updater_state.is_enterprise_managed_ = true;
- attributes = updater_state.BuildAttributes();
- EXPECT_STREQ("1", attributes.at("domainjoined").c_str());
-
- updater_state.is_autoupdate_check_enabled_ = false;
- attributes = updater_state.BuildAttributes();
- EXPECT_STREQ("0", attributes.at("autoupdatecheckenabled").c_str());
-
- updater_state.update_policy_ = 0;
- attributes = updater_state.BuildAttributes();
- EXPECT_STREQ("0", attributes.at("updatepolicy").c_str());
-
- updater_state.update_policy_ = -1;
- attributes = updater_state.BuildAttributes();
- EXPECT_STREQ("-1", attributes.at("updatepolicy").c_str());
-}
-
-} // namespace update_client
diff --git a/chromium/components/update_client/updater_state_win.cc b/chromium/components/update_client/updater_state_win.cc
deleted file mode 100644
index 102029a0fe6..00000000000
--- a/chromium/components/update_client/updater_state_win.cc
+++ /dev/null
@@ -1,135 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/update_client/updater_state.h"
-
-#include <windows.h>
-
-#include <string>
-#include <utility>
-
-#include "base/enterprise_util.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/utf_string_conversions.h"
-#include "base/win/registry.h"
-#include "base/win/win_util.h"
-
-// TODO(sorin): implement this in terms of
-// chrome/installer/util/google_update_settings (crbug.com/615187).
-
-namespace update_client {
-
-namespace {
-
-// Google Update group policy settings.
-const wchar_t kGoogleUpdatePoliciesKey[] =
- L"SOFTWARE\\Policies\\Google\\Update";
-const wchar_t kCheckPeriodOverrideMinutes[] = L"AutoUpdateCheckPeriodMinutes";
-const wchar_t kUpdatePolicyValue[] = L"UpdateDefault";
-const wchar_t kChromeUpdatePolicyOverride[] =
- L"Update{8A69D345-D564-463C-AFF1-A69D9E530F96}";
-
-// Don't allow update periods longer than six weeks (Chrome release cadence).
-const int kCheckPeriodOverrideMinutesMax = 60 * 24 * 7 * 6;
-
-// Google Update registry settings.
-const wchar_t kRegPathGoogleUpdate[] = L"Software\\Google\\Update";
-const wchar_t kRegPathClientsGoogleUpdate[] =
- L"Software\\Google\\Update\\Clients\\"
- L"{430FD4D0-B729-4F61-AA34-91526481799D}";
-const wchar_t kRegValueGoogleUpdatePv[] = L"pv";
-const wchar_t kRegValueLastStartedAU[] = L"LastStartedAU";
-const wchar_t kRegValueLastChecked[] = L"LastChecked";
-
-base::Time GetUpdaterTimeValue(bool is_machine, const wchar_t* value_name) {
- const HKEY root_key = is_machine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
- base::win::RegKey update_key;
-
- if (update_key.Open(root_key, kRegPathGoogleUpdate,
- KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) {
- DWORD value(0);
- if (update_key.ReadValueDW(value_name, &value) == ERROR_SUCCESS) {
- return base::Time::FromTimeT(value);
- }
- }
-
- return base::Time();
-}
-
-} // namespace
-
-std::string UpdaterState::GetUpdaterName() {
- return std::string("Omaha");
-}
-
-base::Version UpdaterState::GetUpdaterVersion(bool is_machine) {
- const HKEY root_key = is_machine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
- std::wstring version;
- base::win::RegKey key;
-
- if (key.Open(root_key, kRegPathClientsGoogleUpdate,
- KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS &&
- key.ReadValue(kRegValueGoogleUpdatePv, &version) == ERROR_SUCCESS) {
- return base::Version(base::WideToUTF8(version));
- }
-
- return base::Version();
-}
-
-base::Time UpdaterState::GetUpdaterLastStartedAU(bool is_machine) {
- return GetUpdaterTimeValue(is_machine, kRegValueLastStartedAU);
-}
-
-base::Time UpdaterState::GetUpdaterLastChecked(bool is_machine) {
- return GetUpdaterTimeValue(is_machine, kRegValueLastChecked);
-}
-
-bool UpdaterState::IsAutoupdateCheckEnabled() {
- // Check the auto-update check period override. If it is 0 or exceeds the
- // maximum timeout, then for all intents and purposes auto updates are
- // disabled.
- base::win::RegKey policy_key;
- DWORD value = 0;
- if (policy_key.Open(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
- KEY_QUERY_VALUE) == ERROR_SUCCESS &&
- policy_key.ReadValueDW(kCheckPeriodOverrideMinutes, &value) ==
- ERROR_SUCCESS &&
- (value == 0 || value > kCheckPeriodOverrideMinutesMax)) {
- return false;
- }
-
- return true;
-}
-
-// Returns -1 if the policy is not found or the value was invalid. Otherwise,
-// returns a value in the [0, 3] range, representing the value of the
-// Chrome update group policy.
-int UpdaterState::GetUpdatePolicy() {
- const int kMaxUpdatePolicyValue = 3;
-
- base::win::RegKey policy_key;
-
- if (policy_key.Open(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
- KEY_QUERY_VALUE) != ERROR_SUCCESS) {
- return -1;
- }
-
- DWORD value = 0;
- // First try to read the Chrome-specific override.
- if (policy_key.ReadValueDW(kChromeUpdatePolicyOverride, &value) ==
- ERROR_SUCCESS &&
- value <= kMaxUpdatePolicyValue) {
- return value;
- }
-
- // Try to read default override.
- if (policy_key.ReadValueDW(kUpdatePolicyValue, &value) == ERROR_SUCCESS &&
- value <= kMaxUpdatePolicyValue) {
- return value;
- }
-
- return -1;
-}
-
-} // namespace update_client
diff --git a/chromium/components/update_client/utils_unittest.cc b/chromium/components/update_client/utils_unittest.cc
index d71e1ab3bfb..fde5c1842a2 100644
--- a/chromium/components/update_client/utils_unittest.cc
+++ b/chromium/components/update_client/utils_unittest.cc
@@ -8,7 +8,6 @@
#include "base/files/file_path.h"
#include "base/path_service.h"
-#include "components/update_client/updater_state.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"