Commit 7a25b6fe authored by Yann Dago's avatar Yann Dago Committed by Commit Bot

Policy WebUI: Add status box for updater policies

Bug: 1032756
Change-Id: I951524da1d6165ede876dc74db74f69291d9d820
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2195086
Commit-Queue: Yann Dago <ydago@chromium.org>
Reviewed-by: default avatarEsmael Elmoslimany <aee@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#768571}
parent 65ae293b
...@@ -24,52 +24,55 @@ content::WebUIDataSource* CreatePolicyUIHtmlSource() { ...@@ -24,52 +24,55 @@ content::WebUIDataSource* CreatePolicyUIHtmlSource() {
PolicyUIHandler::AddCommonLocalizedStringsToSource(source); PolicyUIHandler::AddCommonLocalizedStringsToSource(source);
static constexpr webui::LocalizedString kStrings[] = { static constexpr webui::LocalizedString kStrings[] = {
// Localized strings (alphabetical order). // Localized strings (alphabetical order).
{"exportPoliciesJSON", IDS_EXPORT_POLICIES_JSON}, {"exportPoliciesJSON", IDS_EXPORT_POLICIES_JSON},
{"filterPlaceholder", IDS_POLICY_FILTER_PLACEHOLDER}, {"filterPlaceholder", IDS_POLICY_FILTER_PLACEHOLDER},
{"hideExpandedStatus", IDS_POLICY_HIDE_EXPANDED_STATUS}, {"hideExpandedStatus", IDS_POLICY_HIDE_EXPANDED_STATUS},
{"isAffiliatedYes", IDS_POLICY_IS_AFFILIATED_YES}, {"isAffiliatedYes", IDS_POLICY_IS_AFFILIATED_YES},
{"isAffiliatedNo", IDS_POLICY_IS_AFFILIATED_NO}, {"isAffiliatedNo", IDS_POLICY_IS_AFFILIATED_NO},
{"labelAssetId", IDS_POLICY_LABEL_ASSET_ID}, {"labelAssetId", IDS_POLICY_LABEL_ASSET_ID},
{"labelClientId", IDS_POLICY_LABEL_CLIENT_ID}, {"labelClientId", IDS_POLICY_LABEL_CLIENT_ID},
{"labelDirectoryApiId", IDS_POLICY_LABEL_DIRECTORY_API_ID}, {"labelDirectoryApiId", IDS_POLICY_LABEL_DIRECTORY_API_ID},
{"labelEnterpriseDisplayDomain", {"labelEnterpriseDisplayDomain",
IDS_POLICY_LABEL_ENTERPRISE_DISPLAY_DOMAIN}, IDS_POLICY_LABEL_ENTERPRISE_DISPLAY_DOMAIN},
{"labelEnterpriseEnrollmentDomain", {"labelEnterpriseEnrollmentDomain",
IDS_POLICY_LABEL_ENTERPRISE_ENROLLMENT_DOMAIN}, IDS_POLICY_LABEL_ENTERPRISE_ENROLLMENT_DOMAIN},
{"labelGaiaId", IDS_POLICY_LABEL_GAIA_ID}, {"labelGaiaId", IDS_POLICY_LABEL_GAIA_ID},
{"labelIsAffiliated", IDS_POLICY_LABEL_IS_AFFILIATED}, {"labelIsAffiliated", IDS_POLICY_LABEL_IS_AFFILIATED},
{"labelLocation", IDS_POLICY_LABEL_LOCATION}, {"labelLocation", IDS_POLICY_LABEL_LOCATION},
{"labelMachineEnrollmentDomain", {"labelMachineEnrollmentDomain",
IDS_POLICY_LABEL_MACHINE_ENROLLMENT_DOMAIN}, IDS_POLICY_LABEL_MACHINE_ENROLLMENT_DOMAIN},
{"labelMachineEnrollmentMachineName", {"labelMachineEnrollmentMachineName",
IDS_POLICY_LABEL_MACHINE_ENROLLMENT_MACHINE_NAME}, IDS_POLICY_LABEL_MACHINE_ENROLLMENT_MACHINE_NAME},
{"labelMachineEnrollmentToken", {"labelMachineEnrollmentToken", IDS_POLICY_LABEL_MACHINE_ENROLLMENT_TOKEN},
IDS_POLICY_LABEL_MACHINE_ENROLLMENT_TOKEN}, {"labelMachineEntrollmentDeviceId",
{"labelMachineEntrollmentDeviceId", IDS_POLICY_LABEL_MACHINE_ENROLLMENT_DEVICE_ID},
IDS_POLICY_LABEL_MACHINE_ENROLLMENT_DEVICE_ID}, {"labelIsOffHoursActive", IDS_POLICY_LABEL_IS_OFFHOURS_ACTIVE},
{"labelIsOffHoursActive", IDS_POLICY_LABEL_IS_OFFHOURS_ACTIVE}, {"labelPoliciesPush", IDS_POLICY_LABEL_PUSH_POLICIES},
{"labelPoliciesPush", IDS_POLICY_LABEL_PUSH_POLICIES}, {"labelRefreshInterval", IDS_POLICY_LABEL_REFRESH_INTERVAL},
{"labelRefreshInterval", IDS_POLICY_LABEL_REFRESH_INTERVAL}, {"labelStatus", IDS_POLICY_LABEL_STATUS},
{"labelStatus", IDS_POLICY_LABEL_STATUS}, {"labelTimeSinceLastRefresh", IDS_POLICY_LABEL_TIME_SINCE_LAST_REFRESH},
{"labelTimeSinceLastRefresh", IDS_POLICY_LABEL_TIME_SINCE_LAST_REFRESH}, {"labelUsername", IDS_POLICY_LABEL_USERNAME},
{"labelUsername", IDS_POLICY_LABEL_USERNAME}, {"labelVersion", IDS_POLICY_LABEL_VERSION},
{"noPoliciesSet", IDS_POLICY_NO_POLICIES_SET}, {"noPoliciesSet", IDS_POLICY_NO_POLICIES_SET},
{"offHoursActive", IDS_POLICY_OFFHOURS_ACTIVE}, {"offHoursActive", IDS_POLICY_OFFHOURS_ACTIVE},
{"offHoursNotActive", IDS_POLICY_OFFHOURS_NOT_ACTIVE}, {"offHoursNotActive", IDS_POLICY_OFFHOURS_NOT_ACTIVE},
{"policiesPushOff", IDS_POLICY_PUSH_POLICIES_OFF}, {"policiesPushOff", IDS_POLICY_PUSH_POLICIES_OFF},
{"policiesPushOn", IDS_POLICY_PUSH_POLICIES_ON}, {"policiesPushOn", IDS_POLICY_PUSH_POLICIES_ON},
{"policyLearnMore", IDS_POLICY_LEARN_MORE}, {"policyLearnMore", IDS_POLICY_LEARN_MORE},
{"reloadPolicies", IDS_POLICY_RELOAD_POLICIES}, {"reloadPolicies", IDS_POLICY_RELOAD_POLICIES},
{"showExpandedStatus", IDS_POLICY_SHOW_EXPANDED_STATUS}, {"showExpandedStatus", IDS_POLICY_SHOW_EXPANDED_STATUS},
{"showLess", IDS_POLICY_SHOW_LESS}, {"showLess", IDS_POLICY_SHOW_LESS},
{"showMore", IDS_POLICY_SHOW_MORE}, {"showMore", IDS_POLICY_SHOW_MORE},
{"showUnset", IDS_POLICY_SHOW_UNSET}, {"showUnset", IDS_POLICY_SHOW_UNSET},
{"signinProfile", IDS_POLICY_SIGNIN_PROFILE}, {"signinProfile", IDS_POLICY_SIGNIN_PROFILE},
{"status", IDS_POLICY_STATUS}, {"status", IDS_POLICY_STATUS},
{"statusDevice", IDS_POLICY_STATUS_DEVICE}, {"statusDevice", IDS_POLICY_STATUS_DEVICE},
{"statusMachine", IDS_POLICY_STATUS_MACHINE}, {"statusMachine", IDS_POLICY_STATUS_MACHINE},
{"statusUser", IDS_POLICY_STATUS_USER}, #if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
{"statusUpdater", IDS_POLICY_STATUS_UPDATER},
#endif
{"statusUser", IDS_POLICY_STATUS_USER},
}; };
AddLocalizedStringsBulk(source, kStrings); AddLocalizedStringsBulk(source, kStrings);
......
...@@ -107,7 +107,11 @@ ...@@ -107,7 +107,11 @@
#endif #endif
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING) #if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
#include <DSRole.h>
#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 "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)
...@@ -438,6 +442,23 @@ class DeviceActiveDirectoryPolicyStatusProvider ...@@ -438,6 +442,23 @@ class DeviceActiveDirectoryPolicyStatusProvider
}; };
#endif #endif
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
class UpdaterStatusProvider : public PolicyStatusProvider {
public:
UpdaterStatusProvider();
~UpdaterStatusProvider() override = default;
void GetStatus(base::DictionaryValue* dict) override;
private:
static std::string FetchActiveDirectoryDomain();
void OnDomainReceived(std::string domain);
std::string version_;
std::string domain_;
base::WeakPtrFactory<UpdaterStatusProvider> weak_factory_{this};
};
#endif
PolicyStatusProvider::PolicyStatusProvider() {} PolicyStatusProvider::PolicyStatusProvider() {}
PolicyStatusProvider::~PolicyStatusProvider() {} PolicyStatusProvider::~PolicyStatusProvider() {}
...@@ -710,6 +731,51 @@ void DeviceActiveDirectoryPolicyStatusProvider::GetStatus( ...@@ -710,6 +731,51 @@ void DeviceActiveDirectoryPolicyStatusProvider::GetStatus(
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
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(
FROM_HERE,
{base::ThreadPool(), base::MayBlock(),
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
base::BindOnce(&UpdaterStatusProvider::FetchActiveDirectoryDomain),
base::BindOnce(&UpdaterStatusProvider::OnDomainReceived,
weak_factory_.GetWeakPtr()));
}
void UpdaterStatusProvider::GetStatus(base::DictionaryValue* dict) {
if (!version_.empty())
dict->SetString("version", version_);
if (!domain_.empty())
dict->SetString("domain", domain_);
}
// static
std::string UpdaterStatusProvider::FetchActiveDirectoryDomain() {
std::string domain;
::DSROLE_PRIMARY_DOMAIN_INFO_BASIC* info = nullptr;
if (::DsRoleGetPrimaryDomainInformation(nullptr,
::DsRolePrimaryDomainInfoBasic,
(PBYTE*)&info) != ERROR_SUCCESS) {
return domain;
}
if (info->DomainNameDns)
domain = base::WideToUTF8(info->DomainNameDns);
::DsRoleFreeMemory(info);
return domain;
}
void UpdaterStatusProvider::OnDomainReceived(std::string domain) {
domain_ = std::move(domain);
NotifyStatusChange();
}
#endif
PolicyUIHandler::PolicyUIHandler() {} PolicyUIHandler::PolicyUIHandler() {}
PolicyUIHandler::~PolicyUIHandler() { PolicyUIHandler::~PolicyUIHandler() {
...@@ -822,6 +888,7 @@ void PolicyUIHandler::RegisterMessages() { ...@@ -822,6 +888,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)
updater_status_provider_ = std::make_unique<UpdaterStatusProvider>();
base::PostTaskAndReplyWithResult( base::PostTaskAndReplyWithResult(
base::ThreadPool::CreateCOMSTATaskRunner( base::ThreadPool::CreateCOMSTATaskRunner(
{base::TaskPriority::USER_BLOCKING, {base::TaskPriority::USER_BLOCKING,
...@@ -838,12 +905,15 @@ void PolicyUIHandler::RegisterMessages() { ...@@ -838,12 +905,15 @@ void PolicyUIHandler::RegisterMessages() {
device_status_provider_ = std::make_unique<PolicyStatusProvider>(); device_status_provider_ = std::make_unique<PolicyStatusProvider>();
if (!machine_status_provider_.get()) if (!machine_status_provider_.get())
machine_status_provider_ = std::make_unique<PolicyStatusProvider>(); machine_status_provider_ = std::make_unique<PolicyStatusProvider>();
if (!updater_status_provider_.get())
updater_status_provider_ = std::make_unique<PolicyStatusProvider>();
auto update_callback(base::BindRepeating(&PolicyUIHandler::SendStatus, auto update_callback(base::BindRepeating(&PolicyUIHandler::SendStatus,
base::Unretained(this))); base::Unretained(this)));
user_status_provider_->SetStatusChangeCallback(update_callback); user_status_provider_->SetStatusChangeCallback(update_callback);
device_status_provider_->SetStatusChangeCallback(update_callback); device_status_provider_->SetStatusChangeCallback(update_callback);
machine_status_provider_->SetStatusChangeCallback(update_callback); machine_status_provider_->SetStatusChangeCallback(update_callback);
updater_status_provider_->SetStatusChangeCallback(update_callback);
GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_CHROME, this); GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_CHROME, this);
GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_EXTENSIONS, this); GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_EXTENSIONS, this);
...@@ -1033,6 +1103,10 @@ void PolicyUIHandler::SendStatus() { ...@@ -1033,6 +1103,10 @@ void PolicyUIHandler::SendStatus() {
new base::DictionaryValue); new base::DictionaryValue);
machine_status_provider_->GetStatus(machine_status.get()); machine_status_provider_->GetStatus(machine_status.get());
std::unique_ptr<base::DictionaryValue> updater_status(
new base::DictionaryValue);
updater_status_provider_->GetStatus(updater_status.get());
base::DictionaryValue status; base::DictionaryValue status;
if (!device_status->empty()) if (!device_status->empty())
status.Set("device", std::move(device_status)); status.Set("device", std::move(device_status));
...@@ -1040,6 +1114,8 @@ void PolicyUIHandler::SendStatus() { ...@@ -1040,6 +1114,8 @@ void PolicyUIHandler::SendStatus() {
status.Set("machine", std::move(machine_status)); status.Set("machine", std::move(machine_status));
if (!user_status->empty()) if (!user_status->empty())
status.Set("user", std::move(user_status)); status.Set("user", std::move(user_status));
if (!updater_status->empty())
status.Set("updater", std::move(updater_status));
FireWebUIListener("status-updated", status); FireWebUIListener("status-updated", status);
} }
......
...@@ -122,6 +122,7 @@ class PolicyUIHandler : public content::WebUIMessageHandler, ...@@ -122,6 +122,7 @@ class PolicyUIHandler : public content::WebUIMessageHandler,
std::unique_ptr<PolicyStatusProvider> user_status_provider_; std::unique_ptr<PolicyStatusProvider> user_status_provider_;
std::unique_ptr<PolicyStatusProvider> device_status_provider_; std::unique_ptr<PolicyStatusProvider> device_status_provider_;
std::unique_ptr<PolicyStatusProvider> machine_status_provider_; std::unique_ptr<PolicyStatusProvider> machine_status_provider_;
std::unique_ptr<PolicyStatusProvider> updater_status_provider_;
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING) #if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
std::unique_ptr<policy::PolicyMap> updater_policies_; std::unique_ptr<policy::PolicyMap> updater_policies_;
......
...@@ -52,6 +52,10 @@ ...@@ -52,6 +52,10 @@
<div hidden> <div hidden>
<fieldset id="status-box-template"> <fieldset id="status-box-template">
<legend class="legend"></legend> <legend class="legend"></legend>
<div class="status-entry" hidden>
<div class="label">$i18n{labelVersion}</div>
<div class="version"></div>
</div>
<div class="status-entry" hidden> <div class="status-entry" hidden>
<div class="label">$i18n{labelEnterpriseEnrollmentDomain}</div> <div class="label">$i18n{labelEnterpriseEnrollmentDomain}</div>
<div class="enterprise-enrollment-domain"></div> <div class="enterprise-enrollment-domain"></div>
...@@ -100,19 +104,19 @@ ...@@ -100,19 +104,19 @@
<div class="label">$i18n{labelDirectoryApiId}</div> <div class="label">$i18n{labelDirectoryApiId}</div>
<div class="directory-api-id"></div> <div class="directory-api-id"></div>
</div> </div>
<div class="status-entry"> <div class="status-entry" hidden>
<div class="label">$i18n{labelTimeSinceLastRefresh}</div> <div class="label">$i18n{labelTimeSinceLastRefresh}</div>
<div class="time-since-last-refresh"></div> <div class="time-since-last-refresh"></div>
</div> </div>
<div class="status-entry"> <div class="status-entry" hidden>
<div class="label">$i18n{labelRefreshInterval}</div> <div class="label">$i18n{labelRefreshInterval}</div>
<div class="refresh-interval"></div> <div class="refresh-interval"></div>
</div> </div>
<div class="status-entry"> <div class="status-entry" hidden>
<div class="label">$i18n{labelPoliciesPush}</div> <div class="label">$i18n{labelPoliciesPush}</div>
<div class="policy-push"></div> <div class="policy-push"></div>
</div> </div>
<div class="status-entry"> <div class="status-entry" hidden>
<div class="label">$i18n{labelStatus}</div> <div class="label">$i18n{labelStatus}</div>
<div class="status"></div> <div class="status"></div>
</div> </div>
...@@ -124,6 +128,10 @@ ...@@ -124,6 +128,10 @@
<div class="label">$i18n{labelIsOffHoursActive}</div> <div class="label">$i18n{labelIsOffHoursActive}</div>
<div class="is-offhours-active"></div> <div class="is-offhours-active"></div>
</div> </div>
<div class="status-entry" hidden>
<div class="label">$i18n{labelVersion}</div>
<div class="version"></div>
</div>
</fieldset> </fieldset>
<div class="policy-table" id="policy-table-template" role="table" <div class="policy-table" id="policy-table-template" role="table"
......
...@@ -96,8 +96,8 @@ cr.define('policy', function() { ...@@ -96,8 +96,8 @@ cr.define('policy', function() {
}, },
/** /**
* Populate the box with the given cloud policy status. * Populate the box with the given cloud policy status.
* @param {string} scope The policy scope, either "device", "machine", or * @param {string} scope The policy scope, either "device", "machine",
* "user". * "user", or "updater".
* @param {Object} status Dictionary with information about the status. * @param {Object} status Dictionary with information about the status.
*/ */
initialize(scope, status) { initialize(scope, status) {
...@@ -144,6 +144,15 @@ cr.define('policy', function() { ...@@ -144,6 +144,15 @@ cr.define('policy', function() {
'.machine-enrollment-token', status.enrollmentToken); '.machine-enrollment-token', status.enrollmentToken);
this.setLabelAndShow_('.machine-enrollment-name', status.machine); this.setLabelAndShow_('.machine-enrollment-name', status.machine);
this.setLabelAndShow_('.machine-enrollment-domain', status.domain); this.setLabelAndShow_('.machine-enrollment-domain', status.domain);
} else if (scope === 'updater') {
this.querySelector('.legend').textContent =
loadTimeData.getString('statusUpdater');
if (status.version) {
this.setLabelAndShow_('.version', status.version);
}
if (status.domain) {
this.setLabelAndShow_('.enterprise-enrollment-domain', status.domain);
}
} else { } else {
// For user policy, set the appropriate title and populate the topmost // For user policy, set the appropriate title and populate the topmost
// status item with the username that policies apply to. // status item with the username that policies apply to.
...@@ -161,15 +170,19 @@ cr.define('policy', function() { ...@@ -161,15 +170,19 @@ cr.define('policy', function() {
status.isAffiliated ? 'isAffiliatedYes' : 'isAffiliatedNo')); status.isAffiliated ? 'isAffiliatedYes' : 'isAffiliatedNo'));
} }
} }
this.setLabelAndShow_(
'.time-since-last-refresh', status.timeSinceLastRefresh, false); if (scope !== 'updater') {
this.setLabelAndShow_('.refresh-interval', status.refreshInterval, false); this.setLabelAndShow_(
this.setLabelAndShow_('.status', status.status, false); '.time-since-last-refresh', status.timeSinceLastRefresh, false);
this.setLabelAndShow_( this.setLabelAndShow_(
'.policy-push', '.refresh-interval', status.refreshInterval, false);
loadTimeData.getString( this.setLabelAndShow_('.status', status.status, false);
status.policiesPushAvailable ? 'policiesPushOn' : this.setLabelAndShow_(
'policiesPushOff')); '.policy-push',
loadTimeData.getString(
status.policiesPushAvailable ? 'policiesPushOn' :
'policiesPushOff'));
}
}, },
}; };
......
...@@ -297,6 +297,11 @@ Additional details: ...@@ -297,6 +297,11 @@ Additional details:
<message name="IDS_POLICY_STATUS_MACHINE" desc="Title for the machine policy status box."> <message name="IDS_POLICY_STATUS_MACHINE" desc="Title for the machine policy status box.">
Machine policies Machine policies
</message> </message>
<if expr="is_win">
<message name="IDS_POLICY_STATUS_UPDATER" desc="Title for the updater policy status box on windows.">
Google Update
</message>
</if>
<message name="IDS_POLICY_LABEL_ENTERPRISE_ENROLLMENT_DOMAIN" desc="Label for the enrollment domain in the device policy status box."> <message name="IDS_POLICY_LABEL_ENTERPRISE_ENROLLMENT_DOMAIN" desc="Label for the enrollment domain in the device policy status box.">
Enrollment domain: Enrollment domain:
</message> </message>
...@@ -369,6 +374,9 @@ Additional details: ...@@ -369,6 +374,9 @@ Additional details:
<message name="IDS_POLICY_LABEL_VALUE" desc="Label for the value row in the policy table."> <message name="IDS_POLICY_LABEL_VALUE" desc="Label for the value row in the policy table.">
Value Value
</message> </message>
<message name="IDS_POLICY_LABEL_VERSION" desc="Label for the version in the policy status box.">
Version:
</message>
<message name="IDS_POLICY_LABEL_STATUS" desc="Label for the actual status in the policy status boxes."> <message name="IDS_POLICY_LABEL_STATUS" desc="Label for the actual status in the policy status boxes.">
Status: Status:
</message> </message>
......
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