Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / chromeos / settings / device_settings_cache.cc
blob0942994fccd331e1ffe359b59352c9d2539bc7a0
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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/settings/device_settings_cache.h"
7 #include <string>
9 #include "base/base64.h"
10 #include "base/bind.h"
11 #include "base/prefs/pref_registry_simple.h"
12 #include "base/prefs/pref_service.h"
13 #include "chrome/browser/chromeos/settings/cros_settings.h"
14 #include "chrome/common/pref_names.h"
15 #include "policy/proto/device_management_backend.pb.h"
17 namespace em = enterprise_management;
19 namespace chromeos {
21 namespace device_settings_cache {
23 void RegisterPrefs(PrefRegistrySimple* registry) {
24 registry->RegisterStringPref(prefs::kDeviceSettingsCache, "invalid");
27 bool Store(const em::PolicyData& policy, PrefService* local_state) {
28 if (local_state) {
29 std::string policy_string = policy.SerializeAsString();
30 std::string encoded;
31 base::Base64Encode(policy_string, &encoded);
32 local_state->SetString(prefs::kDeviceSettingsCache, encoded);
33 return true;
35 return false;
38 bool Retrieve(em::PolicyData *policy, PrefService* local_state) {
39 if (local_state) {
40 std::string encoded =
41 local_state->GetString(prefs::kDeviceSettingsCache);
42 std::string policy_string;
43 if (!base::Base64Decode(encoded, &policy_string)) {
44 // This is normal and happens on first boot.
45 VLOG(1) << "Can't decode policy from base64.";
46 return false;
48 return policy->ParseFromString(policy_string);
50 return false;
53 } // namespace device_settings_cache
55 } // namespace chromeos