Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: components/cronet/host_cache_persistence_manager.h

Issue 2958023002: Add histograms and NetLog for host cache persistence (Closed)
Patch Set: use scoped timer Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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 #ifndef COMPONENTS_CRONET_HOST_CACHE_PERSISTENCE_MANAGER_H_ 5 #ifndef COMPONENTS_CRONET_HOST_CACHE_PERSISTENCE_MANAGER_H_
6 #define COMPONENTS_CRONET_HOST_CACHE_PERSISTENCE_MANAGER_H_ 6 #define COMPONENTS_CRONET_HOST_CACHE_PERSISTENCE_MANAGER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/sequence_checker.h" 13 #include "base/sequence_checker.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "base/timer/timer.h" 15 #include "base/timer/timer.h"
16 #include "components/prefs/pref_change_registrar.h" 16 #include "components/prefs/pref_change_registrar.h"
17 #include "net/dns/host_cache.h" 17 #include "net/dns/host_cache.h"
18 #include "net/log/net_log_with_source.h"
18 19
19 class PrefService; 20 class PrefService;
20 21
22 namespace net {
23 class NetLog;
24 }
25
21 namespace cronet { 26 namespace cronet {
22 // Handles the interaction between HostCache and prefs for persistence. 27 // Handles the interaction between HostCache and prefs for persistence.
23 // When notified of a change in the HostCache, starts a timer, or ignores if the 28 // When notified of a change in the HostCache, starts a timer, or ignores if the
24 // timer is already running. When that timer expires, writes the current state 29 // timer is already running. When that timer expires, writes the current state
25 // of the HostCache to prefs. 30 // of the HostCache to prefs.
26 // 31 //
27 // Can be used with synchronous or asynchronous prefs loading. Not appropriate 32 // Can be used with synchronous or asynchronous prefs loading. Not appropriate
28 // for use outside of Cronet because its network and prefs operations run on 33 // for use outside of Cronet because its network and prefs operations run on
29 // the same sequence. Must be created after and destroyed before the HostCache 34 // the same sequence. Must be created after and destroyed before the HostCache
30 // and PrefService. 35 // and PrefService.
31 class HostCachePersistenceManager : public net::HostCache::PersistenceDelegate { 36 class HostCachePersistenceManager : public net::HostCache::PersistenceDelegate {
32 public: 37 public:
33 // |cache| is the HostCache whose contents will be persisted. It must be 38 // |cache| is the HostCache whose contents will be persisted. It must be
34 // non-null and must outlive the HostCachePersistenceManager. 39 // non-null and must outlive the HostCachePersistenceManager.
35 // |pref_service| is the PrefService that will be used to persist the cache 40 // |pref_service| is the PrefService that will be used to persist the cache
36 // contents. It must outlive the HostCachePersistenceManager. 41 // contents. It must outlive the HostCachePersistenceManager.
37 // |pref_name| is the name of the pref to read and write. 42 // |pref_name| is the name of the pref to read and write.
38 // |delay| is the maximum time between a change in the cache and writing that 43 // |delay| is the maximum time between a change in the cache and writing that
39 // change to prefs. 44 // change to prefs.
40 HostCachePersistenceManager(net::HostCache* cache, 45 HostCachePersistenceManager(net::HostCache* cache,
41 PrefService* pref_service, 46 PrefService* pref_service,
42 std::string pref_name, 47 std::string pref_name,
43 base::TimeDelta delay); 48 base::TimeDelta delay,
49 net::NetLog* net_log);
44 virtual ~HostCachePersistenceManager(); 50 virtual ~HostCachePersistenceManager();
45 51
46 // net::HostCache::PersistenceDelegate implementation 52 // net::HostCache::PersistenceDelegate implementation
47 void ScheduleWrite() override; 53 void ScheduleWrite() override;
48 54
49 private: 55 private:
50 // Gets the serialized HostCache and writes it to prefs. 56 // Gets the serialized HostCache and writes it to prefs.
51 void WriteToDisk(); 57 void WriteToDisk();
52 // On initial prefs read, passes the serialized entries to the HostCache. 58 // On initial prefs read, passes the serialized entries to the HostCache.
53 void ReadFromDisk(); 59 void ReadFromDisk();
54 60
55 net::HostCache* const cache_; 61 net::HostCache* const cache_;
56 62
57 PrefChangeRegistrar registrar_; 63 PrefChangeRegistrar registrar_;
58 PrefService* const pref_service_; 64 PrefService* const pref_service_;
59 const std::string pref_name_; 65 const std::string pref_name_;
60 bool writing_pref_; 66 bool writing_pref_;
61 67
62 const base::TimeDelta delay_; 68 const base::TimeDelta delay_;
63 base::OneShotTimer timer_; 69 base::OneShotTimer timer_;
64 70
71 const net::NetLogWithSource net_log_;
72
65 SEQUENCE_CHECKER(sequence_checker_); 73 SEQUENCE_CHECKER(sequence_checker_);
66 base::WeakPtrFactory<HostCachePersistenceManager> weak_factory_; 74 base::WeakPtrFactory<HostCachePersistenceManager> weak_factory_;
67 75
68 DISALLOW_COPY_AND_ASSIGN(HostCachePersistenceManager); 76 DISALLOW_COPY_AND_ASSIGN(HostCachePersistenceManager);
69 }; 77 };
70 78
71 } // namespace cronet 79 } // namespace cronet
72 80
73 #endif // COMPONENTS_CRONET_HOST_CACHE_PERSISTENCE_MANAGER_H_ 81 #endif // COMPONENTS_CRONET_HOST_CACHE_PERSISTENCE_MANAGER_H_
OLDNEW
« no previous file with comments | « components/cronet/android/cronet_url_request_context_adapter.cc ('k') | components/cronet/host_cache_persistence_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698