File: BoundStorageKeyCache.h

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (180 lines) | stat: -rw-r--r-- 6,214 bytes parent folder | download | duplicates (5)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_dom_cache_BoundStorageKeyCache_h
#define mozilla_dom_cache_BoundStorageKeyCache_h

#include "mozilla/dom/cache/CacheTypes.h"
#include "mozilla/dom/cache/TypeUtils.h"
#include "mozilla/dom/cache/Types.h"
#include "nsCOMPtr.h"
#include "nsISupportsImpl.h"

class nsIGlobalObject;

namespace mozilla {
class ErrorResult;

namespace dom {

class OwningRequestOrUTF8String;
struct CacheQueryOptions;
class RequestOrUTF8String;
class Response;
class Request;
template <typename T>
class Optional;
template <typename T>
class Sequence;
enum class CallerType : uint32_t;

namespace cache {
class AutoChildOpArgs;
class CacheChild;

using CachePromise = MozPromiseBase;

/* This is similar to Cache class as BoundStorageKeyCacheStorage is to
 * CacheStorage i.e.
 * 1. Exposes and implements Cache APIs but uses MozPromise as it's return value
 * rather than JS Promise
 * 2. IPC communication can be retargetted to any event target as it's protocol
 * gets created on a top-level actor
 */
class BoundStorageKeyCache final : public nsISupports,
                                   public TypeUtils,
                                   public CacheChildListener {
 public:
  NS_DECL_ISUPPORTS

  using MatchResultPromise =
      mozilla::MozPromise<RefPtr<dom::Response>, ErrorResult,
                          true /* IsExclusive= */>;
  using MatchAllResultPromise =
      mozilla::MozPromise<nsTArray<RefPtr<dom::Response>>, ErrorResult,
                          true /* IsExclusive= */>;
  using AddResultPromise =
      mozilla::MozPromise<bool, ErrorResult, true /* IsExclusive= */>;
  using AddAllResultPromise =
      mozilla::MozPromise<bool, ErrorResult, true /* IsExclusive= */>;
  using PutResultPromise =
      mozilla::MozPromise<bool, ErrorResult, true /* IsExclusive= */>;
  using PutAllResultPromise =
      mozilla::MozPromise<bool, ErrorResult, true /* IsExclusive= */>;
  using DeleteResultPromise =
      mozilla::MozPromise<bool, ErrorResult, true /* IsExclusive= */>;
  using KeysResultPromise =
      mozilla::MozPromise<nsTArray<SafeRefPtr<dom::Request>>, ErrorResult,
                          true /* IsExclusive= */>;

  BoundStorageKeyCache(nsIGlobalObject* aGlobal, CacheChild* aActor,
                       Namespace aNamespace);

  static bool CachesEnabled(JSContext* aCx, JSObject*);

  already_AddRefed<CachePromise> Match(JSContext* aCx,
                                       const RequestOrUTF8String& aRequest,
                                       const CacheQueryOptions& aOptions,
                                       ErrorResult& aRv);

  already_AddRefed<CachePromise> MatchAll(
      JSContext* aCx, const Optional<RequestOrUTF8String>& aRequest,
      const CacheQueryOptions& aOptions, ErrorResult& aRv);

  already_AddRefed<CachePromise> Add(JSContext* aContext,
                                     const RequestOrUTF8String& aRequest,
                                     CallerType aCallerType, ErrorResult& aRv);

  already_AddRefed<CachePromise> AddAll(
      JSContext* aContext,
      const Sequence<OwningRequestOrUTF8String>& aRequestList,
      CallerType aCallerType, ErrorResult& aRv);

  already_AddRefed<CachePromise> Put(JSContext* aCx,
                                     const RequestOrUTF8String& aRequest,
                                     Response& aResponse, ErrorResult& aRv);

  already_AddRefed<CachePromise> Delete(JSContext* aCx,
                                        const RequestOrUTF8String& aRequest,
                                        const CacheQueryOptions& aOptions,
                                        ErrorResult& aRv);

  already_AddRefed<CachePromise> Keys(
      JSContext* aCx, const Optional<RequestOrUTF8String>& aRequest,
      const CacheQueryOptions& aOptions, ErrorResult& aRv);

  // Called when CacheChild actor is being destroyed
  void OnActorDestroy(CacheChild* aActor) override;

  // TypeUtils methods
  virtual nsIGlobalObject* GetGlobalObject() const override;

#ifdef DEBUG
  virtual void AssertOwningThread() const override;
#endif

 private:
  ~BoundStorageKeyCache();

  // Called when we're destroyed or CCed.
  void DisconnectFromActor();

  void ExecuteOp(AutoChildOpArgs& aOpArgs, RefPtr<CachePromise>& aPromise,
                 ErrorResult& aRv);

  already_AddRefed<CachePromise> AddAll(
      const GlobalObject& aGlobal, nsTArray<SafeRefPtr<Request>>&& aRequestList,
      CallerType aCallerType, ErrorResult& aRv);

  already_AddRefed<CachePromise> PutAll(
      JSContext* aCx, const nsTArray<SafeRefPtr<Request>>& aRequestList,
      const nsTArray<RefPtr<Response>>& aResponseList, ErrorResult& aRv);

  OpenMode GetOpenMode() const;

  nsCOMPtr<nsIGlobalObject> mGlobal;
  CacheChild* mActor;
  const Namespace mNamespace;
};

}  // namespace cache

template <dom::cache::CacheOpResult::Type OP_TYPE>
struct cachestorage_traits;

template <>
struct cachestorage_traits<dom::cache::CacheOpResult::Type::TCacheMatchResult> {
  using PromiseType = cache::BoundStorageKeyCache::MatchResultPromise::Private;
};

template <>
struct cachestorage_traits<
    dom::cache::CacheOpResult::Type::TCacheMatchAllResult> {
  using PromiseType =
      cache::BoundStorageKeyCache::MatchAllResultPromise::Private;
};

template <>
struct cachestorage_traits<
    dom::cache::CacheOpResult::Type::TCachePutAllResult> {
  using PromiseType = cache::BoundStorageKeyCache::PutAllResultPromise::Private;
};

template <>
struct cachestorage_traits<
    dom::cache::CacheOpResult::Type::TCacheDeleteResult> {
  using PromiseType = cache::BoundStorageKeyCache::DeleteResultPromise::Private;
};

template <>
struct cachestorage_traits<dom::cache::CacheOpResult::Type::TCacheKeysResult> {
  using PromiseType = cache::BoundStorageKeyCache::KeysResultPromise::Private;
};

}  // namespace dom
}  // namespace mozilla

#endif  // mozilla_dom_cache_BoundStorageKeyCache_h