LCOV - code coverage report
Current view: directory - toolkit/components/places - nsAnnotationService.h (source / functions) Found Hit Coverage
Test: app.info Lines: 6 6 100.0 %
Date: 2012-06-02 Functions: 1 1 100.0 %

       1                 : //* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla Annotation Service
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Google Inc.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2005
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Brett Wilson <brettw@gmail.com> (original author)
      24                 :  *   Marco Bonardo <mak77@bonardo.net>
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      28                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #ifndef nsAnnotationService_h___
      41                 : #define nsAnnotationService_h___
      42                 : 
      43                 : #include "nsIAnnotationService.h"
      44                 : #include "nsTArray.h"
      45                 : #include "nsCOMArray.h"
      46                 : #include "nsCOMPtr.h"
      47                 : #include "nsServiceManagerUtils.h"
      48                 : #include "nsWeakReference.h"
      49                 : #include "nsToolkitCompsCID.h"
      50                 : #include "Database.h"
      51                 : #include "nsString.h"
      52                 : 
      53                 : class nsAnnotationService : public nsIAnnotationService
      54                 :                           , public nsIObserver
      55                 :                           , public nsSupportsWeakReference
      56                 : {
      57                 : public:
      58                 :   NS_DECL_ISUPPORTS
      59                 :   NS_DECL_NSIANNOTATIONSERVICE
      60                 :   NS_DECL_NSIOBSERVER
      61                 : 
      62                 :   nsAnnotationService();
      63                 : 
      64                 :   /**
      65                 :    * Obtains the service's object.
      66                 :    */
      67                 :   static nsAnnotationService* GetSingleton();
      68                 : 
      69                 :   /**
      70                 :    * Initializes the service's object.  This should only be called once.
      71                 :    */
      72                 :   nsresult Init();
      73                 : 
      74                 :   static nsAnnotationService* GetAnnotationServiceIfAvailable() {
      75                 :     return gAnnotationService;
      76                 :   }
      77                 : 
      78                 :   /**
      79                 :    * Returns a cached pointer to the annotation service for consumers in the
      80                 :    * places directory.
      81                 :    */
      82             913 :   static nsAnnotationService* GetAnnotationService()
      83                 :   {
      84             913 :     if (!gAnnotationService) {
      85                 :       nsCOMPtr<nsIAnnotationService> serv =
      86             384 :         do_GetService(NS_ANNOTATIONSERVICE_CONTRACTID);
      87             192 :       NS_ENSURE_TRUE(serv, nsnull);
      88             192 :       NS_ASSERTION(gAnnotationService,
      89                 :                    "Should have static instance pointer now");
      90                 :     }
      91             913 :     return gAnnotationService;
      92                 :   }
      93                 : 
      94                 : private:
      95                 :   ~nsAnnotationService();
      96                 : 
      97                 : protected:
      98                 :   nsRefPtr<mozilla::places::Database> mDB;
      99                 : 
     100                 :   nsCOMArray<nsIAnnotationObserver> mObservers;
     101                 :   bool mHasSessionAnnotations;
     102                 : 
     103                 :   static nsAnnotationService* gAnnotationService;
     104                 : 
     105                 :   static const int kAnnoIndex_ID;
     106                 :   static const int kAnnoIndex_PageOrItem;
     107                 :   static const int kAnnoIndex_NameID;
     108                 :   static const int kAnnoIndex_MimeType;
     109                 :   static const int kAnnoIndex_Content;
     110                 :   static const int kAnnoIndex_Flags;
     111                 :   static const int kAnnoIndex_Expiration;
     112                 :   static const int kAnnoIndex_Type;
     113                 :   static const int kAnnoIndex_DateAdded;
     114                 :   static const int kAnnoIndex_LastModified;
     115                 : 
     116                 :   nsresult HasAnnotationInternal(nsIURI* aURI,
     117                 :                                  PRInt64 aItemId,
     118                 :                                  const nsACString& aName,
     119                 :                                  bool* _hasAnno);
     120                 : 
     121                 :   nsresult StartGetAnnotation(nsIURI* aURI,
     122                 :                               PRInt64 aItemId,
     123                 :                               const nsACString& aName,
     124                 :                               nsCOMPtr<mozIStorageStatement>& aStatement);
     125                 : 
     126                 :   nsresult StartSetAnnotation(nsIURI* aURI,
     127                 :                               PRInt64 aItemId,
     128                 :                               const nsACString& aName,
     129                 :                               PRInt32 aFlags,
     130                 :                               PRUint16 aExpiration,
     131                 :                               PRUint16 aType,
     132                 :                               nsCOMPtr<mozIStorageStatement>& aStatement);
     133                 : 
     134                 :   nsresult SetAnnotationStringInternal(nsIURI* aURI,
     135                 :                                        PRInt64 aItemId,
     136                 :                                        const nsACString& aName,
     137                 :                                        const nsAString& aValue,
     138                 :                                        PRInt32 aFlags,
     139                 :                                        PRUint16 aExpiration);
     140                 :   nsresult SetAnnotationInt32Internal(nsIURI* aURI,
     141                 :                                       PRInt64 aItemId,
     142                 :                                       const nsACString& aName,
     143                 :                                       PRInt32 aValue,
     144                 :                                       PRInt32 aFlags,
     145                 :                                       PRUint16 aExpiration);
     146                 :   nsresult SetAnnotationInt64Internal(nsIURI* aURI,
     147                 :                                       PRInt64 aItemId,
     148                 :                                       const nsACString& aName,
     149                 :                                       PRInt64 aValue,
     150                 :                                       PRInt32 aFlags,
     151                 :                                       PRUint16 aExpiration);
     152                 :   nsresult SetAnnotationDoubleInternal(nsIURI* aURI,
     153                 :                                        PRInt64 aItemId,
     154                 :                                        const nsACString& aName,
     155                 :                                        double aValue,
     156                 :                                        PRInt32 aFlags,
     157                 :                                        PRUint16 aExpiration);
     158                 :   nsresult SetAnnotationBinaryInternal(nsIURI* aURI,
     159                 :                                        PRInt64 aItemId,
     160                 :                                        const nsACString& aName,
     161                 :                                        const PRUint8* aData,
     162                 :                                        PRUint32 aDataLen,
     163                 :                                        const nsACString& aMimeType,
     164                 :                                        PRInt32 aFlags,
     165                 :                                        PRUint16 aExpiration);
     166                 : 
     167                 :   nsresult RemoveAnnotationInternal(nsIURI* aURI,
     168                 :                                     PRInt64 aItemId,
     169                 :                                     const nsACString& aName);
     170                 : 
     171                 :   bool InPrivateBrowsingMode() const;
     172                 : 
     173                 : public:
     174                 :   nsresult GetPagesWithAnnotationCOMArray(const nsACString& aName,
     175                 :                                           nsCOMArray<nsIURI>* _results);
     176                 :   nsresult GetItemsWithAnnotationTArray(const nsACString& aName,
     177                 :                                         nsTArray<PRInt64>* _result);
     178                 :   nsresult GetAnnotationNamesTArray(nsIURI* aURI,
     179                 :                                     PRInt64 aItemId,
     180                 :                                     nsTArray<nsCString>* _result);
     181                 : };
     182                 : 
     183                 : #endif /* nsAnnotationService_h___ */

Generated by: LCOV version 1.7