Index: components/cronet/host_cache_persistence_manager.h |
diff --git a/components/cronet/host_cache_persistence_manager.h b/components/cronet/host_cache_persistence_manager.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..76a64894c49d4155ca8ecf2d6795c586062aefc6 |
--- /dev/null |
+++ b/components/cronet/host_cache_persistence_manager.h |
@@ -0,0 +1,68 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_CRONET_HOST_CACHE_PERSISTENCE_MANAGER_H_ |
+#define COMPONENTS_CRONET_HOST_CACHE_PERSISTENCE_MANAGER_H_ |
+ |
+#include <memory> |
+#include <string> |
+ |
+#include "base/macros.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/sequence_checker.h" |
+#include "base/time/time.h" |
+#include "net/dns/host_cache.h" |
+ |
+class PrefChangeRegistrar; |
+class PrefService; |
+ |
+namespace base { |
+class OneShotTimer; |
+} |
+ |
+namespace cronet { |
+// Handles the interaction between HostCache and prefs for persistence. |
+// On write, starts a timer, or ignores if the timer is already running. When |
+// that timer expires, writes the current state of the HostCache to prefs. |
+// |
+// Can be used with synchronous or asynchronous prefs loading. Not appropriate |
+// for use outside of Cronet because its network and prefs operations run on |
+// the same sequence. Must be created after and destroyed before the HostCache |
+// and PrefService. |
+class HostCachePersistenceManager : public net::HostCache::PersistenceDelegate { |
+ public: |
+ 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.
|
+ PrefService* pref_service, |
+ std::string pref_name, |
+ base::TimeDelta delay); |
+ ~HostCachePersistenceManager(); |
+ |
+ // HostCache::PersistenceDelegate implementation |
+ void ScheduleWrite() override; |
+ |
+ private: |
+ // Gets the serialized HostCache and writes it to prefs. |
+ void DoWrite(); |
+ // On initial prefs read, passes the serialized entries to the HostCache. |
+ void OnRead(); |
+ |
+ 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.
|
+ |
+ 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.
|
+ 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.
|
+ const std::string pref_name_; |
+ bool writing_pref_; |
+ |
+ base::TimeDelta delay_; |
pauljensen
2017/06/22 19:03:50
const
mgersh
2017/06/22 21:27:32
Done.
|
+ 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.
|
+ |
+ SEQUENCE_CHECKER(sequence_checker_); |
+ base::WeakPtrFactory<HostCachePersistenceManager> weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(HostCachePersistenceManager); |
+}; |
+ |
+} // namespace cronet |
+ |
+#endif // COMPONENTS_CRONET_HOST_CACHE_PERSISTENCE_MANAGER_H_ |