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

Side by Side Diff: chrome/browser/chromeos/settings/device_settings_service.cc

Issue 23532034: Postpone loading about:flags ui until the certificates have been loaded (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/settings/device_settings_service.h" 5 #include "chrome/browser/chromeos/settings/device_settings_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // static 67 // static
68 DeviceSettingsService* DeviceSettingsService::Get() { 68 DeviceSettingsService* DeviceSettingsService::Get() {
69 CHECK(g_device_settings_service); 69 CHECK(g_device_settings_service);
70 return g_device_settings_service; 70 return g_device_settings_service;
71 } 71 }
72 72
73 DeviceSettingsService::DeviceSettingsService() 73 DeviceSettingsService::DeviceSettingsService()
74 : session_manager_client_(NULL), 74 : session_manager_client_(NULL),
75 weak_factory_(this), 75 weak_factory_(this),
76 store_status_(STORE_SUCCESS), 76 store_status_(STORE_SUCCESS),
77 certificates_loaded_(false),
78 owner_key_loaded_with_certificates_(false),
77 load_retries_left_(kMaxLoadRetries) { 79 load_retries_left_(kMaxLoadRetries) {
78 if (CertLoader::IsInitialized()) 80 if (CertLoader::IsInitialized()) {
81 certificates_loaded_ = CertLoader::Get()->certificates_loaded();
79 CertLoader::Get()->AddObserver(this); 82 CertLoader::Get()->AddObserver(this);
83 }
80 } 84 }
81 85
82 DeviceSettingsService::~DeviceSettingsService() { 86 DeviceSettingsService::~DeviceSettingsService() {
83 DCHECK(pending_operations_.empty()); 87 DCHECK(pending_operations_.empty());
84 if (CertLoader::IsInitialized()) 88 if (CertLoader::IsInitialized())
85 CertLoader::Get()->RemoveObserver(this); 89 CertLoader::Get()->RemoveObserver(this);
86 } 90 }
87 91
88 void DeviceSettingsService::SetSessionManager( 92 void DeviceSettingsService::SetSessionManager(
89 SessionManagerClient* session_manager_client, 93 SessionManagerClient* session_manager_client,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 153
150 return OWNERSHIP_UNKNOWN; 154 return OWNERSHIP_UNKNOWN;
151 } 155 }
152 156
153 void DeviceSettingsService::GetOwnershipStatusAsync( 157 void DeviceSettingsService::GetOwnershipStatusAsync(
154 const OwnershipStatusCallback& callback) { 158 const OwnershipStatusCallback& callback) {
155 if (owner_key_.get()) { 159 if (owner_key_.get()) {
156 // If there is a key, report status immediately. 160 // If there is a key, report status immediately.
157 base::MessageLoop::current()->PostTask( 161 base::MessageLoop::current()->PostTask(
158 FROM_HERE, 162 FROM_HERE,
159 base::Bind(callback, 163 base::Bind(
160 owner_key_->public_key() ? OWNERSHIP_TAKEN : OWNERSHIP_NONE, 164 callback,
161 owner_key_->private_key() != NULL)); 165 owner_key_->public_key() ? OWNERSHIP_TAKEN : OWNERSHIP_NONE));
162 } else { 166 } else {
163 // If the key hasn't been loaded yet, enqueue the callback to be fired when 167 // If the key hasn't been loaded yet, enqueue the callback to be fired when
164 // the next SessionManagerOperation completes. If no operation is pending, 168 // the next SessionManagerOperation completes. If no operation is pending,
165 // start a load operation to fetch the key and report the result. 169 // start a load operation to fetch the key and report the result.
166 pending_ownership_status_callbacks_.push_back(callback); 170 pending_ownership_status_callbacks_.push_back(callback);
167 if (pending_operations_.empty()) 171 if (pending_operations_.empty())
168 EnqueueLoad(false); 172 EnqueueLoad(false);
169 } 173 }
170 } 174 }
171 175
172 bool DeviceSettingsService::HasPrivateOwnerKey() { 176 bool DeviceSettingsService::HasPrivateOwnerKey() {
173 return owner_key_.get() && owner_key_->private_key(); 177 return owner_key_.get() && owner_key_->private_key();
174 } 178 }
175 179
180 void DeviceSettingsService::IsCurrentUserOwnerAsync(
181 const IsCurrentUserOwnerCallback& callback) {
182 if (owner_key_loaded_with_certificates_) {
183 // If the current owner key was loaded while the certificates were loaded,
184 // or the certificate loader is not initialized, in which case the private
185 // key cannot be set, report status immediately.
186 base::MessageLoop::current()->PostTask(
187 FROM_HERE,
188 base::Bind(callback, HasPrivateOwnerKey()));
189 } else {
190 // If the key hasn't been loaded with the known certificates, enqueue the
191 // callback to be fired when the next SessionManagerOperation completes in
192 // an environment where the certificates are loaded. There is no need to
193 // start a new operation, as the reload operation will be started when the
194 // certificates are loaded.
195 pending_is_current_user_owner_callbacks_.push_back(callback);
196 }
197 }
198
176 void DeviceSettingsService::SetUsername(const std::string& username) { 199 void DeviceSettingsService::SetUsername(const std::string& username) {
177 username_ = username; 200 username_ = username;
178 201
179 // The private key may have become available, so force a key reload. 202 // The private key may have become available, so force a key reload.
180 owner_key_ = NULL; 203 owner_key_ = NULL;
181 EnsureReload(true); 204 EnsureReload(true);
182 } 205 }
183 206
184 const std::string& DeviceSettingsService::GetUsername() const { 207 const std::string& DeviceSettingsService::GetUsername() const {
185 return username_; 208 return username_;
(...skipping 22 matching lines...) Expand all
208 LOG(ERROR) << "Policy update failed."; 231 LOG(ERROR) << "Policy update failed.";
209 return; 232 return;
210 } 233 }
211 234
212 EnsureReload(false); 235 EnsureReload(false);
213 } 236 }
214 237
215 void DeviceSettingsService::OnCertificatesLoaded( 238 void DeviceSettingsService::OnCertificatesLoaded(
216 const net::CertificateList& cert_list, 239 const net::CertificateList& cert_list,
217 bool initial_load) { 240 bool initial_load) {
241 certificates_loaded_ = true;
218 // CertLoader initializes the TPM and NSS database which is necessary to 242 // CertLoader initializes the TPM and NSS database which is necessary to
219 // determine ownership. Force a reload once we know these are initialized. 243 // determine ownership. Force a reload once we know these are initialized.
220 EnsureReload(true); 244 EnsureReload(true);
221 } 245 }
222 246
223 void DeviceSettingsService::Enqueue(SessionManagerOperation* operation) { 247 void DeviceSettingsService::Enqueue(SessionManagerOperation* operation) {
224 pending_operations_.push_back(operation); 248 pending_operations_.push_back(operation);
225 if (pending_operations_.front() == operation) 249 if (pending_operations_.front() == operation)
226 StartNextOperation(); 250 StartNextOperation();
227 } 251 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 content::Source<DeviceSettingsService>(this), 328 content::Source<DeviceSettingsService>(this),
305 content::NotificationService::NoDetails()); 329 content::NotificationService::NoDetails());
306 } 330 }
307 331
308 FOR_EACH_OBSERVER(Observer, observers_, DeviceSettingsUpdated()); 332 FOR_EACH_OBSERVER(Observer, observers_, DeviceSettingsUpdated());
309 333
310 std::vector<OwnershipStatusCallback> callbacks; 334 std::vector<OwnershipStatusCallback> callbacks;
311 callbacks.swap(pending_ownership_status_callbacks_); 335 callbacks.swap(pending_ownership_status_callbacks_);
312 for (std::vector<OwnershipStatusCallback>::iterator iter(callbacks.begin()); 336 for (std::vector<OwnershipStatusCallback>::iterator iter(callbacks.begin());
313 iter != callbacks.end(); ++iter) { 337 iter != callbacks.end(); ++iter) {
314 iter->Run(ownership_status, is_owner); 338 iter->Run(ownership_status);
339 }
340
341 if (certificates_loaded_) {
342 owner_key_loaded_with_certificates_ = true;
343 std::vector<IsCurrentUserOwnerCallback> is_owner_callbacks;
344 is_owner_callbacks.swap(pending_is_current_user_owner_callbacks_);
345 for (std::vector<IsCurrentUserOwnerCallback>::iterator iter(
346 is_owner_callbacks.begin());
347 iter != is_owner_callbacks.end(); ++iter) {
348 iter->Run(is_owner);
349 }
315 } 350 }
316 351
317 // The completion callback happens after the notification so clients can 352 // The completion callback happens after the notification so clients can
318 // filter self-triggered updates. 353 // filter self-triggered updates.
319 if (!callback.is_null()) 354 if (!callback.is_null())
320 callback.Run(); 355 callback.Run();
321 356
322 // Only remove the pending operation here, so new operations triggered by any 357 // Only remove the pending operation here, so new operations triggered by any
323 // of the callbacks above are queued up properly. 358 // of the callbacks above are queued up properly.
324 pending_operations_.pop_front(); 359 pending_operations_.pop_front();
325 delete operation; 360 delete operation;
326 361
327 StartNextOperation(); 362 StartNextOperation();
328 } 363 }
329 364
330 ScopedTestDeviceSettingsService::ScopedTestDeviceSettingsService() { 365 ScopedTestDeviceSettingsService::ScopedTestDeviceSettingsService() {
331 DeviceSettingsService::Initialize(); 366 DeviceSettingsService::Initialize();
332 } 367 }
333 368
334 ScopedTestDeviceSettingsService::~ScopedTestDeviceSettingsService() { 369 ScopedTestDeviceSettingsService::~ScopedTestDeviceSettingsService() {
335 DeviceSettingsService::Shutdown(); 370 DeviceSettingsService::Shutdown();
336 } 371 }
337 372
338 } // namespace chromeos 373 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698