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/chromeos/policy/device_local_account_policy_service.h" | 5 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "chrome/browser/chromeos/policy/device_local_account_policy_store.h" | 9 #include "chrome/browser/chromeos/policy/device_local_account_policy_store.h" |
10 #include "chrome/browser/policy/cloud/cloud_policy_client.h" | 10 #include "chrome/browser/policy/cloud/cloud_policy_client.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 void DeviceLocalAccountPolicyService::UpdateAccountList( | 159 void DeviceLocalAccountPolicyService::UpdateAccountList( |
160 const em::ChromeDeviceSettingsProto& device_settings) { | 160 const em::ChromeDeviceSettingsProto& device_settings) { |
161 using google::protobuf::RepeatedPtrField; | 161 using google::protobuf::RepeatedPtrField; |
162 | 162 |
163 // Update |policy_brokers_|, keeping existing entries. | 163 // Update |policy_brokers_|, keeping existing entries. |
164 PolicyBrokerMap new_policy_brokers; | 164 PolicyBrokerMap new_policy_brokers; |
165 const RepeatedPtrField<em::DeviceLocalAccountInfoProto>& accounts = | 165 const RepeatedPtrField<em::DeviceLocalAccountInfoProto>& accounts = |
166 device_settings.device_local_accounts().account(); | 166 device_settings.device_local_accounts().account(); |
167 RepeatedPtrField<em::DeviceLocalAccountInfoProto>::const_iterator entry; | 167 RepeatedPtrField<em::DeviceLocalAccountInfoProto>::const_iterator entry; |
168 for (entry = accounts.begin(); entry != accounts.end(); ++entry) { | 168 for (entry = accounts.begin(); entry != accounts.end(); ++entry) { |
169 if (entry->has_id()) { | 169 std::string account_id; |
170 // Sanity check for whether this account ID has already been processed. | 170 if (entry->has_type() && |
171 DeviceLocalAccountPolicyBroker*& new_broker = | 171 entry->type() == |
172 new_policy_brokers[entry->id()]; | 172 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION) { |
173 if (new_broker) { | 173 account_id = entry->account_id(); |
174 LOG(WARNING) << "Duplicate public account " << entry->id(); | 174 } else if (entry->has_id()) { |
175 continue; | 175 account_id = entry->id(); |
176 } | 176 } |
177 | 177 |
178 // Reuse the existing broker if present. | 178 if (account_id.empty()) |
179 DeviceLocalAccountPolicyBroker*& existing_broker = | 179 continue; |
180 policy_brokers_[entry->id()]; | |
181 new_broker = existing_broker; | |
182 existing_broker = NULL; | |
183 | 180 |
184 // Fire up the cloud connection for fetching policy for the account from | 181 // Sanity check for whether this account ID has already been processed. |
185 // the cloud if this is an enterprise-managed device. | 182 DeviceLocalAccountPolicyBroker*& new_broker = |
186 if (!new_broker || !new_broker->core()->client()) { | 183 new_policy_brokers[account_id]; |
187 scoped_ptr<CloudPolicyClient> client( | 184 if (new_broker) { |
188 CreateClientForAccount(entry->id())); | 185 LOG(WARNING) << "Duplicate public account " << account_id; |
189 if (client.get()) { | 186 continue; |
190 if (!new_broker) | 187 } |
191 new_broker = CreateBroker(entry->id()).release(); | 188 |
192 new_broker->Connect(client.Pass()); | 189 // Reuse the existing broker if present. |
193 } | 190 DeviceLocalAccountPolicyBroker*& existing_broker = |
| 191 policy_brokers_[account_id]; |
| 192 new_broker = existing_broker; |
| 193 existing_broker = NULL; |
| 194 |
| 195 // Fire up the cloud connection for fetching policy for the account from |
| 196 // the cloud if this is an enterprise-managed device. |
| 197 if (!new_broker || !new_broker->core()->client()) { |
| 198 scoped_ptr<CloudPolicyClient> client( |
| 199 CreateClientForAccount(account_id)); |
| 200 if (client.get()) { |
| 201 if (!new_broker) |
| 202 new_broker = CreateBroker(account_id).release(); |
| 203 new_broker->Connect(client.Pass()); |
194 } | 204 } |
195 } | 205 } |
196 } | 206 } |
197 policy_brokers_.swap(new_policy_brokers); | 207 policy_brokers_.swap(new_policy_brokers); |
198 DeleteBrokers(&new_policy_brokers); | 208 DeleteBrokers(&new_policy_brokers); |
199 | 209 |
200 FOR_EACH_OBSERVER(Observer, observers_, OnDeviceLocalAccountsChanged()); | 210 FOR_EACH_OBSERVER(Observer, observers_, OnDeviceLocalAccountsChanged()); |
201 } | 211 } |
202 | 212 |
203 scoped_ptr<DeviceLocalAccountPolicyBroker> | 213 scoped_ptr<DeviceLocalAccountPolicyBroker> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 scoped_ptr<CloudPolicyClient> client( | 259 scoped_ptr<CloudPolicyClient> client( |
250 new CloudPolicyClient(std::string(), std::string(), | 260 new CloudPolicyClient(std::string(), std::string(), |
251 USER_AFFILIATION_MANAGED, | 261 USER_AFFILIATION_MANAGED, |
252 NULL, device_management_service_)); | 262 NULL, device_management_service_)); |
253 client->SetupRegistration(policy_data->request_token(), | 263 client->SetupRegistration(policy_data->request_token(), |
254 policy_data->device_id()); | 264 policy_data->device_id()); |
255 return client.Pass(); | 265 return client.Pass(); |
256 } | 266 } |
257 | 267 |
258 } // namespace policy | 268 } // namespace policy |
OLD | NEW |