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