|
1 //* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef nsAnnotationService_h___ |
|
7 #define nsAnnotationService_h___ |
|
8 |
|
9 #include "nsIAnnotationService.h" |
|
10 #include "nsTArray.h" |
|
11 #include "nsCOMArray.h" |
|
12 #include "nsCOMPtr.h" |
|
13 #include "nsServiceManagerUtils.h" |
|
14 #include "nsWeakReference.h" |
|
15 #include "nsToolkitCompsCID.h" |
|
16 #include "Database.h" |
|
17 #include "nsString.h" |
|
18 #include "mozilla/Attributes.h" |
|
19 |
|
20 namespace mozilla { |
|
21 namespace places { |
|
22 |
|
23 class AnnotatedResult MOZ_FINAL : public mozIAnnotatedResult |
|
24 { |
|
25 public: |
|
26 NS_DECL_ISUPPORTS |
|
27 NS_DECL_MOZIANNOTATEDRESULT |
|
28 |
|
29 AnnotatedResult(const nsCString& aGUID, nsIURI* aURI, int64_t aItemd, |
|
30 const nsACString& aAnnotationName, |
|
31 nsIVariant* aAnnotationValue); |
|
32 |
|
33 private: |
|
34 const nsCString mGUID; |
|
35 nsCOMPtr<nsIURI> mURI; |
|
36 const int64_t mItemId; |
|
37 const nsCString mAnnotationName; |
|
38 nsCOMPtr<nsIVariant> mAnnotationValue; |
|
39 }; |
|
40 |
|
41 } // namespace places |
|
42 } // namespace mozilla |
|
43 |
|
44 class nsAnnotationService MOZ_FINAL : public nsIAnnotationService |
|
45 , public nsIObserver |
|
46 , public nsSupportsWeakReference |
|
47 { |
|
48 public: |
|
49 NS_DECL_ISUPPORTS |
|
50 NS_DECL_NSIANNOTATIONSERVICE |
|
51 NS_DECL_NSIOBSERVER |
|
52 |
|
53 nsAnnotationService(); |
|
54 |
|
55 /** |
|
56 * Obtains the service's object. |
|
57 */ |
|
58 static already_AddRefed<nsAnnotationService> GetSingleton(); |
|
59 |
|
60 /** |
|
61 * Initializes the service's object. This should only be called once. |
|
62 */ |
|
63 nsresult Init(); |
|
64 |
|
65 /** |
|
66 * Returns a cached pointer to the annotation service for consumers in the |
|
67 * places directory. |
|
68 */ |
|
69 static nsAnnotationService* GetAnnotationService() |
|
70 { |
|
71 if (!gAnnotationService) { |
|
72 nsCOMPtr<nsIAnnotationService> serv = |
|
73 do_GetService(NS_ANNOTATIONSERVICE_CONTRACTID); |
|
74 NS_ENSURE_TRUE(serv, nullptr); |
|
75 NS_ASSERTION(gAnnotationService, |
|
76 "Should have static instance pointer now"); |
|
77 } |
|
78 return gAnnotationService; |
|
79 } |
|
80 |
|
81 private: |
|
82 ~nsAnnotationService(); |
|
83 |
|
84 protected: |
|
85 nsRefPtr<mozilla::places::Database> mDB; |
|
86 |
|
87 nsCOMArray<nsIAnnotationObserver> mObservers; |
|
88 bool mHasSessionAnnotations; |
|
89 |
|
90 static nsAnnotationService* gAnnotationService; |
|
91 |
|
92 static const int kAnnoIndex_ID; |
|
93 static const int kAnnoIndex_PageOrItem; |
|
94 static const int kAnnoIndex_NameID; |
|
95 static const int kAnnoIndex_Content; |
|
96 static const int kAnnoIndex_Flags; |
|
97 static const int kAnnoIndex_Expiration; |
|
98 static const int kAnnoIndex_Type; |
|
99 static const int kAnnoIndex_DateAdded; |
|
100 static const int kAnnoIndex_LastModified; |
|
101 |
|
102 nsresult HasAnnotationInternal(nsIURI* aURI, |
|
103 int64_t aItemId, |
|
104 const nsACString& aName, |
|
105 bool* _hasAnno); |
|
106 |
|
107 nsresult StartGetAnnotation(nsIURI* aURI, |
|
108 int64_t aItemId, |
|
109 const nsACString& aName, |
|
110 nsCOMPtr<mozIStorageStatement>& aStatement); |
|
111 |
|
112 nsresult StartSetAnnotation(nsIURI* aURI, |
|
113 int64_t aItemId, |
|
114 const nsACString& aName, |
|
115 int32_t aFlags, |
|
116 uint16_t aExpiration, |
|
117 uint16_t aType, |
|
118 nsCOMPtr<mozIStorageStatement>& aStatement); |
|
119 |
|
120 nsresult SetAnnotationStringInternal(nsIURI* aURI, |
|
121 int64_t aItemId, |
|
122 const nsACString& aName, |
|
123 const nsAString& aValue, |
|
124 int32_t aFlags, |
|
125 uint16_t aExpiration); |
|
126 nsresult SetAnnotationInt32Internal(nsIURI* aURI, |
|
127 int64_t aItemId, |
|
128 const nsACString& aName, |
|
129 int32_t aValue, |
|
130 int32_t aFlags, |
|
131 uint16_t aExpiration); |
|
132 nsresult SetAnnotationInt64Internal(nsIURI* aURI, |
|
133 int64_t aItemId, |
|
134 const nsACString& aName, |
|
135 int64_t aValue, |
|
136 int32_t aFlags, |
|
137 uint16_t aExpiration); |
|
138 nsresult SetAnnotationDoubleInternal(nsIURI* aURI, |
|
139 int64_t aItemId, |
|
140 const nsACString& aName, |
|
141 double aValue, |
|
142 int32_t aFlags, |
|
143 uint16_t aExpiration); |
|
144 |
|
145 nsresult RemoveAnnotationInternal(nsIURI* aURI, |
|
146 int64_t aItemId, |
|
147 const nsACString& aName); |
|
148 |
|
149 public: |
|
150 nsresult GetPagesWithAnnotationCOMArray(const nsACString& aName, |
|
151 nsCOMArray<nsIURI>* _results); |
|
152 nsresult GetItemsWithAnnotationTArray(const nsACString& aName, |
|
153 nsTArray<int64_t>* _result); |
|
154 nsresult GetAnnotationNamesTArray(nsIURI* aURI, |
|
155 int64_t aItemId, |
|
156 nsTArray<nsCString>* _result); |
|
157 }; |
|
158 |
|
159 #endif /* nsAnnotationService_h___ */ |