1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/nsAnnotationService.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,159 @@ 1.4 +//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsAnnotationService_h___ 1.10 +#define nsAnnotationService_h___ 1.11 + 1.12 +#include "nsIAnnotationService.h" 1.13 +#include "nsTArray.h" 1.14 +#include "nsCOMArray.h" 1.15 +#include "nsCOMPtr.h" 1.16 +#include "nsServiceManagerUtils.h" 1.17 +#include "nsWeakReference.h" 1.18 +#include "nsToolkitCompsCID.h" 1.19 +#include "Database.h" 1.20 +#include "nsString.h" 1.21 +#include "mozilla/Attributes.h" 1.22 + 1.23 +namespace mozilla { 1.24 +namespace places { 1.25 + 1.26 +class AnnotatedResult MOZ_FINAL : public mozIAnnotatedResult 1.27 +{ 1.28 +public: 1.29 + NS_DECL_ISUPPORTS 1.30 + NS_DECL_MOZIANNOTATEDRESULT 1.31 + 1.32 + AnnotatedResult(const nsCString& aGUID, nsIURI* aURI, int64_t aItemd, 1.33 + const nsACString& aAnnotationName, 1.34 + nsIVariant* aAnnotationValue); 1.35 + 1.36 +private: 1.37 + const nsCString mGUID; 1.38 + nsCOMPtr<nsIURI> mURI; 1.39 + const int64_t mItemId; 1.40 + const nsCString mAnnotationName; 1.41 + nsCOMPtr<nsIVariant> mAnnotationValue; 1.42 +}; 1.43 + 1.44 +} // namespace places 1.45 +} // namespace mozilla 1.46 + 1.47 +class nsAnnotationService MOZ_FINAL : public nsIAnnotationService 1.48 + , public nsIObserver 1.49 + , public nsSupportsWeakReference 1.50 +{ 1.51 +public: 1.52 + NS_DECL_ISUPPORTS 1.53 + NS_DECL_NSIANNOTATIONSERVICE 1.54 + NS_DECL_NSIOBSERVER 1.55 + 1.56 + nsAnnotationService(); 1.57 + 1.58 + /** 1.59 + * Obtains the service's object. 1.60 + */ 1.61 + static already_AddRefed<nsAnnotationService> GetSingleton(); 1.62 + 1.63 + /** 1.64 + * Initializes the service's object. This should only be called once. 1.65 + */ 1.66 + nsresult Init(); 1.67 + 1.68 + /** 1.69 + * Returns a cached pointer to the annotation service for consumers in the 1.70 + * places directory. 1.71 + */ 1.72 + static nsAnnotationService* GetAnnotationService() 1.73 + { 1.74 + if (!gAnnotationService) { 1.75 + nsCOMPtr<nsIAnnotationService> serv = 1.76 + do_GetService(NS_ANNOTATIONSERVICE_CONTRACTID); 1.77 + NS_ENSURE_TRUE(serv, nullptr); 1.78 + NS_ASSERTION(gAnnotationService, 1.79 + "Should have static instance pointer now"); 1.80 + } 1.81 + return gAnnotationService; 1.82 + } 1.83 + 1.84 +private: 1.85 + ~nsAnnotationService(); 1.86 + 1.87 +protected: 1.88 + nsRefPtr<mozilla::places::Database> mDB; 1.89 + 1.90 + nsCOMArray<nsIAnnotationObserver> mObservers; 1.91 + bool mHasSessionAnnotations; 1.92 + 1.93 + static nsAnnotationService* gAnnotationService; 1.94 + 1.95 + static const int kAnnoIndex_ID; 1.96 + static const int kAnnoIndex_PageOrItem; 1.97 + static const int kAnnoIndex_NameID; 1.98 + static const int kAnnoIndex_Content; 1.99 + static const int kAnnoIndex_Flags; 1.100 + static const int kAnnoIndex_Expiration; 1.101 + static const int kAnnoIndex_Type; 1.102 + static const int kAnnoIndex_DateAdded; 1.103 + static const int kAnnoIndex_LastModified; 1.104 + 1.105 + nsresult HasAnnotationInternal(nsIURI* aURI, 1.106 + int64_t aItemId, 1.107 + const nsACString& aName, 1.108 + bool* _hasAnno); 1.109 + 1.110 + nsresult StartGetAnnotation(nsIURI* aURI, 1.111 + int64_t aItemId, 1.112 + const nsACString& aName, 1.113 + nsCOMPtr<mozIStorageStatement>& aStatement); 1.114 + 1.115 + nsresult StartSetAnnotation(nsIURI* aURI, 1.116 + int64_t aItemId, 1.117 + const nsACString& aName, 1.118 + int32_t aFlags, 1.119 + uint16_t aExpiration, 1.120 + uint16_t aType, 1.121 + nsCOMPtr<mozIStorageStatement>& aStatement); 1.122 + 1.123 + nsresult SetAnnotationStringInternal(nsIURI* aURI, 1.124 + int64_t aItemId, 1.125 + const nsACString& aName, 1.126 + const nsAString& aValue, 1.127 + int32_t aFlags, 1.128 + uint16_t aExpiration); 1.129 + nsresult SetAnnotationInt32Internal(nsIURI* aURI, 1.130 + int64_t aItemId, 1.131 + const nsACString& aName, 1.132 + int32_t aValue, 1.133 + int32_t aFlags, 1.134 + uint16_t aExpiration); 1.135 + nsresult SetAnnotationInt64Internal(nsIURI* aURI, 1.136 + int64_t aItemId, 1.137 + const nsACString& aName, 1.138 + int64_t aValue, 1.139 + int32_t aFlags, 1.140 + uint16_t aExpiration); 1.141 + nsresult SetAnnotationDoubleInternal(nsIURI* aURI, 1.142 + int64_t aItemId, 1.143 + const nsACString& aName, 1.144 + double aValue, 1.145 + int32_t aFlags, 1.146 + uint16_t aExpiration); 1.147 + 1.148 + nsresult RemoveAnnotationInternal(nsIURI* aURI, 1.149 + int64_t aItemId, 1.150 + const nsACString& aName); 1.151 + 1.152 +public: 1.153 + nsresult GetPagesWithAnnotationCOMArray(const nsACString& aName, 1.154 + nsCOMArray<nsIURI>* _results); 1.155 + nsresult GetItemsWithAnnotationTArray(const nsACString& aName, 1.156 + nsTArray<int64_t>* _result); 1.157 + nsresult GetAnnotationNamesTArray(nsIURI* aURI, 1.158 + int64_t aItemId, 1.159 + nsTArray<nsCString>* _result); 1.160 +}; 1.161 + 1.162 +#endif /* nsAnnotationService_h___ */