OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ownership/owner_settings_service_chromeos.h" | 5 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 scoped_refptr<base::TaskRunner> task_runner = | 139 scoped_refptr<base::TaskRunner> task_runner = |
140 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( | 140 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
141 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 141 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
142 base::PostTaskAndReplyWithResult( | 142 base::PostTaskAndReplyWithResult( |
143 task_runner.get(), | 143 task_runner.get(), |
144 FROM_HERE, | 144 FROM_HERE, |
145 base::Bind(&DoesPrivateKeyExistAsyncHelper, owner_key_util), | 145 base::Bind(&DoesPrivateKeyExistAsyncHelper, owner_key_util), |
146 callback); | 146 callback); |
147 } | 147 } |
148 | 148 |
149 template <typename E> | |
150 bool Eq(const E& lhs, const E& rhs) { | |
151 return lhs == rhs; | |
152 } | |
153 | |
154 template <> | |
155 bool Eq<em::AppPackEntryProto>(const em::AppPackEntryProto& lhs, | |
156 const em::AppPackEntryProto& rhs) { | |
157 if (lhs.has_extension_id() != rhs.has_extension_id()) | |
158 return false; | |
159 if (lhs.has_extension_id() && lhs.extension_id() != rhs.extension_id()) | |
160 return false; | |
161 if (lhs.has_update_url() != rhs.has_update_url()) | |
162 return false; | |
163 if (lhs.has_update_url() && lhs.update_url() != rhs.update_url()) | |
164 return false; | |
165 if (lhs.has_obsolete_online_only() != rhs.has_obsolete_online_only()) | |
166 return false; | |
167 if (lhs.has_obsolete_online_only() && | |
168 lhs.obsolete_online_only() != rhs.obsolete_online_only()) | |
169 return false; | |
170 return true; | |
171 } | |
172 | |
173 template <> | |
174 bool Eq<em::KioskAppInfoProto>(const em::KioskAppInfoProto& lhs, | |
175 const em::KioskAppInfoProto& rhs) { | |
176 if (lhs.has_app_id() != rhs.has_app_id()) | |
177 return false; | |
178 if (lhs.has_app_id() && lhs.app_id() != rhs.app_id()) | |
179 return false; | |
180 if (lhs.has_update_url() != rhs.has_update_url()) | |
181 return false; | |
182 if (lhs.has_update_url() && lhs.update_url() != rhs.update_url()) | |
183 return false; | |
184 return true; | |
185 } | |
186 | |
187 template <> | |
188 bool Eq<em::DeviceLocalAccountInfoProto>( | |
189 const em::DeviceLocalAccountInfoProto& lhs, | |
190 const em::DeviceLocalAccountInfoProto& rhs) { | |
191 if (lhs.has_deprecated_public_session_id() != | |
192 rhs.has_deprecated_public_session_id()) { | |
193 return false; | |
194 } | |
195 if (lhs.has_deprecated_public_session_id() && | |
196 lhs.deprecated_public_session_id() != | |
197 rhs.deprecated_public_session_id()) { | |
198 return false; | |
199 } | |
200 if (lhs.has_account_id() != rhs.has_account_id()) | |
201 return false; | |
202 if (lhs.has_account_id() && lhs.account_id() != rhs.account_id()) | |
203 return false; | |
204 if (lhs.has_type() != rhs.has_type()) | |
205 return false; | |
206 if (lhs.has_type() && lhs.type() != rhs.type()) | |
207 return false; | |
208 if (lhs.has_kiosk_app() != rhs.has_kiosk_app()) | |
209 return false; | |
210 if (lhs.has_kiosk_app() && !Eq(lhs.kiosk_app(), rhs.kiosk_app())) | |
211 return false; | |
212 return true; | |
213 } | |
214 | |
215 template <template <typename> class R, typename E> | |
Mattias Nissler (ping if slow)
2014/11/07 16:07:35
Could use better names for R and E to indicate wha
| |
216 bool Exists(const R<E>& collection, const E& elem) { | |
217 for (const auto& e : collection) { | |
218 if (Eq(e, elem)) | |
219 return true; | |
220 } | |
221 return false; | |
222 } | |
223 | |
224 template <template <typename> class R, typename E> | |
225 void Merge(const R<E>& from, R<E>* to) { | |
226 for (const auto& f : from) { | |
227 if (!Exists(*to, f)) | |
228 *to->Add() = f; | |
Mattias Nissler (ping if slow)
2014/11/07 16:07:35
If merging only ever adds fields, how would I actu
ygorshenin1
2014/11/07 17:24:32
You're right, it's impossible to remove values fro
| |
229 } | |
230 } | |
231 | |
232 void MergeSettings(const em::ChromeDeviceSettingsProto& from, | |
233 em::ChromeDeviceSettingsProto* to) { | |
234 ::google::protobuf::RepeatedPtrField<std::string> user_whitelist( | |
235 to->user_whitelist().user_whitelist()); | |
236 Merge(from.user_whitelist().user_whitelist(), &user_whitelist); | |
237 | |
238 ::google::protobuf::RepeatedPtrField<em::AppPackEntryProto> app_pack( | |
239 to->app_pack().app_pack()); | |
240 Merge(from.app_pack().app_pack(), &app_pack); | |
241 | |
242 ::google::protobuf::RepeatedPtrField<std::string> app_id( | |
243 to->pinned_apps().app_id()); | |
244 Merge(from.pinned_apps().app_id(), &app_id); | |
245 | |
246 ::google::protobuf::RepeatedField<int> connection_types( | |
247 to->auto_update_settings().allowed_connection_types()); | |
248 Merge(from.auto_update_settings().allowed_connection_types(), | |
249 &connection_types); | |
250 | |
251 ::google::protobuf::RepeatedPtrField<std::string> start_up_urls( | |
252 to->start_up_urls().start_up_urls()); | |
253 Merge(from.start_up_urls().start_up_urls(), &start_up_urls); | |
254 | |
255 ::google::protobuf::RepeatedPtrField<em::DeviceLocalAccountInfoProto> account( | |
256 to->device_local_accounts().account()); | |
257 Merge(from.device_local_accounts().account(), &account); | |
258 | |
259 em::ChromeDeviceSettingsProto settings = from; | |
260 settings.MergeFrom(*to); | |
261 settings.mutable_user_whitelist()->mutable_user_whitelist()->CopyFrom( | |
262 user_whitelist); | |
263 settings.mutable_app_pack()->mutable_app_pack()->CopyFrom(app_pack); | |
264 settings.mutable_pinned_apps()->mutable_app_id()->CopyFrom(app_id); | |
265 settings.mutable_auto_update_settings() | |
266 ->mutable_allowed_connection_types() | |
267 ->CopyFrom(connection_types); | |
268 settings.mutable_start_up_urls()->mutable_start_up_urls()->CopyFrom( | |
269 start_up_urls); | |
270 settings.mutable_device_local_accounts()->mutable_account()->CopyFrom( | |
271 account); | |
272 to->Swap(&settings); | |
273 } | |
274 | |
149 } // namespace | 275 } // namespace |
150 | 276 |
151 OwnerSettingsServiceChromeOS::OwnerSettingsServiceChromeOS( | 277 OwnerSettingsServiceChromeOS::OwnerSettingsServiceChromeOS( |
152 DeviceSettingsService* device_settings_service, | 278 DeviceSettingsService* device_settings_service, |
153 Profile* profile, | 279 Profile* profile, |
154 const scoped_refptr<OwnerKeyUtil>& owner_key_util) | 280 const scoped_refptr<OwnerKeyUtil>& owner_key_util) |
155 : ownership::OwnerSettingsService(owner_key_util), | 281 : ownership::OwnerSettingsService(owner_key_util), |
156 device_settings_service_(device_settings_service), | 282 device_settings_service_(device_settings_service), |
157 profile_(profile), | 283 profile_(profile), |
158 waiting_for_profile_creation_(true), | 284 waiting_for_profile_creation_(true), |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
626 has_pending_changes_ = true; | 752 has_pending_changes_ = true; |
627 } | 753 } |
628 | 754 |
629 bool OwnerSettingsServiceChromeOS::UpdateFromService() { | 755 bool OwnerSettingsServiceChromeOS::UpdateFromService() { |
630 if (!device_settings_service_ || | 756 if (!device_settings_service_ || |
631 device_settings_service_->status() != | 757 device_settings_service_->status() != |
632 DeviceSettingsService::STORE_SUCCESS || | 758 DeviceSettingsService::STORE_SUCCESS || |
633 !device_settings_service_->device_settings()) { | 759 !device_settings_service_->device_settings()) { |
634 return false; | 760 return false; |
635 } | 761 } |
636 enterprise_management::ChromeDeviceSettingsProto settings = | 762 MergeSettings(*device_settings_service_->device_settings(), |
637 *device_settings_service_->device_settings(); | 763 &device_settings_); |
638 settings.MergeFrom(device_settings_); | |
639 device_settings_.Swap(&settings); | |
640 return true; | 764 return true; |
641 } | 765 } |
642 | 766 |
643 } // namespace chromeos | 767 } // namespace chromeos |
OLD | NEW |