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

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: Next round of comments. All bots meanwhile good and manual testing seems fine as well. 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 void FinishFinalize(PrefService* local_state,
28 SignedSettings::ReturnCode code,
29 const em::PolicyFetchResponse& policy) {
30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
31
32 if (code != SignedSettings::SUCCESS) {
33 LOG(ERROR) << "Can't finalize temp store error code:" << code;
34 return;
35 }
36
37 if (local_state) {
38 std::string policy_string =
39 local_state->GetString(prefs::kSignedSettingsCache);
40
41 em::PolicyData merging_policy_data;
42 if (!merging_policy_data.ParseFromString(policy_string)) {
43 LOG(WARNING) << "Can't decode policy from string on finalizing.";
44 return;
45 }
46
47 em::PolicyFetchResponse policy_envelope = policy;
48 DCHECK(policy_envelope.has_policy_data());
49 em::PolicyData base_policy_data;
50 base_policy_data.ParseFromString(policy_envelope.policy_data());
51 // Merge only the policy value as we should never ever rewrite the other
52 // fields of the PolicyData protobuf.
53 base_policy_data.set_policy_value(merging_policy_data.policy_value());
54 policy_envelope.set_policy_data(base_policy_data.SerializeAsString());
55 DCHECK(base_policy_data.has_username());
56 policy_envelope.clear_policy_data_signature();
57 SignedSettingsHelper::Get()->StartStorePolicyOp(
58 policy_envelope, base::Bind(&OnStorePolicyCompleted));
59 }
60 }
61
62 } // namespace
63
64 namespace signed_settings_cache {
65
66 void RegisterPrefs(PrefService* local_state) {
67 local_state->RegisterStringPref(prefs::kSignedSettingsCache,
68 "invalid",
69 PrefService::UNSYNCABLE_PREF);
70 }
71
72 bool Store(const em::PolicyData& policy, PrefService* local_state) {
73 if (local_state) {
74 std::string policy_string = policy.SerializeAsString();
75 local_state->SetString(prefs::kSignedSettingsCache, policy_string);
76 return true;
77 }
78 return false;
79 }
80
81 bool Retrieve(em::PolicyData *policy, PrefService* local_state) {
82 if (local_state) {
83 std::string policy_string =
84 local_state->GetString(prefs::kSignedSettingsCache);
85 return policy->ParseFromString(policy_string);
86 }
87 return false;
88 }
89
90 void Finalize(PrefService* local_state) {
91 // Reload the initial policy blob, apply settings from temp storage,
92 // and write back the blob.
93 SignedSettingsHelper::Get()->StartRetrievePolicyOp(
94 base::Bind(FinishFinalize, local_state));
95 }
96
97 } // namespace signed_settings_cache
98
99 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698