Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: chrome/browser/policy/device_policy_identity_strategy.cc

Issue 6821045: Connect enrollment screen to cloud policy subsystem. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit tests... Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 LOG(ERROR) << "Failed to get machine model.";
34 }
35 if (!sys_lib->GetMachineStatistic(kMachineInfoSerialNumber,
36 &machine_id_)) {
37 LOG(ERROR) << "Failed to get machine serial number.";
38 }
22 } 39 }
23 40
24 DevicePolicyIdentityStrategy::~DevicePolicyIdentityStrategy() { 41 DevicePolicyIdentityStrategy::~DevicePolicyIdentityStrategy() {
25 } 42 }
26 43
27 std::string DevicePolicyIdentityStrategy::GetDeviceToken() { 44 std::string DevicePolicyIdentityStrategy::GetDeviceToken() {
28 return device_token_; 45 return device_token_;
29 } 46 }
30 47
31 std::string DevicePolicyIdentityStrategy::GetDeviceID() { 48 std::string DevicePolicyIdentityStrategy::GetDeviceID() {
32 return device_id_; 49 return device_id_;
33 } 50 }
34 51
35 std::string DevicePolicyIdentityStrategy::GetMachineID() { 52 std::string DevicePolicyIdentityStrategy::GetMachineID() {
36 return machine_id_; 53 return machine_id_;
37 } 54 }
38 55
56 std::string DevicePolicyIdentityStrategy::GetMachineModel() {
57 return machine_model_;
58 }
59
39 em::DeviceRegisterRequest_Type 60 em::DeviceRegisterRequest_Type
40 DevicePolicyIdentityStrategy::GetPolicyRegisterType() { 61 DevicePolicyIdentityStrategy::GetPolicyRegisterType() {
41 return em::DeviceRegisterRequest::DEVICE; 62 return em::DeviceRegisterRequest::DEVICE;
42 } 63 }
43 64
44 std::string DevicePolicyIdentityStrategy::GetPolicyType() { 65 std::string DevicePolicyIdentityStrategy::GetPolicyType() {
45 return kChromeDevicePolicyType; 66 return kChromeDevicePolicyType;
46 } 67 }
47 68
48 void DevicePolicyIdentityStrategy::SetAuthCredentials( 69 void DevicePolicyIdentityStrategy::SetAuthCredentials(
49 const std::string& username, 70 const std::string& username,
50 const std::string& auth_token, 71 const std::string& auth_token) {
51 const std::string& machine_id) {
52 username_ = username; 72 username_ = username;
53 auth_token_ = auth_token; 73 auth_token_ = auth_token;
54 machine_id_ = machine_id;
55 device_id_ = guid::GenerateGUID(); 74 device_id_ = guid::GenerateGUID();
56 NotifyAuthChanged(); 75 NotifyAuthChanged();
57 } 76 }
58 77
59 void DevicePolicyIdentityStrategy::SetDeviceManagementCredentials( 78 void DevicePolicyIdentityStrategy::SetDeviceManagementCredentials(
60 const std::string& owner_email, 79 const std::string& owner_email,
61 const std::string& device_id, 80 const std::string& device_id,
62 const std::string& device_token) { 81 const std::string& device_token) {
63 username_ = owner_email; 82 username_ = owner_email;
64 device_id_ = device_id; 83 device_id_ = device_id;
65 device_token_ = device_token; 84 device_token_ = device_token;
66 NotifyDeviceTokenChanged(); 85 NotifyDeviceTokenChanged();
67 } 86 }
68 87
69 bool DevicePolicyIdentityStrategy::GetCredentials(std::string* username, 88 bool DevicePolicyIdentityStrategy::GetCredentials(std::string* username,
70 std::string* auth_token) { 89 std::string* auth_token) {
71 // Need to know the machine id.
72 if (machine_id_.empty())
73 return false;
74
75 *username = username_; 90 *username = username_;
76 *auth_token = auth_token_; 91 *auth_token = auth_token_;
77 92
78 return !username->empty() && !auth_token->empty(); 93 return !username->empty() && !auth_token->empty();
79 } 94 }
80 95
81 void DevicePolicyIdentityStrategy::OnDeviceTokenAvailable( 96 void DevicePolicyIdentityStrategy::OnDeviceTokenAvailable(
82 const std::string& token) { 97 const std::string& token) {
83 DCHECK(!machine_id_.empty()); 98 DCHECK(!machine_id_.empty());
84 99
85 device_token_ = token; 100 device_token_ = token;
86 NotifyDeviceTokenChanged(); 101 NotifyDeviceTokenChanged();
87 } 102 }
88 103
89 } // namespace policy 104 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/device_policy_identity_strategy.h ('k') | chrome/browser/policy/device_token_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698