Chromium Code Reviews| 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 | |
|
xunjieli
2016/08/18 17:15:17
Could you add a comment here that the NetID's lowe
pauljensen
2016/08/19 11:57:47
Done.
| |
| 26 // Network.getNetworkHandle(). | |
| 27 if (base::android::BuildInfo::GetInstance()->sdk_int() >= | |
| 28 base::android::SDK_VERSION_MARSHMALLOW) { | |
| 29 return network >> 32; | |
| 30 } | |
| 31 #endif | |
| 32 return network; | |
| 33 } | |
| 34 | |
| 18 // Return a dictionary of values that provide information about a | 35 // Return a dictionary of values that provide information about a |
| 19 // network-specific change. This also includes relevant current state | 36 // network-specific change. This also includes relevant current state |
| 20 // like the default network, and the types of active networks. | 37 // like the default network, and the types of active networks. |
| 21 std::unique_ptr<base::Value> NetworkSpecificNetLogCallback( | 38 std::unique_ptr<base::Value> NetworkSpecificNetLogCallback( |
| 22 NetworkChangeNotifier::NetworkHandle network, | 39 NetworkChangeNotifier::NetworkHandle network, |
| 23 NetLogCaptureMode capture_mode) { | 40 NetLogCaptureMode capture_mode) { |
| 24 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 41 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 25 dict->SetInteger("changed_network_handle", network); | 42 dict->SetInteger("changed_network_handle", |
| 43 HumanReadableNetworkHandle(network)); | |
| 26 dict->SetString( | 44 dict->SetString( |
| 27 "changed_network_type", | 45 "changed_network_type", |
| 28 NetworkChangeNotifier::ConnectionTypeToString( | 46 NetworkChangeNotifier::ConnectionTypeToString( |
| 29 NetworkChangeNotifier::GetNetworkConnectionType(network))); | 47 NetworkChangeNotifier::GetNetworkConnectionType(network))); |
| 30 dict->SetInteger("default_active_network_handle", | 48 dict->SetInteger( |
| 31 NetworkChangeNotifier::GetDefaultNetwork()); | 49 "default_active_network_handle", |
| 50 HumanReadableNetworkHandle(NetworkChangeNotifier::GetDefaultNetwork())); | |
| 32 NetworkChangeNotifier::NetworkList networks; | 51 NetworkChangeNotifier::NetworkList networks; |
| 33 NetworkChangeNotifier::GetConnectedNetworks(&networks); | 52 NetworkChangeNotifier::GetConnectedNetworks(&networks); |
| 34 for (NetworkChangeNotifier::NetworkHandle active_network : networks) { | 53 for (NetworkChangeNotifier::NetworkHandle active_network : networks) { |
| 35 dict->SetString( | 54 dict->SetString( |
| 36 "current_active_networks." + base::IntToString(active_network), | 55 "current_active_networks." + |
| 56 base::IntToString(HumanReadableNetworkHandle(active_network)), | |
|
xunjieli
2016/08/18 16:13:16
Why does ">>32" make network handle human readable
pauljensen
2016/08/18 16:16:49
">> 32" makes it readable because it undoes the mu
xunjieli
2016/08/18 17:15:16
Makes sense. I forgot about the 0xfacade part.
| |
| 37 NetworkChangeNotifier::ConnectionTypeToString( | 57 NetworkChangeNotifier::ConnectionTypeToString( |
| 38 NetworkChangeNotifier::GetNetworkConnectionType(active_network))); | 58 NetworkChangeNotifier::GetNetworkConnectionType(active_network))); |
| 39 } | 59 } |
| 40 return std::move(dict); | 60 return std::move(dict); |
| 41 } | 61 } |
| 42 | 62 |
| 43 } // namespace | 63 } // namespace |
| 44 | 64 |
| 45 LoggingNetworkChangeObserver::LoggingNetworkChangeObserver(NetLog* net_log) | 65 LoggingNetworkChangeObserver::LoggingNetworkChangeObserver(NetLog* net_log) |
| 46 : net_log_(net_log) { | 66 : net_log_(net_log) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 | 136 |
| 117 void LoggingNetworkChangeObserver::OnNetworkMadeDefault( | 137 void LoggingNetworkChangeObserver::OnNetworkMadeDefault( |
| 118 NetworkChangeNotifier::NetworkHandle network) { | 138 NetworkChangeNotifier::NetworkHandle network) { |
| 119 VLOG(1) << "Observed network " << network << " made the default network"; | 139 VLOG(1) << "Observed network " << network << " made the default network"; |
| 120 | 140 |
| 121 net_log_->AddGlobalEntry(NetLog::TYPE_SPECIFIC_NETWORK_MADE_DEFAULT, | 141 net_log_->AddGlobalEntry(NetLog::TYPE_SPECIFIC_NETWORK_MADE_DEFAULT, |
| 122 base::Bind(&NetworkSpecificNetLogCallback, network)); | 142 base::Bind(&NetworkSpecificNetLogCallback, network)); |
| 123 } | 143 } |
| 124 | 144 |
| 125 } // namespace net | 145 } // namespace net |
| OLD | NEW |