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" | |
9 #include "chrome/browser/chromeos/cros/system_library.h" | |
8 #include "chrome/browser/chromeos/login/ownership_service.h" | 10 #include "chrome/browser/chromeos/login/ownership_service.h" |
9 #include "chrome/browser/chromeos/login/user_manager.h" | 11 #include "chrome/browser/chromeos/login/user_manager.h" |
10 #include "chrome/browser/net/gaia/token_service.h" | 12 #include "chrome/browser/net/gaia/token_service.h" |
11 #include "chrome/browser/policy/proto/device_management_constants.h" | 13 #include "chrome/browser/policy/proto/device_management_constants.h" |
12 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/common/guid.h" | 16 #include "chrome/common/guid.h" |
15 #include "chrome/common/net/gaia/gaia_constants.h" | 17 #include "chrome/common/net/gaia/gaia_constants.h" |
16 #include "content/common/notification_service.h" | 18 #include "content/common/notification_service.h" |
17 #include "content/common/notification_type.h" | 19 #include "content/common/notification_type.h" |
18 | 20 |
21 // MachineInfo key names. | |
22 static const char kMachineInfoSystemHwqual[] = "hardware_class"; | |
23 static const char kMachineInfoSerialNumber[] = "serial_number"; | |
24 | |
19 namespace policy { | 25 namespace policy { |
20 | 26 |
21 DevicePolicyIdentityStrategy::DevicePolicyIdentityStrategy() { | 27 DevicePolicyIdentityStrategy::DevicePolicyIdentityStrategy() { |
28 chromeos::SystemLibrary* sys_lib = | |
29 chromeos::CrosLibrary::Get()->GetSystemLibrary(); | |
30 | |
31 if (!sys_lib->GetMachineStatistic(kMachineInfoSystemHwqual, | |
32 &machine_model_) || | |
33 !sys_lib->GetMachineStatistic(kMachineInfoSerialNumber, | |
Jakob Kummerow
2011/04/12 16:42:59
Due to lazy evaluation of conditions, if fetching
Mattias Nissler (ping if slow)
2011/04/12 16:49:47
Good point, no reason to not be more careful.
Done
| |
34 &machine_id_)) { | |
35 LOG(ERROR) << "Failed to get machine information, using dummy model " | |
36 << machine_model_ << " and id " << machine_id_; | |
37 } | |
22 } | 38 } |
23 | 39 |
24 DevicePolicyIdentityStrategy::~DevicePolicyIdentityStrategy() { | 40 DevicePolicyIdentityStrategy::~DevicePolicyIdentityStrategy() { |
25 } | 41 } |
26 | 42 |
27 std::string DevicePolicyIdentityStrategy::GetDeviceToken() { | 43 std::string DevicePolicyIdentityStrategy::GetDeviceToken() { |
28 return device_token_; | 44 return device_token_; |
29 } | 45 } |
30 | 46 |
31 std::string DevicePolicyIdentityStrategy::GetDeviceID() { | 47 std::string DevicePolicyIdentityStrategy::GetDeviceID() { |
32 return device_id_; | 48 return device_id_; |
33 } | 49 } |
34 | 50 |
35 std::string DevicePolicyIdentityStrategy::GetMachineID() { | 51 std::string DevicePolicyIdentityStrategy::GetMachineID() { |
36 return machine_id_; | 52 return machine_id_; |
37 } | 53 } |
38 | 54 |
55 std::string DevicePolicyIdentityStrategy::GetMachineModel() { | |
56 return machine_model_; | |
57 } | |
58 | |
39 em::DeviceRegisterRequest_Type | 59 em::DeviceRegisterRequest_Type |
40 DevicePolicyIdentityStrategy::GetPolicyRegisterType() { | 60 DevicePolicyIdentityStrategy::GetPolicyRegisterType() { |
41 return em::DeviceRegisterRequest::DEVICE; | 61 return em::DeviceRegisterRequest::DEVICE; |
42 } | 62 } |
43 | 63 |
44 std::string DevicePolicyIdentityStrategy::GetPolicyType() { | 64 std::string DevicePolicyIdentityStrategy::GetPolicyType() { |
45 return kChromeDevicePolicyType; | 65 return kChromeDevicePolicyType; |
46 } | 66 } |
47 | 67 |
48 void DevicePolicyIdentityStrategy::SetAuthCredentials( | 68 void DevicePolicyIdentityStrategy::SetAuthCredentials( |
49 const std::string& username, | 69 const std::string& username, |
50 const std::string& auth_token, | 70 const std::string& auth_token) { |
51 const std::string& machine_id) { | |
52 username_ = username; | 71 username_ = username; |
53 auth_token_ = auth_token; | 72 auth_token_ = auth_token; |
54 machine_id_ = machine_id; | |
55 device_id_ = guid::GenerateGUID(); | 73 device_id_ = guid::GenerateGUID(); |
56 NotifyAuthChanged(); | 74 NotifyAuthChanged(); |
57 } | 75 } |
58 | 76 |
59 void DevicePolicyIdentityStrategy::SetDeviceManagementCredentials( | 77 void DevicePolicyIdentityStrategy::SetDeviceManagementCredentials( |
60 const std::string& owner_email, | 78 const std::string& owner_email, |
61 const std::string& device_id, | 79 const std::string& device_id, |
62 const std::string& device_token) { | 80 const std::string& device_token) { |
63 username_ = owner_email; | 81 username_ = owner_email; |
64 device_id_ = device_id; | 82 device_id_ = device_id; |
65 device_token_ = device_token; | 83 device_token_ = device_token; |
66 NotifyDeviceTokenChanged(); | 84 NotifyDeviceTokenChanged(); |
67 } | 85 } |
68 | 86 |
69 bool DevicePolicyIdentityStrategy::GetCredentials(std::string* username, | 87 bool DevicePolicyIdentityStrategy::GetCredentials(std::string* username, |
70 std::string* auth_token) { | 88 std::string* auth_token) { |
71 // Need to know the machine id. | |
72 if (machine_id_.empty()) | |
73 return false; | |
74 | |
75 *username = username_; | 89 *username = username_; |
76 *auth_token = auth_token_; | 90 *auth_token = auth_token_; |
77 | 91 |
78 return !username->empty() && !auth_token->empty(); | 92 return !username->empty() && !auth_token->empty(); |
79 } | 93 } |
80 | 94 |
81 void DevicePolicyIdentityStrategy::OnDeviceTokenAvailable( | 95 void DevicePolicyIdentityStrategy::OnDeviceTokenAvailable( |
82 const std::string& token) { | 96 const std::string& token) { |
83 DCHECK(!machine_id_.empty()); | 97 DCHECK(!machine_id_.empty()); |
84 | 98 |
85 device_token_ = token; | 99 device_token_ = token; |
86 NotifyDeviceTokenChanged(); | 100 NotifyDeviceTokenChanged(); |
87 } | 101 } |
88 | 102 |
89 } // namespace policy | 103 } // namespace policy |
OLD | NEW |