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

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: Add missing POLICY_EXPORT 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 void DeviceCloudPolicyInitializer::Shutdown() { 88 void DeviceCloudPolicyInitializer::Shutdown() {
92 DCHECK(is_initialized_); 89 DCHECK(is_initialized_);
93 90
94 device_store_->RemoveObserver(this); 91 device_store_->RemoveObserver(this);
95 enrollment_handler_.reset(); 92 enrollment_handler_.reset();
96 state_keys_update_subscription_.reset(); 93 state_keys_update_subscription_.reset();
97 is_initialized_ = false; 94 is_initialized_ = false;
98 } 95 }
99 96
100 void DeviceCloudPolicyInitializer::StartEnrollment( 97 void DeviceCloudPolicyInitializer::StartEnrollment(
101 em::PolicyData::ManagementMode management_mode, 98 ManagementMode management_mode,
102 DeviceManagementService* device_management_service, 99 DeviceManagementService* device_management_service,
103 const std::string& auth_token, 100 const std::string& auth_token,
104 bool is_auto_enrollment, 101 bool is_auto_enrollment,
105 const AllowedDeviceModes& allowed_device_modes, 102 const AllowedDeviceModes& allowed_device_modes,
106 const EnrollmentCallback& enrollment_callback) { 103 const EnrollmentCallback& enrollment_callback) {
107 DCHECK(is_initialized_); 104 DCHECK(is_initialized_);
108 DCHECK(!enrollment_handler_); 105 DCHECK(!enrollment_handler_);
109 106
110 manager_->core()->Disconnect(); 107 manager_->core()->Disconnect();
111 enrollment_handler_.reset(new EnrollmentHandlerChromeOS( 108 enrollment_handler_.reset(new EnrollmentHandlerChromeOS(
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 return make_scoped_ptr( 208 return make_scoped_ptr(
212 new CloudPolicyClient(DeviceCloudPolicyManagerChromeOS::GetMachineID(), 209 new CloudPolicyClient(DeviceCloudPolicyManagerChromeOS::GetMachineID(),
213 DeviceCloudPolicyManagerChromeOS::GetMachineModel(), 210 DeviceCloudPolicyManagerChromeOS::GetMachineModel(),
214 kPolicyVerificationKeyHash, 211 kPolicyVerificationKeyHash,
215 USER_AFFILIATION_NONE, 212 USER_AFFILIATION_NONE,
216 device_management_service, 213 device_management_service,
217 request_context)); 214 request_context));
218 } 215 }
219 216
220 void DeviceCloudPolicyInitializer::TryToCreateClient() { 217 void DeviceCloudPolicyInitializer::TryToCreateClient() {
221 if (device_store_->is_initialized() && 218 if (!device_store_->is_initialized() ||
222 device_store_->has_policy() && 219 !device_store_->has_policy() ||
223 !device_store_->policy()->request_token().empty() && 220 state_keys_broker_->pending() ||
224 !state_keys_broker_->pending() && 221 enrollment_handler_) {
225 !enrollment_handler_) { 222 return;
226 DeviceManagementService* service = NULL;
227 if (device_store_->policy()->management_mode() ==
228 em::PolicyData::CONSUMER_MANAGED) {
229 service = consumer_service_;
230 } else {
231 service = enterprise_service_;
232 }
233 if (service)
234 StartConnection(CreateClient(service));
235 } 223 }
224
225 DeviceManagementService* service = nullptr;
226 if (GetManagementMode(*device_store_->policy()) ==
227 MANAGEMENT_MODE_CONSUMER_MANAGED) {
228 service = consumer_service_;
229 } else if (GetManagementMode(*device_store_->policy()) ==
230 MANAGEMENT_MODE_ENTERPRISE_MANAGED) {
231 service = enterprise_service_;
232 }
233
234 if (service)
235 StartConnection(CreateClient(service));
236 } 236 }
237 237
238 void DeviceCloudPolicyInitializer::StartConnection( 238 void DeviceCloudPolicyInitializer::StartConnection(
239 scoped_ptr<CloudPolicyClient> client) { 239 scoped_ptr<CloudPolicyClient> client) {
240 if (!manager_->core()->service()) 240 if (!manager_->core()->service())
241 manager_->StartConnection(client.Pass(), install_attributes_); 241 manager_->StartConnection(client.Pass(), install_attributes_);
242 242
243 if (!on_connected_callback_.is_null()) { 243 if (!on_connected_callback_.is_null()) {
244 on_connected_callback_.Run(); 244 on_connected_callback_.Run();
245 on_connected_callback_.Reset(); 245 on_connected_callback_.Reset();
246 } 246 }
247 } 247 }
248 248
249 } // namespace policy 249 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698