LCOV - code coverage report
Current view: top level - toolkit/components/places - nsAnnotationService.h (source / functions) Hit Total Coverage
Test: output.info Lines: 6 6 100.0 %
Date: 2017-07-14 16:53:18 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 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             :   ~AnnotatedResult();
      35             : 
      36             :   const nsCString mGUID;
      37             :   nsCOMPtr<nsIURI> mURI;
      38             :   const int64_t mItemId;
      39             :   const nsCString mAnnotationName;
      40             :   nsCOMPtr<nsIVariant> mAnnotationValue;
      41             : };
      42             : 
      43             : } // namespace places
      44             : } // namespace mozilla
      45             : 
      46             : class nsAnnotationService final : public nsIAnnotationService
      47             :                                 , public nsIObserver
      48             :                                 , public nsSupportsWeakReference
      49             : {
      50             : public:
      51             :   NS_DECL_ISUPPORTS
      52             :   NS_DECL_NSIANNOTATIONSERVICE
      53             :   NS_DECL_NSIOBSERVER
      54             : 
      55             :   nsAnnotationService();
      56             : 
      57             :   /**
      58             :    * Obtains the service's object.
      59             :    */
      60             :   static already_AddRefed<nsAnnotationService> GetSingleton();
      61             : 
      62             :   /**
      63             :    * Initializes the service's object.  This should only be called once.
      64             :    */
      65             :   nsresult Init();
      66             : 
      67             :   /**
      68             :    * Returns a cached pointer to the annotation service for consumers in the
      69             :    * places directory.
      70             :    */
      71           1 :   static nsAnnotationService* GetAnnotationService()
      72             :   {
      73           1 :     if (!gAnnotationService) {
      74             :       nsCOMPtr<nsIAnnotationService> serv =
      75           2 :         do_GetService(NS_ANNOTATIONSERVICE_CONTRACTID);
      76           1 :       NS_ENSURE_TRUE(serv, nullptr);
      77           1 :       NS_ASSERTION(gAnnotationService,
      78             :                    "Should have static instance pointer now");
      79             :     }
      80           1 :     return gAnnotationService;
      81             :   }
      82             : 
      83             : private:
      84             :   ~nsAnnotationService();
      85             : 
      86             : protected:
      87             :   RefPtr<mozilla::places::Database> mDB;
      88             : 
      89             :   nsCOMArray<nsIAnnotationObserver> mObservers;
      90             :   bool mHasSessionAnnotations;
      91             : 
      92             :   static nsAnnotationService* gAnnotationService;
      93             : 
      94             :   static const int kAnnoIndex_ID;
      95             :   static const int kAnnoIndex_PageOrItem;
      96             :   static const int kAnnoIndex_NameID;
      97             :   static const int kAnnoIndex_Content;
      98             :   static const int kAnnoIndex_Flags;
      99             :   static const int kAnnoIndex_Expiration;
     100             :   static const int kAnnoIndex_Type;
     101             :   static const int kAnnoIndex_DateAdded;
     102             :   static const int kAnnoIndex_LastModified;
     103             : 
     104             :   nsresult HasAnnotationInternal(nsIURI* aURI,
     105             :                                  int64_t aItemId,
     106             :                                  const nsACString& aName,
     107             :                                  bool* _hasAnno);
     108             : 
     109             :   nsresult StartGetAnnotation(nsIURI* aURI,
     110             :                               int64_t aItemId,
     111             :                               const nsACString& aName,
     112             :                               nsCOMPtr<mozIStorageStatement>& aStatement);
     113             : 
     114             :   nsresult StartSetAnnotation(nsIURI* aURI,
     115             :                               int64_t aItemId,
     116             :                               const nsACString& aName,
     117             :                               int32_t aFlags,
     118             :                               uint16_t aExpiration,
     119             :                               uint16_t aType,
     120             :                               nsCOMPtr<mozIStorageStatement>& aStatement);
     121             : 
     122             :   nsresult SetAnnotationStringInternal(nsIURI* aURI,
     123             :                                        int64_t aItemId,
     124             :                                        const nsACString& aName,
     125             :                                        const nsAString& aValue,
     126             :                                        int32_t aFlags,
     127             :                                        uint16_t aExpiration);
     128             :   nsresult SetAnnotationInt32Internal(nsIURI* aURI,
     129             :                                       int64_t aItemId,
     130             :                                       const nsACString& aName,
     131             :                                       int32_t aValue,
     132             :                                       int32_t aFlags,
     133             :                                       uint16_t aExpiration);
     134             :   nsresult SetAnnotationInt64Internal(nsIURI* aURI,
     135             :                                       int64_t aItemId,
     136             :                                       const nsACString& aName,
     137             :                                       int64_t aValue,
     138             :                                       int32_t aFlags,
     139             :                                       uint16_t aExpiration);
     140             :   nsresult SetAnnotationDoubleInternal(nsIURI* aURI,
     141             :                                        int64_t aItemId,
     142             :                                        const nsACString& aName,
     143             :                                        double aValue,
     144             :                                        int32_t aFlags,
     145             :                                        uint16_t aExpiration);
     146             : 
     147             :   nsresult RemoveAnnotationInternal(nsIURI* aURI,
     148             :                                     int64_t aItemId,
     149             :                                     const nsACString& aName);
     150             : 
     151             : public:
     152             :   nsresult GetPagesWithAnnotationCOMArray(const nsACString& aName,
     153             :                                           nsCOMArray<nsIURI>* _results);
     154             :   nsresult GetItemsWithAnnotationTArray(const nsACString& aName,
     155             :                                         nsTArray<int64_t>* _result);
     156             :   nsresult GetAnnotationNamesTArray(nsIURI* aURI,
     157             :                                     int64_t aItemId,
     158             :                                     nsTArray<nsCString>* _result);
     159             : };
     160             : 
     161             : #endif /* nsAnnotationService_h___ */

Generated by: LCOV version 1.13