| 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 <keyhi.h> | 7 #include <keyhi.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 |
| 9 #include <algorithm> | 10 #include <algorithm> |
| 10 #include <string> | 11 #include <string> |
| 11 #include <utility> | 12 #include <utility> |
| 12 | 13 |
| 13 #include "base/bind.h" | 14 #include "base/bind.h" |
| 14 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
| 15 #include "base/callback.h" | 16 #include "base/callback.h" |
| 16 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/memory/ptr_util.h" |
| 17 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
| 19 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact
ory.h" | 21 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact
ory.h" |
| 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 22 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 21 #include "chrome/browser/chromeos/settings/cros_settings.h" | 23 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 22 #include "chrome/browser/chromeos/settings/device_settings_provider.h" | 24 #include "chrome/browser/chromeos/settings/device_settings_provider.h" |
| 23 #include "chrome/browser/chromeos/settings/session_manager_operation.h" | 25 #include "chrome/browser/chromeos/settings/session_manager_operation.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chromeos/chromeos_switches.h" | 27 #include "chromeos/chromeos_switches.h" |
| 26 #include "chromeos/dbus/dbus_thread_manager.h" | 28 #include "chromeos/dbus/dbus_thread_manager.h" |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } | 272 } |
| 271 return DeviceSettingsProvider::IsDeviceSetting(setting); | 273 return DeviceSettingsProvider::IsDeviceSetting(setting); |
| 272 } | 274 } |
| 273 | 275 |
| 274 bool OwnerSettingsServiceChromeOS::Set(const std::string& setting, | 276 bool OwnerSettingsServiceChromeOS::Set(const std::string& setting, |
| 275 const base::Value& value) { | 277 const base::Value& value) { |
| 276 DCHECK(thread_checker_.CalledOnValidThread()); | 278 DCHECK(thread_checker_.CalledOnValidThread()); |
| 277 if (!IsOwner() && !IsOwnerInTests(user_id_)) | 279 if (!IsOwner() && !IsOwnerInTests(user_id_)) |
| 278 return false; | 280 return false; |
| 279 | 281 |
| 280 pending_changes_.add(setting, make_scoped_ptr(value.DeepCopy())); | 282 pending_changes_.add(setting, base::WrapUnique(value.DeepCopy())); |
| 281 | 283 |
| 282 em::ChromeDeviceSettingsProto settings; | 284 em::ChromeDeviceSettingsProto settings; |
| 283 if (tentative_settings_.get()) { | 285 if (tentative_settings_.get()) { |
| 284 settings = *tentative_settings_; | 286 settings = *tentative_settings_; |
| 285 } else if (device_settings_service_->status() == | 287 } else if (device_settings_service_->status() == |
| 286 DeviceSettingsService::STORE_SUCCESS && | 288 DeviceSettingsService::STORE_SUCCESS && |
| 287 device_settings_service_->device_settings()) { | 289 device_settings_service_->device_settings()) { |
| 288 settings = *device_settings_service_->device_settings(); | 290 settings = *device_settings_service_->device_settings(); |
| 289 } | 291 } |
| 290 UpdateDeviceSettings(setting, value, settings); | 292 UpdateDeviceSettings(setting, value, settings); |
| 291 em::PolicyData policy_data; | 293 em::PolicyData policy_data; |
| 292 policy_data.set_username(user_id_); | 294 policy_data.set_username(user_id_); |
| 293 CHECK(settings.SerializeToString(policy_data.mutable_policy_value())); | 295 CHECK(settings.SerializeToString(policy_data.mutable_policy_value())); |
| 294 FOR_EACH_OBSERVER(OwnerSettingsService::Observer, observers_, | 296 FOR_EACH_OBSERVER(OwnerSettingsService::Observer, observers_, |
| 295 OnTentativeChangesInPolicy(policy_data)); | 297 OnTentativeChangesInPolicy(policy_data)); |
| 296 StorePendingChanges(); | 298 StorePendingChanges(); |
| 297 return true; | 299 return true; |
| 298 } | 300 } |
| 299 | 301 |
| 300 bool OwnerSettingsServiceChromeOS::AppendToList(const std::string& setting, | 302 bool OwnerSettingsServiceChromeOS::AppendToList(const std::string& setting, |
| 301 const base::Value& value) { | 303 const base::Value& value) { |
| 302 DCHECK(thread_checker_.CalledOnValidThread()); | 304 DCHECK(thread_checker_.CalledOnValidThread()); |
| 303 const base::Value* old_value = CrosSettings::Get()->GetPref(setting); | 305 const base::Value* old_value = CrosSettings::Get()->GetPref(setting); |
| 304 if (old_value && !old_value->IsType(base::Value::TYPE_LIST)) | 306 if (old_value && !old_value->IsType(base::Value::TYPE_LIST)) |
| 305 return false; | 307 return false; |
| 306 scoped_ptr<base::ListValue> new_value( | 308 std::unique_ptr<base::ListValue> new_value( |
| 307 old_value ? static_cast<const base::ListValue*>(old_value)->DeepCopy() | 309 old_value ? static_cast<const base::ListValue*>(old_value)->DeepCopy() |
| 308 : new base::ListValue()); | 310 : new base::ListValue()); |
| 309 new_value->Append(value.DeepCopy()); | 311 new_value->Append(value.DeepCopy()); |
| 310 return Set(setting, *new_value); | 312 return Set(setting, *new_value); |
| 311 } | 313 } |
| 312 | 314 |
| 313 bool OwnerSettingsServiceChromeOS::RemoveFromList(const std::string& setting, | 315 bool OwnerSettingsServiceChromeOS::RemoveFromList(const std::string& setting, |
| 314 const base::Value& value) { | 316 const base::Value& value) { |
| 315 DCHECK(thread_checker_.CalledOnValidThread()); | 317 DCHECK(thread_checker_.CalledOnValidThread()); |
| 316 const base::Value* old_value = CrosSettings::Get()->GetPref(setting); | 318 const base::Value* old_value = CrosSettings::Get()->GetPref(setting); |
| 317 if (old_value && !old_value->IsType(base::Value::TYPE_LIST)) | 319 if (old_value && !old_value->IsType(base::Value::TYPE_LIST)) |
| 318 return false; | 320 return false; |
| 319 scoped_ptr<base::ListValue> new_value( | 321 std::unique_ptr<base::ListValue> new_value( |
| 320 old_value ? static_cast<const base::ListValue*>(old_value)->DeepCopy() | 322 old_value ? static_cast<const base::ListValue*>(old_value)->DeepCopy() |
| 321 : new base::ListValue()); | 323 : new base::ListValue()); |
| 322 new_value->Remove(value, nullptr); | 324 new_value->Remove(value, nullptr); |
| 323 return Set(setting, *new_value); | 325 return Set(setting, *new_value); |
| 324 } | 326 } |
| 325 | 327 |
| 326 bool OwnerSettingsServiceChromeOS::CommitTentativeDeviceSettings( | 328 bool OwnerSettingsServiceChromeOS::CommitTentativeDeviceSettings( |
| 327 scoped_ptr<enterprise_management::PolicyData> policy) { | 329 std::unique_ptr<enterprise_management::PolicyData> policy) { |
| 328 if (!IsOwner() && !IsOwnerInTests(user_id_)) | 330 if (!IsOwner() && !IsOwnerInTests(user_id_)) |
| 329 return false; | 331 return false; |
| 330 if (policy->username() != user_id_) { | 332 if (policy->username() != user_id_) { |
| 331 LOG(ERROR) << "Username mismatch: " << policy->username() << " vs. " | 333 LOG(ERROR) << "Username mismatch: " << policy->username() << " vs. " |
| 332 << user_id_; | 334 << user_id_; |
| 333 return false; | 335 return false; |
| 334 } | 336 } |
| 335 tentative_settings_.reset(new em::ChromeDeviceSettingsProto); | 337 tentative_settings_.reset(new em::ChromeDeviceSettingsProto); |
| 336 CHECK(tentative_settings_->ParseFromString(policy->policy_value())); | 338 CHECK(tentative_settings_->ParseFromString(policy->policy_value())); |
| 337 StorePendingChanges(); | 339 StorePendingChanges(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 BrowserThread::PostTaskAndReply( | 424 BrowserThread::PostTaskAndReply( |
| 423 BrowserThread::IO, | 425 BrowserThread::IO, |
| 424 FROM_HERE, | 426 FROM_HERE, |
| 425 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser), | 427 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser), |
| 426 user_hash, | 428 user_hash, |
| 427 ProfileHelper::GetProfilePathByUserIdHash(user_hash)), | 429 ProfileHelper::GetProfilePathByUserIdHash(user_hash)), |
| 428 base::Bind(&DoesPrivateKeyExistAsync, owner_key_util, callback)); | 430 base::Bind(&DoesPrivateKeyExistAsync, owner_key_util, callback)); |
| 429 } | 431 } |
| 430 | 432 |
| 431 // static | 433 // static |
| 432 scoped_ptr<em::PolicyData> OwnerSettingsServiceChromeOS::AssemblePolicy( | 434 std::unique_ptr<em::PolicyData> OwnerSettingsServiceChromeOS::AssemblePolicy( |
| 433 const std::string& user_id, | 435 const std::string& user_id, |
| 434 const em::PolicyData* policy_data, | 436 const em::PolicyData* policy_data, |
| 435 bool apply_pending_management_settings, | 437 bool apply_pending_management_settings, |
| 436 const ManagementSettings& pending_management_settings, | 438 const ManagementSettings& pending_management_settings, |
| 437 em::ChromeDeviceSettingsProto* settings) { | 439 em::ChromeDeviceSettingsProto* settings) { |
| 438 scoped_ptr<em::PolicyData> policy(new em::PolicyData()); | 440 std::unique_ptr<em::PolicyData> policy(new em::PolicyData()); |
| 439 if (policy_data) { | 441 if (policy_data) { |
| 440 // Preserve management settings. | 442 // Preserve management settings. |
| 441 if (policy_data->has_management_mode()) | 443 if (policy_data->has_management_mode()) |
| 442 policy->set_management_mode(policy_data->management_mode()); | 444 policy->set_management_mode(policy_data->management_mode()); |
| 443 if (policy_data->has_request_token()) | 445 if (policy_data->has_request_token()) |
| 444 policy->set_request_token(policy_data->request_token()); | 446 policy->set_request_token(policy_data->request_token()); |
| 445 if (policy_data->has_device_id()) | 447 if (policy_data->has_device_id()) |
| 446 policy->set_device_id(policy_data->device_id()); | 448 policy->set_device_id(policy_data->device_id()); |
| 447 } else { | 449 } else { |
| 448 // If there's no previous policy data, this is the first time the device | 450 // If there's no previous policy data, this is the first time the device |
| (...skipping 16 matching lines...) Expand all Loading... |
| 465 } | 467 } |
| 466 policy->set_policy_type(policy::dm_protocol::kChromeDevicePolicyType); | 468 policy->set_policy_type(policy::dm_protocol::kChromeDevicePolicyType); |
| 467 policy->set_timestamp( | 469 policy->set_timestamp( |
| 468 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()); | 470 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()); |
| 469 policy->set_username(user_id); | 471 policy->set_username(user_id); |
| 470 if (policy_data->management_mode() == em::PolicyData::LOCAL_OWNER || | 472 if (policy_data->management_mode() == em::PolicyData::LOCAL_OWNER || |
| 471 policy_data->management_mode() == em::PolicyData::CONSUMER_MANAGED) { | 473 policy_data->management_mode() == em::PolicyData::CONSUMER_MANAGED) { |
| 472 FixupLocalOwnerPolicy(user_id, settings); | 474 FixupLocalOwnerPolicy(user_id, settings); |
| 473 } | 475 } |
| 474 if (!settings->SerializeToString(policy->mutable_policy_value())) | 476 if (!settings->SerializeToString(policy->mutable_policy_value())) |
| 475 return scoped_ptr<em::PolicyData>(); | 477 return std::unique_ptr<em::PolicyData>(); |
| 476 | 478 |
| 477 return policy; | 479 return policy; |
| 478 } | 480 } |
| 479 | 481 |
| 480 // static | 482 // static |
| 481 void OwnerSettingsServiceChromeOS::FixupLocalOwnerPolicy( | 483 void OwnerSettingsServiceChromeOS::FixupLocalOwnerPolicy( |
| 482 const std::string& user_id, | 484 const std::string& user_id, |
| 483 enterprise_management::ChromeDeviceSettingsProto* settings) { | 485 enterprise_management::ChromeDeviceSettingsProto* settings) { |
| 484 if (!settings->has_allow_new_users()) | 486 if (!settings->has_allow_new_users()) |
| 485 settings->mutable_allow_new_users()->set_allow_new_users(true); | 487 settings->mutable_allow_new_users()->set_allow_new_users(true); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 device_settings_service_->device_settings()) { | 766 device_settings_service_->device_settings()) { |
| 765 settings = *device_settings_service_->device_settings(); | 767 settings = *device_settings_service_->device_settings(); |
| 766 } else { | 768 } else { |
| 767 return; | 769 return; |
| 768 } | 770 } |
| 769 | 771 |
| 770 for (const auto& change : pending_changes_) | 772 for (const auto& change : pending_changes_) |
| 771 UpdateDeviceSettings(change.first, *change.second, settings); | 773 UpdateDeviceSettings(change.first, *change.second, settings); |
| 772 pending_changes_.clear(); | 774 pending_changes_.clear(); |
| 773 | 775 |
| 774 scoped_ptr<em::PolicyData> policy = | 776 std::unique_ptr<em::PolicyData> policy = |
| 775 AssemblePolicy(user_id_, device_settings_service_->policy_data(), | 777 AssemblePolicy(user_id_, device_settings_service_->policy_data(), |
| 776 has_pending_management_settings_, | 778 has_pending_management_settings_, |
| 777 pending_management_settings_, &settings); | 779 pending_management_settings_, &settings); |
| 778 has_pending_fixups_ = false; | 780 has_pending_fixups_ = false; |
| 779 has_pending_management_settings_ = false; | 781 has_pending_management_settings_ = false; |
| 780 | 782 |
| 781 bool rv = AssembleAndSignPolicyAsync( | 783 bool rv = AssembleAndSignPolicyAsync( |
| 782 content::BrowserThread::GetBlockingPool(), std::move(policy), | 784 content::BrowserThread::GetBlockingPool(), std::move(policy), |
| 783 base::Bind(&OwnerSettingsServiceChromeOS::OnPolicyAssembledAndSigned, | 785 base::Bind(&OwnerSettingsServiceChromeOS::OnPolicyAssembledAndSigned, |
| 784 store_settings_factory_.GetWeakPtr())); | 786 store_settings_factory_.GetWeakPtr())); |
| 785 if (!rv) | 787 if (!rv) |
| 786 ReportStatusAndContinueStoring(false /* success */); | 788 ReportStatusAndContinueStoring(false /* success */); |
| 787 } | 789 } |
| 788 | 790 |
| 789 void OwnerSettingsServiceChromeOS::OnPolicyAssembledAndSigned( | 791 void OwnerSettingsServiceChromeOS::OnPolicyAssembledAndSigned( |
| 790 scoped_ptr<em::PolicyFetchResponse> policy_response) { | 792 std::unique_ptr<em::PolicyFetchResponse> policy_response) { |
| 791 if (!policy_response.get() || !device_settings_service_) { | 793 if (!policy_response.get() || !device_settings_service_) { |
| 792 ReportStatusAndContinueStoring(false /* success */); | 794 ReportStatusAndContinueStoring(false /* success */); |
| 793 return; | 795 return; |
| 794 } | 796 } |
| 795 device_settings_service_->Store( | 797 device_settings_service_->Store( |
| 796 std::move(policy_response), | 798 std::move(policy_response), |
| 797 base::Bind(&OwnerSettingsServiceChromeOS::OnSignedPolicyStored, | 799 base::Bind(&OwnerSettingsServiceChromeOS::OnSignedPolicyStored, |
| 798 store_settings_factory_.GetWeakPtr(), true /* success */)); | 800 store_settings_factory_.GetWeakPtr(), true /* success */)); |
| 799 } | 801 } |
| 800 | 802 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 814 std::vector<OnManagementSettingsSetCallback> callbacks; | 816 std::vector<OnManagementSettingsSetCallback> callbacks; |
| 815 pending_management_settings_callbacks_.swap(callbacks); | 817 pending_management_settings_callbacks_.swap(callbacks); |
| 816 for (const auto& callback : callbacks) { | 818 for (const auto& callback : callbacks) { |
| 817 if (!callback.is_null()) | 819 if (!callback.is_null()) |
| 818 callback.Run(success); | 820 callback.Run(success); |
| 819 } | 821 } |
| 820 StorePendingChanges(); | 822 StorePendingChanges(); |
| 821 } | 823 } |
| 822 | 824 |
| 823 } // namespace chromeos | 825 } // namespace chromeos |
| OLD | NEW |