| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/chromeos/settings/device_settings_cache.h" | 5 #include "chrome/browser/chromeos/settings/device_settings_cache.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 namespace device_settings_cache { | 21 namespace device_settings_cache { |
| 22 | 22 |
| 23 void RegisterPrefs(PrefRegistrySimple* registry) { | 23 void RegisterPrefs(PrefRegistrySimple* registry) { |
| 24 registry->RegisterStringPref(prefs::kDeviceSettingsCache, "invalid"); | 24 registry->RegisterStringPref(prefs::kDeviceSettingsCache, "invalid"); |
| 25 } | 25 } |
| 26 | 26 |
| 27 bool Store(const em::PolicyData& policy, PrefService* local_state) { | 27 bool Store(const em::PolicyData& policy, PrefService* local_state) { |
| 28 if (local_state) { | 28 if (local_state) { |
| 29 std::string policy_string = policy.SerializeAsString(); | 29 std::string policy_string = policy.SerializeAsString(); |
| 30 std::string encoded; | 30 std::string encoded; |
| 31 base::Base64Encode(policy_string, &encoded); | 31 if (!base::Base64Encode(policy_string, &encoded)) { |
| 32 LOG(ERROR) << "Can't encode policy in base64."; |
| 33 return false; |
| 34 } |
| 32 local_state->SetString(prefs::kDeviceSettingsCache, encoded); | 35 local_state->SetString(prefs::kDeviceSettingsCache, encoded); |
| 33 return true; | 36 return true; |
| 34 } | 37 } |
| 35 return false; | 38 return false; |
| 36 } | 39 } |
| 37 | 40 |
| 38 bool Retrieve(em::PolicyData *policy, PrefService* local_state) { | 41 bool Retrieve(em::PolicyData *policy, PrefService* local_state) { |
| 39 if (local_state) { | 42 if (local_state) { |
| 40 std::string encoded = | 43 std::string encoded = |
| 41 local_state->GetString(prefs::kDeviceSettingsCache); | 44 local_state->GetString(prefs::kDeviceSettingsCache); |
| 42 std::string policy_string; | 45 std::string policy_string; |
| 43 if (!base::Base64Decode(encoded, &policy_string)) { | 46 if (!base::Base64Decode(encoded, &policy_string)) { |
| 44 // This is normal and happens on first boot. | 47 // This is normal and happens on first boot. |
| 45 VLOG(1) << "Can't decode policy from base64."; | 48 VLOG(1) << "Can't decode policy from base64."; |
| 46 return false; | 49 return false; |
| 47 } | 50 } |
| 48 return policy->ParseFromString(policy_string); | 51 return policy->ParseFromString(policy_string); |
| 49 } | 52 } |
| 50 return false; | 53 return false; |
| 51 } | 54 } |
| 52 | 55 |
| 53 } // namespace device_settings_cache | 56 } // namespace device_settings_cache |
| 54 | 57 |
| 55 } // namespace chromeos | 58 } // namespace chromeos |
| OLD | NEW |