chromium/third_party/blink/renderer/core/loader/resource/font_resource.cc

/*
 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
 * Copyright (C) 2009 Torch Mobile, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#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  // IS_WIN

ResultOrError;

namespace WTF {

template <>
struct CrossThreadCopier<ResultOrError> {};

template <>
struct CrossThreadCopier<SegmentedBuffer> {};

}  // namespace WTF

namespace blink {

namespace {
// Durations of font-display periods.
// https://tabatkins.github.io/specs/css-font-display/#font-display-desc
// TODO(toyoshim): Revisit short limit value once cache-aware font display is
// launched. crbug.com/570205
constexpr base::TimeDelta kFontLoadWaitShort =;
constexpr base::TimeDelta kFontLoadWaitLong =;

base::expected<FontResource::DecodedResult, String> DecodeFont(
    SegmentedBuffer* buffer) {}

scoped_refptr<base::SequencedTaskRunner> GetFontDecodingTaskRunner() {}

}  // namespace

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() {}

// static
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 {}

}  // namespace blink