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

Unified Diff: chrome/browser/pref_service.cc

Issue 2858060: Changing policy while Chrome is running should refresh preferences without relaunching (Closed)
Patch Set: changed name of mock Created 10 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
« no previous file with comments | « chrome/browser/pref_service.h ('k') | chrome/browser/pref_value_store.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/pref_service.cc
diff --git a/chrome/browser/pref_service.cc b/chrome/browser/pref_service.cc
index 1b7c90980f99a63d2376a20013b2745d831ec260..c02dd349b21b4afc914f34d7f03f8177fee77158 100644
--- a/chrome/browser/pref_service.cc
+++ b/chrome/browser/pref_service.cc
@@ -119,6 +119,9 @@ PrefService* PrefService::CreateUserPrefService(
PrefService::PrefService(PrefValueStore* pref_value_store)
: pref_value_store_(pref_value_store) {
InitFromStorage();
+ registrar_.Add(this,
+ NotificationType(NotificationType::POLICY_CHANGED),
+ NotificationService::AllSources());
}
PrefService::~PrefService() {
@@ -826,6 +829,38 @@ bool PrefService::Preference::IsUserControlled() const {
return pref_value_store_->PrefValueFromUserStore(name_.c_str());
}
+void PrefService::FireObserversForRefreshedManagedPrefs(
+ std::vector<std::string> changed_prefs_paths) {
+ DCHECK(CalledOnValidThread());
+ std::vector<std::string>::const_iterator current;
+ for (current = changed_prefs_paths.begin();
+ current != changed_prefs_paths.end();
+ ++current) {
+ FireObservers(UTF8ToWide(current->data()).data());
+ }
+}
+
bool PrefService::Preference::IsUserModifiable() const {
return pref_value_store_->PrefValueUserModifiable(name_.c_str());
}
+
+void PrefService::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::POLICY_CHANGED) {
+ PrefValueStore::AfterRefreshCallback callback =
+ NewCallback(this,
+ &PrefService::FireObserversForRefreshedManagedPrefs);
+ // The notification of the policy refresh can come from any thread,
+ // but the manipulation of the PrefValueStore must happen on the UI
+ // thread, thus the policy refresh must be explicitly started on it.
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(
+ pref_value_store_.get(),
+ &PrefValueStore::RefreshPolicyPrefs,
+ ConfigurationPolicyPrefStore::CreateManagedPolicyPrefStore(),
+ ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(),
+ callback));
+ }
+}
« no previous file with comments | « chrome/browser/pref_service.h ('k') | chrome/browser/pref_value_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698