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/time.h" | 9 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/policy/browser_policy_connector.h" | 12 #include "chrome/browser/policy/browser_policy_connector.h" |
| 13 #include "chrome/browser/policy/cloud_policy_cache_base.h" | 13 #include "chrome/browser/policy/cloud_policy_cache_base.h" |
| 14 #include "chrome/browser/policy/cloud_policy_data_store.h" | 14 #include "chrome/browser/policy/cloud_policy_data_store.h" |
| 15 #include "chrome/browser/policy/policy_service.h" | |
| 15 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 18 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 18 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 19 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/common/time_format.h" | 21 #include "chrome/common/time_format.h" |
| 21 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 22 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/browser/web_ui.h" | 24 #include "content/public/browser/web_ui.h" |
| 24 #include "grit/browser_resources.h" | 25 #include "grit/browser_resources.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 | 72 |
| 72 return source; | 73 return source; |
| 73 } | 74 } |
| 74 | 75 |
| 75 //////////////////////////////////////////////////////////////////////////////// | 76 //////////////////////////////////////////////////////////////////////////////// |
| 76 // | 77 // |
| 77 // PolicyUIHandler | 78 // PolicyUIHandler |
| 78 // | 79 // |
| 79 //////////////////////////////////////////////////////////////////////////////// | 80 //////////////////////////////////////////////////////////////////////////////// |
| 80 | 81 |
| 81 PolicyUIHandler::PolicyUIHandler() { | 82 PolicyUIHandler::PolicyUIHandler() |
| 83 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | |
| 82 policy::ConfigurationPolicyReader* managed_platform = | 84 policy::ConfigurationPolicyReader* managed_platform = |
| 83 policy::ConfigurationPolicyReader::CreateManagedPlatformPolicyReader(); | 85 policy::ConfigurationPolicyReader::CreateManagedPlatformPolicyReader(); |
| 84 policy::ConfigurationPolicyReader* managed_cloud = | 86 policy::ConfigurationPolicyReader* managed_cloud = |
| 85 policy::ConfigurationPolicyReader::CreateManagedCloudPolicyReader(); | 87 policy::ConfigurationPolicyReader::CreateManagedCloudPolicyReader(); |
| 86 policy::ConfigurationPolicyReader* recommended_platform = | 88 policy::ConfigurationPolicyReader* recommended_platform = |
| 87 policy::ConfigurationPolicyReader:: | 89 policy::ConfigurationPolicyReader:: |
| 88 CreateRecommendedPlatformPolicyReader(); | 90 CreateRecommendedPlatformPolicyReader(); |
| 89 policy::ConfigurationPolicyReader* recommended_cloud = | 91 policy::ConfigurationPolicyReader* recommended_cloud = |
| 90 policy::ConfigurationPolicyReader::CreateRecommendedCloudPolicyReader(); | 92 policy::ConfigurationPolicyReader::CreateRecommendedCloudPolicyReader(); |
| 91 policy_status_.reset(new policy::PolicyStatus(managed_platform, | 93 policy_status_.reset(new policy::PolicyStatus(managed_platform, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 112 | 114 |
| 113 void PolicyUIHandler::OnPolicyValuesChanged() { | 115 void PolicyUIHandler::OnPolicyValuesChanged() { |
| 114 SendDataToUI(true); | 116 SendDataToUI(true); |
| 115 } | 117 } |
| 116 | 118 |
| 117 void PolicyUIHandler::HandleRequestData(const ListValue* args) { | 119 void PolicyUIHandler::HandleRequestData(const ListValue* args) { |
| 118 SendDataToUI(false); | 120 SendDataToUI(false); |
| 119 } | 121 } |
| 120 | 122 |
| 121 void PolicyUIHandler::HandleFetchPolicy(const ListValue* args) { | 123 void PolicyUIHandler::HandleFetchPolicy(const ListValue* args) { |
| 122 g_browser_process->browser_policy_connector()->RefreshPolicies(); | 124 // Fetching policy can potentially take a while due to cloud policy fetches. |
| 125 // Use a WeakPtr to make sure the callback is invalidated if the tab is closed | |
| 126 // before the fetching completes. | |
| 127 g_browser_process->policy_service()->RefreshPolicies( | |
| 128 base::Bind(&PolicyUIHandler::SendDataToUI, | |
| 129 weak_ptr_factory_.GetWeakPtr(), | |
| 130 true)); | |
|
Mattias Nissler (ping if slow)
2012/04/26 11:08:52
Hm, this code still follows the model that the fir
Joao da Silva
2012/04/26 14:43:58
Added a new field to flag this.
| |
| 123 } | 131 } |
| 124 | 132 |
| 125 void PolicyUIHandler::SendDataToUI(bool is_policy_update) { | 133 void PolicyUIHandler::SendDataToUI(bool is_policy_update) { |
| 126 DictionaryValue results; | 134 DictionaryValue results; |
| 127 bool any_policies_set; | 135 bool any_policies_set; |
| 128 ListValue* list = policy_status_->GetPolicyStatusList(&any_policies_set); | 136 ListValue* list = policy_status_->GetPolicyStatusList(&any_policies_set); |
| 129 results.Set("policies", list); | 137 results.Set("policies", list); |
| 130 results.SetBoolean("anyPoliciesSet", any_policies_set); | 138 results.SetBoolean("anyPoliciesSet", any_policies_set); |
| 131 DictionaryValue* dict = GetStatusData(); | 139 DictionaryValue* dict = GetStatusData(); |
| 132 results.Set("status", dict); | 140 results.Set("status", dict); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 246 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 239 web_ui->AddMessageHandler(new PolicyUIHandler); | 247 web_ui->AddMessageHandler(new PolicyUIHandler); |
| 240 | 248 |
| 241 // Set up the chrome://policy/ source. | 249 // Set up the chrome://policy/ source. |
| 242 Profile* profile = Profile::FromWebUI(web_ui); | 250 Profile* profile = Profile::FromWebUI(web_ui); |
| 243 ChromeURLDataManager::AddDataSource(profile, CreatePolicyUIHTMLSource()); | 251 ChromeURLDataManager::AddDataSource(profile, CreatePolicyUIHTMLSource()); |
| 244 } | 252 } |
| 245 | 253 |
| 246 PolicyUI::~PolicyUI() { | 254 PolicyUI::~PolicyUI() { |
| 247 } | 255 } |
| OLD | NEW |