Bumping manifests a=b2g-bump
[gecko.git] / dom / workers / DataStore.h
blob927d1cd8ab611d21d3bfd78c3b5f9a3ab2caf554
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_dom_workers_DataStore_h
6 #define mozilla_dom_workers_DataStore_h
8 #include "mozilla/DOMEventTargetHelper.h"
9 #include "nsProxyRelease.h"
11 #include "WorkerFeature.h"
13 namespace mozilla {
15 class ErrorResult;
17 namespace dom {
19 class Promise;
20 class DataStore;
21 class DataStoreImpl;
22 class StringOrUnsignedLong;
23 class OwningStringOrUnsignedLong;
25 namespace workers {
27 class DataStoreChangeEventProxy;
28 class WorkerDataStoreCursor;
29 class WorkerGlobalScope;
31 class WorkerDataStore MOZ_FINAL : public DOMEventTargetHelper
33 public:
34 NS_DECL_ISUPPORTS_INHERITED
36 WorkerDataStore(WorkerGlobalScope* aScope);
38 // WebIDL (internal functions)
40 static already_AddRefed<WorkerDataStore> Constructor(GlobalObject& aGlobal,
41 ErrorResult& aRv);
43 virtual JSObject* WrapObject(JSContext *aCx) MOZ_OVERRIDE;
45 // WebIDL (public APIs)
47 void GetName(JSContext* aCx, nsAString& aName, ErrorResult& aRv);
49 void GetOwner(JSContext* aCx, nsAString& aOwner, ErrorResult& aRv);
51 bool GetReadOnly(JSContext* aCx, ErrorResult& aRv);
53 already_AddRefed<Promise> Get(JSContext* aCx,
54 const Sequence<OwningStringOrUnsignedLong>& aId,
55 ErrorResult& aRv);
57 already_AddRefed<Promise> Put(JSContext* aCx,
58 JS::Handle<JS::Value> aObj,
59 const StringOrUnsignedLong& aId,
60 const nsAString& aRevisionId,
61 ErrorResult& aRv);
63 already_AddRefed<Promise> Add(JSContext* aCx,
64 JS::Handle<JS::Value> aObj,
65 const Optional<StringOrUnsignedLong>& aId,
66 const nsAString& aRevisionId,
67 ErrorResult& aRv);
69 already_AddRefed<Promise> Remove(JSContext* aCx,
70 const StringOrUnsignedLong& aId,
71 const nsAString& aRevisionId,
72 ErrorResult& aRv);
74 already_AddRefed<Promise> Clear(JSContext* aCx,
75 const nsAString& aRevisionId,
76 ErrorResult& aRv);
78 void GetRevisionId(JSContext* aCx, nsAString& aRevisionId, ErrorResult& aRv);
80 already_AddRefed<Promise> GetLength(JSContext* aCx, ErrorResult& aRv);
82 already_AddRefed<WorkerDataStoreCursor> Sync(JSContext* aCx,
83 const nsAString& aRevisionId,
84 ErrorResult& aRv);
86 IMPL_EVENT_HANDLER(change)
88 // We don't use this for the WorkerDataStore.
89 void SetDataStoreImpl(DataStoreImpl& aStore, ErrorResult& aRv);
91 void SetBackingDataStore(
92 const nsMainThreadPtrHandle<DataStore>& aBackingStore);
94 void SetDataStoreChangeEventProxy(DataStoreChangeEventProxy* aEventProxy);
96 protected:
97 virtual ~WorkerDataStore() {}
99 private:
100 nsMainThreadPtrHandle<DataStore> mBackingStore;
101 nsRefPtr<DataStoreChangeEventProxy> mEventProxy;
104 class DataStoreChangeEventProxy MOZ_FINAL : public nsIDOMEventListener
105 , public WorkerFeature
107 public:
108 NS_DECL_THREADSAFE_ISUPPORTS
109 NS_DECL_NSIDOMEVENTLISTENER
111 DataStoreChangeEventProxy(WorkerPrivate* aWorkerPrivate,
112 WorkerDataStore* aWorkerStore);
114 WorkerPrivate* GetWorkerPrivate() const;
116 WorkerDataStore* GetWorkerStore() const;
118 protected:
119 // WorkerFeature implementation.
121 bool Notify(JSContext* aCx, Status aStatus) MOZ_OVERRIDE;
123 private:
124 ~DataStoreChangeEventProxy() {};
126 WorkerPrivate* mWorkerPrivate;
128 nsRefPtr<WorkerDataStore> mWorkerStore;
130 bool mCleanedUp; // To specify if the worker has been cancelled.
132 // Ensure the worker and the main thread won't race to access |mCleanedUp|.
133 Mutex mCleanUpLock;
136 } //namespace workers
137 } //namespace dom
138 } //namespace mozilla
140 #endif