OLD | NEW |
---|---|
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/policy/enterprise_install_attributes.h" | 5 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 consistency_check_running_(false), | 72 consistency_check_running_(false), |
73 device_lock_running_(false), | 73 device_lock_running_(false), |
74 registration_mode_(DEVICE_MODE_PENDING), | 74 registration_mode_(DEVICE_MODE_PENDING), |
75 cryptohome_client_(cryptohome_client), | 75 cryptohome_client_(cryptohome_client), |
76 weak_ptr_factory_(this) { | 76 weak_ptr_factory_(this) { |
77 } | 77 } |
78 | 78 |
79 EnterpriseInstallAttributes::~EnterpriseInstallAttributes() {} | 79 EnterpriseInstallAttributes::~EnterpriseInstallAttributes() {} |
80 | 80 |
81 void EnterpriseInstallAttributes::Init(const base::FilePath& cache_file) { | 81 void EnterpriseInstallAttributes::Init(const base::FilePath& cache_file) { |
82 DCHECK_EQ(false, device_locked_); | 82 DCHECK(!device_locked_); |
83 | 83 |
84 // The actual check happens asynchronously, thus it is ok to trigger it before | 84 // Mark the consistency check as running to ensure that LockDevice() is |
85 // Init() has completed. | 85 // blocked, but wait for the cryptohome service to be available before |
86 TriggerConsistencyCheck(kDbusRetryCount * kDbusRetryIntervalInSeconds); | 86 // actually calling TriggerConsistencyCheck(). |
87 consistency_check_running_ = true; | |
88 cryptohome_client_->WaitForServiceToBeAvailable(base::Bind( | |
89 &EnterpriseInstallAttributes::OnCryptohomeServiceInitiallyAvailable, | |
90 weak_ptr_factory_.GetWeakPtr())); | |
87 | 91 |
88 if (!base::PathExists(cache_file)) | 92 if (!base::PathExists(cache_file)) |
89 return; | 93 return; |
90 | 94 |
91 device_locked_ = true; | 95 device_locked_ = true; |
92 | 96 |
93 char buf[16384]; | 97 char buf[16384]; |
94 int len = base::ReadFile(cache_file, buf, sizeof(buf)); | 98 int len = base::ReadFile(cache_file, buf, sizeof(buf)); |
95 if (len == -1 || len >= static_cast<int>(sizeof(buf))) { | 99 if (len == -1 || len >= static_cast<int>(sizeof(buf))) { |
96 PLOG(ERROR) << "Failed to read " << cache_file.value(); | 100 PLOG(ERROR) << "Failed to read " << cache_file.value(); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 return std::string(); | 353 return std::string(); |
350 | 354 |
351 return registration_device_id_; | 355 return registration_device_id_; |
352 } | 356 } |
353 | 357 |
354 DeviceMode EnterpriseInstallAttributes::GetMode() { | 358 DeviceMode EnterpriseInstallAttributes::GetMode() { |
355 return registration_mode_; | 359 return registration_mode_; |
356 } | 360 } |
357 | 361 |
358 void EnterpriseInstallAttributes::TriggerConsistencyCheck(int dbus_retries) { | 362 void EnterpriseInstallAttributes::TriggerConsistencyCheck(int dbus_retries) { |
359 consistency_check_running_ = true; | |
360 cryptohome_client_->TpmIsOwned( | 363 cryptohome_client_->TpmIsOwned( |
361 base::Bind(&EnterpriseInstallAttributes::OnTpmOwnerCheckCompleted, | 364 base::Bind(&EnterpriseInstallAttributes::OnTpmOwnerCheckCompleted, |
362 weak_ptr_factory_.GetWeakPtr(), | 365 weak_ptr_factory_.GetWeakPtr(), |
363 dbus_retries)); | 366 dbus_retries)); |
364 } | 367 } |
365 | 368 |
366 void EnterpriseInstallAttributes::OnTpmOwnerCheckCompleted( | 369 void EnterpriseInstallAttributes::OnTpmOwnerCheckCompleted( |
367 int dbus_retries_remaining, | 370 int dbus_retries_remaining, |
368 chromeos::DBusMethodCallStatus call_status, | 371 chromeos::DBusMethodCallStatus call_status, |
369 bool result) { | 372 bool result) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 "enterprise.domain"; | 414 "enterprise.domain"; |
412 const char EnterpriseInstallAttributes::kAttrEnterpriseMode[] = | 415 const char EnterpriseInstallAttributes::kAttrEnterpriseMode[] = |
413 "enterprise.mode"; | 416 "enterprise.mode"; |
414 const char EnterpriseInstallAttributes::kAttrEnterpriseOwned[] = | 417 const char EnterpriseInstallAttributes::kAttrEnterpriseOwned[] = |
415 "enterprise.owned"; | 418 "enterprise.owned"; |
416 const char EnterpriseInstallAttributes::kAttrEnterpriseUser[] = | 419 const char EnterpriseInstallAttributes::kAttrEnterpriseUser[] = |
417 "enterprise.user"; | 420 "enterprise.user"; |
418 const char EnterpriseInstallAttributes::kAttrConsumerKioskEnabled[] = | 421 const char EnterpriseInstallAttributes::kAttrConsumerKioskEnabled[] = |
419 "consumer.app_kiosk_enabled"; | 422 "consumer.app_kiosk_enabled"; |
420 | 423 |
424 void EnterpriseInstallAttributes::OnCryptohomeServiceInitiallyAvailable( | |
425 bool service_is_ready) { | |
426 if (!service_is_ready) | |
427 LOG(ERROR) << "Failed waiting for cryptohome D-Bus service availability"; | |
Thiemo Nagel
2016/09/16 03:22:06
Nit: I'd suggest ending sentence with a period.
Daniel Erat
2016/09/16 15:25:51
chrome appears to lean slightly more in the direct
| |
428 | |
429 // Start the consistency check even if we failed to wait for availability; | |
430 // hopefully the service will become available eventually. | |
431 TriggerConsistencyCheck(kDbusRetryCount); | |
432 } | |
433 | |
421 std::string EnterpriseInstallAttributes::GetDeviceModeString(DeviceMode mode) { | 434 std::string EnterpriseInstallAttributes::GetDeviceModeString(DeviceMode mode) { |
422 switch (mode) { | 435 switch (mode) { |
423 case DEVICE_MODE_CONSUMER: | 436 case DEVICE_MODE_CONSUMER: |
424 return EnterpriseInstallAttributes::kConsumerDeviceMode; | 437 return EnterpriseInstallAttributes::kConsumerDeviceMode; |
425 case DEVICE_MODE_ENTERPRISE: | 438 case DEVICE_MODE_ENTERPRISE: |
426 return EnterpriseInstallAttributes::kEnterpriseDeviceMode; | 439 return EnterpriseInstallAttributes::kEnterpriseDeviceMode; |
427 case DEVICE_MODE_LEGACY_RETAIL_MODE: | 440 case DEVICE_MODE_LEGACY_RETAIL_MODE: |
428 return EnterpriseInstallAttributes::kLegacyRetailDeviceMode; | 441 return EnterpriseInstallAttributes::kLegacyRetailDeviceMode; |
429 case DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH: | 442 case DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH: |
430 return EnterpriseInstallAttributes::kConsumerKioskDeviceMode; | 443 return EnterpriseInstallAttributes::kConsumerKioskDeviceMode; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 } | 504 } |
492 | 505 |
493 std::string EnterpriseInstallAttributes::GetRegistrationUser() const { | 506 std::string EnterpriseInstallAttributes::GetRegistrationUser() const { |
494 if (!device_locked_) | 507 if (!device_locked_) |
495 return std::string(); | 508 return std::string(); |
496 | 509 |
497 return registration_user_; | 510 return registration_user_; |
498 } | 511 } |
499 | 512 |
500 } // namespace policy | 513 } // namespace policy |
OLD | NEW |