| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/base/logging_network_change_observer.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "net/log/net_log.h" |
| 11 |
| 12 namespace net { |
| 13 |
| 14 LoggingNetworkChangeObserver::LoggingNetworkChangeObserver(net::NetLog* net_log) |
| 15 : net_log_(net_log) { |
| 16 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
| 17 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 18 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
| 19 } |
| 20 |
| 21 LoggingNetworkChangeObserver::~LoggingNetworkChangeObserver() { |
| 22 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 23 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 24 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
| 25 } |
| 26 |
| 27 void LoggingNetworkChangeObserver::OnIPAddressChanged() { |
| 28 VLOG(1) << "Observed a change to the network IP addresses"; |
| 29 |
| 30 net_log_->AddGlobalEntry(net::NetLog::TYPE_NETWORK_IP_ADDRESSES_CHANGED); |
| 31 } |
| 32 |
| 33 void LoggingNetworkChangeObserver::OnConnectionTypeChanged( |
| 34 net::NetworkChangeNotifier::ConnectionType type) { |
| 35 std::string type_as_string = |
| 36 net::NetworkChangeNotifier::ConnectionTypeToString(type); |
| 37 |
| 38 VLOG(1) << "Observed a change to network connectivity state " |
| 39 << type_as_string; |
| 40 |
| 41 net_log_->AddGlobalEntry( |
| 42 net::NetLog::TYPE_NETWORK_CONNECTIVITY_CHANGED, |
| 43 net::NetLog::StringCallback("new_connection_type", &type_as_string)); |
| 44 } |
| 45 |
| 46 void LoggingNetworkChangeObserver::OnNetworkChanged( |
| 47 net::NetworkChangeNotifier::ConnectionType type) { |
| 48 std::string type_as_string = |
| 49 net::NetworkChangeNotifier::ConnectionTypeToString(type); |
| 50 |
| 51 VLOG(1) << "Observed a network change to state " << type_as_string; |
| 52 |
| 53 net_log_->AddGlobalEntry( |
| 54 net::NetLog::TYPE_NETWORK_CHANGED, |
| 55 net::NetLog::StringCallback("new_connection_type", &type_as_string)); |
| 56 } |
| 57 |
| 58 } // namespace net |
| OLD | NEW |