#include "third_party/blink/renderer/core/loader/resource/font_resource.h"
#include <utility>
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/numerics/checked_math.h"
#include "base/numerics/safe_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/trace_event/memory_dump_manager.h"
#include "base/types/expected.h"
#include "build/build_config.h"
#include "mojo/public/cpp/system/data_pipe_drainer.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-blink.h"
#include "third_party/blink/public/mojom/loader/request_context_frame_type.mojom-blink.h"
#include "third_party/blink/renderer/platform/fonts/font_custom_platform_data.h"
#include "third_party/blink/renderer/platform/fonts/font_platform_data.h"
#include "third_party/blink/renderer/platform/fonts/web_font_decoder.h"
#include "third_party/blink/renderer/platform/heap/cross_thread_handle.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_parameters.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_client_walker.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_loader.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_pool.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_base.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_mojo.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/deque.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/shared_buffer.h"
#if BUILDFLAG(IS_WIN)
#include "third_party/blink/renderer/platform/scheduler/public/non_main_thread.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#endif
ResultOrError;
namespace WTF {
template <>
struct CrossThreadCopier<ResultOrError> { … };
template <>
struct CrossThreadCopier<SegmentedBuffer> { … };
}
namespace blink {
namespace {
constexpr base::TimeDelta kFontLoadWaitShort = …;
constexpr base::TimeDelta kFontLoadWaitLong = …;
base::expected<FontResource::DecodedResult, String> DecodeFont(
SegmentedBuffer* buffer) { … }
scoped_refptr<base::SequencedTaskRunner> GetFontDecodingTaskRunner() { … }
}
class FontResource::BackgroundFontProcessor final
: public BackgroundResponseProcessor,
public mojo::DataPipeDrainer::Client { … };
class FontResource::BackgroundFontProcessorFactory
: public BackgroundResponseProcessorFactory { … };
FontResource::BackgroundFontProcessor::BackgroundFontProcessor(
CrossThreadWeakHandle<FontResource> resource_handle)
: … { … }
FontResource::BackgroundFontProcessor::~BackgroundFontProcessor() = default;
bool FontResource::BackgroundFontProcessor::MaybeStartProcessingResponse(
network::mojom::URLResponseHeadPtr& head,
mojo::ScopedDataPipeConsumerHandle& body,
std::optional<mojo_base::BigBuffer>& cached_metadata_buffer,
scoped_refptr<base::SequencedTaskRunner> background_task_runner,
BackgroundResponseProcessor::Client* client) { … }
void FontResource::BackgroundFontProcessor::OnDataAvailable(
base::span<const uint8_t> data) { … }
void FontResource::BackgroundFontProcessor::OnDataComplete() { … }
void FontResource::BackgroundFontProcessor::DecodeOnBackgroundThread(
SegmentedBuffer data,
scoped_refptr<base::SequencedTaskRunner> background_task_runner,
base::WeakPtr<BackgroundFontProcessor> weak_this) { … }
void FontResource::BackgroundFontProcessor::OnDecodeComplete(
base::expected<DecodedResult, String> result_or_error,
SegmentedBuffer data) { … }
FontResource::BackgroundFontProcessorFactory::BackgroundFontProcessorFactory(
CrossThreadWeakHandle<FontResource> resource_handle)
: … { … }
FontResource::BackgroundFontProcessorFactory::
~BackgroundFontProcessorFactory() = default;
std::unique_ptr<BackgroundResponseProcessor>
FontResource::BackgroundFontProcessorFactory::Create() && { … }
FontResource* FontResource::Fetch(FetchParameters& params,
ResourceFetcher* fetcher,
FontResourceClient* client) { … }
FontResource::FontResource(const ResourceRequest& resource_request,
const ResourceLoaderOptions& options)
: … { … }
FontResource::~FontResource() = default;
void FontResource::DidAddClient(ResourceClient* c) { … }
void FontResource::SetRevalidatingRequest(const ResourceRequestHead& request) { … }
void FontResource::StartLoadLimitTimersIfNecessary(
base::SingleThreadTaskRunner* task_runner) { … }
const FontCustomPlatformData* FontResource::GetCustomFontData() { … }
void FontResource::WillReloadAfterDiskCacheMiss() { … }
void FontResource::FontLoadShortLimitCallback() { … }
void FontResource::FontLoadLongLimitCallback() { … }
void FontResource::NotifyClientsShortLimitExceeded() { … }
void FontResource::NotifyClientsLongLimitExceeded() { … }
void FontResource::NotifyFinished() { … }
bool FontResource::IsLowPriorityLoadingAllowedForRemoteFont() const { … }
void FontResource::OnMemoryDump(WebMemoryDumpLevelOfDetail level,
WebProcessMemoryDump* memory_dump) const { … }
void FontResource::AddClearDataObserver(
FontResourceClearDataObserver* observer) const { … }
std::unique_ptr<BackgroundResponseProcessorFactory>
FontResource::MaybeCreateBackgroundResponseProcessorFactory() { … }
void FontResource::OnBackgroundDecodeFinished(
base::expected<DecodedResult, String> result_or_error) { … }
void FontResource::Trace(Visitor* visitor) const { … }
}