spanification: WebAssociatedURLLoaderClient
Pass a span<const char> to DidReceiveData(). Bug: 351564777 Change-Id: Iccf9c41cf7af89b913870ba60acff5e18fe29114 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5829129 Commit-Queue: Fredrik Söderquist <fs@opera.com> Reviewed-by: Derek Schuff <dschuff@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Dave Tapuska <dtapuska@chromium.org> Cr-Commit-Position: refs/heads/main@{#1351934}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
5f63052ea6
commit
c2e890261e
components/nacl/renderer
file_downloader.ccfile_downloader.hmanifest_downloader.ccmanifest_downloader.hppb_nacl_private_impl.cc
content/renderer/pepper
pepper_plugin_instance_impl.ccpepper_plugin_instance_impl.hpepper_url_loader_host.ccpepper_url_loader_host.hpepper_webplugin_impl.cc
pdf/loader
third_party/blink
public
renderer
core
exported
loader
modules
image_downloader
platform
@ -50,14 +50,13 @@ void FileDownloader::DidReceiveResponse(const blink::WebURLResponse& response) {
|
|||||||
progress_cb_.Run(total_bytes_received_, total_bytes_to_be_received_);
|
progress_cb_.Run(total_bytes_received_, total_bytes_to_be_received_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileDownloader::DidReceiveData(const char* data, int data_length) {
|
void FileDownloader::DidReceiveData(base::span<const char> data) {
|
||||||
if (status_ == SUCCESS) {
|
if (status_ == SUCCESS) {
|
||||||
if (UNSAFE_TODO(file_.Write(total_bytes_received_, data, data_length)) ==
|
if (file_.Write(total_bytes_received_, base::as_bytes(data)) == -1) {
|
||||||
-1) {
|
|
||||||
status_ = FAILED;
|
status_ = FAILED;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
total_bytes_received_ += data_length;
|
total_bytes_received_ += data.size();
|
||||||
if (!progress_cb_.is_null())
|
if (!progress_cb_.is_null())
|
||||||
progress_cb_.Run(total_bytes_received_, total_bytes_to_be_received_);
|
progress_cb_.Run(total_bytes_received_, total_bytes_to_be_received_);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ class FileDownloader : public blink::WebAssociatedURLLoaderClient {
|
|||||||
private:
|
private:
|
||||||
// WebAssociatedURLLoaderClient implementation.
|
// WebAssociatedURLLoaderClient implementation.
|
||||||
void DidReceiveResponse(const blink::WebURLResponse& response) override;
|
void DidReceiveResponse(const blink::WebURLResponse& response) override;
|
||||||
void DidReceiveData(const char* data, int data_length) override;
|
void DidReceiveData(base::span<const char> data) override;
|
||||||
void DidFinishLoading() override;
|
void DidFinishLoading() override;
|
||||||
void DidFail(const blink::WebURLError& error) override;
|
void DidFail(const blink::WebURLError& error) override;
|
||||||
|
|
||||||
|
@ -41,14 +41,14 @@ void ManifestDownloader::DidReceiveResponse(
|
|||||||
status_code_ = response.HttpStatusCode();
|
status_code_ = response.HttpStatusCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManifestDownloader::DidReceiveData(const char* data, int data_length) {
|
void ManifestDownloader::DidReceiveData(base::span<const char> data) {
|
||||||
if (buffer_.size() + data_length > kNaClManifestMaxFileBytes) {
|
if (buffer_.size() + data.size() > kNaClManifestMaxFileBytes) {
|
||||||
pp_nacl_error_ = PP_NACL_ERROR_MANIFEST_TOO_LARGE;
|
pp_nacl_error_ = PP_NACL_ERROR_MANIFEST_TOO_LARGE;
|
||||||
buffer_.clear();
|
buffer_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pp_nacl_error_ == PP_NACL_ERROR_LOAD_SUCCESS)
|
if (pp_nacl_error_ == PP_NACL_ERROR_LOAD_SUCCESS)
|
||||||
buffer_.append(data, data_length);
|
buffer_.append(data.data(), data.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManifestDownloader::Close() {
|
void ManifestDownloader::Close() {
|
||||||
|
@ -48,7 +48,7 @@ class ManifestDownloader : public blink::WebAssociatedURLLoaderClient {
|
|||||||
|
|
||||||
// WebAssociatedURLLoaderClient implementation.
|
// WebAssociatedURLLoaderClient implementation.
|
||||||
void DidReceiveResponse(const blink::WebURLResponse& response) override;
|
void DidReceiveResponse(const blink::WebURLResponse& response) override;
|
||||||
void DidReceiveData(const char* data, int data_length) override;
|
void DidReceiveData(base::span<const char> data) override;
|
||||||
void DidFinishLoading() override;
|
void DidFinishLoading() override;
|
||||||
void DidFail(const blink::WebURLError& error) override;
|
void DidFail(const blink::WebURLError& error) override;
|
||||||
|
|
||||||
|
@ -1633,12 +1633,11 @@ class PexeDownloader : public blink::WebAssociatedURLLoaderClient {
|
|||||||
url_loader_->SetDefersLoading(false);
|
url_loader_->SetDefersLoading(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DidReceiveData(const char* data, int data_length) override {
|
void DidReceiveData(base::span<const char> data) override {
|
||||||
if (content::PepperPluginInstance::Get(instance_)) {
|
if (content::PepperPluginInstance::Get(instance_)) {
|
||||||
// Stream the data we received to the stream callback.
|
// Stream the data we received to the stream callback.
|
||||||
stream_handler_->DidStreamData(stream_handler_user_data_,
|
stream_handler_->DidStreamData(stream_handler_user_data_, data.data(),
|
||||||
data,
|
base::checked_cast<int32_t>(data.size()));
|
||||||
data_length);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,7 +443,7 @@ PepperPluginInstanceImpl::ExternalDocumentLoader::~ExternalDocumentLoader() {}
|
|||||||
void PepperPluginInstanceImpl::ExternalDocumentLoader::ReplayReceivedData(
|
void PepperPluginInstanceImpl::ExternalDocumentLoader::ReplayReceivedData(
|
||||||
WebAssociatedURLLoaderClient* document_loader) {
|
WebAssociatedURLLoaderClient* document_loader) {
|
||||||
for (auto it = data_.begin(); it != data_.end(); ++it) {
|
for (auto it = data_.begin(); it != data_.end(); ++it) {
|
||||||
document_loader->DidReceiveData(it->c_str(), it->length());
|
document_loader->DidReceiveData(*it);
|
||||||
}
|
}
|
||||||
if (finished_loading_) {
|
if (finished_loading_) {
|
||||||
document_loader->DidFinishLoading();
|
document_loader->DidFinishLoading();
|
||||||
@ -454,9 +454,8 @@ void PepperPluginInstanceImpl::ExternalDocumentLoader::ReplayReceivedData(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PepperPluginInstanceImpl::ExternalDocumentLoader::DidReceiveData(
|
void PepperPluginInstanceImpl::ExternalDocumentLoader::DidReceiveData(
|
||||||
const char* data,
|
base::span<const char> data) {
|
||||||
int data_length) {
|
data_.push_back(std::string(data.data(), data.size()));
|
||||||
data_.push_back(std::string(data, data_length));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PepperPluginInstanceImpl::ExternalDocumentLoader::DidFinishLoading() {
|
void PepperPluginInstanceImpl::ExternalDocumentLoader::DidFinishLoading() {
|
||||||
|
@ -478,7 +478,7 @@ class CONTENT_EXPORT PepperPluginInstanceImpl
|
|||||||
void ReplayReceivedData(WebAssociatedURLLoaderClient* document_loader);
|
void ReplayReceivedData(WebAssociatedURLLoaderClient* document_loader);
|
||||||
|
|
||||||
// blink::WebAssociatedURLLoaderClient implementation.
|
// blink::WebAssociatedURLLoaderClient implementation.
|
||||||
void DidReceiveData(const char* data, int data_length) override;
|
void DidReceiveData(base::span<const char> data) override;
|
||||||
void DidFinishLoading() override;
|
void DidFinishLoading() override;
|
||||||
void DidFail(const blink::WebURLError& error) override;
|
void DidFail(const blink::WebURLError& error) override;
|
||||||
|
|
||||||
|
@ -178,13 +178,13 @@ void PepperURLLoaderHost::DidDownloadData(uint64_t data_length) {
|
|||||||
UpdateProgress();
|
UpdateProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PepperURLLoaderHost::DidReceiveData(const char* data, int data_length) {
|
void PepperURLLoaderHost::DidReceiveData(base::span<const char> data) {
|
||||||
// Note that |loader| will be NULL for document loads.
|
// Note that |loader| will be NULL for document loads.
|
||||||
bytes_received_ += data_length;
|
bytes_received_ += data.size();
|
||||||
UpdateProgress();
|
UpdateProgress();
|
||||||
|
|
||||||
auto message = std::make_unique<PpapiPluginMsg_URLLoader_SendData>();
|
auto message = std::make_unique<PpapiPluginMsg_URLLoader_SendData>();
|
||||||
message->WriteData(data, base::checked_cast<size_t>(data_length));
|
message->WriteData(data.data(), data.size());
|
||||||
SendUpdateToPlugin(std::move(message));
|
SendUpdateToPlugin(std::move(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ class PepperURLLoaderHost : public ppapi::host::ResourceHost,
|
|||||||
uint64_t total_bytes_to_be_sent) override;
|
uint64_t total_bytes_to_be_sent) override;
|
||||||
void DidReceiveResponse(const blink::WebURLResponse& response) override;
|
void DidReceiveResponse(const blink::WebURLResponse& response) override;
|
||||||
void DidDownloadData(uint64_t data_length) override;
|
void DidDownloadData(uint64_t data_length) override;
|
||||||
void DidReceiveData(const char* data, int data_length) override;
|
void DidReceiveData(base::span<const char> data) override;
|
||||||
void DidFinishLoading() override;
|
void DidFinishLoading() override;
|
||||||
void DidFail(const blink::WebURLError& error) override;
|
void DidFail(const blink::WebURLError& error) override;
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ void PepperWebPluginImpl::DidReceiveData(base::span<const char> data) {
|
|||||||
blink::WebAssociatedURLLoaderClient* document_loader =
|
blink::WebAssociatedURLLoaderClient* document_loader =
|
||||||
instance_->document_loader();
|
instance_->document_loader();
|
||||||
if (document_loader)
|
if (document_loader)
|
||||||
document_loader->DidReceiveData(data.data(), data.size());
|
document_loader->DidReceiveData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PepperWebPluginImpl::DidFinishLoading() {
|
void PepperWebPluginImpl::DidFinishLoading() {
|
||||||
|
@ -209,15 +209,15 @@ void UrlLoader::DidDownloadData(uint64_t data_length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Modeled on `content::PepperURLLoaderHost::DidReceiveData()`.
|
// Modeled on `content::PepperURLLoaderHost::DidReceiveData()`.
|
||||||
void UrlLoader::DidReceiveData(const char* data, int data_length) {
|
void UrlLoader::DidReceiveData(base::span<const char> data) {
|
||||||
DCHECK_EQ(state_, LoadingState::kStreamingData);
|
DCHECK_EQ(state_, LoadingState::kStreamingData);
|
||||||
|
|
||||||
// It's surprisingly difficult to guarantee that this is always >0.
|
// It's surprisingly difficult to guarantee that this is always >0.
|
||||||
if (data_length < 1)
|
if (data.empty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(crbug.com/40284755): spanify to fix the errors.
|
buffer_.insert(buffer_.end(), data.begin(), data.end());
|
||||||
buffer_.insert(buffer_.end(), data, UNSAFE_TODO(data + data_length));
|
|
||||||
|
|
||||||
// Defer loading if the buffer is too full.
|
// Defer loading if the buffer is too full.
|
||||||
if (!deferring_loading_ && buffer_.size() >= buffer_upper_threshold_) {
|
if (!deferring_loading_ && buffer_.size() >= buffer_upper_threshold_) {
|
||||||
|
@ -144,7 +144,7 @@ class UrlLoader final : public blink::WebAssociatedURLLoaderClient {
|
|||||||
uint64_t total_bytes_to_be_sent) override;
|
uint64_t total_bytes_to_be_sent) override;
|
||||||
void DidReceiveResponse(const blink::WebURLResponse& response) override;
|
void DidReceiveResponse(const blink::WebURLResponse& response) override;
|
||||||
void DidDownloadData(uint64_t data_length) override;
|
void DidDownloadData(uint64_t data_length) override;
|
||||||
void DidReceiveData(const char* data, int data_length) override;
|
void DidReceiveData(base::span<const char> data) override;
|
||||||
void DidFinishLoading() override;
|
void DidFinishLoading() override;
|
||||||
void DidFail(const blink::WebURLError& error) override;
|
void DidFail(const blink::WebURLError& error) override;
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ TEST_F(UrlLoaderTest, DidReceiveData) {
|
|||||||
loader_->ReadResponseBody(buffer, mock_callback_.Get());
|
loader_->ReadResponseBody(buffer, mock_callback_.Get());
|
||||||
EXPECT_CALL(mock_callback_, Run(kFakeData.size()));
|
EXPECT_CALL(mock_callback_, Run(kFakeData.size()));
|
||||||
|
|
||||||
loader_->DidReceiveData(kFakeData.data(), kFakeData.size());
|
loader_->DidReceiveData(kFakeData);
|
||||||
|
|
||||||
EXPECT_THAT(buffer, ElementsAreArray(kFakeData));
|
EXPECT_THAT(buffer, ElementsAreArray(kFakeData));
|
||||||
}
|
}
|
||||||
@ -336,7 +336,7 @@ TEST_F(UrlLoaderTest, DidReceiveDataWithZeroLength) {
|
|||||||
loader_->ReadResponseBody(buffer, mock_callback_.Get());
|
loader_->ReadResponseBody(buffer, mock_callback_.Get());
|
||||||
EXPECT_CALL(mock_callback_, Run).Times(0);
|
EXPECT_CALL(mock_callback_, Run).Times(0);
|
||||||
|
|
||||||
loader_->DidReceiveData(kFakeData.data(), 0);
|
loader_->DidReceiveData(kFakeData.first(0u));
|
||||||
|
|
||||||
EXPECT_THAT(buffer, Each(0));
|
EXPECT_THAT(buffer, Each(0));
|
||||||
}
|
}
|
||||||
@ -346,7 +346,7 @@ TEST_F(UrlLoaderTest, DidReceiveDataBelowUpperThreshold) {
|
|||||||
EXPECT_CALL(*mock_url_loader_, SetDefersLoading).Times(0);
|
EXPECT_CALL(*mock_url_loader_, SetDefersLoading).Times(0);
|
||||||
|
|
||||||
char buffer[3] = {};
|
char buffer[3] = {};
|
||||||
loader_->DidReceiveData(buffer, sizeof(buffer));
|
loader_->DidReceiveData(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UrlLoaderTest, DidReceiveDataCrossUpperThreshold) {
|
TEST_F(UrlLoaderTest, DidReceiveDataCrossUpperThreshold) {
|
||||||
@ -361,23 +361,23 @@ TEST_F(UrlLoaderTest, DidReceiveDataCrossUpperThreshold) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char buffer[4] = {};
|
char buffer[4] = {};
|
||||||
loader_->DidReceiveData(buffer, sizeof(buffer));
|
loader_->DidReceiveData(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UrlLoaderTest, DidReceiveDataAboveUpperThreshold) {
|
TEST_F(UrlLoaderTest, DidReceiveDataAboveUpperThreshold) {
|
||||||
StartLoadWithThresholds(/*lower=*/2, /*upper=*/4);
|
StartLoadWithThresholds(/*lower=*/2, /*upper=*/4);
|
||||||
|
|
||||||
char buffer[4] = {};
|
char buffer[4] = {};
|
||||||
loader_->DidReceiveData(buffer, sizeof(buffer));
|
loader_->DidReceiveData(buffer);
|
||||||
EXPECT_CALL(*mock_url_loader_, SetDefersLoading).Times(0);
|
EXPECT_CALL(*mock_url_loader_, SetDefersLoading).Times(0);
|
||||||
|
|
||||||
loader_->DidReceiveData(buffer, sizeof(buffer));
|
loader_->DidReceiveData(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UrlLoaderTest, ReadResponseBody) {
|
TEST_F(UrlLoaderTest, ReadResponseBody) {
|
||||||
loader_->Open(UrlRequest(), mock_callback_.Get());
|
loader_->Open(UrlRequest(), mock_callback_.Get());
|
||||||
loader_->DidReceiveResponse(blink::WebURLResponse());
|
loader_->DidReceiveResponse(blink::WebURLResponse());
|
||||||
loader_->DidReceiveData(kFakeData.data(), kFakeData.size());
|
loader_->DidReceiveData(kFakeData);
|
||||||
EXPECT_CALL(mock_callback_, Run(kFakeData.size()));
|
EXPECT_CALL(mock_callback_, Run(kFakeData.size()));
|
||||||
|
|
||||||
char buffer[kFakeData.size()] = {};
|
char buffer[kFakeData.size()] = {};
|
||||||
@ -415,7 +415,7 @@ TEST_F(UrlLoaderTest, ReadResponseBodyWithSmallerBuffer) {
|
|||||||
|
|
||||||
loader_->Open(UrlRequest(), mock_callback_.Get());
|
loader_->Open(UrlRequest(), mock_callback_.Get());
|
||||||
loader_->DidReceiveResponse(blink::WebURLResponse());
|
loader_->DidReceiveResponse(blink::WebURLResponse());
|
||||||
loader_->DidReceiveData(kFakeData.data(), kFakeData.size());
|
loader_->DidReceiveData(kFakeData);
|
||||||
EXPECT_CALL(mock_callback_, Run(kBufferSize));
|
EXPECT_CALL(mock_callback_, Run(kBufferSize));
|
||||||
|
|
||||||
char buffer[kBufferSize] = {};
|
char buffer[kBufferSize] = {};
|
||||||
@ -433,7 +433,7 @@ TEST_F(UrlLoaderTest, ReadResponseBodyWithSmallerBuffer) {
|
|||||||
TEST_F(UrlLoaderTest, ReadResponseBodyWithBiggerBuffer) {
|
TEST_F(UrlLoaderTest, ReadResponseBodyWithBiggerBuffer) {
|
||||||
loader_->Open(UrlRequest(), mock_callback_.Get());
|
loader_->Open(UrlRequest(), mock_callback_.Get());
|
||||||
loader_->DidReceiveResponse(blink::WebURLResponse());
|
loader_->DidReceiveResponse(blink::WebURLResponse());
|
||||||
loader_->DidReceiveData(kFakeData.data(), kFakeData.size());
|
loader_->DidReceiveData(kFakeData);
|
||||||
EXPECT_CALL(mock_callback_, Run(kFakeData.size()));
|
EXPECT_CALL(mock_callback_, Run(kFakeData.size()));
|
||||||
|
|
||||||
char buffer[kFakeData.size() + 1] = {};
|
char buffer[kFakeData.size() + 1] = {};
|
||||||
@ -451,7 +451,7 @@ TEST_F(UrlLoaderTest, ReadResponseBodyWithBiggerBuffer) {
|
|||||||
TEST_F(UrlLoaderTest, ReadResponseBodyWhileLoadComplete) {
|
TEST_F(UrlLoaderTest, ReadResponseBodyWhileLoadComplete) {
|
||||||
loader_->Open(UrlRequest(), mock_callback_.Get());
|
loader_->Open(UrlRequest(), mock_callback_.Get());
|
||||||
loader_->DidReceiveResponse(blink::WebURLResponse());
|
loader_->DidReceiveResponse(blink::WebURLResponse());
|
||||||
loader_->DidReceiveData(kFakeData.data(), kFakeData.size());
|
loader_->DidReceiveData(kFakeData);
|
||||||
loader_->DidFinishLoading();
|
loader_->DidFinishLoading();
|
||||||
EXPECT_CALL(mock_callback_, Run(kFakeData.size()));
|
EXPECT_CALL(mock_callback_, Run(kFakeData.size()));
|
||||||
|
|
||||||
@ -482,7 +482,7 @@ TEST_F(UrlLoaderTest, ReadResponseBodyWhileLoadCompleteWithoutData) {
|
|||||||
TEST_F(UrlLoaderTest, ReadResponseBodyWhileLoadCompleteWithError) {
|
TEST_F(UrlLoaderTest, ReadResponseBodyWhileLoadCompleteWithError) {
|
||||||
loader_->Open(UrlRequest(), mock_callback_.Get());
|
loader_->Open(UrlRequest(), mock_callback_.Get());
|
||||||
loader_->DidReceiveResponse(blink::WebURLResponse());
|
loader_->DidReceiveResponse(blink::WebURLResponse());
|
||||||
loader_->DidReceiveData(kFakeData.data(), kFakeData.size());
|
loader_->DidReceiveData(kFakeData);
|
||||||
loader_->DidFail(MakeWebURLError(net::ERR_FAILED));
|
loader_->DidFail(MakeWebURLError(net::ERR_FAILED));
|
||||||
EXPECT_CALL(mock_callback_, Run(Result::kErrorFailed));
|
EXPECT_CALL(mock_callback_, Run(Result::kErrorFailed));
|
||||||
|
|
||||||
@ -496,7 +496,7 @@ TEST_F(UrlLoaderTest, ReadResponseBodyAboveLowerThreshold) {
|
|||||||
StartLoadWithThresholds(/*lower=*/2, /*upper=*/4);
|
StartLoadWithThresholds(/*lower=*/2, /*upper=*/4);
|
||||||
|
|
||||||
char write_buffer[5] = {};
|
char write_buffer[5] = {};
|
||||||
loader_->DidReceiveData(write_buffer, sizeof(write_buffer));
|
loader_->DidReceiveData(write_buffer);
|
||||||
EXPECT_CALL(*mock_url_loader_, SetDefersLoading).Times(0);
|
EXPECT_CALL(*mock_url_loader_, SetDefersLoading).Times(0);
|
||||||
|
|
||||||
char buffer[2] = {};
|
char buffer[2] = {};
|
||||||
@ -507,7 +507,7 @@ TEST_F(UrlLoaderTest, ReadResponseBodyCrossLowerThreshold) {
|
|||||||
StartLoadWithThresholds(/*lower=*/2, /*upper=*/4);
|
StartLoadWithThresholds(/*lower=*/2, /*upper=*/4);
|
||||||
|
|
||||||
char write_buffer[5] = {};
|
char write_buffer[5] = {};
|
||||||
loader_->DidReceiveData(write_buffer, sizeof(write_buffer));
|
loader_->DidReceiveData(write_buffer);
|
||||||
{
|
{
|
||||||
InSequence resume_before_read_callback;
|
InSequence resume_before_read_callback;
|
||||||
EXPECT_CALL(*mock_url_loader_, SetDefersLoading(false));
|
EXPECT_CALL(*mock_url_loader_, SetDefersLoading(false));
|
||||||
@ -522,7 +522,7 @@ TEST_F(UrlLoaderTest, ReadResponseBodyBelowLowerThreshold) {
|
|||||||
StartLoadWithThresholds(/*lower=*/2, /*upper=*/4);
|
StartLoadWithThresholds(/*lower=*/2, /*upper=*/4);
|
||||||
|
|
||||||
char write_buffer[5] = {};
|
char write_buffer[5] = {};
|
||||||
loader_->DidReceiveData(write_buffer, sizeof(write_buffer));
|
loader_->DidReceiveData(write_buffer);
|
||||||
|
|
||||||
char buffer[3] = {};
|
char buffer[3] = {};
|
||||||
loader_->ReadResponseBody(buffer, mock_callback_.Get());
|
loader_->ReadResponseBody(buffer, mock_callback_.Get());
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
#ifndef THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_ASSOCIATED_URL_LOADER_CLIENT_H_
|
#ifndef THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_ASSOCIATED_URL_LOADER_CLIENT_H_
|
||||||
#define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_ASSOCIATED_URL_LOADER_CLIENT_H_
|
#define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_ASSOCIATED_URL_LOADER_CLIENT_H_
|
||||||
|
|
||||||
|
#include "base/containers/span.h"
|
||||||
|
|
||||||
namespace blink {
|
namespace blink {
|
||||||
|
|
||||||
class WebURL;
|
class WebURL;
|
||||||
@ -21,7 +23,7 @@ class WebAssociatedURLLoaderClient {
|
|||||||
uint64_t total_bytes_to_be_sent) {}
|
uint64_t total_bytes_to_be_sent) {}
|
||||||
virtual void DidReceiveResponse(const WebURLResponse&) {}
|
virtual void DidReceiveResponse(const WebURLResponse&) {}
|
||||||
virtual void DidDownloadData(uint64_t data_length) {}
|
virtual void DidDownloadData(uint64_t data_length) {}
|
||||||
virtual void DidReceiveData(const char* data, int data_length) {}
|
virtual void DidReceiveData(base::span<const char> data) {}
|
||||||
virtual void DidFinishLoading() {}
|
virtual void DidFinishLoading() {}
|
||||||
virtual void DidFail(const WebURLError&) {}
|
virtual void DidFail(const WebURLError&) {}
|
||||||
|
|
||||||
|
@ -826,8 +826,7 @@ class WebMediaPlayerImplTest
|
|||||||
client->DidReceiveResponse(response);
|
client->DidReceiveResponse(response);
|
||||||
|
|
||||||
// Copy over the file data.
|
// Copy over the file data.
|
||||||
client->DidReceiveData(reinterpret_cast<const char*>(data->data()),
|
client->DidReceiveData(base::as_chars(data->AsSpan()));
|
||||||
static_cast<int>(data->size()));
|
|
||||||
|
|
||||||
// If we're pretending to be a streaming resource, don't complete the load;
|
// If we're pretending to be a streaming resource, don't complete the load;
|
||||||
// otherwise the DataSource will not be marked as streaming.
|
// otherwise the DataSource will not be marked as streaming.
|
||||||
|
@ -259,7 +259,7 @@ void WebAssociatedURLLoaderImpl::ClientAdapter::DidReceiveData(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
client_->DidReceiveData(data.data(), base::checked_cast<int>(data.size()));
|
client_->DidReceiveData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebAssociatedURLLoaderImpl::ClientAdapter::DidFinishLoading(
|
void WebAssociatedURLLoaderImpl::ClientAdapter::DidFinishLoading(
|
||||||
|
@ -155,10 +155,10 @@ class WebAssociatedURLLoaderTest : public testing::Test,
|
|||||||
did_download_data_ = true;
|
did_download_data_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DidReceiveData(const char* data, int data_length) override {
|
void DidReceiveData(base::span<const char> data) override {
|
||||||
did_receive_data_ = true;
|
did_receive_data_ = true;
|
||||||
EXPECT_TRUE(data);
|
EXPECT_TRUE(data.data());
|
||||||
EXPECT_GT(data_length, 0);
|
EXPECT_GT(data.size(), 0u);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DidFinishLoading() override { did_finish_loading_ = true; }
|
void DidFinishLoading() override { did_finish_loading_ = true; }
|
||||||
|
6
third_party/blink/renderer/modules/image_downloader/multi_resolution_image_resource_fetcher.cc
vendored
6
third_party/blink/renderer/modules/image_downloader/multi_resolution_image_resource_fetcher.cc
vendored
@ -69,14 +69,14 @@ class MultiResolutionImageResourceFetcher::ClientImpl
|
|||||||
DCHECK(!completed_);
|
DCHECK(!completed_);
|
||||||
response_ = response;
|
response_ = response;
|
||||||
}
|
}
|
||||||
void DidReceiveData(const char* data, int data_length) override {
|
void DidReceiveData(base::span<const char> data) override {
|
||||||
// The WebAssociatedURLLoader will continue after a load failure.
|
// The WebAssociatedURLLoader will continue after a load failure.
|
||||||
// For example, for an Access Control error.
|
// For example, for an Access Control error.
|
||||||
if (completed_)
|
if (completed_)
|
||||||
return;
|
return;
|
||||||
DCHECK_GT(data_length, 0);
|
DCHECK_GT(data.size(), 0u);
|
||||||
|
|
||||||
data_.append(data, data_length);
|
data_.append(data.data(), data.size());
|
||||||
}
|
}
|
||||||
void DidFinishLoading() override {
|
void DidFinishLoading() override {
|
||||||
// The WebAssociatedURLLoader will continue after a load failure.
|
// The WebAssociatedURLLoader will continue after a load failure.
|
||||||
|
@ -342,7 +342,7 @@ class MultiBufferDataSourceTest : public testing::Test {
|
|||||||
auto data = base::HeapArray<char>::Uninit(size);
|
auto data = base::HeapArray<char>::Uninit(size);
|
||||||
memset(data.data(), 0xA5, size); // Arbitrary non-zero value.
|
memset(data.data(), 0xA5, size); // Arbitrary non-zero value.
|
||||||
|
|
||||||
data_provider()->DidReceiveData(data.data(), size);
|
data_provider()->DidReceiveData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReceiveData(int size) {
|
void ReceiveData(int size) {
|
||||||
|
@ -379,26 +379,26 @@ void ResourceMultiBufferDataProvider::DidReceiveResponse(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceMultiBufferDataProvider::DidReceiveData(const char* data,
|
void ResourceMultiBufferDataProvider::DidReceiveData(
|
||||||
int data_length) {
|
base::span<const char> data) {
|
||||||
DVLOG(1) << "didReceiveData: " << data_length << " bytes";
|
DVLOG(1) << "didReceiveData: " << data.size() << " bytes";
|
||||||
DCHECK(!Available());
|
DCHECK(!Available());
|
||||||
DCHECK(active_loader_);
|
DCHECK(active_loader_);
|
||||||
DCHECK_GT(data_length, 0);
|
DCHECK_GT(data.size(), 0u);
|
||||||
|
|
||||||
if (bytes_to_discard_) {
|
if (bytes_to_discard_) {
|
||||||
uint64_t tmp = std::min<uint64_t>(bytes_to_discard_, data_length);
|
uint64_t tmp = std::min<uint64_t>(bytes_to_discard_, data.size());
|
||||||
data_length -= tmp;
|
data = data.subspan(static_cast<size_t>(tmp));
|
||||||
data += tmp;
|
|
||||||
bytes_to_discard_ -= tmp;
|
bytes_to_discard_ -= tmp;
|
||||||
if (data_length == 0)
|
if (data.empty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When we receive data, we allow more retries.
|
// When we receive data, we allow more retries.
|
||||||
retries_ = 0;
|
retries_ = 0;
|
||||||
|
|
||||||
while (data_length) {
|
while (!data.empty()) {
|
||||||
if (fifo_.empty() || fifo_.back()->data_size() == block_size()) {
|
if (fifo_.empty() || fifo_.back()->data_size() == block_size()) {
|
||||||
fifo_.push_back(base::MakeRefCounted<media::DataBuffer>(
|
fifo_.push_back(base::MakeRefCounted<media::DataBuffer>(
|
||||||
static_cast<int>(block_size())));
|
static_cast<int>(block_size())));
|
||||||
@ -406,13 +406,12 @@ void ResourceMultiBufferDataProvider::DidReceiveData(const char* data,
|
|||||||
}
|
}
|
||||||
int last_block_size = fifo_.back()->data_size();
|
int last_block_size = fifo_.back()->data_size();
|
||||||
auto to_append =
|
auto to_append =
|
||||||
std::min<int64_t>(data_length, block_size() - last_block_size);
|
std::min<int64_t>(data.size(), block_size() - last_block_size);
|
||||||
DCHECK_GT(to_append, 0);
|
DCHECK_GT(to_append, 0);
|
||||||
memcpy(fifo_.back()->writable_data() + last_block_size, data,
|
memcpy(fifo_.back()->writable_data() + last_block_size, data.data(),
|
||||||
static_cast<size_t>(to_append));
|
static_cast<size_t>(to_append));
|
||||||
data += to_append;
|
data = data.subspan(static_cast<size_t>(to_append));
|
||||||
fifo_.back()->set_data_size(static_cast<int>(last_block_size + to_append));
|
fifo_.back()->set_data_size(static_cast<int>(last_block_size + to_append));
|
||||||
data_length -= to_append;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
url_data_->multibuffer()->OnDataProviderEvent(this);
|
url_data_->multibuffer()->OnDataProviderEvent(this);
|
||||||
|
@ -60,7 +60,7 @@ class PLATFORM_EXPORT ResourceMultiBufferDataProvider
|
|||||||
void DidSendData(uint64_t bytesSent, uint64_t totalBytesToBeSent) override;
|
void DidSendData(uint64_t bytesSent, uint64_t totalBytesToBeSent) override;
|
||||||
void DidReceiveResponse(const WebURLResponse& response) override;
|
void DidReceiveResponse(const WebURLResponse& response) override;
|
||||||
void DidDownloadData(uint64_t data_length) override;
|
void DidDownloadData(uint64_t data_length) override;
|
||||||
void DidReceiveData(const char* data, int data_length) override;
|
void DidReceiveData(base::span<const char> data_length) override;
|
||||||
void DidFinishLoading() override;
|
void DidFinishLoading() override;
|
||||||
void DidFail(const WebURLError&) override;
|
void DidFail(const WebURLError&) override;
|
||||||
|
|
||||||
|
5
third_party/blink/renderer/platform/media/resource_multi_buffer_data_provider_unittest.cc
vendored
5
third_party/blink/renderer/platform/media/resource_multi_buffer_data_provider_unittest.cc
vendored
@ -185,12 +185,13 @@ class ResourceMultiBufferDataProviderTest : public testing::Test {
|
|||||||
|
|
||||||
// Helper method to write to |loader_| from |data_|.
|
// Helper method to write to |loader_| from |data_|.
|
||||||
void WriteLoader(int position, int size) {
|
void WriteLoader(int position, int size) {
|
||||||
loader_->DidReceiveData(reinterpret_cast<char*>(data_ + position), size);
|
loader_->DidReceiveData(
|
||||||
|
base::as_chars(base::span(data_).subspan(position, size)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteData(int size) {
|
void WriteData(int size) {
|
||||||
auto data = base::HeapArray<char>::Uninit(size);
|
auto data = base::HeapArray<char>::Uninit(size);
|
||||||
loader_->DidReceiveData(data.data(), size);
|
loader_->DidReceiveData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verifies that data in buffer[0...size] is equal to data_[pos...pos+size].
|
// Verifies that data in buffer[0...size] is equal to data_[pos...pos+size].
|
||||||
|
Reference in New Issue
Block a user