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_INVALIDATION_INVALIDATOR_STORAGE_H_ 10 #define CHROME_BROWSER_INVALIDATION_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 #include "sync/notifier/unacked_invalidation_set.h" 18 19 class PrefService; 20 21 namespace base { 22 class DictionaryValue; 23 class ListValue; 24 } 25 26 namespace user_prefs { 27 class PrefRegistrySyncable; 28 } 29 30 namespace invalidation { 31 32 class InvalidatorStorage : public base::SupportsWeakPtr<InvalidatorStorage>, 33 public syncer::InvalidationStateTracker { 34 public: 35 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 36 37 // |pref_service| may not be NULL. Does not own |pref_service|. 38 explicit InvalidatorStorage(PrefService* pref_service); 39 virtual ~InvalidatorStorage(); 40 41 // InvalidationStateTracker implementation. 42 virtual void SetInvalidatorClientId(const std::string& client_id) OVERRIDE; 43 virtual std::string GetInvalidatorClientId() const OVERRIDE; 44 virtual void SetBootstrapData(const std::string& data) OVERRIDE; 45 virtual std::string GetBootstrapData() const OVERRIDE; 46 virtual void SetSavedInvalidations( 47 const syncer::UnackedInvalidationsMap& map) OVERRIDE; 48 virtual syncer::UnackedInvalidationsMap GetSavedInvalidations() 49 const OVERRIDE; 50 virtual void Clear() OVERRIDE; 51 52 private: 53 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, SerializeEmptyMap); 54 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, 55 DeserializeFromListOutOfRange); 56 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, 57 DeserializeFromListInvalidFormat); 58 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, 59 DeserializeFromListWithDuplicates); 60 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, 61 DeserializeFromEmptyList); 62 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, DeserializeFromListBasic); 63 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, 64 DeserializeFromListMissingOptionalValues); 65 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, DeserializeMapOutOfRange); 66 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, DeserializeMapInvalidFormat); 67 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, 68 DeserializeMapEmptyDictionary); 69 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, DeserializeMapBasic); 70 FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, MigrateLegacyPreferences); 71 72 base::ThreadChecker thread_checker_; 73 74 PrefService* const pref_service_; 75 76 DISALLOW_COPY_AND_ASSIGN(InvalidatorStorage); 77 }; 78 79 } // namespace invalidation 80 81 #endif // CHROME_BROWSER_INVALIDATION_INVALIDATOR_STORAGE_H_ 82