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

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: Addressed comments, rebased. Created 8 years, 1 month 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"
8 #include "base/bind_helpers.h"
7 #include "chrome/browser/chromeos/system/statistics_provider.h" 9 #include "chrome/browser/chromeos/system/statistics_provider.h"
8 #include "chrome/browser/policy/cloud_policy_client.h" 10 #include "chrome/browser/policy/cloud_policy_client.h"
9 #include "chrome/browser/policy/device_cloud_policy_store_chromeos.h" 11 #include "chrome/browser/policy/device_cloud_policy_store_chromeos.h"
10 #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"
11 #include "chrome/browser/policy/enterprise_install_attributes.h" 14 #include "chrome/browser/policy/enterprise_install_attributes.h"
12 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
13 16
14 namespace policy { 17 namespace policy {
15 18
16 namespace { 19 namespace {
17 20
18 // MachineInfo key names. 21 // MachineInfo key names.
19 const char kMachineInfoSystemHwqual[] = "hardware_class"; 22 const char kMachineInfoSystemHwqual[] = "hardware_class";
20 23
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 CHECK(!device_management_service_); 63 CHECK(!device_management_service_);
61 CHECK(device_management_service); 64 CHECK(device_management_service);
62 CHECK(local_state); 65 CHECK(local_state);
63 66
64 local_state_ = local_state; 67 local_state_ = local_state;
65 device_management_service_ = device_management_service; 68 device_management_service_ = device_management_service;
66 69
67 StartIfManaged(); 70 StartIfManaged();
68 } 71 }
69 72
73 void DeviceCloudPolicyManagerChromeOS::StartEnrollment(
74 const std::string& auth_token,
75 const AllowedDeviceModes& allowed_device_modes,
76 const EnrollmentCallback& callback) {
77 CHECK(device_management_service_);
78 ShutdownService();
79
80 enrollment_handler_.reset(
81 new EnrollmentHandlerChromeOS(
82 device_store_, install_attributes_, CreateClient(), auth_token,
83 allowed_device_modes,
84 base::Bind(&DeviceCloudPolicyManagerChromeOS::EnrollmentCompleted,
85 base::Unretained(this), callback)));
86 enrollment_handler_->StartEnrollment();
87 }
88
89 void DeviceCloudPolicyManagerChromeOS::CancelEnrollment() {
90 if (enrollment_handler_.get()) {
91 enrollment_handler_.reset();
92 StartIfManaged();
93 }
94 }
95
70 void DeviceCloudPolicyManagerChromeOS::OnStoreLoaded(CloudPolicyStore* store) { 96 void DeviceCloudPolicyManagerChromeOS::OnStoreLoaded(CloudPolicyStore* store) {
71 CloudPolicyManager::OnStoreLoaded(store); 97 CloudPolicyManager::OnStoreLoaded(store);
72 98
73 StartIfManaged(); 99 if (!enrollment_handler_.get())
100 StartIfManaged();
74 } 101 }
75 102
76 // static 103 // static
77 std::string DeviceCloudPolicyManagerChromeOS::GetMachineID() { 104 std::string DeviceCloudPolicyManagerChromeOS::GetMachineID() {
78 std::string machine_id; 105 std::string machine_id;
79 chromeos::system::StatisticsProvider* provider = 106 chromeos::system::StatisticsProvider* provider =
80 chromeos::system::StatisticsProvider::GetInstance(); 107 chromeos::system::StatisticsProvider::GetInstance();
81 for (size_t i = 0; i < arraysize(kMachineInfoSerialNumberKeys); i++) { 108 for (size_t i = 0; i < arraysize(kMachineInfoSerialNumberKeys); i++) {
82 if (provider->GetMachineStatistic(kMachineInfoSerialNumberKeys[i], 109 if (provider->GetMachineStatistic(kMachineInfoSerialNumberKeys[i],
83 &machine_id) && 110 &machine_id) &&
(...skipping 19 matching lines...) Expand all
103 return machine_model; 130 return machine_model;
104 } 131 }
105 132
106 scoped_ptr<CloudPolicyClient> DeviceCloudPolicyManagerChromeOS::CreateClient() { 133 scoped_ptr<CloudPolicyClient> DeviceCloudPolicyManagerChromeOS::CreateClient() {
107 return make_scoped_ptr( 134 return make_scoped_ptr(
108 new CloudPolicyClient(GetMachineID(), GetMachineModel(), 135 new CloudPolicyClient(GetMachineID(), GetMachineModel(),
109 USER_AFFILIATION_NONE, POLICY_SCOPE_MACHINE, NULL, 136 USER_AFFILIATION_NONE, POLICY_SCOPE_MACHINE, NULL,
110 device_management_service_)); 137 device_management_service_));
111 } 138 }
112 139
140 void DeviceCloudPolicyManagerChromeOS::EnrollmentCompleted(
141 const EnrollmentCallback& callback,
142 EnrollmentStatus status) {
143 if (status.status() == EnrollmentStatus::STATUS_SUCCESS) {
pastarmovj 2012/10/23 15:58:08 Isn't it possible to call StartIfManaged() uncondi
Mattias Nissler (ping if slow) 2012/10/23 16:33:03 No, in this case we want to reuse the client. I gu
144 InitializeService(enrollment_handler_->ReleaseClient());
145 StartRefreshScheduler(local_state_, prefs::kDevicePolicyRefreshRate);
146 } else {
147 StartIfManaged();
148 }
149
150 enrollment_handler_.reset();
151 if (!callback.is_null())
152 callback.Run(status);
153 }
154
113 void DeviceCloudPolicyManagerChromeOS::StartIfManaged() { 155 void DeviceCloudPolicyManagerChromeOS::StartIfManaged() {
114 if (device_management_service_ && 156 if (device_management_service_ &&
115 local_state_ && 157 local_state_ &&
116 cloud_policy_store()->is_initialized() && 158 cloud_policy_store()->is_initialized() &&
117 cloud_policy_store()->is_managed() && 159 cloud_policy_store()->is_managed() &&
118 !cloud_policy_service()) { 160 !cloud_policy_service()) {
119 InitializeService(CreateClient()); 161 InitializeService(CreateClient());
120 StartRefreshScheduler(local_state_, prefs::kDevicePolicyRefreshRate); 162 StartRefreshScheduler(local_state_, prefs::kDevicePolicyRefreshRate);
121 } 163 }
122 } 164 }
123 165
124 } // namespace policy 166 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698