Bug 306640 r=annie.sullivan sr=bryner

Add annotation service. This checkin addresses sr comments I forgot in the
checkin of the main code.
This commit is contained in:
brettw%gmail.com 2005-11-16 00:20:15 +00:00
Родитель 0ddc82f39a
Коммит 4d8d07c2b6
5 изменённых файлов: 57 добавлений и 55 удалений

Просмотреть файл

@ -37,8 +37,9 @@
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
#include "nsIURI.idl"
#include "nsIVariant.idl"
interface nsIURI;
interface nsIVariant;
[scriptable, uuid(05537263-9bb4-45c8-ae96-461817f53972)]
interface nsIAnnotationService : nsISupports
@ -47,7 +48,7 @@ interface nsIAnnotationService : nsISupports
* Valid values for aExpiration, which sets the expiration policy for your
* annotation. These times are measured since the last visit date of the
* page in question. This means that if you set an annotation with anything
* but session expiratin, it will not expire so long as the user keeps
* but session expiration, it will not expire so long as the user keeps
* visiting the page from time to time.
*/
@ -55,24 +56,24 @@ interface nsIAnnotationService : nsISupports
expiration policy. May be changed. Currently, use 0 for expiration.
*/
// For temporary stuff that can be discarded when the user exists
const long EXPIRE_SESSION = 0;
const PRInt32 EXPIRE_SESSION = 0;
// for short-lived temporary data that you still want to outlast a session
const long EXPIRE_DAYS = 1;
const PRInt32 EXPIRE_DAYS = 1;
// for general page settings, things the user is interested in seeing
// if they come back to this page some time in the future.
const long EXPIRE_WEEKS = 2;
const PRInt32 EXPIRE_WEEKS = 2;
// Something that the user will be interested in seeing in their
// history like favicons. If they haven't visited a page in a couple
// of months, they probably aren't interested in much other annotation,
// the positions of things, or other stuff you create, so put that in
// the weeks policy.
const long EXPIRE_MONTHS = 3;
const PRInt32 EXPIRE_MONTHS = 3;
// For small, user-entered data like notes that should never expire.
const long EXPIRE_NEVER = 5;
const PRInt32 EXPIRE_NEVER = 4;
/**
* Sets an annotation, overwriting any previous annotation with the same
@ -87,23 +88,23 @@ interface nsIAnnotationService : nsISupports
* flags will be defined in the future.
*/
void setAnnotation(in nsIURI aURI, in ACString aName, in nsIVariant aValue,
in long aFlags, in long aExpiration);
in PRInt32 aFlags, in PRInt32 aExpiration);
/**
* Sets an annotation just like setAnnotation, but takes a string as
* input, which will be more convenient for C++.
*/
void setAnnotationString(in nsIURI aURI, in ACString aName,
in AString aValue, in long aFlags,
in long aExpiration);
in AString aValue, in PRInt32 aFlags,
in PRInt32 aExpiration);
/**
* Sets an annotation just like setAnnotation, but takes an Int32 as input
* for convenience.
*/
void setAnnotationInt32(in nsIURI aURI, in ACString aName,
in PRInt32 aValue, in long aFlags,
in long aExpiration);
in PRInt32 aValue, in PRInt32 aFlags,
in PRInt32 aExpiration);
/*
* Sets an annotation just like setAnnotation, but takes binary data as
@ -111,8 +112,8 @@ interface nsIAnnotationService : nsISupports
*/
void setAnnotationBinary(in nsIURI aURI, in ACString aName,
[const,array,size_is(aDataLen)] in octet aData,
in unsigned long aDataLen, in ACString aMimeType,
in long aFlags, in long aExpiration);
in PRUint32 aDataLen, in ACString aMimeType,
in PRInt32 aFlags, in PRInt32 aExpiration);
/**
* Retrieves the value of an existing annotation. Throws if the annotation
@ -139,7 +140,7 @@ interface nsIAnnotationService : nsISupports
*/
void getAnnotationBinary(in nsIURI aURI, in ACString aName,
[array,size_is(aDataLen)] out octet aData,
out unsigned long aDataLen,
out PRUint32 aDataLen,
out ACString aMimeType);
/**
@ -156,8 +157,8 @@ interface nsIAnnotationService : nsISupports
* // now you can use 'exp.value' and 'flags.value'
*/
void getAnnotationInfo(in nsIURI aURI, in ACString aName,
out long aFlags, out long aExpiration,
out ACString aMimeType, out long aStorageType);
out PRInt32 aFlags, out PRInt32 aExpiration,
out ACString aMimeType, out PRInt32 aStorageType);
/**
* Get the names of all annotations for this URI.
@ -166,7 +167,7 @@ interface nsIAnnotationService : nsISupports
* var annotations = annotator.getAnnotations(myURI, {});
*/
// IMPLEMENT ME
//void getAnnotations(in AString aURI, out unsigned long count,
//void getAnnotations(in AString aURI, out unsigned PRInt32 count,
// [retval, array, size_is(count)] out wstring result);
/**
@ -183,8 +184,8 @@ interface nsIAnnotationService : nsISupports
*/
/* IMPLEMENT ME?
void getMultipleAnnotations([array, size_is(aCount)] in nsIURI aURIList,
[array, size_is(aCount)] in wstring aNameList, in unsigned long aCount,
out unsigned long aResultCount,
[array, size_is(aCount)] in wstring aNameList, in unsigned PRInt32 aCount,
out unsigned PRInt32 aResultCount,
[retval, array, size_is(aResultCount)] out wstring aResultList);
*/

Просмотреть файл

@ -44,15 +44,16 @@
#include "mozIStorageFunction.h"
#include "mozStorageHelper.h"
#include "nsIServiceManager.h"
#include "nsIVariant.h"
#include "nsString.h"
const int nsAnnotationService::kAnnoIndex_ID = 0;
const int nsAnnotationService::kAnnoIndex_Page = 1;
const int nsAnnotationService::kAnnoIndex_Name = 2;
const int nsAnnotationService::kAnnoIndex_MimeType = 3;
const int nsAnnotationService::kAnnoIndex_Content = 4;
const int nsAnnotationService::kAnnoIndex_Flags = 5;
const int nsAnnotationService::kAnnoIndex_Expiration = 6;
const PRInt32 nsAnnotationService::kAnnoIndex_ID = 0;
const PRInt32 nsAnnotationService::kAnnoIndex_Page = 1;
const PRInt32 nsAnnotationService::kAnnoIndex_Name = 2;
const PRInt32 nsAnnotationService::kAnnoIndex_MimeType = 3;
const PRInt32 nsAnnotationService::kAnnoIndex_Content = 4;
const PRInt32 nsAnnotationService::kAnnoIndex_Flags = 5;
const PRInt32 nsAnnotationService::kAnnoIndex_Expiration = 6;
static NS_DEFINE_CID(kmozStorageServiceCID, MOZ_STORAGE_SERVICE_CID);
static NS_DEFINE_CID(kmozStorageConnectionCID, MOZ_STORAGE_CONNECTION_CID);
@ -121,7 +122,7 @@ nsAnnotationService::SetAnnotation(nsIURI* aURI,
{
if (! aValue)
return NS_ERROR_INVALID_ARG;
nsString stringValue;
nsAutoString stringValue;
nsresult rv = aValue->GetAsAString(stringValue);
NS_ENSURE_SUCCESS(rv, rv);
return SetAnnotationString(aURI, aName, stringValue, aFlags, aExpiration);
@ -140,6 +141,7 @@ nsAnnotationService::SetAnnotationString(nsIURI* aURI,
mozIStorageStatement* statement; // class var, not owned by this function
nsresult rv = StartSetAnnotation(aURI, aName, aFlags, aExpiration, &statement);
NS_ENSURE_SUCCESS(rv, rv);
mozStorageStatementScoper statementResetter(statement);
rv = statement->BindStringParameter(kAnnoIndex_Content, aValue);
NS_ENSURE_SUCCESS(rv, rv);
@ -165,6 +167,7 @@ nsAnnotationService::SetAnnotationInt32(nsIURI* aURI,
mozIStorageStatement* statement; // class var, not owned by this function
nsresult rv = StartSetAnnotation(aURI, aName, aFlags, aExpiration, &statement);
NS_ENSURE_SUCCESS(rv, rv);
mozStorageStatementScoper statementResetter(statement);
rv = statement->BindInt32Parameter(kAnnoIndex_Content, aValue);
NS_ENSURE_SUCCESS(rv, rv);
@ -195,6 +198,7 @@ nsAnnotationService::SetAnnotationBinary(nsIURI* aURI,
mozIStorageStatement* statement; // class var, not owned by this function
nsresult rv = StartSetAnnotation(aURI, aName, aFlags, aExpiration, &statement);
NS_ENSURE_SUCCESS(rv, rv);
mozStorageStatementScoper statementResetter(statement);
rv = statement->BindBlobParameter(kAnnoIndex_Content, aData, aDataLen);
NS_ENSURE_SUCCESS(rv, rv);
@ -215,20 +219,18 @@ nsAnnotationService::GetAnnotation(nsIURI* aURI,
const nsACString& aName,
nsIVariant** _retval)
{
nsString stringValue;
nsAutoString stringValue;
nsresult rv = GetAnnotationString(aURI, aName, stringValue);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIWritableVariant> var = do_CreateInstance("@mozilla.org/variant;1");
if (! var)
return NS_ERROR_FAILURE;
rv = var->SetWritable(PR_TRUE);
nsCOMPtr<nsIWritableVariant> var = do_CreateInstance("@mozilla.org/variant;1",
&rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = var->SetAsAString(stringValue);
NS_ENSURE_SUCCESS(rv, rv);
*_retval = var;
(*_retval)->AddRef();
NS_ADDREF(*_retval);
return NS_OK;
}
@ -257,9 +259,9 @@ nsAnnotationService::GetAnnotationInt32(nsIURI* aURI,
{
nsresult rv = StartGetAnnotationFromURI(aURI, aName);
NS_ENSURE_SUCCESS(rv, rv);
rv = mDBGetAnnotationFromURI->GetInt32(kAnnoIndex_Content, _retval);
*_retval = mDBGetAnnotationFromURI->AsInt32(kAnnoIndex_Content);
mDBGetAnnotationFromURI->Reset();
return rv;
return NS_OK;
}
@ -297,10 +299,8 @@ nsAnnotationService::GetAnnotationInfo(nsIURI* aURI,
NS_ENSURE_SUCCESS(rv, rv);
mozStorageStatementScoper resetter(mDBGetAnnotationFromURI);
rv = mDBGetAnnotationFromURI->GetInt32(kAnnoIndex_Flags, aFlags);
NS_ENSURE_SUCCESS(rv, rv);
rv = mDBGetAnnotationFromURI->GetInt32(kAnnoIndex_Expiration, aExpiration);
NS_ENSURE_SUCCESS(rv, rv);
*aFlags = mDBGetAnnotationFromURI->AsInt32(kAnnoIndex_Flags);
*aExpiration = mDBGetAnnotationFromURI->AsInt32(kAnnoIndex_Expiration);
rv = mDBGetAnnotationFromURI->GetUTF8String(kAnnoIndex_MimeType, aMimeType);
NS_ENSURE_SUCCESS(rv, rv);
rv = mDBGetAnnotationFromURI->GetTypeOfIndex(kAnnoIndex_Content, aStorageType);
@ -407,7 +407,7 @@ nsAnnotationService::StartGetAnnotationFromURI(nsIURI* aURI,
// create a URL entry if necessary. It will either update an existing
// annotation or insert a new one, and aStatement will be set to either
// mDBAddAnnotation or mDBSetAnnotation. The aStatement RESULT IS NOT
// ADDREFED. This is just one of the class vars, which control it's scope.
// ADDREFED. This is just one of the class vars, which control its scope.
// DO NOT RELEASE.
//
// The caller must make sure the statement is reset. On error, the

Просмотреть файл

@ -45,13 +45,15 @@ class nsAnnotationService : public nsIAnnotationService
{
public:
nsAnnotationService();
virtual ~nsAnnotationService();
nsresult Init();
NS_DECL_ISUPPORTS
NS_DECL_NSIANNOTATIONSERVICE
private:
~nsAnnotationService();
protected:
nsCOMPtr<mozIStorageService> mDBService;
nsCOMPtr<mozIStorageConnection> mDBConn;

Просмотреть файл

@ -239,8 +239,8 @@ nsNavHistory::~nsNavHistory()
// remove the static reference to the service. Check to make sure its us
// in case somebody creates an extra instance of the service.
if (gHistoryService == this)
gHistoryService = nsnull;
NS_ASSERTION(gHistoryService == this, "YOU CREATED 2 COPIES OF THE HISTORY SERVICE.");
gHistoryService = nsnull;
}
@ -450,7 +450,7 @@ nsNavHistory::SaveExpandItem(const nsAString& aTitle)
// nsNavHistory::GetUrlIdFor
//
// Called by the bookmarks and annotation servii, this function returns the
// Called by the bookmarks and annotation services, this function returns the
// ID of the row for the given URL, optionally creating one if it doesn't
// exist. A newly created entry will have no visits.
//

Просмотреть файл

@ -300,16 +300,15 @@ public:
*/
static nsNavHistory* GetHistoryService()
{
if (gHistoryService)
return gHistoryService;
if (! gHistoryService) {
// don't want the return value, since that's the interface. We want the
// pointer to the implementation.
do_GetService("@mozilla.org/browser/nav-history;1");
// don't want the return value, since that's the interface. We want the
// pointer to the implementation.
do_GetService("@mozilla.org/browser/nav-history;1");
// our constructor should have set the static variable. If it didn't,
// something is wrong.
NS_ASSERTION(gHistoryService, "History service creation failed");
// our constructor should have set the static variable. If it didn't,
// something is wrong.
NS_ASSERTION(gHistoryService, "History service creation failed");
}
return gHistoryService;
}