Skip to content

Commit

Permalink
Replace use of std containers with WTF's equivalents in loader/*
Browse files Browse the repository at this point in the history
This CL replaces the use of std::vector and std::queue of std
containers and std::string with WTF::Vector, blink::WebVector and
WTF::String in loader/*.

Bug: 952716
Change-Id: I2f93adcf4cdce37b7fdcc4cf3bc3e43fd37bac5f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1681718
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Cr-Commit-Position: refs/heads/master@{#673318}
  • Loading branch information
MyidShin authored and Commit Bot committed Jun 28, 2019
1 parent 3d7b2a7 commit 0ddd49c
Show file tree
Hide file tree
Showing 22 changed files with 65 additions and 86 deletions.
3 changes: 2 additions & 1 deletion content/renderer/loader/web_url_loader_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "third_party/blink/public/platform/web_url_loader_client.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/public/platform/web_url_response.h"
#include "third_party/blink/public/platform/web_vector.h"
#include "url/gurl.h"
#include "url/origin.h"

Expand Down Expand Up @@ -235,7 +236,7 @@ class TestWebURLLoaderClient : public blink::WebURLLoaderClient {
int64_t totalEncodedBodyLength,
int64_t totalDecodedBodyLength,
bool should_report_corb_blocking,
const std::vector<network::cors::PreflightTimingInfo>&) override {
const blink::WebVector<network::cors::PreflightTimingInfo>&) override {
EXPECT_TRUE(loader_);
EXPECT_TRUE(did_receive_response_);
EXPECT_FALSE(did_finish_);
Expand Down
3 changes: 2 additions & 1 deletion third_party/blink/public/platform/web_url_loader_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "services/network/public/mojom/referrer_policy.mojom-shared.h"
#include "third_party/blink/public/platform/web_common.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/public/platform/web_vector.h"

namespace blink {

Expand Down Expand Up @@ -108,7 +109,7 @@ class BLINK_PLATFORM_EXPORT WebURLLoaderClient {
int64_t total_encoded_body_length,
int64_t total_decoded_body_length,
bool should_report_corb_blocking,
const std::vector<network::cors::PreflightTimingInfo>&) {}
const WebVector<network::cors::PreflightTimingInfo>&) {}

// Called when the load completes with an error.
// |total_encoded_data_length| may be equal to kUnknownEncodedDataLength.
Expand Down
2 changes: 1 addition & 1 deletion third_party/blink/renderer/core/loader/document_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ void MergeFeaturesFromOriginPolicy(WTF::StringBuilder& feature_policy,
if (!origin_policy)
return;

for (const std::string& policy : origin_policy->GetFeaturePolicies()) {
for (const auto& policy : origin_policy->GetFeaturePolicies()) {
if (!feature_policy.IsEmpty()) {
feature_policy.Append(',');
}
Expand Down
18 changes: 8 additions & 10 deletions third_party/blink/renderer/core/loader/document_loader_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "third_party/blink/renderer/core/loader/document_loader.h"

#include <queue>
#include <string>
#include <utility>
#include "base/auto_reset.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand All @@ -20,6 +18,7 @@
#include "third_party/blink/renderer/platform/loader/static_data_navigation_body_loader.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/url_test_helpers.h"
#include "third_party/blink/renderer/platform/wtf/deque.h"

namespace blink {

Expand Down Expand Up @@ -102,9 +101,9 @@ TEST_F(DocumentLoaderTest, MultiChunkWithReentrancy) {
params->response.SetMimeType("application/pdf");
params->response.SetHttpStatusCode(200);

std::string data("<html><body>foo</body></html>");
for (size_t i = 0; i < data.size(); i++)
data_.push(data[i]);
String data("<html><body>foo</body></html>");
for (wtf_size_t i = 0; i < data.length(); i++)
data_.push_back(data[i]);

auto body_loader = std::make_unique<StaticDataNavigationBodyLoader>();
body_loader_ = body_loader.get();
Expand All @@ -122,8 +121,8 @@ TEST_F(DocumentLoaderTest, MultiChunkWithReentrancy) {
}

// Serve the remaining bytes to complete the load.
EXPECT_FALSE(data_.empty());
while (!data_.empty())
EXPECT_FALSE(data_.IsEmpty());
while (!data_.IsEmpty())
DispatchOneByte();

body_loader_->Finish();
Expand All @@ -147,15 +146,14 @@ TEST_F(DocumentLoaderTest, MultiChunkWithReentrancy) {
}

void DispatchOneByte() {
char c = data_.front();
data_.pop();
char c = data_.TakeFirst();
body_loader_->Write(&c, 1);
}

bool ServedReentrantly() const { return served_reentrantly_; }

private:
std::queue<char> data_;
Deque<char> data_;
bool dispatching_did_receive_data_ = false;
bool served_reentrantly_ = false;
StaticDataNavigationBodyLoader* body_loader_ = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,7 @@ void FrameFetchContext::AddClientHintsIfNecessary(
if (RuntimeEnabledFeatures::UserAgentClientHintEnabled()) {
StringBuilder result;
result.Append(ua.brand.data());
const std::string& version =
use_full_ua ? ua.full_version : ua.major_version;
const auto& version = use_full_ua ? ua.full_version : ua.major_version;
if (!version.empty()) {
result.Append(' ');
result.Append(version.data());
Expand Down
11 changes: 6 additions & 5 deletions third_party/blink/renderer/core/loader/interactive_detector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ void InteractiveDetector::OnInvalidatingInputEvent(
}

void InteractiveDetector::OnPageHiddenChanged(bool is_hidden) {
visibility_change_events_.push_back({clock_->NowTicks(), is_hidden});
visibility_change_events_.push_back(
VisibilityChangeEvent{clock_->NowTicks(), is_hidden});
}

void InteractiveDetector::TimeToInteractiveTimerFired(TimerBase*) {
Expand Down Expand Up @@ -402,13 +403,13 @@ void InteractiveDetector::AddCurrentlyActiveQuietIntervals(
}

void InteractiveDetector::RemoveCurrentlyActiveQuietIntervals() {
if (!network_quiet_windows_.empty() &&
if (!network_quiet_windows_.IsEmpty() &&
network_quiet_windows_.back().Low() ==
active_network_quiet_window_start_) {
network_quiet_windows_.pop_back();
}

if (!main_thread_quiet_windows_.empty() &&
if (!main_thread_quiet_windows_.IsEmpty() &&
main_thread_quiet_windows_.back().Low() ==
active_main_thread_quiet_window_start_) {
main_thread_quiet_windows_.pop_back();
Expand All @@ -418,9 +419,9 @@ void InteractiveDetector::RemoveCurrentlyActiveQuietIntervals() {
base::TimeTicks InteractiveDetector::FindInteractiveCandidate(
base::TimeTicks lower_bound) {
// Main thread iterator.
auto it_mt = main_thread_quiet_windows_.begin();
auto* it_mt = main_thread_quiet_windows_.begin();
// Network iterator.
auto it_net = network_quiet_windows_.begin();
auto* it_net = network_quiet_windows_.begin();

while (it_mt < main_thread_quiet_windows_.end() &&
it_net < network_quiet_windows_.end()) {
Expand Down
7 changes: 4 additions & 3 deletions third_party/blink/renderer/core/loader/interactive_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "third_party/blink/renderer/platform/supplementable.h"
#include "third_party/blink/renderer/platform/timer.h"
#include "third_party/blink/renderer/platform/wtf/pod_interval.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace base {
class TickClock;
Expand Down Expand Up @@ -153,8 +154,8 @@ class CORE_EXPORT InteractiveDetector
};

// Stores sufficiently long quiet windows on main thread and network.
std::vector<WTF::PODInterval<base::TimeTicks>> main_thread_quiet_windows_;
std::vector<WTF::PODInterval<base::TimeTicks>> network_quiet_windows_;
Vector<WTF::PODInterval<base::TimeTicks>> main_thread_quiet_windows_;
Vector<WTF::PODInterval<base::TimeTicks>> network_quiet_windows_;

// Start times of currently active main thread and network quiet windows.
// Null base::TimeTicks values indicate main thread or network is not quiet at
Expand Down Expand Up @@ -185,7 +186,7 @@ class CORE_EXPORT InteractiveDetector
void CheckTimeToInteractiveReached();
void OnTimeToInteractiveDetected();

std::vector<VisibilityChangeEvent> visibility_change_events_;
Vector<VisibilityChangeEvent> visibility_change_events_;
bool initially_hidden_;
// Returns true if page was ever backgrounded in the range
// [event_time, CurrentTimeTicks()].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ bool MixedContentChecker::ShouldAutoupgrade(HttpsState context_https_state,
return false;
}

std::string autoupgrade_mode = base::GetFieldTrialParamValueByFeature(
auto autoupgrade_mode = base::GetFieldTrialParamValueByFeature(
blink::features::kMixedContentAutoupgrade,
blink::features::kMixedContentAutoupgradeModeParamName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ PrefetchedSignedExchangeManager::CreatePrefetchedSignedExchangeURLLoader(
}

void PrefetchedSignedExchangeManager::TriggerLoad() {
std::vector<WebNavigationParams::PrefetchedSignedExchange*>
Vector<WebNavigationParams::PrefetchedSignedExchange*>
maching_prefetched_exchanges;
for (auto loader : loaders_) {
if (!loader) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ PreviewsResourceLoadingHints::PreviewsResourceLoadingHints(

subresource_patterns_to_block_usage_.Fill(
false, subresource_patterns_to_block.size());
blocked_resource_load_priority_counts_.fill(0);
blocked_resource_load_priority_counts_.Fill(
0, static_cast<int>(ResourceLoadPriority::kHighest) + 1);

// Populate which specific resource types are eligible for blocking.
// Certain resource types are blocked by default since their blocking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_PREVIEWS_RESOURCE_LOADING_HINTS_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_PREVIEWS_RESOURCE_LOADING_HINTS_H_

#include <vector>

#include "base/feature_list.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
Expand Down Expand Up @@ -79,8 +77,7 @@ class CORE_EXPORT PreviewsResourceLoadingHints final

// |blocked_resource_load_priority_counts_| records the total number of
// resources blocked at each ResourceLoadPriority.
mutable std::array<int, static_cast<int>(ResourceLoadPriority::kHighest) + 1>
blocked_resource_load_priority_counts_;
mutable Vector<int> blocked_resource_load_priority_counts_;
};

} // namespace blink
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "third_party/blink/renderer/core/loader/previews_resource_loading_hints_receiver_impl.h"

#include <vector>

#include "base/metrics/histogram_macros.h"
#include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/loader/previews_resource_loading_hints.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,20 @@ class ProgrammaticScrollTest : public testing::Test {
}

protected:
void RegisterMockedHttpURLLoad(const std::string& file_name) {
void RegisterMockedHttpURLLoad(const String& file_name) {
url_test_helpers::RegisterMockedURLLoadFromBase(
WebString::FromUTF8(base_url_), test::CoreTestDataPath(),
WebString::FromUTF8(file_name));
WebString(base_url_), test::CoreTestDataPath(), WebString(file_name));
}

std::string base_url_;
String base_url_;
};

TEST_F(ProgrammaticScrollTest, RestoreScrollPositionAndViewStateWithScale) {
RegisterMockedHttpURLLoad("long_scroll.html");

frame_test_helpers::WebViewHelper web_view_helper;
WebViewImpl* web_view =
web_view_helper.InitializeAndLoad(base_url_ + "long_scroll.html");
web_view_helper.InitializeAndLoad(base_url_.Utf8() + "long_scroll.html");
web_view->MainFrameWidget()->Resize(WebSize(1000, 1000));
web_view->MainFrameWidget()->UpdateAllLifecyclePhases(
WebWidget::LifecycleUpdateReason::kTest);
Expand Down Expand Up @@ -84,7 +83,7 @@ TEST_F(ProgrammaticScrollTest, RestoreScrollPositionAndViewStateWithoutScale) {

frame_test_helpers::WebViewHelper web_view_helper;
WebViewImpl* web_view =
web_view_helper.InitializeAndLoad(base_url_ + "long_scroll.html");
web_view_helper.InitializeAndLoad(base_url_.Utf8() + "long_scroll.html");
web_view->MainFrameWidget()->Resize(WebSize(1000, 1000));
web_view->MainFrameWidget()->UpdateAllLifecyclePhases(
WebWidget::LifecycleUpdateReason::kTest);
Expand Down Expand Up @@ -114,7 +113,7 @@ TEST_F(ProgrammaticScrollTest, SaveScrollStateClearsAnchor) {

frame_test_helpers::WebViewHelper web_view_helper;
WebViewImpl* web_view =
web_view_helper.InitializeAndLoad(base_url_ + "long_scroll.html");
web_view_helper.InitializeAndLoad(base_url_.Utf8() + "long_scroll.html");
web_view->MainFrameWidget()->Resize(WebSize(1000, 1000));
web_view->MainFrameWidget()->UpdateAllLifecyclePhases(
WebWidget::LifecycleUpdateReason::kTest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,7 @@ void ImageResource::DecodeError(bool all_data_received) {
// Observers are notified via ImageResource::finish().
// TODO(hiroshige): Do not call didFinishLoading() directly.
Loader()->AbortResponseBodyLoading();
Loader()->DidFinishLoading(
CurrentTimeTicks(), size, size, size, false,
std::vector<network::cors::PreflightTimingInfo>());
Loader()->DidFinishLoading(CurrentTimeTicks(), size, size, size, false, {});
} else {
auto result = GetContent()->UpdateImage(
nullptr, GetStatus(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ void TestThatReloadIsStartedThenServeReload(
WrappedResourceResponse(resource_response));
image_resource->Loader()->DidReceiveData(data, kDataLength);
image_resource->Loader()->DidFinishLoading(
base::TimeTicks(), kDataLength, kDataLength, kDataLength, false,
std::vector<network::cors::PreflightTimingInfo>());
base::TimeTicks(), kDataLength, kDataLength, kDataLength, false, {});

// Checks |imageResource|'s status after reloading.
EXPECT_EQ(ResourceStatus::kCached, image_resource->GetStatus());
Expand Down Expand Up @@ -291,8 +290,7 @@ void TestThatIsPlaceholderRequestAndServeResponse(
image_resource->Loader()->DidFinishLoading(
base::TimeTicks(), kJpegImageSubrangeWithDimensionsLength,
kJpegImageSubrangeWithDimensionsLength,
kJpegImageSubrangeWithDimensionsLength, false,
std::vector<network::cors::PreflightTimingInfo>());
kJpegImageSubrangeWithDimensionsLength, false, {});

// Checks that |imageResource| is successfully loaded, showing a placeholder.
EXPECT_EQ(ResourceStatus::kCached, image_resource->GetStatus());
Expand Down Expand Up @@ -334,8 +332,7 @@ void TestThatIsNotPlaceholderRequestAndServeResponse(
reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage));
image_resource->Loader()->DidFinishLoading(
base::TimeTicks(), sizeof(kJpegImage), sizeof(kJpegImage),
sizeof(kJpegImage), false,
std::vector<network::cors::PreflightTimingInfo>());
sizeof(kJpegImage), false, {});

// Checks that |imageResource| is successfully loaded,
// showing a non-placeholder image.
Expand Down Expand Up @@ -432,9 +429,8 @@ TEST(ImageResourceTest, MultipartImage) {

// This part finishes. The image is created, callbacks are sent, and the data
// buffer is cleared.
image_resource->Loader()->DidFinishLoading(
base::TimeTicks(), 0, 0, 0, false,
std::vector<network::cors::PreflightTimingInfo>());
image_resource->Loader()->DidFinishLoading(base::TimeTicks(), 0, 0, 0, false,
{});
EXPECT_TRUE(image_resource->ResourceBuffer());
EXPECT_FALSE(image_resource->ErrorOccurred());
ASSERT_TRUE(image_resource->GetContent()->HasImage());
Expand Down Expand Up @@ -478,9 +474,8 @@ TEST(ImageResourceTest, BitmapMultipartImage) {
image_resource->AppendData(reinterpret_cast<const char*>(kJpegImage),
sizeof(kJpegImage));
image_resource->AppendData(kBoundary, strlen(kBoundary));
image_resource->Loader()->DidFinishLoading(
base::TimeTicks(), 0, 0, 0, false,
std::vector<network::cors::PreflightTimingInfo>());
image_resource->Loader()->DidFinishLoading(base::TimeTicks(), 0, 0, 0, false,
{});
EXPECT_TRUE(image_resource->GetContent()->HasImage());
EXPECT_TRUE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_TRUE(image_resource->GetContent()
Expand Down Expand Up @@ -1044,9 +1039,8 @@ TEST(ImageResourceTest, DecodeErrorWithEmptyBody) {
EXPECT_FALSE(observer->ImageNotifyFinishedCalled());
EXPECT_EQ(0, observer->ImageChangedCount());

image_resource->Loader()->DidFinishLoading(
base::TimeTicks(), 0, 0, 0, false,
std::vector<network::cors::PreflightTimingInfo>());
image_resource->Loader()->DidFinishLoading(base::TimeTicks(), 0, 0, 0, false,
{});

EXPECT_EQ(ResourceStatus::kDecodeError, image_resource->GetStatus());
EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
Expand Down Expand Up @@ -1093,8 +1087,7 @@ TEST(ImageResourceTest, PartialContentWithoutDimensions) {
image_resource->Loader()->DidFinishLoading(
base::TimeTicks(), kJpegImageSubrangeWithoutDimensionsLength,
kJpegImageSubrangeWithoutDimensionsLength,
kJpegImageSubrangeWithoutDimensionsLength, false,
std::vector<network::cors::PreflightTimingInfo>());
kJpegImageSubrangeWithoutDimensionsLength, false, {});

EXPECT_EQ(ResourceStatus::kDecodeError, image_resource->GetStatus());
EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
Expand Down Expand Up @@ -1322,8 +1315,7 @@ TEST(ImageResourceTest, FetchAllowPlaceholderPartialContentWithoutDimensions) {
image_resource->Loader()->DidFinishLoading(
base::TimeTicks(), kJpegImageSubrangeWithoutDimensionsLength,
kJpegImageSubrangeWithoutDimensionsLength,
kJpegImageSubrangeWithoutDimensionsLength, false,
std::vector<network::cors::PreflightTimingInfo>());
kJpegImageSubrangeWithoutDimensionsLength, false, {});

EXPECT_FALSE(observer->ImageNotifyFinishedCalled());
EXPECT_EQ(2, observer->ImageChangedCount());
Expand Down Expand Up @@ -1464,8 +1456,7 @@ TEST(ImageResourceTest, FetchAllowPlaceholderFullResponseDecodeSuccess) {
reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage));
image_resource->Loader()->DidFinishLoading(
base::TimeTicks(), sizeof(kJpegImage), sizeof(kJpegImage),
sizeof(kJpegImage), false,
std::vector<network::cors::PreflightTimingInfo>());
sizeof(kJpegImage), false, {});

EXPECT_EQ(ResourceStatus::kCached, image_resource->GetStatus());
EXPECT_EQ(sizeof(kJpegImage), image_resource->EncodedSize());
Expand Down
3 changes: 1 addition & 2 deletions third_party/blink/renderer/core/testing/sim/sim_network.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ void SimNetwork::DidFinishLoading(WebURLLoaderClient* client,
if (!current_request_) {
client->DidFinishLoading(finish_time, total_encoded_data_length,
total_encoded_body_length,
total_decoded_body_length, false,
std::vector<network::cors::PreflightTimingInfo>());
total_decoded_body_length, false, {});
return;
}
current_request_ = nullptr;
Expand Down
Loading

0 comments on commit 0ddd49c

Please sign in to comment.