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/policy/configuration_policy_pref_store.h" | 5 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( | 41 ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( |
42 PolicyService* service, | 42 PolicyService* service, |
43 PolicyLevel level) | 43 PolicyLevel level) |
44 : policy_service_(service), | 44 : policy_service_(service), |
45 level_(level) { | 45 level_(level) { |
46 // Read initial policy. | 46 // Read initial policy. |
47 prefs_.reset(CreatePreferencesFromPolicies()); | 47 prefs_.reset(CreatePreferencesFromPolicies()); |
48 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, "", this); | 48 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, "", this); |
49 } | 49 } |
50 | 50 |
51 ConfigurationPolicyPrefStore::~ConfigurationPolicyPrefStore() { | |
52 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, "", this); | |
53 } | |
54 | |
55 void ConfigurationPolicyPrefStore::AddObserver(PrefStore::Observer* observer) { | 51 void ConfigurationPolicyPrefStore::AddObserver(PrefStore::Observer* observer) { |
56 observers_.AddObserver(observer); | 52 observers_.AddObserver(observer); |
57 } | 53 } |
58 | 54 |
59 void ConfigurationPolicyPrefStore::RemoveObserver( | 55 void ConfigurationPolicyPrefStore::RemoveObserver( |
60 PrefStore::Observer* observer) { | 56 PrefStore::Observer* observer) { |
61 observers_.RemoveObserver(observer); | 57 observers_.RemoveObserver(observer); |
62 } | 58 } |
63 | 59 |
64 size_t ConfigurationPolicyPrefStore::NumberOfObservers() const { | 60 size_t ConfigurationPolicyPrefStore::NumberOfObservers() const { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 POLICY_LEVEL_MANDATORY); | 99 POLICY_LEVEL_MANDATORY); |
104 } | 100 } |
105 | 101 |
106 // static | 102 // static |
107 ConfigurationPolicyPrefStore* | 103 ConfigurationPolicyPrefStore* |
108 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore() { | 104 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore() { |
109 return new ConfigurationPolicyPrefStore(g_browser_process->policy_service(), | 105 return new ConfigurationPolicyPrefStore(g_browser_process->policy_service(), |
110 POLICY_LEVEL_RECOMMENDED); | 106 POLICY_LEVEL_RECOMMENDED); |
111 } | 107 } |
112 | 108 |
| 109 ConfigurationPolicyPrefStore::~ConfigurationPolicyPrefStore() { |
| 110 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, "", this); |
| 111 } |
| 112 |
113 void ConfigurationPolicyPrefStore::Refresh() { | 113 void ConfigurationPolicyPrefStore::Refresh() { |
114 scoped_ptr<PrefValueMap> new_prefs(CreatePreferencesFromPolicies()); | 114 scoped_ptr<PrefValueMap> new_prefs(CreatePreferencesFromPolicies()); |
115 std::vector<std::string> changed_prefs; | 115 std::vector<std::string> changed_prefs; |
116 new_prefs->GetDifferingKeys(prefs_.get(), &changed_prefs); | 116 new_prefs->GetDifferingKeys(prefs_.get(), &changed_prefs); |
117 prefs_.swap(new_prefs); | 117 prefs_.swap(new_prefs); |
118 | 118 |
119 // Send out change notifications. | 119 // Send out change notifications. |
120 for (std::vector<std::string>::const_iterator pref(changed_prefs.begin()); | 120 for (std::vector<std::string>::const_iterator pref(changed_prefs.begin()); |
121 pref != changed_prefs.end(); | 121 pref != changed_prefs.end(); |
122 ++pref) { | 122 ++pref) { |
(...skipping 24 matching lines...) Expand all Loading... |
147 // issue during startup. | 147 // issue during startup. |
148 BrowserThread::PostTask(BrowserThread::UI, | 148 BrowserThread::PostTask(BrowserThread::UI, |
149 FROM_HERE, | 149 FROM_HERE, |
150 base::Bind(&LogErrors, | 150 base::Bind(&LogErrors, |
151 base::Owned(errors.release()))); | 151 base::Owned(errors.release()))); |
152 | 152 |
153 return prefs.release(); | 153 return prefs.release(); |
154 } | 154 } |
155 | 155 |
156 } // namespace policy | 156 } // namespace policy |
OLD | NEW |