Commit 2644fc8d authored by Yann Dago's avatar Yann Dago Committed by Commit Bot

Use IPolicyStatus2 to get the updater's policies and state.

Use the new COM interface to show the updater's policies and conflicts.
Use the new interface to get the updater's version and the last time
policies were fetched. Maintain compatibility with IPolicyStatus so
that machine with older versions of the updater still show policies.

Bug: 1032756
Change-Id: Iadb2199bcdc704a426e80e00e2bb8aa5b21e0648
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2380582
Commit-Queue: Yann Dago <ydago@chromium.org>
Reviewed-by: default avatarS. Ganesh <ganesh@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814536}
parent d90a982c
...@@ -4619,6 +4619,8 @@ static_library("browser") { ...@@ -4619,6 +4619,8 @@ static_library("browser") {
"component_updater/third_party_module_list_component_installer_win.h", "component_updater/third_party_module_list_component_installer_win.h",
"google/google_update_policy_fetcher_win.cc", "google/google_update_policy_fetcher_win.cc",
"google/google_update_policy_fetcher_win.h", "google/google_update_policy_fetcher_win.h",
"google/google_update_policy_fetcher_win_util.cc",
"google/google_update_policy_fetcher_win_util.h",
"google/google_update_win.cc", "google/google_update_win.cc",
"google/google_update_win.h", "google/google_update_win.h",
"google/switches.cc", "google/switches.cc",
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <memory> #include <memory>
#include "base/strings/string16.h"
#include "base/time/time.h"
#include "base/values.h" #include "base/values.h"
#include "components/policy/core/browser/policy_conversions.h" #include "components/policy/core/browser/policy_conversions.h"
...@@ -14,6 +16,18 @@ namespace policy { ...@@ -14,6 +16,18 @@ namespace policy {
class PolicyMap; class PolicyMap;
} }
struct GoogleUpdateState {
base::string16 version;
base::Time last_checked_time;
};
struct GoogleUpdatePoliciesAndState {
GoogleUpdatePoliciesAndState();
~GoogleUpdatePoliciesAndState();
std::unique_ptr<policy::PolicyMap> policies;
std::unique_ptr<GoogleUpdateState> state;
};
// Returns a list of all the Google Update policies available through the // Returns a list of all the Google Update policies available through the
// IPolicyStatus COM interface. // IPolicyStatus COM interface.
base::Value GetGoogleUpdatePolicyNames(); base::Value GetGoogleUpdatePolicyNames();
...@@ -22,11 +36,11 @@ base::Value GetGoogleUpdatePolicyNames(); ...@@ -22,11 +36,11 @@ base::Value GetGoogleUpdatePolicyNames();
// IPolicyStatus COM interface. // IPolicyStatus COM interface.
policy::PolicyConversions::PolicyToSchemaMap GetGoogleUpdatePolicySchemas(); policy::PolicyConversions::PolicyToSchemaMap GetGoogleUpdatePolicySchemas();
// Fetches all the Google Update Policies available through the IPolicyStatus // Fetches all the Google Update Policies and state values available through the
// COM interface. Only the policies that have been set are returned by this // IPolicyStatus2 or IPolicyStatus COM interface. Only the policies that have
// function. This function returns null if the fetch fails because IPolicyStatus // been set are returned by this function. This function returns null if the
// could not be instantiated. This function must run on a COM STA thread because // fetch fails because IPolicyStatus interface could not be instantiated. This
// it makes some COM calls. // function must run on a COM STA thread because it makes some COM calls.
std::unique_ptr<policy::PolicyMap> GetGoogleUpdatePolicies(); std::unique_ptr<GoogleUpdatePoliciesAndState> GetGoogleUpdatePoliciesAndState();
#endif // CHROME_BROWSER_GOOGLE_GOOGLE_UPDATE_POLICY_FETCHER_WIN_H_ #endif // CHROME_BROWSER_GOOGLE_GOOGLE_UPDATE_POLICY_FETCHER_WIN_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 "chrome/browser/google/google_update_policy_fetcher_win_util.h"
#include <OleCtl.h>
#include "base/check.h"
#include "base/strings/string_piece.h"
#include "base/values.h"
#include "base/win/scoped_bstr.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_types.h"
namespace {
policy::PolicySource GetPolicySource(BSTR source_bstr) {
constexpr base::WStringPiece kCloudSource = L"Device Management";
constexpr base::WStringPiece kDefaultSource = L"Default";
const auto source =
base::WStringPiece(source_bstr, ::SysStringLen(source_bstr));
if (source == kCloudSource)
return policy::POLICY_SOURCE_CLOUD;
if (source == kDefaultSource)
return policy::POLICY_SOURCE_ENTERPRISE_DEFAULT;
DCHECK_EQ(source, base::WStringPiece(L"Group Policy"));
return policy::POLICY_SOURCE_PLATFORM;
}
} // namespace
std::unique_ptr<policy::PolicyMap::Entry> ConvertPolicyStatusValueToPolicyEntry(
IPolicyStatusValue* policy,
const PolicyValueOverrideFunction& value_override_function) {
DCHECK(policy);
base::win::ScopedBstr value;
if (FAILED(policy->get_value(value.Receive())) || value.Length() == 0) {
return nullptr;
}
base::win::ScopedBstr source;
if (FAILED(policy->get_source(source.Receive())))
return nullptr;
auto entry = std::make_unique<policy::PolicyMap::Entry>(
policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_MACHINE,
GetPolicySource(source.Get()),
value_override_function ? value_override_function.Run(value.Get())
: base::Value(value.Get()),
nullptr);
VARIANT_BOOL has_conflict = VARIANT_FALSE;
base::win::ScopedBstr conflict_value;
base::win::ScopedBstr conflict_source;
if (SUCCEEDED(policy->get_hasConflict(&has_conflict)) &&
has_conflict == VARIANT_TRUE &&
SUCCEEDED(policy->get_conflictValue(conflict_value.Receive())) &&
SUCCEEDED(policy->get_conflictSource(conflict_source.Receive()))) {
entry->AddConflictingPolicy(policy::PolicyMap::Entry(
policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_MACHINE,
GetPolicySource(conflict_source.Get()),
value_override_function
? value_override_function.Run(conflict_value.Get())
: base::Value(conflict_value.Get()),
nullptr));
}
if (entry->source == policy::POLICY_SOURCE_ENTERPRISE_DEFAULT)
entry->SetIsDefaultValue();
return entry;
}
// 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_BROWSER_GOOGLE_GOOGLE_UPDATE_POLICY_FETCHER_WIN_UTIL_H_
#define CHROME_BROWSER_GOOGLE_GOOGLE_UPDATE_POLICY_FETCHER_WIN_UTIL_H_
#include <wtypes.h>
#include <memory>
#include "base/callback.h"
#include "base/values.h"
#include "components/policy/core/common/policy_map.h"
#include "google_update/google_update_idl.h"
using PolicyValueOverrideFunction = base::RepeatingCallback<base::Value(BSTR)>;
// Converts a |policy| into a PolicyMap::Entry. |value_override_function|
// is an optional callback that modifies the value of the resulting policy.
std::unique_ptr<policy::PolicyMap::Entry> ConvertPolicyStatusValueToPolicyEntry(
IPolicyStatusValue* policy,
const PolicyValueOverrideFunction& value_override_function);
#endif // CHROME_BROWSER_GOOGLE_GOOGLE_UPDATE_POLICY_FETCHER_WIN_UTIL_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 "chrome/browser/google/google_update_policy_fetcher_win_util.h"
#include <OleCtl.h>
#include <wtypes.h>
#include "base/test/bind_test_util.h"
#include "base/values.h"
#include "base/win/scoped_bstr.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_types.h"
#include "google_update/google_update_idl.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
struct MockPolicyStatusValue : public IPolicyStatusValue {
public:
MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, get_source, HRESULT(BSTR*));
MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, get_value, HRESULT(BSTR*));
MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
get_hasConflict,
HRESULT(VARIANT_BOOL*));
MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
get_conflictSource,
HRESULT(BSTR*));
MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
get_conflictValue,
HRESULT(BSTR*));
// IDispatch:
MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE,
GetTypeInfoCount,
HRESULT(UINT*));
MOCK_METHOD3_WITH_CALLTYPE(STDMETHODCALLTYPE,
GetTypeInfo,
HRESULT(UINT, LCID, ITypeInfo**));
MOCK_METHOD5_WITH_CALLTYPE(STDMETHODCALLTYPE,
GetIDsOfNames,
HRESULT(REFIID, LPOLESTR*, UINT, LCID, DISPID*));
MOCK_METHOD8_WITH_CALLTYPE(STDMETHODCALLTYPE,
Invoke,
HRESULT(DISPID,
REFIID,
LCID,
WORD,
DISPPARAMS*,
VARIANT*,
EXCEPINFO*,
UINT*));
// IUnknown:
MOCK_METHOD2_WITH_CALLTYPE(STDMETHODCALLTYPE,
QueryInterface,
HRESULT(REFIID,
_COM_Outptr_ void __RPC_FAR* __RPC_FAR*));
MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, AddRef, ULONG(void));
MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, Release, ULONG(void));
};
} // namespace
TEST(ConvertPolicyStatusValueToPolicyEntry, DefaultSource) {
MockPolicyStatusValue policy_status_value;
base::win::ScopedBstr value(L"value");
base::win::ScopedBstr source(L"Default");
VARIANT_BOOL has_conflict = VARIANT_FALSE;
EXPECT_CALL(policy_status_value, get_value(testing::_))
.WillOnce(testing::DoAll(testing::SetArgPointee<0>(value.Get()),
testing::Return(S_OK)));
EXPECT_CALL(policy_status_value, get_source(testing::_))
.WillOnce(testing::DoAll(testing::SetArgPointee<0>(source.Get()),
testing::Return(S_OK)));
EXPECT_CALL(policy_status_value, get_hasConflict(testing::_))
.WillOnce(testing::DoAll(testing::SetArgPointee<0>(has_conflict),
testing::Return(S_OK)));
policy::PolicyMap::Entry expected(
policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_MACHINE,
policy::POLICY_SOURCE_ENTERPRISE_DEFAULT, base::Value("value"), nullptr);
expected.SetIsDefaultValue();
auto actual = ConvertPolicyStatusValueToPolicyEntry(
&policy_status_value, PolicyValueOverrideFunction());
EXPECT_TRUE(expected.Equals(*actual));
}
TEST(ConvertPolicyStatusValueToPolicyEntry, CloudSource) {
MockPolicyStatusValue policy_status_value;
base::win::ScopedBstr value(L"1");
base::win::ScopedBstr source(L"Device Management");
VARIANT_BOOL has_conflict = VARIANT_FALSE;
EXPECT_CALL(policy_status_value, get_value(testing::_))
.WillOnce(testing::DoAll(testing::SetArgPointee<0>(value.Get()),
testing::Return(S_OK)));
EXPECT_CALL(policy_status_value, get_source(testing::_))
.WillOnce(testing::DoAll(testing::SetArgPointee<0>(source.Get()),
testing::Return(S_OK)));
EXPECT_CALL(policy_status_value, get_hasConflict(testing::_))
.WillOnce(testing::DoAll(testing::SetArgPointee<0>(has_conflict),
testing::Return(S_OK)));
policy::PolicyMap::Entry expected(
policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_MACHINE,
policy::POLICY_SOURCE_CLOUD, base::Value("1"), nullptr);
auto actual = ConvertPolicyStatusValueToPolicyEntry(
&policy_status_value, PolicyValueOverrideFunction());
EXPECT_TRUE(expected.Equals(*actual));
}
TEST(ConvertPolicyStatusValueToPolicyEntry, Conflict) {
MockPolicyStatusValue policy_status_value;
base::win::ScopedBstr value(L"a");
base::win::ScopedBstr source(L"Group Policy");
VARIANT_BOOL has_conflict = VARIANT_TRUE;
base::win::ScopedBstr conflict_value(L"ab");
base::win::ScopedBstr conflict_source(L"Device Management");
EXPECT_CALL(policy_status_value, get_value(testing::_))
.WillOnce(testing::DoAll(testing::SetArgPointee<0>(value.Get()),
testing::Return(S_OK)));
EXPECT_CALL(policy_status_value, get_source(testing::_))
.WillOnce(testing::DoAll(testing::SetArgPointee<0>(source.Get()),
testing::Return(S_OK)));
EXPECT_CALL(policy_status_value, get_hasConflict(testing::_))
.WillOnce(testing::DoAll(testing::SetArgPointee<0>(has_conflict),
testing::Return(S_OK)));
EXPECT_CALL(policy_status_value, get_conflictValue(testing::_))
.WillOnce(testing::DoAll(testing::SetArgPointee<0>(conflict_value.Get()),
testing::Return(S_OK)));
EXPECT_CALL(policy_status_value, get_conflictSource(testing::_))
.WillOnce(testing::DoAll(testing::SetArgPointee<0>(conflict_source.Get()),
testing::Return(S_OK)));
policy::PolicyMap::Entry expected(
policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_MACHINE,
policy::POLICY_SOURCE_PLATFORM, base::Value(false), nullptr);
policy::PolicyMap::Entry conflict(
policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_MACHINE,
policy::POLICY_SOURCE_CLOUD, base::Value(true), nullptr);
expected.AddConflictingPolicy(std::move(conflict));
const auto override_value = [](BSTR initial_value) {
return base::Value(::SysStringLen(initial_value) > 1);
};
auto actual = ConvertPolicyStatusValueToPolicyEntry(
&policy_status_value, base::BindRepeating(override_value));
EXPECT_TRUE(expected.Equals(*actual));
}
TEST(ConvertPolicyStatusValueToPolicyEntry, ValueError) {
MockPolicyStatusValue policy_status_value;
base::win::ScopedBstr value(L"a");
base::win::ScopedBstr source(L"Group Policy");
VARIANT_BOOL has_conflict = VARIANT_TRUE;
base::win::ScopedBstr conflict_value(L"ab");
base::win::ScopedBstr conflict_source(L"Device Management");
policy::PolicyMap::Entry expected(
policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_MACHINE,
policy::POLICY_SOURCE_PLATFORM, base::Value("a"), nullptr);
// No policy created if we fail to get the value.
EXPECT_CALL(policy_status_value, get_value(testing::_))
.WillOnce(testing::Return(-1))
.WillRepeatedly(testing::DoAll(testing::SetArgPointee<0>(value.Get()),
testing::Return(S_OK)));
EXPECT_EQ(nullptr, ConvertPolicyStatusValueToPolicyEntry(
&policy_status_value, PolicyValueOverrideFunction())
.get());
// No policy created if we fail to get the source.
EXPECT_CALL(policy_status_value, get_source(testing::_))
.WillOnce(testing::Return(-1))
.WillRepeatedly(testing::DoAll(testing::SetArgPointee<0>(source.Get()),
testing::Return(S_OK)));
EXPECT_EQ(nullptr, ConvertPolicyStatusValueToPolicyEntry(
&policy_status_value, PolicyValueOverrideFunction())
.get());
// No conflict added if we fail to get any of the conflict info.
EXPECT_CALL(policy_status_value, get_hasConflict(testing::_))
.WillOnce(testing::Return(-1))
.WillRepeatedly(testing::DoAll(testing::SetArgPointee<0>(has_conflict),
testing::Return(S_OK)));
EXPECT_TRUE(expected.Equals(*ConvertPolicyStatusValueToPolicyEntry(
&policy_status_value, PolicyValueOverrideFunction())));
// No conflict added if we fail to get any of the conflict value.
EXPECT_CALL(policy_status_value, get_conflictValue(testing::_))
.WillOnce(testing::Return(-1))
.WillRepeatedly(
testing::DoAll(testing::SetArgPointee<0>(conflict_value.Get()),
testing::Return(S_OK)));
EXPECT_TRUE(expected.Equals(*ConvertPolicyStatusValueToPolicyEntry(
&policy_status_value, PolicyValueOverrideFunction())));
// No conflict added if we fail to get any of the conflict info.
EXPECT_CALL(policy_status_value, get_conflictSource(testing::_))
.WillOnce(testing::Return(-1));
EXPECT_TRUE(expected.Equals(*ConvertPolicyStatusValueToPolicyEntry(
&policy_status_value, PolicyValueOverrideFunction())));
}
...@@ -114,7 +114,6 @@ ...@@ -114,7 +114,6 @@
#include "chrome/browser/google/google_update_policy_fetcher_win.h" #include "chrome/browser/google/google_update_policy_fetcher_win.h"
#include "chrome/install_static/install_util.h" #include "chrome/install_static/install_util.h"
#include "components/update_client/updater_state.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING) #endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
...@@ -450,13 +449,14 @@ class UpdaterStatusProvider : public PolicyStatusProvider { ...@@ -450,13 +449,14 @@ class UpdaterStatusProvider : public PolicyStatusProvider {
public: public:
UpdaterStatusProvider(); UpdaterStatusProvider();
~UpdaterStatusProvider() override = default; ~UpdaterStatusProvider() override = default;
void SetUpdaterStatus(std::unique_ptr<GoogleUpdateState> status);
void GetStatus(base::DictionaryValue* dict) override; void GetStatus(base::DictionaryValue* dict) override;
private: private:
static std::string FetchActiveDirectoryDomain(); static std::string FetchActiveDirectoryDomain();
void OnDomainReceived(std::string domain); void OnDomainReceived(std::string domain);
std::string version_; std::unique_ptr<GoogleUpdateState> updater_status_;
std::string domain_; std::string domain_;
base::WeakPtrFactory<UpdaterStatusProvider> weak_factory_{this}; base::WeakPtrFactory<UpdaterStatusProvider> weak_factory_{this};
}; };
...@@ -739,12 +739,6 @@ void DeviceActiveDirectoryPolicyStatusProvider::GetStatus( ...@@ -739,12 +739,6 @@ void DeviceActiveDirectoryPolicyStatusProvider::GetStatus(
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING) #if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
UpdaterStatusProvider::UpdaterStatusProvider() { UpdaterStatusProvider::UpdaterStatusProvider() {
auto state =
update_client::UpdaterState::GetState(install_static::IsSystemInstall());
const auto& version = state->find("version");
if (version != state->end())
version_ = version->second;
base::ThreadPool::PostTaskAndReplyWithResult( base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE, FROM_HERE,
{base::ThreadPool(), base::MayBlock(), {base::ThreadPool(), base::MayBlock(),
...@@ -754,11 +748,24 @@ UpdaterStatusProvider::UpdaterStatusProvider() { ...@@ -754,11 +748,24 @@ UpdaterStatusProvider::UpdaterStatusProvider() {
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
void UpdaterStatusProvider::SetUpdaterStatus(
std::unique_ptr<GoogleUpdateState> status) {
updater_status_ = std::move(status);
NotifyStatusChange();
}
void UpdaterStatusProvider::GetStatus(base::DictionaryValue* dict) { void UpdaterStatusProvider::GetStatus(base::DictionaryValue* dict) {
if (!version_.empty())
dict->SetString("version", version_);
if (!domain_.empty()) if (!domain_.empty())
dict->SetString("domain", domain_); dict->SetStringKey("domain", domain_);
if (!updater_status_)
return;
if (!updater_status_->version.empty())
dict->SetStringKey("version", updater_status_->version);
if (!updater_status_->last_checked_time.is_null()) {
dict->SetStringKey(
"timeSinceLastRefresh",
GetTimeSinceLastRefreshString(updater_status_->last_checked_time));
}
} }
// static // static
...@@ -780,7 +787,8 @@ void UpdaterStatusProvider::OnDomainReceived(std::string domain) { ...@@ -780,7 +787,8 @@ void UpdaterStatusProvider::OnDomainReceived(std::string domain) {
domain_ = std::move(domain); domain_ = std::move(domain);
NotifyStatusChange(); NotifyStatusChange();
} }
#endif
#endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
PolicyUIHandler::PolicyUIHandler() {} PolicyUIHandler::PolicyUIHandler() {}
...@@ -826,6 +834,7 @@ void PolicyUIHandler::AddCommonLocalizedStringsToSource( ...@@ -826,6 +834,7 @@ void PolicyUIHandler::AddCommonLocalizedStringsToSource(
{"unknown", IDS_POLICY_UNKNOWN}, {"unknown", IDS_POLICY_UNKNOWN},
{"unset", IDS_POLICY_UNSET}, {"unset", IDS_POLICY_UNSET},
{"value", IDS_POLICY_LABEL_VALUE}, {"value", IDS_POLICY_LABEL_VALUE},
{"sourceDefault", IDS_POLICY_SOURCE_DEFAULT},
}; };
AddLocalizedStringsBulk(source, kStrings); AddLocalizedStringsBulk(source, kStrings);
...@@ -895,7 +904,7 @@ void PolicyUIHandler::RegisterMessages() { ...@@ -895,7 +904,7 @@ void PolicyUIHandler::RegisterMessages() {
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING) #if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
ReloadUpdaterPolicies(); ReloadUpdaterPoliciesAndState();
#endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING) #endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
if (!user_status_provider_.get()) if (!user_status_provider_.get())
...@@ -1179,7 +1188,7 @@ void PolicyUIHandler::HandleReloadPolicies(const base::ListValue* args) { ...@@ -1179,7 +1188,7 @@ void PolicyUIHandler::HandleReloadPolicies(const base::ListValue* args) {
#endif #endif
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING) #if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
ReloadUpdaterPolicies(); ReloadUpdaterPoliciesAndState();
#endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING) #endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
GetPolicyService()->RefreshPolicies(base::BindOnce( GetPolicyService()->RefreshPolicies(base::BindOnce(
...@@ -1286,14 +1295,16 @@ void PolicyUIHandler::SendPolicies() { ...@@ -1286,14 +1295,16 @@ void PolicyUIHandler::SendPolicies() {
} }
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING) #if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
void PolicyUIHandler::SetUpdaterPolicies( void PolicyUIHandler::SetUpdaterPoliciesAndState(
std::unique_ptr<policy::PolicyMap> updater_policies) { std::unique_ptr<GoogleUpdatePoliciesAndState> updater_policies_and_state) {
updater_policies_ = std::move(updater_policies); updater_policies_ = std::move(updater_policies_and_state->policies);
static_cast<UpdaterStatusProvider*>(updater_status_provider_.get())
->SetUpdaterStatus(std::move(updater_policies_and_state->state));
if (updater_policies_) if (updater_policies_)
SendPolicies(); SendPolicies();
} }
void PolicyUIHandler::ReloadUpdaterPolicies() { void PolicyUIHandler::ReloadUpdaterPoliciesAndState() {
if (!updater_status_provider_) if (!updater_status_provider_)
updater_status_provider_ = std::make_unique<UpdaterStatusProvider>(); updater_status_provider_ = std::make_unique<UpdaterStatusProvider>();
base::PostTaskAndReplyWithResult( base::PostTaskAndReplyWithResult(
...@@ -1301,8 +1312,8 @@ void PolicyUIHandler::ReloadUpdaterPolicies() { ...@@ -1301,8 +1312,8 @@ void PolicyUIHandler::ReloadUpdaterPolicies() {
{base::TaskPriority::USER_BLOCKING, {base::TaskPriority::USER_BLOCKING,
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN, base::MayBlock()}) base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN, base::MayBlock()})
.get(), .get(),
FROM_HERE, base::BindOnce(&GetGoogleUpdatePolicies), FROM_HERE, base::BindOnce(&GetGoogleUpdatePoliciesAndState),
base::BindOnce(&PolicyUIHandler::SetUpdaterPolicies, base::BindOnce(&PolicyUIHandler::SetUpdaterPoliciesAndState,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#endif #endif
class PolicyStatusProvider; class PolicyStatusProvider;
struct GoogleUpdatePoliciesAndState;
namespace policy { namespace policy {
class PolicyMap; class PolicyMap;
...@@ -97,11 +98,13 @@ class PolicyUIHandler : public content::WebUIMessageHandler, ...@@ -97,11 +98,13 @@ class PolicyUIHandler : public content::WebUIMessageHandler,
void SendPolicies(); void SendPolicies();
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING) #if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Sets |updater_policies_| in this instance and refreshes the UI via // Sets |updater_policies_| in this instance, updates
// |updater_status_provider_| with a new state and refreshes the UI via
// SendPolicies. // SendPolicies.
void SetUpdaterPolicies(std::unique_ptr<policy::PolicyMap> updater_policies); void SetUpdaterPoliciesAndState(
std::unique_ptr<GoogleUpdatePoliciesAndState> updater_policies_and_state);
void ReloadUpdaterPolicies(); void ReloadUpdaterPoliciesAndState();
#endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING) #endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Send the status of cloud policy to the UI. For each scope that has cloud // Send the status of cloud policy to the UI. For each scope that has cloud
......
...@@ -5828,7 +5828,10 @@ test("unit_tests") { ...@@ -5828,7 +5828,10 @@ test("unit_tests") {
] ]
if (is_chrome_branded) { if (is_chrome_branded) {
sources += [ "../browser/google/google_update_win_unittest.cc" ] sources += [
"../browser/google/google_update_policy_fetcher_win_util_unittest.cc",
"../browser/google/google_update_win_unittest.cc",
]
} }
} }
if (!is_android && !is_chromeos) { if (!is_android && !is_chromeos) {
......
...@@ -153,7 +153,9 @@ Value PolicyConversionsClient::GetPolicyValue( ...@@ -153,7 +153,9 @@ Value PolicyConversionsClient::GetPolicyValue(
value.SetKey("level", Value(Value((policy.level == POLICY_LEVEL_RECOMMENDED) value.SetKey("level", Value(Value((policy.level == POLICY_LEVEL_RECOMMENDED)
? "recommended" ? "recommended"
: "mandatory"))); : "mandatory")));
value.SetKey("source", Value(kPolicySources[policy.source].name)); value.SetKey("source", Value(policy.IsDefaultValue()
? "sourceDefault"
: kPolicySources[policy.source].name));
} else { } else {
value.SetKey("scope", Value(policy.scope)); value.SetKey("scope", Value(policy.scope));
value.SetKey("level", Value(policy.level)); value.SetKey("level", Value(policy.level));
......
...@@ -67,6 +67,7 @@ PolicyMap::Entry PolicyMap::Entry::DeepCopy() const { ...@@ -67,6 +67,7 @@ PolicyMap::Entry PolicyMap::Entry::DeepCopy() const {
copy.error_strings_ = error_strings_; copy.error_strings_ = error_strings_;
copy.error_message_ids_ = error_message_ids_; copy.error_message_ids_ = error_message_ids_;
copy.warning_message_ids_ = warning_message_ids_; copy.warning_message_ids_ = warning_message_ids_;
copy.is_default_value_ = is_default_value_;
copy.conflicts.reserve(conflicts.size()); copy.conflicts.reserve(conflicts.size());
for (const auto& conflict : conflicts) { for (const auto& conflict : conflicts) {
copy.AddConflictingPolicy(conflict.DeepCopy()); copy.AddConflictingPolicy(conflict.DeepCopy());
...@@ -96,6 +97,7 @@ bool PolicyMap::Entry::Equals(const PolicyMap::Entry& other) const { ...@@ -96,6 +97,7 @@ bool PolicyMap::Entry::Equals(const PolicyMap::Entry& other) const {
error_strings_ == other.error_strings_ && error_strings_ == other.error_strings_ &&
error_message_ids_ == other.error_message_ids_ && error_message_ids_ == other.error_message_ids_ &&
warning_message_ids_ == other.warning_message_ids_ && warning_message_ids_ == other.warning_message_ids_ &&
is_default_value_ == other.is_default_value_ &&
((!value_ && !other.value()) || ((!value_ && !other.value()) ||
(value_ && other.value() && *value_ == *other.value())) && (value_ && other.value() && *value_ == *other.value())) &&
ExternalDataFetcher::Equals(external_data_fetcher.get(), ExternalDataFetcher::Equals(external_data_fetcher.get(),
...@@ -171,6 +173,14 @@ bool PolicyMap::Entry::IsIgnoredByAtomicGroup() const { ...@@ -171,6 +173,14 @@ bool PolicyMap::Entry::IsIgnoredByAtomicGroup() const {
error_message_ids_.end(); error_message_ids_.end();
} }
void PolicyMap::Entry::SetIsDefaultValue() {
is_default_value_ = true;
}
bool PolicyMap::Entry::IsDefaultValue() const {
return is_default_value_;
}
PolicyMap::PolicyMap() = default; PolicyMap::PolicyMap() = default;
PolicyMap::~PolicyMap() { PolicyMap::~PolicyMap() {
......
...@@ -102,6 +102,11 @@ class POLICY_EXPORT PolicyMap { ...@@ -102,6 +102,11 @@ class POLICY_EXPORT PolicyMap {
void SetIgnoredByPolicyAtomicGroup(); void SetIgnoredByPolicyAtomicGroup();
bool IsIgnoredByAtomicGroup() const; bool IsIgnoredByAtomicGroup() const;
// Sets that the policy's value is a default value set by the policy
// provider.
void SetIsDefaultValue();
bool IsDefaultValue() const;
// Callback used to look up a localized string given its l10n message ID. It // Callback used to look up a localized string given its l10n message ID. It
// should return a UTF-16 string. // should return a UTF-16 string.
typedef base::RepeatingCallback<base::string16(int message_id)> typedef base::RepeatingCallback<base::string16(int message_id)>
...@@ -118,6 +123,7 @@ class POLICY_EXPORT PolicyMap { ...@@ -118,6 +123,7 @@ class POLICY_EXPORT PolicyMap {
private: private:
base::Optional<base::Value> value_; base::Optional<base::Value> value_;
bool ignored_ = false; bool ignored_ = false;
bool is_default_value_ = false;
std::string error_strings_; std::string error_strings_;
std::set<int> error_message_ids_; std::set<int> error_message_ids_;
std::set<int> warning_message_ids_; std::set<int> warning_message_ids_;
......
...@@ -171,10 +171,12 @@ cr.define('policy', function() { ...@@ -171,10 +171,12 @@ cr.define('policy', function() {
status.isAffiliated ? 'isAffiliatedYes' : 'isAffiliatedNo')); status.isAffiliated ? 'isAffiliatedYes' : 'isAffiliatedNo'));
} }
} }
if (status.timeSinceLastRefresh) {
if (scope !== 'updater') {
this.setLabelAndShow_( this.setLabelAndShow_(
'.time-since-last-refresh', status.timeSinceLastRefresh); '.time-since-last-refresh', status.timeSinceLastRefresh);
}
if (scope !== 'updater') {
this.setLabelAndShow_('.refresh-interval', status.refreshInterval); this.setLabelAndShow_('.refresh-interval', status.refreshInterval);
this.setLabelAndShow_('.status', status.status); this.setLabelAndShow_('.status', status.status);
this.setLabelAndShow_( this.setLabelAndShow_(
......
...@@ -444,6 +444,9 @@ Additional details: ...@@ -444,6 +444,9 @@ Additional details:
<message name="IDS_POLICY_SOURCE_ENTERPRISE_DEFAULT" desc="Indicates that a policy is set by default in an enterprise environment and can be overridden (for Chrome OS only)."> <message name="IDS_POLICY_SOURCE_ENTERPRISE_DEFAULT" desc="Indicates that a policy is set by default in an enterprise environment and can be overridden (for Chrome OS only).">
Enterprise default Enterprise default
</message> </message>
<message name="IDS_POLICY_SOURCE_DEFAULT" desc="Indicates that a policy is set by default and can be overridden.">
Default
</message>
<message name="IDS_POLICY_SOURCE_COMMAND_LINE" desc="Indicates that a policy is set by command line switch for testing purpose."> <message name="IDS_POLICY_SOURCE_COMMAND_LINE" desc="Indicates that a policy is set by command line switch for testing purpose.">
Command line Command line
</message> </message>
......
27e8e99e4c0e7bf60c11bd98395e7bebc3b9ad29
\ No newline at end of file
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