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

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

Issue 6537020: Update policy backend and testserver for the newest policy protocol (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 5 Created 9 years, 10 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/login/ownership_service.h" 8 #include "chrome/browser/chromeos/login/ownership_service.h"
9 #include "chrome/browser/chromeos/login/user_manager.h" 9 #include "chrome/browser/chromeos/login/user_manager.h"
10 #include "chrome/browser/net/gaia/token_service.h" 10 #include "chrome/browser/net/gaia/token_service.h"
11 #include "chrome/browser/policy/proto/device_management_constants.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/common/guid.h"
13 #include "chrome/common/net/gaia/gaia_constants.h" 15 #include "chrome/common/net/gaia/gaia_constants.h"
14 #include "chrome/common/notification_service.h" 16 #include "chrome/common/notification_service.h"
15 #include "chrome/common/notification_type.h" 17 #include "chrome/common/notification_type.h"
16 18
19 #if defined(OS_CHROMEOS)
Mattias Nissler (ping if slow) 2011/02/21 14:55:27 Not needed, this file is on compiled on CrOS
gfeher 2011/02/22 15:57:29 Done.
20 #include "chrome/browser/chromeos/cros/cros_library.h"
21 #include "chrome/browser/chromeos/cros/system_library.h"
22 #endif
23
17 namespace policy { 24 namespace policy {
18 25
26 namespace {
27 // Key name for MachineInfo.
28 const char kMachineInfoSerialNumber[] = "serial_number";
29 }
30
19 DevicePolicyIdentityStrategy::DevicePolicyIdentityStrategy() 31 DevicePolicyIdentityStrategy::DevicePolicyIdentityStrategy()
20 : should_register_(false) { 32 : should_register_(false) {
21 registrar_.Add(this, 33 registrar_.Add(this,
22 NotificationType::TOKEN_AVAILABLE, 34 NotificationType::TOKEN_AVAILABLE,
23 NotificationService::AllSources()); 35 NotificationService::AllSources());
24 registrar_.Add(this, 36 registrar_.Add(this,
25 NotificationType::LOGIN_USER_CHANGED, 37 NotificationType::LOGIN_USER_CHANGED,
26 NotificationService::AllSources()); 38 NotificationService::AllSources());
27 registrar_.Add(this, 39 registrar_.Add(this,
28 NotificationType::OWNERSHIP_TAKEN, 40 NotificationType::OWNERSHIP_TAKEN,
29 NotificationService::AllSources()); 41 NotificationService::AllSources());
30 registrar_.Add(this, 42 registrar_.Add(this,
31 NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, 43 NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED,
32 NotificationService::AllSources()); 44 NotificationService::AllSources());
33 45
34 // TODO(mnissler): Figure out how to read the machine id. 46 machine_id_ = "unknown-cros-machine-ID";
35 machine_id_ = "dummy-cros-machine-ID"; 47 #if defined(OS_CHROMEOS)
48 chromeos::SystemLibrary* sys_lib =
49 chromeos::CrosLibrary::Get()->GetSystemLibrary();
Mattias Nissler (ping if slow) 2011/02/21 14:55:27 Nice! But I've heard rumors about the serial numb
gfeher 2011/02/22 15:57:29 I am still fighting with ChromeOS build to make a
50
51 // Required info.
52 std::string serial_number;
53 if (!sys_lib->GetMachineStatistic(kMachineInfoSerialNumber, &machine_id_)) {
54 LOG(WARNING) << "Failed to get machine serial number." << std::endl;
55 }
56 #endif
36 } 57 }
37 58
38 std::string DevicePolicyIdentityStrategy::GetDeviceToken() { 59 std::string DevicePolicyIdentityStrategy::GetDeviceToken() {
39 return device_token_; 60 return device_token_;
40 } 61 }
41 62
42 std::string DevicePolicyIdentityStrategy::GetDeviceID() { 63 std::string DevicePolicyIdentityStrategy::GetDeviceID() {
43 return machine_id_; 64 return machine_id_;
Jakob Kummerow 2011/02/21 16:15:00 s/machine_id_/device_id_/ ?
gfeher 2011/02/22 15:57:29 Whoops!
44 } 65 }
45 66
67 std::string DevicePolicyIdentityStrategy::GetMachineID() {
68 return machine_id_;
69 }
70
71 em::DeviceRegisterRequest_Type
72 DevicePolicyIdentityStrategy::GetPolicyRegisterType() {
73 return em::DeviceRegisterRequest::DEVICE;
74 }
75
76 std::string DevicePolicyIdentityStrategy::GetPolicyType() {
77 return kChromeDevicePolicyType;
78 }
79
46 bool DevicePolicyIdentityStrategy::GetCredentials(std::string* username, 80 bool DevicePolicyIdentityStrategy::GetCredentials(std::string* username,
47 std::string* auth_token) { 81 std::string* auth_token) {
48 // Only register if requested. 82 // Only register if requested.
49 if (!should_register_) 83 if (!should_register_)
50 return false; 84 return false;
51 85
52 // Need to know the machine id. 86 // Need to know the machine id.
53 if (machine_id_.empty()) 87 if (machine_id_.empty())
54 return false; 88 return false;
55 89
(...skipping 23 matching lines...) Expand all
79 // Reset registration flag, so we only attempt registration once. 113 // Reset registration flag, so we only attempt registration once.
80 should_register_ = false; 114 should_register_ = false;
81 115
82 device_token_ = token; 116 device_token_ = token;
83 NotifyDeviceTokenChanged(); 117 NotifyDeviceTokenChanged();
84 } 118 }
85 119
86 void DevicePolicyIdentityStrategy::CheckAndTriggerFetch() { 120 void DevicePolicyIdentityStrategy::CheckAndTriggerFetch() {
87 std::string username; 121 std::string username;
88 std::string auth_token; 122 std::string auth_token;
89 if (GetCredentials(&username, &auth_token)) 123 if (GetCredentials(&username, &auth_token)) {
124 device_id_ = guid::GenerateGUID();
90 NotifyAuthChanged(); 125 NotifyAuthChanged();
126 }
91 } 127 }
92 128
93 void DevicePolicyIdentityStrategy::Observe(NotificationType type, 129 void DevicePolicyIdentityStrategy::Observe(NotificationType type,
94 const NotificationSource& source, 130 const NotificationSource& source,
95 const NotificationDetails& details) { 131 const NotificationDetails& details) {
96 if (type == NotificationType::TOKEN_AVAILABLE) { 132 if (type == NotificationType::TOKEN_AVAILABLE) {
97 const TokenService::TokenAvailableDetails* token_details = 133 const TokenService::TokenAvailableDetails* token_details =
98 Details<const TokenService::TokenAvailableDetails>(details).ptr(); 134 Details<const TokenService::TokenAvailableDetails>(details).ptr();
99 if (token_details->service() == GaiaConstants::kDeviceManagementService) 135 if (token_details->service() == GaiaConstants::kDeviceManagementService)
100 CheckAndTriggerFetch(); 136 CheckAndTriggerFetch();
101 } else if (type == NotificationType::LOGIN_USER_CHANGED) { 137 } else if (type == NotificationType::LOGIN_USER_CHANGED) {
102 should_register_ = false; 138 should_register_ = false;
103 CheckAndTriggerFetch(); 139 CheckAndTriggerFetch();
104 } else if (type == NotificationType::OWNERSHIP_TAKEN) { 140 } else if (type == NotificationType::OWNERSHIP_TAKEN) {
105 should_register_ = true; 141 should_register_ = true;
106 CheckAndTriggerFetch(); 142 CheckAndTriggerFetch();
107 } else if (type == NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) { 143 } else if (type == NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) {
108 CheckAndTriggerFetch(); 144 CheckAndTriggerFetch();
109 } else { 145 } else {
110 NOTREACHED(); 146 NOTREACHED();
111 } 147 }
112 } 148 }
113 149
114 } // namespace policy 150 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698