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

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

Issue 2322183002: Add Network Quality Estimator (NQE) pref manager (Closed)
Patch Set: rebased, addressed kundaji and ryansturm comments 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
Not at Google. Contact bengr 2016/09/15 21:13:16 How about starting with: // Propagates network qua
tbansal1 2016/09/15 21:32:30 Your comment made me think what exactly class comm
Not at Google. Contact bengr 2016/09/15 22:46:57 It seems to me my suggestion sticks to these exact
RyanSturm 2016/09/16 16:23:41 Sounds like you guys are arguing about what the co
Not at Google. Contact bengr 2016/09/16 17:01:28 My comment suggestion was mainly for any engineer
tbansal1 2016/09/16 18:05:26 I added the suggested comment, although I added it
36 // updates network quality prefs. Instances of this class must be constructed on
37 // the pref thread.
38 //
39 // This class interacts with the pref thread, where it reads/writes to the pref
40 // using the provided PrefDelegate. This class also interacts with the network
41 // thread on which it interacts with the network quality estimator.
42 //
43 // ShutdownOnPrefThread must be called from pref thread before destruction.
44 class NET_EXPORT NetworkQualitiesPrefsManager
45 : public nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver {
46 public:
47 // Provides an interface that must be implemented by the embedder.
48 class NET_EXPORT PrefDelegate {
49 public:
50 // Sets the persistent pref to the given value.
51 virtual void SetDictionaryValue(const base::DictionaryValue& value) = 0;
52 };
53
54 // Create an instance of the NetworkQualitiesPrefsManager. Ownership of
55 // |pref_delegate| is taken by this class. Must be constructed on the Pref
56 // thread, and then moved to network thread.
57 explicit NetworkQualitiesPrefsManager(
58 std::unique_ptr<PrefDelegate> pref_delegate);
59 ~NetworkQualitiesPrefsManager() override;
60
61 // Initialize on Network thread.
62 void InitializeOnNetworkThread(
63 NetworkQualityEstimator* network_quality_estimator);
64
65 // Prepare for shutdown. Must be called on the Pref thread before destruction.
66 void ShutdownOnPrefThread();
67
68 private:
69 // -----------
70 // Pref thread
71 // -----------
72
73 // Called on pref thread when there is a change in the cached network quality.
74 void OnChangeInCachedNetworkQualityOnPrefThread(
75 const nqe::internal::NetworkID& network_id,
76 const nqe::internal::CachedNetworkQuality& cached_network_quality);
77
78 // Responsible for writing the persistent prefs to the disk.
79 std::unique_ptr<PrefDelegate> pref_delegate_;
80
81 scoped_refptr<base::SequencedTaskRunner> pref_task_runner_;
82
83 // Should be accessed only on the pref thread.
84 base::WeakPtr<NetworkQualitiesPrefsManager> pref_weak_ptr_;
85
86 // --------------
87 // Network thread
88 // --------------
89
90 // nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver
91 // implementation:
92 void OnChangeInCachedNetworkQuality(
93 const nqe::internal::NetworkID& network_id,
94 const nqe::internal::CachedNetworkQuality& cached_network_quality)
95 override;
96
97 NetworkQualityEstimator* network_quality_estimator_;
98
99 scoped_refptr<base::SequencedTaskRunner> network_task_runner_;
100
101 // --------------
102 // Common
103 // --------------
104
105 // Used to get |weak_ptr_| to self on the pref thread.
106 base::WeakPtrFactory<NetworkQualitiesPrefsManager> pref_weak_ptr_factory_;
107
108 DISALLOW_COPY_AND_ASSIGN(NetworkQualitiesPrefsManager);
109 };
110
111 } // namespace net
112
113 #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