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

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: Fixes. 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"
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 if (DBusThreadManager::IsInitialized() && 188 if (DBusThreadManager::IsInitialized() &&
189 DBusThreadManager::Get()->GetSessionManagerClient()) { 189 DBusThreadManager::Get()->GetSessionManagerClient()) {
190 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); 190 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this);
191 } 191 }
192
193 device_settings_service_->RemoveObserver(this);
Mattias Nissler (ping if slow) 2014/10/24 08:29:56 nit: should probably do this first in order to mat
ygorshenin1 2014/10/24 10:33:01 Done.
192 } 194 }
193 195
194 void OwnerSettingsServiceChromeOS::OnTPMTokenReady( 196 void OwnerSettingsServiceChromeOS::OnTPMTokenReady(
195 bool /* tpm_token_enabled */) { 197 bool /* tpm_token_enabled */) {
196 DCHECK(thread_checker_.CalledOnValidThread()); 198 DCHECK(thread_checker_.CalledOnValidThread());
197 waiting_for_tpm_token_ = false; 199 waiting_for_tpm_token_ = false;
198 200
199 // TPMTokenLoader initializes the TPM and NSS database which is necessary to 201 // TPMTokenLoader initializes the TPM and NSS database which is necessary to
200 // determine ownership. Force a reload once we know these are initialized. 202 // determine ownership. Force a reload once we know these are initialized.
201 ReloadKeypair(); 203 ReloadKeypair();
202 } 204 }
203 205
204 void OwnerSettingsServiceChromeOS::SignAndStorePolicyAsync( 206 bool OwnerSettingsServiceChromeOS::HandlesSetting(const std::string& setting) {
205 scoped_ptr<em::PolicyData> policy, 207 return DeviceSettingsProvider::IsDeviceSetting(setting);
206 const base::Closure& callback) { 208 }
207 DCHECK(thread_checker_.CalledOnValidThread()); 209
208 SignAndStoreSettingsOperation* operation = new SignAndStoreSettingsOperation( 210 bool OwnerSettingsServiceChromeOS::Set(const std::string& setting,
209 base::Bind(&OwnerSettingsServiceChromeOS::HandleCompletedOperation, 211 const base::Value& value) {
210 weak_factory_.GetWeakPtr(), 212 if (!IsOwner() && !IsOwnerInTests(user_id_))
211 callback), 213 return false;
212 policy.Pass()); 214
213 operation->set_owner_settings_service(weak_factory_.GetWeakPtr()); 215 UpdateDeviceSettings(setting, value, device_settings_);
214 pending_operations_.push_back(operation); 216 em::PolicyData policy_data;
215 if (pending_operations_.front() == operation) 217 policy_data.set_username(user_id_);
216 StartNextOperation(); 218 CHECK(device_settings_.SerializeToString(policy_data.mutable_policy_value()));
219 FOR_EACH_OBSERVER(OwnerSettingsService::Observer,
220 observers_,
221 OnTentativeChangesInPolicy(policy_data));
222 has_pending_changes_ = true;
223 StoreDeviceSettings();
224 return true;
217 } 225 }
218 226
219 void OwnerSettingsServiceChromeOS::Observe( 227 void OwnerSettingsServiceChromeOS::Observe(
220 int type, 228 int type,
221 const content::NotificationSource& source, 229 const content::NotificationSource& source,
222 const content::NotificationDetails& details) { 230 const content::NotificationDetails& details) {
223 DCHECK(thread_checker_.CalledOnValidThread()); 231 DCHECK(thread_checker_.CalledOnValidThread());
224 if (type != chrome::NOTIFICATION_PROFILE_CREATED) { 232 if (type != chrome::NOTIFICATION_PROFILE_CREATED) {
225 NOTREACHED(); 233 NOTREACHED();
226 return; 234 return;
227 } 235 }
228 236
229 Profile* profile = content::Source<Profile>(source).ptr(); 237 Profile* profile = content::Source<Profile>(source).ptr();
230 if (profile != profile_) { 238 if (profile != profile_) {
231 NOTREACHED(); 239 NOTREACHED();
232 return; 240 return;
233 } 241 }
234 242
235 waiting_for_profile_creation_ = false; 243 waiting_for_profile_creation_ = false;
236 ReloadKeypair(); 244 ReloadKeypair();
237 } 245 }
238 246
239 void OwnerSettingsServiceChromeOS::OwnerKeySet(bool success) { 247 void OwnerSettingsServiceChromeOS::OwnerKeySet(bool success) {
240 DCHECK(thread_checker_.CalledOnValidThread()); 248 DCHECK(thread_checker_.CalledOnValidThread());
241 if (success) 249 if (success)
242 ReloadKeypair(); 250 ReloadKeypair();
243 } 251 }
244 252
253 void OwnerSettingsServiceChromeOS::OwnershipStatusChanged() {
254 DCHECK(thread_checker_.CalledOnValidThread());
255 StoreDeviceSettings();
256 }
257
258 void OwnerSettingsServiceChromeOS::DeviceSettingsUpdated() {
259 DCHECK(thread_checker_.CalledOnValidThread());
260 StoreDeviceSettings();
261 }
262
245 // static 263 // static
246 void OwnerSettingsServiceChromeOS::IsOwnerForSafeModeAsync( 264 void OwnerSettingsServiceChromeOS::IsOwnerForSafeModeAsync(
247 const std::string& user_hash, 265 const std::string& user_hash,
248 const scoped_refptr<OwnerKeyUtil>& owner_key_util, 266 const scoped_refptr<OwnerKeyUtil>& owner_key_util,
249 const IsOwnerCallback& callback) { 267 const IsOwnerCallback& callback) {
250 CHECK(chromeos::LoginState::Get()->IsInSafeMode()); 268 CHECK(chromeos::LoginState::Get()->IsInSafeMode());
251 269
252 // Make sure NSS is initialized and NSS DB is loaded for the user before 270 // Make sure NSS is initialized and NSS DB is loaded for the user before
253 // searching for the owner key. 271 // searching for the owner key.
254 BrowserThread::PostTaskAndReply( 272 BrowserThread::PostTaskAndReply(
255 BrowserThread::IO, 273 BrowserThread::IO,
256 FROM_HERE, 274 FROM_HERE,
257 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser), 275 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser),
258 user_hash, 276 user_hash,
259 ProfileHelper::GetProfilePathByUserIdHash(user_hash)), 277 ProfileHelper::GetProfilePathByUserIdHash(user_hash)),
260 base::Bind(&DoesPrivateKeyExistAsync, owner_key_util, callback)); 278 base::Bind(&DoesPrivateKeyExistAsync, owner_key_util, callback));
261 } 279 }
262 280
263 // static 281 // static
264 void OwnerSettingsServiceChromeOS::SetDeviceSettingsServiceForTesting( 282 scoped_ptr<em::PolicyData> OwnerSettingsServiceChromeOS::AssemblePolicy(
265 DeviceSettingsService* device_settings_service) { 283 const std::string& user_id,
266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 284 const em::PolicyData* policy_data,
267 g_device_settings_service_for_testing = device_settings_service; 285 const em::ChromeDeviceSettingsProto* settings) {
286 scoped_ptr<em::PolicyData> policy(new em::PolicyData());
287 if (policy_data) {
288 // Preserve management settings.
289 if (policy_data->has_management_mode())
290 policy->set_management_mode(policy_data->management_mode());
291 if (policy_data->has_request_token())
292 policy->set_request_token(policy_data->request_token());
293 if (policy_data->has_device_id())
294 policy->set_device_id(policy_data->device_id());
295 } else {
296 // If there's no previous policy data, this is the first time the device
297 // setting is set. We set the management mode to NOT_MANAGED initially.
298 policy->set_management_mode(em::PolicyData::NOT_MANAGED);
299 }
300 policy->set_policy_type(policy::dm_protocol::kChromeDevicePolicyType);
301 policy->set_timestamp(
302 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds());
303 policy->set_username(user_id);
304 if (!settings->SerializeToString(policy->mutable_policy_value()))
305 return scoped_ptr<em::PolicyData>();
306
307 return policy.Pass();
268 } 308 }
269 309
310 // static
311 void OwnerSettingsServiceChromeOS::UpdateDeviceSettings(
312 const std::string& path,
313 const base::Value& value,
314 enterprise_management::ChromeDeviceSettingsProto& settings) {
315 if (path == kAccountsPrefAllowNewUser) {
316 em::AllowNewUsersProto* allow = settings.mutable_allow_new_users();
317 bool allow_value;
318 if (value.GetAsBoolean(&allow_value)) {
319 allow->set_allow_new_users(allow_value);
320 } else {
321 NOTREACHED();
322 }
323 } else if (path == kAccountsPrefAllowGuest) {
324 em::GuestModeEnabledProto* guest = settings.mutable_guest_mode_enabled();
325 bool guest_value;
326 if (value.GetAsBoolean(&guest_value))
327 guest->set_guest_mode_enabled(guest_value);
328 else
329 NOTREACHED();
330 } else if (path == kAccountsPrefSupervisedUsersEnabled) {
331 em::SupervisedUsersSettingsProto* supervised =
332 settings.mutable_supervised_users_settings();
333 bool supervised_value;
334 if (value.GetAsBoolean(&supervised_value))
335 supervised->set_supervised_users_enabled(supervised_value);
336 else
337 NOTREACHED();
338 } else if (path == kAccountsPrefShowUserNamesOnSignIn) {
339 em::ShowUserNamesOnSigninProto* show = settings.mutable_show_user_names();
340 bool show_value;
341 if (value.GetAsBoolean(&show_value))
342 show->set_show_user_names(show_value);
343 else
344 NOTREACHED();
345 } else if (path == kAccountsPrefDeviceLocalAccounts) {
346 em::DeviceLocalAccountsProto* device_local_accounts =
347 settings.mutable_device_local_accounts();
348 device_local_accounts->clear_account();
349 const base::ListValue* accounts_list = NULL;
350 if (value.GetAsList(&accounts_list)) {
351 for (base::ListValue::const_iterator entry(accounts_list->begin());
352 entry != accounts_list->end();
353 ++entry) {
354 const base::DictionaryValue* entry_dict = NULL;
355 if ((*entry)->GetAsDictionary(&entry_dict)) {
356 em::DeviceLocalAccountInfoProto* account =
357 device_local_accounts->add_account();
358 std::string account_id;
359 if (entry_dict->GetStringWithoutPathExpansion(
360 kAccountsPrefDeviceLocalAccountsKeyId, &account_id)) {
361 account->set_account_id(account_id);
362 }
363 int type;
364 if (entry_dict->GetIntegerWithoutPathExpansion(
365 kAccountsPrefDeviceLocalAccountsKeyType, &type)) {
366 account->set_type(
367 static_cast<em::DeviceLocalAccountInfoProto::AccountType>(
368 type));
369 }
370 std::string kiosk_app_id;
371 if (entry_dict->GetStringWithoutPathExpansion(
372 kAccountsPrefDeviceLocalAccountsKeyKioskAppId,
373 &kiosk_app_id)) {
374 account->mutable_kiosk_app()->set_app_id(kiosk_app_id);
375 }
376 } else {
377 NOTREACHED();
378 }
379 }
380 } else {
381 NOTREACHED();
382 }
383 } else if (path == kAccountsPrefDeviceLocalAccountAutoLoginId) {
384 em::DeviceLocalAccountsProto* device_local_accounts =
385 settings.mutable_device_local_accounts();
386 std::string id;
387 if (value.GetAsString(&id))
388 device_local_accounts->set_auto_login_id(id);
389 else
390 NOTREACHED();
391 } else if (path == kAccountsPrefDeviceLocalAccountAutoLoginDelay) {
392 em::DeviceLocalAccountsProto* device_local_accounts =
393 settings.mutable_device_local_accounts();
394 int delay;
395 if (value.GetAsInteger(&delay))
396 device_local_accounts->set_auto_login_delay(delay);
397 else
398 NOTREACHED();
399 } else if (path == kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled) {
400 em::DeviceLocalAccountsProto* device_local_accounts =
401 settings.mutable_device_local_accounts();
402 bool enabled;
403 if (value.GetAsBoolean(&enabled))
404 device_local_accounts->set_enable_auto_login_bailout(enabled);
405 else
406 NOTREACHED();
407 } else if (path ==
408 kAccountsPrefDeviceLocalAccountPromptForNetworkWhenOffline) {
409 em::DeviceLocalAccountsProto* device_local_accounts =
410 settings.mutable_device_local_accounts();
411 bool should_prompt;
412 if (value.GetAsBoolean(&should_prompt))
413 device_local_accounts->set_prompt_for_network_when_offline(should_prompt);
414 else
415 NOTREACHED();
416 } else if (path == kSignedDataRoamingEnabled) {
417 em::DataRoamingEnabledProto* roam = settings.mutable_data_roaming_enabled();
418 bool roaming_value = false;
419 if (value.GetAsBoolean(&roaming_value))
420 roam->set_data_roaming_enabled(roaming_value);
421 else
422 NOTREACHED();
423 } else if (path == kReleaseChannel) {
424 em::ReleaseChannelProto* release_channel =
425 settings.mutable_release_channel();
426 std::string channel_value;
427 if (value.GetAsString(&channel_value))
428 release_channel->set_release_channel(channel_value);
429 else
430 NOTREACHED();
431 } else if (path == kStatsReportingPref) {
432 em::MetricsEnabledProto* metrics = settings.mutable_metrics_enabled();
433 bool metrics_value = false;
434 if (value.GetAsBoolean(&metrics_value))
435 metrics->set_metrics_enabled(metrics_value);
436 else
437 NOTREACHED();
438 } else if (path == kAccountsPrefUsers) {
439 em::UserWhitelistProto* whitelist_proto = settings.mutable_user_whitelist();
440 whitelist_proto->clear_user_whitelist();
441 const base::ListValue* users;
442 if (value.GetAsList(&users)) {
443 for (base::ListValue::const_iterator i = users->begin();
444 i != users->end();
445 ++i) {
446 std::string email;
447 if ((*i)->GetAsString(&email))
448 whitelist_proto->add_user_whitelist(email);
449 }
450 }
451 } else if (path == kAccountsPrefEphemeralUsersEnabled) {
452 em::EphemeralUsersEnabledProto* ephemeral_users_enabled =
453 settings.mutable_ephemeral_users_enabled();
454 bool ephemeral_users_enabled_value = false;
455 if (value.GetAsBoolean(&ephemeral_users_enabled_value)) {
456 ephemeral_users_enabled->set_ephemeral_users_enabled(
457 ephemeral_users_enabled_value);
458 } else {
459 NOTREACHED();
460 }
461 } else if (path == kAllowRedeemChromeOsRegistrationOffers) {
462 em::AllowRedeemChromeOsRegistrationOffersProto* allow_redeem_offers =
463 settings.mutable_allow_redeem_offers();
464 bool allow_redeem_offers_value;
465 if (value.GetAsBoolean(&allow_redeem_offers_value)) {
466 allow_redeem_offers->set_allow_redeem_offers(allow_redeem_offers_value);
467 } else {
468 NOTREACHED();
469 }
470 } else if (path == kStartUpFlags) {
471 em::StartUpFlagsProto* flags_proto = settings.mutable_start_up_flags();
472 flags_proto->Clear();
473 const base::ListValue* flags;
474 if (value.GetAsList(&flags)) {
475 for (base::ListValue::const_iterator i = flags->begin();
476 i != flags->end();
477 ++i) {
478 std::string flag;
479 if ((*i)->GetAsString(&flag))
480 flags_proto->add_flags(flag);
481 }
482 }
483 } else if (path == kSystemUse24HourClock) {
484 em::SystemUse24HourClockProto* use_24hour_clock_proto =
485 settings.mutable_use_24hour_clock();
486 use_24hour_clock_proto->Clear();
487 bool use_24hour_clock_value;
488 if (value.GetAsBoolean(&use_24hour_clock_value)) {
489 use_24hour_clock_proto->set_use_24hour_clock(use_24hour_clock_value);
490 } else {
491 NOTREACHED();
492 }
493 } else if (path == kAttestationForContentProtectionEnabled) {
494 em::AttestationSettingsProto* attestation_settings =
495 settings.mutable_attestation_settings();
496 bool setting_enabled;
497 if (value.GetAsBoolean(&setting_enabled)) {
498 attestation_settings->set_content_protection_enabled(setting_enabled);
499 } else {
500 NOTREACHED();
501 }
502 } else {
503 // The remaining settings don't support Set(), since they are not
504 // intended to be customizable by the user:
505 // kAccountsPrefTransferSAMLCookies
506 // kAppPack
507 // kDeviceAttestationEnabled
508 // kDeviceOwner
509 // kIdleLogoutTimeout
510 // kIdleLogoutWarningDuration
511 // kReleaseChannelDelegated
512 // kReportDeviceActivityTimes
513 // kReportDeviceBootMode
514 // kReportDeviceLocation
515 // kReportDeviceVersionInfo
516 // kReportDeviceNetworkInterfaces
517 // kReportDeviceUsers
518 // kScreenSaverExtensionId
519 // kScreenSaverTimeout
520 // kServiceAccountIdentity
521 // kStartUpUrls
522 // kSystemTimezonePolicy
523 // kVariationsRestrictParameter
524
525 LOG(FATAL) << "Device setting " << path << " is read-only.";
526 }
527 }
528
270 void OwnerSettingsServiceChromeOS::OnPostKeypairLoadedActions() { 529 void OwnerSettingsServiceChromeOS::OnPostKeypairLoadedActions() {
271 DCHECK(thread_checker_.CalledOnValidThread()); 530 DCHECK(thread_checker_.CalledOnValidThread());
272 531
273 user_id_ = profile_->GetProfileName(); 532 user_id_ = profile_->GetProfileName();
274 const bool is_owner = IsOwner() || IsOwnerInTests(user_id_); 533 const bool is_owner = IsOwner() || IsOwnerInTests(user_id_);
275 if (is_owner && GetDeviceSettingsService()) 534 if (is_owner)
276 GetDeviceSettingsService()->InitOwner(user_id_, weak_factory_.GetWeakPtr()); 535 device_settings_service_->InitOwner(user_id_, weak_factory_.GetWeakPtr());
277 } 536 }
278 537
279 void OwnerSettingsServiceChromeOS::ReloadKeypairImpl(const base::Callback< 538 void OwnerSettingsServiceChromeOS::ReloadKeypairImpl(const base::Callback<
280 void(const scoped_refptr<PublicKey>& public_key, 539 void(const scoped_refptr<PublicKey>& public_key,
281 const scoped_refptr<PrivateKey>& private_key)>& callback) { 540 const scoped_refptr<PrivateKey>& private_key)>& callback) {
282 DCHECK(thread_checker_.CalledOnValidThread()); 541 DCHECK(thread_checker_.CalledOnValidThread());
283 542
284 if (waiting_for_profile_creation_ || waiting_for_tpm_token_) 543 if (waiting_for_profile_creation_ || waiting_for_tpm_token_)
285 return; 544 return;
286 scoped_refptr<base::TaskRunner> task_runner = 545 scoped_refptr<base::TaskRunner> task_runner =
287 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( 546 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
288 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 547 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
289 task_runner->PostTask( 548 task_runner->PostTask(
290 FROM_HERE, 549 FROM_HERE,
291 base::Bind(&LoadPrivateKey, 550 base::Bind(&LoadPrivateKey,
292 owner_key_util_, 551 owner_key_util_,
293 ProfileHelper::GetUserIdHashFromProfile(profile_), 552 ProfileHelper::GetUserIdHashFromProfile(profile_),
294 callback)); 553 callback));
295 } 554 }
296 555
297 void OwnerSettingsServiceChromeOS::StartNextOperation() { 556 void OwnerSettingsServiceChromeOS::StoreDeviceSettings() {
298 DeviceSettingsService* service = GetDeviceSettingsService(); 557 if (!has_pending_changes_ || store_settings_factory_.HasWeakPtrs())
299 if (!pending_operations_.empty() && service && 558 return;
300 service->session_manager_client()) { 559 if (!UpdateFromService())
301 pending_operations_.front()->Start( 560 return;
302 service->session_manager_client(), owner_key_util_, public_key_); 561 scoped_ptr<em::PolicyData> policy = AssemblePolicy(
303 } 562 user_id_, device_settings_service_->policy_data(), &device_settings_);
563 has_pending_changes_ = false;
564 bool rv = AssembleAndSignPolicyAsync(
565 content::BrowserThread::GetBlockingPool(),
566 policy.Pass(),
567 base::Bind(&OwnerSettingsServiceChromeOS::OnPolicyAssembledAndSigned,
568 store_settings_factory_.GetWeakPtr()));
569 if (!rv)
570 OnSignedPolicyStored(false /* success */);
304 } 571 }
305 572
306 void OwnerSettingsServiceChromeOS::HandleCompletedOperation( 573 void OwnerSettingsServiceChromeOS::OnPolicyAssembledAndSigned(
307 const base::Closure& callback, 574 scoped_ptr<em::PolicyFetchResponse> policy_response) {
308 SessionManagerOperation* operation, 575 if (!policy_response.get()) {
309 DeviceSettingsService::Status status) { 576 OnSignedPolicyStored(false /* success */);
310 DCHECK_EQ(operation, pending_operations_.front()); 577 return;
578 }
579 device_settings_service_->Store(
580 policy_response.Pass(),
581 base::Bind(&OwnerSettingsServiceChromeOS::OnSignedPolicyStored,
582 store_settings_factory_.GetWeakPtr(),
583 true /* success */));
584 }
311 585
312 DeviceSettingsService* service = GetDeviceSettingsService(); 586 void OwnerSettingsServiceChromeOS::OnSignedPolicyStored(bool success) {
313 if (status == DeviceSettingsService::STORE_SUCCESS) { 587 store_settings_factory_.InvalidateWeakPtrs();
314 service->set_policy_data(operation->policy_data().Pass()); 588 FOR_EACH_OBSERVER(OwnerSettingsService::Observer,
315 service->set_device_settings(operation->device_settings().Pass()); 589 observers_,
590 OnSignedPolicyStored(success));
591 if (!success)
592 has_pending_changes_ = true;
Mattias Nissler (ping if slow) 2014/10/24 08:29:56 Won't this cause an infinite store loop in the err
ygorshenin1 2014/10/24 10:33:01 Done, thanks! On 2014/10/24 08:29:56, Mattias Nis
593 StoreDeviceSettings();
594 }
595
596 bool OwnerSettingsServiceChromeOS::UpdateFromService() {
597 if (device_settings_service_->status() !=
598 DeviceSettingsService::STORE_SUCCESS ||
599 !device_settings_service_->device_settings()) {
600 return false;
316 } 601 }
317 602 enterprise_management::ChromeDeviceSettingsProto settings =
318 if ((operation->public_key().get() && !public_key_.get()) || 603 *device_settings_service_->device_settings();
319 (operation->public_key().get() && public_key_.get() && 604 settings.MergeFrom(device_settings_);
320 operation->public_key()->data() != public_key_->data())) { 605 device_settings_.Swap(&settings);
321 // Public part changed so we need to reload private part too. 606 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 } 607 }
336 608
337 } // namespace chromeos 609 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698