diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/components/metrics/net | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/metrics/net')
7 files changed, 60 insertions, 359 deletions
diff --git a/chromium/components/metrics/net/net_metrics_log_uploader.cc b/chromium/components/metrics/net/net_metrics_log_uploader.cc index 641e119282f..3c0562bb3c0 100644 --- a/chromium/components/metrics/net/net_metrics_log_uploader.cc +++ b/chromium/components/metrics/net/net_metrics_log_uploader.cc @@ -4,12 +4,17 @@ #include "components/metrics/net/net_metrics_log_uploader.h" +#include <sstream> + #include "base/base64.h" #include "base/bind.h" #include "base/feature_list.h" #include "base/metrics/field_trial_params.h" #include "base/metrics/histogram_macros.h" +#include "base/metrics/statistics_recorder.h" #include "base/rand_util.h" +#include "base/strings/strcat.h" +#include "base/strings/string_number_conversions.h" #include "base/task/post_task.h" #include "base/threading/sequenced_task_runner_handle.h" #include "components/encrypted_messages/encrypted_message.pb.h" @@ -21,7 +26,9 @@ #include "net/url_request/url_fetcher.h" #include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/simple_url_loader.h" +#include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h" #include "third_party/metrics_proto/reporting_info.pb.h" +#include "third_party/zlib/google/compression_utils.h" #include "url/gurl.h" namespace { @@ -182,6 +189,52 @@ bool EncryptAndBase64EncodeString(const std::string& plaintext, return true; } +#ifndef NDEBUG +void LogUploadingHistograms(const std::string& compressed_log_data) { + if (!VLOG_IS_ON(2)) + return; + + std::string uncompressed; + if (!compression::GzipUncompress(compressed_log_data, &uncompressed)) { + DVLOG(2) << "failed to uncompress log"; + return; + } + metrics::ChromeUserMetricsExtension proto; + if (!proto.ParseFromString(uncompressed)) { + DVLOG(2) << "failed to parse uncompressed log"; + return; + }; + DVLOG(2) << "Uploading histograms..."; + + const base::StatisticsRecorder::Histograms histograms = + base::StatisticsRecorder::GetHistograms(); + auto get_histogram_name = [&](uint64_t name_hash) -> std::string { + for (base::HistogramBase* histogram : histograms) { + if (histogram->name_hash() == name_hash) + return histogram->histogram_name(); + } + return base::StrCat({"unnamed ", base::NumberToString(name_hash)}); + }; + + for (int i = 0; i < proto.histogram_event_size(); i++) { + const metrics::HistogramEventProto& event = proto.histogram_event(i); + + std::stringstream summary; + summary << " sum=" << event.sum(); + for (int j = 0; j < event.bucket_size(); j++) { + const metrics::HistogramEventProto::Bucket& b = event.bucket(j); + // Empty fields have a specific meaning, see + // third_party/metrics_proto/histogram_event.proto. + summary << " bucket[" + << (b.has_min() ? base::NumberToString(b.min()) : "..") << '-' + << (b.has_max() ? base::NumberToString(b.max()) : "..") << ")=" + << (b.has_count() ? base::NumberToString(b.count()) : "(1)"); + } + DVLOG(2) << get_histogram_name(event.name_hash()) << summary.str(); + } +} +#endif + } // namespace namespace metrics { @@ -243,6 +296,13 @@ void NetMetricsLogUploader::UploadLogToURL( const GURL& url) { DCHECK(!log_hash.empty()); +#ifndef NDEBUG + // For debug builds, you can use -vmodule=net_metrics_log_uploader=2 + // to enable logging of uploaded histograms. You probably also want to use + // --force-enable-metrics-reporting, or metrics reporting may not be enabled. + LogUploadingHistograms(compressed_log_data); +#endif + auto resource_request = std::make_unique<network::ResourceRequest>(); resource_request->url = url; // Drop cookies and auth data. diff --git a/chromium/components/metrics/net/network_metrics_provider.cc b/chromium/components/metrics/net/network_metrics_provider.cc index 1c99f32282c..1f4bfda67a4 100644 --- a/chromium/components/metrics/net/network_metrics_provider.cc +++ b/chromium/components/metrics/net/network_metrics_provider.cc @@ -34,10 +34,6 @@ #include "services/network/public/cpp/network_connection_tracker.h" #endif -#if defined(OS_CHROMEOS) -#include "components/metrics/net/wifi_access_point_info_provider_chromeos.h" -#endif // OS_CHROMEOS - namespace { #if defined(OS_ANDROID) @@ -200,21 +196,6 @@ void NetworkMetricsProvider::ProvideSystemProfileMetrics( wifi_phy_layer_protocol_is_ambiguous_ = false; min_effective_connection_type_ = effective_connection_type_; max_effective_connection_type_ = effective_connection_type_; - - if (!wifi_access_point_info_provider_) { -#if defined(OS_CHROMEOS) - wifi_access_point_info_provider_.reset( - new WifiAccessPointInfoProviderChromeos()); -#else - wifi_access_point_info_provider_.reset( - new WifiAccessPointInfoProvider()); -#endif // OS_CHROMEOS - } - - // Connected wifi access point information. - WifiAccessPointInfoProvider::WifiAccessPointInfo info; - if (wifi_access_point_info_provider_->GetInfo(&info)) - WriteWifiAccessPointProto(info, network); } void NetworkMetricsProvider::OnConnectionChanged( @@ -321,85 +302,6 @@ void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult( wifi_phy_layer_protocol_ = mode; } -void NetworkMetricsProvider::WriteWifiAccessPointProto( - const WifiAccessPointInfoProvider::WifiAccessPointInfo& info, - SystemProfileProto::Network* network_proto) { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - SystemProfileProto::Network::WifiAccessPoint* access_point_info = - network_proto->mutable_access_point_info(); - SystemProfileProto::Network::WifiAccessPoint::SecurityMode security = - SystemProfileProto::Network::WifiAccessPoint::SECURITY_UNKNOWN; - switch (info.security) { - case WifiAccessPointInfoProvider::WIFI_SECURITY_NONE: - security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_NONE; - break; - case WifiAccessPointInfoProvider::WIFI_SECURITY_WPA: - security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_WPA; - break; - case WifiAccessPointInfoProvider::WIFI_SECURITY_WEP: - security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_WEP; - break; - case WifiAccessPointInfoProvider::WIFI_SECURITY_RSN: - security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_RSN; - break; - case WifiAccessPointInfoProvider::WIFI_SECURITY_802_1X: - security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_802_1X; - break; - case WifiAccessPointInfoProvider::WIFI_SECURITY_PSK: - security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_PSK; - break; - case WifiAccessPointInfoProvider::WIFI_SECURITY_UNKNOWN: - security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_UNKNOWN; - break; - } - access_point_info->set_security_mode(security); - - // |bssid| is xx:xx:xx:xx:xx:xx, extract the first three components and - // pack into a uint32_t. - std::string bssid = info.bssid; - if (bssid.size() == 17 && bssid[2] == ':' && bssid[5] == ':' && - bssid[8] == ':' && bssid[11] == ':' && bssid[14] == ':') { - std::string vendor_prefix_str; - uint32_t vendor_prefix; - - base::RemoveChars(bssid.substr(0, 9), ":", &vendor_prefix_str); - DCHECK_EQ(6U, vendor_prefix_str.size()); - if (base::HexStringToUInt(vendor_prefix_str, &vendor_prefix)) - access_point_info->set_vendor_prefix(vendor_prefix); - else - NOTREACHED(); - } - - // Return if vendor information is not provided. - if (info.model_number.empty() && info.model_name.empty() && - info.device_name.empty() && info.oui_list.empty()) - return; - - SystemProfileProto::Network::WifiAccessPoint::VendorInformation* vendor = - access_point_info->mutable_vendor_info(); - if (!info.model_number.empty()) - vendor->set_model_number(info.model_number); - if (!info.model_name.empty()) - vendor->set_model_name(info.model_name); - if (!info.device_name.empty()) - vendor->set_device_name(info.device_name); - - // Return if OUI list is not provided. - if (info.oui_list.empty()) - return; - - // Parse OUI list. - for (const base::StringPiece& oui_str : base::SplitStringPiece( - info.oui_list, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { - uint32_t oui; - if (base::HexStringToUInt(oui_str, &oui)) { - vendor->add_element_identifier(oui); - } else { - DLOG(WARNING) << "Error when parsing OUI list of the WiFi access point"; - } - } -} - void NetworkMetricsProvider::LogAggregatedMetrics() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); base::HistogramBase* error_codes = base::SparseHistogram::FactoryGet( diff --git a/chromium/components/metrics/net/network_metrics_provider.h b/chromium/components/metrics/net/network_metrics_provider.h index 7d8a8682584..9278e319e03 100644 --- a/chromium/components/metrics/net/network_metrics_provider.h +++ b/chromium/components/metrics/net/network_metrics_provider.h @@ -15,7 +15,6 @@ #include "base/sequenced_task_runner.h" #include "base/single_thread_task_runner.h" #include "components/metrics/metrics_provider.h" -#include "components/metrics/net/wifi_access_point_info_provider.h" #include "net/base/network_interfaces.h" #include "net/nqe/effective_connection_type.h" #include "services/network/public/cpp/network_connection_tracker.h" @@ -87,12 +86,6 @@ class NetworkMetricsProvider // net::GetWifiPHYLayerProtocol. void OnWifiPHYLayerProtocolResult(net::WifiPHYLayerProtocol mode); - // Writes info about the wireless access points that this system is - // connected to. - void WriteWifiAccessPointProto( - const WifiAccessPointInfoProvider::WifiAccessPointInfo& info, - SystemProfileProto::Network* network_proto); - // Logs metrics that are functions of other metrics being uploaded. void LogAggregatedMetrics(); @@ -128,9 +121,6 @@ class NetworkMetricsProvider // net::GetWifiPHYLayerProtocol. net::WifiPHYLayerProtocol wifi_phy_layer_protocol_; - // Helper object for retrieving connected wifi access point information. - std::unique_ptr<WifiAccessPointInfoProvider> wifi_access_point_info_provider_; - // These metrics track histogram totals for the Net.ErrorCodesForMainFrame4 // histogram. They are used to compute deltas at upload time. base::HistogramBase::Count total_aborts_; diff --git a/chromium/components/metrics/net/wifi_access_point_info_provider.cc b/chromium/components/metrics/net/wifi_access_point_info_provider.cc deleted file mode 100644 index 21e04b181d2..00000000000 --- a/chromium/components/metrics/net/wifi_access_point_info_provider.cc +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "components/metrics/net/wifi_access_point_info_provider.h" - -namespace metrics { - -WifiAccessPointInfoProvider::WifiAccessPointInfo::WifiAccessPointInfo() { -} - -WifiAccessPointInfoProvider::WifiAccessPointInfo::~WifiAccessPointInfo() { -} - -WifiAccessPointInfoProvider::WifiAccessPointInfoProvider() { -} - -WifiAccessPointInfoProvider::~WifiAccessPointInfoProvider() { -} - -bool WifiAccessPointInfoProvider::GetInfo(WifiAccessPointInfo *info) { - return false; -} - -} // namespace metrics diff --git a/chromium/components/metrics/net/wifi_access_point_info_provider.h b/chromium/components/metrics/net/wifi_access_point_info_provider.h deleted file mode 100644 index 3a761da1b12..00000000000 --- a/chromium/components/metrics/net/wifi_access_point_info_provider.h +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef COMPONENTS_METRICS_NET_WIFI_ACCESS_POINT_INFO_PROVIDER_H_ -#define COMPONENTS_METRICS_NET_WIFI_ACCESS_POINT_INFO_PROVIDER_H_ - -#include <string> - -#include "base/macros.h" - -namespace metrics { - -// Interface for accessing connected wireless access point information. -class WifiAccessPointInfoProvider { - public: - // Wifi access point security mode definitions. - enum WifiSecurityMode { - WIFI_SECURITY_UNKNOWN = 0, - WIFI_SECURITY_WPA = 1, - WIFI_SECURITY_WEP = 2, - WIFI_SECURITY_RSN = 3, - WIFI_SECURITY_802_1X = 4, - WIFI_SECURITY_PSK = 5, - WIFI_SECURITY_NONE - }; - - // Information of the currently connected wifi access point. - struct WifiAccessPointInfo { - WifiAccessPointInfo(); - ~WifiAccessPointInfo(); - WifiSecurityMode security; - std::string bssid; - std::string model_number; - std::string model_name; - std::string device_name; - std::string oui_list; - }; - - WifiAccessPointInfoProvider(); - virtual ~WifiAccessPointInfoProvider(); - - // Fill in the wifi access point info if device is currently connected to a - // wifi access point. Return true if device is connected to a wifi access - // point, false otherwise. - virtual bool GetInfo(WifiAccessPointInfo *info); - - private: - DISALLOW_COPY_AND_ASSIGN(WifiAccessPointInfoProvider); -}; - -} // namespace metrics - -#endif // COMPONENTS_METRICS_NET_WIFI_ACCESS_POINT_INFO_PROVIDER_H_ diff --git a/chromium/components/metrics/net/wifi_access_point_info_provider_chromeos.cc b/chromium/components/metrics/net/wifi_access_point_info_provider_chromeos.cc deleted file mode 100644 index 91bcfdfa34b..00000000000 --- a/chromium/components/metrics/net/wifi_access_point_info_provider_chromeos.cc +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "components/metrics/net/wifi_access_point_info_provider_chromeos.h" - -#include <stdint.h> - -#include "base/bind.h" -#include "base/location.h" -#include "base/strings/string_number_conversions.h" -#include "chromeos/network/network_configuration_handler.h" -#include "chromeos/network/network_handler.h" -#include "chromeos/network/network_state.h" -#include "chromeos/network/network_state_handler.h" -#include "chromeos/network/shill_property_util.h" -#include "third_party/cros_system_api/dbus/service_constants.h" - -using chromeos::NetworkHandler; - -namespace metrics { - -WifiAccessPointInfoProviderChromeos::WifiAccessPointInfoProviderChromeos() { - NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE); - - // Update initial connection state. - DefaultNetworkChanged( - NetworkHandler::Get()->network_state_handler()->DefaultNetwork()); -} - -WifiAccessPointInfoProviderChromeos::~WifiAccessPointInfoProviderChromeos() { - NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, - FROM_HERE); -} - -bool WifiAccessPointInfoProviderChromeos::GetInfo(WifiAccessPointInfo* info) { - // Wifi access point information is not provided if the BSSID is empty. - // This assumes the BSSID is never empty when access point information exists. - if (wifi_access_point_info_.bssid.empty()) - return false; - - *info = wifi_access_point_info_; - return true; -} - -void WifiAccessPointInfoProviderChromeos::DefaultNetworkChanged( - const chromeos::NetworkState* default_network) { - // Reset access point info to prevent reporting of out-dated data. - wifi_access_point_info_ = WifiAccessPointInfo(); - - // Skip non-wifi connections - if (!default_network || default_network->type() != shill::kTypeWifi) - return; - - // Retrieve access point info for wifi connection. - NetworkHandler::Get()->network_configuration_handler()->GetShillProperties( - default_network->path(), - base::BindRepeating(&WifiAccessPointInfoProviderChromeos::ParseInfo, - AsWeakPtr()), - chromeos::network_handler::ErrorCallback()); -} - -void WifiAccessPointInfoProviderChromeos::ParseInfo( - const std::string &service_path, - const base::DictionaryValue& properties) { - // Skip services that contain "_nomap" in the SSID. - std::string ssid = chromeos::shill_property_util::GetSSIDFromProperties( - properties, false /* verbose_logging */, nullptr); - if (ssid.find("_nomap", 0) != std::string::npos) - return; - - std::string bssid; - if (!properties.GetStringWithoutPathExpansion(shill::kWifiBSsid, &bssid) || - bssid.empty()) - return; - - // Filter out BSSID with local bit set in the first byte. - uint32_t first_octet; - if (!base::HexStringToUInt(bssid.substr(0, 2), &first_octet)) - NOTREACHED(); - if (first_octet & 0x2) - return; - wifi_access_point_info_.bssid = bssid; - - // Parse security info. - std::string security; - properties.GetStringWithoutPathExpansion( - shill::kSecurityProperty, &security); - wifi_access_point_info_.security = WIFI_SECURITY_UNKNOWN; - if (security == shill::kSecurityWpa) - wifi_access_point_info_.security = WIFI_SECURITY_WPA; - else if (security == shill::kSecurityWep) - wifi_access_point_info_.security = WIFI_SECURITY_WEP; - else if (security == shill::kSecurityRsn) - wifi_access_point_info_.security = WIFI_SECURITY_RSN; - else if (security == shill::kSecurity8021x) - wifi_access_point_info_.security = WIFI_SECURITY_802_1X; - else if (security == shill::kSecurityPsk) - wifi_access_point_info_.security = WIFI_SECURITY_PSK; - else if (security == shill::kSecurityNone) - wifi_access_point_info_.security = WIFI_SECURITY_NONE; - - properties.GetStringWithoutPathExpansion( - shill::kWifiBSsid, &wifi_access_point_info_.bssid); - const base::DictionaryValue* vendor_dict = nullptr; - if (!properties.GetDictionaryWithoutPathExpansion( - shill::kWifiVendorInformationProperty, - &vendor_dict)) - return; - - vendor_dict->GetStringWithoutPathExpansion( - shill::kVendorWPSModelNumberProperty, - &wifi_access_point_info_.model_number); - vendor_dict->GetStringWithoutPathExpansion( - shill::kVendorWPSModelNameProperty, - &wifi_access_point_info_.model_name); - vendor_dict->GetStringWithoutPathExpansion( - shill::kVendorWPSDeviceNameProperty, - &wifi_access_point_info_.device_name); - vendor_dict->GetStringWithoutPathExpansion(shill::kVendorOUIListProperty, - &wifi_access_point_info_.oui_list); -} - -} // namespace metrics diff --git a/chromium/components/metrics/net/wifi_access_point_info_provider_chromeos.h b/chromium/components/metrics/net/wifi_access_point_info_provider_chromeos.h deleted file mode 100644 index d3102397741..00000000000 --- a/chromium/components/metrics/net/wifi_access_point_info_provider_chromeos.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef COMPONENTS_METRICS_NET_WIFI_ACCESS_POINT_INFO_PROVIDER_CHROMEOS_H_ -#define COMPONENTS_METRICS_NET_WIFI_ACCESS_POINT_INFO_PROVIDER_CHROMEOS_H_ - -#include <string> - -#include "base/macros.h" -#include "base/memory/weak_ptr.h" -#include "base/values.h" -#include "chromeos/network/network_state_handler_observer.h" -#include "components/metrics/net/wifi_access_point_info_provider.h" - -namespace metrics { - -// WifiAccessPointInfoProviderChromeos provides the connected wifi -// acccess point information for chromeos. -class WifiAccessPointInfoProviderChromeos - : public WifiAccessPointInfoProvider, - public chromeos::NetworkStateHandlerObserver, - public base::SupportsWeakPtr<WifiAccessPointInfoProviderChromeos> { - public: - WifiAccessPointInfoProviderChromeos(); - ~WifiAccessPointInfoProviderChromeos() override; - - // WifiAccessPointInfoProvider: - bool GetInfo(WifiAccessPointInfo* info) override; - - // NetworkStateHandlerObserver: - void DefaultNetworkChanged( - const chromeos::NetworkState* default_network) override; - - private: - // Callback from Shill.Service.GetProperties. Parses |properties| to obtain - // the wifi access point information. - void ParseInfo(const std::string& service_path, - const base::DictionaryValue& properties); - - WifiAccessPointInfo wifi_access_point_info_; - - DISALLOW_COPY_AND_ASSIGN(WifiAccessPointInfoProviderChromeos); -}; - -} // namespace metrics - -#endif // COMPONENTS_METRICS_NET_WIFI_ACCESS_POINT_INFO_PROVIDER_CHROMEOS_H_ |