Source code

Revision control

Other Tools

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 "Database.h"
16
#include "nsString.h"
17
#include "mozilla/Attributes.h"
18
19
namespace mozilla {
20
namespace places {
21
22
struct BookmarkData;
23
24
} // namespace places
25
} // namespace mozilla
26
27
class nsAnnotationService final : public nsIAnnotationService,
28
public nsSupportsWeakReference {
29
using BookmarkData = mozilla::places::BookmarkData;
30
31
public:
32
NS_DECL_ISUPPORTS
33
NS_DECL_NSIANNOTATIONSERVICE
34
35
nsAnnotationService();
36
37
/**
38
* Obtains the service's object.
39
*/
40
static already_AddRefed<nsAnnotationService> GetSingleton();
41
42
/**
43
* Initializes the service's object. This should only be called once.
44
*/
45
nsresult Init();
46
47
/**
48
* Returns a cached pointer to the annotation service for consumers in the
49
* places directory.
50
*/
51
static nsAnnotationService* GetAnnotationService() {
52
if (!gAnnotationService) {
53
nsCOMPtr<nsIAnnotationService> serv =
54
do_GetService(NS_ANNOTATIONSERVICE_CONTRACTID);
55
NS_ENSURE_TRUE(serv, nullptr);
56
NS_ASSERTION(gAnnotationService,
57
"Should have static instance pointer now");
58
}
59
return gAnnotationService;
60
}
61
62
private:
63
~nsAnnotationService();
64
65
protected:
66
RefPtr<mozilla::places::Database> mDB;
67
68
static nsAnnotationService* gAnnotationService;
69
70
static const int kAnnoIndex_ID;
71
static const int kAnnoIndex_PageOrItem;
72
static const int kAnnoIndex_NameID;
73
static const int kAnnoIndex_Content;
74
static const int kAnnoIndex_Flags;
75
static const int kAnnoIndex_Expiration;
76
static const int kAnnoIndex_Type;
77
static const int kAnnoIndex_DateAdded;
78
static const int kAnnoIndex_LastModified;
79
80
nsresult StartGetAnnotation(int64_t aItemId, const nsACString& aName,
81
nsCOMPtr<mozIStorageStatement>& aStatement);
82
83
nsresult StartSetAnnotation(int64_t aItemId, BookmarkData* aBookmark,
84
const nsACString& aName, int32_t aFlags,
85
uint16_t aExpiration, uint16_t aType,
86
nsCOMPtr<mozIStorageStatement>& aStatement);
87
88
nsresult SetAnnotationStringInternal(int64_t aItemId, BookmarkData* aBookmark,
89
const nsACString& aName,
90
const nsAString& aValue, int32_t aFlags,
91
uint16_t aExpiration);
92
nsresult SetAnnotationInt32Internal(int64_t aItemId, BookmarkData* aBookmark,
93
const nsACString& aName, int32_t aValue,
94
int32_t aFlags, uint16_t aExpiration);
95
nsresult SetAnnotationInt64Internal(int64_t aItemId, BookmarkData* aBookmark,
96
const nsACString& aName, int64_t aValue,
97
int32_t aFlags, uint16_t aExpiration);
98
nsresult SetAnnotationDoubleInternal(int64_t aItemId, BookmarkData* aBookmark,
99
const nsACString& aName, double aValue,
100
int32_t aFlags, uint16_t aExpiration);
101
102
nsresult RemoveAnnotationInternal(int64_t aItemId, BookmarkData* aBookmark,
103
const nsACString& aName);
104
105
nsresult GetValueFromStatement(nsCOMPtr<mozIStorageStatement>& aStatement,
106
nsIVariant** _retval);
107
108
public:
109
nsresult RemoveItemAnnotations(int64_t aItemId);
110
};
111
112
#endif /* nsAnnotationService_h___ */