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

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

Powered by Google App Engine
This is Rietveld 408576698