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

Side by Side Diff: chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper_impl.cc

Issue 2977033002: Mixed Licenses Enrollment (Closed)
Patch Set: First test part Created 3 years, 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/chromeos/login/enrollment/enterprise_enrollment_helper_ impl.h" 5 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper_ impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h"
8 #include "base/location.h" 9 #include "base/location.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
13 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/browser_process_platform_part.h" 15 #include "chrome/browser/browser_process_platform_part.h"
15 #include "chrome/browser/chromeos/login/enrollment/enrollment_uma.h" 16 #include "chrome/browser/chromeos/login/enrollment/enrollment_uma.h"
16 #include "chrome/browser/chromeos/login/startup_utils.h" 17 #include "chrome/browser/chromeos/login/startup_utils.h"
17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
18 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" 19 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h"
19 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" 20 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h"
20 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" 21 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h"
21 #include "chrome/browser/chromeos/profiles/profile_helper.h" 22 #include "chrome/browser/chromeos/profiles/profile_helper.h"
23 #include "chromeos/chromeos_switches.h"
22 #include "chromeos/dbus/dbus_thread_manager.h" 24 #include "chromeos/dbus/dbus_thread_manager.h"
23 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 25 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
24 #include "google_apis/gaia/gaia_auth_consumer.h" 26 #include "google_apis/gaia/gaia_auth_consumer.h"
25 #include "google_apis/gaia/gaia_auth_fetcher.h" 27 #include "google_apis/gaia/gaia_auth_fetcher.h"
26 #include "google_apis/gaia/gaia_constants.h" 28 #include "google_apis/gaia/gaia_constants.h"
27 29
28 namespace { 30 namespace {
29 31
30 // A helper class that takes care of asynchronously revoking a given token. 32 // A helper class that takes care of asynchronously revoking a given token.
31 class TokenRevoker : public GaiaAuthConsumer { 33 class TokenRevoker : public GaiaAuthConsumer {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 connector->GetEnterpriseEnrollmentDomain() != enrolling_user_domain_) { 155 connector->GetEnterpriseEnrollmentDomain() != enrolling_user_domain_) {
154 LOG(ERROR) << "Trying to re-enroll to a different domain than " 156 LOG(ERROR) << "Trying to re-enroll to a different domain than "
155 << connector->GetEnterpriseEnrollmentDomain(); 157 << connector->GetEnterpriseEnrollmentDomain();
156 UMA(policy::kMetricEnrollmentPrecheckDomainMismatch); 158 UMA(policy::kMetricEnrollmentPrecheckDomainMismatch);
157 if (oauth_status_ != OAUTH_NOT_STARTED) 159 if (oauth_status_ != OAUTH_NOT_STARTED)
158 oauth_status_ = OAUTH_FINISHED; 160 oauth_status_ = OAUTH_FINISHED;
159 status_consumer()->OnOtherError(OTHER_ERROR_DOMAIN_MISMATCH); 161 status_consumer()->OnOtherError(OTHER_ERROR_DOMAIN_MISMATCH);
160 return; 162 return;
161 } 163 }
162 164
165 bool check_license_type = false;
166 // The license selection dialog is not used when doing Zero Touch.
167 if (!enrollment_config_.is_mode_attestation()) {
168 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
169 if (command_line->HasSwitch(
170 chromeos::switches::kEnterpriseEnableLicenseTypeSelection)) {
171 check_license_type = true;
172 }
173 }
174
163 connector->ScheduleServiceInitialization(0); 175 connector->ScheduleServiceInitialization(0);
164 policy::DeviceCloudPolicyInitializer* dcp_initializer = 176 policy::DeviceCloudPolicyInitializer* dcp_initializer =
165 connector->GetDeviceCloudPolicyInitializer(); 177 connector->GetDeviceCloudPolicyInitializer();
166 CHECK(dcp_initializer); 178 CHECK(dcp_initializer);
167 dcp_initializer->StartEnrollment( 179 dcp_initializer->PrepareEnrollment(
168 connector->device_management_service(), ad_join_delegate_, 180 connector->device_management_service(), ad_join_delegate_,
169 enrollment_config_, token, 181 enrollment_config_, token,
170 base::Bind(&EnterpriseEnrollmentHelperImpl::OnEnrollmentFinished, 182 base::Bind(&EnterpriseEnrollmentHelperImpl::OnEnrollmentFinished,
171 weak_ptr_factory_.GetWeakPtr())); 183 weak_ptr_factory_.GetWeakPtr()));
184 if (check_license_type) {
185 dcp_initializer->CheckAvailableLicenses(
186 base::Bind(&EnterpriseEnrollmentHelperImpl::OnLicenseMapObtained,
187 weak_ptr_factory_.GetWeakPtr()));
188 } else {
189 dcp_initializer->StartEnrollment();
190 }
191 }
192
193 void EnterpriseEnrollmentHelperImpl::UseLicenseType(policy::LicenseType type) {
194 DCHECK(type != policy::LicenseType::UNKNOWN);
195
196 policy::BrowserPolicyConnectorChromeOS* connector =
197 g_browser_process->platform_part()->browser_policy_connector_chromeos();
198 policy::DeviceCloudPolicyInitializer* dcp_initializer =
199 connector->GetDeviceCloudPolicyInitializer();
200 CHECK(dcp_initializer);
201 dcp_initializer->StartEnrollmentWithLicense(type);
172 } 202 }
173 203
174 void EnterpriseEnrollmentHelperImpl::GetDeviceAttributeUpdatePermission() { 204 void EnterpriseEnrollmentHelperImpl::GetDeviceAttributeUpdatePermission() {
175 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed. 205 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed.
176 LOG(WARNING) << "Get device attribute update permission"; 206 LOG(WARNING) << "Get device attribute update permission";
177 policy::BrowserPolicyConnectorChromeOS* connector = 207 policy::BrowserPolicyConnectorChromeOS* connector =
178 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 208 g_browser_process->platform_part()->browser_policy_connector_chromeos();
179 // Don't update device attributes for Active Directory management. 209 // Don't update device attributes for Active Directory management.
180 if (connector->IsActiveDirectoryManaged()) { 210 if (connector->IsActiveDirectoryManaged()) {
181 OnDeviceAttributeUpdatePermission(false); 211 OnDeviceAttributeUpdatePermission(false);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 oauth_status_ = OAUTH_FINISHED; 273 oauth_status_ = OAUTH_FINISHED;
244 if (status.status() == policy::EnrollmentStatus::SUCCESS) { 274 if (status.status() == policy::EnrollmentStatus::SUCCESS) {
245 success_ = true; 275 success_ = true;
246 StartupUtils::MarkOobeCompleted(); 276 StartupUtils::MarkOobeCompleted();
247 status_consumer()->OnDeviceEnrolled(additional_token_); 277 status_consumer()->OnDeviceEnrolled(additional_token_);
248 } else { 278 } else {
249 status_consumer()->OnEnrollmentError(status); 279 status_consumer()->OnEnrollmentError(status);
250 } 280 }
251 } 281 }
252 282
283 void EnterpriseEnrollmentHelperImpl::OnLicenseMapObtained(
284 const EnrollmentLicenseMap& licenses) {
285 int count = 0;
286 policy::LicenseType license_type = policy::LicenseType::UNKNOWN;
287 for (const auto& it : licenses) {
288 if (it.second > 0) {
289 count++;
290 license_type = it.first;
291 }
292 }
293 if (count == 0) {
294 // No user license type selection allowed, start usual enrollment.
295 policy::BrowserPolicyConnectorChromeOS* connector =
296 g_browser_process->platform_part()->browser_policy_connector_chromeos();
297 policy::DeviceCloudPolicyInitializer* dcp_initializer =
298 connector->GetDeviceCloudPolicyInitializer();
299 CHECK(dcp_initializer);
300 dcp_initializer->StartEnrollment();
301 } else if (count == 1) {
302 UseLicenseType(license_type);
303 } else {
304 status_consumer()->OnMultipleLicensesAvailable(licenses);
305 }
306 }
307
253 void EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUpdatePermission( 308 void EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUpdatePermission(
254 bool granted) { 309 bool granted) {
255 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed. 310 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed.
256 LOG(WARNING) << "Device attribute update permission granted=" << granted; 311 LOG(WARNING) << "Device attribute update permission granted=" << granted;
257 status_consumer()->OnDeviceAttributeUpdatePermission(granted); 312 status_consumer()->OnDeviceAttributeUpdatePermission(granted);
258 } 313 }
259 314
260 void EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUploadCompleted( 315 void EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUploadCompleted(
261 bool success) { 316 bool success) {
262 status_consumer()->OnDeviceAttributeUploadCompleted(success); 317 status_consumer()->OnDeviceAttributeUploadCompleted(success);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 EnrollmentUMA(sample, enrollment_config_.mode); 498 EnrollmentUMA(sample, enrollment_config_.mode);
444 } 499 }
445 500
446 void EnterpriseEnrollmentHelperImpl::OnSigninProfileCleared( 501 void EnterpriseEnrollmentHelperImpl::OnSigninProfileCleared(
447 const base::Closure& callback) { 502 const base::Closure& callback) {
448 oauth_data_cleared_ = true; 503 oauth_data_cleared_ = true;
449 callback.Run(); 504 callback.Run();
450 } 505 }
451 506
452 } // namespace chromeos 507 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698