OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser_online_state_observer.h" | 5 #include "content/browser/net/browser_online_state_observer.h" |
6 | 6 |
7 #include "content/common/view_messages.h" | 7 #include "content/common/view_messages.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/public/browser/notification_service.h" | 9 #include "content/public/browser/notification_service.h" |
10 #include "content/public/browser/notification_types.h" | 10 #include "content/public/browser/notification_types.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 BrowserOnlineStateObserver::BrowserOnlineStateObserver() { | 14 BrowserOnlineStateObserver::BrowserOnlineStateObserver() { |
15 net::NetworkChangeNotifier::AddMaxBandwidthObserver(this); | 15 net::NetworkChangeNotifier::AddMaxBandwidthObserver(this); |
16 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, | 16 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
17 content::NotificationService::AllSources()); | 17 content::NotificationService::AllSources()); |
18 } | 18 } |
19 | 19 |
20 BrowserOnlineStateObserver::~BrowserOnlineStateObserver() { | 20 BrowserOnlineStateObserver::~BrowserOnlineStateObserver() { |
21 net::NetworkChangeNotifier::RemoveMaxBandwidthObserver(this); | 21 net::NetworkChangeNotifier::RemoveMaxBandwidthObserver(this); |
22 } | 22 } |
23 | 23 |
24 void BrowserOnlineStateObserver::OnMaxBandwidthChanged( | 24 void BrowserOnlineStateObserver::OnMaxBandwidthChanged( |
25 double max_bandwidth_mbps, | 25 double max_bandwidth_mbps, |
26 net::NetworkChangeNotifier::ConnectionType type) { | 26 net::NetworkChangeNotifier::ConnectionType type) { |
27 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); | 27 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); |
28 !it.IsAtEnd(); it.Advance()) { | 28 !it.IsAtEnd(); it.Advance()) { |
29 it.GetCurrentValue()->Send( | 29 it.GetCurrentValue()->GetRendererInterface()->OnNetworkConnectionChanged( |
30 new ViewMsg_NetworkConnectionChanged(type, max_bandwidth_mbps)); | 30 type, max_bandwidth_mbps); |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 void BrowserOnlineStateObserver::Observe( | 34 void BrowserOnlineStateObserver::Observe( |
35 int type, | 35 int type, |
36 const content::NotificationSource& source, | 36 const content::NotificationSource& source, |
37 const content::NotificationDetails& details) { | 37 const content::NotificationDetails& details) { |
38 DCHECK_EQ(NOTIFICATION_RENDERER_PROCESS_CREATED, type); | 38 DCHECK_EQ(NOTIFICATION_RENDERER_PROCESS_CREATED, type); |
39 | 39 |
40 content::RenderProcessHost* rph = | 40 content::RenderProcessHost* rph = |
41 content::Source<content::RenderProcessHost>(source).ptr(); | 41 content::Source<content::RenderProcessHost>(source).ptr(); |
42 double max_bandwidth_mbps; | 42 double max_bandwidth_mbps; |
43 net::NetworkChangeNotifier::ConnectionType connection_type; | 43 net::NetworkChangeNotifier::ConnectionType connection_type; |
44 net::NetworkChangeNotifier::GetMaxBandwidthAndConnectionType( | 44 net::NetworkChangeNotifier::GetMaxBandwidthAndConnectionType( |
45 &max_bandwidth_mbps, &connection_type); | 45 &max_bandwidth_mbps, &connection_type); |
46 rph->Send(new ViewMsg_NetworkConnectionChanged(connection_type, | 46 rph->GetRendererInterface()->OnNetworkConnectionChanged( |
47 max_bandwidth_mbps)); | 47 connection_type, max_bandwidth_mbps); |
48 } | 48 } |
49 | 49 |
50 } // namespace content | 50 } // namespace content |
OLD | NEW |