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

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

Issue 845313008: Refactored device status uploading out of policy fetch infrastructure. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added tests, fixed existing tests. Created 5 years, 11 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 (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/chromeos/policy/device_cloud_policy_manager_chromeos.h" 5 #include "chrome/browser/chromeos/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 "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/port.h" 12 #include "base/port.h"
13 #include "base/prefs/pref_registry_simple.h" 13 #include "base/prefs/pref_registry_simple.h"
14 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "chrome/browser/chromeos/attestation/attestation_policy_observer.h" 17 #include "chrome/browser/chromeos/attestation/attestation_policy_observer.h"
18 #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h" 18 #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h"
19 #include "chrome/browser/chromeos/login/startup_utils.h" 19 #include "chrome/browser/chromeos/login/startup_utils.h"
20 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" 20 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
21 #include "chrome/browser/chromeos/policy/device_status_collector.h" 21 #include "chrome/browser/chromeos/policy/device_status_collector.h"
22 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" 22 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
23 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h" 23 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h"
24 #include "chrome/browser/chromeos/policy/status_uploader.h"
24 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
25 #include "chromeos/chromeos_constants.h" 26 #include "chromeos/chromeos_constants.h"
26 #include "chromeos/chromeos_switches.h" 27 #include "chromeos/chromeos_switches.h"
27 #include "chromeos/system/statistics_provider.h" 28 #include "chromeos/system/statistics_provider.h"
28 #include "components/policy/core/common/cloud/cloud_policy_core.h" 29 #include "components/policy/core/common/cloud/cloud_policy_core.h"
29 #include "components/policy/core/common/cloud/cloud_policy_service.h" 30 #include "components/policy/core/common/cloud/cloud_policy_service.h"
30 #include "components/policy/core/common/cloud/cloud_policy_store.h" 31 #include "components/policy/core/common/cloud/cloud_policy_store.h"
31 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
32 #include "crypto/sha2.h" 33 #include "crypto/sha2.h"
33 #include "policy/proto/device_management_backend.pb.h" 34 #include "policy/proto/device_management_backend.pb.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 ServerBackedStateKeysBroker* state_keys_broker) 107 ServerBackedStateKeysBroker* state_keys_broker)
107 : CloudPolicyManager( 108 : CloudPolicyManager(
108 dm_protocol::kChromeDevicePolicyType, 109 dm_protocol::kChromeDevicePolicyType,
109 std::string(), 110 std::string(),
110 store.get(), 111 store.get(),
111 task_runner, 112 task_runner,
112 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), 113 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
113 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)), 114 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)),
114 device_store_(store.Pass()), 115 device_store_(store.Pass()),
115 state_keys_broker_(state_keys_broker), 116 state_keys_broker_(state_keys_broker),
117 task_runner_(task_runner),
116 local_state_(nullptr) { 118 local_state_(nullptr) {
117 } 119 }
118 120
119 DeviceCloudPolicyManagerChromeOS::~DeviceCloudPolicyManagerChromeOS() {} 121 DeviceCloudPolicyManagerChromeOS::~DeviceCloudPolicyManagerChromeOS() {}
120 122
121 void DeviceCloudPolicyManagerChromeOS::Initialize(PrefService* local_state) { 123 void DeviceCloudPolicyManagerChromeOS::Initialize(PrefService* local_state) {
122 CHECK(local_state); 124 CHECK(local_state);
123 125
124 local_state_ = local_state; 126 local_state_ = local_state;
125 127
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 178
177 bool DeviceCloudPolicyManagerChromeOS::IsRemoraRequisition() const { 179 bool DeviceCloudPolicyManagerChromeOS::IsRemoraRequisition() const {
178 return GetDeviceRequisition() == kRemoraRequisition; 180 return GetDeviceRequisition() == kRemoraRequisition;
179 } 181 }
180 182
181 bool DeviceCloudPolicyManagerChromeOS::IsSharkRequisition() const { 183 bool DeviceCloudPolicyManagerChromeOS::IsSharkRequisition() const {
182 return GetDeviceRequisition() == kSharkRequisition; 184 return GetDeviceRequisition() == kSharkRequisition;
183 } 185 }
184 186
185 void DeviceCloudPolicyManagerChromeOS::Shutdown() { 187 void DeviceCloudPolicyManagerChromeOS::Shutdown() {
188 status_uploader_.reset();
186 state_keys_update_subscription_.reset(); 189 state_keys_update_subscription_.reset();
187 CloudPolicyManager::Shutdown(); 190 CloudPolicyManager::Shutdown();
188 } 191 }
189 192
190 // static 193 // static
191 void DeviceCloudPolicyManagerChromeOS::RegisterPrefs( 194 void DeviceCloudPolicyManagerChromeOS::RegisterPrefs(
192 PrefRegistrySimple* registry) { 195 PrefRegistrySimple* registry) {
193 registry->RegisterStringPref(prefs::kDeviceEnrollmentRequisition, 196 registry->RegisterStringPref(prefs::kDeviceEnrollmentRequisition,
194 std::string()); 197 std::string());
195 registry->RegisterBooleanPref(prefs::kDeviceEnrollmentAutoStart, false); 198 registry->RegisterBooleanPref(prefs::kDeviceEnrollmentAutoStart, false);
(...skipping 22 matching lines...) Expand all
218 221
219 // static 222 // static
220 std::string DeviceCloudPolicyManagerChromeOS::GetMachineModel() { 223 std::string DeviceCloudPolicyManagerChromeOS::GetMachineModel() {
221 return GetMachineStatistic(chromeos::system::kHardwareClassKey); 224 return GetMachineStatistic(chromeos::system::kHardwareClassKey);
222 } 225 }
223 226
224 void DeviceCloudPolicyManagerChromeOS::StartConnection( 227 void DeviceCloudPolicyManagerChromeOS::StartConnection(
225 scoped_ptr<CloudPolicyClient> client_to_connect, 228 scoped_ptr<CloudPolicyClient> client_to_connect,
226 EnterpriseInstallAttributes* install_attributes) { 229 EnterpriseInstallAttributes* install_attributes) {
227 CHECK(!service()); 230 CHECK(!service());
228 // Enable device reporting for enterprise enrolled devices. We want to do this
229 // even if management is currently inactive, in case management is turned
230 // back on in a future policy fetch.
231 if (install_attributes->IsEnterpriseDevice()) {
232 client_to_connect->SetStatusProvider(
233 scoped_ptr<CloudPolicyClient::StatusProvider>(
234 new DeviceStatusCollector(
235 local_state_,
236 chromeos::system::StatisticsProvider::GetInstance(),
237 DeviceStatusCollector::LocationUpdateRequester(),
238 DeviceStatusCollector::VolumeInfoFetcher())));
239 }
240 231
241 // Set state keys here so the first policy fetch submits them to the server. 232 // Set state keys here so the first policy fetch submits them to the server.
242 if (ForcedReEnrollmentEnabled()) 233 if (ForcedReEnrollmentEnabled())
243 client_to_connect->SetStateKeysToUpload(state_keys_broker_->state_keys()); 234 client_to_connect->SetStateKeysToUpload(state_keys_broker_->state_keys());
244 235
245 core()->Connect(client_to_connect.Pass()); 236 core()->Connect(client_to_connect.Pass());
246 core()->StartRefreshScheduler(); 237 core()->StartRefreshScheduler();
247 core()->TrackRefreshDelayPref(local_state_, 238 core()->TrackRefreshDelayPref(local_state_,
248 prefs::kDevicePolicyRefreshRate); 239 prefs::kDevicePolicyRefreshRate);
249 attestation_policy_observer_.reset( 240 attestation_policy_observer_.reset(
250 new chromeos::attestation::AttestationPolicyObserver(client())); 241 new chromeos::attestation::AttestationPolicyObserver(client()));
251 242
243 // Enable device reporting for enterprise enrolled devices. We want to do this
244 // even if management is currently inactive, in case management is turned
245 // back on in a future policy fetch.
246 if (install_attributes->IsEnterpriseDevice()) {
247 status_uploader_.reset(
248 new StatusUploader(
249 local_state_,
250 client(),
251 make_scoped_ptr(new DeviceStatusCollector(
252 local_state_,
253 chromeos::system::StatisticsProvider::GetInstance(),
254 DeviceStatusCollector::LocationUpdateRequester(),
255 DeviceStatusCollector::VolumeInfoFetcher())),
256 task_runner_));
257 }
258
252 NotifyConnected(); 259 NotifyConnected();
253 } 260 }
254 261
255 void DeviceCloudPolicyManagerChromeOS::Unregister( 262 void DeviceCloudPolicyManagerChromeOS::Unregister(
256 const UnregisterCallback& callback) { 263 const UnregisterCallback& callback) {
257 if (!service()) { 264 if (!service()) {
258 LOG(ERROR) << "Tried to unregister but DeviceCloudPolicyManagerChromeOS is " 265 LOG(ERROR) << "Tried to unregister but DeviceCloudPolicyManagerChromeOS is "
259 << "not connected."; 266 << "not connected.";
260 callback.Run(false); 267 callback.Run(false);
261 return; 268 return;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 FOR_EACH_OBSERVER( 318 FOR_EACH_OBSERVER(
312 Observer, observers_, OnDeviceCloudPolicyManagerConnected()); 319 Observer, observers_, OnDeviceCloudPolicyManagerConnected());
313 } 320 }
314 321
315 void DeviceCloudPolicyManagerChromeOS::NotifyDisconnected() { 322 void DeviceCloudPolicyManagerChromeOS::NotifyDisconnected() {
316 FOR_EACH_OBSERVER( 323 FOR_EACH_OBSERVER(
317 Observer, observers_, OnDeviceCloudPolicyManagerDisconnected()); 324 Observer, observers_, OnDeviceCloudPolicyManagerDisconnected());
318 } 325 }
319 326
320 } // namespace policy 327 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698