| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 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 | 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/logging_network_change_observer.h" | 5 #include "net/base/logging_network_change_observer.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "net/log/net_log.h" | 12 #include "net/log/net_log.h" |
| 13 | 13 |
| 14 #if defined(OS_ANDROID) |
| 15 #include "base/android/build_info.h" |
| 16 #endif |
| 17 |
| 14 namespace net { | 18 namespace net { |
| 15 | 19 |
| 16 namespace { | 20 namespace { |
| 17 | 21 |
| 22 // Returns a human readable integer from a NetworkHandle. |
| 23 int HumanReadableNetworkHandle(NetworkChangeNotifier::NetworkHandle network) { |
| 24 #if defined(OS_ANDROID) |
| 25 // On Marshmallow, demunge the NetID to undo munging done in java |
| 26 // Network.getNetworkHandle() by shifting away 0xfacade from |
| 27 // http://androidxref.com/6.0.1_r10/xref/frameworks/base/core/java/android/net
/Network.java#385 |
| 28 if (base::android::BuildInfo::GetInstance()->sdk_int() >= |
| 29 base::android::SDK_VERSION_MARSHMALLOW) { |
| 30 return network >> 32; |
| 31 } |
| 32 #endif |
| 33 return network; |
| 34 } |
| 35 |
| 18 // Return a dictionary of values that provide information about a | 36 // Return a dictionary of values that provide information about a |
| 19 // network-specific change. This also includes relevant current state | 37 // network-specific change. This also includes relevant current state |
| 20 // like the default network, and the types of active networks. | 38 // like the default network, and the types of active networks. |
| 21 std::unique_ptr<base::Value> NetworkSpecificNetLogCallback( | 39 std::unique_ptr<base::Value> NetworkSpecificNetLogCallback( |
| 22 NetworkChangeNotifier::NetworkHandle network, | 40 NetworkChangeNotifier::NetworkHandle network, |
| 23 NetLogCaptureMode capture_mode) { | 41 NetLogCaptureMode capture_mode) { |
| 24 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 42 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 25 dict->SetInteger("changed_network_handle", network); | 43 dict->SetInteger("changed_network_handle", |
| 44 HumanReadableNetworkHandle(network)); |
| 26 dict->SetString( | 45 dict->SetString( |
| 27 "changed_network_type", | 46 "changed_network_type", |
| 28 NetworkChangeNotifier::ConnectionTypeToString( | 47 NetworkChangeNotifier::ConnectionTypeToString( |
| 29 NetworkChangeNotifier::GetNetworkConnectionType(network))); | 48 NetworkChangeNotifier::GetNetworkConnectionType(network))); |
| 30 dict->SetInteger("default_active_network_handle", | 49 dict->SetInteger( |
| 31 NetworkChangeNotifier::GetDefaultNetwork()); | 50 "default_active_network_handle", |
| 51 HumanReadableNetworkHandle(NetworkChangeNotifier::GetDefaultNetwork())); |
| 32 NetworkChangeNotifier::NetworkList networks; | 52 NetworkChangeNotifier::NetworkList networks; |
| 33 NetworkChangeNotifier::GetConnectedNetworks(&networks); | 53 NetworkChangeNotifier::GetConnectedNetworks(&networks); |
| 34 for (NetworkChangeNotifier::NetworkHandle active_network : networks) { | 54 for (NetworkChangeNotifier::NetworkHandle active_network : networks) { |
| 35 dict->SetString( | 55 dict->SetString( |
| 36 "current_active_networks." + base::IntToString(active_network), | 56 "current_active_networks." + |
| 57 base::IntToString(HumanReadableNetworkHandle(active_network)), |
| 37 NetworkChangeNotifier::ConnectionTypeToString( | 58 NetworkChangeNotifier::ConnectionTypeToString( |
| 38 NetworkChangeNotifier::GetNetworkConnectionType(active_network))); | 59 NetworkChangeNotifier::GetNetworkConnectionType(active_network))); |
| 39 } | 60 } |
| 40 return std::move(dict); | 61 return std::move(dict); |
| 41 } | 62 } |
| 42 | 63 |
| 43 } // namespace | 64 } // namespace |
| 44 | 65 |
| 45 LoggingNetworkChangeObserver::LoggingNetworkChangeObserver(NetLog* net_log) | 66 LoggingNetworkChangeObserver::LoggingNetworkChangeObserver(NetLog* net_log) |
| 46 : net_log_(net_log) { | 67 : net_log_(net_log) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 137 |
| 117 void LoggingNetworkChangeObserver::OnNetworkMadeDefault( | 138 void LoggingNetworkChangeObserver::OnNetworkMadeDefault( |
| 118 NetworkChangeNotifier::NetworkHandle network) { | 139 NetworkChangeNotifier::NetworkHandle network) { |
| 119 VLOG(1) << "Observed network " << network << " made the default network"; | 140 VLOG(1) << "Observed network " << network << " made the default network"; |
| 120 | 141 |
| 121 net_log_->AddGlobalEntry(NetLog::TYPE_SPECIFIC_NETWORK_MADE_DEFAULT, | 142 net_log_->AddGlobalEntry(NetLog::TYPE_SPECIFIC_NETWORK_MADE_DEFAULT, |
| 122 base::Bind(&NetworkSpecificNetLogCallback, network)); | 143 base::Bind(&NetworkSpecificNetLogCallback, network)); |
| 123 } | 144 } |
| 124 | 145 |
| 125 } // namespace net | 146 } // namespace net |
| OLD | NEW |