diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/platform/network')
7 files changed, 227 insertions, 10 deletions
diff --git a/chromium/third_party/blink/renderer/platform/network/encoded_form_data.h b/chromium/third_party/blink/renderer/platform/network/encoded_form_data.h index 83eb456a0d2..3c4e6f6146c 100644 --- a/chromium/third_party/blink/renderer/platform/network/encoded_form_data.h +++ b/chromium/third_party/blink/renderer/platform/network/encoded_form_data.h @@ -54,7 +54,7 @@ class PLATFORM_EXPORT WrappedDataPipeGetter final }; class PLATFORM_EXPORT FormDataElement final { - DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); + DISALLOW_NEW(); public: FormDataElement() : type_(kData) {} diff --git a/chromium/third_party/blink/renderer/platform/network/mime/mime_type_registry.cc b/chromium/third_party/blink/renderer/platform/network/mime/mime_type_registry.cc index e024e3609bb..354528a3938 100644 --- a/chromium/third_party/blink/renderer/platform/network/mime/mime_type_registry.cc +++ b/chromium/third_party/blink/renderer/platform/network/mime/mime_type_registry.cc @@ -161,7 +161,7 @@ MIMETypeRegistry::SupportsType MIMETypeRegistry::SupportsMediaMIMEType( const String& codecs) { const std::string ascii_mime_type = ToLowerASCIIOrEmpty(mime_type); std::vector<std::string> codec_vector; - media::SplitCodecsToVector(ToASCIIOrEmpty(codecs), &codec_vector, false); + media::SplitCodecs(ToASCIIOrEmpty(codecs), &codec_vector); return static_cast<SupportsType>( media::IsSupportedMediaFormat(ascii_mime_type, codec_vector)); } @@ -172,7 +172,7 @@ bool MIMETypeRegistry::IsSupportedMediaSourceMIMEType(const String& mime_type, if (ascii_mime_type.empty()) return false; std::vector<std::string> parsed_codec_ids; - media::SplitCodecsToVector(ToASCIIOrEmpty(codecs), &parsed_codec_ids, false); + media::SplitCodecs(ToASCIIOrEmpty(codecs), &parsed_codec_ids); return static_cast<MIMETypeRegistry::SupportsType>( media::StreamParserFactory::IsTypeSupported(ascii_mime_type, parsed_codec_ids)); diff --git a/chromium/third_party/blink/renderer/platform/network/network_state_notifier.cc b/chromium/third_party/blink/renderer/platform/network/network_state_notifier.cc index 4a22c312362..91e7ab621fe 100644 --- a/chromium/third_party/blink/renderer/platform/network/network_state_notifier.cc +++ b/chromium/third_party/blink/renderer/platform/network/network_state_notifier.cc @@ -40,6 +40,29 @@ namespace blink { +namespace { + +// Typical HTTP RTT value corresponding to a given WebEffectiveConnectionType +// value. Taken from +// https://cs.chromium.org/chromium/src/net/nqe/network_quality_estimator_params.cc. +const base::TimeDelta kTypicalHttpRttEffectiveConnectionType + [static_cast<size_t>(WebEffectiveConnectionType::kMaxValue) + 1] = { + base::TimeDelta::FromMilliseconds(0), + base::TimeDelta::FromMilliseconds(0), + base::TimeDelta::FromMilliseconds(3600), + base::TimeDelta::FromMilliseconds(1800), + base::TimeDelta::FromMilliseconds(450), + base::TimeDelta::FromMilliseconds(175)}; + +// Typical downlink throughput (in Mbps) value corresponding to a given +// WebEffectiveConnectionType value. Taken from +// https://cs.chromium.org/chromium/src/net/nqe/network_quality_estimator_params.cc. +const double kTypicalDownlinkMbpsEffectiveConnectionType + [static_cast<size_t>(WebEffectiveConnectionType::kMaxValue) + 1] = { + 0, 0, 0.040, 0.075, 0.400, 1.600}; + +} // namespace + template <> struct CrossThreadCopier<NetworkStateNotifier::NetworkState> : public CrossThreadCopierPassThrough<NetworkStateNotifier::NetworkState> { @@ -144,6 +167,19 @@ void NetworkStateNotifier::SetNetworkQuality(WebEffectiveConnectionType type, } } +void NetworkStateNotifier::SetNetworkQualityWebHoldback( + WebEffectiveConnectionType type) { + DCHECK(IsMainThread()); + if (type == WebEffectiveConnectionType::kTypeUnknown) + return; + ScopedNotifier notifier(*this); + { + MutexLocker locker(mutex_); + + state_.network_quality_web_holdback = type; + } +} + std::unique_ptr<NetworkStateNotifier::NetworkStateObserverHandle> NetworkStateNotifier::AddConnectionObserver( NetworkStateObserver* observer, @@ -448,4 +484,67 @@ double NetworkStateNotifier::RoundMbps( return downlink_kbps_rounded / 1000; } +base::Optional<WebEffectiveConnectionType> +NetworkStateNotifier::GetWebHoldbackEffectiveType() const { + MutexLocker locker(mutex_); + + const NetworkState& state = has_override_ ? override_ : state_; + // TODO (tbansal): Add a DCHECK to check that |state.on_line_initialized| is + // true once https://crbug.com/728771 is fixed. + return state.network_quality_web_holdback; +} + +base::Optional<TimeDelta> NetworkStateNotifier::GetWebHoldbackHttpRtt() const { + base::Optional<WebEffectiveConnectionType> override_ect = + GetWebHoldbackEffectiveType(); + + if (override_ect) { + return kTypicalHttpRttEffectiveConnectionType[static_cast<size_t>( + override_ect.value())]; + } + return base::nullopt; +} + +base::Optional<double> +NetworkStateNotifier::GetWebHoldbackDownlinkThroughputMbps() const { + base::Optional<WebEffectiveConnectionType> override_ect = + GetWebHoldbackEffectiveType(); + + if (override_ect) { + return kTypicalDownlinkMbpsEffectiveConnectionType[static_cast<size_t>( + override_ect.value())]; + } + return base::nullopt; +} + +void NetworkStateNotifier::GetMetricsWithWebHoldback( + WebConnectionType* type, + double* downlink_max_mbps, + WebEffectiveConnectionType* effective_type, + base::Optional<TimeDelta>* http_rtt, + base::Optional<double>* downlink_mbps, + bool* save_data) const { + MutexLocker locker(mutex_); + const NetworkState& state = has_override_ ? override_ : state_; + + *type = state.type; + *downlink_max_mbps = state.max_bandwidth_mbps; + + base::Optional<WebEffectiveConnectionType> override_ect = + state.network_quality_web_holdback; + if (override_ect) { + *effective_type = override_ect.value(); + *http_rtt = kTypicalHttpRttEffectiveConnectionType[static_cast<size_t>( + override_ect.value())]; + *downlink_mbps = + kTypicalDownlinkMbpsEffectiveConnectionType[static_cast<size_t>( + override_ect.value())]; + } else { + *effective_type = state.effective_type; + *http_rtt = state.http_rtt; + *downlink_mbps = state.downlink_throughput_mbps; + } + *save_data = state.save_data; +} + } // namespace blink diff --git a/chromium/third_party/blink/renderer/platform/network/network_state_notifier.h b/chromium/third_party/blink/renderer/platform/network/network_state_notifier.h index dd02480e88a..5fb43bd0fc3 100644 --- a/chromium/third_party/blink/renderer/platform/network/network_state_notifier.h +++ b/chromium/third_party/blink/renderer/platform/network/network_state_notifier.h @@ -63,6 +63,12 @@ class PLATFORM_EXPORT NetworkStateNotifier { base::Optional<TimeDelta> transport_rtt; base::Optional<double> downlink_throughput_mbps; bool save_data = false; + + // If set, then network quality corresponding to + // |network_quality_web_holdback| should be returned to the web consumers. + // Consumers within Blink should still receive the actual network quality + // values. + base::Optional<WebEffectiveConnectionType> network_quality_web_holdback; }; class NetworkStateObserver { @@ -212,6 +218,7 @@ class PLATFORM_EXPORT NetworkStateNotifier { TimeDelta http_rtt, TimeDelta transport_rtt, int downlink_throughput_kbps); + void SetNetworkQualityWebHoldback(WebEffectiveConnectionType); void SetSaveDataEnabled(bool enabled); // When called, successive setWebConnectionType/setOnLine calls are stored, @@ -263,6 +270,35 @@ class PLATFORM_EXPORT NetworkStateNotifier { // amount of noise for a given origin. uint8_t RandomizationSalt() const { return randomization_salt_; } + // Returns the overriding effective connection type that should be returned to + // the web consumers. If the returned value is null, then the actual network + // quality value should be returned to the web consumers. + // Consumers within Blink should not call this API. + base::Optional<WebEffectiveConnectionType> GetWebHoldbackEffectiveType() + const; + + // Returns the overriding HTTP RTT estimate that should be returned to + // the web consumers. If the returned value is null, then the actual network + // quality value should be returned to the web consumers. + // Consumers within Blink should not call this API. + base::Optional<TimeDelta> GetWebHoldbackHttpRtt() const; + + // Returns the overriding HTTP RTT estimate that should be returned to + // the web consumers. If the returned value is null, then the actual network + // quality value should be returned to the web consumers. + // Consumers within Blink should not call this API. + base::Optional<double> GetWebHoldbackDownlinkThroughputMbps() const; + + // Sets the metrics of all the values while taking into account any network + // quality web holdbacks in place. The caller must guarantee that all pointers + // are non-null. + void GetMetricsWithWebHoldback(WebConnectionType* type, + double* downlink_max_mbps, + WebEffectiveConnectionType* effective_type, + base::Optional<TimeDelta>* http_rtt, + base::Optional<double>* downlink_mbps, + bool* save_data) const; + private: friend class NetworkStateObserverHandle; diff --git a/chromium/third_party/blink/renderer/platform/network/network_state_notifier_test.cc b/chromium/third_party/blink/renderer/platform/network/network_state_notifier_test.cc index d77df97ec99..f047651859c 100644 --- a/chromium/third_party/blink/renderer/platform/network/network_state_notifier_test.cc +++ b/chromium/third_party/blink/renderer/platform/network/network_state_notifier_test.cc @@ -36,7 +36,7 @@ #include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/web_connection_type.h" #include "third_party/blink/public/platform/web_effective_connection_type.h" -#include "third_party/blink/public/platform/web_thread.h" +#include "third_party/blink/renderer/platform/scheduler/public/thread.h" #include "third_party/blink/renderer/platform/scheduler/test/fake_task_runner.h" #include "third_party/blink/renderer/platform/testing/unit_test_helpers.h" #include "third_party/blink/renderer/platform/wtf/functional.h" @@ -217,6 +217,32 @@ class NetworkStateNotifierTest : public testing::Test { RunPendingTasks(); } + void VerifyInitialMetricsWithWebHoldbackState( + WebConnectionType expected_type, + double expected_max_bandwidth_mbps, + WebEffectiveConnectionType expected_effective_type, + const base::Optional<TimeDelta>& expected_http_rtt, + const base::Optional<double>& expected_downlink_throughput_mbps, + SaveData expected_save_data) const { + WebConnectionType initial_type; + double initial_downlink_max_mbps; + WebEffectiveConnectionType initial_effective_type; + base::Optional<TimeDelta> initial_http_rtt; + base::Optional<double> initial_downlink_mbps; + bool initial_save_data; + + notifier_.GetMetricsWithWebHoldback( + &initial_type, &initial_downlink_max_mbps, &initial_effective_type, + &initial_http_rtt, &initial_downlink_mbps, &initial_save_data); + + EXPECT_EQ(expected_type, initial_type); + EXPECT_EQ(expected_max_bandwidth_mbps, initial_downlink_max_mbps); + EXPECT_EQ(expected_effective_type, initial_effective_type); + EXPECT_EQ(expected_http_rtt, initial_http_rtt); + EXPECT_EQ(expected_downlink_throughput_mbps, initial_downlink_mbps); + EXPECT_EQ(expected_save_data == SaveData::kOn, initial_save_data); + } + bool VerifyObservations( const StateObserver& observer, WebConnectionType type, @@ -259,6 +285,11 @@ TEST_F(NetworkStateNotifierTest, AddObserver) { WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps, SaveData::kOff)); + VerifyInitialMetricsWithWebHoldbackState( + kWebConnectionTypeUnknown, kNoneMaxBandwidthMbps, + WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, + kUnknownThroughputMbps, SaveData::kOff); + // Change max. bandwidth and the network quality estimates. SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, WebEffectiveConnectionType::kType3G, kEthernetHttpRtt, @@ -269,6 +300,11 @@ TEST_F(NetworkStateNotifierTest, AddObserver) { kEthernetTransportRtt, kEthernetThroughputMbps, SaveData::kOff)); EXPECT_EQ(observer.CallbackCount(), 2); + VerifyInitialMetricsWithWebHoldbackState( + kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, + WebEffectiveConnectionType::kType3G, kEthernetHttpRtt, + kEthernetThroughputMbps, SaveData::kOff); + // Only change the connection type. SetConnection(kWebConnectionTypeEthernet, kBluetoothMaxBandwidthMbps, WebEffectiveConnectionType::kType3G, kEthernetHttpRtt, @@ -571,6 +607,10 @@ TEST_F(NetworkStateNotifierTest, SetNetworkConnectionInfoOverride) { EXPECT_TRUE(notifier_.OnLine()); EXPECT_EQ(kWebConnectionTypeBluetooth, notifier_.ConnectionType()); EXPECT_EQ(kBluetoothMaxBandwidthMbps, notifier_.MaxBandwidth()); + VerifyInitialMetricsWithWebHoldbackState( + kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, + WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, + kUnknownThroughputMbps, SaveData::kOff); notifier_.SetNetworkConnectionInfoOverride( true, kWebConnectionTypeEthernet, WebEffectiveConnectionType::kType4G, @@ -583,6 +623,10 @@ TEST_F(NetworkStateNotifierTest, SetNetworkConnectionInfoOverride) { EXPECT_TRUE(notifier_.OnLine()); EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType()); EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth()); + VerifyInitialMetricsWithWebHoldbackState( + kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, + WebEffectiveConnectionType::kType4G, kEthernetHttpRtt, + kEthernetMaxBandwidthMbps, SaveData::kOff); // When override is active, calls to setOnLine and setConnection are temporary // ignored. @@ -598,6 +642,10 @@ TEST_F(NetworkStateNotifierTest, SetNetworkConnectionInfoOverride) { EXPECT_TRUE(notifier_.OnLine()); EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType()); EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth()); + VerifyInitialMetricsWithWebHoldbackState( + kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, + WebEffectiveConnectionType::kType4G, kEthernetHttpRtt, + kEthernetMaxBandwidthMbps, SaveData::kOff); notifier_.ClearOverride(); RunPendingTasks(); @@ -608,6 +656,10 @@ TEST_F(NetworkStateNotifierTest, SetNetworkConnectionInfoOverride) { EXPECT_FALSE(notifier_.OnLine()); EXPECT_EQ(kWebConnectionTypeNone, notifier_.ConnectionType()); EXPECT_EQ(kNoneMaxBandwidthMbps, notifier_.MaxBandwidth()); + VerifyInitialMetricsWithWebHoldbackState( + kWebConnectionTypeNone, kNoneMaxBandwidthMbps, + WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, + kUnknownThroughputMbps, SaveData::kOff); } TEST_F(NetworkStateNotifierTest, SetNetworkQualityInfoOverride) { @@ -626,6 +678,10 @@ TEST_F(NetworkStateNotifierTest, SetNetworkQualityInfoOverride) { EXPECT_TRUE(notifier_.OnLine()); EXPECT_EQ(kWebConnectionTypeBluetooth, notifier_.ConnectionType()); EXPECT_EQ(kBluetoothMaxBandwidthMbps, notifier_.MaxBandwidth()); + VerifyInitialMetricsWithWebHoldbackState( + kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, + WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, + kUnknownThroughputMbps, SaveData::kOff); notifier_.SetNetworkConnectionInfoOverride( true, kWebConnectionTypeOther, WebEffectiveConnectionType::kType3G, @@ -642,6 +698,10 @@ TEST_F(NetworkStateNotifierTest, SetNetworkQualityInfoOverride) { EXPECT_EQ(WebEffectiveConnectionType::kType3G, notifier_.EffectiveType()); EXPECT_EQ(kEthernetHttpRtt, notifier_.HttpRtt()); EXPECT_EQ(kEthernetThroughputMbps, notifier_.DownlinkThroughputMbps()); + VerifyInitialMetricsWithWebHoldbackState( + kWebConnectionTypeOther, kEthernetThroughputMbps.value(), + WebEffectiveConnectionType::kType3G, kEthernetHttpRtt, + kEthernetThroughputMbps, SaveData::kOff); // When override is active, calls to SetConnection are temporary ignored. notifier_.SetOnLine(false); @@ -966,4 +1026,29 @@ TEST_F(NetworkStateNotifierTest, SetNetworkConnectionInfoOverrideGenerateECTs) { } } +// Verify that network state notifier APIs return the correct value when the +// network quality web holdback experiment is enabled. +TEST_F(NetworkStateNotifierTest, SetNetInfoHoldback) { + VerifyInitialMetricsWithWebHoldbackState( + kWebConnectionTypeUnknown, kNoneMaxBandwidthMbps, + WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, + kUnknownThroughputMbps, SaveData::kOff); + + EXPECT_FALSE(notifier_.GetWebHoldbackEffectiveType().has_value()); + EXPECT_FALSE(notifier_.GetWebHoldbackHttpRtt().has_value()); + EXPECT_FALSE(notifier_.GetWebHoldbackDownlinkThroughputMbps().has_value()); + + notifier_.SetNetworkQualityWebHoldback(WebEffectiveConnectionType::kType2G); + VerifyInitialMetricsWithWebHoldbackState( + kWebConnectionTypeUnknown, kNoneMaxBandwidthMbps, + WebEffectiveConnectionType::kType2G, + base::TimeDelta::FromMilliseconds(1800), 0.075, SaveData::kOff); + + EXPECT_EQ(WebEffectiveConnectionType::kType2G, + notifier_.GetWebHoldbackEffectiveType().value()); + EXPECT_EQ(base::TimeDelta::FromMilliseconds(1800), + notifier_.GetWebHoldbackHttpRtt().value()); + EXPECT_EQ(0.075, notifier_.GetWebHoldbackDownlinkThroughputMbps().value()); +} + } // namespace blink diff --git a/chromium/third_party/blink/renderer/platform/network/network_utils.cc b/chromium/third_party/blink/renderer/platform/network/network_utils.cc index a0c34aefe7e..ef4690790df 100644 --- a/chromium/third_party/blink/renderer/platform/network/network_utils.cc +++ b/chromium/third_party/blink/renderer/platform/network/network_utils.cc @@ -13,7 +13,6 @@ #include "net/http/http_util.h" #include "net/url_request/url_request_data_job.h" #include "third_party/blink/public/common/mime_util/mime_util.h" -#include "third_party/blink/public/platform/url_conversion.h" #include "third_party/blink/public/platform/web_string.h" #include "third_party/blink/renderer/platform/loader/fetch/resource_response.h" #include "third_party/blink/renderer/platform/shared_buffer.h" @@ -79,8 +78,7 @@ scoped_refptr<SharedBuffer> ParseDataURLAndPopulateResponse( new net::HttpResponseHeaders(std::string())); int result = net::URLRequestDataJob::BuildResponse( - WebStringToGURL(url.GetString()), &utf8_mime_type, &utf8_charset, - &data_string, headers.get()); + GURL(url), &utf8_mime_type, &utf8_charset, &data_string, headers.get()); if (result != net::OK) return nullptr; @@ -109,8 +107,7 @@ scoped_refptr<SharedBuffer> ParseDataURLAndPopulateResponse( bool IsDataURLMimeTypeSupported(const KURL& url) { std::string utf8_mime_type; std::string utf8_charset; - if (net::DataURL::Parse(WebStringToGURL(url.GetString()), &utf8_mime_type, - &utf8_charset, nullptr)) { + if (net::DataURL::Parse(GURL(url), &utf8_mime_type, &utf8_charset, nullptr)) { return blink::IsSupportedMimeType(utf8_mime_type); } return false; diff --git a/chromium/third_party/blink/renderer/platform/network/parsed_content_header_field_parameters.h b/chromium/third_party/blink/renderer/platform/network/parsed_content_header_field_parameters.h index 99f1cc9bea8..ce19c47e28a 100644 --- a/chromium/third_party/blink/renderer/platform/network/parsed_content_header_field_parameters.h +++ b/chromium/third_party/blink/renderer/platform/network/parsed_content_header_field_parameters.h @@ -19,7 +19,7 @@ class HeaderFieldTokenizer; // them. It is used internally by ParsedContent* classes. // FIXME: add support for comments. class PLATFORM_EXPORT ParsedContentHeaderFieldParameters final { - DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); + DISALLOW_NEW(); public: struct NameValue { |