| 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/browser_policy_connector.h" | 5 #include "chrome/browser/policy/browser_policy_connector.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 #if defined(OS_CHROMEOS) | 63 #if defined(OS_CHROMEOS) |
| 64 // MachineInfo key names. | 64 // MachineInfo key names. |
| 65 const char kMachineInfoSystemHwqual[] = "hardware_class"; | 65 const char kMachineInfoSystemHwqual[] = "hardware_class"; |
| 66 | 66 |
| 67 // These are the machine serial number keys that we check in order until we | 67 // These are the machine serial number keys that we check in order until we |
| 68 // find a non-empty serial number. The VPD spec says the serial number should be | 68 // find a non-empty serial number. The VPD spec says the serial number should be |
| 69 // in the "serial_number" key for v2+ VPDs. However, we cannot check this first, | 69 // in the "serial_number" key for v2+ VPDs. However, we cannot check this first, |
| 70 // since we'd get the "serial_number" value from the SMBIOS (yes, there's a name | 70 // since we'd get the "serial_number" value from the SMBIOS (yes, there's a name |
| 71 // clash here!), which is different from the serial number we want and not | 71 // clash here!), which is different from the serial number we want and not |
| 72 // actually per-device. So, we check the the legacy keys first. If we find a | 72 // actually per-device. So, we check the legacy keys first. If we find a |
| 73 // serial number for these, we use it, otherwise we must be on a newer device | 73 // serial number for these, we use it, otherwise we must be on a newer device |
| 74 // that provides the correct data in "serial_number". | 74 // that provides the correct data in "serial_number". |
| 75 const char* kMachineInfoSerialNumberKeys[] = { | 75 const char* kMachineInfoSerialNumberKeys[] = { |
| 76 "sn", // ZGB | 76 "sn", // ZGB |
| 77 "Product_S/N", // Alex | 77 "Product_S/N", // Alex |
| 78 "Product_SN", // Mario | 78 "Product_SN", // Mario |
| 79 "serial_number" // VPD v2+ devices | 79 "serial_number" // VPD v2+ devices |
| 80 }; | 80 }; |
| 81 #endif | 81 #endif |
| 82 | 82 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 } | 148 } |
| 149 | 149 |
| 150 void BrowserPolicyConnector::RegisterForDevicePolicy( | 150 void BrowserPolicyConnector::RegisterForDevicePolicy( |
| 151 const std::string& owner_email, | 151 const std::string& owner_email, |
| 152 const std::string& token, | 152 const std::string& token, |
| 153 TokenType token_type) { | 153 TokenType token_type) { |
| 154 #if defined(OS_CHROMEOS) | 154 #if defined(OS_CHROMEOS) |
| 155 if (device_data_store_.get()) { | 155 if (device_data_store_.get()) { |
| 156 if (device_data_store_->machine_id().empty() || | 156 if (device_data_store_->machine_id().empty() || |
| 157 device_data_store_->machine_model().empty()) { | 157 device_data_store_->machine_model().empty()) { |
| 158 std::string machine_id; | |
| 159 std::string machine_model; | |
| 160 chromeos::system::StatisticsProvider* provider = | 158 chromeos::system::StatisticsProvider* provider = |
| 161 chromeos::system::StatisticsProvider::GetInstance(); | 159 chromeos::system::StatisticsProvider::GetInstance(); |
| 160 |
| 161 std::string machine_model; |
| 162 if (!provider->GetMachineStatistic(kMachineInfoSystemHwqual, | 162 if (!provider->GetMachineStatistic(kMachineInfoSystemHwqual, |
| 163 &machine_model)) { | 163 &machine_model)) { |
| 164 LOG(ERROR) << "Failed to get machine model."; | 164 LOG(ERROR) << "Failed to get machine model."; |
| 165 } | 165 } |
| 166 for (size_t i = 0; i < arraysize(kMachineInfoSerialNumberKeys); i++) { | |
| 167 if (provider->GetMachineStatistic(kMachineInfoSerialNumberKeys[i], | |
| 168 &machine_id) && | |
| 169 !machine_id.empty()) { | |
| 170 break; | |
| 171 } | |
| 172 } | |
| 173 | 166 |
| 167 std::string machine_id = GetSerialNumber(); |
| 174 if (machine_id.empty()) | 168 if (machine_id.empty()) |
| 175 LOG(ERROR) << "Failed to get machine serial number."; | 169 LOG(ERROR) << "Failed to get machine serial number."; |
| 176 | 170 |
| 177 device_data_store_->set_machine_id(machine_id); | 171 device_data_store_->set_machine_id(machine_id); |
| 178 device_data_store_->set_machine_model(machine_model); | 172 device_data_store_->set_machine_model(machine_model); |
| 179 } | 173 } |
| 180 device_data_store_->set_user_name(owner_email); | 174 device_data_store_->set_user_name(owner_email); |
| 181 switch (token_type) { | 175 switch (token_type) { |
| 182 case TOKEN_TYPE_OAUTH: | 176 case TOKEN_TYPE_OAUTH: |
| 183 device_data_store_->SetOAuthToken(token); | 177 device_data_store_->SetOAuthToken(token); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 203 EnterpriseInstallAttributes::LockResult | 197 EnterpriseInstallAttributes::LockResult |
| 204 BrowserPolicyConnector::LockDevice(const std::string& user) { | 198 BrowserPolicyConnector::LockDevice(const std::string& user) { |
| 205 #if defined(OS_CHROMEOS) | 199 #if defined(OS_CHROMEOS) |
| 206 if (install_attributes_.get()) | 200 if (install_attributes_.get()) |
| 207 return install_attributes_->LockDevice(user); | 201 return install_attributes_->LockDevice(user); |
| 208 #endif | 202 #endif |
| 209 | 203 |
| 210 return EnterpriseInstallAttributes::LOCK_BACKEND_ERROR; | 204 return EnterpriseInstallAttributes::LOCK_BACKEND_ERROR; |
| 211 } | 205 } |
| 212 | 206 |
| 207 // static |
| 208 std::string BrowserPolicyConnector::GetSerialNumber() { |
| 209 std::string serial_number; |
| 210 #if defined(OS_CHROMEOS) |
| 211 chromeos::system::StatisticsProvider* provider = |
| 212 chromeos::system::StatisticsProvider::GetInstance(); |
| 213 for (size_t i = 0; i < arraysize(kMachineInfoSerialNumberKeys); i++) { |
| 214 if (provider->GetMachineStatistic(kMachineInfoSerialNumberKeys[i], |
| 215 &serial_number) && |
| 216 !serial_number.empty()) { |
| 217 break; |
| 218 } |
| 219 } |
| 220 #endif |
| 221 return serial_number; |
| 222 } |
| 223 |
| 213 std::string BrowserPolicyConnector::GetEnterpriseDomain() { | 224 std::string BrowserPolicyConnector::GetEnterpriseDomain() { |
| 214 #if defined(OS_CHROMEOS) | 225 #if defined(OS_CHROMEOS) |
| 215 if (install_attributes_.get()) | 226 if (install_attributes_.get()) |
| 216 return install_attributes_->GetDomain(); | 227 return install_attributes_->GetDomain(); |
| 217 #endif | 228 #endif |
| 218 | 229 |
| 219 return std::string(); | 230 return std::string(); |
| 220 } | 231 } |
| 221 | 232 |
| 222 void BrowserPolicyConnector::ResetDevicePolicy() { | 233 void BrowserPolicyConnector::ResetDevicePolicy() { |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); | 491 config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); |
| 481 } else { | 492 } else { |
| 482 return NULL; | 493 return NULL; |
| 483 } | 494 } |
| 484 #else | 495 #else |
| 485 return NULL; | 496 return NULL; |
| 486 #endif | 497 #endif |
| 487 } | 498 } |
| 488 | 499 |
| 489 } // namespace policy | 500 } // namespace policy |
| OLD | NEW |