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

Side by Side Diff: chrome/browser/chromeos/device_settings_provider.cc

Issue 8727037: Signed settings refactoring: Proper caching and more tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased to ToT and removed some debug output left. Created 9 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/device_settings_provider.h"
6
7 #include "base/base64.h"
8 #include "base/bind.h"
9 #include "base/bind_helpers.h"
10 #include "base/callback.h"
11 #include "base/hash_tables.h"
12 #include "base/logging.h"
13 #include "base/memory/singleton.h"
14 #include "base/string_util.h"
15 #include "base/values.h"
16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chromeos/cros/cros_library.h"
18 #include "chrome/browser/chromeos/cros/network_library.h"
19 #include "chrome/browser/chromeos/cros_settings.h"
20 #include "chrome/browser/chromeos/cros_settings_names.h"
21 #include "chrome/browser/chromeos/login/ownership_service.h"
22 #include "chrome/browser/chromeos/login/ownership_status_checker.h"
23 #include "chrome/browser/chromeos/login/signed_settings_cache.h"
24 #include "chrome/browser/chromeos/login/user_manager.h"
25 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h"
26 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
27 #include "chrome/browser/prefs/pref_service.h"
28 #include "chrome/browser/prefs/pref_value_map.h"
29 #include "chrome/browser/prefs/scoped_user_pref_update.h"
30 #include "chrome/browser/ui/options/options_util.h"
31 #include "chrome/common/chrome_notification_types.h"
32 #include "chrome/installer/util/google_update_settings.h"
33 #include "content/public/browser/browser_thread.h"
34 #include "content/public/browser/notification_service.h"
35
36 using content::BrowserThread;
37 using google::protobuf::RepeatedPtrField;
38
39 namespace chromeos {
40
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 remove extra blank line.
pastarmovj 2011/11/30 17:21:16 Done.
41
42 namespace {
43
44 // For all our boolean settings following is applicable:
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 missing "the"
pastarmovj 2011/11/30 17:21:16 Done.
45 // true is default permissive value and false is safe prohibitive value.
46 // Exception: kSignedDataRoamingEnabled which has default value of false.
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 This comment is interesting, but doesn't seem to b
pastarmovj 2011/11/30 17:21:16 Moved to UpdateValuesCache. The place we apply def
47 const char* kBooleanSettings[] = {
48 kAccountsPrefAllowNewUser,
49 kAccountsPrefAllowGuest,
50 kAccountsPrefShowUserNamesOnSignIn,
51 kSignedDataRoamingEnabled,
52 kStatsReportingPref
53 };
54
55 const char* kStringSettings[] = {
56 kDeviceOwner,
57 kReleaseChannel,
58 kSettingProxyEverywhere
59 };
60
61 const char* kListSettings[] = {
62 kAccountsPrefUsers
63 };
64
65 // upper bound for number of retries to fetch a signed setting.
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 Upper-case upper :)
pastarmovj 2011/11/30 17:21:16 Done.
66 static const int kNumRetriesLimit = 9;
67
68 bool IsControlledBooleanSetting(const std::string& pref_path) {
69 return std::find(kBooleanSettings,
70 kBooleanSettings + arraysize(kBooleanSettings),
71 pref_path) !=
72 kBooleanSettings + arraysize(kBooleanSettings);
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 how about const char* end = kBooleanSettings + arr
pastarmovj 2011/11/30 17:21:16 Done.
73 }
74
75 bool IsControlledStringSetting(const std::string& pref_path) {
76 return std::find(kStringSettings,
77 kStringSettings + arraysize(kStringSettings),
78 pref_path) !=
79 kStringSettings + arraysize(kStringSettings);
80 }
81
82 bool IsControlledListSetting(const std::string& pref_path) {
83 return std::find(kListSettings,
84 kListSettings + arraysize(kListSettings),
85 pref_path) !=
86 kListSettings + arraysize(kListSettings);
87 }
88
89 bool IsControlledSetting(const std::string& pref_path) {
90 return (IsControlledBooleanSetting(pref_path) ||
91 IsControlledStringSetting(pref_path) ||
92 IsControlledListSetting(pref_path));
93 }
94
95 bool HasOldMetricsFile() {
96 // TODO(pastarmovj): Remove this once migration is not needed anymore.
97 // If the value is not set we should try to migrate legacy consent file.
98 // Loading consent file state causes us to do blocking IO on UI thread.
99 // Temporarily allow it until we fix http://crbug.com/62626
100 base::ThreadRestrictions::ScopedAllowIO allow_io;
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 Any chance we can clean this up? Read the file asy
pastarmovj 2011/11/30 17:21:16 I changed a bit DeviceSettingsProvider::ApplyMetri
101 return GoogleUpdateSettings::GetCollectStatsConsent();
102 }
103
104 } // namespace
105
106 // ###########################################################################
107 // ###########################################################################
108 // ###########################################################################
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 what's this?
pastarmovj 2011/11/30 17:21:16 A bar made of hashes ... i think :S ... removed :)
109
110 DeviceSettingsProvider::DeviceSettingsProvider()
111 : ownership_service_(OwnershipService::GetSharedInstance()),
112 migration_helper_(new SignedSettingsMigrationHelper()),
113 retries_left_(kNumRetriesLimit),
114 trusted_(false) {
115 // Register for notification when user logs in, so that we can activate the
116 // new proxy config.
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 Proxy config? Observe() doesn't appear to do proxy
pastarmovj 2011/11/30 17:21:16 Nope the comment was wrong. Fixed now.
117 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED,
118 content::NotificationService::AllSources());
119 // Make sure we have at least the cache data immediately.
120 RetrieveCachedData();
121 // Start prefetching preferences.
122 Reload();
123 }
124
125 void DeviceSettingsProvider::Reload() {
126 // While fetching we can't trust the cache anymore.
127 trusted_ = false;
128 OwnershipService::Status ownership_status =
129 ownership_service_->GetStatus(true);
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 All the GetStatus calls you have here are potentia
pastarmovj 2011/11/30 17:21:16 All are potentially blocking but only one at most
130 if (ownership_status == OwnershipService::OWNERSHIP_NONE) {
131 RetrieveCachedData();
132 } else {
133 // Retrieve the real data.
134 SignedSettingsHelper::Get()->StartRetrievePolicyOp(
135 base::Bind(&DeviceSettingsProvider::OnRetrievePolicyCompleted,
136 base::Unretained(this)));
137 }
138 }
139
140 void DeviceSettingsProvider::DoSet(const std::string& path,
141 const base::Value& in_value) {
142 OwnershipService::Status ownership_status =
143 ownership_service_->GetStatus(true);
144 if (!UserManager::Get()->current_user_is_owner() &&
145 ownership_status != OwnershipService::OWNERSHIP_NONE) {
146 LOG(WARNING) << "Changing settings from non-owner, setting=" << path;
147
148 // Revert UI change.
149 CrosSettings::Get()->FireObservers(path.c_str());
150 return;
151 }
152
153 if (IsControlledSetting(path))
154 SetInPolicy(path, in_value);
155 else
156 NOTREACHED() << "Try to set unhandled cros setting " << path;
157 }
158
159 void DeviceSettingsProvider::Observe(
160 int type,
161 const content::NotificationSource& source,
162 const content::NotificationDetails& details) {
163 if (type == chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED &&
164 UserManager::Get()->current_user_is_owner()) {
165 // Store data from the temp storage to the signed settings store but first
166 // we have to load the initially generated blob in the cache.
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 s/in/into/. Also, the comment is backwards. Maybe
pastarmovj 2011/11/30 17:21:16 Done.
167 SignedSettingsHelper::Get()->StartRetrievePolicyOp(
168 base::Bind(&DeviceSettingsProvider::FinalizeTempStorage,
169 base::Unretained(this)));
170 }
171 }
172
173 void DeviceSettingsProvider::FinalizeTempStorage(
174 SignedSettings::ReturnCode code,
175 const em::PolicyFetchResponse& policy) {
176 if (code != SignedSettings::SUCCESS) {
177 LOG(ERROR) << "Can't finalize temp store error code:" << code;
178 return;
179 }
180
181 policy_.ParseFromString(policy.policy_data());
182 trusted_ = true;
183 SignedSettingsCache::Finalize(g_browser_process->local_state(), policy);
184 Reload();
185 }
186
187 const em::PolicyData DeviceSettingsProvider::get_policy() const {
188 return policy_;
189 }
190
191 void DeviceSettingsProvider::RetrieveCachedData() {
192 // No owner yet use the temp storage.
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 Make a proper sentence? "If there is no owner yet,
pastarmovj 2011/11/30 17:21:16 Done.
193 em::PolicyData policy;
194 if (!SignedSettingsCache::Retrieve(&policy,
195 g_browser_process->local_state())) {
196 LOG(WARNING) << "Can't retrieve temp store possibly not created yet";
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 Missing period, full sentence? Also, if this is a
pastarmovj 2011/11/30 17:21:16 Done.
197 // prepare empty data for the case we don't have temp cache yet.
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 s/prepare/Prepare/
pastarmovj 2011/11/30 17:21:16 Done.
198 policy.set_policy_type(kDevicePolicyType);
199 em::ChromeDeviceSettingsProto pol;
200 policy.set_policy_value(pol.SerializeAsString());
201 }
202
203 policy_ = policy;
204 }
205
206 void DeviceSettingsProvider::SetInPolicy(const std::string& prop,
207 const base::Value& value) {
208 if (prop == kDeviceOwner) {
209 // Just store it in the memory cache no trusted checks no persisting.
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 Full sentence? Also, I don't quite understand why
pastarmovj 2011/11/30 17:21:16 I made this branch set the trusted flag to false b
210 std::string owner;
211 if (value.GetAsString(&owner))
212 policy_.set_username(owner);
213 else
214 NOTREACHED();
215 return;
216 }
217
218 if (!RequestTrustedEntity()) {
219 // Otherwise we should first reload and apply on top of that.
220 SignedSettingsHelper::Get()->StartRetrievePolicyOp(
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 Isn't this redundant? I mean, if RequestTrustedEnt
pastarmovj 2011/11/30 17:21:16 Not necessarily. It might be a failed read so retr
221 base::Bind(&DeviceSettingsProvider::FinishSetInPolicy,
222 base::Unretained(this),
223 prop, base::Owned(value.DeepCopy())));
224 return;
225 }
226
227 trusted_ = false;
228 em::PolicyData data = get_policy();
229 em::ChromeDeviceSettingsProto pol;
230 pol.ParseFromString(data.policy_value());
231 if (prop == kAccountsPrefAllowNewUser) {
232 em::AllowNewUsersProto* allow = pol.mutable_allow_new_users();
233 bool allow_value;
234 if (value.GetAsBoolean(&allow_value))
235 allow->set_allow_new_users(allow_value);
236 else
237 NOTREACHED();
238 } else if (prop == kAccountsPrefAllowGuest) {
239 em::GuestModeEnabledProto* guest = pol.mutable_guest_mode_enabled();
240 bool guest_value;
241 if (value.GetAsBoolean(&guest_value))
242 guest->set_guest_mode_enabled(guest_value);
243 else
244 NOTREACHED();
245 } else if (prop == kAccountsPrefShowUserNamesOnSignIn) {
246 em::ShowUserNamesOnSigninProto* show = pol.mutable_show_user_names();
247 bool show_value;
248 if (value.GetAsBoolean(&show_value))
249 show->set_show_user_names(show_value);
250 else
251 NOTREACHED();
252 } else if (prop == kSignedDataRoamingEnabled) {
253 em::DataRoamingEnabledProto* roam = pol.mutable_data_roaming_enabled();
254 bool roaming_value = false;
255 if (value.GetAsBoolean(&roaming_value))
256 roam->set_data_roaming_enabled(roaming_value);
257 else
258 NOTREACHED();
259 ApplyRoamingSetting(roaming_value);
260 } else if (prop == kSettingProxyEverywhere) {
261 // TODO(cmasone): NOTIMPLEMENTED() once http://crosbug.com/13052 is fixed.
262 std::string proxy_value;
263 if (value.GetAsString(&proxy_value)) {
264 bool success =
265 pol.mutable_device_proxy_settings()->ParseFromString(proxy_value);
266 DCHECK(success);
267 } else {
268 NOTREACHED();
269 }
270 } else if (prop == kReleaseChannel) {
271 em::ReleaseChannelProto* release_channel = pol.mutable_release_channel();
272 std::string channel_value;
273 if (value.GetAsString(&channel_value))
274 release_channel->set_release_channel(channel_value);
275 else
276 NOTREACHED();
277 } else if (prop == kStatsReportingPref) {
278 em::MetricsEnabledProto* metrics = pol.mutable_metrics_enabled();
279 bool metrics_value = false;
280 if (value.GetAsBoolean(&metrics_value))
281 metrics->set_metrics_enabled(metrics_value);
282 else
283 NOTREACHED();
284 ApplyMetricsSetting(false, metrics_value);
285 } else if (prop == kAccountsPrefUsers) {
286 em::UserWhitelistProto* whitelist_proto = pol.mutable_user_whitelist();
287 whitelist_proto->clear_user_whitelist();
288 const base::ListValue& users = static_cast<const base::ListValue&>(value);
289 for (base::ListValue::const_iterator i = users.begin();
290 i != users.end(); ++i) {
291 std::string email;
292 if ((*i)->GetAsString(&email))
293 whitelist_proto->add_user_whitelist(email.c_str());
294 }
295 } else {
296 NOTREACHED();
297 }
298 data.set_policy_value(pol.SerializeAsString());
299 // Set the cache to the updated value.
300 policy_ = data;
301
302 if (!SignedSettingsCache::Store(data, g_browser_process->local_state()))
303 LOG(ERROR) << "Couldn't store to the temp storage.";
304
305 OwnershipService::Status ownership_status =
306 ownership_service_->GetStatus(true);
307 if (ownership_status == OwnershipService::OWNERSHIP_TAKEN) {
308 em::PolicyFetchResponse policy_envelope;
309 policy_envelope.set_policy_data(policy_.SerializeAsString());
310 SignedSettingsHelper::Get()->StartStorePolicyOp(
311 policy_envelope, base::Bind(
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 I think an additional line break after , would hel
pastarmovj 2011/11/30 17:21:16 Done.
312 &DeviceSettingsProvider::OnStorePolicyCompleted,
313 base::Unretained(this)));
314 }
315 }
316
317 void DeviceSettingsProvider::FinishSetInPolicy(
318 const std::string& prop,
319 const base::Value* value,
320 SignedSettings::ReturnCode code,
321 const em::PolicyFetchResponse& policy) {
322 if (code != SignedSettings::SUCCESS) {
323 LOG(ERROR) << "Can't serialize to policy error code: " << code;
324 Reload();
325 return;
326 }
327 SetInPolicy(prop, *value);
328 }
329
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 remove extra blank line.
pastarmovj 2011/11/30 17:21:16 Done.
330
331 base::Value* DeviceSettingsProvider::LookUpInPolicy(
332 const std::string& prop) const {
333 const em::PolicyData data = get_policy();
334 if (prop == kDeviceOwner) {
335 if (data.has_username() && !data.has_request_token())
336 return base::Value::CreateStringValue(data.username());
337 }
338 VLOG(2) << "Looking up " << prop;
339 em::ChromeDeviceSettingsProto pol;
340 pol.ParseFromString(data.policy_value());
341 if (prop == kAccountsPrefAllowNewUser) {
342 if (pol.has_allow_new_users() &&
343 pol.allow_new_users().has_allow_new_users() &&
344 pol.allow_new_users().allow_new_users()) {
345 // New users allowed, user_whitelist() ignored.
346 return base::Value::CreateBooleanValue(true);
347 }
348 // If we have the allow_new_users bool, and it is true, we honor that above.
349 // In all other cases (don't have it, have it and it is set to false, etc),
350 // We will honor the user_whitelist() if it is there and populated.
351 // Otherwise we default to allowing new users.
352 if (!pol.has_user_whitelist())
353 return base::Value::CreateBooleanValue(true);
354 return base::Value::CreateBooleanValue(
355 pol.user_whitelist().user_whitelist_size() == 0);
356
357 } else if (prop == kAccountsPrefAllowGuest) {
358 if (!pol.has_guest_mode_enabled() ||
359 !pol.guest_mode_enabled().has_guest_mode_enabled()) {
360 // Default to allowing guests;
361 return base::Value::CreateBooleanValue(true);
362 }
363 return base::Value::CreateBooleanValue(
364 pol.guest_mode_enabled().guest_mode_enabled());
365
366 } else if (prop == kAccountsPrefShowUserNamesOnSignIn) {
367 if (!pol.has_show_user_names() ||
368 !pol.show_user_names().has_show_user_names()) {
369 // Default to showing pods on the login screen;
370 return base::Value::CreateBooleanValue(true);
371 }
372 return base::Value::CreateBooleanValue(
373 pol.show_user_names().show_user_names());
374
375 } else if (prop == kSignedDataRoamingEnabled) {
376 if (!pol.has_data_roaming_enabled() ||
377 !pol.data_roaming_enabled().has_data_roaming_enabled()) {
378 // Default to disabling cellular data roaming;
379 return base::Value::CreateBooleanValue(false);
380 }
381 return base::Value::CreateBooleanValue(
382 pol.data_roaming_enabled().data_roaming_enabled());
383
384 } else if (prop == kSettingProxyEverywhere) {
385 // TODO(cmasone): NOTIMPLEMENTED() once http://crosbug.com/13052 is fixed.
386 std::string serialized;
387 if (pol.has_device_proxy_settings() &&
388 pol.device_proxy_settings().SerializeToString(&serialized)) {
389 return base::Value::CreateStringValue(serialized);
390 }
391
392 } else if (prop == kReleaseChannel) {
393 if (!pol.has_release_channel() ||
394 !pol.release_channel().has_release_channel()) {
395 // Default to an invalid channel (will be ignored).
396 return base::Value::CreateStringValue("");
397 }
398 return base::Value::CreateStringValue(
399 pol.release_channel().release_channel());
400
401 } else if (prop == kStatsReportingPref) {
402 if (pol.has_metrics_enabled()) {
403 return base::Value::CreateBooleanValue(
404 pol.metrics_enabled().metrics_enabled());
405 } else {
406 return base::Value::CreateBooleanValue(HasOldMetricsFile());
407 }
408 } else if (prop == kAccountsPrefUsers) {
409 base::ListValue* list = new base::ListValue();
410 const em::UserWhitelistProto& whitelist_proto = pol.user_whitelist();
411 const RepeatedPtrField<std::string>& whitelist =
412 whitelist_proto.user_whitelist();
413 for (RepeatedPtrField<std::string>::const_iterator it = whitelist.begin();
414 it != whitelist.end(); ++it) {
415 list->Append(base::Value::CreateStringValue(*it));
416 }
417 return list;
418 }
419 return NULL;
420 }
421
422 void DeviceSettingsProvider::ApplyMetricsSetting(bool use_file,
423 bool new_value) const {
424 // TODO(pastarmovj): Remove this once migration is not needed anymore.
425 // If the value is not set we should try to migrate legacy consent file.
426 bool stats_consent = HasOldMetricsFile();
427 if (use_file) {
428 new_value = stats_consent;
429 // Make sure the values will get eventually written to the policy file.
430 migration_helper_->AddMigrationValue(
431 kStatsReportingPref, base::Value::CreateBooleanValue(new_value));
432 migration_helper_->MigrateValues();
433 LOG(WARNING) << "No metrics policy set will revert to checking "
434 << "consent file which is "
435 << (new_value ? "on." : "off.");
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 We always print this when you initially claim a de
pastarmovj 2011/11/30 17:21:16 Made INFO out of it.
436 }
437 VLOG(1) << "Metrics policy is being set to : " << stats_consent
438 << "(use file : " << use_file << ")";
439 // TODO(pastarmovj): Remove this once we don't need to regenerate the
440 // consent file for the GUID anymore.
441 OptionsUtil::ResolveMetricsReportingEnabled(new_value);
442 }
443
444 void DeviceSettingsProvider::ApplyRoamingSetting(bool new_value) const {
445 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
446 const NetworkDevice* cellular = cros->FindCellularDevice();
447 if (cellular) {
448 bool device_value = cellular->data_roaming_allowed();
449 if (!device_value && cros->IsCellularAlwaysInRoaming()) {
450 // If operator requires roaming always enabled, ignore supplied value
451 // and set data roaming allowed in true always.
452 cros->SetCellularDataRoamingAllowed(true);
453 } else if (device_value != new_value) {
454 cros->SetCellularDataRoamingAllowed(new_value);
455 }
456 }
457 }
458
459 void DeviceSettingsProvider::ApplySideEffects() const {
460 const em::PolicyData data = get_policy();
461 em::ChromeDeviceSettingsProto pol;
462 pol.ParseFromString(data.policy_value());
463 // First migrate metrics settings as needed.
464 if (pol.has_metrics_enabled())
465 ApplyMetricsSetting(false, pol.metrics_enabled().metrics_enabled());
466 else
467 ApplyMetricsSetting(true, false);
468 // Next set the roaming setting as needed.
469 ApplyRoamingSetting(pol.has_data_roaming_enabled() ?
470 pol.data_roaming_enabled().data_roaming_enabled() : false);
471 }
472
473 base::Value* DeviceSettingsProvider::Get(const std::string& path) const {
474 if (IsControlledSetting(path))
475 return LookUpInPolicy(path);
476 else
477 NOTREACHED() << "Trying to get non cros setting.";
478 return NULL;
479 }
480
481 bool DeviceSettingsProvider::GetTrusted(const std::string& path,
482 const base::Closure& callback) {
483 if (!IsControlledSetting(path)) {
484 NOTREACHED();
485 return true;
486 }
487
488 if (RequestTrustedEntity()) {
489 return true;
490 } else {
491 if (!callback.is_null())
492 callbacks_.push_back(callback);
493 return false;
494 }
495 }
496
497 bool DeviceSettingsProvider::HandlesSetting(const std::string& path) const {
498 return IsControlledSetting(path);
499 }
500
501 bool DeviceSettingsProvider::RequestTrustedEntity() {
502 OwnershipService::Status ownership_status =
503 ownership_service_->GetStatus(true);
504 if (ownership_status == OwnershipService::OWNERSHIP_NONE)
505 return true;
506 return trusted_;
507 }
508
509 void DeviceSettingsProvider::OnStorePolicyCompleted(
510 SignedSettings::ReturnCode code) {
511 // In any case reload the policy cache to now.
512 if (code != SignedSettings::SUCCESS)
513 Reload();
514 else
515 trusted_ = true;
516 }
517
518 void DeviceSettingsProvider::OnRetrievePolicyCompleted(
519 SignedSettings::ReturnCode code,
520 const em::PolicyFetchResponse& policy) {
521 switch (code) {
522 case SignedSettings::SUCCESS: {
523 DCHECK(policy.has_policy_data());
524 policy_.ParseFromString(policy.policy_data());
525 SignedSettingsCache::Store(get_policy(),
526 g_browser_process->local_state());
527 trusted_ = true;
528 for (size_t i = 0; i < callbacks_.size(); ++i)
529 MessageLoop::current()->PostTask(FROM_HERE, callbacks_[i]);
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 any reason to go through the message loop? Can't w
pastarmovj 2011/11/30 17:21:16 I guess not. This was legacy code using tasks.
530 callbacks_.clear();
531 // TODO(pastarmovj): Make those side effects responsibility of the
532 // respective subsystems.
533 ApplySideEffects();
534 break;
535 }
536 case SignedSettings::NOT_FOUND:
537 case SignedSettings::KEY_UNAVAILABLE: {
538 if (ownership_service_->GetStatus(true) !=
539 OwnershipService::OWNERSHIP_TAKEN) {
540 NOTREACHED() << "No policies present yet will use the temp storage.";
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 comma after yet
pastarmovj 2011/11/30 17:21:16 Done.
541 }
542 break;
543 }
544 case SignedSettings::BAD_SIGNATURE:
545 case SignedSettings::OPERATION_FAILED: {
546 LOG(ERROR) << "Failed to retrieve cros policies. Reason:" << code;
547 if (retries_left_ > 0) {
548 retries_left_ -= 1;
549 Reload();
550 return;
551 }
552 LOG(ERROR) << "No retries left";
553 break;
554 }
555 }
556 }
557
558 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698