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

Side by Side Diff: chrome/browser/chromeos/login/signed_settings_cache.cc

Issue 8727037: Signed settings refactoring: Proper caching and more tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. 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/login/signed_settings_cache.h"
6
7 #include "base/base64.h"
8 #include "base/bind.h"
9 #include "base/values.h"
10 #include "chrome/browser/chromeos/login/ownership_service.h"
11 #include "chrome/browser/chromeos/login/signed_settings_helper.h"
12 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/prefs/scoped_user_pref_update.h"
14 #include "chrome/common/pref_names.h"
15
16 using content::BrowserThread;
17
18 namespace chromeos {
19
20 namespace {
21
22 void OnStorePolicyCompleted(SignedSettings::ReturnCode code) {
23 if (code != SignedSettings::SUCCESS)
24 LOG(ERROR) << "Couldn't save temp store to the policy blob. code: " << code;
25 }
26
27 } // namespace
28
29 namespace signed_settings_cache {
30
31 void RegisterPrefs(PrefService* local_state) {
32 local_state->RegisterStringPref(prefs::kSignedSettingsCache,
33 "invalid",
34 PrefService::UNSYNCABLE_PREF);
35 }
36
37 bool Store(const em::PolicyData& policy, PrefService* local_state) {
38 if (local_state) {
39 std::string policy_string = policy.SerializeAsString();
40 local_state->SetString(prefs::kSignedSettingsCache, policy_string);
41 return true;
42 }
43 return false;
44 }
45
46 bool Retrieve(em::PolicyData *policy, PrefService* local_state) {
47 if (local_state) {
48 std::string policy_string =
49 local_state->GetString(prefs::kSignedSettingsCache);
50 return policy->ParseFromString(policy_string);
51 }
52 return false;
53 }
54
55 void Finalize(PrefService* local_state, const em::PolicyFetchResponse& policy) {
56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
57 if (local_state) {
58 std::string policy_string =
59 local_state->GetString(prefs::kSignedSettingsCache);
60
61 em::PolicyData merging_policy_data;
62 if (!merging_policy_data.ParseFromString(policy_string)) {
63 LOG(WARNING) << "Can't decode policy from string on finalizing.";
64 return;
65 }
66
67 em::PolicyFetchResponse policy_envelope = policy;
68 DCHECK(policy_envelope.has_policy_data());
69 em::PolicyData base_policy_data;
70 base_policy_data.ParseFromString(policy_envelope.policy_data());
71 // Merge only the policy value as we should never ever rewrite the other
72 // fields of the PolicyData protobuf.
73 base_policy_data.set_policy_value(merging_policy_data.policy_value());
74 policy_envelope.set_policy_data(base_policy_data.SerializeAsString());
75 DCHECK(base_policy_data.has_username());
76 policy_envelope.clear_policy_data_signature();
77 SignedSettingsHelper::Get()->StartStorePolicyOp(
78 policy_envelope, base::Bind(&OnStorePolicyCompleted));
79 }
80 }
81
82 } // namespace signed_settings_cache
83
84 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698