Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/policy_ui.h" | 5 #include "chrome/browser/ui/webui/policy_ui.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 | 123 |
| 124 // Add required resources. | 124 // Add required resources. |
| 125 source->AddResourcePath("policy.css", IDR_POLICY_CSS); | 125 source->AddResourcePath("policy.css", IDR_POLICY_CSS); |
| 126 source->AddResourcePath("policy.js", IDR_POLICY_JS); | 126 source->AddResourcePath("policy.js", IDR_POLICY_JS); |
| 127 source->AddResourcePath("uber_utils.js", IDR_UBER_UTILS_JS); | 127 source->AddResourcePath("uber_utils.js", IDR_UBER_UTILS_JS); |
| 128 source->SetDefaultResource(IDR_POLICY_HTML); | 128 source->SetDefaultResource(IDR_POLICY_HTML); |
| 129 | 129 |
| 130 return source; | 130 return source; |
| 131 } | 131 } |
| 132 | 132 |
| 133 // Formats the association state indicated by |data|. If |data| is null, the | |
|
bartfab (slow)
2013/12/19 11:00:22
Nit: s/null/NULL/.
Mattias Nissler (ping if slow)
2013/12/20 11:42:13
Done.
| |
| 134 // state is considered to be UNMANAGED. | |
| 135 base::string16 FormatAssociationState(const em::PolicyData* data) { | |
| 136 if (data) { | |
| 137 switch (data->state()) { | |
| 138 case em::PolicyData::ACTIVE: | |
| 139 return l10n_util::GetStringUTF16(IDS_POLICY_ASSOCIATION_STATE_ACTIVE); | |
| 140 case em::PolicyData::UNMANAGED: | |
| 141 return l10n_util::GetStringUTF16( | |
| 142 IDS_POLICY_ASSOCIATION_STATE_UNMANAGED); | |
| 143 case em::PolicyData::DEPROVISIONED: | |
| 144 return l10n_util::GetStringUTF16( | |
| 145 IDS_POLICY_ASSOCIATION_STATE_DEPROVISIONED); | |
| 146 } | |
| 147 NOTREACHED() << "Unknown state " << data->state(); | |
| 148 } | |
| 149 | |
| 150 // Default to UNMANAGED for the case of missing policy or bad state enum. | |
| 151 return l10n_util::GetStringUTF16(IDS_POLICY_ASSOCIATION_STATE_UNMANAGED); | |
| 152 } | |
| 153 | |
| 133 void GetStatusFromCore(const policy::CloudPolicyCore* core, | 154 void GetStatusFromCore(const policy::CloudPolicyCore* core, |
| 134 base::DictionaryValue* dict) { | 155 base::DictionaryValue* dict) { |
| 135 const policy::CloudPolicyStore* store = core->store(); | 156 const policy::CloudPolicyStore* store = core->store(); |
| 136 const policy::CloudPolicyClient* client = core->client(); | 157 const policy::CloudPolicyClient* client = core->client(); |
| 137 const policy::CloudPolicyRefreshScheduler* refresh_scheduler = | 158 const policy::CloudPolicyRefreshScheduler* refresh_scheduler = |
| 138 core->refresh_scheduler(); | 159 core->refresh_scheduler(); |
| 139 | 160 |
| 140 bool no_error = store->status() == policy::CloudPolicyStore::STATUS_OK && | 161 // CloudPolicyStore errors take precedence to show in the status message. |
| 141 client && client->status() == policy::DM_STATUS_SUCCESS; | 162 // Other errors (such as transient policy fetching problems) get displayed |
| 163 // only if CloudPolicyStore is in STATUS_OK. | |
| 142 base::string16 status = | 164 base::string16 status = |
| 143 store->status() == policy::CloudPolicyStore::STATUS_OK && | 165 policy::FormatStoreStatus(store->status(), store->validation_status()); |
| 144 client && client->status() != policy::DM_STATUS_SUCCESS ? | 166 if (store->status() == policy::CloudPolicyStore::STATUS_OK) { |
| 145 policy::FormatDeviceManagementStatus(client->status()) : | 167 if (client && client->status() != policy::DM_STATUS_SUCCESS) |
| 146 policy::FormatStoreStatus(store->status(), | 168 status = policy::FormatDeviceManagementStatus(client->status()); |
| 147 store->validation_status()); | 169 else if (!store->is_managed()) |
| 170 status = FormatAssociationState(store->policy()); | |
| 171 } | |
| 172 | |
| 148 const em::PolicyData* policy = store->policy(); | 173 const em::PolicyData* policy = store->policy(); |
| 149 std::string client_id = policy ? policy->device_id() : std::string(); | 174 std::string client_id = policy ? policy->device_id() : std::string(); |
| 150 std::string username = policy ? policy->username() : std::string(); | 175 std::string username = policy ? policy->username() : std::string(); |
| 151 base::TimeDelta refresh_interval = | 176 base::TimeDelta refresh_interval = |
| 152 base::TimeDelta::FromMilliseconds(refresh_scheduler ? | 177 base::TimeDelta::FromMilliseconds(refresh_scheduler ? |
| 153 refresh_scheduler->refresh_delay() : | 178 refresh_scheduler->refresh_delay() : |
| 154 policy::CloudPolicyRefreshScheduler::kDefaultRefreshDelayMs); | 179 policy::CloudPolicyRefreshScheduler::kDefaultRefreshDelayMs); |
| 155 base::Time last_refresh_time = refresh_scheduler ? | 180 base::Time last_refresh_time = refresh_scheduler ? |
| 156 refresh_scheduler->last_refresh() : base::Time(); | 181 refresh_scheduler->last_refresh() : base::Time(); |
| 157 | 182 |
| 183 bool no_error = store->status() == policy::CloudPolicyStore::STATUS_OK && | |
| 184 client && client->status() == policy::DM_STATUS_SUCCESS; | |
| 158 dict->SetBoolean("error", !no_error); | 185 dict->SetBoolean("error", !no_error); |
| 159 dict->SetString("status", status); | 186 dict->SetString("status", status); |
| 160 dict->SetString("clientId", client_id); | 187 dict->SetString("clientId", client_id); |
| 161 dict->SetString("username", username); | 188 dict->SetString("username", username); |
| 162 dict->SetString("refreshInterval", | 189 dict->SetString("refreshInterval", |
| 163 ui::TimeFormat::TimeRemainingShort(refresh_interval)); | 190 ui::TimeFormat::TimeRemainingShort(refresh_interval)); |
| 164 dict->SetString("timeSinceLastRefresh", last_refresh_time.is_null() ? | 191 dict->SetString("timeSinceLastRefresh", last_refresh_time.is_null() ? |
| 165 l10n_util::GetStringUTF16(IDS_POLICY_NEVER_FETCHED) : | 192 l10n_util::GetStringUTF16(IDS_POLICY_NEVER_FETCHED) : |
| 166 ui::TimeFormat::TimeElapsed(base::Time::NowFromSystemTime() - | 193 ui::TimeFormat::TimeElapsed(base::Time::NowFromSystemTime() - |
| 167 last_refresh_time)); | 194 last_refresh_time)); |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 756 } | 783 } |
| 757 | 784 |
| 758 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 785 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 759 web_ui->AddMessageHandler(new PolicyUIHandler); | 786 web_ui->AddMessageHandler(new PolicyUIHandler); |
| 760 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), | 787 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), |
| 761 CreatePolicyUIHTMLSource()); | 788 CreatePolicyUIHTMLSource()); |
| 762 } | 789 } |
| 763 | 790 |
| 764 PolicyUI::~PolicyUI() { | 791 PolicyUI::~PolicyUI() { |
| 765 } | 792 } |
| OLD | NEW |