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

Unified Diff: chrome/browser/sync/invalidations/invalidator_storage.h

Issue 10451058: sync: move invalidation version prefs out of SyncPrefs into InvalidatorStorage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 8 years, 7 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
Index: chrome/browser/sync/invalidations/invalidator_storage.h
diff --git a/chrome/browser/sync/invalidations/invalidator_storage.h b/chrome/browser/sync/invalidations/invalidator_storage.h
new file mode 100644
index 0000000000000000000000000000000000000000..ab5ceca0ecc2006a37d3c42cffe489e87467936b
--- /dev/null
+++ b/chrome/browser/sync/invalidations/invalidator_storage.h
@@ -0,0 +1,75 @@
+// Copyright (c) 2012 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.
+//
+// Wraps PrefService in an InvalidationStateTracker to allow SyncNotifiers
+// to use PrefService as persistence for invalidation state. It is not thread
+// safe, and lives on the UI thread.
+
+#ifndef CHROME_BROWSER_SYNC_INVALIDATIONS_INVALIDATOR_STORAGE_H_
+#define CHROME_BROWSER_SYNC_INVALIDATIONS_INVALIDATOR_STORAGE_H_
+
+#include "base/basictypes.h"
+#include "base/gtest_prod_util.h"
+#include "base/memory/weak_ptr.h"
+#include "base/threading/non_thread_safe.h"
+#include "sync/notifier/invalidation_state_tracker.h"
+#include "sync/syncable/model_type.h"
+
+class PrefService;
+
+namespace base {
+ class DictionaryValue;
+}
+
+namespace browser_sync {
+
+// TODO(tim): Bug 124137. We may want to move this outside of sync/ into a
+// browser/invalidations directory, or re-organize to have a browser
+// subdirectory that contains signin/ sync/ invalidations/ and other cloud
+// services. For now this is still tied to sync while we refactor, so minimize
+// churn and keep it here.
+class InvalidatorStorage : public base::SupportsWeakPtr<InvalidatorStorage>,
+ public sync_notifier::InvalidationStateTracker {
+ public:
+ // |pref_service| may be NULL (for unit tests), but in that case no setter
+ // methods should be called. Does not own |pref_service|.
+ explicit InvalidatorStorage(PrefService* pref_service);
+ virtual ~InvalidatorStorage();
+
+ // Erases invalidation versions and state stored on disk.
+ void Clear();
+
+ // InvalidationStateTracker implementation.
+ virtual sync_notifier::InvalidationVersionMap GetAllMaxVersions() const
+ OVERRIDE;
+ virtual void SetMaxVersion(syncable::ModelType model_type,
+ int64 max_version) OVERRIDE;
+ // TODO(tim): These are not yet used. Bug 124140.
+ virtual void SetInvalidationState(const std::string& state) OVERRIDE;
+ virtual std::string GetInvalidationState() const OVERRIDE;
+
+ private:
+ FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, SerializeEmptyMap);
+ FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, DeserializeOutOfRange);
+ FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, DeserializeInvalidFormat);
+ FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, DeserializeEmptyDictionary);
+ FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, DeserializeBasic);
+
+ base::NonThreadSafe non_thread_safe_;
+
+ // Helpers to convert between InvalidationVersionMap <--> DictionaryValue.
+ static void DeserializeMap(const base::DictionaryValue* max_versions_dict,
+ sync_notifier::InvalidationVersionMap* map);
+ static void SerializeMap(const sync_notifier::InvalidationVersionMap& map,
+ base::DictionaryValue* to_dict);
+
+ // May be NULL.
+ PrefService* const pref_service_;
+
+ DISALLOW_COPY_AND_ASSIGN(InvalidatorStorage);
+};
+
+} // namespace browser_sync
+
+#endif // CHROME_BROWSER_SYNC_INVALIDATIONS_INVALIDATOR_STORAGE_H_
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host_unittest.cc ('k') | chrome/browser/sync/invalidations/invalidator_storage.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698