| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Wraps PrefService in an InvalidationStateTracker to allow SyncNotifiers | 5 // Wraps PrefService in an InvalidationStateTracker to allow SyncNotifiers |
| 6 // to use PrefService as persistence for invalidation state. It is not thread | 6 // to use PrefService as persistence for invalidation state. It is not thread |
| 7 // safe, and lives on the UI thread. | 7 // safe, and lives on the UI thread. |
| 8 | 8 |
| 9 #ifndef CHROME_BROWSER_SYNC_INVALIDATIONS_INVALIDATOR_STORAGE_H_ | 9 #ifndef CHROME_BROWSER_SYNC_INVALIDATIONS_INVALIDATOR_STORAGE_H_ |
| 10 #define CHROME_BROWSER_SYNC_INVALIDATIONS_INVALIDATOR_STORAGE_H_ | 10 #define CHROME_BROWSER_SYNC_INVALIDATIONS_INVALIDATOR_STORAGE_H_ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace browser_sync { | 25 namespace browser_sync { |
| 26 | 26 |
| 27 // TODO(tim): Bug 124137. We may want to move this outside of sync/ into a | 27 // TODO(tim): Bug 124137. We may want to move this outside of sync/ into a |
| 28 // browser/invalidations directory, or re-organize to have a browser | 28 // browser/invalidations directory, or re-organize to have a browser |
| 29 // subdirectory that contains signin/ sync/ invalidations/ and other cloud | 29 // subdirectory that contains signin/ sync/ invalidations/ and other cloud |
| 30 // services. For now this is still tied to sync while we refactor, so minimize | 30 // services. For now this is still tied to sync while we refactor, so minimize |
| 31 // churn and keep it here. | 31 // churn and keep it here. |
| 32 class InvalidatorStorage : public base::SupportsWeakPtr<InvalidatorStorage>, | 32 class InvalidatorStorage : public base::SupportsWeakPtr<InvalidatorStorage>, |
| 33 public csync::InvalidationStateTracker { | 33 public syncer::InvalidationStateTracker { |
| 34 public: | 34 public: |
| 35 // |pref_service| may be NULL (for unit tests), but in that case no setter | 35 // |pref_service| may be NULL (for unit tests), but in that case no setter |
| 36 // methods should be called. Does not own |pref_service|. | 36 // methods should be called. Does not own |pref_service|. |
| 37 explicit InvalidatorStorage(PrefService* pref_service); | 37 explicit InvalidatorStorage(PrefService* pref_service); |
| 38 virtual ~InvalidatorStorage(); | 38 virtual ~InvalidatorStorage(); |
| 39 | 39 |
| 40 // Erases invalidation versions and state stored on disk. | 40 // Erases invalidation versions and state stored on disk. |
| 41 void Clear(); | 41 void Clear(); |
| 42 | 42 |
| 43 // InvalidationStateTracker implementation. | 43 // InvalidationStateTracker implementation. |
| 44 virtual csync::InvalidationVersionMap GetAllMaxVersions() const | 44 virtual syncer::InvalidationVersionMap GetAllMaxVersions() const |
| 45 OVERRIDE; | 45 OVERRIDE; |
| 46 virtual void SetMaxVersion(const invalidation::ObjectId& id, | 46 virtual void SetMaxVersion(const invalidation::ObjectId& id, |
| 47 int64 max_version) OVERRIDE; | 47 int64 max_version) OVERRIDE; |
| 48 // TODO(tim): These are not yet used. Bug 124140. | 48 // TODO(tim): These are not yet used. Bug 124140. |
| 49 virtual void SetInvalidationState(const std::string& state) OVERRIDE; | 49 virtual void SetInvalidationState(const std::string& state) OVERRIDE; |
| 50 virtual std::string GetInvalidationState() const OVERRIDE; | 50 virtual std::string GetInvalidationState() const OVERRIDE; |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, SerializeEmptyMap); | 53 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, SerializeEmptyMap); |
| 54 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, | 54 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 65 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, | 65 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, |
| 66 DeserializeMapEmptyDictionary); | 66 DeserializeMapEmptyDictionary); |
| 67 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, DeserializeMapBasic); | 67 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, DeserializeMapBasic); |
| 68 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, MigrateLegacyPreferences); | 68 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, MigrateLegacyPreferences); |
| 69 | 69 |
| 70 base::ThreadChecker thread_checker_; | 70 base::ThreadChecker thread_checker_; |
| 71 | 71 |
| 72 // Helpers to convert between InvalidationVersionMap <--> ListValue. | 72 // Helpers to convert between InvalidationVersionMap <--> ListValue. |
| 73 static void DeserializeFromList( | 73 static void DeserializeFromList( |
| 74 const base::ListValue& max_versions_list, | 74 const base::ListValue& max_versions_list, |
| 75 csync::InvalidationVersionMap* max_versions_map); | 75 syncer::InvalidationVersionMap* max_versions_map); |
| 76 static void SerializeToList( | 76 static void SerializeToList( |
| 77 const csync::InvalidationVersionMap& max_versions_map, | 77 const syncer::InvalidationVersionMap& max_versions_map, |
| 78 base::ListValue* max_versions_list); | 78 base::ListValue* max_versions_list); |
| 79 | 79 |
| 80 // Code for migrating from old MaxInvalidationVersions pref, which was a map | 80 // Code for migrating from old MaxInvalidationVersions pref, which was a map |
| 81 // from sync types to max invalidation versions. | 81 // from sync types to max invalidation versions. |
| 82 void MigrateMaxInvalidationVersionsPref(); | 82 void MigrateMaxInvalidationVersionsPref(); |
| 83 static void DeserializeMap(const base::DictionaryValue* max_versions_dict, | 83 static void DeserializeMap(const base::DictionaryValue* max_versions_dict, |
| 84 csync::InvalidationVersionMap* map); | 84 syncer::InvalidationVersionMap* map); |
| 85 | 85 |
| 86 // May be NULL. | 86 // May be NULL. |
| 87 PrefService* const pref_service_; | 87 PrefService* const pref_service_; |
| 88 | 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(InvalidatorStorage); | 89 DISALLOW_COPY_AND_ASSIGN(InvalidatorStorage); |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 } // namespace browser_sync | 92 } // namespace browser_sync |
| 93 | 93 |
| 94 #endif // CHROME_BROWSER_SYNC_INVALIDATIONS_INVALIDATOR_STORAGE_H_ | 94 #endif // CHROME_BROWSER_SYNC_INVALIDATIONS_INVALIDATOR_STORAGE_H_ |
| OLD | NEW |