Chromium Code Reviews| Index: third_party/WebKit/Source/platform/loader/fetch/PreloadKey.h |
| diff --git a/third_party/WebKit/Source/platform/loader/fetch/PreloadKey.h b/third_party/WebKit/Source/platform/loader/fetch/PreloadKey.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a840049cd8d830c27bb9f242922b2be7e6688cfa |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/platform/loader/fetch/PreloadKey.h |
| @@ -0,0 +1,71 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef PreloadKey_h |
| +#define PreloadKey_h |
| + |
| +#include "platform/loader/fetch/Resource.h" |
| +#include "platform/weborigin/KURL.h" |
| +#include "platform/weborigin/KURLHash.h" |
| +#include "platform/wtf/HashTraits.h" |
| + |
| +namespace blink { |
| + |
| +// PreloadKey is a key type of the prealods map in a fetch group (a.k.a. |
| +// blink::ResourceFetcher). |
| +struct PreloadKey final { |
| + public: |
| + struct Hash { |
| + STATIC_ONLY(Hash); |
| + |
| + public: |
| + static unsigned GetHash(const PreloadKey& key) { |
| + return KURLHash::GetHash(key.url); |
| + } |
| + static bool Equal(const PreloadKey& x, const PreloadKey& y) { |
| + return x == y; |
| + } |
| + static constexpr bool safe_to_compare_to_empty_or_deleted = false; |
| + }; |
| + |
| + PreloadKey() = default; |
| + PreloadKey(WTF::HashTableDeletedValueType) |
| + : url(WTF::kHashTableDeletedValue) {} |
| + PreloadKey(const KURL& url, Resource::Type type) |
| + : url(FragmentRemovedUrl(url)), type(type) {} |
| + |
| + bool IsHashTableDeletedValue() const { return url.IsHashTableDeletedValue(); } |
| + |
| + bool operator==(const PreloadKey& x) const { |
| + return url == x.url && type == x.type; |
| + } |
| + |
| + static KURL FragmentRemovedUrl(const KURL& src) { |
|
Nate Chapin
2017/05/02 00:02:16
RemoveFragmentFromUrl() would be a little clearer.
yhirano
2017/05/02 10:22:17
Done.
|
| + if (!src.HasFragmentIdentifier()) |
| + return src; |
| + KURL url = src; |
| + url.RemoveFragmentIdentifier(); |
| + return url; |
| + } |
| + |
| + KURL url; |
| + Resource::Type type = Resource::kMainResource; |
| +}; |
| + |
| +} // namespace blink |
| + |
| +namespace WTF { |
| + |
| +template <> |
| +struct DefaultHash<blink::PreloadKey> { |
| + using Hash = blink::PreloadKey::Hash; |
| +}; |
| + |
| +template <> |
| +struct HashTraits<blink::PreloadKey> |
| + : public SimpleClassHashTraits<blink::PreloadKey> {}; |
| + |
| +} // namespace WTF |
| + |
| +#endif // PreloadKey_h |