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 "net/base/network_change_notifier_mac.h" | 5 #include "net/base/network_change_notifier_mac.h" |
6 | 6 |
7 #include <netinet/in.h> | 7 #include <netinet/in.h> |
8 #include <resolv.h> | 8 #include <resolv.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 NetworkChangeNotifier::ConnectionType | 75 NetworkChangeNotifier::ConnectionType |
76 NetworkChangeNotifierMac::GetCurrentConnectionType() const { | 76 NetworkChangeNotifierMac::GetCurrentConnectionType() const { |
77 base::AutoLock lock(connection_type_lock_); | 77 base::AutoLock lock(connection_type_lock_); |
78 // Make sure the initial connection type is set before returning. | 78 // Make sure the initial connection type is set before returning. |
79 while (!connection_type_initialized_) { | 79 while (!connection_type_initialized_) { |
80 initial_connection_type_cv_.Wait(); | 80 initial_connection_type_cv_.Wait(); |
81 } | 81 } |
82 return connection_type_; | 82 return connection_type_; |
83 } | 83 } |
84 | 84 |
| 85 void NetworkChangeNotifierMac::Forwarder::Init() { |
| 86 net_config_watcher_->SetInitialConnectionType(); |
| 87 } |
| 88 |
| 89 void NetworkChangeNotifierMac::Forwarder::StartReachabilityNotifications() { |
| 90 net_config_watcher_->StartReachabilityNotifications(); |
| 91 } |
| 92 |
| 93 void NetworkChangeNotifierMac::Forwarder::SetDynamicStoreNotificationKeys( |
| 94 SCDynamicStoreRef store) { |
| 95 net_config_watcher_->SetDynamicStoreNotificationKeys(store); |
| 96 } |
| 97 |
| 98 void NetworkChangeNotifierMac::Forwarder::OnNetworkConfigChange( |
| 99 CFArrayRef changed_keys) { |
| 100 net_config_watcher_->OnNetworkConfigChange(changed_keys); |
| 101 } |
| 102 |
85 void NetworkChangeNotifierMac::SetInitialConnectionType() { | 103 void NetworkChangeNotifierMac::SetInitialConnectionType() { |
86 // Called on notifier thread. | 104 // Called on notifier thread. |
87 | 105 |
88 // Try to reach 0.0.0.0. This is the approach taken by Firefox: | 106 // Try to reach 0.0.0.0. This is the approach taken by Firefox: |
89 // | 107 // |
90 // http://mxr.mozilla.org/mozilla2.0/source/netwerk/system/mac/nsNetworkLinkSe
rvice.mm | 108 // http://mxr.mozilla.org/mozilla2.0/source/netwerk/system/mac/nsNetworkLinkSe
rvice.mm |
91 // | 109 // |
92 // From my (adamk) testing on Snow Leopard, 0.0.0.0 | 110 // From my (adamk) testing on Snow Leopard, 0.0.0.0 |
93 // seems to be reachable if any network connection is available. | 111 // seems to be reachable if any network connection is available. |
94 struct sockaddr_in addr = {0}; | 112 struct sockaddr_in addr = {0}; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 { | 217 { |
200 base::AutoLock lock(notifier_mac->connection_type_lock_); | 218 base::AutoLock lock(notifier_mac->connection_type_lock_); |
201 old_type = notifier_mac->connection_type_; | 219 old_type = notifier_mac->connection_type_; |
202 notifier_mac->connection_type_ = new_type; | 220 notifier_mac->connection_type_ = new_type; |
203 } | 221 } |
204 if (old_type != new_type) | 222 if (old_type != new_type) |
205 NotifyObserversOfConnectionTypeChange(); | 223 NotifyObserversOfConnectionTypeChange(); |
206 } | 224 } |
207 | 225 |
208 } // namespace net | 226 } // namespace net |
OLD | NEW |