Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/policy/device_policy_identity_strategy.h" | 5 #include "chrome/browser/policy/device_policy_identity_strategy.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/chromeos/cros/cros_library.h" | 8 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 9 #include "chrome/browser/chromeos/login/ownership_service.h" | 9 #include "chrome/browser/chromeos/login/ownership_service.h" |
| 10 #include "chrome/browser/chromeos/login/user_manager.h" | 10 #include "chrome/browser/chromeos/login/user_manager.h" |
| 11 #include "chrome/browser/chromeos/system_access.h" | 11 #include "chrome/browser/chromeos/system_access.h" |
| 12 #include "chrome/browser/net/gaia/token_service.h" | 12 #include "chrome/browser/net/gaia/token_service.h" |
| 13 #include "chrome/browser/policy/proto/device_management_constants.h" | 13 #include "chrome/browser/policy/proto/device_management_constants.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/common/guid.h" | 16 #include "chrome/common/guid.h" |
| 17 #include "chrome/common/net/gaia/gaia_constants.h" | 17 #include "chrome/common/net/gaia/gaia_constants.h" |
| 18 #include "content/common/notification_service.h" | 18 #include "content/common/notification_service.h" |
| 19 #include "content/common/notification_type.h" | 19 #include "content/common/notification_type.h" |
| 20 | 20 |
| 21 // MachineInfo key names. | 21 // MachineInfo key names. |
| 22 static const char kMachineInfoSystemHwqual[] = "hardware_class"; | 22 static const char kMachineInfoSystemHwqual[] = "hardware_class"; |
| 23 static const char kMachineInfoSerialNumber[] = "serial_number"; | 23 |
| 24 // These are the machine serial number keys that we check in order until we | |
| 25 // find a non-empty serial number. The VPD spec says the serial number should be | |
| 26 // in the "serial_number" key for v2+ VPDs. However, we cannot check this first, | |
| 27 // since we'd get the "serial_number" value from the SMBIOS (yes, there's a name | |
| 28 // clash here!), which is different from the serial number we want and not | |
| 29 // actually per-device. So, we check the the legacy keys first. If we find a | |
| 30 // serial number for these, we use it, otherwise we must be on a newer device | |
| 31 // that provides the correct data in "serial_number". | |
| 32 static const char* kMachineInfoSerialNumberKeys[] = { | |
| 33 "sn", // ZGB | |
| 34 "Product_S/N", // Alex | |
| 35 "serial_number" // VPD v2+ devices | |
|
Louis
2011/07/29 02:52:05
I'd like to suggest to re-order the list. Try "ser
Mattias Nissler (ping if slow)
2011/07/29 09:19:52
That's unfortunately not possible due to the name
Louis
2011/08/01 08:18:11
What argument do you use for mosys? Does its seria
Mattias Nissler (ping if slow)
2011/08/01 08:31:17
/sbin/chromeos_startup does this:
mosys -k smbios
| |
| 36 }; | |
| 24 | 37 |
| 25 namespace policy { | 38 namespace policy { |
| 26 | 39 |
| 27 DevicePolicyIdentityStrategy::DevicePolicyIdentityStrategy() { | 40 DevicePolicyIdentityStrategy::DevicePolicyIdentityStrategy() { |
| 28 chromeos::SystemAccess* sys_lib = chromeos::SystemAccess::GetInstance(); | 41 chromeos::SystemAccess* sys_lib = chromeos::SystemAccess::GetInstance(); |
| 29 | 42 |
| 30 if (!sys_lib->GetMachineStatistic(kMachineInfoSystemHwqual, | 43 if (!sys_lib->GetMachineStatistic(kMachineInfoSystemHwqual, |
| 31 &machine_model_)) { | 44 &machine_model_)) { |
| 32 LOG(ERROR) << "Failed to get machine model."; | 45 LOG(ERROR) << "Failed to get machine model."; |
| 33 } | 46 } |
| 34 if (!sys_lib->GetMachineStatistic(kMachineInfoSerialNumber, | 47 for (unsigned int i = 0; i < arraysize(kMachineInfoSerialNumberKeys); i++) { |
| 35 &machine_id_)) { | 48 if (sys_lib->GetMachineStatistic(kMachineInfoSerialNumberKeys[i], |
| 49 &machine_id_) && | |
| 50 !machine_id_.empty()) { | |
| 51 break; | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 if (machine_id_.empty()) | |
| 36 LOG(ERROR) << "Failed to get machine serial number."; | 56 LOG(ERROR) << "Failed to get machine serial number."; |
| 37 } | |
| 38 } | 57 } |
| 39 | 58 |
| 40 DevicePolicyIdentityStrategy::~DevicePolicyIdentityStrategy() { | 59 DevicePolicyIdentityStrategy::~DevicePolicyIdentityStrategy() { |
| 41 } | 60 } |
| 42 | 61 |
| 43 std::string DevicePolicyIdentityStrategy::GetDeviceToken() { | 62 std::string DevicePolicyIdentityStrategy::GetDeviceToken() { |
| 44 return device_token_; | 63 return device_token_; |
| 45 } | 64 } |
| 46 | 65 |
| 47 std::string DevicePolicyIdentityStrategy::GetDeviceID() { | 66 std::string DevicePolicyIdentityStrategy::GetDeviceID() { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 | 115 |
| 97 return !username->empty() && !auth_token->empty(); | 116 return !username->empty() && !auth_token->empty(); |
| 98 } | 117 } |
| 99 | 118 |
| 100 void DevicePolicyIdentityStrategy::OnDeviceTokenAvailable( | 119 void DevicePolicyIdentityStrategy::OnDeviceTokenAvailable( |
| 101 const std::string& token) { | 120 const std::string& token) { |
| 102 device_token_ = token; | 121 device_token_ = token; |
| 103 } | 122 } |
| 104 | 123 |
| 105 } // namespace policy | 124 } // namespace policy |
| OLD | NEW |