Commit 84505256 authored by Yann Dago's avatar Yann Dago Committed by Commit Bot

Send channel param to updater server

Bug: 1102927
Change-Id: Iee104ca7c5c75ecaa964e8d121c331cfbb8b5abb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2289384
Commit-Queue: Yann Dago <ydago@chromium.org>
Reviewed-by: default avatarSorin Jianu <sorin@chromium.org>
Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Reviewed-by: default avatarS. Ganesh <ganesh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802393}
parent 2a8d57b9
......@@ -104,6 +104,8 @@ if (is_win || is_mac) {
"installer.cc",
"installer.h",
"lib_util.h",
"policy_service.cc",
"policy_service.h",
"prefs.cc",
"prefs.h",
"prefs_impl.h",
......@@ -183,6 +185,7 @@ if (is_win || is_mac) {
if (is_mac) {
deps += [
"//chrome/updater/app/server/mac:protocol",
"//chrome/updater/mac:enterprise",
"//chrome/updater/mac:installer_sources",
"//chrome/updater/mac:network_fetcher_sources",
"//chrome/updater/mac:updater_setup_sources",
......@@ -290,6 +293,7 @@ if (is_win || is_mac) {
"lib_util_unittest.cc",
"persisted_data_unittest.cc",
"policy_manager_unittest.cc",
"policy_service_unittest.cc",
"prefs_unittest.cc",
"run_all_unittests.cc",
"service_scope_unittest.cc",
......
......@@ -202,6 +202,16 @@ bool DMPolicyManager::GetTargetVersionPrefix(
return true;
}
bool DMPolicyManager::GetTargetChannel(const std::string& app_id,
std::string* channel) const {
const auto* app_settings = GetAppSettings(app_id);
if (!app_settings || !app_settings->has_target_channel())
return false;
*channel = app_settings->target_channel();
return true;
}
bool DMPolicyManager::IsRollbackToTargetVersionAllowed(
const std::string& app_id,
bool* rollback_allowed) const {
......
......@@ -47,6 +47,8 @@ class DMPolicyManager : public PolicyManagerInterface {
bool GetTargetVersionPrefix(
const std::string& app_id,
std::string* target_version_prefix) const override;
bool GetTargetChannel(const std::string& app_id,
std::string* channel) const override;
bool IsRollbackToTargetVersionAllowed(const std::string& app_id,
bool* rollback_allowed) const override;
......
......@@ -17,6 +17,7 @@
#include "build/build_config.h"
#include "chrome/updater/action_handler.h"
#include "chrome/updater/constants.h"
#include "chrome/updater/policy_service.h"
#include "chrome/updater/util.h"
#include "components/crx_file/crx_verifier.h"
#include "components/update_client/update_client_errors.h"
......@@ -78,6 +79,13 @@ update_client::CrxComponent Installer::MakeCrxComponent() {
component.name = app_id_;
component.version = pv_;
component.fingerprint = fingerprint_;
// In case we fail at getting the target channel, make sure that
// |component.channel| is an empty string. Possible failure cases are if the
// machine is not managed, the policy was not set or any other unexpected
// error.
if (!GetUpdaterPolicyService()->GetTargetChannel(app_id_, &component.channel))
component.channel.clear();
return component;
}
......
......@@ -52,6 +52,8 @@ class ManagedPreferencePolicyManager : public PolicyManagerInterface {
bool GetProxyMode(std::string* proxy_mode) const override;
bool GetProxyPacUrl(std::string* proxy_pac_url) const override;
bool GetProxyServer(std::string* proxy_server) const override;
bool GetTargetChannel(const std::string& app_id,
std::string* channel) const override;
private:
base::scoped_nsobject<CRUManagedPreferencePolicyManager> impl_;
......@@ -188,6 +190,18 @@ bool ManagedPreferencePolicyManager::GetProxyServer(
return false;
}
bool ManagedPreferencePolicyManager::GetTargetChannel(
const std::string& app_id,
std::string* channel) const {
NSString* value = [impl_ targetChannel:base::SysUTF8ToNSString(app_id)];
if (value) {
*channel = base::SysNSStringToUTF8(value);
return true;
}
return false;
}
NSDictionary* ReadManagedPreferencePolicyDictionary() {
base::ScopedCFTypeRef<CFPropertyListRef> policies(CFPreferencesCopyAppValue(
(__bridge CFStringRef)kManagedPreferencesUpdatePolicies,
......
......@@ -67,6 +67,7 @@ struct CRUUpdatesSuppressed {
// App-level policies.
- (int)appUpdatePolicy:(nonnull NSString*)appid;
- (nullable NSString*)targetChannel:(nonnull NSString*)appid;
- (nullable NSString*)targetVersionPrefix:(nonnull NSString*)appid;
- (int)rollbackToTargetVersion:(nonnull NSString*)appid;
......
......@@ -16,6 +16,7 @@ static NSString* kUpdatesSuppressedStartMinuteKey =
@"UpdatesSuppressedStartMin";
static NSString* kUpdatesSuppressedDurationMinuteKey =
@"UpdatesSuppressedDurationMin";
static NSString* kTargetChannelKey = @"TargetChannel";
static NSString* kTargetVersionPrefixKey = @"TargetVersionPrefix";
static NSString* kRollbackToTargetVersionKey = @"RollbackToTargetVersion";
......@@ -119,11 +120,13 @@ base::scoped_nsobject<NSString> ReadPolicyString(id value) {
/// Class that manages policies for a single App.
@interface CRUManagedPreferenceAppPolicySettings : NSObject {
base::scoped_nsobject<NSString> _targetChannel;
base::scoped_nsobject<NSString> _targetVersionPrefix;
}
@property(nonatomic, readonly) int updatePolicy;
@property(nonatomic, readonly) int rollbackToTargetVersion;
@property(nonatomic, readonly, nullable) NSString* targetChannel;
@property(nonatomic, readonly, nullable) NSString* targetVersionPrefix;
@end
......@@ -137,6 +140,8 @@ base::scoped_nsobject<NSString> ReadPolicyString(id value) {
if (([super init])) {
_updatePolicy =
updater::ReadPolicyInteger([policyDict objectForKey:kUpdateDefaultKey]);
_targetChannel =
updater::ReadPolicyString([policyDict objectForKey:kTargetChannelKey]);
_targetVersionPrefix = updater::ReadPolicyString(
[policyDict objectForKey:kTargetVersionPrefixKey]);
_rollbackToTargetVersion = updater::ReadPolicyInteger(
......@@ -146,6 +151,14 @@ base::scoped_nsobject<NSString> ReadPolicyString(id value) {
return self;
}
- (NSString*)targetChannel {
if (_targetChannel) {
return [NSString stringWithString:_targetChannel];
} else {
return nil;
}
}
- (NSString*)targetVersionPrefix {
if (_targetVersionPrefix) {
return [NSString stringWithString:_targetVersionPrefix];
......@@ -233,6 +246,11 @@ base::scoped_nsobject<NSString> ReadPolicyString(id value) {
return [_appPolicies objectForKey:appid].updatePolicy;
}
- (NSString*)targetChannel:(NSString*)appid {
appid = appid.lowercaseString;
return [_appPolicies objectForKey:appid].targetChannel;
}
- (NSString*)targetVersionPrefix:(NSString*)appid {
appid = appid.lowercaseString;
return [_appPolicies objectForKey:appid].targetVersionPrefix;
......
......@@ -44,6 +44,8 @@ class DefaultPolicyManager : public PolicyManagerInterface {
bool GetProxyMode(std::string* proxy_mode) const override;
bool GetProxyPacUrl(std::string* proxy_pac_url) const override;
bool GetProxyServer(std::string* proxy_server) const override;
bool GetTargetChannel(const std::string& app_id,
std::string* channel) const override;
};
DefaultPolicyManager::DefaultPolicyManager() = default;
......@@ -119,6 +121,11 @@ bool DefaultPolicyManager::GetProxyServer(std::string* proxy_server) const {
return false;
}
bool DefaultPolicyManager::GetTargetChannel(const std::string& app_id,
std::string* channel) const {
return false;
}
std::unique_ptr<PolicyManagerInterface> GetPolicyManager() {
return std::make_unique<DefaultPolicyManager>();
}
......
......@@ -84,6 +84,10 @@ class PolicyManagerInterface {
// Returns a proxy server.
virtual bool GetProxyServer(std::string* proxy_server) const = 0;
// Returns a channel, for example {stable|beta|dev}.
virtual bool GetTargetChannel(const std::string& app_id,
std::string* channel) const = 0;
};
std::unique_ptr<PolicyManagerInterface> GetPolicyManager();
......
// Copyright 2020 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 "chrome/updater/policy_service.h"
#include "base/check.h"
#include "build/build_config.h"
#if defined(OS_WIN)
#include "chrome/updater/win/group_policy_manager.h"
#elif defined(OS_MAC)
#include "chrome/updater/mac/managed_preference_policy_manager.h"
#endif
namespace updater {
// Only policy manager that are enterprise managed are used by the policy
// service.
PolicyService::PolicyService() : default_policy_manager_(GetPolicyManager()) {
#if defined(OS_WIN)
auto group_policy_manager = std::make_unique<GroupPolicyManager>();
if (group_policy_manager->IsManaged())
policy_managers_.emplace_back(std::move(group_policy_manager));
#endif
// TODO (crbug/1122118): Inject the DMPolicyManager here.
#if defined(OS_MAC)
auto mac_policy_manager = CreateManagedPreferencePolicyManager();
if (mac_policy_manager->IsManaged())
policy_managers_.emplace_back(std::move(mac_policy_manager));
#endif
UpdateActivePolicyManager();
}
PolicyService::~PolicyService() = default;
void PolicyService::SetPolicyManagersForTesting(
std::vector<std::unique_ptr<PolicyManagerInterface>> managers) {
policy_managers_ = std::move(managers);
UpdateActivePolicyManager();
}
std::string PolicyService::source() const {
return active_policy_manager_->source();
}
bool PolicyService::IsManaged() const {
return active_policy_manager_->IsManaged();
}
bool PolicyService::GetLastCheckPeriodMinutes(int* minutes) const {
return active_policy_manager_->GetLastCheckPeriodMinutes(minutes) ||
(ShouldFallbackToDefaultManager() &&
default_policy_manager_->GetLastCheckPeriodMinutes(minutes));
}
bool PolicyService::GetUpdatesSuppressedTimes(int* start_hour,
int* start_min,
int* duration_min) const {
return active_policy_manager_->GetUpdatesSuppressedTimes(
start_hour, start_min, duration_min) ||
(ShouldFallbackToDefaultManager() &&
default_policy_manager_->GetUpdatesSuppressedTimes(
start_hour, start_min, duration_min));
}
bool PolicyService::GetDownloadPreferenceGroupPolicy(
std::string* download_preference) const {
return active_policy_manager_->GetDownloadPreferenceGroupPolicy(
download_preference) ||
(ShouldFallbackToDefaultManager() &&
default_policy_manager_->GetDownloadPreferenceGroupPolicy(
download_preference));
}
bool PolicyService::GetPackageCacheSizeLimitMBytes(
int* cache_size_limit) const {
return active_policy_manager_->GetPackageCacheSizeLimitMBytes(
cache_size_limit) ||
(ShouldFallbackToDefaultManager() &&
default_policy_manager_->GetPackageCacheSizeLimitMBytes(
cache_size_limit));
}
bool PolicyService::GetPackageCacheExpirationTimeDays(
int* cache_life_limit) const {
return active_policy_manager_->GetPackageCacheExpirationTimeDays(
cache_life_limit) ||
(ShouldFallbackToDefaultManager() &&
default_policy_manager_->GetPackageCacheExpirationTimeDays(
cache_life_limit));
}
bool PolicyService::GetEffectivePolicyForAppInstalls(
const std::string& app_id,
int* install_policy) const {
return active_policy_manager_->GetEffectivePolicyForAppInstalls(
app_id, install_policy) ||
(ShouldFallbackToDefaultManager() &&
default_policy_manager_->GetEffectivePolicyForAppInstalls(
app_id, install_policy));
}
bool PolicyService::GetEffectivePolicyForAppUpdates(const std::string& app_id,
int* update_policy) const {
return active_policy_manager_->GetEffectivePolicyForAppUpdates(
app_id, update_policy) ||
(ShouldFallbackToDefaultManager() &&
default_policy_manager_->GetEffectivePolicyForAppUpdates(
app_id, update_policy));
}
bool PolicyService::GetTargetChannel(const std::string& app_id,
std::string* channel) const {
return active_policy_manager_->GetTargetChannel(app_id, channel) ||
(ShouldFallbackToDefaultManager() &&
default_policy_manager_->GetTargetChannel(app_id, channel));
}
bool PolicyService::GetTargetVersionPrefix(
const std::string& app_id,
std::string* target_version_prefix) const {
return active_policy_manager_->GetTargetVersionPrefix(
app_id, target_version_prefix) ||
(ShouldFallbackToDefaultManager() &&
default_policy_manager_->GetTargetVersionPrefix(
app_id, target_version_prefix));
}
bool PolicyService::IsRollbackToTargetVersionAllowed(
const std::string& app_id,
bool* rollback_allowed) const {
return active_policy_manager_->IsRollbackToTargetVersionAllowed(
app_id, rollback_allowed) ||
(ShouldFallbackToDefaultManager() &&
default_policy_manager_->IsRollbackToTargetVersionAllowed(
app_id, rollback_allowed));
}
bool PolicyService::GetProxyMode(std::string* proxy_mode) const {
return active_policy_manager_->GetProxyMode(proxy_mode) ||
(ShouldFallbackToDefaultManager() &&
default_policy_manager_->GetProxyMode(proxy_mode));
}
bool PolicyService::GetProxyPacUrl(std::string* proxy_pac_url) const {
return active_policy_manager_->GetProxyPacUrl(proxy_pac_url) ||
(ShouldFallbackToDefaultManager() &&
default_policy_manager_->GetProxyPacUrl(proxy_pac_url));
}
bool PolicyService::GetProxyServer(std::string* proxy_server) const {
return active_policy_manager_->GetProxyServer(proxy_server) ||
(ShouldFallbackToDefaultManager() &&
default_policy_manager_->GetProxyServer(proxy_server));
}
const PolicyManagerInterface& PolicyService::GetActivePolicyManager() {
DCHECK(active_policy_manager_);
return *active_policy_manager_;
}
bool PolicyService::ShouldFallbackToDefaultManager() const {
return active_policy_manager_ != default_policy_manager_.get();
}
void PolicyService::UpdateActivePolicyManager() {
// The active policy manager is either the default policy manager or the
// manager with the highest level that is managed.
active_policy_manager_ = default_policy_manager_.get();
for (const auto& manager : policy_managers_) {
if (manager->IsManaged()) {
active_policy_manager_ = manager.get();
return;
}
}
}
std::unique_ptr<PolicyService> GetUpdaterPolicyService() {
return std::make_unique<PolicyService>();
}
} // namespace updater
// Copyright 2020 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 CHROME_UPDATER_POLICY_SERVICE_H_
#define CHROME_UPDATER_POLICY_SERVICE_H_
#include <memory>
#include <string>
#include <vector>
#include "chrome/updater/policy_manager.h"
namespace updater {
// The PolicyService returns policies for enterprise managed machines from the
// source with the highest priority where the policy available.
class PolicyService : public PolicyManagerInterface {
public:
PolicyService();
PolicyService(const PolicyService&) = delete;
PolicyService& operator=(const PolicyService&) = delete;
~PolicyService() override;
// Overrides for PolicyManagerInterface.
std::string source() const override;
bool IsManaged() const override;
bool GetLastCheckPeriodMinutes(int* minutes) const override;
bool GetUpdatesSuppressedTimes(int* start_hour,
int* start_min,
int* duration_min) const override;
bool GetDownloadPreferenceGroupPolicy(
std::string* download_preference) const override;
bool GetPackageCacheSizeLimitMBytes(int* cache_size_limit) const override;
bool GetPackageCacheExpirationTimeDays(int* cache_life_limit) const override;
bool GetEffectivePolicyForAppInstalls(const std::string& app_id,
int* install_policy) const override;
bool GetEffectivePolicyForAppUpdates(const std::string& app_id,
int* update_policy) const override;
bool GetTargetChannel(const std::string& app_id,
std::string* channel) const override;
bool GetTargetVersionPrefix(
const std::string& app_id,
std::string* target_version_prefix) const override;
bool IsRollbackToTargetVersionAllowed(const std::string& app_id,
bool* rollback_allowed) const override;
bool GetProxyMode(std::string* proxy_mode) const override;
bool GetProxyPacUrl(std::string* proxy_pac_url) const override;
bool GetProxyServer(std::string* proxy_server) const override;
const std::vector<std::unique_ptr<PolicyManagerInterface>>&
policy_managers() {
return policy_managers_;
}
void SetPolicyManagersForTesting(
std::vector<std::unique_ptr<PolicyManagerInterface>> managers);
const PolicyManagerInterface& GetActivePolicyManager();
private:
bool ShouldFallbackToDefaultManager() const;
// Sets the policy manager that is managed and has the highest priority as the
// active policy manager. If no manager is managed, use the default policy
// manager as the active one.
void UpdateActivePolicyManager();
// List of policy managers in descending order of priority. The first policy
// manager's policies takes precedence over the following.
std::vector<std::unique_ptr<PolicyManagerInterface>> policy_managers_;
std::unique_ptr<PolicyManagerInterface> default_policy_manager_;
const PolicyManagerInterface* active_policy_manager_;
};
std::unique_ptr<PolicyService> GetUpdaterPolicyService();
} // namespace updater
#endif // CHROME_UPDATER_POLICY_SERVICE_H_
// Copyright 2020 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 <memory>
#include <string>
#include <vector>
#include "chrome/updater/policy_manager.h"
#include "chrome/updater/policy_service.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace updater {
// The Policy Manager Interface is implemented by policy managers such as Group
// Policy and Device Management.
class FakePolicyManager : public PolicyManagerInterface {
public:
~FakePolicyManager() override = default;
std::string source() const override { return source_; }
bool IsManaged() const override { return managed_; }
bool GetLastCheckPeriodMinutes(int* minutes) const override { return false; }
bool GetUpdatesSuppressedTimes(int* start_hour,
int* start_min,
int* duration_min) const override {
return false;
}
bool GetDownloadPreferenceGroupPolicy(
std::string* download_preference) const override {
return false;
}
bool GetPackageCacheSizeLimitMBytes(int* cache_size_limit) const override {
return false;
}
bool GetPackageCacheExpirationTimeDays(int* cache_life_limit) const override {
return false;
}
bool GetEffectivePolicyForAppInstalls(const std::string& app_id,
int* install_policy) const override {
return false;
}
bool GetEffectivePolicyForAppUpdates(const std::string& app_id,
int* update_policy) const override {
return false;
}
bool GetTargetVersionPrefix(
const std::string& app_id,
std::string* target_version_prefix) const override {
return false;
}
bool IsRollbackToTargetVersionAllowed(const std::string& app_id,
bool* rollback_allowed) const override {
return false;
}
bool GetProxyMode(std::string* proxy_mode) const override { return false; }
bool GetProxyPacUrl(std::string* proxy_pac_url) const override {
return false;
}
bool GetProxyServer(std::string* proxy_server) const override {
return false;
}
bool GetTargetChannel(const std::string& app_id,
std::string* channel) const override {
auto value = channels_.find(app_id);
if (value == channels_.end())
return false;
*channel = value->second;
return true;
}
void SetChannel(const std::string& app_id, std::string channel) {
channels_[app_id] = std::move(channel);
}
static std::unique_ptr<FakePolicyManager> GetTestingPolicyManager(
std::string source,
bool managed) {
auto manager = std::make_unique<FakePolicyManager>();
manager->source_ = std::move(source);
manager->managed_ = managed;
return manager;
}
private:
std::string source_;
std::map<std::string, std::string> channels_;
bool managed_;
};
TEST(PolicyService, ReturnsHighestPriorityManagedPolicyManager) {
std::unique_ptr<PolicyService> policy_service(GetUpdaterPolicyService());
std::vector<std::unique_ptr<PolicyManagerInterface>> managers;
managers.emplace_back(
FakePolicyManager::GetTestingPolicyManager("highest_unmanaged", false));
managers.emplace_back(
FakePolicyManager::GetTestingPolicyManager("highest_managed", true));
managers.emplace_back(
FakePolicyManager::GetTestingPolicyManager("managed", true));
managers.emplace_back(
FakePolicyManager::GetTestingPolicyManager("lowest_managed", true));
managers.emplace_back(
FakePolicyManager::GetTestingPolicyManager("lowest_unmanaged", false));
policy_service->SetPolicyManagersForTesting(std::move(managers));
ASSERT_EQ("highest_managed",
policy_service->GetActivePolicyManager().source());
}
TEST(PolicyService, ReturnsDefaultPolicyManager) {
std::unique_ptr<PolicyService> policy_service(GetUpdaterPolicyService());
policy_service->SetPolicyManagersForTesting({});
ASSERT_EQ("default", policy_service->GetActivePolicyManager().source());
}
TEST(PolicyService, TargetChannelUnmanagedSource) {
std::unique_ptr<PolicyService> policy_service(GetUpdaterPolicyService());
auto manager = FakePolicyManager::GetTestingPolicyManager("unmanaged", false);
manager->SetChannel("", "channel");
std::vector<std::unique_ptr<PolicyManagerInterface>> managers;
managers.emplace_back(std::move(manager));
policy_service->SetPolicyManagersForTesting(std::move(managers));
std::string channel;
policy_service->GetTargetChannel("", &channel);
ASSERT_TRUE(channel.empty());
}
TEST(PolicyService, TargetChannelManagedSource) {
std::unique_ptr<PolicyService> policy_service(GetUpdaterPolicyService());
auto manager = FakePolicyManager::GetTestingPolicyManager("managed", true);
manager->SetChannel("", "channel");
std::vector<std::unique_ptr<PolicyManagerInterface>> managers;
managers.emplace_back(std::move(manager));
policy_service->SetPolicyManagersForTesting(std::move(managers));
std::string channel;
policy_service->GetTargetChannel("", &channel);
ASSERT_EQ(channel, "channel");
}
} // namespace updater
......@@ -129,6 +129,24 @@ message ApplicationSettings {
// specified by "Target version prefix override" will be downgraded to the
// highest available version that matches the target version.
optional RollbackToTargetVersionValue rollback_to_target_version = 6;
// Gcpw specific application setting which contains a list of domains from
// which the user is allowed to login.
optional GcpwSpecificApplicationSettings gcpw_application_settings = 7;
// Target Channel
//
// Specifies the channel to which <app> should be updated.
//
// When this policy is set, the binaries returned by Google Update will be the
// binaries for the specified channel. If this policy is not set, the default
// channel will be used.
optional string target_channel = 8;
}
message GcpwSpecificApplicationSettings {
// List of domains from which the user is allowed to login.
repeated string domains_allowed_to_login = 1;
}
message OmahaSettingsClientProto {
......
......@@ -48,6 +48,7 @@ const base::char16 kRegValueInstallAppPrefix[] = L"Install";
const base::char16 kRegValueUpdateAppsDefault[] = L"UpdateDefault";
const base::char16 kRegValueUpdateAppPrefix[] = L"Update";
const base::char16 kRegValueTargetVersionPrefix[] = L"TargetVersionPrefix";
const base::char16 kRegValueTargetChannel[] = L"TargetChannel";
const base::char16 kRegValueRollbackToTargetVersion[] =
L"RollbackToTargetVersion";
......@@ -112,6 +113,13 @@ bool GroupPolicyManager::GetEffectivePolicyForAppUpdates(
: ReadValueDW(kRegValueUpdateAppsDefault, update_policy);
}
bool GroupPolicyManager::GetTargetChannel(const std::string& app_id,
std::string* channel) const {
base::string16 app_value_name(kRegValueTargetChannel);
app_value_name.append(base::SysUTF8ToWide(app_id));
return ReadValue(app_value_name.c_str(), channel);
}
bool GroupPolicyManager::GetTargetVersionPrefix(
const std::string& app_id,
std::string* target_version_prefix) const {
......
......@@ -39,6 +39,8 @@ class GroupPolicyManager : public PolicyManagerInterface {
int* install_policy) const override;
bool GetEffectivePolicyForAppUpdates(const std::string& app_id,
int* update_policy) const override;
bool GetTargetChannel(const std::string& app_id,
std::string* channel) const override;
bool GetTargetVersionPrefix(
const std::string& app_id,
std::string* target_version_prefix) const override;
......
......@@ -103,6 +103,8 @@ struct App {
std::string cohort_hint; // Server may use to move the app to a new cohort.
std::string cohort_name; // Human-readable interpretation of the cohort.
std::string release_channel;
base::Optional<bool> enabled;
base::Optional<std::vector<int>> disabled_reasons;
......
......@@ -193,6 +193,7 @@ protocol_request::App MakeProtocolApp(
const std::string& cohort,
const std::string& cohort_hint,
const std::string& cohort_name,
const std::string& release_channel,
const std::vector<int>& disabled_reasons,
base::Optional<protocol_request::UpdateCheck> update_check,
base::Optional<protocol_request::Ping> ping) {
......@@ -205,6 +206,7 @@ protocol_request::App MakeProtocolApp(
app.cohort = cohort;
app.cohort_hint = cohort_hint;
app.cohort_name = cohort_name;
app.release_channel = release_channel;
app.enabled = disabled_reasons.empty();
app.disabled_reasons = disabled_reasons;
app.update_check = std::move(update_check);
......
......@@ -60,6 +60,7 @@ protocol_request::App MakeProtocolApp(
const std::string& cohort,
const std::string& cohort_hint,
const std::string& cohort_name,
const std::string& release_channel,
const std::vector<int>& disabled_reasons,
base::Optional<protocol_request::UpdateCheck> update_check,
base::Optional<protocol_request::Ping> ping);
......
......@@ -97,6 +97,10 @@ std::string ProtocolSerializerJSON::Serialize(
app_node.SetKey("installsource", Value(app.install_source));
if (!app.install_location.empty())
app_node.SetKey("installedby", Value(app.install_location));
// TODO(crbug/1120685): Test that this is never sent to the server if the
// machine is not enterprise managed.
if (!app.release_channel.empty())
app_node.SetKey("release_channel", Value(app.release_channel));
if (!app.cohort.empty())
app_node.SetKey("cohort", Value(app.cohort));
if (!app.cohort_name.empty())
......
......@@ -47,7 +47,7 @@ TEST(SerializeRequestJSON, Serialize) {
std::vector<protocol_request::App> apps;
apps.push_back(MakeProtocolApp(
"id1", base::Version("1.0"), "brand1", "source1", "location1", "fp1",
{{"attr1", "1"}, {"attr2", "2"}}, "c1", "ch1", "cn1", {0, 1},
{{"attr1", "1"}, {"attr2", "2"}}, "c1", "ch1", "cn1", "test", {0, 1},
MakeProtocolUpdateCheck(true), MakeProtocolPing("id1", metadata.get())));
apps.push_back(
MakeProtocolApp("id2", base::Version("2.0"), std::move(events)));
......@@ -65,6 +65,7 @@ TEST(SerializeRequestJSON, Serialize) {
R"("installedby":"location1","installsource":"source1",)"
R"("packages":{"package":\[{"fp":"fp1"}]},)"
R"("ping":{"ping_freshness":"{[-\w]{36}}","rd":1234},)"
R"("release_channel":"test",)"
R"("updatecheck":{"updatedisabled":true},"version":"1.0"},)"
R"({"appid":"id2","event":\[{"a":1,"b":"2"},{"error":0}],)"
R"("version":"2.0"}],"arch":"\w+","dedup":"cr","dlpref":"cacheable",)"
......@@ -74,7 +75,7 @@ TEST(SerializeRequestJSON, Serialize) {
R"("prodversion":"1.0","protocol":"3.1","requestid":"{[-\w]{36}}",)"
R"("sessionid":"{[-\w]{36}}","updaterchannel":"channel",)"
R"("updaterversion":"1.0"(,"wow64":true)?}})";
EXPECT_TRUE(RE2::FullMatch(request, regex)) << request;
EXPECT_TRUE(RE2::FullMatch(request, regex)) << request << "\n VS \n" << regex;
}
TEST(SerializeRequestJSON, DownloadPreference) {
......
......@@ -200,7 +200,8 @@ void UpdateCheckerImpl::CheckForUpdatesHelper(
crx_component->fingerprint,
SanitizeInstallerAttributes(crx_component->installer_attributes),
metadata_->GetCohort(app_id), metadata_->GetCohortName(app_id),
metadata_->GetCohortHint(app_id), crx_component->disabled_reasons,
metadata_->GetCohortHint(app_id), crx_component->channel,
crx_component->disabled_reasons,
MakeProtocolUpdateCheck(is_update_disabled),
MakeProtocolPing(app_id, metadata_)));
}
......
......@@ -315,6 +315,11 @@ struct CrxComponent {
// For extensions, this information is inferred from the extension
// registry.
std::string install_location;
// Information about the channel to send to the update server when updating
// the component. This optional field is typically populated by policy and is
// only populated on managed devices.
std::string channel;
};
// Called when a non-blocking call of UpdateClient completes.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment