Commit 4d908127 authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Replace use of std containers with WTF's equivalents in source_keyed_cached_metadata_handler.h

This CL replaces the use of std::array of std containers
with WTF::Vector in source_keyed_cached_metadata_handler.h.

Bug: 952716
Change-Id: Ia345560fef2b6f4546bb7c300f630ac451f9ecd3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1695142Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Cr-Commit-Position: refs/heads/master@{#676188}
parent 34966cc4
...@@ -96,7 +96,7 @@ SingleCachedMetadataHandler* SourceKeyedCachedMetadataHandler::HandlerForSource( ...@@ -96,7 +96,7 @@ SingleCachedMetadataHandler* SourceKeyedCachedMetadataHandler::HandlerForSource(
source.CharactersSizeInBytes(), digest_value)) source.CharactersSizeInBytes(), digest_value))
return nullptr; return nullptr;
Key key; Key key(kKeySize);
DCHECK_EQ(digest_value.size(), kKeySize); DCHECK_EQ(digest_value.size(), kKeySize);
memcpy(key.data(), digest_value.data(), kKeySize); memcpy(key.data(), digest_value.data(), kKeySize);
...@@ -192,7 +192,7 @@ void SourceKeyedCachedMetadataHandler::SetSerializedCachedMetadata( ...@@ -192,7 +192,7 @@ void SourceKeyedCachedMetadataHandler::SetSerializedCachedMetadata(
return; return;
} }
Key key; Key key(kKeySize);
std::copy(data, data + kKeySize, std::begin(key)); std::copy(data, data + kKeySize, std::begin(key));
data += kKeySize; data += kKeySize;
size_t entry_size = ReadVal<size_t>(data); size_t entry_size = ReadVal<size_t>(data);
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_LOADER_FETCH_SOURCE_KEYED_CACHED_METADATA_HANDLER_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_LOADER_FETCH_SOURCE_KEYED_CACHED_METADATA_HANDLER_H_
#include <stdint.h> #include <stdint.h>
#include <array>
#include "third_party/blink/renderer/platform/loader/fetch/cached_metadata.h" #include "third_party/blink/renderer/platform/loader/fetch/cached_metadata.h"
#include "third_party/blink/renderer/platform/loader/fetch/cached_metadata_handler.h" #include "third_party/blink/renderer/platform/loader/fetch/cached_metadata_handler.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource.h" #include "third_party/blink/renderer/platform/loader/fetch/resource.h"
...@@ -51,7 +50,7 @@ class PLATFORM_EXPORT SourceKeyedCachedMetadataHandler final ...@@ -51,7 +50,7 @@ class PLATFORM_EXPORT SourceKeyedCachedMetadataHandler final
private: private:
// Keys are SHA-256, which are 256/8 = 32 bytes. // Keys are SHA-256, which are 256/8 = 32 bytes.
static constexpr size_t kKeySize = 32; static constexpr size_t kKeySize = 32;
typedef std::array<uint8_t, kKeySize> Key; typedef Vector<uint8_t, kKeySize> Key;
class SingleKeyHandler; class SingleKeyHandler;
class KeyHash; class KeyHash;
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
#include "third_party/blink/renderer/platform/loader/fetch/source_keyed_cached_metadata_handler.h" #include "third_party/blink/renderer/platform/loader/fetch/source_keyed_cached_metadata_handler.h"
#include <array>
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/web_crypto.h" #include "third_party/blink/public/platform/web_crypto.h"
#include "third_party/blink/renderer/platform/crypto.h" #include "third_party/blink/renderer/platform/crypto.h"
...@@ -88,16 +86,15 @@ class MockCachedMetadataSender final : public CachedMetadataSender { ...@@ -88,16 +86,15 @@ class MockCachedMetadataSender final : public CachedMetadataSender {
const base::Time response_time_; const base::Time response_time_;
}; };
template <size_t N>
::testing::AssertionResult CachedMetadataFailure( ::testing::AssertionResult CachedMetadataFailure(
const char* failure_msg, const char* failure_msg,
const char* actual_expression, const char* actual_expression,
const std::array<uint8_t, N>& expected, const Vector<uint8_t>& expected,
const scoped_refptr<CachedMetadata>& actual) { const scoped_refptr<CachedMetadata>& actual) {
::testing::Message msg; ::testing::Message msg;
msg << failure_msg << " for " << actual_expression; msg << failure_msg << " for " << actual_expression;
msg << "\n Expected: [" << N << "] { "; msg << "\n Expected: [" << expected.size() << "] { ";
for (size_t i = 0; i < N; ++i) { for (size_t i = 0; i < expected.size(); ++i) {
if (i > 0) if (i > 0)
msg << ", "; msg << ", ";
msg << std::hex << static_cast<int>(expected[i]); msg << std::hex << static_cast<int>(expected[i]);
...@@ -118,22 +115,21 @@ template <size_t N> ...@@ -118,22 +115,21 @@ template <size_t N>
return testing::AssertionFailure() << msg; return testing::AssertionFailure() << msg;
} }
template <size_t N>
::testing::AssertionResult CachedMetadataEqual( ::testing::AssertionResult CachedMetadataEqual(
const char* expected_expression, const char* expected_expression,
const char* actual_expression, const char* actual_expression,
const std::array<uint8_t, N>& expected, const Vector<uint8_t>& expected,
const scoped_refptr<CachedMetadata>& actual) { const scoped_refptr<CachedMetadata>& actual) {
if (!actual) { if (!actual) {
return CachedMetadataFailure("Expected non-null data", actual_expression, return CachedMetadataFailure("Expected non-null data", actual_expression,
expected, actual); expected, actual);
} }
if (actual->size() != N) { if (actual->size() != expected.size()) {
return CachedMetadataFailure("Wrong size", actual_expression, expected, return CachedMetadataFailure("Wrong size", actual_expression, expected,
actual); actual);
} }
const uint8_t* actual_data = actual->Data(); const uint8_t* actual_data = actual->Data();
for (size_t i = 0; i < N; ++i) { for (size_t i = 0; i < expected.size(); ++i) {
if (actual_data[i] != expected[i]) { if (actual_data[i] != expected[i]) {
return CachedMetadataFailure("Wrong data", actual_expression, expected, return CachedMetadataFailure("Wrong data", actual_expression, expected,
actual); actual);
...@@ -190,7 +186,7 @@ TEST(SourceKeyedCachedMetadataHandlerTest, ...@@ -190,7 +186,7 @@ TEST(SourceKeyedCachedMetadataHandlerTest,
SingleCachedMetadataHandler* source2_handler = SingleCachedMetadataHandler* source2_handler =
handler->HandlerForSource(source2); handler->HandlerForSource(source2);
std::array<uint8_t, 3> data1 = {1, 2, 3}; Vector<uint8_t> data1 = {1, 2, 3};
source1_handler->SetCachedMetadata(0xbeef, data1.data(), data1.size()); source1_handler->SetCachedMetadata(0xbeef, data1.data(), data1.size());
EXPECT_NE(nullptr, source1_handler); EXPECT_NE(nullptr, source1_handler);
...@@ -217,10 +213,10 @@ TEST(SourceKeyedCachedMetadataHandlerTest, HandlerForSource_BothHandlersSet) { ...@@ -217,10 +213,10 @@ TEST(SourceKeyedCachedMetadataHandlerTest, HandlerForSource_BothHandlersSet) {
SingleCachedMetadataHandler* source2_handler = SingleCachedMetadataHandler* source2_handler =
handler->HandlerForSource(source2); handler->HandlerForSource(source2);
std::array<uint8_t, 3> data1 = {1, 2, 3}; Vector<uint8_t> data1 = {1, 2, 3};
source1_handler->SetCachedMetadata(0xbeef, data1.data(), data1.size()); source1_handler->SetCachedMetadata(0xbeef, data1.data(), data1.size());
std::array<uint8_t, 4> data2 = {3, 4, 5, 6}; Vector<uint8_t> data2 = {3, 4, 5, 6};
source2_handler->SetCachedMetadata(0x5eed, data2.data(), data2.size()); source2_handler->SetCachedMetadata(0x5eed, data2.data(), data2.size());
EXPECT_NE(nullptr, source1_handler); EXPECT_NE(nullptr, source1_handler);
...@@ -266,10 +262,10 @@ TEST(SourceKeyedCachedMetadataHandlerTest, Serialize_EachSetDoesSend) { ...@@ -266,10 +262,10 @@ TEST(SourceKeyedCachedMetadataHandlerTest, Serialize_EachSetDoesSend) {
SingleCachedMetadataHandler* source2_handler = SingleCachedMetadataHandler* source2_handler =
handler->HandlerForSource(source2); handler->HandlerForSource(source2);
std::array<uint8_t, 3> data1 = {1, 2, 3}; Vector<uint8_t> data1 = {1, 2, 3};
source1_handler->SetCachedMetadata(0xbeef, data1.data(), data1.size()); source1_handler->SetCachedMetadata(0xbeef, data1.data(), data1.size());
std::array<uint8_t, 4> data2 = {3, 4, 5, 6}; Vector<uint8_t> data2 = {3, 4, 5, 6};
source2_handler->SetCachedMetadata(0x5eed, data2.data(), data2.size()); source2_handler->SetCachedMetadata(0x5eed, data2.data(), data2.size());
// Load from platform // Load from platform
...@@ -296,11 +292,11 @@ TEST(SourceKeyedCachedMetadataHandlerTest, Serialize_SetWithNoSendDoesNotSend) { ...@@ -296,11 +292,11 @@ TEST(SourceKeyedCachedMetadataHandlerTest, Serialize_SetWithNoSendDoesNotSend) {
SingleCachedMetadataHandler* source2_handler = SingleCachedMetadataHandler* source2_handler =
handler->HandlerForSource(source2); handler->HandlerForSource(source2);
std::array<uint8_t, 3> data1 = {1, 2, 3}; Vector<uint8_t> data1 = {1, 2, 3};
source1_handler->SetCachedMetadata(0xbeef, data1.data(), data1.size(), source1_handler->SetCachedMetadata(0xbeef, data1.data(), data1.size(),
CachedMetadataHandler::kCacheLocally); CachedMetadataHandler::kCacheLocally);
std::array<uint8_t, 4> data2 = {3, 4, 5, 6}; Vector<uint8_t> data2 = {3, 4, 5, 6};
source2_handler->SetCachedMetadata(0x5eed, data2.data(), data2.size()); source2_handler->SetCachedMetadata(0x5eed, data2.data(), data2.size());
// Load from platform // Load from platform
...@@ -364,8 +360,8 @@ TEST(SourceKeyedCachedMetadataHandlerTest, ...@@ -364,8 +360,8 @@ TEST(SourceKeyedCachedMetadataHandlerTest,
KURL url("http://SourceKeyedCachedMetadataHandlerTest.com"); KURL url("http://SourceKeyedCachedMetadataHandlerTest.com");
WTF::String source1("source1"); WTF::String source1("source1");
WTF::String source2("source2"); WTF::String source2("source2");
std::array<uint8_t, 3> data1 = {1, 2, 3}; Vector<uint8_t> data1 = {1, 2, 3};
std::array<uint8_t, 4> data2 = {3, 4, 5, 6}; Vector<uint8_t> data2 = {3, 4, 5, 6};
{ {
SourceKeyedCachedMetadataHandler* handler = SourceKeyedCachedMetadataHandler* handler =
MakeGarbageCollected<SourceKeyedCachedMetadataHandler>( MakeGarbageCollected<SourceKeyedCachedMetadataHandler>(
......
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