Coverage Report

Created: 2018-09-25 14:53

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