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

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

Issue 10928036: Implement Chrome OS device enrollment on the new cloud policy stack. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_cloud_policy_manager_chromeos.h" 5 #include "chrome/browser/policy/device_cloud_policy_manager_chromeos.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "chrome/browser/chromeos/system/statistics_provider.h" 9 #include "chrome/browser/chromeos/system/statistics_provider.h"
10 #include "chrome/browser/policy/cloud_policy_client.h" 10 #include "chrome/browser/policy/cloud_policy_client.h"
11 #include "chrome/browser/policy/device_cloud_policy_store_chromeos.h" 11 #include "chrome/browser/policy/device_cloud_policy_store_chromeos.h"
12 #include "chrome/browser/policy/device_management_service.h" 12 #include "chrome/browser/policy/device_management_service.h"
13 #include "chrome/browser/policy/enrollment_handler_chromeos.h"
13 #include "chrome/browser/policy/enterprise_install_attributes.h" 14 #include "chrome/browser/policy/enterprise_install_attributes.h"
14 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
15 16
16 namespace policy { 17 namespace policy {
17 18
18 namespace { 19 namespace {
19 20
20 // MachineInfo key names. 21 // MachineInfo key names.
21 const char kMachineInfoSystemHwqual[] = "hardware_class"; 22 const char kMachineInfoSystemHwqual[] = "hardware_class";
22 23
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 CHECK(device_management_service); 64 CHECK(device_management_service);
64 CHECK(local_state); 65 CHECK(local_state);
65 66
66 local_state_ = local_state; 67 local_state_ = local_state;
67 device_management_service_ = device_management_service; 68 device_management_service_ = device_management_service;
68 69
69 StartIfInitialized(); 70 StartIfInitialized();
70 } 71 }
71 72
72 void DeviceCloudPolicyManagerChromeOS::Shutdown() { 73 void DeviceCloudPolicyManagerChromeOS::Shutdown() {
74 enrollment_handler_.reset();
73 ShutdownService(); 75 ShutdownService();
74 } 76 }
75 77
78 void DeviceCloudPolicyManagerChromeOS::StartEnrollment(
79 const std::string& auth_token,
80 const EnrollmentCallback& callback) {
81 CHECK(device_management_service_);
82 ShutdownService();
83
84 enrollment_handler_.reset(
85 new EnrollmentHandlerChromeOS(
86 device_store_, install_attributes_, CreateClient(), auth_token,
87 base::Bind(&DeviceCloudPolicyManagerChromeOS::EnrollmentCompleted,
88 base::Unretained(this), callback)));
89 enrollment_handler_->StartEnrollment();
90 }
91
92 void DeviceCloudPolicyManagerChromeOS::CancelEnrollment() {
93 if (enrollment_handler_.get()) {
94 enrollment_handler_.reset();
95 StartIfInitialized();
Joao da Silva 2012/09/07 14:01:42 Why? Is this for the re-enrollment case?
Mattias Nissler (ping if slow) 2012/10/23 15:30:41 Yes. Also, for robustness. While enrollment is on,
96 }
97 }
98
76 // static 99 // static
77 std::string DeviceCloudPolicyManagerChromeOS::GetMachineID() { 100 std::string DeviceCloudPolicyManagerChromeOS::GetMachineID() {
78 std::string machine_id; 101 std::string machine_id;
79 chromeos::system::StatisticsProvider* provider = 102 chromeos::system::StatisticsProvider* provider =
80 chromeos::system::StatisticsProvider::GetInstance(); 103 chromeos::system::StatisticsProvider::GetInstance();
81 for (size_t i = 0; i < arraysize(kMachineInfoSerialNumberKeys); i++) { 104 for (size_t i = 0; i < arraysize(kMachineInfoSerialNumberKeys); i++) {
82 if (provider->GetMachineStatistic(kMachineInfoSerialNumberKeys[i], 105 if (provider->GetMachineStatistic(kMachineInfoSerialNumberKeys[i],
83 &machine_id) && 106 &machine_id) &&
84 !machine_id.empty()) { 107 !machine_id.empty()) {
85 break; 108 break;
(...skipping 13 matching lines...) Expand all
99 chromeos::system::StatisticsProvider::GetInstance(); 122 chromeos::system::StatisticsProvider::GetInstance();
100 if (!provider->GetMachineStatistic(kMachineInfoSystemHwqual, &machine_model)) 123 if (!provider->GetMachineStatistic(kMachineInfoSystemHwqual, &machine_model))
101 LOG(WARNING) << "Failed to get machine model."; 124 LOG(WARNING) << "Failed to get machine model.";
102 125
103 return machine_model; 126 return machine_model;
104 } 127 }
105 128
106 void DeviceCloudPolicyManagerChromeOS::OnStoreLoaded(CloudPolicyStore* store) { 129 void DeviceCloudPolicyManagerChromeOS::OnStoreLoaded(CloudPolicyStore* store) {
107 CloudPolicyManager::OnStoreLoaded(store); 130 CloudPolicyManager::OnStoreLoaded(store);
108 131
109 if (device_management_service_ && local_state_) 132 if (!enrollment_handler_.get() && device_management_service_ && local_state_)
110 StartIfInitialized(); 133 StartIfInitialized();
111 } 134 }
112 135
113 scoped_ptr<CloudPolicyClient> DeviceCloudPolicyManagerChromeOS::CreateClient() { 136 scoped_ptr<CloudPolicyClient> DeviceCloudPolicyManagerChromeOS::CreateClient() {
114 return make_scoped_ptr( 137 return make_scoped_ptr(
115 new CloudPolicyClient(GetMachineID(), GetMachineModel(), 138 new CloudPolicyClient(GetMachineID(), GetMachineModel(),
116 USER_AFFILIATION_NONE, POLICY_SCOPE_MACHINE, NULL, 139 USER_AFFILIATION_NONE, POLICY_SCOPE_MACHINE, NULL,
117 device_management_service_)); 140 device_management_service_));
118 } 141 }
119 142
143 void DeviceCloudPolicyManagerChromeOS::EnrollmentCompleted(
144 const EnrollmentCallback& callback,
145 EnrollmentStatus status,
146 DeviceManagementStatus dm_status,
147 CloudPolicyValidatorBase::Status validator_status,
148 CloudPolicyStore::Status store_status) {
149 if (status == ENROLLMENT_STATUS_SUCCESS) {
150 InitializeService(enrollment_handler_->ReleaseClient());
151 StartRefreshScheduler(local_state_, prefs::kDevicePolicyRefreshRate);
152 } else {
153 StartIfInitialized();
154 }
155
156 enrollment_handler_.reset();
157 if (!callback.is_null())
158 callback.Run(status, dm_status, validator_status, store_status);
159 }
160
120 void DeviceCloudPolicyManagerChromeOS::StartIfInitialized() { 161 void DeviceCloudPolicyManagerChromeOS::StartIfInitialized() {
121 if (cloud_policy_store()->is_initialized() && 162 if (cloud_policy_store()->is_initialized() &&
122 cloud_policy_store()->has_policy()) { 163 cloud_policy_store()->has_policy()) {
123 InitializeService(CreateClient()); 164 InitializeService(CreateClient());
124 StartRefreshScheduler(local_state_, prefs::kDevicePolicyRefreshRate); 165 StartRefreshScheduler(local_state_, prefs::kDevicePolicyRefreshRate);
125 } 166 }
126 } 167 }
127 168
128 } // namespace policy 169 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698