|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
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/. */ |
|
6 |
|
7 #ifndef mozilla_dom_quota_client_h__ |
|
8 #define mozilla_dom_quota_client_h__ |
|
9 |
|
10 #include "mozilla/dom/quota/QuotaCommon.h" |
|
11 |
|
12 #include "PersistenceType.h" |
|
13 |
|
14 class nsIOfflineStorage; |
|
15 class nsIRunnable; |
|
16 |
|
17 #define IDB_DIRECTORY_NAME "idb" |
|
18 #define ASMJSCACHE_DIRECTORY_NAME "asmjs" |
|
19 |
|
20 BEGIN_QUOTA_NAMESPACE |
|
21 |
|
22 class OriginOrPatternString; |
|
23 class UsageInfo; |
|
24 |
|
25 // An abstract interface for quota manager clients. |
|
26 // Each storage API must provide an implementation of this interface in order |
|
27 // to participate in centralized quota and storage handling. |
|
28 class Client |
|
29 { |
|
30 public: |
|
31 NS_IMETHOD_(MozExternalRefCountType) |
|
32 AddRef() = 0; |
|
33 |
|
34 NS_IMETHOD_(MozExternalRefCountType) |
|
35 Release() = 0; |
|
36 |
|
37 enum Type { |
|
38 IDB = 0, |
|
39 //LS, |
|
40 //APPCACHE, |
|
41 ASMJS, |
|
42 TYPE_MAX |
|
43 }; |
|
44 |
|
45 virtual Type |
|
46 GetType() = 0; |
|
47 |
|
48 static nsresult |
|
49 TypeToText(Type aType, nsAString& aText) |
|
50 { |
|
51 switch (aType) { |
|
52 case IDB: |
|
53 aText.AssignLiteral(IDB_DIRECTORY_NAME); |
|
54 break; |
|
55 |
|
56 case ASMJS: |
|
57 aText.AssignLiteral(ASMJSCACHE_DIRECTORY_NAME); |
|
58 break; |
|
59 |
|
60 case TYPE_MAX: |
|
61 default: |
|
62 NS_NOTREACHED("Bad id value!"); |
|
63 return NS_ERROR_UNEXPECTED; |
|
64 } |
|
65 |
|
66 return NS_OK; |
|
67 } |
|
68 |
|
69 static nsresult |
|
70 TypeFromText(const nsAString& aText, Type& aType) |
|
71 { |
|
72 if (aText.EqualsLiteral(IDB_DIRECTORY_NAME)) { |
|
73 aType = IDB; |
|
74 } |
|
75 else if (aText.EqualsLiteral(ASMJSCACHE_DIRECTORY_NAME)) { |
|
76 aType = ASMJS; |
|
77 } |
|
78 else { |
|
79 return NS_ERROR_FAILURE; |
|
80 } |
|
81 |
|
82 return NS_OK; |
|
83 } |
|
84 |
|
85 // Methods which are called on the IO thred. |
|
86 virtual nsresult |
|
87 InitOrigin(PersistenceType aPersistenceType, |
|
88 const nsACString& aGroup, |
|
89 const nsACString& aOrigin, |
|
90 UsageInfo* aUsageInfo) = 0; |
|
91 |
|
92 virtual nsresult |
|
93 GetUsageForOrigin(PersistenceType aPersistenceType, |
|
94 const nsACString& aGroup, |
|
95 const nsACString& aOrigin, |
|
96 UsageInfo* aUsageInfo) = 0; |
|
97 |
|
98 virtual void |
|
99 OnOriginClearCompleted(PersistenceType aPersistenceType, |
|
100 const OriginOrPatternString& aOriginOrPattern) = 0; |
|
101 |
|
102 virtual void |
|
103 ReleaseIOThreadObjects() = 0; |
|
104 |
|
105 // Methods which are called on the main thred. |
|
106 virtual bool |
|
107 IsFileServiceUtilized() = 0; |
|
108 |
|
109 virtual bool |
|
110 IsTransactionServiceActivated() = 0; |
|
111 |
|
112 virtual void |
|
113 WaitForStoragesToComplete(nsTArray<nsIOfflineStorage*>& aStorages, |
|
114 nsIRunnable* aCallback) = 0; |
|
115 |
|
116 virtual void |
|
117 AbortTransactionsForStorage(nsIOfflineStorage* aStorage) = 0; |
|
118 |
|
119 virtual bool |
|
120 HasTransactionsForStorage(nsIOfflineStorage* aStorage) = 0; |
|
121 |
|
122 virtual void |
|
123 ShutdownTransactionService() = 0; |
|
124 |
|
125 protected: |
|
126 virtual ~Client() |
|
127 { } |
|
128 }; |
|
129 |
|
130 END_QUOTA_NAMESPACE |
|
131 |
|
132 #endif // mozilla_dom_quota_client_h__ |