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

Side by Side Diff: chrome/browser/chromeos/policy/device_cloud_policy_initializer.cc

Issue 742513006: Add ManagementMode enum and GetManagementMode(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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/policy/device_cloud_policy_initializer.h" 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.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 "base/logging.h" 9 #include "base/logging.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/sequenced_task_runner.h" 11 #include "base/sequenced_task_runner.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chromeos/login/startup_utils.h" 14 #include "chrome/browser/chromeos/login/startup_utils.h"
15 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" 15 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
16 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" 16 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
17 #include "chrome/browser/chromeos/policy/device_status_collector.h" 17 #include "chrome/browser/chromeos/policy/device_status_collector.h"
18 #include "chrome/browser/chromeos/policy/enrollment_handler_chromeos.h" 18 #include "chrome/browser/chromeos/policy/enrollment_handler_chromeos.h"
19 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" 19 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
20 #include "chrome/browser/chromeos/policy/server_backed_device_state.h" 20 #include "chrome/browser/chromeos/policy/server_backed_device_state.h"
21 #include "chrome/browser/chromeos/settings/device_settings_service.h" 21 #include "chrome/browser/chromeos/settings/device_settings_service.h"
22 #include "chrome/common/chrome_content_client.h" 22 #include "chrome/common/chrome_content_client.h"
23 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "chromeos/system/statistics_provider.h" 24 #include "chromeos/system/statistics_provider.h"
25 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
26 #include "components/policy/core/common/cloud/cloud_policy_core.h" 25 #include "components/policy/core/common/cloud/cloud_policy_core.h"
27 #include "components/policy/core/common/cloud/device_management_service.h" 26 #include "components/policy/core/common/cloud/device_management_service.h"
28 #include "components/policy/core/common/cloud/system_policy_request_context.h" 27 #include "components/policy/core/common/cloud/system_policy_request_context.h"
29 #include "net/url_request/url_request_context_getter.h" 28 #include "net/url_request/url_request_context_getter.h"
30 29
31 namespace em = enterprise_management;
32
33 namespace policy { 30 namespace policy {
34 31
35 namespace { 32 namespace {
36 33
37 // Gets a machine flag from StatisticsProvider, returning the given 34 // Gets a machine flag from StatisticsProvider, returning the given
38 // |default_value| if not present. 35 // |default_value| if not present.
39 bool GetMachineFlag(const std::string& key, bool default_value) { 36 bool GetMachineFlag(const std::string& key, bool default_value) {
40 bool value = default_value; 37 bool value = default_value;
41 chromeos::system::StatisticsProvider* provider = 38 chromeos::system::StatisticsProvider* provider =
42 chromeos::system::StatisticsProvider::GetInstance(); 39 chromeos::system::StatisticsProvider::GetInstance();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 DCHECK(is_initialized_); 95 DCHECK(is_initialized_);
99 96
100 device_store_->RemoveObserver(this); 97 device_store_->RemoveObserver(this);
101 device_status_provider_.reset(); 98 device_status_provider_.reset();
102 enrollment_handler_.reset(); 99 enrollment_handler_.reset();
103 state_keys_update_subscription_.reset(); 100 state_keys_update_subscription_.reset();
104 is_initialized_ = false; 101 is_initialized_ = false;
105 } 102 }
106 103
107 void DeviceCloudPolicyInitializer::StartEnrollment( 104 void DeviceCloudPolicyInitializer::StartEnrollment(
108 em::PolicyData::ManagementMode management_mode, 105 ManagementMode management_mode,
109 DeviceManagementService* device_management_service, 106 DeviceManagementService* device_management_service,
110 const std::string& auth_token, 107 const std::string& auth_token,
111 bool is_auto_enrollment, 108 bool is_auto_enrollment,
112 const AllowedDeviceModes& allowed_device_modes, 109 const AllowedDeviceModes& allowed_device_modes,
113 const EnrollmentCallback& enrollment_callback) { 110 const EnrollmentCallback& enrollment_callback) {
114 DCHECK(is_initialized_); 111 DCHECK(is_initialized_);
115 DCHECK(!enrollment_handler_); 112 DCHECK(!enrollment_handler_);
116 113
117 manager_->core()->Disconnect(); 114 manager_->core()->Disconnect();
118 enrollment_handler_.reset(new EnrollmentHandlerChromeOS( 115 enrollment_handler_.reset(new EnrollmentHandlerChromeOS(
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 new CloudPolicyClient(DeviceCloudPolicyManagerChromeOS::GetMachineID(), 216 new CloudPolicyClient(DeviceCloudPolicyManagerChromeOS::GetMachineID(),
220 DeviceCloudPolicyManagerChromeOS::GetMachineModel(), 217 DeviceCloudPolicyManagerChromeOS::GetMachineModel(),
221 kPolicyVerificationKeyHash, 218 kPolicyVerificationKeyHash,
222 USER_AFFILIATION_NONE, 219 USER_AFFILIATION_NONE,
223 device_status_provider_.get(), 220 device_status_provider_.get(),
224 device_management_service, 221 device_management_service,
225 request_context)); 222 request_context));
226 } 223 }
227 224
228 void DeviceCloudPolicyInitializer::TryToCreateClient() { 225 void DeviceCloudPolicyInitializer::TryToCreateClient() {
229 if (device_store_->is_initialized() && 226 if (!device_store_->is_initialized() ||
230 device_store_->has_policy() && 227 !device_store_->has_policy() ||
231 !device_store_->policy()->request_token().empty() && 228 state_keys_broker_->pending() ||
232 !state_keys_broker_->pending() && 229 enrollment_handler_) {
233 !enrollment_handler_) { 230 return;
234 DeviceManagementService* service = NULL;
235 if (device_store_->policy()->management_mode() ==
236 em::PolicyData::CONSUMER_MANAGED) {
237 service = consumer_service_;
238 } else {
239 service = enterprise_service_;
240 }
241 if (service)
242 StartConnection(CreateClient(service));
243 } 231 }
232
233 DeviceManagementService* service = NULL;
bartfab (slow) 2014/11/28 13:56:53 Nit: s/NULL/nullptr/
davidyu 2014/11/29 01:50:13 Done.
234 if (GetManagementMode(*device_store_->policy()) == MANAGEMENT_MODE_CONSUMER) {
235 service = consumer_service_;
236 } else if (GetManagementMode(*device_store_->policy()) ==
237 MANAGEMENT_MODE_ENTERPRISE) {
238 service = enterprise_service_;
239 }
240
241 if (service)
242 StartConnection(CreateClient(service));
244 } 243 }
245 244
246 void DeviceCloudPolicyInitializer::StartConnection( 245 void DeviceCloudPolicyInitializer::StartConnection(
247 scoped_ptr<CloudPolicyClient> client) { 246 scoped_ptr<CloudPolicyClient> client) {
248 if (!manager_->core()->service()) 247 if (!manager_->core()->service())
249 manager_->StartConnection(client.Pass(), device_status_provider_.Pass()); 248 manager_->StartConnection(client.Pass(), device_status_provider_.Pass());
250 249
251 if (!on_connected_callback_.is_null()) { 250 if (!on_connected_callback_.is_null()) {
252 on_connected_callback_.Run(); 251 on_connected_callback_.Run();
253 on_connected_callback_.Reset(); 252 on_connected_callback_.Reset();
254 } 253 }
255 } 254 }
256 255
257 } // namespace policy 256 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698