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

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: address comments + tweaks 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/task.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "chrome/browser/chromeos/cros/cros_library.h" 13 #include "chrome/browser/chromeos/cros/cros_library.h"
13 #include "chrome/browser/chromeos/cros/update_library.h" 14 #include "chrome/browser/chromeos/cros/update_library.h"
14 #include "chrome/browser/chromeos/cros_settings_names.h" 15 #include "chrome/browser/chromeos/cros_settings_names.h"
15 #include "chrome/browser/chromeos/login/ownership_service.h" 16 #include "chrome/browser/chromeos/login/ownership_service.h"
16 #include "chrome/browser/chromeos/user_cros_settings_provider.h" 17 #include "chrome/browser/chromeos/user_cros_settings_provider.h"
17 #include "chrome/browser/policy/configuration_policy_pref_store.h" 18 #include "chrome/browser/policy/cloud_policy_data.h"
18 #include "chrome/browser/policy/device_policy_identity_strategy.h"
19 #include "chrome/browser/policy/enterprise_install_attributes.h" 19 #include "chrome/browser/policy/enterprise_install_attributes.h"
20 #include "chrome/browser/policy/policy_map.h" 20 #include "chrome/browser/policy/policy_map.h"
21 #include "chrome/browser/policy/proto/device_management_backend.pb.h" 21 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
22 #include "chrome/browser/policy/proto/device_management_constants.h" 22 #include "chrome/browser/policy/proto/device_management_constants.h"
23 #include "chrome/browser/policy/proto/device_management_local.pb.h" 23 #include "chrome/browser/policy/proto/device_management_local.pb.h"
24 #include "content/browser/browser_thread.h"
25 #include "policy/configuration_policy_type.h" 24 #include "policy/configuration_policy_type.h"
26 25
27 namespace { 26 namespace {
28 27
29 // Stores policy, updates the owner key if required and reports the status 28 // Stores policy, updates the owner key if required and reports the status
30 // through a callback. 29 // through a callback.
31 class StorePolicyOperation : public chromeos::SignedSettingsHelper::Callback, 30 class StorePolicyOperation : public chromeos::SignedSettingsHelper::Callback,
32 public chromeos::OwnerManager::KeyUpdateDelegate { 31 public chromeos::OwnerManager::KeyUpdateDelegate {
33 public: 32 public:
34 typedef Callback1<chromeos::SignedSettings::ReturnCode>::Type Callback; 33 typedef Callback1<chromeos::SignedSettings::ReturnCode>::Type Callback;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 103 }
105 104
106 return Value::CreateIntegerValue(static_cast<int>(value)); 105 return Value::CreateIntegerValue(static_cast<int>(value));
107 } 106 }
108 107
109 } // namespace 108 } // namespace
110 109
111 namespace policy { 110 namespace policy {
112 111
113 DevicePolicyCache::DevicePolicyCache( 112 DevicePolicyCache::DevicePolicyCache(
114 DevicePolicyIdentityStrategy* identity_strategy, 113 CloudPolicyData* data,
115 EnterpriseInstallAttributes* install_attributes) 114 EnterpriseInstallAttributes* install_attributes)
116 : identity_strategy_(identity_strategy), 115 : data_(data),
117 install_attributes_(install_attributes), 116 install_attributes_(install_attributes),
118 signed_settings_helper_(chromeos::SignedSettingsHelper::Get()), 117 signed_settings_helper_(chromeos::SignedSettingsHelper::Get()),
119 starting_up_(true), 118 starting_up_(true),
120 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { 119 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) {
121 } 120 }
122 121
123 DevicePolicyCache::DevicePolicyCache( 122 DevicePolicyCache::DevicePolicyCache(
124 DevicePolicyIdentityStrategy* identity_strategy, 123 CloudPolicyData* data,
125 EnterpriseInstallAttributes* install_attributes, 124 EnterpriseInstallAttributes* install_attributes,
126 chromeos::SignedSettingsHelper* signed_settings_helper) 125 chromeos::SignedSettingsHelper* signed_settings_helper)
127 : identity_strategy_(identity_strategy), 126 : data_(data),
128 install_attributes_(install_attributes), 127 install_attributes_(install_attributes),
129 signed_settings_helper_(signed_settings_helper), 128 signed_settings_helper_(signed_settings_helper),
130 starting_up_(true), 129 starting_up_(true),
131 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { 130 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) {
132 } 131 }
133 132
134 DevicePolicyCache::~DevicePolicyCache() { 133 DevicePolicyCache::~DevicePolicyCache() {
135 signed_settings_helper_->CancelCallback(this); 134 signed_settings_helper_->CancelCallback(this);
136 } 135 }
137 136
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 bool DevicePolicyCache::IsReady() { 184 bool DevicePolicyCache::IsReady() {
186 return initialization_complete() || !starting_up_; 185 return initialization_complete() || !starting_up_;
187 } 186 }
188 187
189 void DevicePolicyCache::OnRetrievePolicyCompleted( 188 void DevicePolicyCache::OnRetrievePolicyCompleted(
190 chromeos::SignedSettings::ReturnCode code, 189 chromeos::SignedSettings::ReturnCode code,
191 const em::PolicyFetchResponse& policy) { 190 const em::PolicyFetchResponse& policy) {
192 DCHECK(CalledOnValidThread()); 191 DCHECK(CalledOnValidThread());
193 if (starting_up_) { 192 if (starting_up_) {
194 starting_up_ = false; 193 starting_up_ = false;
194 // All the code paths should issue a data_->SetDeviceToken(..., true)
195 // to signal that the cache has finished loading, so other components
196 // are free to modify token data.
195 if (code == chromeos::SignedSettings::NOT_FOUND || 197 if (code == chromeos::SignedSettings::NOT_FOUND ||
196 code == chromeos::SignedSettings::KEY_UNAVAILABLE || 198 code == chromeos::SignedSettings::KEY_UNAVAILABLE ||
197 !policy.has_policy_data()) { 199 !policy.has_policy_data()) {
198 InformNotifier(CloudPolicySubsystem::UNENROLLED, 200 InformNotifier(CloudPolicySubsystem::UNENROLLED,
199 CloudPolicySubsystem::NO_DETAILS); 201 CloudPolicySubsystem::NO_DETAILS);
202 data_->SetDeviceToken("", true);
200 return; 203 return;
201 } 204 }
202 em::PolicyData policy_data; 205 em::PolicyData policy_data;
203 if (!policy_data.ParseFromString(policy.policy_data())) { 206 if (!policy_data.ParseFromString(policy.policy_data())) {
204 LOG(WARNING) << "Failed to parse PolicyData protobuf."; 207 LOG(WARNING) << "Failed to parse PolicyData protobuf.";
205 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, 208 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR,
206 CloudPolicySubsystem::POLICY_LOCAL_ERROR); 209 CloudPolicySubsystem::POLICY_LOCAL_ERROR);
210 data_->SetDeviceToken("", true);
207 return; 211 return;
208 } 212 }
209 if (!policy_data.has_request_token() || 213 if (!policy_data.has_request_token() ||
210 policy_data.request_token().empty()) { 214 policy_data.request_token().empty()) {
211 SetUnmanagedInternal(base::Time::NowFromSystemTime()); 215 SetUnmanagedInternal(base::Time::NowFromSystemTime());
212 InformNotifier(CloudPolicySubsystem::UNMANAGED, 216 InformNotifier(CloudPolicySubsystem::UNMANAGED,
213 CloudPolicySubsystem::NO_DETAILS); 217 CloudPolicySubsystem::NO_DETAILS);
214 // TODO(jkummerow): Reminder: When we want to feed device-wide settings 218 // TODO(jkummerow): Reminder: When we want to feed device-wide settings
215 // made by a local owner into this cache, we need to call 219 // made by a local owner into this cache, we need to call
216 // SetPolicyInternal() here. 220 // SetPolicyInternal() here.
221 data_->SetDeviceToken("", true);
217 return; 222 return;
218 } 223 }
219 if (!policy_data.has_username() || !policy_data.has_device_id()) { 224 if (!policy_data.has_username() || !policy_data.has_device_id()) {
220 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, 225 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR,
221 CloudPolicySubsystem::POLICY_LOCAL_ERROR); 226 CloudPolicySubsystem::POLICY_LOCAL_ERROR);
227 data_->SetDeviceToken("", true);
222 return; 228 return;
223 } 229 }
224 identity_strategy_->SetDeviceManagementCredentials( 230 data_->set_user_name(policy_data.username());
225 policy_data.username(), 231 data_->set_device_id(policy_data.device_id());
226 policy_data.device_id(), 232 data_->SetDeviceToken(policy_data.request_token(), true);
227 policy_data.request_token());
228 SetPolicyInternal(policy, NULL, false); 233 SetPolicyInternal(policy, NULL, false);
229 } else { // In other words, starting_up_ == false. 234 } else { // In other words, starting_up_ == false.
230 if (code != chromeos::SignedSettings::SUCCESS) { 235 if (code != chromeos::SignedSettings::SUCCESS) {
231 if (code == chromeos::SignedSettings::BAD_SIGNATURE) { 236 if (code == chromeos::SignedSettings::BAD_SIGNATURE) {
232 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, 237 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR,
233 CloudPolicySubsystem::SIGNATURE_MISMATCH); 238 CloudPolicySubsystem::SIGNATURE_MISMATCH);
234 } else { 239 } else {
235 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, 240 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR,
236 CloudPolicySubsystem::POLICY_LOCAL_ERROR); 241 CloudPolicySubsystem::POLICY_LOCAL_ERROR);
237 } 242 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 std::string channel = policy.release_channel().release_channel(); 315 std::string channel = policy.release_channel().release_channel();
311 mandatory->Set( 316 mandatory->Set(
312 kPolicyChromeOsReleaseChannel, Value::CreateStringValue(channel)); 317 kPolicyChromeOsReleaseChannel, Value::CreateStringValue(channel));
313 // TODO: We should probably set the release track somewhere else, but this 318 // TODO: We should probably set the release track somewhere else, but this
314 // policy is a work-in-progress (http://crosbug.com/15382). 319 // policy is a work-in-progress (http://crosbug.com/15382).
315 chromeos::CrosLibrary::Get()->GetUpdateLibrary()->SetReleaseTrack(channel); 320 chromeos::CrosLibrary::Get()->GetUpdateLibrary()->SetReleaseTrack(channel);
316 } 321 }
317 } 322 }
318 323
319 } // namespace policy 324 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698