1 // Copyright 2017 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 #ifndef CHROMEOS_COMPONENTS_TETHER_PERSISTENT_HOST_SCAN_CACHE_IMPL_H_ 6 #define CHROMEOS_COMPONENTS_TETHER_PERSISTENT_HOST_SCAN_CACHE_IMPL_H_ 7 8 #include <string> 9 #include <unordered_map> 10 #include <unordered_set> 11 12 #include "base/macros.h" 13 #include "base/values.h" 14 #include "chromeos/components/tether/persistent_host_scan_cache.h" 15 16 class PrefRegistrySimple; 17 class PrefService; 18 19 namespace chromeos { 20 21 namespace tether { 22 23 // HostScanCache implementation which stores scan results in persistent user 24 // prefs. 25 class PersistentHostScanCacheImpl : public PersistentHostScanCache { 26 public: 27 // Registers the prefs used by this class to the given |registry|. 28 static void RegisterPrefs(PrefRegistrySimple* registry); 29 30 PersistentHostScanCacheImpl(PrefService* pref_service); 31 ~PersistentHostScanCacheImpl() override; 32 33 // HostScanCache: 34 void SetHostScanResult(const HostScanCacheEntry& entry) override; 35 bool ExistsInCache(const std::string& tether_network_guid) override; 36 std::unordered_set<std::string> GetTetherGuidsInCache() override; 37 bool DoesHostRequireSetup(const std::string& tether_network_guid) override; 38 39 // PersistentHostScanCache: 40 std::unordered_map<std::string, HostScanCacheEntry> GetStoredCacheEntries() 41 override; 42 43 protected: 44 bool RemoveHostScanResultImpl( 45 const std::string& tether_network_guid) override; 46 47 private: 48 void StoreCacheEntriesToPrefs( 49 const std::unordered_map<std::string, HostScanCacheEntry>& entries); 50 51 PrefService* pref_service_; 52 53 DISALLOW_COPY_AND_ASSIGN(PersistentHostScanCacheImpl); 54 }; 55 56 } // namespace tether 57 58 } // namespace chromeos 59 60 #endif // CHROMEOS_COMPONENTS_TETHER_PERSISTENT_HOST_SCAN_CACHE_IMPL_H_ 61