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

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

Powered by Google App Engine
This is Rietveld 408576698