chromium/third_party/blink/renderer/modules/cache_storage/cache.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/modules/cache_storage/cache.h"

#include <memory>
#include <utility>

#include "base/containers/contains.h"
#include "base/metrics/histogram_macros.h"
#include "base/task/single_thread_task_runner.h"
#include "services/network/public/mojom/fetch_api.mojom-blink.h"
#include "third_party/blink/public/common/cache_storage/cache_storage_utils.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/callback_promise_adapter.h"
#include "third_party/blink/renderer/bindings/core/v8/idl_types.h"
#include "third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h"
#include "third_party/blink/renderer/bindings/core/v8/script_function.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_code_cache.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_request_init.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_response.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_throw_dom_exception.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_union_request_usvstring.h"
#include "third_party/blink/renderer/core/dom/abort_controller.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/fetch/blob_bytes_consumer.h"
#include "third_party/blink/renderer/core/fetch/body_stream_buffer.h"
#include "third_party/blink/renderer/core/fetch/fetch_data_loader.h"
#include "third_party/blink/renderer/core/fetch/request.h"
#include "third_party/blink/renderer/core/fetch/response.h"
#include "third_party/blink/renderer/core/html/parser/text_resource_decoder.h"
#include "third_party/blink/renderer/modules/cache_storage/cache_storage.h"
#include "third_party/blink/renderer/modules/cache_storage/cache_storage_blob_client_list.h"
#include "third_party/blink/renderer/modules/cache_storage/cache_storage_error.h"
#include "third_party/blink/renderer/modules/cache_storage/cache_storage_trace_utils.h"
#include "third_party/blink/renderer/modules/cache_storage/cache_utils.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/bindings/v8_throw_exception.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/traced_value.h"
#include "third_party/blink/renderer/platform/loader/fetch/cached_metadata.h"
#include "third_party/blink/renderer/platform/network/http_names.h"
#include "third_party/blink/renderer/platform/network/http_parsers.h"
#include "third_party/blink/renderer/platform/network/mime/mime_type_registry.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"

namespace blink {

namespace {

bool VaryHeaderContainsAsterisk(const Response* response) {}

bool HasJavascriptMimeType(const Response* response) {}

void ValidateRequestForPut(const Request* request,
                           ExceptionState& exception_state) {}

enum class CodeCachePolicy {};

CodeCachePolicy GetCodeCachePolicy(ExecutionContext* context,
                                   const Response* response) {}

bool ShouldGenerateV8CodeCache(ScriptState* script_state,
                               const Response* response) {}

}  // namespace

// Waits for all expected Responses and their blob bodies to be available.
class Cache::BarrierCallbackForPutResponse final
    : public GarbageCollected<BarrierCallbackForPutResponse> {};

// Waits for a single Response and then loads its body as a blob.  This class
// also performs validation on the Response and triggers a failure if
// necessary.  Passing true for |require_response_ok| will also trigger a
// failure if the Response status code is not ok.  This is necessary for the
// add/addAll case, but is not used in the put case.
class Cache::ResponseBodyLoader final
    : public GarbageCollected<Cache::ResponseBodyLoader>,
      public FetchDataLoader::Client {};

// Waits for code cache to be generated and writing to cache_storage to
// complete.
class Cache::BarrierCallbackForPutComplete final
    : public GarbageCollected<BarrierCallbackForPutComplete> {};

// Used to handle the GlobalFetch::ScopedFetcher::Fetch promise in AddAllImpl.
// TODO(nhiroki): Unfortunately, we have to go through V8 to wait for the fetch
// promise. It should be better to achieve this only within C++ world.
class Cache::FetchHandler final : public ScriptFunction::Callable {};

class Cache::CodeCacheHandleCallbackForPut final
    : public GarbageCollected<CodeCacheHandleCallbackForPut>,
      public FetchDataLoader::Client {};

ScriptPromise<Response> Cache::match(ScriptState* script_state,
                                     const V8RequestInfo* request,
                                     const CacheQueryOptions* options,
                                     ExceptionState& exception_state) {}

ScriptPromise<IDLSequence<Response>> Cache::matchAll(
    ScriptState* script_state,
    ExceptionState& exception_state) {}

ScriptPromise<IDLSequence<Response>> Cache::matchAll(
    ScriptState* script_state,
    const V8RequestInfo* request,
    const CacheQueryOptions* options,
    ExceptionState& exception_state) {}

ScriptPromise<IDLUndefined> Cache::add(ScriptState* script_state,
                                       const V8RequestInfo* request,
                                       ExceptionState& exception_state) {}

ScriptPromise<IDLUndefined> Cache::addAll(
    ScriptState* script_state,
    const HeapVector<Member<V8RequestInfo>>& requests,
    ExceptionState& exception_state) {}

ScriptPromise<IDLBoolean> Cache::Delete(ScriptState* script_state,
                                        const V8RequestInfo* request,
                                        const CacheQueryOptions* options,
                                        ExceptionState& exception_state) {}

ScriptPromise<IDLUndefined> Cache::put(ScriptState* script_state,
                                       const V8RequestInfo* request_info,
                                       Response* response,
                                       ExceptionState& exception_state) {}

ScriptPromise<IDLSequence<Request>> Cache::keys(
    ScriptState* script_state,
    ExceptionState& exception_state) {}

ScriptPromise<IDLSequence<Request>> Cache::keys(
    ScriptState* script_state,
    const V8RequestInfo* request,
    const CacheQueryOptions* options,
    ExceptionState& exception_state) {}

Cache::Cache(GlobalFetch::ScopedFetcher* fetcher,
             CacheStorageBlobClientList* blob_client_list,
             mojo::PendingAssociatedRemote<mojom::blink::CacheStorageCache>
                 cache_pending_remote,
             ExecutionContext* execution_context,
             TaskType task_type)
    :{}

void Cache::Trace(Visitor* visitor) const {}

AbortController* Cache::CreateAbortController(ScriptState* script_state) {}

ScriptPromise<Response> Cache::MatchImpl(ScriptState* script_state,
                                         const Request* request,
                                         const CacheQueryOptions* options,
                                         ExceptionState& exception_state) {}

ScriptPromise<IDLSequence<Response>> Cache::MatchAllImpl(
    ScriptState* script_state,
    const Request* request,
    const CacheQueryOptions* options,
    ExceptionState& exception_state) {}

ScriptPromise<IDLUndefined> Cache::AddAllImpl(
    ScriptState* script_state,
    const String& method_name,
    const HeapVector<Member<Request>>& request_list,
    ExceptionState& exception_state) {}

ScriptPromise<IDLBoolean> Cache::DeleteImpl(ScriptState* script_state,
                                            const Request* request,
                                            const CacheQueryOptions* options,
                                            ExceptionState& exception_state) {}

void Cache::PutImpl(ScriptPromiseResolver<IDLUndefined>* resolver,
                    const String& method_name,
                    const HeapVector<Member<Request>>& requests,
                    const HeapVector<Member<Response>>& responses,
                    const WTF::Vector<scoped_refptr<BlobDataHandle>>& blob_list,
                    ExceptionState& exception_state,
                    int64_t trace_id) {}

ScriptPromise<IDLSequence<Request>> Cache::KeysImpl(
    ScriptState* script_state,
    const Request* request,
    const CacheQueryOptions* options,
    ExceptionState& exception_state) {}

}  // namespace blink