OLD | NEW |
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_store_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 scoped_refptr<base::SequencedTaskRunner> background_task_runner) | 33 scoped_refptr<base::SequencedTaskRunner> background_task_runner) |
34 : device_settings_service_(device_settings_service), | 34 : device_settings_service_(device_settings_service), |
35 install_attributes_(install_attributes), | 35 install_attributes_(install_attributes), |
36 background_task_runner_(background_task_runner), | 36 background_task_runner_(background_task_runner), |
37 weak_factory_(this) { | 37 weak_factory_(this) { |
38 device_settings_service_->AddObserver(this); | 38 device_settings_service_->AddObserver(this); |
39 device_settings_service_->SetDeviceMode(install_attributes_->GetMode()); | 39 device_settings_service_->SetDeviceMode(install_attributes_->GetMode()); |
40 } | 40 } |
41 | 41 |
42 DeviceCloudPolicyStoreChromeOS::~DeviceCloudPolicyStoreChromeOS() { | 42 DeviceCloudPolicyStoreChromeOS::~DeviceCloudPolicyStoreChromeOS() { |
43 if (device_settings_service_) | 43 device_settings_service_->RemoveObserver(this); |
44 device_settings_service_->RemoveObserver(this); | |
45 } | 44 } |
46 | 45 |
47 void DeviceCloudPolicyStoreChromeOS::Store( | 46 void DeviceCloudPolicyStoreChromeOS::Store( |
48 const em::PolicyFetchResponse& policy) { | 47 const em::PolicyFetchResponse& policy) { |
49 // The policy and the public key must have already been loaded by the device | 48 // The policy and the public key must have already been loaded by the device |
50 // settings service. | 49 // settings service. |
51 DCHECK(is_initialized()); | 50 DCHECK(is_initialized()); |
52 | 51 |
53 // Cancel all pending requests. | 52 // Cancel all pending requests. |
54 weak_factory_.InvalidateWeakPtrs(); | 53 weak_factory_.InvalidateWeakPtrs(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 base::Bind(&DeviceCloudPolicyStoreChromeOS::OnPolicyToStoreValidated, | 100 base::Bind(&DeviceCloudPolicyStoreChromeOS::OnPolicyToStoreValidated, |
102 weak_factory_.GetWeakPtr())); | 101 weak_factory_.GetWeakPtr())); |
103 } | 102 } |
104 | 103 |
105 void DeviceCloudPolicyStoreChromeOS::DeviceSettingsUpdated() { | 104 void DeviceCloudPolicyStoreChromeOS::DeviceSettingsUpdated() { |
106 if (!weak_factory_.HasWeakPtrs()) | 105 if (!weak_factory_.HasWeakPtrs()) |
107 UpdateFromService(); | 106 UpdateFromService(); |
108 } | 107 } |
109 | 108 |
110 void DeviceCloudPolicyStoreChromeOS::OnDeviceSettingsServiceShutdown() { | 109 void DeviceCloudPolicyStoreChromeOS::OnDeviceSettingsServiceShutdown() { |
111 device_settings_service_->RemoveObserver(this); | |
112 device_settings_service_ = nullptr; | 110 device_settings_service_ = nullptr; |
113 } | 111 } |
114 | 112 |
115 std::unique_ptr<DeviceCloudPolicyValidator> | 113 std::unique_ptr<DeviceCloudPolicyValidator> |
116 DeviceCloudPolicyStoreChromeOS::CreateValidator( | 114 DeviceCloudPolicyStoreChromeOS::CreateValidator( |
117 const em::PolicyFetchResponse& policy) { | 115 const em::PolicyFetchResponse& policy) { |
118 std::unique_ptr<DeviceCloudPolicyValidator> validator( | 116 std::unique_ptr<DeviceCloudPolicyValidator> validator( |
119 DeviceCloudPolicyValidator::Create( | 117 DeviceCloudPolicyValidator::Create( |
120 base::MakeUnique<em::PolicyFetchResponse>(policy), | 118 base::MakeUnique<em::PolicyFetchResponse>(policy), |
121 background_task_runner_)); | 119 background_task_runner_)); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 UMA_HISTOGRAM_BOOLEAN(kDMTokenCheckHistogram, true); | 237 UMA_HISTOGRAM_BOOLEAN(kDMTokenCheckHistogram, true); |
240 } else { | 238 } else { |
241 LOG(ERROR) << "Device policy read on enrolled device yields " | 239 LOG(ERROR) << "Device policy read on enrolled device yields " |
242 << "no DM token! Status: " << service_status << "."; | 240 << "no DM token! Status: " << service_status << "."; |
243 chromeos::StartupUtils::MarkEnrollmentRecoveryRequired(); | 241 chromeos::StartupUtils::MarkEnrollmentRecoveryRequired(); |
244 UMA_HISTOGRAM_BOOLEAN(kDMTokenCheckHistogram, false); | 242 UMA_HISTOGRAM_BOOLEAN(kDMTokenCheckHistogram, false); |
245 } | 243 } |
246 } | 244 } |
247 | 245 |
248 } // namespace policy | 246 } // namespace policy |
OLD | NEW |