OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "content/browser/net/network_quality_observer_impl.h" | 5 #include "content/browser/net/network_quality_observer_impl.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "content/browser/renderer_host/render_process_host_impl.h" | 8 #include "content/browser/renderer_host/render_process_host_impl.h" |
9 #include "content/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 void OnRTTOrThroughputEstimatesComputed( | 74 void OnRTTOrThroughputEstimatesComputed( |
75 const net::nqe::internal::NetworkQuality& network_quality) { | 75 const net::nqe::internal::NetworkQuality& network_quality) { |
76 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 76 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
77 | 77 |
78 last_notified_network_quality_ = network_quality; | 78 last_notified_network_quality_ = network_quality; |
79 | 79 |
80 // Notify all the existing renderers of the change in the network quality. | 80 // Notify all the existing renderers of the change in the network quality. |
81 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); | 81 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); |
82 !it.IsAtEnd(); it.Advance()) { | 82 !it.IsAtEnd(); it.Advance()) { |
83 it.GetCurrentValue()->GetRendererInterface()->OnNetworkQualityChanged( | 83 it.GetCurrentValue()->GetRendererInterface()->OnNetworkQualityChanged( |
84 last_notified_network_quality_.http_rtt().InMilliseconds(), | 84 last_notified_network_quality_.http_rtt(), |
85 last_notified_network_quality_.transport_rtt().InMilliseconds(), | 85 last_notified_network_quality_.transport_rtt(), |
86 last_notified_network_quality_.downstream_throughput_kbps()); | 86 last_notified_network_quality_.downstream_throughput_kbps()); |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 private: | 90 private: |
91 // NotificationObserver implementation: | 91 // NotificationObserver implementation: |
92 void Observe(int type, | 92 void Observe(int type, |
93 const NotificationSource& source, | 93 const NotificationSource& source, |
94 const NotificationDetails& details) override { | 94 const NotificationDetails& details) override { |
95 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 95 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
96 DCHECK_EQ(NOTIFICATION_RENDERER_PROCESS_CREATED, type); | 96 DCHECK_EQ(NOTIFICATION_RENDERER_PROCESS_CREATED, type); |
97 | 97 |
98 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr(); | 98 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr(); |
99 | 99 |
100 // Notify the newly created renderer of the current network quality. | 100 // Notify the newly created renderer of the current network quality. |
101 rph->GetRendererInterface()->OnNetworkQualityChanged( | 101 rph->GetRendererInterface()->OnNetworkQualityChanged( |
102 last_notified_network_quality_.http_rtt().InMilliseconds(), | 102 last_notified_network_quality_.http_rtt(), |
103 last_notified_network_quality_.transport_rtt().InMilliseconds(), | 103 last_notified_network_quality_.transport_rtt(), |
104 last_notified_network_quality_.downstream_throughput_kbps()); | 104 last_notified_network_quality_.downstream_throughput_kbps()); |
105 } | 105 } |
106 | 106 |
107 content::NotificationRegistrar registrar_; | 107 content::NotificationRegistrar registrar_; |
108 | 108 |
109 // The network quality that was last sent to the renderers. | 109 // The network quality that was last sent to the renderers. |
110 net::nqe::internal::NetworkQuality last_notified_network_quality_; | 110 net::nqe::internal::NetworkQuality last_notified_network_quality_; |
111 | 111 |
112 DISALLOW_COPY_AND_ASSIGN(UiThreadObserver); | 112 DISALLOW_COPY_AND_ASSIGN(UiThreadObserver); |
113 }; | 113 }; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 175 } |
176 | 176 |
177 std::unique_ptr<net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver> | 177 std::unique_ptr<net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver> |
178 CreateNetworkQualityObserver( | 178 CreateNetworkQualityObserver( |
179 net::NetworkQualityEstimator* network_quality_estimator) { | 179 net::NetworkQualityEstimator* network_quality_estimator) { |
180 return base::MakeUnique<NetworkQualityObserverImpl>( | 180 return base::MakeUnique<NetworkQualityObserverImpl>( |
181 network_quality_estimator); | 181 network_quality_estimator); |
182 } | 182 } |
183 | 183 |
184 } // namespace content | 184 } // namespace content |
OLD | NEW |