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

Side by Side Diff: chrome/browser/chromeos/ownership/owner_settings_service_chromeos.cc

Issue 654263003: Implemented OwnerSettingsService::Set() method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with https://codereview.chromium.org/666363002/. Created 6 years, 2 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
OLDNEW
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"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/chromeos/profiles/profile_helper.h" 16 #include "chrome/browser/chromeos/profiles/profile_helper.h"
17 #include "chrome/browser/chromeos/settings/cros_settings.h" 17 #include "chrome/browser/chromeos/settings/cros_settings.h"
18 #include "chrome/browser/chromeos/settings/device_settings_provider.h"
18 #include "chrome/browser/chromeos/settings/session_manager_operation.h" 19 #include "chrome/browser/chromeos/settings/session_manager_operation.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chromeos/dbus/dbus_thread_manager.h" 21 #include "chromeos/dbus/dbus_thread_manager.h"
21 #include "chromeos/tpm_token_loader.h" 22 #include "chromeos/tpm_token_loader.h"
22 #include "components/ownership/owner_key_util.h" 23 #include "components/ownership/owner_key_util.h"
23 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 24 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
24 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/notification_details.h" 26 #include "content/public/browser/notification_details.h"
26 #include "content/public/browser/notification_service.h" 27 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/notification_source.h" 28 #include "content/public/browser/notification_source.h"
28 #include "content/public/common/content_switches.h" 29 #include "content/public/common/content_switches.h"
29 #include "crypto/nss_util.h" 30 #include "crypto/nss_util.h"
30 #include "crypto/nss_util_internal.h" 31 #include "crypto/nss_util_internal.h"
31 #include "crypto/rsa_private_key.h" 32 #include "crypto/rsa_private_key.h"
32 #include "crypto/scoped_nss_types.h" 33 #include "crypto/scoped_nss_types.h"
33 #include "crypto/signature_creator.h" 34 #include "crypto/signature_creator.h"
34 35
35 namespace em = enterprise_management; 36 namespace em = enterprise_management;
36 37
37 using content::BrowserThread; 38 using content::BrowserThread;
38 using ownership::OwnerKeyUtil; 39 using ownership::OwnerKeyUtil;
39 using ownership::PrivateKey; 40 using ownership::PrivateKey;
40 using ownership::PublicKey; 41 using ownership::PublicKey;
41 42
42 namespace chromeos { 43 namespace chromeos {
43 44
44 namespace { 45 namespace {
45 46
46 DeviceSettingsService* g_device_settings_service_for_testing = NULL;
47
48 bool IsOwnerInTests(const std::string& user_id) { 47 bool IsOwnerInTests(const std::string& user_id) {
49 if (user_id.empty() || 48 if (user_id.empty() ||
50 !CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType) || 49 !CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType) ||
51 !CrosSettings::IsInitialized()) { 50 !CrosSettings::IsInitialized()) {
52 return false; 51 return false;
53 } 52 }
54 const base::Value* value = CrosSettings::Get()->GetPref(kDeviceOwner); 53 const base::Value* value = CrosSettings::Get()->GetPref(kDeviceOwner);
55 if (!value || value->GetType() != base::Value::TYPE_STRING) 54 if (!value || value->GetType() != base::Value::TYPE_STRING)
56 return false; 55 return false;
57 return static_cast<const base::StringValue*>(value)->GetString() == user_id; 56 return static_cast<const base::StringValue*>(value)->GetString() == user_id;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 scoped_refptr<base::TaskRunner> task_runner = 139 scoped_refptr<base::TaskRunner> task_runner =
141 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( 140 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
142 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 141 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
143 base::PostTaskAndReplyWithResult( 142 base::PostTaskAndReplyWithResult(
144 task_runner.get(), 143 task_runner.get(),
145 FROM_HERE, 144 FROM_HERE,
146 base::Bind(&DoesPrivateKeyExistAsyncHelper, owner_key_util), 145 base::Bind(&DoesPrivateKeyExistAsyncHelper, owner_key_util),
147 callback); 146 callback);
148 } 147 }
149 148
150 DeviceSettingsService* GetDeviceSettingsService() {
151 if (g_device_settings_service_for_testing)
152 return g_device_settings_service_for_testing;
153 return DeviceSettingsService::IsInitialized() ? DeviceSettingsService::Get()
154 : NULL;
155 }
156
157 } // namespace 149 } // namespace
158 150
159 OwnerSettingsServiceChromeOS::OwnerSettingsServiceChromeOS( 151 OwnerSettingsServiceChromeOS::OwnerSettingsServiceChromeOS(
152 DeviceSettingsService* device_settings_service,
160 Profile* profile, 153 Profile* profile,
161 const scoped_refptr<OwnerKeyUtil>& owner_key_util) 154 const scoped_refptr<OwnerKeyUtil>& owner_key_util)
162 : ownership::OwnerSettingsService(owner_key_util), 155 : ownership::OwnerSettingsService(owner_key_util),
156 device_settings_service_(device_settings_service),
163 profile_(profile), 157 profile_(profile),
164 waiting_for_profile_creation_(true), 158 waiting_for_profile_creation_(true),
165 waiting_for_tpm_token_(true), 159 waiting_for_tpm_token_(true),
166 weak_factory_(this) { 160 has_pending_changes_(false),
161 weak_factory_(this),
162 store_settings_factory_(this) {
167 if (TPMTokenLoader::IsInitialized()) { 163 if (TPMTokenLoader::IsInitialized()) {
168 TPMTokenLoader::TPMTokenStatus tpm_token_status = 164 TPMTokenLoader::TPMTokenStatus tpm_token_status =
169 TPMTokenLoader::Get()->IsTPMTokenEnabled( 165 TPMTokenLoader::Get()->IsTPMTokenEnabled(
170 base::Bind(&OwnerSettingsServiceChromeOS::OnTPMTokenReady, 166 base::Bind(&OwnerSettingsServiceChromeOS::OnTPMTokenReady,
171 weak_factory_.GetWeakPtr())); 167 weak_factory_.GetWeakPtr()));
172 waiting_for_tpm_token_ = 168 waiting_for_tpm_token_ =
173 tpm_token_status == TPMTokenLoader::TPM_TOKEN_STATUS_UNDETERMINED; 169 tpm_token_status == TPMTokenLoader::TPM_TOKEN_STATUS_UNDETERMINED;
174 } 170 }
175 171
176 if (DBusThreadManager::IsInitialized() && 172 if (DBusThreadManager::IsInitialized() &&
177 DBusThreadManager::Get()->GetSessionManagerClient()) { 173 DBusThreadManager::Get()->GetSessionManagerClient()) {
178 DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this); 174 DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this);
179 } 175 }
180 176
177 device_settings_service_->AddObserver(this);
178
181 registrar_.Add(this, 179 registrar_.Add(this,
182 chrome::NOTIFICATION_PROFILE_CREATED, 180 chrome::NOTIFICATION_PROFILE_CREATED,
183 content::Source<Profile>(profile_)); 181 content::Source<Profile>(profile_));
182
183 UpdateFromService();
184 } 184 }
185 185
186 OwnerSettingsServiceChromeOS::~OwnerSettingsServiceChromeOS() { 186 OwnerSettingsServiceChromeOS::~OwnerSettingsServiceChromeOS() {
187 DCHECK(thread_checker_.CalledOnValidThread()); 187 DCHECK(thread_checker_.CalledOnValidThread());
188
189 device_settings_service_->RemoveObserver(this);
190
188 if (DBusThreadManager::IsInitialized() && 191 if (DBusThreadManager::IsInitialized() &&
189 DBusThreadManager::Get()->GetSessionManagerClient()) { 192 DBusThreadManager::Get()->GetSessionManagerClient()) {
190 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); 193 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this);
191 } 194 }
195
196 device_settings_service_->RemoveObserver(this);
192 } 197 }
193 198
194 void OwnerSettingsServiceChromeOS::OnTPMTokenReady( 199 void OwnerSettingsServiceChromeOS::OnTPMTokenReady(
195 bool /* tpm_token_enabled */) { 200 bool /* tpm_token_enabled */) {
196 DCHECK(thread_checker_.CalledOnValidThread()); 201 DCHECK(thread_checker_.CalledOnValidThread());
197 waiting_for_tpm_token_ = false; 202 waiting_for_tpm_token_ = false;
198 203
199 // TPMTokenLoader initializes the TPM and NSS database which is necessary to 204 // TPMTokenLoader initializes the TPM and NSS database which is necessary to
200 // determine ownership. Force a reload once we know these are initialized. 205 // determine ownership. Force a reload once we know these are initialized.
201 ReloadKeypair(); 206 ReloadKeypair();
202 } 207 }
203 208
204 void OwnerSettingsServiceChromeOS::SignAndStorePolicyAsync( 209 bool OwnerSettingsServiceChromeOS::HandlesSetting(const std::string& setting) {
205 scoped_ptr<em::PolicyData> policy, 210 return DeviceSettingsProvider::IsDeviceSetting(setting);
206 const base::Closure& callback) { 211 }
207 DCHECK(thread_checker_.CalledOnValidThread()); 212
208 SignAndStoreSettingsOperation* operation = new SignAndStoreSettingsOperation( 213 bool OwnerSettingsServiceChromeOS::Set(const std::string& setting,
209 base::Bind(&OwnerSettingsServiceChromeOS::HandleCompletedOperation, 214 const base::Value& value) {
210 weak_factory_.GetWeakPtr(), 215 if (!IsOwner() && !IsOwnerInTests(user_id_))
211 callback), 216 return false;
212 policy.Pass()); 217
213 operation->set_owner_settings_service(weak_factory_.GetWeakPtr()); 218 UpdateDeviceSettings(setting, value, device_settings_);
214 pending_operations_.push_back(operation); 219 em::PolicyData policy_data;
215 if (pending_operations_.front() == operation) 220 policy_data.set_username(user_id_);
216 StartNextOperation(); 221 CHECK(device_settings_.SerializeToString(policy_data.mutable_policy_value()));
222 FOR_EACH_OBSERVER(OwnerSettingsService::Observer,
223 observers_,
224 OnTentativeChangesInPolicy(policy_data));
225 has_pending_changes_ = true;
226 StoreDeviceSettings();
227 return true;
228 }
229
230 bool OwnerSettingsServiceChromeOS::CommitTentativeDeviceSettings(
231 scoped_ptr<enterprise_management::PolicyData> policy) {
232 if (!IsOwner() && !IsOwnerInTests(user_id_))
233 return false;
234 if (policy->username() != user_id_) {
235 LOG(ERROR) << "Username mismatch: " << policy->username() << " vs. "
236 << user_id_;
237 return false;
238 }
239 CHECK(device_settings_.ParseFromString(policy->policy_value()));
240 FOR_EACH_OBSERVER(OwnerSettingsService::Observer,
241 observers_,
242 OnTentativeChangesInPolicy(*policy));
243 has_pending_changes_ = true;
244 StoreDeviceSettings();
245 return true;
217 } 246 }
218 247
219 void OwnerSettingsServiceChromeOS::Observe( 248 void OwnerSettingsServiceChromeOS::Observe(
220 int type, 249 int type,
221 const content::NotificationSource& source, 250 const content::NotificationSource& source,
222 const content::NotificationDetails& details) { 251 const content::NotificationDetails& details) {
223 DCHECK(thread_checker_.CalledOnValidThread()); 252 DCHECK(thread_checker_.CalledOnValidThread());
224 if (type != chrome::NOTIFICATION_PROFILE_CREATED) { 253 if (type != chrome::NOTIFICATION_PROFILE_CREATED) {
225 NOTREACHED(); 254 NOTREACHED();
226 return; 255 return;
227 } 256 }
228 257
229 Profile* profile = content::Source<Profile>(source).ptr(); 258 Profile* profile = content::Source<Profile>(source).ptr();
230 if (profile != profile_) { 259 if (profile != profile_) {
231 NOTREACHED(); 260 NOTREACHED();
232 return; 261 return;
233 } 262 }
234 263
235 waiting_for_profile_creation_ = false; 264 waiting_for_profile_creation_ = false;
236 ReloadKeypair(); 265 ReloadKeypair();
237 } 266 }
238 267
239 void OwnerSettingsServiceChromeOS::OwnerKeySet(bool success) { 268 void OwnerSettingsServiceChromeOS::OwnerKeySet(bool success) {
240 DCHECK(thread_checker_.CalledOnValidThread()); 269 DCHECK(thread_checker_.CalledOnValidThread());
241 if (success) 270 if (success)
242 ReloadKeypair(); 271 ReloadKeypair();
243 } 272 }
244 273
274 void OwnerSettingsServiceChromeOS::OwnershipStatusChanged() {
275 DCHECK(thread_checker_.CalledOnValidThread());
276 StoreDeviceSettings();
277 }
278
279 void OwnerSettingsServiceChromeOS::DeviceSettingsUpdated() {
280 DCHECK(thread_checker_.CalledOnValidThread());
281 StoreDeviceSettings();
282 }
283
245 // static 284 // static
246 void OwnerSettingsServiceChromeOS::IsOwnerForSafeModeAsync( 285 void OwnerSettingsServiceChromeOS::IsOwnerForSafeModeAsync(
247 const std::string& user_hash, 286 const std::string& user_hash,
248 const scoped_refptr<OwnerKeyUtil>& owner_key_util, 287 const scoped_refptr<OwnerKeyUtil>& owner_key_util,
249 const IsOwnerCallback& callback) { 288 const IsOwnerCallback& callback) {
250 CHECK(chromeos::LoginState::Get()->IsInSafeMode()); 289 CHECK(chromeos::LoginState::Get()->IsInSafeMode());
251 290
252 // Make sure NSS is initialized and NSS DB is loaded for the user before 291 // Make sure NSS is initialized and NSS DB is loaded for the user before
253 // searching for the owner key. 292 // searching for the owner key.
254 BrowserThread::PostTaskAndReply( 293 BrowserThread::PostTaskAndReply(
255 BrowserThread::IO, 294 BrowserThread::IO,
256 FROM_HERE, 295 FROM_HERE,
257 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser), 296 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser),
258 user_hash, 297 user_hash,
259 ProfileHelper::GetProfilePathByUserIdHash(user_hash)), 298 ProfileHelper::GetProfilePathByUserIdHash(user_hash)),
260 base::Bind(&DoesPrivateKeyExistAsync, owner_key_util, callback)); 299 base::Bind(&DoesPrivateKeyExistAsync, owner_key_util, callback));
261 } 300 }
262 301
263 // static 302 // static
264 void OwnerSettingsServiceChromeOS::SetDeviceSettingsServiceForTesting( 303 scoped_ptr<em::PolicyData> OwnerSettingsServiceChromeOS::AssemblePolicy(
265 DeviceSettingsService* device_settings_service) { 304 const std::string& user_id,
266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 305 const em::PolicyData* policy_data,
267 g_device_settings_service_for_testing = device_settings_service; 306 const em::ChromeDeviceSettingsProto* settings) {
307 scoped_ptr<em::PolicyData> policy(new em::PolicyData());
308 if (policy_data) {
309 // Preserve management settings.
310 if (policy_data->has_management_mode())
311 policy->set_management_mode(policy_data->management_mode());
312 if (policy_data->has_request_token())
313 policy->set_request_token(policy_data->request_token());
314 if (policy_data->has_device_id())
315 policy->set_device_id(policy_data->device_id());
316 } else {
317 // If there's no previous policy data, this is the first time the device
318 // setting is set. We set the management mode to NOT_MANAGED initially.
319 policy->set_management_mode(em::PolicyData::NOT_MANAGED);
320 }
321 policy->set_policy_type(policy::dm_protocol::kChromeDevicePolicyType);
322 policy->set_timestamp(
323 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds());
324 policy->set_username(user_id);
325 if (!settings->SerializeToString(policy->mutable_policy_value()))
326 return scoped_ptr<em::PolicyData>();
327
328 return policy.Pass();
268 } 329 }
269 330
331 // static
332 void OwnerSettingsServiceChromeOS::UpdateDeviceSettings(
333 const std::string& path,
334 const base::Value& value,
335 enterprise_management::ChromeDeviceSettingsProto& settings) {
336 if (path == kAccountsPrefAllowNewUser) {
337 em::AllowNewUsersProto* allow = settings.mutable_allow_new_users();
338 bool allow_value;
339 if (value.GetAsBoolean(&allow_value)) {
340 allow->set_allow_new_users(allow_value);
341 } else {
342 NOTREACHED();
343 }
344 } else if (path == kAccountsPrefAllowGuest) {
345 em::GuestModeEnabledProto* guest = settings.mutable_guest_mode_enabled();
346 bool guest_value;
347 if (value.GetAsBoolean(&guest_value))
348 guest->set_guest_mode_enabled(guest_value);
349 else
350 NOTREACHED();
351 } else if (path == kAccountsPrefSupervisedUsersEnabled) {
352 em::SupervisedUsersSettingsProto* supervised =
353 settings.mutable_supervised_users_settings();
354 bool supervised_value;
355 if (value.GetAsBoolean(&supervised_value))
356 supervised->set_supervised_users_enabled(supervised_value);
357 else
358 NOTREACHED();
359 } else if (path == kAccountsPrefShowUserNamesOnSignIn) {
360 em::ShowUserNamesOnSigninProto* show = settings.mutable_show_user_names();
361 bool show_value;
362 if (value.GetAsBoolean(&show_value))
363 show->set_show_user_names(show_value);
364 else
365 NOTREACHED();
366 } else if (path == kAccountsPrefDeviceLocalAccounts) {
367 em::DeviceLocalAccountsProto* device_local_accounts =
368 settings.mutable_device_local_accounts();
369 device_local_accounts->clear_account();
370 const base::ListValue* accounts_list = NULL;
371 if (value.GetAsList(&accounts_list)) {
372 for (base::ListValue::const_iterator entry(accounts_list->begin());
373 entry != accounts_list->end();
374 ++entry) {
375 const base::DictionaryValue* entry_dict = NULL;
376 if ((*entry)->GetAsDictionary(&entry_dict)) {
377 em::DeviceLocalAccountInfoProto* account =
378 device_local_accounts->add_account();
379 std::string account_id;
380 if (entry_dict->GetStringWithoutPathExpansion(
381 kAccountsPrefDeviceLocalAccountsKeyId, &account_id)) {
382 account->set_account_id(account_id);
383 }
384 int type;
385 if (entry_dict->GetIntegerWithoutPathExpansion(
386 kAccountsPrefDeviceLocalAccountsKeyType, &type)) {
387 account->set_type(
388 static_cast<em::DeviceLocalAccountInfoProto::AccountType>(
389 type));
390 }
391 std::string kiosk_app_id;
392 if (entry_dict->GetStringWithoutPathExpansion(
393 kAccountsPrefDeviceLocalAccountsKeyKioskAppId,
394 &kiosk_app_id)) {
395 account->mutable_kiosk_app()->set_app_id(kiosk_app_id);
396 }
397 } else {
398 NOTREACHED();
399 }
400 }
401 } else {
402 NOTREACHED();
403 }
404 } else if (path == kAccountsPrefDeviceLocalAccountAutoLoginId) {
405 em::DeviceLocalAccountsProto* device_local_accounts =
406 settings.mutable_device_local_accounts();
407 std::string id;
408 if (value.GetAsString(&id))
409 device_local_accounts->set_auto_login_id(id);
410 else
411 NOTREACHED();
412 } else if (path == kAccountsPrefDeviceLocalAccountAutoLoginDelay) {
413 em::DeviceLocalAccountsProto* device_local_accounts =
414 settings.mutable_device_local_accounts();
415 int delay;
416 if (value.GetAsInteger(&delay))
417 device_local_accounts->set_auto_login_delay(delay);
418 else
419 NOTREACHED();
420 } else if (path == kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled) {
421 em::DeviceLocalAccountsProto* device_local_accounts =
422 settings.mutable_device_local_accounts();
423 bool enabled;
424 if (value.GetAsBoolean(&enabled))
425 device_local_accounts->set_enable_auto_login_bailout(enabled);
426 else
427 NOTREACHED();
428 } else if (path ==
429 kAccountsPrefDeviceLocalAccountPromptForNetworkWhenOffline) {
430 em::DeviceLocalAccountsProto* device_local_accounts =
431 settings.mutable_device_local_accounts();
432 bool should_prompt;
433 if (value.GetAsBoolean(&should_prompt))
434 device_local_accounts->set_prompt_for_network_when_offline(should_prompt);
435 else
436 NOTREACHED();
437 } else if (path == kSignedDataRoamingEnabled) {
438 em::DataRoamingEnabledProto* roam = settings.mutable_data_roaming_enabled();
439 bool roaming_value = false;
440 if (value.GetAsBoolean(&roaming_value))
441 roam->set_data_roaming_enabled(roaming_value);
442 else
443 NOTREACHED();
444 } else if (path == kReleaseChannel) {
445 em::ReleaseChannelProto* release_channel =
446 settings.mutable_release_channel();
447 std::string channel_value;
448 if (value.GetAsString(&channel_value))
449 release_channel->set_release_channel(channel_value);
450 else
451 NOTREACHED();
452 } else if (path == kStatsReportingPref) {
453 em::MetricsEnabledProto* metrics = settings.mutable_metrics_enabled();
454 bool metrics_value = false;
455 if (value.GetAsBoolean(&metrics_value))
456 metrics->set_metrics_enabled(metrics_value);
457 else
458 NOTREACHED();
459 } else if (path == kAccountsPrefUsers) {
460 em::UserWhitelistProto* whitelist_proto = settings.mutable_user_whitelist();
461 whitelist_proto->clear_user_whitelist();
462 const base::ListValue* users;
463 if (value.GetAsList(&users)) {
464 for (base::ListValue::const_iterator i = users->begin();
465 i != users->end();
466 ++i) {
467 std::string email;
468 if ((*i)->GetAsString(&email))
469 whitelist_proto->add_user_whitelist(email);
470 }
471 }
472 } else if (path == kAccountsPrefEphemeralUsersEnabled) {
473 em::EphemeralUsersEnabledProto* ephemeral_users_enabled =
474 settings.mutable_ephemeral_users_enabled();
475 bool ephemeral_users_enabled_value = false;
476 if (value.GetAsBoolean(&ephemeral_users_enabled_value)) {
477 ephemeral_users_enabled->set_ephemeral_users_enabled(
478 ephemeral_users_enabled_value);
479 } else {
480 NOTREACHED();
481 }
482 } else if (path == kAllowRedeemChromeOsRegistrationOffers) {
483 em::AllowRedeemChromeOsRegistrationOffersProto* allow_redeem_offers =
484 settings.mutable_allow_redeem_offers();
485 bool allow_redeem_offers_value;
486 if (value.GetAsBoolean(&allow_redeem_offers_value)) {
487 allow_redeem_offers->set_allow_redeem_offers(allow_redeem_offers_value);
488 } else {
489 NOTREACHED();
490 }
491 } else if (path == kStartUpFlags) {
492 em::StartUpFlagsProto* flags_proto = settings.mutable_start_up_flags();
493 flags_proto->Clear();
494 const base::ListValue* flags;
495 if (value.GetAsList(&flags)) {
496 for (base::ListValue::const_iterator i = flags->begin();
497 i != flags->end();
498 ++i) {
499 std::string flag;
500 if ((*i)->GetAsString(&flag))
501 flags_proto->add_flags(flag);
502 }
503 }
504 } else if (path == kSystemUse24HourClock) {
505 em::SystemUse24HourClockProto* use_24hour_clock_proto =
506 settings.mutable_use_24hour_clock();
507 use_24hour_clock_proto->Clear();
508 bool use_24hour_clock_value;
509 if (value.GetAsBoolean(&use_24hour_clock_value)) {
510 use_24hour_clock_proto->set_use_24hour_clock(use_24hour_clock_value);
511 } else {
512 NOTREACHED();
513 }
514 } else if (path == kAttestationForContentProtectionEnabled) {
515 em::AttestationSettingsProto* attestation_settings =
516 settings.mutable_attestation_settings();
517 bool setting_enabled;
518 if (value.GetAsBoolean(&setting_enabled)) {
519 attestation_settings->set_content_protection_enabled(setting_enabled);
520 } else {
521 NOTREACHED();
522 }
523 } else {
524 // The remaining settings don't support Set(), since they are not
525 // intended to be customizable by the user:
526 // kAccountsPrefTransferSAMLCookies
527 // kAppPack
528 // kDeviceAttestationEnabled
529 // kDeviceOwner
530 // kIdleLogoutTimeout
531 // kIdleLogoutWarningDuration
532 // kReleaseChannelDelegated
533 // kReportDeviceActivityTimes
534 // kReportDeviceBootMode
535 // kReportDeviceLocation
536 // kReportDeviceVersionInfo
537 // kReportDeviceNetworkInterfaces
538 // kReportDeviceUsers
539 // kScreenSaverExtensionId
540 // kScreenSaverTimeout
541 // kServiceAccountIdentity
542 // kStartUpUrls
543 // kSystemTimezonePolicy
544 // kVariationsRestrictParameter
545
546 LOG(FATAL) << "Device setting " << path << " is read-only.";
547 }
548 }
549
270 void OwnerSettingsServiceChromeOS::OnPostKeypairLoadedActions() { 550 void OwnerSettingsServiceChromeOS::OnPostKeypairLoadedActions() {
271 DCHECK(thread_checker_.CalledOnValidThread()); 551 DCHECK(thread_checker_.CalledOnValidThread());
272 552
273 user_id_ = profile_->GetProfileName(); 553 user_id_ = profile_->GetProfileName();
274 const bool is_owner = IsOwner() || IsOwnerInTests(user_id_); 554 const bool is_owner = IsOwner() || IsOwnerInTests(user_id_);
275 if (is_owner && GetDeviceSettingsService()) 555 if (is_owner)
276 GetDeviceSettingsService()->InitOwner(user_id_, weak_factory_.GetWeakPtr()); 556 device_settings_service_->InitOwner(user_id_, weak_factory_.GetWeakPtr());
277 } 557 }
278 558
279 void OwnerSettingsServiceChromeOS::ReloadKeypairImpl(const base::Callback< 559 void OwnerSettingsServiceChromeOS::ReloadKeypairImpl(const base::Callback<
280 void(const scoped_refptr<PublicKey>& public_key, 560 void(const scoped_refptr<PublicKey>& public_key,
281 const scoped_refptr<PrivateKey>& private_key)>& callback) { 561 const scoped_refptr<PrivateKey>& private_key)>& callback) {
282 DCHECK(thread_checker_.CalledOnValidThread()); 562 DCHECK(thread_checker_.CalledOnValidThread());
283 563
284 if (waiting_for_profile_creation_ || waiting_for_tpm_token_) 564 if (waiting_for_profile_creation_ || waiting_for_tpm_token_)
285 return; 565 return;
286 scoped_refptr<base::TaskRunner> task_runner = 566 scoped_refptr<base::TaskRunner> task_runner =
287 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( 567 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
288 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 568 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
289 task_runner->PostTask( 569 task_runner->PostTask(
290 FROM_HERE, 570 FROM_HERE,
291 base::Bind(&LoadPrivateKey, 571 base::Bind(&LoadPrivateKey,
292 owner_key_util_, 572 owner_key_util_,
293 ProfileHelper::GetUserIdHashFromProfile(profile_), 573 ProfileHelper::GetUserIdHashFromProfile(profile_),
294 callback)); 574 callback));
295 } 575 }
296 576
297 void OwnerSettingsServiceChromeOS::StartNextOperation() { 577 void OwnerSettingsServiceChromeOS::StoreDeviceSettings() {
298 DeviceSettingsService* service = GetDeviceSettingsService(); 578 if (!has_pending_changes_ || store_settings_factory_.HasWeakPtrs())
299 if (!pending_operations_.empty() && service && 579 return;
300 service->session_manager_client()) { 580 if (!UpdateFromService())
301 pending_operations_.front()->Start( 581 return;
302 service->session_manager_client(), owner_key_util_, public_key_); 582 scoped_ptr<em::PolicyData> policy = AssemblePolicy(
303 } 583 user_id_, device_settings_service_->policy_data(), &device_settings_);
584 has_pending_changes_ = false;
585 bool rv = AssembleAndSignPolicyAsync(
586 content::BrowserThread::GetBlockingPool(),
587 policy.Pass(),
588 base::Bind(&OwnerSettingsServiceChromeOS::OnPolicyAssembledAndSigned,
589 store_settings_factory_.GetWeakPtr()));
590 if (!rv)
591 OnSignedPolicyStored(false /* success */);
304 } 592 }
305 593
306 void OwnerSettingsServiceChromeOS::HandleCompletedOperation( 594 void OwnerSettingsServiceChromeOS::OnPolicyAssembledAndSigned(
307 const base::Closure& callback, 595 scoped_ptr<em::PolicyFetchResponse> policy_response) {
308 SessionManagerOperation* operation, 596 if (!policy_response.get()) {
309 DeviceSettingsService::Status status) { 597 OnSignedPolicyStored(false /* success */);
310 DCHECK_EQ(operation, pending_operations_.front()); 598 return;
599 }
600 device_settings_service_->Store(
601 policy_response.Pass(),
602 base::Bind(&OwnerSettingsServiceChromeOS::OnSignedPolicyStored,
603 store_settings_factory_.GetWeakPtr(),
604 true /* success */));
605 }
311 606
312 DeviceSettingsService* service = GetDeviceSettingsService(); 607 void OwnerSettingsServiceChromeOS::OnSignedPolicyStored(bool success) {
313 if (status == DeviceSettingsService::STORE_SUCCESS) { 608 store_settings_factory_.InvalidateWeakPtrs();
314 service->set_policy_data(operation->policy_data().Pass()); 609 FOR_EACH_OBSERVER(OwnerSettingsService::Observer,
315 service->set_device_settings(operation->device_settings().Pass()); 610 observers_,
611 OnSignedPolicyStored(success));
612 StoreDeviceSettings();
613 if (!success)
614 has_pending_changes_ = true;
615 }
616
617 bool OwnerSettingsServiceChromeOS::UpdateFromService() {
618 if (device_settings_service_->status() !=
619 DeviceSettingsService::STORE_SUCCESS ||
620 !device_settings_service_->device_settings()) {
621 return false;
316 } 622 }
317 623 enterprise_management::ChromeDeviceSettingsProto settings =
318 if ((operation->public_key().get() && !public_key_.get()) || 624 *device_settings_service_->device_settings();
319 (operation->public_key().get() && public_key_.get() && 625 settings.MergeFrom(device_settings_);
320 operation->public_key()->data() != public_key_->data())) { 626 device_settings_.Swap(&settings);
321 // Public part changed so we need to reload private part too. 627 return true;
322 ReloadKeypair();
323 content::NotificationService::current()->Notify(
324 chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED,
325 content::Source<OwnerSettingsServiceChromeOS>(this),
326 content::NotificationService::NoDetails());
327 }
328 service->OnSignAndStoreOperationCompleted(status);
329 if (!callback.is_null())
330 callback.Run();
331
332 pending_operations_.pop_front();
333 delete operation;
334 StartNextOperation();
335 } 628 }
336 629
337 } // namespace chromeos 630 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698