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

Side by Side Diff: chrome/browser/net/nqe/ui_network_quality_estimator_service.h

Issue 2450433003: Adding observer functionality to UINetworkQualityService (Closed)
Patch Set: testing Created 4 years, 1 month 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 | « no previous file | chrome/browser/net/nqe/ui_network_quality_estimator_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_ 5 #ifndef CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_
6 #define CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_ 6 #define CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
13 #include "components/keyed_service/core/keyed_service.h" 14 #include "components/keyed_service/core/keyed_service.h"
14 #include "net/nqe/cached_network_quality.h" 15 #include "net/nqe/cached_network_quality.h"
15 #include "net/nqe/effective_connection_type.h" 16 #include "net/nqe/effective_connection_type.h"
16 #include "net/nqe/network_id.h" 17 #include "net/nqe/network_id.h"
17 #include "net/nqe/network_quality_estimator.h" 18 #include "net/nqe/network_quality_estimator.h"
18 19
19 class PrefRegistrySimple; 20 class PrefRegistrySimple;
20 class Profile; 21 class Profile;
21 22
22 namespace net { 23 namespace net {
23 class NetworkQualitiesPrefsManager; 24 class NetworkQualitiesPrefsManager;
24 } 25 }
25 26
26 // UI service to determine the current EffectiveConnectionType. 27 // UI service to determine the current EffectiveConnectionType.
27 class UINetworkQualityEstimatorService 28 class UINetworkQualityEstimatorService
28 : public KeyedService, 29 : public KeyedService,
29 public net::NetworkQualityEstimator::NetworkQualityProvider { 30 public net::NetworkQualityEstimator::NetworkQualityProvider {
30 public: 31 public:
31 explicit UINetworkQualityEstimatorService(Profile* profile); 32 explicit UINetworkQualityEstimatorService(Profile* profile);
32 ~UINetworkQualityEstimatorService() override; 33 ~UINetworkQualityEstimatorService() override;
33 34
35 // NetworkQualityProvider implmentation:
tbansal1 2016/10/25 17:34:18 "implmentation" typo
RyanSturm 2016/10/25 17:40:32 Done.
36 net::EffectiveConnectionType GetEffectiveConnectionType() const override;
37 void AddEffectiveConnectionTypeObserver(
tbansal1 2016/10/25 17:34:18 You might want to say that this must be called on
RyanSturm 2016/10/25 17:40:32 Done.
38 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer)
39 override;
40 void RemoveEffectiveConnectionTypeObserver(
41 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer)
42 override;
43
34 // Registers the profile-specific network quality estimator prefs. 44 // Registers the profile-specific network quality estimator prefs.
35 static void RegisterProfilePrefs(PrefRegistrySimple* registry); 45 static void RegisterProfilePrefs(PrefRegistrySimple* registry);
36 46
37 // The current EffectiveConnectionType.
38 net::EffectiveConnectionType GetEffectiveConnectionType() const override;
39
40 // Tests can manually set EffectiveConnectionType, but browser tests should 47 // Tests can manually set EffectiveConnectionType, but browser tests should
41 // expect that the EffectiveConnectionType could change. 48 // expect that the EffectiveConnectionType could change.
42 void SetEffectiveConnectionTypeForTesting(net::EffectiveConnectionType type); 49 void SetEffectiveConnectionTypeForTesting(net::EffectiveConnectionType type);
43 50
44 // Reads the prefs from the disk, parses them into a map of NetworkIDs and 51 // Reads the prefs from the disk, parses them into a map of NetworkIDs and
45 // CachedNetworkQualities, and returns the map. 52 // CachedNetworkQualities, and returns the map.
46 std::map<net::nqe::internal::NetworkID, 53 std::map<net::nqe::internal::NetworkID,
47 net::nqe::internal::CachedNetworkQuality> 54 net::nqe::internal::CachedNetworkQuality>
48 ForceReadPrefsForTesting() const; 55 ForceReadPrefsForTesting() const;
49 56
50 private: 57 private:
51 class IONetworkQualityObserver; 58 class IONetworkQualityObserver;
52 59
53 // KeyedService implementation: 60 // KeyedService implementation:
54 void Shutdown() override; 61 void Shutdown() override;
55 62
56 // Called when the EffectiveConnectionType has updated to |type|. 63 // Called when the EffectiveConnectionType has updated to |type|.
57 // NetworkQualityEstimator::EffectiveConnectionType is an estimate of the 64 // NetworkQualityEstimator::EffectiveConnectionType is an estimate of the
58 // quality of the network that may differ from the actual network type 65 // quality of the network that may differ from the actual network type
59 // reported by NetworkchangeNotifier::GetConnectionType. 66 // reported by NetworkchangeNotifier::GetConnectionType.
60 void EffectiveConnectionTypeChanged(net::EffectiveConnectionType type); 67 void EffectiveConnectionTypeChanged(net::EffectiveConnectionType type);
61 68
62 // The current EffectiveConnectionType. 69 // The current EffectiveConnectionType.
63 net::EffectiveConnectionType type_; 70 net::EffectiveConnectionType type_;
64 71
65 // IO thread based observer that is owned by this service. Created on the UI 72 // IO thread based observer that is owned by this service. Created on the UI
66 // thread, but used and deleted on the IO thread. 73 // thread, but used and deleted on the IO thread.
67 std::unique_ptr<IONetworkQualityObserver> io_observer_; 74 std::unique_ptr<IONetworkQualityObserver> io_observer_;
68 75
76 // Observer list for changes in effective connection type.
77 base::ObserverList<
78 net::NetworkQualityEstimator::EffectiveConnectionTypeObserver>
79 effective_connection_type_observer_list_;
80
69 // Prefs manager that is owned by this service. Created on the UI thread, but 81 // Prefs manager that is owned by this service. Created on the UI thread, but
70 // used and deleted on the IO thread. 82 // used and deleted on the IO thread.
71 std::unique_ptr<net::NetworkQualitiesPrefsManager> prefs_manager_; 83 std::unique_ptr<net::NetworkQualitiesPrefsManager> prefs_manager_;
72 84
73 base::WeakPtrFactory<UINetworkQualityEstimatorService> weak_factory_; 85 base::WeakPtrFactory<UINetworkQualityEstimatorService> weak_factory_;
74 86
75 DISALLOW_COPY_AND_ASSIGN(UINetworkQualityEstimatorService); 87 DISALLOW_COPY_AND_ASSIGN(UINetworkQualityEstimatorService);
76 }; 88 };
77 89
78 #endif // CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_ 90 #endif // CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/net/nqe/ui_network_quality_estimator_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698