| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 // Wraps PrefService in an InvalidationStateTracker to allow SyncNotifiers | |
| 6 // to use PrefService as persistence for invalidation state. It is not thread | |
| 7 // safe, and lives on the UI thread. | |
| 8 | |
| 9 #ifndef CHROME_BROWSER_SYNC_INVALIDATIONS_INVALIDATOR_STORAGE_H_ | |
| 10 #define CHROME_BROWSER_SYNC_INVALIDATIONS_INVALIDATOR_STORAGE_H_ | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/gtest_prod_util.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "base/threading/thread_checker.h" | |
| 16 #include "sync/notifier/invalidation_state_tracker.h" | |
| 17 | |
| 18 class PrefService; | |
| 19 | |
| 20 namespace base { | |
| 21 class DictionaryValue; | |
| 22 class ListValue; | |
| 23 } | |
| 24 | |
| 25 namespace user_prefs { | |
| 26 class PrefRegistrySyncable; | |
| 27 } | |
| 28 | |
| 29 namespace browser_sync { | |
| 30 | |
| 31 // TODO(tim): Bug 124137. We may want to move this outside of sync/ into a | |
| 32 // browser/invalidations directory, or re-organize to have a browser | |
| 33 // subdirectory that contains signin/ sync/ invalidations/ and other cloud | |
| 34 // services. For now this is still tied to sync while we refactor, so minimize | |
| 35 // churn and keep it here. | |
| 36 class InvalidatorStorage : public base::SupportsWeakPtr<InvalidatorStorage>, | |
| 37 public syncer::InvalidationStateTracker { | |
| 38 public: | |
| 39 static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry); | |
| 40 | |
| 41 // |pref_service| may be NULL (for unit tests), but in that case no setter | |
| 42 // methods should be called. Does not own |pref_service|. | |
| 43 explicit InvalidatorStorage(PrefService* pref_service); | |
| 44 virtual ~InvalidatorStorage(); | |
| 45 | |
| 46 // InvalidationStateTracker implementation. | |
| 47 virtual syncer::InvalidationStateMap GetAllInvalidationStates() const | |
| 48 OVERRIDE; | |
| 49 virtual void SetMaxVersionAndPayload(const invalidation::ObjectId& id, | |
| 50 int64 max_version, | |
| 51 const std::string& payload) OVERRIDE; | |
| 52 virtual void Forget(const syncer::ObjectIdSet& ids) OVERRIDE; | |
| 53 virtual void SetInvalidatorClientId(const std::string& client_id) OVERRIDE; | |
| 54 virtual std::string GetInvalidatorClientId() const OVERRIDE; | |
| 55 virtual void SetBootstrapData(const std::string& data) OVERRIDE; | |
| 56 virtual std::string GetBootstrapData() const OVERRIDE; | |
| 57 virtual void Clear() OVERRIDE; | |
| 58 virtual void GenerateAckHandles( | |
| 59 const syncer::ObjectIdSet& ids, | |
| 60 const scoped_refptr<base::TaskRunner>& task_runner, | |
| 61 base::Callback<void(const syncer::AckHandleMap&)> callback) OVERRIDE; | |
| 62 virtual void Acknowledge(const invalidation::ObjectId& id, | |
| 63 const syncer::AckHandle& ack_handle) OVERRIDE; | |
| 64 | |
| 65 private: | |
| 66 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, SerializeEmptyMap); | |
| 67 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, | |
| 68 DeserializeFromListOutOfRange); | |
| 69 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, | |
| 70 DeserializeFromListInvalidFormat); | |
| 71 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, | |
| 72 DeserializeFromListWithDuplicates); | |
| 73 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, | |
| 74 DeserializeFromEmptyList); | |
| 75 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, DeserializeFromListBasic); | |
| 76 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, | |
| 77 DeserializeFromListMissingOptionalValues); | |
| 78 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, DeserializeMapOutOfRange); | |
| 79 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, DeserializeMapInvalidFormat); | |
| 80 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, | |
| 81 DeserializeMapEmptyDictionary); | |
| 82 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, DeserializeMapBasic); | |
| 83 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, MigrateLegacyPreferences); | |
| 84 | |
| 85 base::ThreadChecker thread_checker_; | |
| 86 | |
| 87 // Helpers to convert between InvalidationStateMap <--> ListValue. | |
| 88 static void DeserializeFromList( | |
| 89 const base::ListValue& state_map_list, | |
| 90 syncer::InvalidationStateMap* state_map); | |
| 91 static void SerializeToList( | |
| 92 const syncer::InvalidationStateMap& state_map, | |
| 93 base::ListValue* state_map_list); | |
| 94 | |
| 95 // Code for migrating from old MaxInvalidationVersions pref, which was a map | |
| 96 // from sync types to max invalidation versions. | |
| 97 void MigrateMaxInvalidationVersionsPref(); | |
| 98 static void DeserializeMap(const base::DictionaryValue* max_versions_dict, | |
| 99 syncer::InvalidationStateMap* map); | |
| 100 | |
| 101 // May be NULL. | |
| 102 PrefService* const pref_service_; | |
| 103 | |
| 104 DISALLOW_COPY_AND_ASSIGN(InvalidatorStorage); | |
| 105 }; | |
| 106 | |
| 107 } // namespace browser_sync | |
| 108 | |
| 109 #endif // CHROME_BROWSER_SYNC_INVALIDATIONS_INVALIDATOR_STORAGE_H_ | |
| OLD | NEW |