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

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

Issue 2953483003: Add HostCachePersistenceManager for Cronet (Closed)
Patch Set: address comments Created 3 years, 6 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
(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 "base/timer/timer.h"
16 #include "components/prefs/pref_change_registrar.h"
17 #include "net/dns/host_cache.h"
18
19 class PrefService;
20
21 namespace cronet {
22 // Handles the interaction between HostCache and prefs for persistence.
23 // On write, starts a timer, or ignores if the timer is already running. When
pauljensen 2017/06/23 14:10:31 I'm a little confused by "On write", perhaps "Upon
mgersh 2017/06/23 16:02:06 Done.
24 // that timer expires, writes the current state of the HostCache to prefs.
25 //
26 // Can be used with synchronous or asynchronous prefs loading. Not appropriate
27 // for use outside of Cronet because its network and prefs operations run on
28 // the same sequence. Must be created after and destroyed before the HostCache
29 // and PrefService.
30 class HostCachePersistenceManager : public net::HostCache::PersistenceDelegate {
31 public:
32 // |cache| is the HostCache whose contents will be persisted. It must be
33 // non-null and must outlive the HostCachePersistenceManager.
34 // |pref_service| is the PrefService that will be used to persist the cache
35 // contents. It must outlive the HostCachePersistenceManager.
36 // |pref_name| is the name of the pref to read and write.
37 // |delay| is the maximum time between a change in the cache and writing that
38 // change to prefs.
39 HostCachePersistenceManager(net::HostCache* cache,
40 PrefService* pref_service,
41 std::string pref_name,
42 base::TimeDelta delay);
43 ~HostCachePersistenceManager();
pauljensen 2017/06/23 14:10:31 should be virtual. "If your class has virtual meth
mgersh 2017/06/23 16:02:06 Done.
44
45 // HostCache::PersistenceDelegate implementation
pauljensen 2017/06/23 14:10:31 nit: add "net::"
mgersh 2017/06/23 16:02:06 Done.
46 void ScheduleWrite() override;
47
48 private:
49 // Gets the serialized HostCache and writes it to prefs.
50 void WriteToDisk();
51 // On initial prefs read, passes the serialized entries to the HostCache.
52 void ReadFromDisk();
53
54 net::HostCache* const cache_;
55
56 PrefChangeRegistrar registrar_;
57 PrefService* const pref_service_;
58 const std::string pref_name_;
59 bool writing_pref_;
60
61 const base::TimeDelta delay_;
62 base::OneShotTimer timer_;
63
64 SEQUENCE_CHECKER(sequence_checker_);
65 base::WeakPtrFactory<HostCachePersistenceManager> weak_factory_;
66
67 DISALLOW_COPY_AND_ASSIGN(HostCachePersistenceManager);
68 };
69
70 } // namespace cronet
71
72 #endif // COMPONENTS_CRONET_HOST_CACHE_PERSISTENCE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698