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

Side by Side Diff: chrome/browser/chromeos/policy/device_local_account_policy_service.cc

Issue 23494053: Remove NOTIFICATION_SYSTEM_SETTING_CHANGED, switch CrosSettings to base::CallbackRegistry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: oops Created 7 years, 3 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/chromeos/policy/device_local_account_policy_service.h" 5 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "chrome/browser/chrome_notification_types.h" 12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/chromeos/policy/device_local_account.h" 13 #include "chrome/browser/chromeos/policy/device_local_account.h"
14 #include "chrome/browser/chromeos/policy/device_local_account_policy_store.h" 14 #include "chrome/browser/chromeos/policy/device_local_account_policy_store.h"
15 #include "chrome/browser/chromeos/settings/cros_settings.h" 15 #include "chrome/browser/chromeos/settings/cros_settings.h"
16 #include "chrome/browser/chromeos/settings/cros_settings_names.h" 16 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
17 #include "chrome/browser/chromeos/settings/cros_settings_provider.h" 17 #include "chrome/browser/chromeos/settings/cros_settings_provider.h"
18 #include "chrome/browser/chromeos/settings/device_settings_service.h" 18 #include "chrome/browser/chromeos/settings/device_settings_service.h"
19 #include "chrome/browser/policy/cloud/cloud_policy_client.h" 19 #include "chrome/browser/policy/cloud/cloud_policy_client.h"
20 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" 20 #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
21 #include "chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h" 21 #include "chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h"
22 #include "chrome/browser/policy/cloud/device_management_service.h" 22 #include "chrome/browser/policy/cloud/device_management_service.h"
23 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" 23 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h"
24 #include "chromeos/dbus/session_manager_client.h" 24 #include "chromeos/dbus/session_manager_client.h"
25 #include "content/public/browser/notification_details.h" 25 #include "content/public/browser/notification_details.h"
Lei Zhang 2013/09/18 05:00:53 Remove
Avi (use Gerrit) 2013/09/18 16:41:44 Done.
26 #include "policy/policy_constants.h" 26 #include "policy/policy_constants.h"
27 27
28 namespace em = enterprise_management; 28 namespace em = enterprise_management;
29 29
30 namespace policy { 30 namespace policy {
31 31
32 namespace { 32 namespace {
33 33
34 // Creates a broker for the device-local account with the given |user_id| and 34 // Creates a broker for the device-local account with the given |user_id| and
35 // |account_id|. 35 // |account_id|.
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 154
155 DeviceLocalAccountPolicyService::DeviceLocalAccountPolicyService( 155 DeviceLocalAccountPolicyService::DeviceLocalAccountPolicyService(
156 chromeos::SessionManagerClient* session_manager_client, 156 chromeos::SessionManagerClient* session_manager_client,
157 chromeos::DeviceSettingsService* device_settings_service, 157 chromeos::DeviceSettingsService* device_settings_service,
158 chromeos::CrosSettings* cros_settings) 158 chromeos::CrosSettings* cros_settings)
159 : session_manager_client_(session_manager_client), 159 : session_manager_client_(session_manager_client),
160 device_settings_service_(device_settings_service), 160 device_settings_service_(device_settings_service),
161 cros_settings_(cros_settings), 161 cros_settings_(cros_settings),
162 device_management_service_(NULL), 162 device_management_service_(NULL),
163 cros_settings_callback_factory_(this) { 163 cros_settings_callback_factory_(this) {
164 cros_settings_->AddSettingsObserver( 164 local_accounts_subscription_ = cros_settings_->AddSettingsObserver(
165 chromeos::kAccountsPrefDeviceLocalAccounts, this); 165 chromeos::kAccountsPrefDeviceLocalAccounts,
166 base::Bind(&DeviceLocalAccountPolicyService::
167 UpdateAccountListIfNonePending,
168 base::Unretained(this)));
166 UpdateAccountList(); 169 UpdateAccountList();
167 } 170 }
168 171
169 DeviceLocalAccountPolicyService::~DeviceLocalAccountPolicyService() { 172 DeviceLocalAccountPolicyService::~DeviceLocalAccountPolicyService() {
170 cros_settings_->RemoveSettingsObserver(
171 chromeos::kAccountsPrefDeviceLocalAccounts, this);
172 DeleteBrokers(&policy_brokers_); 173 DeleteBrokers(&policy_brokers_);
173 } 174 }
174 175
175 void DeviceLocalAccountPolicyService::Connect( 176 void DeviceLocalAccountPolicyService::Connect(
176 DeviceManagementService* device_management_service) { 177 DeviceManagementService* device_management_service) {
177 DCHECK(!device_management_service_); 178 DCHECK(!device_management_service_);
178 device_management_service_ = device_management_service; 179 device_management_service_ = device_management_service;
179 180
180 // Connect the brokers. 181 // Connect the brokers.
181 for (PolicyBrokerMap::iterator it(policy_brokers_.begin()); 182 for (PolicyBrokerMap::iterator it(policy_brokers_.begin());
(...skipping 30 matching lines...) Expand all
212 } 213 }
213 214
214 void DeviceLocalAccountPolicyService::AddObserver(Observer* observer) { 215 void DeviceLocalAccountPolicyService::AddObserver(Observer* observer) {
215 observers_.AddObserver(observer); 216 observers_.AddObserver(observer);
216 } 217 }
217 218
218 void DeviceLocalAccountPolicyService::RemoveObserver(Observer* observer) { 219 void DeviceLocalAccountPolicyService::RemoveObserver(Observer* observer) {
219 observers_.RemoveObserver(observer); 220 observers_.RemoveObserver(observer);
220 } 221 }
221 222
222 void DeviceLocalAccountPolicyService::Observe(
223 int type,
224 const content::NotificationSource& source,
225 const content::NotificationDetails& details) {
226 if (type != chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED ||
227 *content::Details<const std::string>(details).ptr() !=
228 chromeos::kAccountsPrefDeviceLocalAccounts) {
229 NOTREACHED();
230 return;
231 }
232
233 // Avoid unnecessary calls to UpdateAccountList(): If an earlier call is still
234 // pending (because the |cros_settings_| are not trusted yet), the updated
235 // account list will be processed by that call when it eventually runs.
236 if (!cros_settings_callback_factory_.HasWeakPtrs())
237 UpdateAccountList();
238 }
239
240 void DeviceLocalAccountPolicyService::OnStoreLoaded(CloudPolicyStore* store) { 223 void DeviceLocalAccountPolicyService::OnStoreLoaded(CloudPolicyStore* store) {
241 DeviceLocalAccountPolicyBroker* broker = GetBrokerForStore(store); 224 DeviceLocalAccountPolicyBroker* broker = GetBrokerForStore(store);
242 DCHECK(broker); 225 DCHECK(broker);
243 if (!broker) 226 if (!broker)
244 return; 227 return;
245 broker->UpdateRefreshDelay(); 228 broker->UpdateRefreshDelay();
246 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyUpdated(broker->user_id())); 229 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyUpdated(broker->user_id()));
247 } 230 }
248 231
249 void DeviceLocalAccountPolicyService::OnStoreError(CloudPolicyStore* store) { 232 void DeviceLocalAccountPolicyService::OnStoreError(CloudPolicyStore* store) {
250 DeviceLocalAccountPolicyBroker* broker = GetBrokerForStore(store); 233 DeviceLocalAccountPolicyBroker* broker = GetBrokerForStore(store);
251 DCHECK(broker); 234 DCHECK(broker);
252 if (!broker) 235 if (!broker)
253 return; 236 return;
254 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyUpdated(broker->user_id())); 237 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyUpdated(broker->user_id()));
255 } 238 }
256 239
240 void DeviceLocalAccountPolicyService::UpdateAccountListIfNonePending() {
241 // Avoid unnecessary calls to UpdateAccountList(): If an earlier call is still
242 // pending (because the |cros_settings_| are not trusted yet), the updated
243 // account list will be processed by that call when it eventually runs.
244 if (!cros_settings_callback_factory_.HasWeakPtrs())
245 UpdateAccountList();
246 }
247
257 void DeviceLocalAccountPolicyService::UpdateAccountList() { 248 void DeviceLocalAccountPolicyService::UpdateAccountList() {
258 if (chromeos::CrosSettingsProvider::TRUSTED != 249 if (chromeos::CrosSettingsProvider::TRUSTED !=
259 cros_settings_->PrepareTrustedValues( 250 cros_settings_->PrepareTrustedValues(
260 base::Bind(&DeviceLocalAccountPolicyService::UpdateAccountList, 251 base::Bind(&DeviceLocalAccountPolicyService::UpdateAccountList,
261 cros_settings_callback_factory_.GetWeakPtr()))) { 252 cros_settings_callback_factory_.GetWeakPtr()))) {
262 return; 253 return;
263 } 254 }
264 255
265 // Update |policy_brokers_|, keeping existing entries. 256 // Update |policy_brokers_|, keeping existing entries.
266 PolicyBrokerMap new_policy_brokers; 257 PolicyBrokerMap new_policy_brokers;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 CloudPolicyStore* store) { 291 CloudPolicyStore* store) {
301 for (PolicyBrokerMap::iterator it(policy_brokers_.begin()); 292 for (PolicyBrokerMap::iterator it(policy_brokers_.begin());
302 it != policy_brokers_.end(); ++it) { 293 it != policy_brokers_.end(); ++it) {
303 if (it->second.broker && it->second.broker->core()->store() == store) 294 if (it->second.broker && it->second.broker->core()->store() == store)
304 return it->second.broker; 295 return it->second.broker;
305 } 296 }
306 return NULL; 297 return NULL;
307 } 298 }
308 299
309 } // namespace policy 300 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698