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

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

Issue 640063008: Revert of Implemented OwnerSettingsService::Set() method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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"
19 #include "chrome/browser/chromeos/settings/session_manager_operation.h" 18 #include "chrome/browser/chromeos/settings/session_manager_operation.h"
20 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
21 #include "chromeos/dbus/dbus_thread_manager.h" 20 #include "chromeos/dbus/dbus_thread_manager.h"
22 #include "chromeos/tpm_token_loader.h" 21 #include "chromeos/tpm_token_loader.h"
23 #include "components/ownership/owner_key_util.h" 22 #include "components/ownership/owner_key_util.h"
24 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 23 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
25 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/notification_details.h" 25 #include "content/public/browser/notification_details.h"
27 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
28 #include "content/public/browser/notification_source.h" 27 #include "content/public/browser/notification_source.h"
29 #include "content/public/common/content_switches.h" 28 #include "content/public/common/content_switches.h"
30 #include "crypto/nss_util.h" 29 #include "crypto/nss_util.h"
31 #include "crypto/nss_util_internal.h" 30 #include "crypto/nss_util_internal.h"
32 #include "crypto/rsa_private_key.h" 31 #include "crypto/rsa_private_key.h"
33 #include "crypto/scoped_nss_types.h" 32 #include "crypto/scoped_nss_types.h"
34 #include "crypto/signature_creator.h" 33 #include "crypto/signature_creator.h"
35 34
36 namespace em = enterprise_management; 35 namespace em = enterprise_management;
37 36
38 using content::BrowserThread; 37 using content::BrowserThread;
39 using ownership::OwnerKeyUtil; 38 using ownership::OwnerKeyUtil;
40 using ownership::PrivateKey; 39 using ownership::PrivateKey;
41 using ownership::PublicKey; 40 using ownership::PublicKey;
42 41
43 namespace chromeos { 42 namespace chromeos {
44 43
45 namespace { 44 namespace {
46 45
46 DeviceSettingsService* g_device_settings_service_for_testing = NULL;
47
47 bool IsOwnerInTests(const std::string& user_id) { 48 bool IsOwnerInTests(const std::string& user_id) {
48 if (user_id.empty() || 49 if (user_id.empty() ||
49 !CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType) || 50 !CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType) ||
50 !CrosSettings::IsInitialized()) { 51 !CrosSettings::IsInitialized()) {
51 return false; 52 return false;
52 } 53 }
53 const base::Value* value = CrosSettings::Get()->GetPref(kDeviceOwner); 54 const base::Value* value = CrosSettings::Get()->GetPref(kDeviceOwner);
54 if (!value || value->GetType() != base::Value::TYPE_STRING) 55 if (!value || value->GetType() != base::Value::TYPE_STRING)
55 return false; 56 return false;
56 return static_cast<const base::StringValue*>(value)->GetString() == user_id; 57 return static_cast<const base::StringValue*>(value)->GetString() == user_id;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 scoped_refptr<base::TaskRunner> task_runner = 140 scoped_refptr<base::TaskRunner> task_runner =
140 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( 141 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
141 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 142 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
142 base::PostTaskAndReplyWithResult( 143 base::PostTaskAndReplyWithResult(
143 task_runner.get(), 144 task_runner.get(),
144 FROM_HERE, 145 FROM_HERE,
145 base::Bind(&DoesPrivateKeyExistAsyncHelper, owner_key_util), 146 base::Bind(&DoesPrivateKeyExistAsyncHelper, owner_key_util),
146 callback); 147 callback);
147 } 148 }
148 149
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
149 } // namespace 157 } // namespace
150 158
151 OwnerSettingsServiceChromeOS::OwnerSettingsServiceChromeOS( 159 OwnerSettingsServiceChromeOS::OwnerSettingsServiceChromeOS(
152 DeviceSettingsService* device_settings_service,
153 Profile* profile, 160 Profile* profile,
154 const scoped_refptr<OwnerKeyUtil>& owner_key_util) 161 const scoped_refptr<OwnerKeyUtil>& owner_key_util)
155 : ownership::OwnerSettingsService(owner_key_util), 162 : ownership::OwnerSettingsService(owner_key_util),
156 device_settings_service_(device_settings_service),
157 profile_(profile), 163 profile_(profile),
158 waiting_for_profile_creation_(true), 164 waiting_for_profile_creation_(true),
159 waiting_for_tpm_token_(true), 165 waiting_for_tpm_token_(true),
160 has_pending_changes_(false), 166 weak_factory_(this) {
161 weak_factory_(this),
162 store_settings_factory_(this) {
163 if (TPMTokenLoader::IsInitialized()) { 167 if (TPMTokenLoader::IsInitialized()) {
164 TPMTokenLoader::TPMTokenStatus tpm_token_status = 168 TPMTokenLoader::TPMTokenStatus tpm_token_status =
165 TPMTokenLoader::Get()->IsTPMTokenEnabled( 169 TPMTokenLoader::Get()->IsTPMTokenEnabled(
166 base::Bind(&OwnerSettingsServiceChromeOS::OnTPMTokenReady, 170 base::Bind(&OwnerSettingsServiceChromeOS::OnTPMTokenReady,
167 weak_factory_.GetWeakPtr())); 171 weak_factory_.GetWeakPtr()));
168 waiting_for_tpm_token_ = 172 waiting_for_tpm_token_ =
169 tpm_token_status == TPMTokenLoader::TPM_TOKEN_STATUS_UNDETERMINED; 173 tpm_token_status == TPMTokenLoader::TPM_TOKEN_STATUS_UNDETERMINED;
170 } 174 }
171 175
172 if (DBusThreadManager::IsInitialized() && 176 if (DBusThreadManager::IsInitialized() &&
173 DBusThreadManager::Get()->GetSessionManagerClient()) { 177 DBusThreadManager::Get()->GetSessionManagerClient()) {
174 DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this); 178 DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this);
175 } 179 }
176 180
177 if (device_settings_service_)
178 device_settings_service_->AddObserver(this);
179
180 registrar_.Add(this, 181 registrar_.Add(this,
181 chrome::NOTIFICATION_PROFILE_CREATED, 182 chrome::NOTIFICATION_PROFILE_CREATED,
182 content::Source<Profile>(profile_)); 183 content::Source<Profile>(profile_));
183
184 UpdateFromService();
185 } 184 }
186 185
187 OwnerSettingsServiceChromeOS::~OwnerSettingsServiceChromeOS() { 186 OwnerSettingsServiceChromeOS::~OwnerSettingsServiceChromeOS() {
188 DCHECK(thread_checker_.CalledOnValidThread()); 187 DCHECK(thread_checker_.CalledOnValidThread());
189
190 if (device_settings_service_)
191 device_settings_service_->RemoveObserver(this);
192
193 if (DBusThreadManager::IsInitialized() && 188 if (DBusThreadManager::IsInitialized() &&
194 DBusThreadManager::Get()->GetSessionManagerClient()) { 189 DBusThreadManager::Get()->GetSessionManagerClient()) {
195 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); 190 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this);
196 } 191 }
197 } 192 }
198 193
199 void OwnerSettingsServiceChromeOS::OnTPMTokenReady( 194 void OwnerSettingsServiceChromeOS::OnTPMTokenReady(
200 bool /* tpm_token_enabled */) { 195 bool /* tpm_token_enabled */) {
201 DCHECK(thread_checker_.CalledOnValidThread()); 196 DCHECK(thread_checker_.CalledOnValidThread());
202 waiting_for_tpm_token_ = false; 197 waiting_for_tpm_token_ = false;
203 198
204 // TPMTokenLoader initializes the TPM and NSS database which is necessary to 199 // TPMTokenLoader initializes the TPM and NSS database which is necessary to
205 // determine ownership. Force a reload once we know these are initialized. 200 // determine ownership. Force a reload once we know these are initialized.
206 ReloadKeypair(); 201 ReloadKeypair();
207 } 202 }
208 203
209 bool OwnerSettingsServiceChromeOS::HandlesSetting(const std::string& setting) { 204 void OwnerSettingsServiceChromeOS::SignAndStorePolicyAsync(
210 return DeviceSettingsProvider::IsDeviceSetting(setting); 205 scoped_ptr<em::PolicyData> policy,
211 } 206 const base::Closure& callback) {
212 207 DCHECK(thread_checker_.CalledOnValidThread());
213 bool OwnerSettingsServiceChromeOS::Set(const std::string& setting, 208 SignAndStoreSettingsOperation* operation = new SignAndStoreSettingsOperation(
214 const base::Value& value) { 209 base::Bind(&OwnerSettingsServiceChromeOS::HandleCompletedOperation,
215 if (!IsOwner() && !IsOwnerInTests(user_id_)) 210 weak_factory_.GetWeakPtr(),
216 return false; 211 callback),
217 212 policy.Pass());
218 UpdateDeviceSettings(setting, value, device_settings_); 213 operation->set_owner_settings_service(weak_factory_.GetWeakPtr());
219 em::PolicyData policy_data; 214 pending_operations_.push_back(operation);
220 policy_data.set_username(user_id_); 215 if (pending_operations_.front() == operation)
221 CHECK(device_settings_.SerializeToString(policy_data.mutable_policy_value())); 216 StartNextOperation();
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;
246 } 217 }
247 218
248 void OwnerSettingsServiceChromeOS::Observe( 219 void OwnerSettingsServiceChromeOS::Observe(
249 int type, 220 int type,
250 const content::NotificationSource& source, 221 const content::NotificationSource& source,
251 const content::NotificationDetails& details) { 222 const content::NotificationDetails& details) {
252 DCHECK(thread_checker_.CalledOnValidThread()); 223 DCHECK(thread_checker_.CalledOnValidThread());
253 if (type != chrome::NOTIFICATION_PROFILE_CREATED) { 224 if (type != chrome::NOTIFICATION_PROFILE_CREATED) {
254 NOTREACHED(); 225 NOTREACHED();
255 return; 226 return;
256 } 227 }
257 228
258 Profile* profile = content::Source<Profile>(source).ptr(); 229 Profile* profile = content::Source<Profile>(source).ptr();
259 if (profile != profile_) { 230 if (profile != profile_) {
260 NOTREACHED(); 231 NOTREACHED();
261 return; 232 return;
262 } 233 }
263 234
264 waiting_for_profile_creation_ = false; 235 waiting_for_profile_creation_ = false;
265 ReloadKeypair(); 236 ReloadKeypair();
266 } 237 }
267 238
268 void OwnerSettingsServiceChromeOS::OwnerKeySet(bool success) { 239 void OwnerSettingsServiceChromeOS::OwnerKeySet(bool success) {
269 DCHECK(thread_checker_.CalledOnValidThread()); 240 DCHECK(thread_checker_.CalledOnValidThread());
270 if (success) 241 if (success)
271 ReloadKeypair(); 242 ReloadKeypair();
272 } 243 }
273 244
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
284 // static 245 // static
285 void OwnerSettingsServiceChromeOS::IsOwnerForSafeModeAsync( 246 void OwnerSettingsServiceChromeOS::IsOwnerForSafeModeAsync(
286 const std::string& user_hash, 247 const std::string& user_hash,
287 const scoped_refptr<OwnerKeyUtil>& owner_key_util, 248 const scoped_refptr<OwnerKeyUtil>& owner_key_util,
288 const IsOwnerCallback& callback) { 249 const IsOwnerCallback& callback) {
289 CHECK(chromeos::LoginState::Get()->IsInSafeMode()); 250 CHECK(chromeos::LoginState::Get()->IsInSafeMode());
290 251
291 // Make sure NSS is initialized and NSS DB is loaded for the user before 252 // Make sure NSS is initialized and NSS DB is loaded for the user before
292 // searching for the owner key. 253 // searching for the owner key.
293 BrowserThread::PostTaskAndReply( 254 BrowserThread::PostTaskAndReply(
294 BrowserThread::IO, 255 BrowserThread::IO,
295 FROM_HERE, 256 FROM_HERE,
296 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser), 257 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser),
297 user_hash, 258 user_hash,
298 ProfileHelper::GetProfilePathByUserIdHash(user_hash)), 259 ProfileHelper::GetProfilePathByUserIdHash(user_hash)),
299 base::Bind(&DoesPrivateKeyExistAsync, owner_key_util, callback)); 260 base::Bind(&DoesPrivateKeyExistAsync, owner_key_util, callback));
300 } 261 }
301 262
302 // static 263 // static
303 scoped_ptr<em::PolicyData> OwnerSettingsServiceChromeOS::AssemblePolicy( 264 void OwnerSettingsServiceChromeOS::SetDeviceSettingsServiceForTesting(
304 const std::string& user_id, 265 DeviceSettingsService* device_settings_service) {
305 const em::PolicyData* policy_data, 266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
306 const em::ChromeDeviceSettingsProto* settings) { 267 g_device_settings_service_for_testing = device_settings_service;
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();
329 }
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 } 268 }
549 269
550 void OwnerSettingsServiceChromeOS::OnPostKeypairLoadedActions() { 270 void OwnerSettingsServiceChromeOS::OnPostKeypairLoadedActions() {
551 DCHECK(thread_checker_.CalledOnValidThread()); 271 DCHECK(thread_checker_.CalledOnValidThread());
552 272
553 user_id_ = profile_->GetProfileName(); 273 user_id_ = profile_->GetProfileName();
554 const bool is_owner = IsOwner() || IsOwnerInTests(user_id_); 274 const bool is_owner = IsOwner() || IsOwnerInTests(user_id_);
555 if (is_owner && device_settings_service_) 275 if (is_owner && GetDeviceSettingsService())
556 device_settings_service_->InitOwner(user_id_, weak_factory_.GetWeakPtr()); 276 GetDeviceSettingsService()->InitOwner(user_id_, weak_factory_.GetWeakPtr());
557 } 277 }
558 278
559 void OwnerSettingsServiceChromeOS::ReloadKeypairImpl(const base::Callback< 279 void OwnerSettingsServiceChromeOS::ReloadKeypairImpl(const base::Callback<
560 void(const scoped_refptr<PublicKey>& public_key, 280 void(const scoped_refptr<PublicKey>& public_key,
561 const scoped_refptr<PrivateKey>& private_key)>& callback) { 281 const scoped_refptr<PrivateKey>& private_key)>& callback) {
562 DCHECK(thread_checker_.CalledOnValidThread()); 282 DCHECK(thread_checker_.CalledOnValidThread());
563 283
564 if (waiting_for_profile_creation_ || waiting_for_tpm_token_) 284 if (waiting_for_profile_creation_ || waiting_for_tpm_token_)
565 return; 285 return;
566 scoped_refptr<base::TaskRunner> task_runner = 286 scoped_refptr<base::TaskRunner> task_runner =
567 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( 287 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
568 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 288 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
569 task_runner->PostTask( 289 task_runner->PostTask(
570 FROM_HERE, 290 FROM_HERE,
571 base::Bind(&LoadPrivateKey, 291 base::Bind(&LoadPrivateKey,
572 owner_key_util_, 292 owner_key_util_,
573 ProfileHelper::GetUserIdHashFromProfile(profile_), 293 ProfileHelper::GetUserIdHashFromProfile(profile_),
574 callback)); 294 callback));
575 } 295 }
576 296
577 void OwnerSettingsServiceChromeOS::StoreDeviceSettings() { 297 void OwnerSettingsServiceChromeOS::StartNextOperation() {
578 if (!has_pending_changes_ || store_settings_factory_.HasWeakPtrs()) 298 DeviceSettingsService* service = GetDeviceSettingsService();
579 return; 299 if (!pending_operations_.empty() && service &&
580 if (!UpdateFromService()) 300 service->session_manager_client()) {
581 return; 301 pending_operations_.front()->Start(
582 scoped_ptr<em::PolicyData> policy = AssemblePolicy( 302 service->session_manager_client(), owner_key_util_, public_key_);
583 user_id_, device_settings_service_->policy_data(), &device_settings_); 303 }
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 */);
592 } 304 }
593 305
594 void OwnerSettingsServiceChromeOS::OnPolicyAssembledAndSigned( 306 void OwnerSettingsServiceChromeOS::HandleCompletedOperation(
595 scoped_ptr<em::PolicyFetchResponse> policy_response) { 307 const base::Closure& callback,
596 if (!policy_response.get()) { 308 SessionManagerOperation* operation,
597 OnSignedPolicyStored(false /* success */); 309 DeviceSettingsService::Status status) {
598 return; 310 DCHECK_EQ(operation, pending_operations_.front());
311
312 DeviceSettingsService* service = GetDeviceSettingsService();
313 if (status == DeviceSettingsService::STORE_SUCCESS) {
314 service->set_policy_data(operation->policy_data().Pass());
315 service->set_device_settings(operation->device_settings().Pass());
599 } 316 }
600 device_settings_service_->Store(
601 policy_response.Pass(),
602 base::Bind(&OwnerSettingsServiceChromeOS::OnSignedPolicyStored,
603 store_settings_factory_.GetWeakPtr(),
604 true /* success */));
605 }
606 317
607 void OwnerSettingsServiceChromeOS::OnSignedPolicyStored(bool success) { 318 if ((operation->public_key().get() && !public_key_.get()) ||
608 store_settings_factory_.InvalidateWeakPtrs(); 319 (operation->public_key().get() && public_key_.get() &&
609 FOR_EACH_OBSERVER(OwnerSettingsService::Observer, 320 operation->public_key()->data() != public_key_->data())) {
610 observers_, 321 // Public part changed so we need to reload private part too.
611 OnSignedPolicyStored(success)); 322 ReloadKeypair();
612 StoreDeviceSettings(); 323 content::NotificationService::current()->Notify(
613 if (!success) 324 chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED,
614 has_pending_changes_ = true; 325 content::Source<OwnerSettingsServiceChromeOS>(this),
615 } 326 content::NotificationService::NoDetails());
327 }
328 service->OnSignAndStoreOperationCompleted(status);
329 if (!callback.is_null())
330 callback.Run();
616 331
617 bool OwnerSettingsServiceChromeOS::UpdateFromService() { 332 pending_operations_.pop_front();
618 if (!device_settings_service_ || 333 delete operation;
619 device_settings_service_->status() != 334 StartNextOperation();
620 DeviceSettingsService::STORE_SUCCESS ||
621 !device_settings_service_->device_settings()) {
622 return false;
623 }
624 enterprise_management::ChromeDeviceSettingsProto settings =
625 *device_settings_service_->device_settings();
626 settings.MergeFrom(device_settings_);
627 device_settings_.Swap(&settings);
628 return true;
629 } 335 }
630 336
631 } // namespace chromeos 337 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698