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