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

Side by Side Diff: chrome/browser/policy/device_policy_cache.cc

Issue 7298012: Consolidate data storage and notifications in the cloud policy subsystem (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/policy/device_policy_cache.h" 5 #include "chrome/browser/policy/device_policy_cache.h"
6 6
7 #include <string>
8
7 #include "base/basictypes.h" 9 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
11 #include "base/task.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "chrome/browser/chromeos/cros/cros_library.h" 14 #include "chrome/browser/chromeos/cros/cros_library.h"
14 #include "chrome/browser/chromeos/cros/update_library.h" 15 #include "chrome/browser/chromeos/cros/update_library.h"
15 #include "chrome/browser/chromeos/cros_settings_names.h" 16 #include "chrome/browser/chromeos/cros_settings_names.h"
16 #include "chrome/browser/chromeos/login/ownership_service.h" 17 #include "chrome/browser/chromeos/login/ownership_service.h"
17 #include "chrome/browser/chromeos/user_cros_settings_provider.h" 18 #include "chrome/browser/chromeos/user_cros_settings_provider.h"
18 #include "chrome/browser/policy/configuration_policy_pref_store.h" 19 #include "chrome/browser/policy/cloud_policy_data_store.h"
19 #include "chrome/browser/policy/device_policy_identity_strategy.h"
20 #include "chrome/browser/policy/enterprise_install_attributes.h" 20 #include "chrome/browser/policy/enterprise_install_attributes.h"
21 #include "chrome/browser/policy/enterprise_metrics.h" 21 #include "chrome/browser/policy/enterprise_metrics.h"
22 #include "chrome/browser/policy/policy_map.h" 22 #include "chrome/browser/policy/policy_map.h"
23 #include "chrome/browser/policy/proto/device_management_backend.pb.h" 23 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
24 #include "chrome/browser/policy/proto/device_management_constants.h" 24 #include "chrome/browser/policy/proto/device_management_constants.h"
25 #include "chrome/browser/policy/proto/device_management_local.pb.h" 25 #include "chrome/browser/policy/proto/device_management_local.pb.h"
26 #include "content/browser/browser_thread.h"
27 #include "policy/configuration_policy_type.h" 26 #include "policy/configuration_policy_type.h"
28 27
29 namespace { 28 namespace {
30 29
31 // Stores policy, updates the owner key if required and reports the status 30 // Stores policy, updates the owner key if required and reports the status
32 // through a callback. 31 // through a callback.
33 class StorePolicyOperation : public chromeos::SignedSettingsHelper::Callback, 32 class StorePolicyOperation : public chromeos::SignedSettingsHelper::Callback,
34 public chromeos::OwnerManager::KeyUpdateDelegate { 33 public chromeos::OwnerManager::KeyUpdateDelegate {
35 public: 34 public:
36 typedef Callback1<chromeos::SignedSettings::ReturnCode>::Type Callback; 35 typedef Callback1<chromeos::SignedSettings::ReturnCode>::Type Callback;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 105 }
107 106
108 return Value::CreateIntegerValue(static_cast<int>(value)); 107 return Value::CreateIntegerValue(static_cast<int>(value));
109 } 108 }
110 109
111 } // namespace 110 } // namespace
112 111
113 namespace policy { 112 namespace policy {
114 113
115 DevicePolicyCache::DevicePolicyCache( 114 DevicePolicyCache::DevicePolicyCache(
116 DevicePolicyIdentityStrategy* identity_strategy, 115 CloudPolicyDataStore* data_store,
117 EnterpriseInstallAttributes* install_attributes) 116 EnterpriseInstallAttributes* install_attributes)
118 : identity_strategy_(identity_strategy), 117 : data_store_(data_store),
119 install_attributes_(install_attributes), 118 install_attributes_(install_attributes),
120 signed_settings_helper_(chromeos::SignedSettingsHelper::Get()), 119 signed_settings_helper_(chromeos::SignedSettingsHelper::Get()),
121 starting_up_(true), 120 starting_up_(true),
122 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { 121 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) {
123 } 122 }
124 123
125 DevicePolicyCache::DevicePolicyCache( 124 DevicePolicyCache::DevicePolicyCache(
126 DevicePolicyIdentityStrategy* identity_strategy, 125 CloudPolicyDataStore* data_store,
127 EnterpriseInstallAttributes* install_attributes, 126 EnterpriseInstallAttributes* install_attributes,
128 chromeos::SignedSettingsHelper* signed_settings_helper) 127 chromeos::SignedSettingsHelper* signed_settings_helper)
129 : identity_strategy_(identity_strategy), 128 : data_store_(data_store),
130 install_attributes_(install_attributes), 129 install_attributes_(install_attributes),
131 signed_settings_helper_(signed_settings_helper), 130 signed_settings_helper_(signed_settings_helper),
132 starting_up_(true), 131 starting_up_(true),
133 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { 132 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) {
134 } 133 }
135 134
136 DevicePolicyCache::~DevicePolicyCache() { 135 DevicePolicyCache::~DevicePolicyCache() {
137 signed_settings_helper_->CancelCallback(this); 136 signed_settings_helper_->CancelCallback(this);
138 } 137 }
139 138
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 bool DevicePolicyCache::IsReady() { 193 bool DevicePolicyCache::IsReady() {
195 return initialization_complete() || !starting_up_; 194 return initialization_complete() || !starting_up_;
196 } 195 }
197 196
198 void DevicePolicyCache::OnRetrievePolicyCompleted( 197 void DevicePolicyCache::OnRetrievePolicyCompleted(
199 chromeos::SignedSettings::ReturnCode code, 198 chromeos::SignedSettings::ReturnCode code,
200 const em::PolicyFetchResponse& policy) { 199 const em::PolicyFetchResponse& policy) {
201 DCHECK(CalledOnValidThread()); 200 DCHECK(CalledOnValidThread());
202 if (starting_up_) { 201 if (starting_up_) {
203 starting_up_ = false; 202 starting_up_ = false;
203 // All the code paths should issue a data_store_->SetDeviceToken(..., true)
204 // to signal that the cache has finished loading, so other components
205 // are free to modify token data.
204 if (code == chromeos::SignedSettings::NOT_FOUND || 206 if (code == chromeos::SignedSettings::NOT_FOUND ||
205 code == chromeos::SignedSettings::KEY_UNAVAILABLE || 207 code == chromeos::SignedSettings::KEY_UNAVAILABLE ||
206 !policy.has_policy_data()) { 208 !policy.has_policy_data()) {
207 InformNotifier(CloudPolicySubsystem::UNENROLLED, 209 InformNotifier(CloudPolicySubsystem::UNENROLLED,
208 CloudPolicySubsystem::NO_DETAILS); 210 CloudPolicySubsystem::NO_DETAILS);
211 data_store_->SetDeviceToken("", true);
209 return; 212 return;
210 } 213 }
211 em::PolicyData policy_data; 214 em::PolicyData policy_data;
212 if (!policy_data.ParseFromString(policy.policy_data())) { 215 if (!policy_data.ParseFromString(policy.policy_data())) {
213 LOG(WARNING) << "Failed to parse PolicyData protobuf."; 216 LOG(WARNING) << "Failed to parse PolicyData protobuf.";
214 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyLoadFailed, 217 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyLoadFailed,
215 kMetricPolicySize); 218 kMetricPolicySize);
216 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, 219 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR,
217 CloudPolicySubsystem::POLICY_LOCAL_ERROR); 220 CloudPolicySubsystem::POLICY_LOCAL_ERROR);
221 data_store_->SetDeviceToken("", true);
218 return; 222 return;
219 } 223 }
220 if (!policy_data.has_request_token() || 224 if (!policy_data.has_request_token() ||
221 policy_data.request_token().empty()) { 225 policy_data.request_token().empty()) {
222 SetUnmanagedInternal(base::Time::NowFromSystemTime()); 226 SetUnmanagedInternal(base::Time::NowFromSystemTime());
223 InformNotifier(CloudPolicySubsystem::UNMANAGED, 227 InformNotifier(CloudPolicySubsystem::UNMANAGED,
224 CloudPolicySubsystem::NO_DETAILS); 228 CloudPolicySubsystem::NO_DETAILS);
225 // TODO(jkummerow): Reminder: When we want to feed device-wide settings 229 // TODO(jkummerow): Reminder: When we want to feed device-wide settings
226 // made by a local owner into this cache, we need to call 230 // made by a local owner into this cache, we need to call
227 // SetPolicyInternal() here. 231 // SetPolicyInternal() here.
232 data_store_->SetDeviceToken("", true);
228 return; 233 return;
229 } 234 }
230 if (!policy_data.has_username() || !policy_data.has_device_id()) { 235 if (!policy_data.has_username() || !policy_data.has_device_id()) {
231 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyLoadFailed, 236 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyLoadFailed,
232 kMetricPolicySize); 237 kMetricPolicySize);
233 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, 238 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR,
234 CloudPolicySubsystem::POLICY_LOCAL_ERROR); 239 CloudPolicySubsystem::POLICY_LOCAL_ERROR);
240 data_store_->SetDeviceToken("", true);
235 return; 241 return;
236 } 242 }
237 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyLoadSucceeded, 243 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyLoadSucceeded,
238 kMetricPolicySize); 244 kMetricPolicySize);
239 identity_strategy_->SetDeviceManagementCredentials( 245 data_store_->set_user_name(policy_data.username());
240 policy_data.username(), 246 data_store_->set_device_id(policy_data.device_id());
241 policy_data.device_id(), 247 data_store_->SetDeviceToken(policy_data.request_token(), true);
242 policy_data.request_token());
243 SetPolicyInternal(policy, NULL, false); 248 SetPolicyInternal(policy, NULL, false);
244 } else { // In other words, starting_up_ == false. 249 } else { // In other words, starting_up_ == false.
245 if (code != chromeos::SignedSettings::SUCCESS) { 250 if (code != chromeos::SignedSettings::SUCCESS) {
246 if (code == chromeos::SignedSettings::BAD_SIGNATURE) { 251 if (code == chromeos::SignedSettings::BAD_SIGNATURE) {
247 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchBadSignature, 252 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchBadSignature,
248 kMetricPolicySize); 253 kMetricPolicySize);
249 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, 254 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR,
250 CloudPolicySubsystem::SIGNATURE_MISMATCH); 255 CloudPolicySubsystem::SIGNATURE_MISMATCH);
251 } else { 256 } else {
252 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchOtherFailed, 257 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchOtherFailed,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 std::string channel = policy.release_channel().release_channel(); 346 std::string channel = policy.release_channel().release_channel();
342 mandatory->Set( 347 mandatory->Set(
343 kPolicyChromeOsReleaseChannel, Value::CreateStringValue(channel)); 348 kPolicyChromeOsReleaseChannel, Value::CreateStringValue(channel));
344 // TODO: We should probably set the release track somewhere else, but this 349 // TODO: We should probably set the release track somewhere else, but this
345 // policy is a work-in-progress (http://crosbug.com/15382). 350 // policy is a work-in-progress (http://crosbug.com/15382).
346 chromeos::CrosLibrary::Get()->GetUpdateLibrary()->SetReleaseTrack(channel); 351 chromeos::CrosLibrary::Get()->GetUpdateLibrary()->SetReleaseTrack(channel);
347 } 352 }
348 } 353 }
349 354
350 } // namespace policy 355 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/device_policy_cache.h ('k') | chrome/browser/policy/device_policy_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698