OLD | NEW |
---|---|
(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 prefs. Instances of this class must be constructed on | |
bengr
2016/09/22 23:35:46
network quality prefs -> network quality informati
tbansal1
2016/09/23 17:10:33
Done.
| |
37 // the pref thread, and should later be moved to network thread by calling | |
bengr
2016/09/22 23:35:46
What is the "pref thread?"
to -> to the
tbansal1
2016/09/23 17:10:32
Thread that is used to access the prefs (https://c
| |
38 // InitializeOnNetworkThread. | |
39 // | |
40 // This class interacts with both the pref thread and the network thread, and | |
41 // propagates network quality pref changes from network thread to the provided | |
bengr
2016/09/22 23:35:46
from -> from the
tbansal1
2016/09/23 17:10:32
Done.
| |
42 // pref delegate on the pref thread. | |
43 // | |
44 // ShutdownOnPrefThread must be called from pref thread before destruction. | |
bengr
2016/09/22 23:35:46
from -> from the
tbansal1
2016/09/23 17:10:32
Done.
| |
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 // Create an instance of the NetworkQualitiesPrefsManager. Ownership of | |
bengr
2016/09/22 23:35:46
Create -> Creates
tbansal1
2016/09/23 17:10:33
Done.
| |
56 // |pref_delegate| is taken by this class. Must be constructed on the Pref | |
bengr
2016/09/22 23:35:46
is Pref capitalized? Here and elsewhere.
tbansal1
2016/09/23 17:10:32
Not sure, made it lower case.
| |
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 Network thread. | |
bengr
2016/09/22 23:35:46
on -> on the
tbansal1
2016/09/23 17:10:32
Done.
| |
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 // ----------- | |
71 // Pref thread | |
72 // ----------- | |
bengr
2016/09/22 23:35:47
I would change this comment to simply be:
// Pref
tbansal1
2016/09/23 17:10:33
Done.
| |
73 | |
74 // Called on pref thread when there is a change in the cached network quality. | |
75 void OnChangeInCachedNetworkQualityOnPrefThread( | |
76 const nqe::internal::NetworkID& network_id, | |
77 const nqe::internal::CachedNetworkQuality& cached_network_quality); | |
78 | |
79 // Responsible for writing the persistent prefs to the disk. | |
80 std::unique_ptr<PrefDelegate> pref_delegate_; | |
81 | |
82 scoped_refptr<base::SequencedTaskRunner> pref_task_runner_; | |
83 | |
84 // Should be accessed only on the pref thread. | |
85 base::WeakPtr<NetworkQualitiesPrefsManager> pref_weak_ptr_; | |
86 | |
87 // -------------- | |
88 // Network thread | |
89 // -------------- | |
90 | |
91 // nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver | |
92 // implementation: | |
93 void OnChangeInCachedNetworkQuality( | |
94 const nqe::internal::NetworkID& network_id, | |
95 const nqe::internal::CachedNetworkQuality& cached_network_quality) | |
96 override; | |
97 | |
98 NetworkQualityEstimator* network_quality_estimator_; | |
99 | |
100 scoped_refptr<base::SequencedTaskRunner> network_task_runner_; | |
101 | |
102 // -------------- | |
103 // Common | |
104 // -------------- | |
105 | |
106 // Used to get |weak_ptr_| to self on the pref thread. | |
107 base::WeakPtrFactory<NetworkQualitiesPrefsManager> pref_weak_ptr_factory_; | |
108 | |
109 DISALLOW_COPY_AND_ASSIGN(NetworkQualitiesPrefsManager); | |
110 }; | |
111 | |
112 } // namespace net | |
113 | |
114 #endif // NET_NQE_NETWORK_QUALITIES_PREFS_MANAGER_H_ | |
OLD | NEW |