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

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

Issue 985093002: Fix up Owner settings on first load (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: based off mattias' patch that injects CrosSettings for testing Created 5 years, 9 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 <algorithm>
7 #include <string> 8 #include <string>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
11 #include "base/callback.h" 12 #include "base/callback.h"
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
14 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
15 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" 17 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h"
17 #include "chrome/browser/chromeos/profiles/profile_helper.h" 18 #include "chrome/browser/chromeos/profiles/profile_helper.h"
18 #include "chrome/browser/chromeos/profiles/profile_helper.h"
19 #include "chrome/browser/chromeos/settings/cros_settings.h" 19 #include "chrome/browser/chromeos/settings/cros_settings.h"
20 #include "chrome/browser/chromeos/settings/device_settings_provider.h" 20 #include "chrome/browser/chromeos/settings/device_settings_provider.h"
21 #include "chrome/browser/chromeos/settings/session_manager_operation.h" 21 #include "chrome/browser/chromeos/settings/session_manager_operation.h"
22 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chromeos/dbus/dbus_thread_manager.h" 23 #include "chromeos/dbus/dbus_thread_manager.h"
24 #include "chromeos/tpm/tpm_token_loader.h" 24 #include "chromeos/tpm/tpm_token_loader.h"
25 #include "components/ownership/owner_key_util.h" 25 #include "components/ownership/owner_key_util.h"
26 #include "components/user_manager/user.h" 26 #include "components/user_manager/user.h"
27 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/notification_details.h" 28 #include "content/public/browser/notification_details.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 88 }
89 89
90 void LoadPrivateKey( 90 void LoadPrivateKey(
91 const scoped_refptr<OwnerKeyUtil>& owner_key_util, 91 const scoped_refptr<OwnerKeyUtil>& owner_key_util,
92 const std::string username_hash, 92 const std::string username_hash,
93 const base::Callback<void(const scoped_refptr<PublicKey>& public_key, 93 const base::Callback<void(const scoped_refptr<PublicKey>& public_key,
94 const scoped_refptr<PrivateKey>& private_key)>& 94 const scoped_refptr<PrivateKey>& private_key)>&
95 callback) { 95 callback) {
96 std::vector<uint8> public_key_data; 96 std::vector<uint8> public_key_data;
97 scoped_refptr<PublicKey> public_key; 97 scoped_refptr<PublicKey> public_key;
98
98 if (!owner_key_util->ImportPublicKey(&public_key_data)) { 99 if (!owner_key_util->ImportPublicKey(&public_key_data)) {
99 scoped_refptr<PrivateKey> private_key; 100 scoped_refptr<PrivateKey> private_key;
100 BrowserThread::PostTask(BrowserThread::UI, 101 BrowserThread::PostTask(BrowserThread::UI,
101 FROM_HERE, 102 FROM_HERE,
102 base::Bind(callback, public_key, private_key)); 103 base::Bind(callback, public_key, private_key));
103 return; 104 return;
104 } 105 }
105 public_key = new PublicKey(); 106 public_key = new PublicKey();
106 public_key->data().swap(public_key_data); 107 public_key->data().swap(public_key_data);
108
107 bool rv = BrowserThread::PostTask(BrowserThread::IO, 109 bool rv = BrowserThread::PostTask(BrowserThread::IO,
108 FROM_HERE, 110 FROM_HERE,
109 base::Bind(&LoadPrivateKeyByPublicKey, 111 base::Bind(&LoadPrivateKeyByPublicKey,
110 owner_key_util, 112 owner_key_util,
111 public_key, 113 public_key,
112 username_hash, 114 username_hash,
113 callback)); 115 callback));
114 if (!rv) { 116 if (!rv) {
115 // IO thread doesn't exists in unit tests, but it's safe to use NSS from 117 // IO thread doesn't exists in unit tests, but it's safe to use NSS from
116 // BlockingPool in unit tests. 118 // BlockingPool in unit tests.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 return false; 169 return false;
168 170
169 case policy::MANAGEMENT_MODE_CONSUMER_MANAGED: 171 case policy::MANAGEMENT_MODE_CONSUMER_MANAGED:
170 // For consumer management unenrollment. 172 // For consumer management unenrollment.
171 return new_mode == policy::MANAGEMENT_MODE_LOCAL_OWNER; 173 return new_mode == policy::MANAGEMENT_MODE_LOCAL_OWNER;
172 } 174 }
173 175
174 NOTREACHED(); 176 NOTREACHED();
175 return false; 177 return false;
176 } 178 }
177
178 } // namespace 179 } // namespace
179 180
180 OwnerSettingsServiceChromeOS::ManagementSettings::ManagementSettings() { 181 OwnerSettingsServiceChromeOS::ManagementSettings::ManagementSettings() {
181 } 182 }
182 183
183 OwnerSettingsServiceChromeOS::ManagementSettings::~ManagementSettings() { 184 OwnerSettingsServiceChromeOS::ManagementSettings::~ManagementSettings() {
184 } 185 }
185 186
186 OwnerSettingsServiceChromeOS::OwnerSettingsServiceChromeOS( 187 OwnerSettingsServiceChromeOS::OwnerSettingsServiceChromeOS(
187 DeviceSettingsService* device_settings_service, 188 DeviceSettingsService* device_settings_service,
189 CrosSettings* cros_settings,
188 Profile* profile, 190 Profile* profile,
189 const scoped_refptr<OwnerKeyUtil>& owner_key_util) 191 const scoped_refptr<OwnerKeyUtil>& owner_key_util)
190 : ownership::OwnerSettingsService(owner_key_util), 192 : ownership::OwnerSettingsService(owner_key_util),
191 device_settings_service_(device_settings_service), 193 device_settings_service_(device_settings_service),
194 cros_settings_(cros_settings),
192 profile_(profile), 195 profile_(profile),
193 waiting_for_profile_creation_(true), 196 waiting_for_profile_creation_(true),
194 waiting_for_tpm_token_(true), 197 waiting_for_tpm_token_(true),
195 has_pending_management_settings_(false), 198 has_pending_management_settings_(false),
196 weak_factory_(this), 199 weak_factory_(this),
197 store_settings_factory_(this) { 200 store_settings_factory_(this) {
198 if (TPMTokenLoader::IsInitialized()) { 201 if (TPMTokenLoader::IsInitialized()) {
199 TPMTokenLoader::TPMTokenStatus tpm_token_status = 202 TPMTokenLoader::TPMTokenStatus tpm_token_status =
200 TPMTokenLoader::Get()->IsTPMTokenEnabled( 203 TPMTokenLoader::Get()->IsTPMTokenEnabled(
201 base::Bind(&OwnerSettingsServiceChromeOS::OnTPMTokenReady, 204 base::Bind(&OwnerSettingsServiceChromeOS::OnTPMTokenReady,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 pending_changes_.add(setting, make_scoped_ptr(value.DeepCopy())); 265 pending_changes_.add(setting, make_scoped_ptr(value.DeepCopy()));
263 266
264 em::ChromeDeviceSettingsProto settings; 267 em::ChromeDeviceSettingsProto settings;
265 if (tentative_settings_.get()) { 268 if (tentative_settings_.get()) {
266 settings = *tentative_settings_; 269 settings = *tentative_settings_;
267 } else if (device_settings_service_->status() == 270 } else if (device_settings_service_->status() ==
268 DeviceSettingsService::STORE_SUCCESS && 271 DeviceSettingsService::STORE_SUCCESS &&
269 device_settings_service_->device_settings()) { 272 device_settings_service_->device_settings()) {
270 settings = *device_settings_service_->device_settings(); 273 settings = *device_settings_service_->device_settings();
271 } 274 }
272 UpdateDeviceSettings(setting, value, settings); 275 UpdateDeviceSettings(setting, value, settings);
Mattias Nissler (ping if slow) 2015/03/16 08:51:42 nit: blank line here
276 // Perform fixups required to ensure sensical local-owner device policy:
277 // 1) The owner must be in the username field,
278 // 2) user whitelisting must be explicitly allowed or disallowed, and
279 // 3) the owner user must be on the whitelist, if it's enforced.
280 // We can enforce the first two here, but need to check the whitelist before
Mattias Nissler (ping if slow) 2015/03/16 08:51:42 I don't get why we can't update the whitelist here
Chris Masone 2015/03/16 16:45:57 I don't think we're actually assured that we've lo
Mattias Nissler (ping if slow) 2015/03/17 14:05:53 Ah, right, the |settings| may have come from elsew
Chris Masone 2015/03/17 15:00:48 Yeah, the pending_changes_ stuff is why I did this
Mattias Nissler (ping if slow) 2015/03/17 15:15:57 Well, I think it's fair to just force an initial w
281 // modifying it, so that will be taken care of in a separate class.
273 em::PolicyData policy_data; 282 em::PolicyData policy_data;
274 policy_data.set_username(user_id_); 283 policy_data.set_username(user_id_);
284 if (!settings.has_allow_new_users())
285 settings.mutable_allow_new_users()->set_allow_new_users(true);
286
275 CHECK(settings.SerializeToString(policy_data.mutable_policy_value())); 287 CHECK(settings.SerializeToString(policy_data.mutable_policy_value()));
276 FOR_EACH_OBSERVER(OwnerSettingsService::Observer, observers_, 288 FOR_EACH_OBSERVER(OwnerSettingsService::Observer, observers_,
277 OnTentativeChangesInPolicy(policy_data)); 289 OnTentativeChangesInPolicy(policy_data));
278 StorePendingChanges(); 290 StorePendingChanges();
279 return true; 291 return true;
280 } 292 }
281 293
282 bool OwnerSettingsServiceChromeOS::AppendToList(const std::string& setting, 294 bool OwnerSettingsServiceChromeOS::AppendToList(const std::string& setting,
283 const base::Value& value) { 295 const base::Value& value) {
284 DCHECK(thread_checker_.CalledOnValidThread()); 296 DCHECK(thread_checker_.CalledOnValidThread());
285 const base::Value* old_value = CrosSettings::Get()->GetPref(setting); 297 const base::Value* old_value = cros_settings_->GetPref(setting);
286 if (old_value && !old_value->IsType(base::Value::TYPE_LIST)) 298 if (old_value && !old_value->IsType(base::Value::TYPE_LIST))
287 return false; 299 return false;
288 scoped_ptr<base::ListValue> new_value( 300 scoped_ptr<base::ListValue> new_value(
289 old_value ? static_cast<const base::ListValue*>(old_value)->DeepCopy() 301 old_value ? static_cast<const base::ListValue*>(old_value)->DeepCopy()
290 : new base::ListValue()); 302 : new base::ListValue());
291 new_value->Append(value.DeepCopy()); 303 new_value->Append(value.DeepCopy());
292 return Set(setting, *new_value); 304 return Set(setting, *new_value);
293 } 305 }
294 306
295 bool OwnerSettingsServiceChromeOS::RemoveFromList(const std::string& setting, 307 bool OwnerSettingsServiceChromeOS::RemoveFromList(const std::string& setting,
296 const base::Value& value) { 308 const base::Value& value) {
297 DCHECK(thread_checker_.CalledOnValidThread()); 309 DCHECK(thread_checker_.CalledOnValidThread());
298 const base::Value* old_value = CrosSettings::Get()->GetPref(setting); 310 const base::Value* old_value = cros_settings_->GetPref(setting);
299 if (old_value && !old_value->IsType(base::Value::TYPE_LIST)) 311 if (old_value && !old_value->IsType(base::Value::TYPE_LIST))
300 return false; 312 return false;
301 scoped_ptr<base::ListValue> new_value( 313 scoped_ptr<base::ListValue> new_value(
302 old_value ? static_cast<const base::ListValue*>(old_value)->DeepCopy() 314 old_value ? static_cast<const base::ListValue*>(old_value)->DeepCopy()
303 : new base::ListValue()); 315 : new base::ListValue());
304 new_value->Remove(value, nullptr); 316 new_value->Remove(value, nullptr);
305 return Set(setting, *new_value); 317 return Set(setting, *new_value);
306 } 318 }
307 319
308 bool OwnerSettingsServiceChromeOS::CommitTentativeDeviceSettings( 320 bool OwnerSettingsServiceChromeOS::CommitTentativeDeviceSettings(
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 void OwnerSettingsServiceChromeOS::OnPostKeypairLoadedActions() { 679 void OwnerSettingsServiceChromeOS::OnPostKeypairLoadedActions() {
668 DCHECK(thread_checker_.CalledOnValidThread()); 680 DCHECK(thread_checker_.CalledOnValidThread());
669 681
670 const user_manager::User* user = 682 const user_manager::User* user =
671 ProfileHelper::Get()->GetUserByProfile(profile_); 683 ProfileHelper::Get()->GetUserByProfile(profile_);
672 user_id_ = user ? user->GetUserID() : std::string(); 684 user_id_ = user ? user->GetUserID() : std::string();
673 685
674 const bool is_owner = IsOwner() || IsOwnerInTests(user_id_); 686 const bool is_owner = IsOwner() || IsOwnerInTests(user_id_);
675 if (is_owner && device_settings_service_) 687 if (is_owner && device_settings_service_)
676 device_settings_service_->InitOwner(user_id_, weak_factory_.GetWeakPtr()); 688 device_settings_service_->InitOwner(user_id_, weak_factory_.GetWeakPtr());
689
690 if (is_owner)
691 FixupLocalOwnerPolicy();
692 }
693
694 void OwnerSettingsServiceChromeOS::FixupLocalOwnerPolicy() {
695 if (CrosSettingsProvider::TRUSTED != cros_settings_->PrepareTrustedValues(
696 base::Bind(&OwnerSettingsServiceChromeOS::FixupLocalOwnerPolicy,
697 weak_factory_.GetWeakPtr()))) {
698 return;
699 }
700 DCHECK(IsOwner());
701 DCHECK(!user_id_.empty());
702
703 bool wildcard = false;
704 if (!cros_settings_->FindEmailInList(kAccountsPrefUsers, user_id_,
705 &wildcard) ||
706 wildcard) {
707 cros_settings_->AppendToList(kAccountsPrefUsers,
Mattias Nissler (ping if slow) 2015/03/16 08:51:42 This is a bit of a step backwards, as the write pa
Chris Masone 2015/03/16 16:45:57 Ah. How's it supposed to work, then?
Mattias Nissler (ping if slow) 2015/03/17 14:05:53 You could just update the protobuf field, i.e. |se
708 new base::StringValue(user_id_));
709 }
677 } 710 }
678 711
679 void OwnerSettingsServiceChromeOS::ReloadKeypairImpl(const base::Callback< 712 void OwnerSettingsServiceChromeOS::ReloadKeypairImpl(const base::Callback<
680 void(const scoped_refptr<PublicKey>& public_key, 713 void(const scoped_refptr<PublicKey>& public_key,
681 const scoped_refptr<PrivateKey>& private_key)>& callback) { 714 const scoped_refptr<PrivateKey>& private_key)>& callback) {
682 DCHECK(thread_checker_.CalledOnValidThread()); 715 DCHECK(thread_checker_.CalledOnValidThread());
683 716
684 if (waiting_for_profile_creation_ || waiting_for_tpm_token_) 717 if (waiting_for_profile_creation_ || waiting_for_tpm_token_)
685 return; 718 return;
686 scoped_refptr<base::TaskRunner> task_runner = 719 scoped_refptr<base::TaskRunner> task_runner =
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 std::vector<OnManagementSettingsSetCallback> callbacks; 805 std::vector<OnManagementSettingsSetCallback> callbacks;
773 pending_management_settings_callbacks_.swap(callbacks); 806 pending_management_settings_callbacks_.swap(callbacks);
774 for (const auto& callback : callbacks) { 807 for (const auto& callback : callbacks) {
775 if (!callback.is_null()) 808 if (!callback.is_null())
776 callback.Run(success); 809 callback.Run(success);
777 } 810 }
778 StorePendingChanges(); 811 StorePendingChanges();
779 } 812 }
780 813
781 } // namespace chromeos 814 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698