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

Side by Side Diff: net/nqe/network_qualities_prefs_manager.h

Issue 2322183002: Add Network Quality Estimator (NQE) pref manager (Closed)
Patch Set: rebased Created 4 years, 3 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
« no previous file with comments | « net/nqe/network_id.h ('k') | net/nqe/network_qualities_prefs_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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 NET_NQE_NETWORK_QUALITIES_PREFS_MANAGER_H_
6 #define NET_NQE_NETWORK_QUALITIES_PREFS_MANAGER_H_
7
8 #include <memory>
9
10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h"
12 #include "net/base/net_export.h"
13 #include "net/nqe/effective_connection_type.h"
14 #include "net/nqe/network_id.h"
15 #include "net/nqe/network_quality_store.h"
16
17 namespace base {
18 class DictionaryValue;
19 class SequencedTaskRunner;
20 }
21
22 namespace net {
23 namespace nqe {
24 namespace internal {
25 class CachedNetworkQuality;
26 }
27 }
28 class NetworkQualityEstimator;
29
30 typedef base::Callback<void(
31 const nqe::internal::NetworkID& network_id,
32 const nqe::internal::CachedNetworkQuality& cached_network_quality)>
33 OnChangeInCachedNetworkQualityCallback;
34
35 // Using the provided PrefDelegate, NetworkQualitiesPrefsManager creates and
36 // updates network quality information that is stored in prefs. Instances of
37 // this class must be constructed on the pref thread, and should later be moved
38 // to the network thread by calling InitializeOnNetworkThread.
39 //
40 // This class interacts with both the pref thread and the network thread, and
41 // propagates network quality pref changes from the network thread to the
42 // provided pref delegate on the pref thread.
43 //
44 // ShutdownOnPrefThread must be called from the pref thread before destruction.
45 class NET_EXPORT NetworkQualitiesPrefsManager
46 : public nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver {
47 public:
48 // Provides an interface that must be implemented by the embedder.
49 class NET_EXPORT PrefDelegate {
50 public:
51 // Sets the persistent pref to the given value.
52 virtual void SetDictionaryValue(const base::DictionaryValue& value) = 0;
53 };
54
55 // Creates an instance of the NetworkQualitiesPrefsManager. Ownership of
56 // |pref_delegate| is taken by this class. Must be constructed on the pref
57 // thread, and then moved to network thread.
58 explicit NetworkQualitiesPrefsManager(
59 std::unique_ptr<PrefDelegate> pref_delegate);
60 ~NetworkQualitiesPrefsManager() override;
61
62 // Initialize on the Network thread.
63 void InitializeOnNetworkThread(
64 NetworkQualityEstimator* network_quality_estimator);
65
66 // Prepare for shutdown. Must be called on the pref thread before destruction.
67 void ShutdownOnPrefThread();
68
69 private:
70 // Pref thread members:
71 // Called on pref thread when there is a change in the cached network quality.
72 void OnChangeInCachedNetworkQualityOnPrefThread(
73 const nqe::internal::NetworkID& network_id,
74 const nqe::internal::CachedNetworkQuality& cached_network_quality);
75
76 // Responsible for writing the persistent prefs to the disk.
77 std::unique_ptr<PrefDelegate> pref_delegate_;
78
79 scoped_refptr<base::SequencedTaskRunner> pref_task_runner_;
80
81 // Should be accessed only on the pref thread.
82 base::WeakPtr<NetworkQualitiesPrefsManager> pref_weak_ptr_;
83
84 // Network thread members:
85 // nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver
86 // implementation:
87 void OnChangeInCachedNetworkQuality(
88 const nqe::internal::NetworkID& network_id,
89 const nqe::internal::CachedNetworkQuality& cached_network_quality)
90 override;
91
92 NetworkQualityEstimator* network_quality_estimator_;
93
94 scoped_refptr<base::SequencedTaskRunner> network_task_runner_;
95
96 // Used to get |weak_ptr_| to self on the pref thread.
97 base::WeakPtrFactory<NetworkQualitiesPrefsManager> pref_weak_ptr_factory_;
98
99 DISALLOW_COPY_AND_ASSIGN(NetworkQualitiesPrefsManager);
100 };
101
102 } // namespace net
103
104 #endif // NET_NQE_NETWORK_QUALITIES_PREFS_MANAGER_H_
OLDNEW
« no previous file with comments | « net/nqe/network_id.h ('k') | net/nqe/network_qualities_prefs_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698