1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_DataStoreService_h
8 #define mozilla_dom_DataStoreService_h
10 #include "mozilla/dom/PContent.h"
11 #include "nsClassHashtable.h"
12 #include "nsIDataStoreService.h"
13 #include "nsIObserver.h"
14 #include "nsRefPtrHashtable.h"
17 class nsIUUIDGenerator
;
24 class FirstRevisionIdCallback
;
27 class RetrieveRevisionsCounter
;
28 class RevisionAddedEnableStoreCallback
;
30 class DataStoreService MOZ_FINAL
: public nsIDataStoreService
33 friend class ContentChild
;
34 friend class FirstRevisionIdCallback
;
35 friend class RetrieveRevisionsCounter
;
36 friend class RevisionAddedEnableStoreCallback
;
41 NS_DECL_NSIDATASTORESERVICE
43 // Returns the DataStoreService singleton. Only to be called from main
45 static already_AddRefed
<DataStoreService
> GetOrCreate();
47 static already_AddRefed
<DataStoreService
> Get();
49 static void Shutdown();
51 static bool CheckPermission(nsIPrincipal
* principal
);
53 nsresult
GenerateUUID(nsAString
& aID
);
55 nsresult
GetDataStoresFromIPC(const nsAString
& aName
,
56 const nsAString
& aOwner
,
57 nsIPrincipal
* aPrincipal
,
58 nsTArray
<DataStoreSetting
>* aValue
);
66 typedef nsClassHashtable
<nsUint32HashKey
, DataStoreInfo
> HashApp
;
68 nsresult
AddPermissions(uint32_t aAppId
, const nsAString
& aName
,
69 const nsAString
& aOriginURL
,
70 const nsAString
& aManifestURL
,
73 nsresult
AddAccessPermissions(uint32_t aAppId
, const nsAString
& aName
,
74 const nsAString
& aOriginURL
,
75 const nsAString
& aManifestURL
,
78 nsresult
CreateFirstRevisionId(uint32_t aAppId
, const nsAString
& aName
,
79 const nsAString
& aManifestURL
);
81 void GetDataStoresCreate(nsPIDOMWindow
* aWindow
, Promise
* aPromise
,
82 const nsTArray
<DataStoreInfo
>& aStores
);
84 void GetDataStoresResolve(nsPIDOMWindow
* aWindow
, Promise
* aPromise
,
85 const nsTArray
<DataStoreInfo
>& aStores
);
87 nsresult
GetDataStoreInfos(const nsAString
& aName
, const nsAString
& aOwner
,
88 uint32_t aAppId
, nsIPrincipal
* aPrincipal
,
89 nsTArray
<DataStoreInfo
>& aStores
);
91 void DeleteDataStores(uint32_t aAppId
);
93 nsresult
EnableDataStore(uint32_t aAppId
, const nsAString
& aName
,
94 const nsAString
& aManifestURL
);
96 already_AddRefed
<RetrieveRevisionsCounter
> GetCounter(uint32_t aId
) const;
98 void RemoveCounter(uint32_t aId
);
100 nsClassHashtable
<nsStringHashKey
, HashApp
> mStores
;
101 nsClassHashtable
<nsStringHashKey
, HashApp
> mAccessStores
;
103 typedef nsTArray
<PendingRequest
> PendingRequests
;
104 nsClassHashtable
<nsStringHashKey
, PendingRequests
> mPendingRequests
;
106 nsRefPtrHashtable
<nsUint32HashKey
, RetrieveRevisionsCounter
> mPendingCounters
;
108 nsCOMPtr
<nsIUUIDGenerator
> mUUIDGenerator
;
112 } // namespace mozilla
114 #endif // mozilla_dom_DataStoreService_h