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

Side by Side Diff: chrome/browser/ui/webui/policy_ui.cc

Issue 10236003: Added RefreshPolicies to PolicyService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/policy_ui.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_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 12 matching lines...) Expand all
104 "requestData", 106 "requestData",
105 base::Bind(&PolicyUIHandler::HandleRequestData, 107 base::Bind(&PolicyUIHandler::HandleRequestData,
106 base::Unretained(this))); 108 base::Unretained(this)));
107 web_ui()->RegisterMessageCallback( 109 web_ui()->RegisterMessageCallback(
108 "fetchPolicy", 110 "fetchPolicy",
109 base::Bind(&PolicyUIHandler::HandleFetchPolicy, 111 base::Bind(&PolicyUIHandler::HandleFetchPolicy,
110 base::Unretained(this))); 112 base::Unretained(this)));
111 } 113 }
112 114
113 void PolicyUIHandler::OnPolicyValuesChanged() { 115 void PolicyUIHandler::OnPolicyValuesChanged() {
114 SendDataToUI(true); 116 SendDataToUI();
115 } 117 }
116 118
117 void PolicyUIHandler::HandleRequestData(const ListValue* args) { 119 void PolicyUIHandler::HandleRequestData(const ListValue* args) {
118 SendDataToUI(false); 120 SendDataToUI();
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::OnRefreshDone,
129 weak_factory_.GetWeakPtr()));
123 } 130 }
124 131
125 void PolicyUIHandler::SendDataToUI(bool is_policy_update) { 132 void PolicyUIHandler::OnRefreshDone() {
133 web_ui()->CallJavascriptFunction("Policy.refreshDone");
134 }
135
136 void PolicyUIHandler::SendDataToUI() {
126 DictionaryValue results; 137 DictionaryValue results;
127 bool any_policies_set; 138 bool any_policies_set;
128 ListValue* list = policy_status_->GetPolicyStatusList(&any_policies_set); 139 ListValue* list = policy_status_->GetPolicyStatusList(&any_policies_set);
129 results.Set("policies", list); 140 results.Set("policies", list);
130 results.SetBoolean("anyPoliciesSet", any_policies_set); 141 results.SetBoolean("anyPoliciesSet", any_policies_set);
131 DictionaryValue* dict = GetStatusData(); 142 DictionaryValue* dict = GetStatusData();
132 results.Set("status", dict); 143 results.Set("status", dict);
133 results.SetBoolean("isPolicyUpdate", is_policy_update);
134
135 web_ui()->CallJavascriptFunction("Policy.returnData", results); 144 web_ui()->CallJavascriptFunction("Policy.returnData", results);
136 } 145 }
137 146
138 DictionaryValue* PolicyUIHandler::GetStatusData() { 147 DictionaryValue* PolicyUIHandler::GetStatusData() {
139 DictionaryValue* results = new DictionaryValue(); 148 DictionaryValue* results = new DictionaryValue();
140 policy::BrowserPolicyConnector* connector = 149 policy::BrowserPolicyConnector* connector =
141 g_browser_process->browser_policy_connector(); 150 g_browser_process->browser_policy_connector();
142 151
143 policy::CloudPolicySubsystem* device_subsystem = 152 policy::CloudPolicySubsystem* device_subsystem =
144 connector->device_cloud_policy_subsystem(); 153 connector->device_cloud_policy_subsystem();
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { 247 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) {
239 web_ui->AddMessageHandler(new PolicyUIHandler); 248 web_ui->AddMessageHandler(new PolicyUIHandler);
240 249
241 // Set up the chrome://policy/ source. 250 // Set up the chrome://policy/ source.
242 Profile* profile = Profile::FromWebUI(web_ui); 251 Profile* profile = Profile::FromWebUI(web_ui);
243 ChromeURLDataManager::AddDataSource(profile, CreatePolicyUIHTMLSource()); 252 ChromeURLDataManager::AddDataSource(profile, CreatePolicyUIHTMLSource());
244 } 253 }
245 254
246 PolicyUI::~PolicyUI() { 255 PolicyUI::~PolicyUI() {
247 } 256 }
OLDNEW
« no previous file with comments | « 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