michael@0: //* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsAnnotationService_h___ michael@0: #define nsAnnotationService_h___ michael@0: michael@0: #include "nsIAnnotationService.h" michael@0: #include "nsTArray.h" michael@0: #include "nsCOMArray.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsServiceManagerUtils.h" michael@0: #include "nsWeakReference.h" michael@0: #include "nsToolkitCompsCID.h" michael@0: #include "Database.h" michael@0: #include "nsString.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: namespace mozilla { michael@0: namespace places { michael@0: michael@0: class AnnotatedResult MOZ_FINAL : public mozIAnnotatedResult michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_MOZIANNOTATEDRESULT michael@0: michael@0: AnnotatedResult(const nsCString& aGUID, nsIURI* aURI, int64_t aItemd, michael@0: const nsACString& aAnnotationName, michael@0: nsIVariant* aAnnotationValue); michael@0: michael@0: private: michael@0: const nsCString mGUID; michael@0: nsCOMPtr mURI; michael@0: const int64_t mItemId; michael@0: const nsCString mAnnotationName; michael@0: nsCOMPtr mAnnotationValue; michael@0: }; michael@0: michael@0: } // namespace places michael@0: } // namespace mozilla michael@0: michael@0: class nsAnnotationService MOZ_FINAL : public nsIAnnotationService michael@0: , public nsIObserver michael@0: , public nsSupportsWeakReference michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIANNOTATIONSERVICE michael@0: NS_DECL_NSIOBSERVER michael@0: michael@0: nsAnnotationService(); michael@0: michael@0: /** michael@0: * Obtains the service's object. michael@0: */ michael@0: static already_AddRefed GetSingleton(); michael@0: michael@0: /** michael@0: * Initializes the service's object. This should only be called once. michael@0: */ michael@0: nsresult Init(); michael@0: michael@0: /** michael@0: * Returns a cached pointer to the annotation service for consumers in the michael@0: * places directory. michael@0: */ michael@0: static nsAnnotationService* GetAnnotationService() michael@0: { michael@0: if (!gAnnotationService) { michael@0: nsCOMPtr serv = michael@0: do_GetService(NS_ANNOTATIONSERVICE_CONTRACTID); michael@0: NS_ENSURE_TRUE(serv, nullptr); michael@0: NS_ASSERTION(gAnnotationService, michael@0: "Should have static instance pointer now"); michael@0: } michael@0: return gAnnotationService; michael@0: } michael@0: michael@0: private: michael@0: ~nsAnnotationService(); michael@0: michael@0: protected: michael@0: nsRefPtr mDB; michael@0: michael@0: nsCOMArray mObservers; michael@0: bool mHasSessionAnnotations; michael@0: michael@0: static nsAnnotationService* gAnnotationService; michael@0: michael@0: static const int kAnnoIndex_ID; michael@0: static const int kAnnoIndex_PageOrItem; michael@0: static const int kAnnoIndex_NameID; michael@0: static const int kAnnoIndex_Content; michael@0: static const int kAnnoIndex_Flags; michael@0: static const int kAnnoIndex_Expiration; michael@0: static const int kAnnoIndex_Type; michael@0: static const int kAnnoIndex_DateAdded; michael@0: static const int kAnnoIndex_LastModified; michael@0: michael@0: nsresult HasAnnotationInternal(nsIURI* aURI, michael@0: int64_t aItemId, michael@0: const nsACString& aName, michael@0: bool* _hasAnno); michael@0: michael@0: nsresult StartGetAnnotation(nsIURI* aURI, michael@0: int64_t aItemId, michael@0: const nsACString& aName, michael@0: nsCOMPtr& aStatement); michael@0: michael@0: nsresult StartSetAnnotation(nsIURI* aURI, michael@0: int64_t aItemId, michael@0: const nsACString& aName, michael@0: int32_t aFlags, michael@0: uint16_t aExpiration, michael@0: uint16_t aType, michael@0: nsCOMPtr& aStatement); michael@0: michael@0: nsresult SetAnnotationStringInternal(nsIURI* aURI, michael@0: int64_t aItemId, michael@0: const nsACString& aName, michael@0: const nsAString& aValue, michael@0: int32_t aFlags, michael@0: uint16_t aExpiration); michael@0: nsresult SetAnnotationInt32Internal(nsIURI* aURI, michael@0: int64_t aItemId, michael@0: const nsACString& aName, michael@0: int32_t aValue, michael@0: int32_t aFlags, michael@0: uint16_t aExpiration); michael@0: nsresult SetAnnotationInt64Internal(nsIURI* aURI, michael@0: int64_t aItemId, michael@0: const nsACString& aName, michael@0: int64_t aValue, michael@0: int32_t aFlags, michael@0: uint16_t aExpiration); michael@0: nsresult SetAnnotationDoubleInternal(nsIURI* aURI, michael@0: int64_t aItemId, michael@0: const nsACString& aName, michael@0: double aValue, michael@0: int32_t aFlags, michael@0: uint16_t aExpiration); michael@0: michael@0: nsresult RemoveAnnotationInternal(nsIURI* aURI, michael@0: int64_t aItemId, michael@0: const nsACString& aName); michael@0: michael@0: public: michael@0: nsresult GetPagesWithAnnotationCOMArray(const nsACString& aName, michael@0: nsCOMArray* _results); michael@0: nsresult GetItemsWithAnnotationTArray(const nsACString& aName, michael@0: nsTArray* _result); michael@0: nsresult GetAnnotationNamesTArray(nsIURI* aURI, michael@0: int64_t aItemId, michael@0: nsTArray* _result); michael@0: }; michael@0: michael@0: #endif /* nsAnnotationService_h___ */