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

Unified Diff: components/invalidation/invalidator_storage.cc

Issue 1191393008: Introduce a layering in the invalidation component as public and impl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Explicitly forbid content to prevent future additions Created 5 years, 6 months 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
« no previous file with comments | « components/invalidation/invalidator_storage.h ('k') | components/invalidation/invalidator_test_template.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/invalidation/invalidator_storage.cc
diff --git a/components/invalidation/invalidator_storage.cc b/components/invalidation/invalidator_storage.cc
deleted file mode 100644
index cd7ae9ce1a722015e201d4f8e2585f466c6868ba..0000000000000000000000000000000000000000
--- a/components/invalidation/invalidator_storage.cc
+++ /dev/null
@@ -1,139 +0,0 @@
-// Copyright 2014 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 "components/invalidation/invalidator_storage.h"
-
-#include <string>
-#include <utility>
-
-#include "base/base64.h"
-#include "base/basictypes.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/prefs/pref_registry_simple.h"
-#include "base/prefs/pref_service.h"
-#include "base/values.h"
-#include "components/invalidation/invalidation_prefs.h"
-#include "components/invalidation/unacked_invalidation_set.h"
-#include "components/pref_registry/pref_registry_syncable.h"
-#include "google/cacheinvalidation/types.pb.h"
-
-namespace {
-
-const char kInvalidatorMaxInvalidationVersions[] =
- "invalidator.max_invalidation_versions";
-
-bool ValueToUnackedInvalidationStorageMap(
- const base::ListValue& value,
- syncer::UnackedInvalidationsMap* map) {
- for (size_t i = 0; i != value.GetSize(); ++i) {
- invalidation::ObjectId invalid_id;
- syncer::UnackedInvalidationSet storage(invalid_id);
- const base::DictionaryValue* dict;
- if (!value.GetDictionary(i, &dict) || !storage.ResetFromValue(*dict)) {
- DLOG(WARNING) << "Failed to parse ObjectState at position " << i;
- return false;
- }
- map->insert(std::make_pair(storage.object_id(), storage));
- }
- return true;
-}
-
-scoped_ptr<base::ListValue> UnackedInvalidationStorageMapToValue(
- const syncer::UnackedInvalidationsMap& map) {
- scoped_ptr<base::ListValue> value(new base::ListValue);
- for (syncer::UnackedInvalidationsMap::const_iterator it = map.begin();
- it != map.end(); ++it) {
- value->Append(it->second.ToValue().release());
- }
- return value.Pass();
-}
-
-} // namespace
-
-namespace invalidation {
-
-// static
-void InvalidatorStorage::RegisterProfilePrefs(
- user_prefs::PrefRegistrySyncable* registry) {
- registry->RegisterListPref(prefs::kInvalidatorSavedInvalidations);
- registry->RegisterStringPref(prefs::kInvalidatorInvalidationState,
- std::string());
- registry->RegisterStringPref(prefs::kInvalidatorClientId, std::string());
-
- // This pref is obsolete. We register it so we can clear it.
- // At some point in the future, it will be safe to remove this.
- registry->RegisterListPref(kInvalidatorMaxInvalidationVersions);
-}
-
-// static
-void InvalidatorStorage::RegisterPrefs(PrefRegistrySimple* registry) {
- registry->RegisterListPref(prefs::kInvalidatorSavedInvalidations);
- registry->RegisterStringPref(prefs::kInvalidatorInvalidationState,
- std::string());
- registry->RegisterStringPref(prefs::kInvalidatorClientId, std::string());
-}
-
-InvalidatorStorage::InvalidatorStorage(PrefService* pref_service)
- : pref_service_(pref_service) {
- DCHECK(pref_service_);
- if (pref_service_->FindPreference(kInvalidatorMaxInvalidationVersions))
- pref_service_->ClearPref(kInvalidatorMaxInvalidationVersions);
-}
-
-InvalidatorStorage::~InvalidatorStorage() {
-}
-
-void InvalidatorStorage::ClearAndSetNewClientId(const std::string& client_id) {
- DCHECK(thread_checker_.CalledOnValidThread());
- Clear(); // We can't reuse our old invalidation state if the ID changes.
- pref_service_->SetString(prefs::kInvalidatorClientId, client_id);
-}
-
-std::string InvalidatorStorage::GetInvalidatorClientId() const {
- return pref_service_->GetString(prefs::kInvalidatorClientId);
-}
-
-void InvalidatorStorage::SetBootstrapData(const std::string& data) {
- DCHECK(thread_checker_.CalledOnValidThread());
- std::string base64_data;
- base::Base64Encode(data, &base64_data);
- pref_service_->SetString(prefs::kInvalidatorInvalidationState,
- base64_data);
-}
-
-std::string InvalidatorStorage::GetBootstrapData() const {
- std::string base64_data(
- pref_service_->GetString(prefs::kInvalidatorInvalidationState));
- std::string data;
- base::Base64Decode(base64_data, &data);
- return data;
-}
-
-void InvalidatorStorage::SetSavedInvalidations(
- const syncer::UnackedInvalidationsMap& map) {
- scoped_ptr<base::ListValue> value(UnackedInvalidationStorageMapToValue(map));
- pref_service_->Set(prefs::kInvalidatorSavedInvalidations, *value.get());
-}
-
-syncer::UnackedInvalidationsMap
-InvalidatorStorage::GetSavedInvalidations() const {
- syncer::UnackedInvalidationsMap map;
- const base::ListValue* value =
- pref_service_->GetList(prefs::kInvalidatorSavedInvalidations);
- if (!ValueToUnackedInvalidationStorageMap(*value, &map)) {
- return syncer::UnackedInvalidationsMap();
- } else {
- return map;
- }
-}
-
-void InvalidatorStorage::Clear() {
- DCHECK(thread_checker_.CalledOnValidThread());
- pref_service_->ClearPref(prefs::kInvalidatorSavedInvalidations);
- pref_service_->ClearPref(prefs::kInvalidatorClientId);
- pref_service_->ClearPref(prefs::kInvalidatorInvalidationState);
-}
-
-} // namespace invalidation
« no previous file with comments | « components/invalidation/invalidator_storage.h ('k') | components/invalidation/invalidator_test_template.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698