Bug 1344282 - prep: add a makeGuid method to nsINavHistory, r?mak
MozReview-Commit-ID: JKIjtcqyTzc
--- a/toolkit/components/places/Helpers.cpp
+++ b/toolkit/components/places/Helpers.cpp
@@ -242,17 +242,17 @@ GenerateRandomBytes(uint32_t aSize,
}
(void)PR_Close(urandom);
}
return rv;
#endif
}
nsresult
-GenerateGUID(nsCString& _guid)
+GenerateGUID(nsACString& _guid)
{
_guid.Truncate();
// Request raw random bytes and base64url encode them. For each set of three
// bytes, we get one character.
const uint32_t kRequiredBytesLength =
static_cast<uint32_t>(GUID_LENGTH / 4 * 3);
--- a/toolkit/components/places/Helpers.h
+++ b/toolkit/components/places/Helpers.h
@@ -132,17 +132,17 @@ void GetReversedHostname(const nsString&
*/
void ReverseString(const nsString& aInput, nsString& aReversed);
/**
* Generates an 12 character guid to be used by bookmark and history entries.
*
* @note This guid uses the characters a-z, A-Z, 0-9, '-', and '_'.
*/
-nsresult GenerateGUID(nsCString& _guid);
+nsresult GenerateGUID(nsACString& _guid);
/**
* Determines if the string is a valid guid or not.
*
* @param aGUID
* The guid to test.
* @return true if it is a valid guid, false otherwise.
*/
--- a/toolkit/components/places/nsINavHistoryService.idl
+++ b/toolkit/components/places/nsINavHistoryService.idl
@@ -1439,16 +1439,23 @@ interface nsINavHistoryService : nsISupp
* history is disabled if the places.history.enabled pref is false.
*/
readonly attribute boolean historyDisabled;
/**
* Clear all TRANSITION_EMBED visits.
*/
void clearEmbedVisits();
+
+ /**
+ * Generate a guid.
+ * Guids can be used for any places purposes (history, bookmarks, etc.)
+ * Returns null if the generation of the guid failed.
+ */
+ ACString makeGuid();
};
/**
* @see runInBatchMode of nsINavHistoryService/nsINavBookmarksService
*/
[scriptable, function, uuid(5a5a9154-95ac-4e3d-90df-558816297407)]
interface nsINavHistoryBatchCallback : nsISupports {
void runBatched(in nsISupports aUserData);
--- a/toolkit/components/places/nsNavHistory.cpp
+++ b/toolkit/components/places/nsNavHistory.cpp
@@ -435,17 +435,16 @@ nsNavHistory::GetOrCreateIdForPage(nsIUR
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("hidden"), 1);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString spec;
rv = aURI->GetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("frecency"),
IsQueryURI(spec) ? 0 : -1);
NS_ENSURE_SUCCESS(rv, rv);
- nsAutoCString guid;
rv = GenerateGUID(_GUID);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("guid"), _GUID);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->Execute();
NS_ENSURE_SUCCESS(rv, rv);
@@ -3718,16 +3717,25 @@ nsNavHistory::clearEmbedVisits() {
}
NS_IMETHODIMP
nsNavHistory::ClearEmbedVisits() {
clearEmbedVisits();
return NS_OK;
}
+NS_IMETHODIMP
+nsNavHistory::MakeGuid(nsACString& aGuid) {
+ if (NS_FAILED(GenerateGUID(aGuid))) {
+ MOZ_ASSERT(false, "Shouldn't fail to create a guid!");
+ aGuid.SetIsVoid(true);
+ }
+ return NS_OK;
+}
+
// nsNavHistory::CheckIsRecentEvent
//
// Sees if this URL happened "recently."
//
// It is always removed from our recent list no matter what. It only counts
// as "recent" if the event happened more recently than our event
// threshold ago.