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

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: Fix chromeos build (this time I mean it) 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
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_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 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(true, false);
115 } 117 }
116 118
117 void PolicyUIHandler::HandleRequestData(const ListValue* args) { 119 void PolicyUIHandler::HandleRequestData(const ListValue* args) {
118 SendDataToUI(false); 120 SendDataToUI(false, 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, true));
123 } 131 }
124 132
125 void PolicyUIHandler::SendDataToUI(bool is_policy_update) { 133 void PolicyUIHandler::SendDataToUI(bool is_policy_update,
134 bool is_refresh_done) {
Mattias Nissler (ping if slow) 2012/04/27 09:03:27 I feel it's odd to multiplex all the different sig
Joao da Silva 2012/04/27 11:24:12 I've removed the booleans from SendDataToUI. The U
126 DictionaryValue results; 135 DictionaryValue results;
127 bool any_policies_set; 136 bool any_policies_set;
128 ListValue* list = policy_status_->GetPolicyStatusList(&any_policies_set); 137 ListValue* list = policy_status_->GetPolicyStatusList(&any_policies_set);
129 results.Set("policies", list); 138 results.Set("policies", list);
130 results.SetBoolean("anyPoliciesSet", any_policies_set); 139 results.SetBoolean("anyPoliciesSet", any_policies_set);
131 DictionaryValue* dict = GetStatusData(); 140 DictionaryValue* dict = GetStatusData();
132 results.Set("status", dict); 141 results.Set("status", dict);
133 results.SetBoolean("isPolicyUpdate", is_policy_update); 142 results.SetBoolean("isPolicyUpdate", is_policy_update);
143 results.SetBoolean("isRefreshDone", is_refresh_done);
134 144
135 web_ui()->CallJavascriptFunction("Policy.returnData", results); 145 web_ui()->CallJavascriptFunction("Policy.returnData", results);
136 } 146 }
137 147
138 DictionaryValue* PolicyUIHandler::GetStatusData() { 148 DictionaryValue* PolicyUIHandler::GetStatusData() {
139 DictionaryValue* results = new DictionaryValue(); 149 DictionaryValue* results = new DictionaryValue();
140 policy::BrowserPolicyConnector* connector = 150 policy::BrowserPolicyConnector* connector =
141 g_browser_process->browser_policy_connector(); 151 g_browser_process->browser_policy_connector();
142 152
143 policy::CloudPolicySubsystem* device_subsystem = 153 policy::CloudPolicySubsystem* device_subsystem =
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { 248 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) {
239 web_ui->AddMessageHandler(new PolicyUIHandler); 249 web_ui->AddMessageHandler(new PolicyUIHandler);
240 250
241 // Set up the chrome://policy/ source. 251 // Set up the chrome://policy/ source.
242 Profile* profile = Profile::FromWebUI(web_ui); 252 Profile* profile = Profile::FromWebUI(web_ui);
243 ChromeURLDataManager::AddDataSource(profile, CreatePolicyUIHTMLSource()); 253 ChromeURLDataManager::AddDataSource(profile, CreatePolicyUIHTMLSource());
244 } 254 }
245 255
246 PolicyUI::~PolicyUI() { 256 PolicyUI::~PolicyUI() {
247 } 257 }
OLDNEW
« chrome/browser/policy/policy_service_stub.cc ('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