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

Unified 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, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/signed_settings_cache.cc
diff --git a/chrome/browser/chromeos/login/signed_settings_cache.cc b/chrome/browser/chromeos/login/signed_settings_cache.cc
new file mode 100644
index 0000000000000000000000000000000000000000..175402475488cb889b1f3027ca59aedfc214e9d5
--- /dev/null
+++ b/chrome/browser/chromeos/login/signed_settings_cache.cc
@@ -0,0 +1,99 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/login/signed_settings_cache.h"
+
+#include "base/base64.h"
+#include "base/bind.h"
+#include "base/values.h"
+#include "chrome/browser/chromeos/login/ownership_service.h"
+#include "chrome/browser/chromeos/login/signed_settings_helper.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/prefs/scoped_user_pref_update.h"
+#include "chrome/common/pref_names.h"
+
+using content::BrowserThread;
+
+namespace chromeos {
+
+namespace {
+
+void OnStorePolicyCompleted(SignedSettings::ReturnCode code) {
+ if (code != SignedSettings::SUCCESS)
+ LOG(ERROR) << "Couldn't save temp store to the policy blob. code: " << code;
+}
+
+void FinishFinalize(PrefService* local_state,
+ SignedSettings::ReturnCode code,
+ const em::PolicyFetchResponse& policy) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ if (code != SignedSettings::SUCCESS) {
+ LOG(ERROR) << "Can't finalize temp store error code:" << code;
+ return;
+ }
+
+ if (local_state) {
+ std::string policy_string =
+ local_state->GetString(prefs::kSignedSettingsCache);
+
+ em::PolicyData merging_policy_data;
+ if (!merging_policy_data.ParseFromString(policy_string)) {
+ LOG(WARNING) << "Can't decode policy from string on finalizing.";
+ return;
+ }
+
+ em::PolicyFetchResponse policy_envelope = policy;
+ DCHECK(policy_envelope.has_policy_data());
+ em::PolicyData base_policy_data;
+ base_policy_data.ParseFromString(policy_envelope.policy_data());
+ // Merge only the policy value as we should never ever rewrite the other
+ // fields of the PolicyData protobuf.
+ base_policy_data.set_policy_value(merging_policy_data.policy_value());
+ policy_envelope.set_policy_data(base_policy_data.SerializeAsString());
+ DCHECK(base_policy_data.has_username());
+ policy_envelope.clear_policy_data_signature();
+ SignedSettingsHelper::Get()->StartStorePolicyOp(
+ policy_envelope, base::Bind(&OnStorePolicyCompleted));
+ }
+}
+
+} // namespace
+
+namespace signed_settings_cache {
+
+void RegisterPrefs(PrefService* local_state) {
+ local_state->RegisterStringPref(prefs::kSignedSettingsCache,
+ "invalid",
+ PrefService::UNSYNCABLE_PREF);
+}
+
+bool Store(const em::PolicyData& policy, PrefService* local_state) {
+ if (local_state) {
+ std::string policy_string = policy.SerializeAsString();
+ local_state->SetString(prefs::kSignedSettingsCache, policy_string);
+ return true;
+ }
+ return false;
+}
+
+bool Retrieve(em::PolicyData *policy, PrefService* local_state) {
+ if (local_state) {
+ std::string policy_string =
+ local_state->GetString(prefs::kSignedSettingsCache);
+ return policy->ParseFromString(policy_string);
+ }
+ return false;
+}
+
+void Finalize(PrefService* local_state) {
+ // Reload the initial policy blob, apply settings from temp storage,
+ // and write back the blob.
+ SignedSettingsHelper::Get()->StartRetrievePolicyOp(
+ base::Bind(FinishFinalize, local_state));
+}
+
+} // namespace signed_settings_cache
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698