Commit a283e03f authored by Dave Tapuska's avatar Dave Tapuska Committed by Commit Bot

Fix 64 bit truncation errors in platform/loader

Use appropriate types in loader code.

BUG=879657

Change-Id: I43da64c50b4dcdb2cd47a4b6ed45ecd7d87d15fb
Reviewed-on: https://chromium-review.googlesource.com/c/1330352Reviewed-by: default avatarNate Chapin <japhet@chromium.org>
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610454}
parent 3a12ff5e
...@@ -670,7 +670,7 @@ void FrameFetchContext::DispatchDidReceiveResponse( ...@@ -670,7 +670,7 @@ void FrameFetchContext::DispatchDidReceiveResponse(
void FrameFetchContext::DispatchDidReceiveData(unsigned long identifier, void FrameFetchContext::DispatchDidReceiveData(unsigned long identifier,
const char* data, const char* data,
int data_length) { size_t data_length) {
if (IsDetached()) if (IsDetached())
return; return;
...@@ -679,8 +679,9 @@ void FrameFetchContext::DispatchDidReceiveData(unsigned long identifier, ...@@ -679,8 +679,9 @@ void FrameFetchContext::DispatchDidReceiveData(unsigned long identifier,
MasterDocumentLoader(), data, data_length); MasterDocumentLoader(), data, data_length);
} }
void FrameFetchContext::DispatchDidReceiveEncodedData(unsigned long identifier, void FrameFetchContext::DispatchDidReceiveEncodedData(
int encoded_data_length) { unsigned long identifier,
size_t encoded_data_length) {
if (IsDetached()) if (IsDetached())
return; return;
probe::didReceiveEncodedDataLength(GetFrame()->GetDocument(), probe::didReceiveEncodedDataLength(GetFrame()->GetDocument(),
......
...@@ -114,9 +114,9 @@ class CORE_EXPORT FrameFetchContext final : public BaseFetchContext { ...@@ -114,9 +114,9 @@ class CORE_EXPORT FrameFetchContext final : public BaseFetchContext {
ResourceResponseType) override; ResourceResponseType) override;
void DispatchDidReceiveData(unsigned long identifier, void DispatchDidReceiveData(unsigned long identifier,
const char* data, const char* data,
int data_length) override; size_t data_length) override;
void DispatchDidReceiveEncodedData(unsigned long identifier, void DispatchDidReceiveEncodedData(unsigned long identifier,
int encoded_data_length) override; size_t encoded_data_length) override;
void DispatchDidDownloadToBlob(unsigned long identifier, void DispatchDidDownloadToBlob(unsigned long identifier,
BlobDataHandle*) override; BlobDataHandle*) override;
void DispatchDidFinishLoading(unsigned long identifier, void DispatchDidFinishLoading(unsigned long identifier,
......
...@@ -308,13 +308,13 @@ void WorkerFetchContext::DispatchDidReceiveResponse( ...@@ -308,13 +308,13 @@ void WorkerFetchContext::DispatchDidReceiveResponse(
void WorkerFetchContext::DispatchDidReceiveData(unsigned long identifier, void WorkerFetchContext::DispatchDidReceiveData(unsigned long identifier,
const char* data, const char* data,
int data_length) { size_t data_length) {
probe::didReceiveData(global_scope_, identifier, nullptr, data, data_length); probe::didReceiveData(global_scope_, identifier, nullptr, data, data_length);
} }
void WorkerFetchContext::DispatchDidReceiveEncodedData( void WorkerFetchContext::DispatchDidReceiveEncodedData(
unsigned long identifier, unsigned long identifier,
int encoded_data_length) { size_t encoded_data_length) {
probe::didReceiveEncodedDataLength(global_scope_, nullptr, identifier, probe::didReceiveEncodedDataLength(global_scope_, nullptr, identifier,
encoded_data_length); encoded_data_length);
} }
......
...@@ -94,9 +94,9 @@ class WorkerFetchContext final : public BaseFetchContext { ...@@ -94,9 +94,9 @@ class WorkerFetchContext final : public BaseFetchContext {
ResourceResponseType) override; ResourceResponseType) override;
void DispatchDidReceiveData(unsigned long identifier, void DispatchDidReceiveData(unsigned long identifier,
const char* data, const char* data,
int dataLength) override; size_t data_length) override;
void DispatchDidReceiveEncodedData(unsigned long identifier, void DispatchDidReceiveEncodedData(unsigned long identifier,
int encoded_data_length) override; size_t encoded_data_length) override;
void DispatchDidFinishLoading(unsigned long identifier, void DispatchDidFinishLoading(unsigned long identifier,
TimeTicks finish_time, TimeTicks finish_time,
int64_t encoded_data_length, int64_t encoded_data_length,
......
...@@ -63,7 +63,7 @@ String GetErrorString(const network::CorsErrorStatus& status, ...@@ -63,7 +63,7 @@ String GetErrorString(const network::CorsErrorStatus& status,
using CorsError = network::mojom::CorsError; using CorsError = network::mojom::CorsError;
const StringView hint(status.failed_parameter.data(), const StringView hint(status.failed_parameter.data(),
status.failed_parameter.size()); SafeCast<wtf_size_t>(status.failed_parameter.size()));
const char* resource_kind_raw = const char* resource_kind_raw =
Resource::ResourceTypeToString(resource_type, initiator_name); Resource::ResourceTypeToString(resource_type, initiator_name);
......
...@@ -36,7 +36,7 @@ class PLATFORM_EXPORT BufferingDataPipeWriter { ...@@ -36,7 +36,7 @@ class PLATFORM_EXPORT BufferingDataPipeWriter {
mojo::ScopedDataPipeProducerHandle handle_; mojo::ScopedDataPipeProducerHandle handle_;
mojo::SimpleWatcher watcher_; mojo::SimpleWatcher watcher_;
Deque<Vector<char>> buffer_; Deque<Vector<char>> buffer_;
size_t front_written_size_ = 0; wtf_size_t front_written_size_ = 0;
bool waiting_ = false; bool waiting_ = false;
bool finished_ = false; bool finished_ = false;
}; };
......
...@@ -31,21 +31,21 @@ TEST(BufferingDataPipeWriterTest, WriteMany) { ...@@ -31,21 +31,21 @@ TEST(BufferingDataPipeWriterTest, WriteMany) {
MojoResult result = mojo::CreateDataPipe(&options, &producer, &consumer); MojoResult result = mojo::CreateDataPipe(&options, &producer, &consumer);
ASSERT_EQ(MOJO_RESULT_OK, result); ASSERT_EQ(MOJO_RESULT_OK, result);
constexpr size_t total = kCapacity * 3; constexpr wtf_size_t total = kCapacity * 3;
constexpr size_t writing_chunk_size = 5; constexpr wtf_size_t writing_chunk_size = 5;
constexpr size_t reading_chunk_size = 7; constexpr wtf_size_t reading_chunk_size = 7;
Vector<char> input, output; Vector<char> input, output;
for (size_t i = 0; i < total; ++i) for (wtf_size_t i = 0; i < total; ++i)
input.push_back(static_cast<char>(engine() % 26 + 'A')); input.push_back(static_cast<char>(engine() % 26 + 'A'));
auto writer = std::make_unique<BufferingDataPipeWriter>( auto writer = std::make_unique<BufferingDataPipeWriter>(
std::move(producer), platform->test_task_runner().get()); std::move(producer), platform->test_task_runner().get());
for (size_t i = 0; i < total;) { for (wtf_size_t i = 0; i < total;) {
// We use a temporary buffer to check that the buffer is copied immediately. // We use a temporary buffer to check that the buffer is copied immediately.
char temp[writing_chunk_size] = {}; char temp[writing_chunk_size] = {};
size_t size = std::min(total - i, writing_chunk_size); wtf_size_t size = std::min(total - i, writing_chunk_size);
std::copy(input.data() + i, input.data() + i + size, temp); std::copy(input.data() + i, input.data() + i + size, temp);
ASSERT_TRUE(writer->Write(temp, size)); ASSERT_TRUE(writer->Write(temp, size));
......
...@@ -12,7 +12,8 @@ scoped_refptr<CachedMetadata> CachedMetadata::CreateFromSerializedData( ...@@ -12,7 +12,8 @@ scoped_refptr<CachedMetadata> CachedMetadata::CreateFromSerializedData(
const char* data, const char* data,
size_t size) { size_t size) {
// Ensure the data is big enough, otherwise discard the data. // Ensure the data is big enough, otherwise discard the data.
if (size < kCachedMetaDataStart) { if (size < kCachedMetaDataStart ||
size > std::numeric_limits<wtf_size_t>::max()) {
return nullptr; return nullptr;
} }
// Ensure the marker matches, otherwise discard the data. // Ensure the marker matches, otherwise discard the data.
...@@ -20,10 +21,10 @@ scoped_refptr<CachedMetadata> CachedMetadata::CreateFromSerializedData( ...@@ -20,10 +21,10 @@ scoped_refptr<CachedMetadata> CachedMetadata::CreateFromSerializedData(
CachedMetadataHandler::kSingleEntry) { CachedMetadataHandler::kSingleEntry) {
return nullptr; return nullptr;
} }
return base::AdoptRef(new CachedMetadata(data, size)); return base::AdoptRef(
new CachedMetadata(data, static_cast<wtf_size_t>(size)));
} }
CachedMetadata::CachedMetadata(const char* data, wtf_size_t size) {
CachedMetadata::CachedMetadata(const char* data, size_t size) {
// Serialized metadata should have non-empty data. // Serialized metadata should have non-empty data.
DCHECK_GT(size, kCachedMetaDataStart); DCHECK_GT(size, kCachedMetaDataStart);
DCHECK(data); DCHECK(data);
...@@ -37,7 +38,7 @@ CachedMetadata::CachedMetadata(const char* data, size_t size) { ...@@ -37,7 +38,7 @@ CachedMetadata::CachedMetadata(const char* data, size_t size) {
CachedMetadata::CachedMetadata(uint32_t data_type_id, CachedMetadata::CachedMetadata(uint32_t data_type_id,
const char* data, const char* data,
size_t size) { wtf_size_t size) {
// Don't allow an ID of 0, it is used internally to indicate errors. // Don't allow an ID of 0, it is used internally to indicate errors.
DCHECK(data_type_id); DCHECK(data_type_id);
DCHECK(data); DCHECK(data);
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "third_party/blink/renderer/platform/platform_export.h" #include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h" #include "third_party/blink/renderer/platform/wtf/assertions.h"
#include "third_party/blink/renderer/platform/wtf/ref_counted.h" #include "third_party/blink/renderer/platform/wtf/ref_counted.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/vector.h" #include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink { namespace blink {
...@@ -54,7 +55,8 @@ class PLATFORM_EXPORT CachedMetadata : public RefCounted<CachedMetadata> { ...@@ -54,7 +55,8 @@ class PLATFORM_EXPORT CachedMetadata : public RefCounted<CachedMetadata> {
static scoped_refptr<CachedMetadata> Create(uint32_t data_type_id, static scoped_refptr<CachedMetadata> Create(uint32_t data_type_id,
const char* data, const char* data,
size_t size) { size_t size) {
return base::AdoptRef(new CachedMetadata(data_type_id, data, size)); return base::AdoptRef(
new CachedMetadata(data_type_id, data, SafeCast<wtf_size_t>(size)));
} }
static scoped_refptr<CachedMetadata> CreateFromSerializedData( static scoped_refptr<CachedMetadata> CreateFromSerializedData(
...@@ -76,14 +78,14 @@ class PLATFORM_EXPORT CachedMetadata : public RefCounted<CachedMetadata> { ...@@ -76,14 +78,14 @@ class PLATFORM_EXPORT CachedMetadata : public RefCounted<CachedMetadata> {
return serialized_data_.data() + kCachedMetaDataStart; return serialized_data_.data() + kCachedMetaDataStart;
} }
size_t size() const { uint32_t size() const {
DCHECK_GE(serialized_data_.size(), kCachedMetaDataStart); DCHECK_GE(serialized_data_.size(), kCachedMetaDataStart);
return serialized_data_.size() - kCachedMetaDataStart; return serialized_data_.size() - kCachedMetaDataStart;
} }
private: private:
CachedMetadata(const char* data, size_t); CachedMetadata(const char* data, wtf_size_t);
CachedMetadata(uint32_t data_type_id, const char* data, size_t); CachedMetadata(uint32_t data_type_id, const char* data, wtf_size_t);
// Since the serialization format supports random access, storing it in // Since the serialization format supports random access, storing it in
// serialized form avoids need for a copy during serialization. // serialized form avoids need for a copy during serialization.
......
...@@ -118,9 +118,9 @@ void FetchContext::DispatchDidReceiveResponse( ...@@ -118,9 +118,9 @@ void FetchContext::DispatchDidReceiveResponse(
Resource*, Resource*,
ResourceResponseType) {} ResourceResponseType) {}
void FetchContext::DispatchDidReceiveData(unsigned long, const char*, int) {} void FetchContext::DispatchDidReceiveData(unsigned long, const char*, size_t) {}
void FetchContext::DispatchDidReceiveEncodedData(unsigned long, int) {} void FetchContext::DispatchDidReceiveEncodedData(unsigned long, size_t) {}
void FetchContext::DispatchDidDownloadToBlob(unsigned long identifier, void FetchContext::DispatchDidDownloadToBlob(unsigned long identifier,
BlobDataHandle*) {} BlobDataHandle*) {}
......
...@@ -157,9 +157,9 @@ class PLATFORM_EXPORT FetchContext ...@@ -157,9 +157,9 @@ class PLATFORM_EXPORT FetchContext
ResourceResponseType); ResourceResponseType);
virtual void DispatchDidReceiveData(unsigned long identifier, virtual void DispatchDidReceiveData(unsigned long identifier,
const char* data, const char* data,
int data_length); size_t data_length);
virtual void DispatchDidReceiveEncodedData(unsigned long identifier, virtual void DispatchDidReceiveEncodedData(unsigned long identifier,
int encoded_data_length); size_t encoded_data_length);
virtual void DispatchDidDownloadToBlob(unsigned long identifier, virtual void DispatchDidDownloadToBlob(unsigned long identifier,
BlobDataHandle*); BlobDataHandle*);
virtual void DispatchDidFinishLoading(unsigned long identifier, virtual void DispatchDidFinishLoading(unsigned long identifier,
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "third_party/blink/renderer/platform/network/http_names.h" #include "third_party/blink/renderer/platform/network/http_names.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h" #include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread_scheduler.h" #include "third_party/blink/renderer/platform/scheduler/public/thread_scheduler.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
namespace blink { namespace blink {
...@@ -139,7 +140,7 @@ RawResource::RawResource(const ResourceRequest& resource_request, ...@@ -139,7 +140,7 @@ RawResource::RawResource(const ResourceRequest& resource_request,
void RawResource::AppendData(const char* data, size_t length) { void RawResource::AppendData(const char* data, size_t length) {
if (data_pipe_writer_) { if (data_pipe_writer_) {
DCHECK_EQ(kDoNotBufferData, GetDataBufferingPolicy()); DCHECK_EQ(kDoNotBufferData, GetDataBufferingPolicy());
data_pipe_writer_->Write(data, length); data_pipe_writer_->Write(data, SafeCast<uint32_t>(length));
} else { } else {
Resource::AppendData(data, length); Resource::AppendData(data, length);
} }
...@@ -340,7 +341,7 @@ bool RawResource::MatchPreload(const FetchParameters& params, ...@@ -340,7 +341,7 @@ bool RawResource::MatchPreload(const FetchParameters& params,
if (Data()) { if (Data()) {
for (const auto& span : *Data()) for (const auto& span : *Data())
data_pipe_writer_->Write(span.data(), span.size()); data_pipe_writer_->Write(span.data(), SafeCast<uint32_t>(span.size()));
} }
SetDataBufferingPolicy(kDoNotBufferData); SetDataBufferingPolicy(kDoNotBufferData);
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include "third_party/blink/renderer/platform/testing/testing_platform_support_with_mock_scheduler.h" #include "third_party/blink/renderer/platform/testing/testing_platform_support_with_mock_scheduler.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h" #include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h" #include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
namespace blink { namespace blink {
...@@ -92,7 +93,7 @@ class DummyClient final : public GarbageCollectedFinalized<DummyClient>, ...@@ -92,7 +93,7 @@ class DummyClient final : public GarbageCollectedFinalized<DummyClient>,
String DebugName() const override { return "DummyClient"; } String DebugName() const override { return "DummyClient"; }
void DataReceived(Resource*, const char* data, size_t length) override { void DataReceived(Resource*, const char* data, size_t length) override {
data_.Append(data, length); data_.Append(data, SafeCast<wtf_size_t>(length));
} }
bool RedirectReceived(Resource*, bool RedirectReceived(Resource*,
......
...@@ -975,7 +975,7 @@ void Resource::OnMemoryDump(WebMemoryDumpLevelOfDetail level_of_detail, ...@@ -975,7 +975,7 @@ void Resource::OnMemoryDump(WebMemoryDumpLevelOfDetail level_of_detail,
WTF::CodePointCompareLessThan); WTF::CodePointCompareLessThan);
StringBuilder builder; StringBuilder builder;
for (size_t i = 0; for (wtf_size_t i = 0;
i < client_names.size() && i < kMaxResourceClientToShowInMemoryInfra; i < client_names.size() && i < kMaxResourceClientToShowInMemoryInfra;
++i) { ++i) {
if (i > 0) if (i > 0)
......
...@@ -358,10 +358,10 @@ class PLATFORM_EXPORT Resource : public GarbageCollectedFinalized<Resource>, ...@@ -358,10 +358,10 @@ class PLATFORM_EXPORT Resource : public GarbageCollectedFinalized<Resource>,
void SetEncodedDataLength(int64_t value) { void SetEncodedDataLength(int64_t value) {
response_.SetEncodedDataLength(value); response_.SetEncodedDataLength(value);
} }
void SetEncodedBodyLength(int value) { void SetEncodedBodyLength(int64_t value) {
response_.SetEncodedBodyLength(value); response_.SetEncodedBodyLength(value);
} }
void SetDecodedBodyLength(int value) { void SetDecodedBodyLength(int64_t value) {
response_.SetDecodedBodyLength(value); response_.SetDecodedBodyLength(value);
} }
......
...@@ -46,7 +46,7 @@ class ResourceClientWalker { ...@@ -46,7 +46,7 @@ class ResourceClientWalker {
} }
T* Next() { T* Next() {
size_t size = client_vector_.size(); wtf_size_t size = client_vector_.size();
while (index_ < size) { while (index_ < size) {
ResourceClient* next = client_vector_[index_++]; ResourceClient* next = client_vector_[index_++];
DCHECK(next); DCHECK(next);
...@@ -60,7 +60,7 @@ class ResourceClientWalker { ...@@ -60,7 +60,7 @@ class ResourceClientWalker {
private: private:
const HeapHashCountedSet<WeakMember<ResourceClient>>& client_set_; const HeapHashCountedSet<WeakMember<ResourceClient>>& client_set_;
HeapVector<Member<ResourceClient>> client_vector_; HeapVector<Member<ResourceClient>> client_vector_;
size_t index_ = 0; wtf_size_t index_ = 0;
}; };
} // namespace blink } // namespace blink
......
...@@ -114,7 +114,7 @@ constexpr base::TimeDelta kKeepaliveLoadersTimeout = ...@@ -114,7 +114,7 @@ constexpr base::TimeDelta kKeepaliveLoadersTimeout =
void AddRedirectsToTimingInfo(Resource* resource, ResourceTimingInfo* info) { void AddRedirectsToTimingInfo(Resource* resource, ResourceTimingInfo* info) {
// Store redirect responses that were packed inside the final response. // Store redirect responses that were packed inside the final response.
const auto& responses = resource->GetResponse().RedirectResponses(); const auto& responses = resource->GetResponse().RedirectResponses();
for (size_t i = 0; i < responses.size(); ++i) { for (wtf_size_t i = 0; i < responses.size(); ++i) {
const KURL& new_url = i + 1 < responses.size() const KURL& new_url = i + 1 < responses.size()
? KURL(responses[i + 1].Url()) ? KURL(responses[i + 1].Url())
: resource->GetResourceRequest().Url(); : resource->GetResourceRequest().Url();
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/metrics/field_trial_params.h" #include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/histogram.h" #include "third_party/blink/renderer/platform/histogram.h"
...@@ -106,7 +107,7 @@ size_t GetOutstandingThrottledLimit(FetchContext* context) { ...@@ -106,7 +107,7 @@ size_t GetOutstandingThrottledLimit(FetchContext* context) {
} }
int TakeWholeKilobytes(int64_t& bytes) { int TakeWholeKilobytes(int64_t& bytes) {
int kilobytes = bytes / 1024; int kilobytes = base::saturated_cast<int>(bytes / 1024);
bytes %= 1024; bytes %= 1024;
return kilobytes; return kilobytes;
} }
...@@ -140,13 +141,13 @@ class ResourceLoadScheduler::TrafficMonitor { ...@@ -140,13 +141,13 @@ class ResourceLoadScheduler::TrafficMonitor {
scheduler::SchedulingLifecycleState current_state_ = scheduler::SchedulingLifecycleState current_state_ =
scheduler::SchedulingLifecycleState::kStopped; scheduler::SchedulingLifecycleState::kStopped;
size_t total_throttled_request_count_ = 0; uint32_t total_throttled_request_count_ = 0;
size_t total_throttled_traffic_bytes_ = 0; size_t total_throttled_traffic_bytes_ = 0;
size_t total_throttled_decoded_bytes_ = 0; size_t total_throttled_decoded_bytes_ = 0;
size_t total_not_throttled_request_count_ = 0; uint32_t total_not_throttled_request_count_ = 0;
size_t total_not_throttled_traffic_bytes_ = 0; size_t total_not_throttled_traffic_bytes_ = 0;
size_t total_not_throttled_decoded_bytes_ = 0; size_t total_not_throttled_decoded_bytes_ = 0;
size_t throttling_state_change_count_ = 0; uint32_t throttling_state_change_count_ = 0;
bool report_all_is_called_ = false; bool report_all_is_called_ = false;
scheduler::AggregatedMetricReporter<scheduler::FrameStatus, int64_t> scheduler::AggregatedMetricReporter<scheduler::FrameStatus, int64_t>
...@@ -311,26 +312,34 @@ void ResourceLoadScheduler::TrafficMonitor::ReportAll() { ...@@ -311,26 +312,34 @@ void ResourceLoadScheduler::TrafficMonitor::ReportAll() {
main_frame_total_not_throttled_request_count.Count( main_frame_total_not_throttled_request_count.Count(
total_not_throttled_request_count_); total_not_throttled_request_count_);
main_frame_total_throttled_traffic_bytes.Count( main_frame_total_throttled_traffic_bytes.Count(
total_throttled_traffic_bytes_); base::saturated_cast<base::Histogram::Sample>(
total_throttled_traffic_bytes_));
main_frame_total_not_throttled_traffic_bytes.Count( main_frame_total_not_throttled_traffic_bytes.Count(
total_not_throttled_traffic_bytes_); base::saturated_cast<base::Histogram::Sample>(
total_not_throttled_traffic_bytes_));
main_frame_total_throttled_decoded_bytes.Count( main_frame_total_throttled_decoded_bytes.Count(
total_throttled_decoded_bytes_); base::saturated_cast<base::Histogram::Sample>(
total_throttled_decoded_bytes_));
main_frame_total_not_throttled_decoded_bytes.Count( main_frame_total_not_throttled_decoded_bytes.Count(
total_not_throttled_decoded_bytes_); base::saturated_cast<base::Histogram::Sample>(
total_not_throttled_decoded_bytes_));
} else { } else {
sub_frame_total_throttled_request_count.Count( sub_frame_total_throttled_request_count.Count(
total_throttled_request_count_); total_throttled_request_count_);
sub_frame_total_not_throttled_request_count.Count( sub_frame_total_not_throttled_request_count.Count(
total_not_throttled_request_count_); total_not_throttled_request_count_);
sub_frame_total_throttled_traffic_bytes.Count( sub_frame_total_throttled_traffic_bytes.Count(
total_throttled_traffic_bytes_); base::saturated_cast<base::Histogram::Sample>(
total_throttled_traffic_bytes_));
sub_frame_total_not_throttled_traffic_bytes.Count( sub_frame_total_not_throttled_traffic_bytes.Count(
total_not_throttled_traffic_bytes_); base::saturated_cast<base::Histogram::Sample>(
total_not_throttled_traffic_bytes_));
sub_frame_total_throttled_decoded_bytes.Count( sub_frame_total_throttled_decoded_bytes.Count(
total_throttled_decoded_bytes_); base::saturated_cast<base::Histogram::Sample>(
total_throttled_decoded_bytes_));
sub_frame_total_not_throttled_decoded_bytes.Count( sub_frame_total_not_throttled_decoded_bytes.Count(
total_not_throttled_decoded_bytes_); base::saturated_cast<base::Histogram::Sample>(
total_not_throttled_decoded_bytes_));
} }
throttling_state_change_count.Count(throttling_state_change_count_); throttling_state_change_count.Count(throttling_state_change_count_);
......
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
#include "third_party/blink/renderer/platform/weborigin/scheme_registry.h" #include "third_party/blink/renderer/platform/weborigin/scheme_registry.h"
#include "third_party/blink/renderer/platform/weborigin/security_violation_reporting_policy.h" #include "third_party/blink/renderer/platform/weborigin/security_violation_reporting_policy.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h" #include "third_party/blink/renderer/platform/wtf/assertions.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h" #include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/time.h" #include "third_party/blink/renderer/platform/wtf/time.h"
...@@ -941,8 +942,8 @@ void ResourceLoader::DidStartLoadingResponseBody( ...@@ -941,8 +942,8 @@ void ResourceLoader::DidStartLoadingResponseBody(
mojom::blink::BlobRegistry* blob_registry = BlobDataHandle::GetBlobRegistry(); mojom::blink::BlobRegistry* blob_registry = BlobDataHandle::GetBlobRegistry();
blob_registry->RegisterFromStream( blob_registry->RegisterFromStream(
mime_type.IsNull() ? g_empty_string : mime_type.LowerASCII(), "", mime_type.IsNull() ? g_empty_string : mime_type.LowerASCII(), "",
std::max(0ll, response.ExpectedContentLength()), std::move(body), std::max(static_cast<int64_t>(0), response.ExpectedContentLength()),
std::move(progress_client_ptr), std::move(body), std::move(progress_client_ptr),
WTF::Bind(&ResourceLoader::FinishedCreatingBlob, WTF::Bind(&ResourceLoader::FinishedCreatingBlob,
WrapWeakPersistent(this))); WrapWeakPersistent(this)));
} }
...@@ -1094,7 +1095,7 @@ void ResourceLoader::RequestSynchronously(const ResourceRequest& request) { ...@@ -1094,7 +1095,7 @@ void ResourceLoader::RequestSynchronously(const ResourceRequest& request) {
if (data_out.size()) { if (data_out.size()) {
data_out.ForEachSegment([this](const char* segment, size_t segment_size, data_out.ForEachSegment([this](const char* segment, size_t segment_size,
size_t segment_offset) { size_t segment_offset) {
DidReceiveData(segment, segment_size); DidReceiveData(segment, SafeCast<int>(segment_size));
return true; return true;
}); });
} }
...@@ -1171,7 +1172,7 @@ void ResourceLoader::OnProgress(uint64_t delta) { ...@@ -1171,7 +1172,7 @@ void ResourceLoader::OnProgress(uint64_t delta) {
return; return;
Context().DispatchDidReceiveData(resource_->Identifier(), nullptr, delta); Context().DispatchDidReceiveData(resource_->Identifier(), nullptr, delta);
resource_->DidDownloadData(delta); resource_->DidDownloadData(SafeCast<int>(delta));
} }
void ResourceLoader::FinishedCreatingBlob( void ResourceLoader::FinishedCreatingBlob(
......
...@@ -112,12 +112,12 @@ void ResourceResponse::SetMimeType(const AtomicString& mime_type) { ...@@ -112,12 +112,12 @@ void ResourceResponse::SetMimeType(const AtomicString& mime_type) {
mime_type_ = mime_type; mime_type_ = mime_type;
} }
long long ResourceResponse::ExpectedContentLength() const { int64_t ResourceResponse::ExpectedContentLength() const {
return expected_content_length_; return expected_content_length_;
} }
void ResourceResponse::SetExpectedContentLength( void ResourceResponse::SetExpectedContentLength(
long long expected_content_length) { int64_t expected_content_length) {
is_null_ = false; is_null_ = false;
// FIXME: Content length is determined by HTTP Content-Length header. We // FIXME: Content length is determined by HTTP Content-Length header. We
...@@ -343,7 +343,7 @@ double ResourceResponse::LastModified() const { ...@@ -343,7 +343,7 @@ double ResourceResponse::LastModified() const {
bool ResourceResponse::IsAttachment() const { bool ResourceResponse::IsAttachment() const {
static const char kAttachmentString[] = "attachment"; static const char kAttachmentString[] = "attachment";
String value = http_header_fields_.Get(http_names::kContentDisposition); String value = http_header_fields_.Get(http_names::kContentDisposition);
size_t loc = value.find(';'); wtf_size_t loc = value.find(';');
if (loc != kNotFound) if (loc != kNotFound)
value = value.Left(loc); value = value.Left(loc);
value = value.StripWhiteSpace(); value = value.StripWhiteSpace();
...@@ -419,15 +419,15 @@ AtomicString ResourceResponse::ConnectionInfoString() const { ...@@ -419,15 +419,15 @@ AtomicString ResourceResponse::ConnectionInfoString() const {
connection_info_string.length()); connection_info_string.length());
} }
void ResourceResponse::SetEncodedDataLength(long long value) { void ResourceResponse::SetEncodedDataLength(int64_t value) {
encoded_data_length_ = value; encoded_data_length_ = value;
} }
void ResourceResponse::SetEncodedBodyLength(long long value) { void ResourceResponse::SetEncodedBodyLength(int64_t value) {
encoded_body_length_ = value; encoded_body_length_ = value;
} }
void ResourceResponse::SetDecodedBodyLength(long long value) { void ResourceResponse::SetDecodedBodyLength(int64_t value) {
decoded_body_length_ = value; decoded_body_length_ = value;
} }
......
...@@ -172,8 +172,8 @@ class PLATFORM_EXPORT ResourceResponse final { ...@@ -172,8 +172,8 @@ class PLATFORM_EXPORT ResourceResponse final {
const AtomicString& MimeType() const; const AtomicString& MimeType() const;
void SetMimeType(const AtomicString&); void SetMimeType(const AtomicString&);
long long ExpectedContentLength() const; int64_t ExpectedContentLength() const;
void SetExpectedContentLength(long long); void SetExpectedContentLength(int64_t);
const AtomicString& TextEncodingName() const; const AtomicString& TextEncodingName() const;
void SetTextEncodingName(const AtomicString&); void SetTextEncodingName(const AtomicString&);
...@@ -272,8 +272,8 @@ class PLATFORM_EXPORT ResourceResponse final { ...@@ -272,8 +272,8 @@ class PLATFORM_EXPORT ResourceResponse final {
const Vector<AtomicString>& certificate, const Vector<AtomicString>& certificate,
const SignedCertificateTimestampList& sct_list); const SignedCertificateTimestampList& sct_list);
long long AppCacheID() const { return app_cache_id_; } int64_t AppCacheID() const { return app_cache_id_; }
void SetAppCacheID(long long id) { app_cache_id_ = id; } void SetAppCacheID(int64_t id) { app_cache_id_ = id; }
const KURL& AppCacheManifestURL() const { return app_cache_manifest_url_; } const KURL& AppCacheManifestURL() const { return app_cache_manifest_url_; }
void SetAppCacheManifestURL(const KURL& url) { void SetAppCacheManifestURL(const KURL& url) {
...@@ -326,7 +326,7 @@ class PLATFORM_EXPORT ResourceResponse final { ...@@ -326,7 +326,7 @@ class PLATFORM_EXPORT ResourceResponse final {
KURL OriginalURLViaServiceWorker() const; KURL OriginalURLViaServiceWorker() const;
const Vector<char>& MultipartBoundary() const { return multipart_boundary_; } const Vector<char>& MultipartBoundary() const { return multipart_boundary_; }
void SetMultipartBoundary(const char* bytes, size_t size) { void SetMultipartBoundary(const char* bytes, uint32_t size) {
multipart_boundary_.clear(); multipart_boundary_.clear();
multipart_boundary_.Append(bytes, size); multipart_boundary_.Append(bytes, size);
} }
...@@ -379,14 +379,14 @@ class PLATFORM_EXPORT ResourceResponse final { ...@@ -379,14 +379,14 @@ class PLATFORM_EXPORT ResourceResponse final {
AtomicString ConnectionInfoString() const; AtomicString ConnectionInfoString() const;
long long EncodedDataLength() const { return encoded_data_length_; } int64_t EncodedDataLength() const { return encoded_data_length_; }
void SetEncodedDataLength(long long value); void SetEncodedDataLength(int64_t value);
long long EncodedBodyLength() const { return encoded_body_length_; } int64_t EncodedBodyLength() const { return encoded_body_length_; }
void SetEncodedBodyLength(long long value); void SetEncodedBodyLength(int64_t value);
long long DecodedBodyLength() const { return decoded_body_length_; } int64_t DecodedBodyLength() const { return decoded_body_length_; }
void SetDecodedBodyLength(long long value); void SetDecodedBodyLength(int64_t value);
// Extra data associated with this response. // Extra data associated with this response.
ExtraData* GetExtraData() const { return extra_data_.get(); } ExtraData* GetExtraData() const { return extra_data_.get(); }
...@@ -536,7 +536,7 @@ class PLATFORM_EXPORT ResourceResponse final { ...@@ -536,7 +536,7 @@ class PLATFORM_EXPORT ResourceResponse final {
// The id of the appcache this response was retrieved from, or zero if // The id of the appcache this response was retrieved from, or zero if
// the response was not retrieved from an appcache. // the response was not retrieved from an appcache.
long long app_cache_id_ = 0; int64_t app_cache_id_ = 0;
// The manifest url of the appcache this response was retrieved from, if any. // The manifest url of the appcache this response was retrieved from, if any.
// Note: only valid for main resource responses. // Note: only valid for main resource responses.
...@@ -569,14 +569,14 @@ class PLATFORM_EXPORT ResourceResponse final { ...@@ -569,14 +569,14 @@ class PLATFORM_EXPORT ResourceResponse final {
net::HttpResponseInfo::ConnectionInfo::CONNECTION_INFO_UNKNOWN; net::HttpResponseInfo::ConnectionInfo::CONNECTION_INFO_UNKNOWN;
// Size of the response in bytes prior to decompression. // Size of the response in bytes prior to decompression.
long long encoded_data_length_ = 0; int64_t encoded_data_length_ = 0;
// Size of the response body in bytes prior to decompression. // Size of the response body in bytes prior to decompression.
long long encoded_body_length_ = 0; int64_t encoded_body_length_ = 0;
// Sizes of the response body in bytes after any content-encoding is // Sizes of the response body in bytes after any content-encoding is
// removed. // removed.
long long decoded_body_length_ = 0; int64_t decoded_body_length_ = 0;
// ExtraData associated with the response. // ExtraData associated with the response.
scoped_refptr<ExtraData> extra_data_; scoped_refptr<ExtraData> extra_data_;
......
...@@ -66,7 +66,8 @@ class SourceKeyedCachedMetadataHandler::SingleKeyHandler final ...@@ -66,7 +66,8 @@ class SourceKeyedCachedMetadataHandler::SingleKeyHandler final
class SourceKeyedCachedMetadataHandler::KeyHash { class SourceKeyedCachedMetadataHandler::KeyHash {
public: public:
static unsigned GetHash(const Key& key) { static unsigned GetHash(const Key& key) {
return StringHasher::ComputeHash(key.data(), key.size()); return StringHasher::ComputeHash(key.data(),
static_cast<uint32_t>(key.size()));
} }
static bool Equal(const Key& a, const Key& b) { return a == b; } static bool Equal(const Key& a, const Key& b) { return a == b; }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/crypto.h" #include "third_party/blink/renderer/platform/crypto.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support_with_mock_scheduler.h" #include "third_party/blink/renderer/platform/testing/testing_platform_support_with_mock_scheduler.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
namespace blink { namespace blink {
...@@ -69,7 +70,7 @@ struct CacheMetadataEntry { ...@@ -69,7 +70,7 @@ struct CacheMetadataEntry {
CacheMetadataEntry(const WebURL& url, CacheMetadataEntry(const WebURL& url,
base::Time response_time, base::Time response_time,
const char* data, const char* data,
size_t data_size) wtf_size_t data_size)
: url(url), response_time(response_time) { : url(url), response_time(response_time) {
this->data.Append(data, data_size); this->data.Append(data, data_size);
} }
...@@ -93,7 +94,8 @@ class SourceKeyedCachedMetadataHandlerMockPlatform final ...@@ -93,7 +94,8 @@ class SourceKeyedCachedMetadataHandlerMockPlatform final
base::Time response_time, base::Time response_time,
const char* data, const char* data,
size_t data_size) override { size_t data_size) override {
cache_entries_.emplace_back(url, response_time, data, data_size); cache_entries_.emplace_back(url, response_time, data,
SafeCast<wtf_size_t>(data_size));
} }
bool HasCacheMetadataFor(const WebURL& url) { bool HasCacheMetadataFor(const WebURL& url) {
......
...@@ -75,8 +75,8 @@ class PLATFORM_EXPORT LinkHeaderSet { ...@@ -75,8 +75,8 @@ class PLATFORM_EXPORT LinkHeaderSet {
return header_set_.begin(); return header_set_.begin();
} }
Vector<LinkHeader>::const_iterator end() const { return header_set_.end(); } Vector<LinkHeader>::const_iterator end() const { return header_set_.end(); }
LinkHeader& operator[](size_t i) { return header_set_[i]; } LinkHeader& operator[](wtf_size_t i) { return header_set_[i]; }
size_t size() { return header_set_.size(); } wtf_size_t size() { return header_set_.size(); }
private: private:
Vector<LinkHeader> header_set_; Vector<LinkHeader> header_set_;
......
...@@ -39,7 +39,7 @@ static bool DigestsEqual(const DigestValue& digest1, ...@@ -39,7 +39,7 @@ static bool DigestsEqual(const DigestValue& digest1,
if (digest1.size() != digest2.size()) if (digest1.size() != digest2.size())
return false; return false;
for (size_t i = 0; i < digest1.size(); i++) { for (wtf_size_t i = 0; i < digest1.size(); i++) {
if (digest1[i] != digest2[i]) if (digest1[i] != digest2[i])
return false; return false;
} }
...@@ -384,7 +384,8 @@ bool SubresourceIntegrity::ParseDigest(const UChar*& position, ...@@ -384,7 +384,8 @@ bool SubresourceIntegrity::ParseDigest(const UChar*& position,
} }
// We accept base64url encoding, but normalize to "normal" base64 internally: // We accept base64url encoding, but normalize to "normal" base64 internally:
digest = NormalizeToBase64(String(begin, position - begin)); digest = NormalizeToBase64(
String(begin, static_cast<wtf_size_t>(position - begin)));
return true; return true;
} }
...@@ -490,7 +491,7 @@ SubresourceIntegrity::ParseIntegrityAttribute( ...@@ -490,7 +491,7 @@ SubresourceIntegrity::ParseIntegrityAttribute(
if (begin != position && report_info) { if (begin != position && report_info) {
report_info->AddConsoleErrorMessage( report_info->AddConsoleErrorMessage(
"Ignoring unrecogized 'integrity' attribute option '" + "Ignoring unrecogized 'integrity' attribute option '" +
String(begin, position - begin) + "'."); String(begin, static_cast<wtf_size_t>(position - begin)) + "'.");
} }
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "third_party/blink/renderer/platform/loader/fetch/fetch_parameters.h" #include "third_party/blink/renderer/platform/loader/fetch/fetch_parameters.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h" #include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_loader_options.h" #include "third_party/blink/renderer/platform/loader/fetch/resource_loader_options.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
namespace blink { namespace blink {
...@@ -81,7 +82,7 @@ MockCacheHandler::MockCacheHandler( ...@@ -81,7 +82,7 @@ MockCacheHandler::MockCacheHandler(
void MockCacheHandler::Set(const char* data, size_t size) { void MockCacheHandler::Set(const char* data, size_t size) {
data_.emplace(); data_.emplace();
data_->Append(data, size); data_->Append(data, SafeCast<wtf_size_t>(size));
} }
void MockCacheHandler::ClearCachedMetadata( void MockCacheHandler::ClearCachedMetadata(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment