| 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_win.h" | 5 #include "net/base/network_change_notifier_win.h" |
| 6 | 6 |
| 7 #include <iphlpapi.h> | 7 #include <iphlpapi.h> |
| 8 #include <winsock2.h> | 8 #include <winsock2.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 service_.reset(); | 45 service_.reset(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 scoped_ptr<DnsConfigService> service_; | 49 scoped_ptr<DnsConfigService> service_; |
| 50 | 50 |
| 51 DISALLOW_COPY_AND_ASSIGN(DnsConfigServiceThread); | 51 DISALLOW_COPY_AND_ASSIGN(DnsConfigServiceThread); |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 NetworkChangeNotifierWin::NetworkChangeNotifierWin() | 54 NetworkChangeNotifierWin::NetworkChangeNotifierWin() |
| 55 : is_watching_(false), | 55 : NetworkChangeNotifier(NetworkChangeCalculatorParamsWin()), |
| 56 is_watching_(false), |
| 56 sequential_failures_(0), | 57 sequential_failures_(0), |
| 57 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 58 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 58 dns_config_service_thread_(new DnsConfigServiceThread()), | 59 dns_config_service_thread_(new DnsConfigServiceThread()), |
| 59 last_announced_offline_(IsOffline()) { | 60 last_announced_offline_(IsOffline()) { |
| 60 memset(&addr_overlapped_, 0, sizeof addr_overlapped_); | 61 memset(&addr_overlapped_, 0, sizeof addr_overlapped_); |
| 61 addr_overlapped_.hEvent = WSACreateEvent(); | 62 addr_overlapped_.hEvent = WSACreateEvent(); |
| 62 dns_config_service_thread_->StartWithOptions( | 63 dns_config_service_thread_->StartWithOptions( |
| 63 base::Thread::Options(MessageLoop::TYPE_IO, 0)); | 64 base::Thread::Options(MessageLoop::TYPE_IO, 0)); |
| 64 } | 65 } |
| 65 | 66 |
| 66 NetworkChangeNotifierWin::~NetworkChangeNotifierWin() { | 67 NetworkChangeNotifierWin::~NetworkChangeNotifierWin() { |
| 67 if (is_watching_) { | 68 if (is_watching_) { |
| 68 CancelIPChangeNotify(&addr_overlapped_); | 69 CancelIPChangeNotify(&addr_overlapped_); |
| 69 addr_watcher_.StopWatching(); | 70 addr_watcher_.StopWatching(); |
| 70 } | 71 } |
| 71 WSACloseEvent(addr_overlapped_.hEvent); | 72 WSACloseEvent(addr_overlapped_.hEvent); |
| 72 } | 73 } |
| 73 | 74 |
| 75 // static |
| 76 NetworkChangeNotifier::NetworkChangeCalculatorParams |
| 77 NetworkChangeNotifierWin::NetworkChangeCalculatorParamsWin() { |
| 78 NetworkChangeCalculatorParams params; |
| 79 // Delay values arrived at by simple experimentation and adjusted so as to |
| 80 // produce a single signal when switching between network connections. |
| 81 params.ip_address_offline_delay_ = base::TimeDelta::FromMilliseconds(1500); |
| 82 params.ip_address_online_delay_ = base::TimeDelta::FromMilliseconds(1500); |
| 83 params.connection_type_offline_delay_ = |
| 84 base::TimeDelta::FromMilliseconds(1500); |
| 85 params.connection_type_online_delay_ = base::TimeDelta::FromMilliseconds(500); |
| 86 return params; |
| 87 } |
| 88 |
| 74 // This implementation does not return the actual connection type but merely | 89 // This implementation does not return the actual connection type but merely |
| 75 // determines if the user is "online" (in which case it returns | 90 // determines if the user is "online" (in which case it returns |
| 76 // CONNECTION_UNKNOWN) or "offline" (and then it returns CONNECTION_NONE). | 91 // CONNECTION_UNKNOWN) or "offline" (and then it returns CONNECTION_NONE). |
| 77 // This is challenging since the only thing we can test with certainty is | 92 // This is challenging since the only thing we can test with certainty is |
| 78 // whether a *particular* host is reachable. | 93 // whether a *particular* host is reachable. |
| 79 // | 94 // |
| 80 // While we can't conclusively determine when a user is "online", we can at | 95 // While we can't conclusively determine when a user is "online", we can at |
| 81 // least reliably recognize some of the situtations when they are clearly | 96 // least reliably recognize some of the situtations when they are clearly |
| 82 // "offline". For example, if the user's laptop is not plugged into an ethernet | 97 // "offline". For example, if the user's laptop is not plugged into an ethernet |
| 83 // network and is not connected to any wireless networks, it must be offline. | 98 // network and is not connected to any wireless networks, it must be offline. |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 return; | 301 return; |
| 287 } | 302 } |
| 288 if (last_announced_offline_) | 303 if (last_announced_offline_) |
| 289 UMA_HISTOGRAM_CUSTOM_COUNTS("NCN.OfflinePolls", offline_polls_, 1, 50, 50); | 304 UMA_HISTOGRAM_CUSTOM_COUNTS("NCN.OfflinePolls", offline_polls_, 1, 50, 50); |
| 290 last_announced_offline_ = current_offline; | 305 last_announced_offline_ = current_offline; |
| 291 | 306 |
| 292 NotifyObserversOfConnectionTypeChange(); | 307 NotifyObserversOfConnectionTypeChange(); |
| 293 } | 308 } |
| 294 | 309 |
| 295 } // namespace net | 310 } // namespace net |
| OLD | NEW |