Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6026)

Unified Diff: chrome/browser/ui/webui/policy_ui.cc

Issue 7828042: Implemented status section functionality for about:policy. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: . Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« chrome/browser/ui/webui/policy_ui.h ('K') | « chrome/browser/ui/webui/policy_ui.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/policy_ui.cc
diff --git a/chrome/browser/ui/webui/policy_ui.cc b/chrome/browser/ui/webui/policy_ui.cc
index 99ebb3e2bba09d7ba130336868c9d6caa7ea5c66..7bf002a31263b3832388ced78074a9a3172258a9 100644
--- a/chrome/browser/ui/webui/policy_ui.cc
+++ b/chrome/browser/ui/webui/policy_ui.cc
@@ -4,9 +4,18 @@
#include "chrome/browser/ui/webui/policy_ui.h"
-#include "chrome/browser/policy/policy_status_info.h"
+#include "base/i18n/time_formatting.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/login/user_manager.h"
+#include "chrome/browser/prefs/pref_service.h"
Mattias Nissler (ping if slow) 2011/09/06 11:19:30 alphabetize
simo 2011/09/07 12:18:16 Done.
+#include "chrome/browser/policy/browser_policy_connector.h"
+#include "chrome/browser/policy/cloud_policy_cache_base.h"
+#include "chrome/browser/policy/cloud_policy_data_store.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
+#include "chrome/common/time_format.h"
+#include "chrome/common/pref_names.h"
Mattias Nissler (ping if slow) 2011/09/06 11:19:30 alphabetize
simo 2011/09/07 12:18:16 Done.
#include "chrome/common/url_constants.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "grit/browser_resources.h"
@@ -26,6 +35,9 @@ ChromeWebUIDataSource* CreatePolicyUIHTMLSource() {
IDS_POLICY_USER_POLICIES);
source->AddLocalizedString("enrollmentDomainText",
IDS_POLICY_ENROLLMENT_DOMAIN);
+ source->AddLocalizedString("clientIdText", IDS_POLICY_CLIENT_ID);
+ source->AddLocalizedString("usernameText",
+ IDS_POLICY_USERNAME);
James Hawkins 2011/09/05 22:10:38 This looks like it doesn't need to be wrapped.
simo 2011/09/07 12:18:16 Done.
source->AddLocalizedString("lastFetchedText", IDS_POLICY_LAST_FETCHED);
source->AddLocalizedString("fetchIntervalText", IDS_POLICY_FETCH_INTERVAL);
source->AddLocalizedString("serverStatusText", IDS_POLICY_SERVER_STATUS);
@@ -39,6 +51,8 @@ ChromeWebUIDataSource* CreatePolicyUIHTMLSource() {
source->AddLocalizedString("policyValueTableHeader", IDS_POLICY_ENTRY_VALUE);
source->AddLocalizedString("policyStatusTableHeader",
IDS_POLICY_ENTRY_STATUS);
+ source->AddLocalizedString("showMoreText", IDS_POLICY_SHOW_MORE);
+ source->AddLocalizedString("hideText", IDS_POLICY_HIDE);
source->set_json_path("strings.js");
// Add required resources.
@@ -68,9 +82,11 @@ PolicyUIHandler::PolicyUIHandler() {
managed_cloud,
recommended_platform,
recommended_cloud));
+ policy_status_->AddObserver(this);
}
PolicyUIHandler::~PolicyUIHandler() {
+ policy_status_->RemoveObserver(this);
}
WebUIMessageHandler* PolicyUIHandler::Attach(WebUI* web_ui) {
@@ -78,17 +94,160 @@ WebUIMessageHandler* PolicyUIHandler::Attach(WebUI* web_ui) {
}
void PolicyUIHandler::RegisterMessages() {
- web_ui_->RegisterMessageCallback("requestPolicyData",
- NewCallback(this, &PolicyUIHandler::HandleRequestPolicyData));
+ web_ui_->RegisterMessageCallback("requestData",
+ NewCallback(this, &PolicyUIHandler::HandleRequestData));
+ web_ui_->RegisterMessageCallback("fetchPolicy",
+ NewCallback(this, &PolicyUIHandler::HandleFetchPolicy));
}
-void PolicyUIHandler::HandleRequestPolicyData(const ListValue* args) {
+void PolicyUIHandler::OnPolicyValuesChanged() {
+ SendDataToUI(true);
+}
+
+void PolicyUIHandler::HandleRequestData(const ListValue* args) {
+ SendDataToUI(false);
+}
+
+void PolicyUIHandler::HandleFetchPolicy(const ListValue* args) {
+ if (FetchPolicyIfTokensAvailable())
+ SendDataToUI(true);
+}
+
+void PolicyUIHandler::SendDataToUI(bool is_policy_update) {
+ DictionaryValue results;
bool any_policies_sent;
Mattias Nissler (ping if slow) 2011/09/06 11:19:30 should this rather be any_policies_set?
simo 2011/09/07 12:18:16 Done.
ListValue* list = policy_status_->GetPolicyStatusList(&any_policies_sent);
- DictionaryValue results;
results.Set("policies", list);
results.SetBoolean("anyPoliciesSet", any_policies_sent);
- web_ui_->CallJavascriptFunction("Policy.returnPolicyData", results);
+ DictionaryValue* dict = GetStatusData();
James Hawkins 2011/09/05 22:10:38 Leak?
simo 2011/09/07 12:18:16 |dict| is added to the |results| DictionaryValue w
+ results.Set("status", dict);
+ results.SetBoolean("isPolicyUpdate", is_policy_update);
Mattias Nissler (ping if slow) 2011/09/06 11:19:30 do we need to pass this flag explicitly? I think i
simo 2011/09/07 12:18:16 is_policy_update is set to true after an OnPolicyV
Mattias Nissler (ping if slow) 2011/09/07 12:50:48 I see.
+
+ web_ui_->CallJavascriptFunction("Policy.returnData", results);
+}
+
+DictionaryValue* PolicyUIHandler::GetStatusData() {
+ DictionaryValue* results = new DictionaryValue();
+ policy::BrowserPolicyConnector* connector =
+ g_browser_process->browser_policy_connector();
+
+ policy::CloudPolicySubsystem* device_subsystem =
+ connector->device_cloud_policy_subsystem();
+ policy::CloudPolicySubsystem* user_subsystem =
+ connector->user_cloud_policy_subsystem();
+
+ // If no CloudPolicySubsystem is available, the status section is not
+ // displayed and we can return here.
+ if (!device_subsystem || !user_subsystem) {
+ results->SetBoolean("displayStatusSection", false);
+ return results;
+ } else {
+ results->SetBoolean("displayStatusSection", true);
+ }
+
+ // Get the server status message and the time at which policy was last fetched
+ // for both user and device policy from the appropriate CloudPolicySubsystem.
+ results->SetString("deviceStatusMessage",
+ CreateStatusMessageString(device_subsystem->error_details()));
+ results->SetString("deviceLastFetchTime", GetLastFetchTime(device_subsystem));
+ results->SetString("userStatusMessage",
+ CreateStatusMessageString(user_subsystem->error_details()));
+ results->SetString("userLastFetchTime", GetLastFetchTime(user_subsystem));
+
+ // Get enterprise domain and username (only on ChromeOS).
+#if defined (OS_CHROMEOS)
+ chromeos::UserManager::User user =
+ chromeos::UserManager::Get()->logged_in_user();
+ results->SetString("devicePolicyDomain",
+ ASCIIToUTF16(connector->GetEnterpriseDomain()));
+ results->SetString("user", ASCIIToUTF16(user.email()));
+#else
+ results->SetString("devicePolicyDomain", string16());
+ results->SetString("user", string16());
+#endif
+
+ GetDeviceIds(results);
Mattias Nissler (ping if slow) 2011/09/06 11:19:30 In the previous comments, I was actually referring
simo 2011/09/07 12:18:16 Done.
+ GetPolicyFetchIntervals(results);
Mattias Nissler (ping if slow) 2011/09/06 11:19:30 Same here.
simo 2011/09/07 12:18:16 Done.
+
+ return results;
+}
+
+bool PolicyUIHandler::FetchPolicyIfTokensAvailable() {
+ policy::BrowserPolicyConnector* connector =
+ g_browser_process->browser_policy_connector();
+ const policy::CloudPolicyDataStore* device_data_store =
+ connector->GetDeviceCloudPolicyDataStore();
+ const policy::CloudPolicyDataStore* user_data_store =
+ connector->GetUserCloudPolicyDataStore();
+
+ bool fetch_device_policy =
+ device_data_store && !device_data_store->device_token().empty();
+ bool fetch_user_policy =
+ user_data_store && !user_data_store->device_token().empty();
+
+ if (fetch_device_policy)
+ connector->FetchDevicePolicy();
+ if (fetch_user_policy)
James Hawkins 2011/09/05 22:10:38 I'd add a blank line here for readability: I initi
simo 2011/09/07 12:18:16 Done.
+ connector->FetchUserPolicy();
+
+ return fetch_device_policy || fetch_user_policy;
+}
+
+string16 PolicyUIHandler::GetLastFetchTime(
+ policy::CloudPolicySubsystem* subsystem) {
+ policy::CloudPolicyCacheBase* cache_base =
+ subsystem->GetCloudPolicyCacheBase();
James Hawkins 2011/09/05 22:10:38 Indentation.
simo 2011/09/07 12:18:16 Done.
+ base::TimeDelta time_delta =
+ base::Time::NowFromSystemTime() - cache_base->last_policy_refresh_time();
+
+ return TimeFormat::TimeElapsed(time_delta);
+}
+
+void PolicyUIHandler::GetDeviceIds(DictionaryValue* results) {
+ policy::BrowserPolicyConnector* connector =
+ g_browser_process->browser_policy_connector();
+ const policy::CloudPolicyDataStore* device_data_store =
+ connector->GetDeviceCloudPolicyDataStore();
+ const policy::CloudPolicyDataStore* user_data_store =
+ connector->GetUserCloudPolicyDataStore();
+
+ if (device_data_store) {
+ results->SetString("deviceId",
+ ASCIIToUTF16(device_data_store->device_id()));
+ } else {
+ results->SetString("deviceId", string16());
+ }
+
+ if (user_data_store)
+ results->SetString("userId", ASCIIToUTF16(user_data_store->device_id()));
+ else
+ results->SetString("userId", string16());
+}
+
+void PolicyUIHandler::GetPolicyFetchIntervals(DictionaryValue* results) {
+ PrefService* prefs = g_browser_process->local_state();
+ base::TimeDelta device_fetch_interval = base::TimeDelta::FromMilliseconds(
+ prefs->GetInteger(prefs::kDevicePolicyRefreshRate));
+ base::TimeDelta user_fetch_interval = base::TimeDelta::FromMilliseconds(
+ prefs->GetInteger(prefs::kUserPolicyRefreshRate));
+
+ results->SetString("deviceFetchInterval",
+ TimeFormat::TimeRemainingShort(device_fetch_interval));
+ results->SetString("userFetchInterval",
+ TimeFormat::TimeRemainingShort(user_fetch_interval));
+}
+
+// static
+string16 PolicyUIHandler::CreateStatusMessageString(
+ CloudPolicySubsystem::ErrorDetails error_details) {
+ static string16 error_to_string[] = { ASCIIToUTF16("OK."),
+ ASCIIToUTF16("Network error."),
+ ASCIIToUTF16("Network error."),
+ ASCIIToUTF16("Bad DMToken."),
+ ASCIIToUTF16("Local error."),
+ ASCIIToUTF16("Signature mismatch.") };
+ DCHECK(static_cast<size_t>(error_details) < arraysize(error_to_string));
+ return error_to_string[error_details];
}
////////////////////////////////////////////////////////////////////////////////
« chrome/browser/ui/webui/policy_ui.h ('K') | « chrome/browser/ui/webui/policy_ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698