Commit a9cd1e88 authored by Owen Min's avatar Owen Min Committed by Commit Bot

Fix a DCHECK failure in chrome:://policy page.

chrome://policy page calculates the elapsed time since last cloud policy
fetch. However, some elpsed times are calculated based on the timestamp
from server side whose clock may not be synced with the local one. This
may ends up with a negative elpsed time in the page.

To fix this:
1) Use last fetch timestamp in ReportScheduler if available. Because
ReportScheduler will use local clock if possible.
2) We have to fallback to server clock if ReportScheduler never records
a last fetch timestamp or there is no ReportScheduler instance.
In this case, a negative elapsed time will be changed to 0.

Bug: 1059025
Change-Id: I94fbc1b2127f81462ab389d448a9e25777edcd6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2090731Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Commit-Queue: Owen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748239}
parent f81d3615
...@@ -153,6 +153,17 @@ base::string16 GetPolicyStatusFromStore( ...@@ -153,6 +153,17 @@ base::string16 GetPolicyStatusFromStore(
return status; return status;
} }
base::string16 GetTimeSinceLastRefreshString(base::Time last_refresh_time) {
if (last_refresh_time.is_null())
return l10n_util::GetStringUTF16(IDS_POLICY_NEVER_FETCHED);
base::Time now = base::Time::NowFromSystemTime();
base::TimeDelta elapsed_time;
if (now > last_refresh_time)
elapsed_time = now - last_refresh_time;
return ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED,
ui::TimeFormat::LENGTH_SHORT, elapsed_time);
}
void GetStatusFromCore(const policy::CloudPolicyCore* core, void GetStatusFromCore(const policy::CloudPolicyCore* core,
base::DictionaryValue* dict) { base::DictionaryValue* dict) {
const policy::CloudPolicyStore* store = core->store(); const policy::CloudPolicyStore* store = core->store();
...@@ -195,13 +206,8 @@ void GetStatusFromCore(const policy::CloudPolicyCore* core, ...@@ -195,13 +206,8 @@ void GetStatusFromCore(const policy::CloudPolicyCore* core,
"refreshInterval", "refreshInterval",
ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_DURATION, ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_DURATION,
ui::TimeFormat::LENGTH_SHORT, refresh_interval)); ui::TimeFormat::LENGTH_SHORT, refresh_interval));
dict->SetString( dict->SetString("timeSinceLastRefresh",
"timeSinceLastRefresh", GetTimeSinceLastRefreshString(last_refresh_time));
last_refresh_time.is_null()
? l10n_util::GetStringUTF16(IDS_POLICY_NEVER_FETCHED)
: ui::TimeFormat::Simple(
ui::TimeFormat::FORMAT_ELAPSED, ui::TimeFormat::LENGTH_SHORT,
base::Time::NowFromSystemTime() - last_refresh_time));
} }
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -522,6 +528,8 @@ void MachineLevelUserCloudPolicyStatusProvider::GetStatus( ...@@ -522,6 +528,8 @@ void MachineLevelUserCloudPolicyStatusProvider::GetStatus(
base::DictionaryValue* dict) { base::DictionaryValue* dict) {
policy::CloudPolicyStore* store = core_->store(); policy::CloudPolicyStore* store = core_->store();
policy::CloudPolicyClient* client = core_->client(); policy::CloudPolicyClient* client = core_->client();
policy::CloudPolicyRefreshScheduler* refresh_scheduler =
core_->refresh_scheduler();
policy::BrowserDMTokenStorage* dmTokenStorage = policy::BrowserDMTokenStorage* dmTokenStorage =
policy::BrowserDMTokenStorage::Get(); policy::BrowserDMTokenStorage::Get();
...@@ -531,7 +539,9 @@ void MachineLevelUserCloudPolicyStatusProvider::GetStatus( ...@@ -531,7 +539,9 @@ void MachineLevelUserCloudPolicyStatusProvider::GetStatus(
ui::TimeFormat::Simple( ui::TimeFormat::Simple(
ui::TimeFormat::FORMAT_DURATION, ui::TimeFormat::LENGTH_SHORT, ui::TimeFormat::FORMAT_DURATION, ui::TimeFormat::LENGTH_SHORT,
base::TimeDelta::FromMilliseconds( base::TimeDelta::FromMilliseconds(
policy::CloudPolicyRefreshScheduler::kDefaultRefreshDelayMs))); refresh_scheduler ? refresh_scheduler->GetActualRefreshDelay()
: policy::CloudPolicyRefreshScheduler::
kDefaultRefreshDelayMs)));
if (dmTokenStorage) { if (dmTokenStorage) {
dict->SetString("enrollmentToken", dict->SetString("enrollmentToken",
...@@ -545,12 +555,10 @@ void MachineLevelUserCloudPolicyStatusProvider::GetStatus( ...@@ -545,12 +555,10 @@ void MachineLevelUserCloudPolicyStatusProvider::GetStatus(
dict->SetString("status", status); dict->SetString("status", status);
const em::PolicyData* policy = store->policy(); const em::PolicyData* policy = store->policy();
if (policy) { if (policy) {
dict->SetString( dict->SetString("timeSinceLastRefresh",
"timeSinceLastRefresh", GetTimeSinceLastRefreshString(
ui::TimeFormat::Simple( refresh_scheduler ? refresh_scheduler->last_refresh()
ui::TimeFormat::FORMAT_ELAPSED, ui::TimeFormat::LENGTH_SHORT, : base::Time()));
base::Time::NowFromSystemTime() -
base::Time::FromJavaTime(policy->timestamp())));
std::string username = policy->username(); std::string username = policy->username();
dict->SetString("domain", gaia::ExtractDomainName(username)); dict->SetString("domain", gaia::ExtractDomainName(username));
} }
...@@ -668,13 +676,8 @@ void UserActiveDirectoryPolicyStatusProvider::GetStatus( ...@@ -668,13 +676,8 @@ void UserActiveDirectoryPolicyStatusProvider::GetStatus(
ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_DURATION, ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_DURATION,
ui::TimeFormat::LENGTH_SHORT, refresh_interval)); ui::TimeFormat::LENGTH_SHORT, refresh_interval));
dict->SetString( dict->SetString("timeSinceLastRefresh",
"timeSinceLastRefresh", GetTimeSinceLastRefreshString(last_refresh_time));
last_refresh_time.is_null()
? l10n_util::GetStringUTF16(IDS_POLICY_NEVER_FETCHED)
: ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED,
ui::TimeFormat::LENGTH_SHORT,
base::Time::Now() - last_refresh_time));
GetUserAffiliationStatus(dict, profile_); GetUserAffiliationStatus(dict, profile_);
} }
......
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