File: cache_storage.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (110 lines) | stat: -rw-r--r-- 4,864 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// 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.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_CACHE_STORAGE_CACHE_STORAGE_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_CACHE_STORAGE_CACHE_STORAGE_H_

#include <optional>

#include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom-blink-forward.h"
#include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h"
#include "third_party/blink/renderer/bindings/core/v8/idl_types.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_typedefs.h"
#include "third_party/blink/renderer/core/fetch/global_fetch.h"
#include "third_party/blink/renderer/modules/cache_storage/cache.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"

namespace blink {
class Cache;
class CacheStorageBlobClientList;
class MultiCacheQueryOptions;
class ScriptState;

class CacheStorage final : public ScriptWrappable,
                           public ActiveScriptWrappable<CacheStorage>,
                           public ExecutionContextClient {
  DEFINE_WRAPPERTYPEINFO();

 public:
  CacheStorage(ExecutionContext*, GlobalFetch::ScopedFetcher*);
  CacheStorage(ExecutionContext*,
               GlobalFetch::ScopedFetcher*,
               mojo::PendingRemote<mojom::blink::CacheStorage>);

  CacheStorage(const CacheStorage&) = delete;
  CacheStorage& operator=(const CacheStorage&) = delete;

  ~CacheStorage() override;

  ScriptPromise<Cache> open(ScriptState*,
                            const String& cache_name,
                            ExceptionState& exception_state);
  ScriptPromise<IDLBoolean> has(ScriptState*,
                                const String& cache_name,
                                ExceptionState& exception_state);
  ScriptPromise<IDLBoolean> Delete(ScriptState*,
                                   const String& cache_name,
                                   ExceptionState& exception_state);
  ScriptPromise<IDLSequence<IDLString>> keys(ScriptState*, ExceptionState&);
  ScriptPromise<Response> match(ScriptState* script_state,
                                const V8RequestInfo* request,
                                const MultiCacheQueryOptions* options,
                                ExceptionState& exception_state);

  bool HasPendingActivity() const override;
  void Trace(Visitor*) const override;

  mojom::blink::CacheStorage* GetRemoteForDevtools(
      base::OnceClosure disconnect_handler);

 private:
  void MaybeInit();

  // The callback passed into IsCacheStorageAllowed is invoked upon success,
  // and the resolver is rejected upon failure.
  void IsCacheStorageAllowed(ExecutionContext* context,
                             ScriptPromiseResolverBase* resolver,
                             base::OnceCallback<void()> callback);
  void OnCacheStorageAllowed(base::OnceCallback<void()> callback,
                             ScriptPromiseResolverBase* resolver,
                             bool allow_access);

  void OpenImpl(const String& cache_name,
                int64_t trace_id,
                ScriptPromiseResolver<Cache>* resolver);
  void HasImpl(const String& cache_name,
               int64_t trace_id,
               ScriptPromiseResolver<IDLBoolean>* resolver);
  void DeleteImpl(const String& cache_name,
                  int64_t trace_id,
                  ScriptPromiseResolver<IDLBoolean>* resolver);
  void KeysImpl(int64_t trace_id,
                ScriptPromiseResolver<IDLSequence<IDLString>>* resolver);
  ScriptPromise<Response> MatchImpl(ScriptState*,
                                    const Request*,
                                    const MultiCacheQueryOptions*,
                                    ExceptionState& exception_state);
  void MatchImplHelper(const MultiCacheQueryOptions* options,
                       mojom::blink::FetchAPIRequestPtr mojo_request,
                       mojom::blink::MultiCacheQueryOptionsPtr mojo_options,
                       bool in_related_fetch_event,
                       bool in_range_fetch_event,
                       int64_t trace_id,
                       ScriptPromiseResolver<Response>* resolver);

  Member<GlobalFetch::ScopedFetcher> scoped_fetcher_;
  Member<CacheStorageBlobClientList> blob_client_list_;

  HeapMojoRemote<mojom::blink::CacheStorage> cache_storage_remote_;
  std::optional<bool> allowed_;
  bool ever_used_ = false;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_CACHE_STORAGE_CACHE_STORAGE_H_