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

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

Issue 2322183002: Add Network Quality Estimator (NQE) pref manager (Closed)
Patch Set: PS 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
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
16 namespace base {
17 class DictionaryValue;
18 class SequencedTaskRunner;
19 }
20
21 namespace net {
22 namespace nqe {
RyanSturm 2016/09/12 20:26:55 What's the rationale behind nqe being a namespace
tbansal1 2016/09/15 21:00:59 Anything that can be called outside from //net sho
RyanSturm 2016/09/16 16:23:41 Acknowledged.
23 namespace internal {
24 class CachedNetworkQuality;
25 }
26 }
27 class NetworkQualityEstimator;
28
29 typedef base::Callback<void(
30 const nqe::internal::NetworkID& network_id,
31 const nqe::internal::CachedNetworkQuality& cached_network_quality)>
32 OnChangeInCachedNetworkQualityCallback;
33
34 // The manager for creating and updating network quality prefs.
35 //
36 // This class interacts with both the pref thread, where the pref is
37 // read or written, and the network thread, which owns it, and it
38 // persists the network quality changes.
39 //
40 // It must be constructed on the pref thread, to set up |pref_task_runner_| and
41 // the prefs listeners.
42 //
43 // ShutdownOnPrefThread must be called from pref thread before destruction.
44 class NET_EXPORT NetworkQualitiesPrefsManager {
Not at Google. Contact bengr 2016/09/09 20:30:40 Does this class need to be prefs specific? Could t
tbansal1 2016/09/15 21:00:59 I have rewritten the class comment to make it clea
45 public:
46 // Provides an interface that must be implemented by the embedder.
47 class NET_EXPORT PrefDelegate {
48 public:
49 // Sets the persistent pref to the given value.
50 virtual void SetDictionaryValue(const base::DictionaryValue& value) = 0;
51 };
52
53 // Create an instance of the NetworkQualitiesPrefsManager. Ownership of
54 // |pref_delegate| is taken by this class. Must be constructed on the Pref
55 // thread, and then moved to network thread.
56 explicit NetworkQualitiesPrefsManager(
57 std::unique_ptr<PrefDelegate> pref_delegate);
58 virtual ~NetworkQualitiesPrefsManager();
59
60 // Initialize on Network thread.
61 void InitializeOnNetworkThread(
62 NetworkQualityEstimator* network_quality_estimator);
63
64 // Prepare for shutdown. Must be called on the Pref thread before destruction.
65 void ShutdownOnPrefThread();
66
67 private:
68 // -----------
69 // Pref thread
70 // -----------
71
72 // Called on pref thread when there is a change in the cached network quality.
73 void OnChangeInCachedNetworkQualityOnPrefThread(
74 const nqe::internal::NetworkID& network_id,
75 const nqe::internal::CachedNetworkQuality& cached_network_quality);
76
77 // Responsible for writing the persistent prefs to the disk.
78 std::unique_ptr<PrefDelegate> pref_delegate_;
79
80 scoped_refptr<base::SequencedTaskRunner> pref_task_runner_;
81
82 // Should be accessed only on the pref thread.
83 base::WeakPtr<NetworkQualitiesPrefsManager> pref_weak_ptr_;
84
85 // --------------
86 // Network thread
87 // --------------
88
89 // Responsible for receiving notifications about changes in the network
90 // quality from the network quality estimator.
91 class CacheObserver;
92 std::unique_ptr<CacheObserver> cache_observer_;
93
94 scoped_refptr<base::SequencedTaskRunner> network_task_runner_;
95
96 // --------------
97 // Common
98 // --------------
99
100 // Used to get |weak_ptr_| to self on the pref thread.
101 std::unique_ptr<base::WeakPtrFactory<NetworkQualitiesPrefsManager>>
RyanSturm 2016/09/12 20:26:55 Do these weak factories need to be std::unique_ptr
tbansal1 2016/09/15 21:00:59 Done.
102 pref_weak_ptr_factory_;
103
104 // Used to get |weak_ptr_| to self on the network thread.
105 std::unique_ptr<base::WeakPtrFactory<NetworkQualitiesPrefsManager>>
106 network_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

Powered by Google App Engine
This is Rietveld 408576698