Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 COMPONENTS_CRONET_HOST_CACHE_PERSISTENCE_MANAGER_H_ | |
| 6 #define COMPONENTS_CRONET_HOST_CACHE_PERSISTENCE_MANAGER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/sequence_checker.h" | |
| 14 #include "base/time/time.h" | |
| 15 #include "net/dns/host_cache.h" | |
| 16 | |
| 17 class PrefChangeRegistrar; | |
| 18 class PrefService; | |
| 19 | |
| 20 namespace base { | |
| 21 class OneShotTimer; | |
| 22 } | |
| 23 | |
| 24 namespace cronet { | |
| 25 // Handles the interaction between HostCache and prefs for persistence. | |
| 26 // On write, starts a timer, or ignores if the timer is already running. When | |
| 27 // that timer expires, writes the current state of the HostCache to prefs. | |
| 28 // | |
| 29 // Can be used with synchronous or asynchronous prefs loading. Not appropriate | |
| 30 // for use outside of Cronet because its network and prefs operations run on | |
| 31 // the same sequence. Must be created after and destroyed before the HostCache | |
| 32 // and PrefService. | |
| 33 class HostCachePersistenceManager : public net::HostCache::PersistenceDelegate { | |
| 34 public: | |
| 35 HostCachePersistenceManager(net::HostCache* cache, | |
|
pauljensen
2017/06/22 19:03:51
Can you add a comment here explaining the argument
mgersh
2017/06/22 21:27:32
Done.
| |
| 36 PrefService* pref_service, | |
| 37 std::string pref_name, | |
| 38 base::TimeDelta delay); | |
| 39 ~HostCachePersistenceManager(); | |
| 40 | |
| 41 // HostCache::PersistenceDelegate implementation | |
| 42 void ScheduleWrite() override; | |
| 43 | |
| 44 private: | |
| 45 // Gets the serialized HostCache and writes it to prefs. | |
| 46 void DoWrite(); | |
| 47 // On initial prefs read, passes the serialized entries to the HostCache. | |
| 48 void OnRead(); | |
| 49 | |
| 50 net::HostCache* cache_; | |
|
pauljensen
2017/06/22 19:03:50
add const, then we can remove all but the construc
mgersh
2017/06/22 21:27:32
Done.
| |
| 51 | |
| 52 std::unique_ptr<PrefChangeRegistrar> registrar_; | |
|
pauljensen
2017/06/22 19:03:51
remove the unique_ptr, so just PrefChangeRegistrar
mgersh
2017/06/22 21:27:32
Done.
| |
| 53 PrefService* pref_service_; | |
|
pauljensen
2017/06/22 19:03:51
add const, then we can remove all but the construc
mgersh
2017/06/22 21:27:32
Done.
| |
| 54 const std::string pref_name_; | |
| 55 bool writing_pref_; | |
| 56 | |
| 57 base::TimeDelta delay_; | |
|
pauljensen
2017/06/22 19:03:50
const
mgersh
2017/06/22 21:27:32
Done.
| |
| 58 std::unique_ptr<base::OneShotTimer> timer_; | |
|
pauljensen
2017/06/22 19:03:50
remove the unique_ptr, so just base::OneShotTimer
mgersh
2017/06/22 21:27:32
Done.
| |
| 59 | |
| 60 SEQUENCE_CHECKER(sequence_checker_); | |
| 61 base::WeakPtrFactory<HostCachePersistenceManager> weak_factory_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(HostCachePersistenceManager); | |
| 64 }; | |
| 65 | |
| 66 } // namespace cronet | |
| 67 | |
| 68 #endif // COMPONENTS_CRONET_HOST_CACHE_PERSISTENCE_MANAGER_H_ | |
| OLD | NEW |