mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-10 17:24:29 +00:00
Backout of last four changesets (places fsync work)
This commit is contained in:
parent
fc42ecfd1f
commit
fcc4936d27
@ -234,7 +234,6 @@ bin/components/libbrowsercomps.so
|
||||
bin/components/txEXSLTRegExFunctions.js
|
||||
bin/components/nsLivemarkService.js
|
||||
bin/components/nsTaggingService.js
|
||||
bin/components/nsPlacesDBFlush.js
|
||||
bin/components/nsDefaultCLH.js
|
||||
bin/components/nsContentPrefService.js
|
||||
bin/components/nsContentDispatchChooser.js
|
||||
|
@ -241,7 +241,6 @@ bin\components\brwsrcmp.dll
|
||||
bin\components\txEXSLTRegExFunctions.js
|
||||
bin\components\nsLivemarkService.js
|
||||
bin\components\nsTaggingService.js
|
||||
bin\components\nsPlacesDBFlush.js
|
||||
bin\components\nsDefaultCLH.js
|
||||
bin\components\nsContentPrefService.js
|
||||
bin\components\nsContentDispatchChooser.js
|
||||
|
@ -105,7 +105,6 @@ LOCAL_INCLUDES += -I$(srcdir)/../../build
|
||||
|
||||
EXTRA_PP_COMPONENTS = nsLivemarkService.js \
|
||||
nsTaggingService.js \
|
||||
nsPlacesDBFlush.js \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_JS_MODULES = \
|
||||
|
@ -49,7 +49,6 @@ const Ci = Components.interfaces;
|
||||
const Cr = Components.results;
|
||||
|
||||
const kQuitApplication = "quit-application";
|
||||
const kPlacesBackgroundShutdown = "places-background-shutdown";
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// nsPlacesBackgound class
|
||||
@ -85,12 +84,6 @@ nsPlacesBackground.prototype = {
|
||||
observe: function PlacesBackground_observe(aSubject, aTopic, aData)
|
||||
{
|
||||
if (aTopic == kQuitApplication) {
|
||||
// Notify consumers that we are shutting down.
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
os.notifyObservers(null, kPlacesBackgroundShutdown, null);
|
||||
|
||||
// Now shut the thread down.
|
||||
this._thread.shutdown();
|
||||
this._thread = null;
|
||||
}
|
||||
|
@ -109,8 +109,7 @@ nsAnnotationService::Init()
|
||||
// mDBSetAnnotation
|
||||
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"UPDATE moz_annos "
|
||||
"SET mime_type = ?4, content = ?5, flags = ?6, expiration = ?7, "
|
||||
"type = ?8, lastModified = ?10 "
|
||||
"SET mime_type = ?4, content = ?5, flags = ?6, expiration = ?7, type = ?8, lastModified = ?10 "
|
||||
"WHERE id = ?1"),
|
||||
getter_AddRefs(mDBSetAnnotation));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -118,8 +117,7 @@ nsAnnotationService::Init()
|
||||
// mDBSetItemAnnotation
|
||||
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"UPDATE moz_items_annos "
|
||||
"SET mime_type = ?4, content = ?5, flags = ?6, expiration = ?7, "
|
||||
"type = ?8, lastModified = ?10 "
|
||||
"SET mime_type = ?4, content = ?5, flags = ?6, expiration = ?7, type = ?8, lastModified = ?10 "
|
||||
"WHERE id = ?1"),
|
||||
getter_AddRefs(mDBSetItemAnnotation));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -129,7 +127,7 @@ nsAnnotationService::Init()
|
||||
"SELECT * "
|
||||
"FROM moz_annos "
|
||||
"WHERE place_id = ?1 AND anno_attribute_id = "
|
||||
"(SELECT id FROM moz_anno_attributes WHERE name = ?2)"),
|
||||
"(SELECT id FROM moz_anno_attributes WHERE name = ?2)"),
|
||||
getter_AddRefs(mDBGetAnnotation));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
@ -138,15 +136,14 @@ nsAnnotationService::Init()
|
||||
"SELECT * "
|
||||
"FROM moz_items_annos "
|
||||
"WHERE item_id = ?1 AND anno_attribute_id = "
|
||||
"(SELECT id FROM moz_anno_attributes WHERE name = ?2)"),
|
||||
"(SELECT id FROM moz_anno_attributes WHERE name = ?2)"),
|
||||
getter_AddRefs(mDBGetItemAnnotation));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// mDBGetAnnotationNames
|
||||
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT n.name "
|
||||
"FROM moz_annos a "
|
||||
"JOIN moz_anno_attributes n ON a.anno_attribute_id = n.id "
|
||||
"FROM moz_annos a LEFT JOIN moz_anno_attributes n ON a.anno_attribute_id = n.id "
|
||||
"WHERE a.place_id = ?1"),
|
||||
getter_AddRefs(mDBGetAnnotationNames));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -154,29 +151,18 @@ nsAnnotationService::Init()
|
||||
// mDBGetItemAnnotationNames
|
||||
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT n.name "
|
||||
"FROM moz_items_annos a "
|
||||
"JOIN moz_anno_attributes n ON a.anno_attribute_id = n.id "
|
||||
"FROM moz_items_annos a LEFT JOIN moz_anno_attributes n ON a.anno_attribute_id = n.id "
|
||||
"WHERE a.item_id = ?1"),
|
||||
getter_AddRefs(mDBGetItemAnnotationNames));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// mDBGetAnnotationFromURI
|
||||
// We are not checking for duplicated ids into the unified table
|
||||
// for perf reasons, LIMIT 1 will discard duplicates faster since we
|
||||
// can only have one anno with a certain name for every place_id.
|
||||
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT a.id, a.place_id, ?2, a.mime_type, a.content, a.flags, "
|
||||
"a.expiration, a.type "
|
||||
"FROM ( "
|
||||
"SELECT id FROM moz_places_temp "
|
||||
"WHERE url = ?1 "
|
||||
"UNION ALL "
|
||||
"SELECT id FROM moz_places "
|
||||
"WHERE url = ?1 "
|
||||
") AS h JOIN moz_annos a ON h.id = a.place_id "
|
||||
"WHERE a.anno_attribute_id = "
|
||||
"(SELECT id FROM moz_anno_attributes WHERE name = ?2) "
|
||||
"LIMIT 1"),
|
||||
"FROM moz_places h JOIN moz_annos a ON h.id = a.place_id "
|
||||
"WHERE h.url = ?1 AND a.anno_attribute_id = "
|
||||
"(SELECT id FROM moz_anno_attributes WHERE name = ?2)"),
|
||||
getter_AddRefs(mDBGetAnnotationFromURI));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
@ -186,7 +172,7 @@ nsAnnotationService::Init()
|
||||
"a.expiration, a.type "
|
||||
"FROM moz_items_annos a "
|
||||
"WHERE a.item_id = ?1 AND a.anno_attribute_id = "
|
||||
"(SELECT id FROM moz_anno_attributes WHERE name = ?2)"),
|
||||
"(SELECT id FROM moz_anno_attributes WHERE name = ?2)"),
|
||||
getter_AddRefs(mDBGetAnnotationFromItemId));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
@ -206,8 +192,7 @@ nsAnnotationService::Init()
|
||||
// Note: kAnnoIndex_Name here is a name ID and not a string like the getters
|
||||
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"INSERT INTO moz_annos "
|
||||
"(place_id, anno_attribute_id, mime_type, content, flags, expiration, "
|
||||
"type, dateAdded) "
|
||||
"(place_id, anno_attribute_id, mime_type, content, flags, expiration, type, dateAdded) "
|
||||
"VALUES (?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)"),
|
||||
getter_AddRefs(mDBAddAnnotation));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -216,8 +201,7 @@ nsAnnotationService::Init()
|
||||
// Note: kAnnoIndex_Name here is a name ID and not a string like the getters
|
||||
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"INSERT INTO moz_items_annos "
|
||||
"(item_id, anno_attribute_id, mime_type, content, flags, expiration, "
|
||||
"type, dateAdded) "
|
||||
"(item_id, anno_attribute_id, mime_type, content, flags, expiration, type, dateAdded) "
|
||||
"VALUES (?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)"),
|
||||
getter_AddRefs(mDBAddItemAnnotation));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -225,21 +209,21 @@ nsAnnotationService::Init()
|
||||
// mDBRemoveAnnotation
|
||||
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"DELETE FROM moz_annos WHERE place_id = ?1 AND anno_attribute_id = "
|
||||
"(SELECT id FROM moz_anno_attributes WHERE name = ?2)"),
|
||||
"(SELECT id FROM moz_anno_attributes WHERE name = ?2)"),
|
||||
getter_AddRefs(mDBRemoveAnnotation));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// mDBRemoveItemAnnotation
|
||||
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"DELETE FROM moz_items_annos WHERE item_id = ?1 AND anno_attribute_id = "
|
||||
"(SELECT id FROM moz_anno_attributes WHERE name = ?2)"),
|
||||
"(SELECT id FROM moz_anno_attributes WHERE name = ?2)"),
|
||||
getter_AddRefs(mDBRemoveItemAnnotation));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// mDBGetItemsWithAnnotation
|
||||
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT a.item_id FROM moz_anno_attributes n "
|
||||
"JOIN moz_items_annos a ON n.id = a.anno_attribute_id "
|
||||
"INNER JOIN moz_items_annos a ON n.id = a.anno_attribute_id "
|
||||
"WHERE n.name = ?1"),
|
||||
getter_AddRefs(mDBGetItemsWithAnnotation));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -269,8 +253,7 @@ nsAnnotationService::InitTables(mozIStorageConnection* aDBConn)
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
||||
"CREATE UNIQUE INDEX moz_annos_placeattributeindex "
|
||||
"ON moz_annos (place_id, anno_attribute_id)"));
|
||||
"CREATE UNIQUE INDEX moz_annos_placeattributeindex ON moz_annos (place_id, anno_attribute_id)"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
@ -287,8 +270,7 @@ nsAnnotationService::InitTables(mozIStorageConnection* aDBConn)
|
||||
rv = aDBConn->ExecuteSimpleSQL(CREATE_MOZ_ITEMS_ANNOS);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
||||
"CREATE UNIQUE INDEX moz_items_annos_itemattributeindex "
|
||||
"ON moz_items_annos (item_id, anno_attribute_id)"));
|
||||
"CREATE UNIQUE INDEX moz_items_annos_itemattributeindex ON moz_items_annos (item_id, anno_attribute_id)"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
@ -1228,18 +1210,10 @@ nsAnnotationService::GetPagesWithAnnotationCOMArray(
|
||||
// statement. Perhaps this should change.
|
||||
nsCOMPtr<mozIStorageStatement> statement;
|
||||
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT h.url "
|
||||
"FROM moz_places_temp h "
|
||||
"JOIN moz_annos a ON h.id = a.place_id "
|
||||
"JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id "
|
||||
"WHERE n.name = ?1 "
|
||||
"UNION ALL "
|
||||
"SELECT h.url "
|
||||
"FROM moz_places h "
|
||||
"JOIN moz_annos a ON h.id = a.place_id "
|
||||
"JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id "
|
||||
"WHERE n.name = ?1 "
|
||||
"AND h.id NOT IN (SELECT id FROM moz_places_temp)"),
|
||||
"SELECT h.url FROM moz_anno_attributes n "
|
||||
"INNER JOIN moz_annos a ON n.id = a.anno_attribute_id "
|
||||
"INNER JOIN moz_places h ON a.place_id = h.id "
|
||||
"WHERE n.name = ?1"),
|
||||
getter_AddRefs(statement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
@ -1654,12 +1628,10 @@ nsAnnotationService::CopyPageAnnotations(nsIURI* aSourceURI,
|
||||
// source with the same values of the annotation on dest.
|
||||
nsCOMPtr<mozIStorageStatement> statement;
|
||||
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"INSERT INTO moz_annos "
|
||||
"(place_id, anno_attribute_id, mime_type, content, flags, expiration) "
|
||||
"INSERT INTO moz_annos (place_id, anno_attribute_id, mime_type, content, flags, expiration) "
|
||||
"SELECT ?1, anno_attribute_id, mime_type, content, flags, expiration "
|
||||
"FROM moz_annos "
|
||||
"WHERE place_id = ?2 AND anno_attribute_id = "
|
||||
"(SELECT id FROM moz_anno_attributes WHERE name = ?3)"),
|
||||
"FROM moz_annos WHERE place_id = ?2 AND anno_attribute_id = "
|
||||
"(SELECT id FROM moz_anno_attributes WHERE name = ?3)"),
|
||||
getter_AddRefs(statement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
@ -154,19 +154,10 @@ nsFaviconService::Init()
|
||||
getter_AddRefs(mDBGetIconInfo));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// We can avoid checking for duplicates in the unified table since an uri
|
||||
// can only have one favicon associated. LIMIT 1 will ensure that we get
|
||||
// only one result.
|
||||
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT f.id, f.url, length(f.data), f.expiration "
|
||||
"FROM ( "
|
||||
"SELECT * FROM moz_places_temp "
|
||||
"WHERE url = ?1 "
|
||||
"UNION ALL "
|
||||
"SELECT * FROM moz_places "
|
||||
"WHERE url = ?1 "
|
||||
") AS h JOIN moz_favicons f ON h.favicon_id = f.id "
|
||||
"LIMIT 1"),
|
||||
"FROM moz_places h JOIN moz_favicons f ON h.favicon_id = f.id "
|
||||
"WHERE h.url = ?1"),
|
||||
getter_AddRefs(mDBGetURL));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
@ -188,7 +179,7 @@ nsFaviconService::Init()
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"UPDATE moz_places_view SET favicon_id = ?2 WHERE id = ?1"),
|
||||
"UPDATE moz_places SET favicon_id = ?2 WHERE id = ?1"),
|
||||
getter_AddRefs(mDBSetPageFavicon));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
@ -113,9 +113,8 @@ nsNavBookmarks::Init()
|
||||
|
||||
{
|
||||
nsCOMPtr<mozIStorageStatement> statement;
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT id FROM moz_bookmarks WHERE type = ?1 AND parent IS NULL"),
|
||||
getter_AddRefs(statement));
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING("SELECT id FROM moz_bookmarks WHERE type = ?1 AND parent IS NULL"),
|
||||
getter_AddRefs(statement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = statement->BindInt32Parameter(0, TYPE_FOLDER);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -133,26 +132,19 @@ nsNavBookmarks::Init()
|
||||
nsCOMPtr<nsIStringBundleService> bundleService =
|
||||
do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = bundleService->CreateBundle("chrome://places/locale/places.properties",
|
||||
getter_AddRefs(mBundle));
|
||||
rv = bundleService->CreateBundle(
|
||||
"chrome://places/locale/places.properties",
|
||||
getter_AddRefs(mBundle));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// mDBFindURIBookmarks
|
||||
// NOTE: Do not modify the ORDER BY segment of the query, as certain
|
||||
// features depend on it. See bug 398914 for an example.
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT b.id "
|
||||
"FROM moz_bookmarks b "
|
||||
"JOIN ( "
|
||||
"SELECT id FROM moz_places_temp "
|
||||
"WHERE url = ?1 "
|
||||
"UNION ALL "
|
||||
"SELECT id FROM moz_places "
|
||||
"WHERE url = ?1 "
|
||||
"AND +id NOT IN (SELECT id FROM moz_places_temp) "
|
||||
") AS h ON b.fk = h.id "
|
||||
"WHERE b.type = ?2 "
|
||||
"ORDER BY MAX(IFNULL(b.lastModified, 0), b.dateAdded) DESC, b.id DESC"),
|
||||
"SELECT a.id "
|
||||
"FROM moz_bookmarks a, moz_places h "
|
||||
"WHERE h.url = ?1 AND a.fk = h.id and a.type = ?2 "
|
||||
"ORDER BY MAX(COALESCE(a.lastModified, 0), a.dateAdded) DESC, a.id DESC"),
|
||||
getter_AddRefs(mDBFindURIBookmarks));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
@ -165,59 +157,36 @@ nsNavBookmarks::Init()
|
||||
// This is a LEFT OUTER JOIN with moz_places since folders does not have
|
||||
// a reference into that table.
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT * FROM ( "
|
||||
"SELECT h.id, h.url, COALESCE(b.title, h.title), "
|
||||
"h.rev_host, h.visit_count, "
|
||||
SQL_STR_FRAGMENT_MAX_VISIT_DATE( "h.id" )
|
||||
", f.url, null, b.id, b.dateAdded, b.lastModified, "
|
||||
"b.position, b.type, b.fk "
|
||||
"FROM moz_bookmarks b "
|
||||
"JOIN moz_places_temp h ON b.fk = h.id "
|
||||
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
|
||||
"WHERE b.parent = ?1 "
|
||||
"UNION ALL "
|
||||
"SELECT h.id, h.url, COALESCE(b.title, h.title), "
|
||||
"h.rev_host, h.visit_count, "
|
||||
SQL_STR_FRAGMENT_MAX_VISIT_DATE( "h.id" )
|
||||
", f.url, null, b.id, b.dateAdded, b.lastModified, "
|
||||
"b.position, b.type, b.fk "
|
||||
"FROM moz_bookmarks b "
|
||||
"LEFT JOIN moz_places h ON b.fk = h.id "
|
||||
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
|
||||
"WHERE b.parent = ?1 "
|
||||
"AND (b.fk ISNULL OR b.fk NOT IN (select id FROM moz_places_temp)) "
|
||||
") "
|
||||
"ORDER BY 12 ASC"), /* position */
|
||||
"SELECT h.id, h.url, COALESCE(b.title, h.title), "
|
||||
"h.rev_host, h.visit_count, "
|
||||
SQL_STR_FRAGMENT_MAX_VISIT_DATE( "h.id" )
|
||||
", f.url, null, b.id, "
|
||||
"b.dateAdded, b.lastModified, "
|
||||
"b.position, b.type, b.fk "
|
||||
"FROM moz_bookmarks b "
|
||||
"LEFT OUTER JOIN moz_places h ON b.fk = h.id "
|
||||
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
|
||||
"WHERE b.parent = ?1 "
|
||||
"ORDER BY b.position"),
|
||||
getter_AddRefs(mDBGetChildren));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// mDBFolderCount: count all of the children of a given folder
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT COUNT(*) FROM moz_bookmarks WHERE parent = ?1"),
|
||||
getter_AddRefs(mDBFolderCount));
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING("SELECT COUNT(*) FROM moz_bookmarks WHERE parent = ?1"),
|
||||
getter_AddRefs(mDBFolderCount));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT position FROM moz_bookmarks WHERE id = ?1"),
|
||||
getter_AddRefs(mDBGetItemIndex));
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING("SELECT position FROM moz_bookmarks WHERE id = ?1"),
|
||||
getter_AddRefs(mDBGetItemIndex));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT id, fk, type FROM moz_bookmarks WHERE parent = ?1 AND position = ?2"),
|
||||
getter_AddRefs(mDBGetChildAt));
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING("SELECT id, fk, type FROM moz_bookmarks WHERE parent = ?1 AND position = ?2"),
|
||||
getter_AddRefs(mDBGetChildAt));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// get bookmark/folder/separator properties
|
||||
// get bookmark/folder/separator properties
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT b.id, "
|
||||
"IFNULL( "
|
||||
"(SELECT url FROM moz_places_temp "
|
||||
"WHERE id = (SELECT fk FROM moz_bookmarks WHERE id = ?1)) "
|
||||
", "
|
||||
"(SELECT url FROM moz_places "
|
||||
"WHERE id = (SELECT fk FROM moz_bookmarks WHERE id = ?1)) "
|
||||
"), b.title, b.position, b.fk, b.parent, b.type, b.folder_type, "
|
||||
"b.dateAdded, b.lastModified "
|
||||
"SELECT b.id, (SELECT url from moz_places WHERE id = b.fk), b.title, b.position, b.fk, b.parent, b.type, b.folder_type, b.dateAdded, b.lastModified "
|
||||
"FROM moz_bookmarks b "
|
||||
"WHERE b.id = ?1"),
|
||||
getter_AddRefs(mDBGetItemProperties));
|
||||
@ -233,93 +202,52 @@ nsNavBookmarks::Init()
|
||||
// mDBGetRedirectDestinations
|
||||
// input = page ID, time threshold; output = unique ID input has redirected to
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT DISTINCT dest_v.place_id "
|
||||
"FROM moz_historyvisits_temp source_v "
|
||||
"JOIN moz_historyvisits_temp dest_v ON dest_v.from_visit = source_v.id "
|
||||
"WHERE source_v.place_id = ?1 "
|
||||
"AND source_v.visit_date >= ?2 "
|
||||
"AND dest_v.visit_type IN (") +
|
||||
nsPrintfCString("%d,%d",
|
||||
nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT,
|
||||
nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY) +
|
||||
NS_LITERAL_CSTRING(") "
|
||||
"UNION "
|
||||
"SELECT DISTINCT dest_v.place_id "
|
||||
"FROM moz_historyvisits_temp source_v "
|
||||
"JOIN moz_historyvisits dest_v ON dest_v.from_visit = source_v.id "
|
||||
"WHERE source_v.place_id = ?1 "
|
||||
"AND source_v.visit_date >= ?2 "
|
||||
"AND dest_v.visit_type IN (") +
|
||||
nsPrintfCString("%d,%d",
|
||||
nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT,
|
||||
nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY) +
|
||||
NS_LITERAL_CSTRING(") "
|
||||
"UNION "
|
||||
"SELECT DISTINCT dest_v.place_id "
|
||||
"SELECT dest_v.place_id "
|
||||
"FROM moz_historyvisits source_v "
|
||||
"JOIN moz_historyvisits_temp dest_v ON dest_v.from_visit = source_v.id "
|
||||
"LEFT JOIN moz_historyvisits dest_v ON dest_v.from_visit = source_v.id "
|
||||
"WHERE source_v.place_id = ?1 "
|
||||
"AND source_v.visit_date >= ?2 "
|
||||
"AND dest_v.visit_type IN (") +
|
||||
nsPrintfCString("%d,%d",
|
||||
nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT,
|
||||
nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY) +
|
||||
NS_LITERAL_CSTRING(") "
|
||||
"UNION "
|
||||
"SELECT DISTINCT dest_v.place_id "
|
||||
"FROM moz_historyvisits source_v "
|
||||
"JOIN moz_historyvisits dest_v ON dest_v.from_visit = source_v.id "
|
||||
"WHERE source_v.place_id = ?1 "
|
||||
"AND source_v.visit_date >= ?2 "
|
||||
"AND dest_v.visit_type IN (") +
|
||||
nsPrintfCString("%d,%d",
|
||||
nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT,
|
||||
nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY) +
|
||||
NS_LITERAL_CSTRING(") "),
|
||||
"AND source_v.visit_date >= ?2 "
|
||||
"AND (dest_v.visit_type = 5 OR dest_v.visit_type = 6) "
|
||||
"GROUP BY dest_v.place_id"),
|
||||
getter_AddRefs(mDBGetRedirectDestinations));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// mDBInsertBookmark
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"INSERT INTO moz_bookmarks "
|
||||
"(fk, type, parent, position, title, dateAdded) "
|
||||
"VALUES (?1, ?2, ?3, ?4, ?5, ?6)"),
|
||||
getter_AddRefs(mDBInsertBookmark));
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING("INSERT INTO moz_bookmarks "
|
||||
"(fk, type, parent, position, title, dateAdded) "
|
||||
"VALUES (?1, ?2, ?3, ?4, ?5, ?6)"),
|
||||
getter_AddRefs(mDBInsertBookmark));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// mDBIsBookmarkedInDatabase
|
||||
// Just select position since it's just an int32 and may be faster.
|
||||
// We don't actually care about the data, just whether there is any.
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
rv = DBConn()->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT position FROM moz_bookmarks WHERE fk = ?1 AND type = ?2"),
|
||||
getter_AddRefs(mDBIsBookmarkedInDatabase));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// mDBGetLastBookmarkID
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
rv = DBConn()->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT id "
|
||||
"FROM moz_bookmarks "
|
||||
"ORDER BY ROWID DESC "
|
||||
"LIMIT 1"),
|
||||
getter_AddRefs(mDBGetLastBookmarkID));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// mDBSetItemDateAdded
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"UPDATE moz_bookmarks SET dateAdded = ?1 WHERE id = ?2"),
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING("UPDATE moz_bookmarks SET dateAdded = ?1 WHERE id = ?2"),
|
||||
getter_AddRefs(mDBSetItemDateAdded));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// mDBSetItemLastModified
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"UPDATE moz_bookmarks SET lastModified = ?1 WHERE id = ?2"),
|
||||
getter_AddRefs(mDBSetItemLastModified));
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING("UPDATE moz_bookmarks SET lastModified = ?1 WHERE id = ?2"),
|
||||
getter_AddRefs(mDBSetItemLastModified));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// mDBSetItemIndex
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"UPDATE moz_bookmarks SET position = ?2 WHERE id = ?1"),
|
||||
getter_AddRefs(mDBSetItemIndex));
|
||||
rv = DBConn()->CreateStatement(NS_LITERAL_CSTRING("UPDATE moz_bookmarks SET position = ?2 WHERE id = ?1"),
|
||||
getter_AddRefs(mDBSetItemIndex));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
FillBookmarksHash();
|
||||
@ -336,31 +264,19 @@ nsNavBookmarks::Init()
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
// get keyword text for URI (must be a bookmarked URI)
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT k.keyword "
|
||||
"FROM ( "
|
||||
"SELECT id FROM moz_places_temp "
|
||||
"WHERE url = ?1 "
|
||||
"UNION ALL "
|
||||
"SELECT id FROM moz_places "
|
||||
"WHERE +id NOT IN (SELECT id FROM moz_places_temp) "
|
||||
"AND url = ?1 "
|
||||
") AS h "
|
||||
"JOIN moz_bookmarks b ON b.fk = h.id "
|
||||
"JOIN moz_keywords k ON k.id = b.keyword_id"),
|
||||
"SELECT k.keyword "
|
||||
"FROM moz_places p "
|
||||
"JOIN moz_bookmarks b ON b.fk = p.id "
|
||||
"JOIN moz_keywords k ON k.id = b.keyword_id "
|
||||
"WHERE p.url = ?1"),
|
||||
getter_AddRefs(mDBGetKeywordForURI));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
// get URI for keyword
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT url FROM moz_keywords k "
|
||||
"SELECT p.url FROM moz_keywords k "
|
||||
"JOIN moz_bookmarks b ON b.keyword_id = k.id "
|
||||
"JOIN moz_places_temp h ON b.fk = h.id "
|
||||
"WHERE k.keyword = ?1 "
|
||||
"UNION ALL "
|
||||
"SELECT url FROM moz_keywords k "
|
||||
"JOIN moz_bookmarks b ON b.keyword_id = k.id "
|
||||
"JOIN moz_places h ON b.fk = h.id "
|
||||
"WHERE k.keyword = ?1 "
|
||||
"AND h.id NOT IN (SELECT id FROM moz_places_temp)"),
|
||||
"JOIN moz_places p ON b.fk = p.id "
|
||||
"WHERE k.keyword = ?1"),
|
||||
getter_AddRefs(mDBGetURIForKeyword));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
@ -382,9 +298,8 @@ nsNavBookmarks::Init()
|
||||
|
||||
// Temporary migration code for bug 396300
|
||||
nsCOMPtr<mozIStorageStatement> moveUnfiledBookmarks;
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"UPDATE moz_bookmarks SET parent = ?1 WHERE type = ?2 AND parent=?3"),
|
||||
getter_AddRefs(moveUnfiledBookmarks));
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING("UPDATE moz_bookmarks SET parent = ?1 WHERE type = ?2 AND parent=?3"),
|
||||
getter_AddRefs(moveUnfiledBookmarks));
|
||||
rv = moveUnfiledBookmarks->BindInt64Parameter(0, mUnfiledRoot);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = moveUnfiledBookmarks->BindInt32Parameter(1, TYPE_BOOKMARK);
|
||||
@ -495,9 +410,8 @@ nsresult
|
||||
nsNavBookmarks::InitRoots()
|
||||
{
|
||||
nsCOMPtr<mozIStorageStatement> getRootStatement;
|
||||
nsresult rv = DBConn()->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT folder_id FROM moz_bookmarks_roots WHERE root_name = ?1"),
|
||||
getter_AddRefs(getRootStatement));
|
||||
nsresult rv = DBConn()->CreateStatement(NS_LITERAL_CSTRING("SELECT folder_id FROM moz_bookmarks_roots WHERE root_name = ?1"),
|
||||
getter_AddRefs(getRootStatement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
PRBool createdPlacesRoot = PR_FALSE;
|
||||
@ -524,9 +438,8 @@ nsNavBookmarks::InitRoots()
|
||||
&folders);
|
||||
if (folders.Length() > 0) {
|
||||
nsCOMPtr<mozIStorageStatement> moveItems;
|
||||
rv = DBConn()->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"UPDATE moz_bookmarks SET parent = ?1 WHERE parent=?2"),
|
||||
getter_AddRefs(moveItems));
|
||||
rv = DBConn()->CreateStatement(NS_LITERAL_CSTRING("UPDATE moz_bookmarks SET parent = ?1 WHERE parent=?2"),
|
||||
getter_AddRefs(moveItems));
|
||||
rv = moveItems->BindInt64Parameter(0, mToolbarFolder);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = moveItems->BindInt64Parameter(1, folders[0]);
|
||||
@ -647,9 +560,8 @@ nsNavBookmarks::CreateRoot(mozIStorageStatement* aGetRootStatement,
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// save root ID
|
||||
rv = DBConn()->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"INSERT INTO moz_bookmarks_roots (root_name, folder_id) VALUES (?1, ?2)"),
|
||||
getter_AddRefs(insertStatement));
|
||||
rv = DBConn()->CreateStatement(NS_LITERAL_CSTRING("INSERT INTO moz_bookmarks_roots (root_name, folder_id) VALUES (?1, ?2)"),
|
||||
getter_AddRefs(insertStatement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = insertStatement->BindUTF8StringParameter(0, name);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -704,48 +616,12 @@ nsNavBookmarks::FillBookmarksHash()
|
||||
// redirection will be handled separately.
|
||||
rv = DBConn()->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT v1.place_id, v2.place_id "
|
||||
"FROM moz_bookmarks b "
|
||||
"LEFT JOIN moz_historyvisits_temp v1 on b.fk = v1.place_id "
|
||||
"LEFT JOIN moz_historyvisits v2 on v2.from_visit = v1.id "
|
||||
"WHERE b.fk IS NOT NULL AND b.type = ?1 "
|
||||
"AND v2.visit_type IN (") +
|
||||
nsPrintfCString("%d,%d",
|
||||
nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT,
|
||||
nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY) +
|
||||
NS_LITERAL_CSTRING(") GROUP BY v2.place_id "
|
||||
"UNION "
|
||||
"SELECT v1.place_id, v2.place_id "
|
||||
"FROM moz_bookmarks b "
|
||||
"LEFT JOIN moz_historyvisits v1 on b.fk = v1.place_id "
|
||||
"LEFT JOIN moz_historyvisits_temp v2 on v2.from_visit = v1.id "
|
||||
"WHERE b.fk IS NOT NULL AND b.type = ?1 "
|
||||
"AND v2.visit_type IN (") +
|
||||
nsPrintfCString("%d,%d",
|
||||
nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT,
|
||||
nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY) +
|
||||
NS_LITERAL_CSTRING(") GROUP BY v2.place_id "
|
||||
"UNION "
|
||||
"SELECT v1.place_id, v2.place_id "
|
||||
"FROM moz_bookmarks b "
|
||||
"LEFT JOIN moz_historyvisits v1 on b.fk = v1.place_id "
|
||||
"LEFT JOIN moz_historyvisits v2 on v2.from_visit = v1.id "
|
||||
"WHERE b.fk IS NOT NULL AND b.type = ?1 "
|
||||
"AND v2.visit_type IN (") +
|
||||
nsPrintfCString("%d,%d",
|
||||
nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT,
|
||||
nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY) +
|
||||
NS_LITERAL_CSTRING(") GROUP BY v2.place_id "
|
||||
"UNION "
|
||||
"SELECT v1.place_id, v2.place_id "
|
||||
"FROM moz_bookmarks b "
|
||||
"LEFT JOIN moz_historyvisits_temp v1 on b.fk = v1.place_id "
|
||||
"LEFT JOIN moz_historyvisits_temp v2 on v2.from_visit = v1.id "
|
||||
"WHERE b.fk IS NOT NULL AND b.type = ?1 "
|
||||
"AND v2.visit_type IN (") +
|
||||
nsPrintfCString("%d,%d",
|
||||
nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT,
|
||||
nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY) +
|
||||
NS_LITERAL_CSTRING(") GROUP BY v2.place_id "),
|
||||
"FROM moz_bookmarks b "
|
||||
"LEFT JOIN moz_historyvisits v1 on b.fk = v1.place_id "
|
||||
"LEFT JOIN moz_historyvisits v2 on v2.from_visit = v1.id "
|
||||
"WHERE b.fk IS NOT NULL AND b.type = ?1 "
|
||||
"AND v2.visit_type = 5 OR v2.visit_type = 6 " // perm. or temp. RDRs
|
||||
"GROUP BY v2.place_id"),
|
||||
getter_AddRefs(statement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = statement->BindInt64Parameter(0, TYPE_BOOKMARK);
|
||||
@ -1300,19 +1176,13 @@ nsNavBookmarks::CreateContainerWithID(PRInt64 aItemId, PRInt64 aParent,
|
||||
|
||||
nsCOMPtr<mozIStorageStatement> statement;
|
||||
if (aItemId == -1) {
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"INSERT INTO moz_bookmarks "
|
||||
"(title, type, parent, position, folder_type, dateAdded) "
|
||||
"VALUES (?1, ?2, ?3, ?4, ?5, ?6)"),
|
||||
getter_AddRefs(statement));
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING("INSERT INTO moz_bookmarks (title, type, parent, position, folder_type, dateAdded) VALUES (?1, ?2, ?3, ?4, ?5, ?6)"),
|
||||
getter_AddRefs(statement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
else {
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"INSERT INTO moz_bookmarks "
|
||||
"(id, title, type, parent, position, folder_type, dateAdded) "
|
||||
"VALUES (?7, ?1, ?2, ?3, ?4, ?5, ?6)"),
|
||||
getter_AddRefs(statement));
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING("INSERT INTO moz_bookmarks (id, title, type, parent, position, folder_type, dateAdded) VALUES (?7, ?1, ?2, ?3, ?4, ?5, ?6)"),
|
||||
getter_AddRefs(statement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = statement->BindInt64Parameter(6, aItemId);
|
||||
@ -1390,10 +1260,9 @@ nsNavBookmarks::InsertSeparator(PRInt64 aParent, PRInt32 aIndex,
|
||||
}
|
||||
|
||||
nsCOMPtr<mozIStorageStatement> statement;
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"INSERT INTO moz_bookmarks "
|
||||
"(type, parent, position, dateAdded) VALUES (?1, ?2, ?3, ?4)"),
|
||||
getter_AddRefs(statement));
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING("INSERT INTO moz_bookmarks "
|
||||
"(type, parent, position, dateAdded) VALUES (?1, ?2, ?3, ?4)"),
|
||||
getter_AddRefs(statement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = statement->BindInt64Parameter(0, TYPE_SEPARATOR);
|
||||
@ -2371,9 +2240,8 @@ nsNavBookmarks::ChangeBookmarkURI(PRInt64 aBookmarkId, nsIURI *aNewURI)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
nsCOMPtr<mozIStorageStatement> statement;
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"UPDATE moz_bookmarks SET fk = ?1 WHERE id = ?2"),
|
||||
getter_AddRefs(statement));
|
||||
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING("UPDATE moz_bookmarks SET fk = ?1 WHERE id = ?2"),
|
||||
getter_AddRefs(statement));
|
||||
statement->BindInt64Parameter(0, placeId);
|
||||
statement->BindInt64Parameter(1, aBookmarkId);
|
||||
|
||||
@ -2556,7 +2424,7 @@ nsNavBookmarks::SetKeywordForBookmark(PRInt64 aBookmarkId, const nsAString& aKey
|
||||
// Attempt to find pre-existing keyword record
|
||||
nsCOMPtr<mozIStorageStatement> getKeywordStmnt;
|
||||
rv = DBConn()->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT id from moz_keywords WHERE keyword = ?1"),
|
||||
"SELECT id from moz_keywords WHERE keyword = ?1"),
|
||||
getter_AddRefs(getKeywordStmnt));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = getKeywordStmnt->BindStringParameter(0, kwd);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -104,15 +104,10 @@
|
||||
// this is a work-around for a problem with the optimizer of sqlite
|
||||
// A sub-select on MAX(visit_date) is slower than this query with our indexes
|
||||
// see Bug #392399 for more details
|
||||
#define SQL_STR_FRAGMENT_MAX_VISIT_DATE_BASE( __place_relation, __table_name ) \
|
||||
"(SELECT visit_date FROM " __table_name \
|
||||
" WHERE place_id = " __place_relation \
|
||||
#define SQL_STR_FRAGMENT_MAX_VISIT_DATE( place_relation ) \
|
||||
"(SELECT visit_date FROM moz_historyvisits WHERE place_id = " place_relation \
|
||||
" AND visit_type NOT IN (0,4,7) ORDER BY visit_date DESC LIMIT 1)"
|
||||
|
||||
#define SQL_STR_FRAGMENT_MAX_VISIT_DATE( __place_relation ) \
|
||||
"IFNULL( " SQL_STR_FRAGMENT_MAX_VISIT_DATE_BASE( __place_relation, "moz_historyvisits_temp") \
|
||||
", " SQL_STR_FRAGMENT_MAX_VISIT_DATE_BASE( __place_relation, "moz_historyvisits") ")"
|
||||
|
||||
struct AutoCompleteIntermediateResult;
|
||||
class AutoCompleteResultComparator;
|
||||
class mozIAnnotationService;
|
||||
@ -468,15 +463,12 @@ protected:
|
||||
* The database was migrated to a new version.
|
||||
*/
|
||||
nsresult InitDB(PRInt16 *aMadeChanges);
|
||||
nsresult InitTempTables();
|
||||
nsresult InitViews();
|
||||
nsresult InitFunctions();
|
||||
nsresult InitStatements();
|
||||
nsresult ForceMigrateBookmarksDB(mozIStorageConnection *aDBConn);
|
||||
nsresult MigrateV3Up(mozIStorageConnection *aDBConn);
|
||||
nsresult MigrateV6Up(mozIStorageConnection *aDBConn);
|
||||
nsresult MigrateV7Up(mozIStorageConnection *aDBConn);
|
||||
nsresult MigrateV8Up(mozIStorageConnection *aDBConn);
|
||||
nsresult EnsureCurrentSchema(mozIStorageConnection* aDBConn, PRBool *aMadeChanges);
|
||||
nsresult CleanUpOnQuit();
|
||||
|
||||
|
@ -92,7 +92,7 @@
|
||||
NS_LITERAL_CSTRING(" AND b.fk = h.id") + \
|
||||
(getMostRecent ? NS_LITERAL_CSTRING(" " \
|
||||
"ORDER BY b.lastModified DESC LIMIT 1") : EmptyCString()) + \
|
||||
NS_LITERAL_CSTRING(") AS " name)
|
||||
NS_LITERAL_CSTRING(") " name)
|
||||
|
||||
// Get three named columns from the bookmarks and tags table
|
||||
#define BOOK_TAG_SQL (\
|
||||
@ -107,15 +107,6 @@
|
||||
const PRUnichar kTitleTagsSeparatorChars[] = { ' ', 0x2013, ' ', 0 };
|
||||
#define TITLE_TAGS_SEPARATOR nsAutoString(kTitleTagsSeparatorChars)
|
||||
|
||||
// This fragment is used to get best favicon for a rev_host
|
||||
#define BEST_FAVICON_FOR_REVHOST( __table_name ) \
|
||||
"(SELECT f.url FROM " __table_name " " \
|
||||
"JOIN moz_favicons f ON f.id = favicon_id " \
|
||||
"WHERE rev_host = IFNULL( " \
|
||||
"(SELECT rev_host FROM moz_places_temp WHERE id = b.fk), " \
|
||||
"(SELECT rev_host FROM moz_places WHERE id = b.fk)) " \
|
||||
"ORDER BY frecency DESC LIMIT 1) "
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// nsNavHistoryAutoComplete Helper Functions
|
||||
|
||||
@ -272,123 +263,81 @@ nsresult
|
||||
nsNavHistory::CreateAutoCompleteQueries()
|
||||
{
|
||||
// Define common pieces of various queries
|
||||
nsCString sqlHead = NS_LITERAL_CSTRING(
|
||||
"SELECT h.url, h.title, f.url") + BOOK_TAG_SQL + NS_LITERAL_CSTRING(", "
|
||||
"h.visit_count "
|
||||
"FROM moz_places h "
|
||||
"LEFT OUTER JOIN moz_favicons f ON f.id = h.favicon_id "
|
||||
"WHERE h.frecency <> 0 ");
|
||||
// NOTE:
|
||||
// after migration or clear all private data, we might end up with
|
||||
// a lot of places with frecency < 0 (until idle)
|
||||
//
|
||||
// XXX bug 412736
|
||||
// in the case of a frecency tie, break it with h.typed and h.visit_count
|
||||
// which is better than nothing. but this is slow, so not doing it yet.
|
||||
nsCString sqlTail = NS_LITERAL_CSTRING(
|
||||
"ORDER BY h.frecency DESC LIMIT ?2 OFFSET ?3");
|
||||
|
||||
// Try to reduce size of compound table since with partitioning this became
|
||||
// slower. Limiting moz_places with OFFSET+LIMIT will mostly help speed
|
||||
// of first chunks, that are usually most wanted.
|
||||
// Can do this only if there aren't additional conditions on final resultset.
|
||||
|
||||
// Note: h.frecency is selected because we need it for ordering, but will
|
||||
// not be read later and we don't have an associated kAutoCompleteIndex_
|
||||
|
||||
nsCString sqlBase = NS_LITERAL_CSTRING(
|
||||
"SELECT h.url, h.title, f.url") + BOOK_TAG_SQL + NS_LITERAL_CSTRING(", "
|
||||
"h.visit_count, h.frecency "
|
||||
"FROM moz_places_temp h "
|
||||
"LEFT OUTER JOIN moz_favicons f ON f.id = h.favicon_id "
|
||||
"WHERE h.frecency <> 0 "
|
||||
"{ADDITIONAL_CONDITIONS} "
|
||||
"UNION ALL "
|
||||
"SELECT * FROM ( "
|
||||
"SELECT h.url, h.title, f.url") + BOOK_TAG_SQL + NS_LITERAL_CSTRING(", "
|
||||
"h.visit_count, h.frecency "
|
||||
"FROM moz_places h "
|
||||
"LEFT OUTER JOIN moz_favicons f ON f.id = h.favicon_id "
|
||||
"WHERE h.id NOT IN (SELECT id FROM moz_places_temp) "
|
||||
"AND h.frecency <> 0 "
|
||||
"{ADDITIONAL_CONDITIONS} "
|
||||
"ORDER BY h.frecency DESC LIMIT (?2 + ?3) "
|
||||
") "
|
||||
"ORDER BY 8 DESC LIMIT ?2 OFFSET ?3"); // ORDER BY frecency
|
||||
|
||||
nsCString AutoCompleteQuery = sqlBase;
|
||||
AutoCompleteQuery.ReplaceSubstring("{ADDITIONAL_CONDITIONS}",
|
||||
(mAutoCompleteOnlyTyped ?
|
||||
"AND h.typed = 1" : ""));
|
||||
nsresult rv = mDBConn->CreateStatement(AutoCompleteQuery,
|
||||
getter_AddRefs(mDBAutoCompleteQuery));
|
||||
nsresult rv = mDBConn->CreateStatement(sqlHead + (mAutoCompleteOnlyTyped ?
|
||||
NS_LITERAL_CSTRING("AND h.typed = 1 ") : EmptyCString()) + sqlTail,
|
||||
getter_AddRefs(mDBAutoCompleteQuery));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCString AutoCompleteHistoryQuery = sqlBase;
|
||||
AutoCompleteHistoryQuery.ReplaceSubstring("{ADDITIONAL_CONDITIONS}",
|
||||
"AND h.visit_count > 0");
|
||||
rv = mDBConn->CreateStatement(AutoCompleteHistoryQuery,
|
||||
getter_AddRefs(mDBAutoCompleteHistoryQuery));
|
||||
rv = mDBConn->CreateStatement(sqlHead +
|
||||
NS_LITERAL_CSTRING("AND h.visit_count > 0 ") + sqlTail,
|
||||
getter_AddRefs(mDBAutoCompleteHistoryQuery));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCString AutoCompleteStarQuery = sqlBase;
|
||||
AutoCompleteStarQuery.ReplaceSubstring("{ADDITIONAL_CONDITIONS}",
|
||||
"AND bookmark IS NOT NULL");
|
||||
rv = mDBConn->CreateStatement(AutoCompleteStarQuery,
|
||||
getter_AddRefs(mDBAutoCompleteStarQuery));
|
||||
rv = mDBConn->CreateStatement(sqlHead +
|
||||
NS_LITERAL_CSTRING("AND bookmark IS NOT NULL ") + sqlTail,
|
||||
getter_AddRefs(mDBAutoCompleteStarQuery));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCString AutoCompleteTagsQuery = sqlBase;
|
||||
AutoCompleteTagsQuery.ReplaceSubstring("{ADDITIONAL_CONDITIONS}",
|
||||
"AND tags IS NOT NULL");
|
||||
rv = mDBConn->CreateStatement(AutoCompleteTagsQuery,
|
||||
getter_AddRefs(mDBAutoCompleteTagsQuery));
|
||||
rv = mDBConn->CreateStatement(sqlHead +
|
||||
NS_LITERAL_CSTRING("AND tags IS NOT NULL ") + sqlTail,
|
||||
getter_AddRefs(mDBAutoCompleteTagsQuery));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// In this query we are taking BOOK_TAG_SQL only for h.id because it
|
||||
// uses data from moz_bookmarks table and we sync tables on bookmark insert.
|
||||
// So, most likely, h.id will always be populated when we have any bookmark.
|
||||
// We still need to join on moz_places_temp for other data (eg. title).
|
||||
nsCString sql = NS_LITERAL_CSTRING(
|
||||
"SELECT IFNULL(h_t.url, h.url), IFNULL(h_t.title, h.title), f.url ") +
|
||||
BOOK_TAG_SQL + NS_LITERAL_CSTRING(", "
|
||||
"IFNULL(h_t.visit_count, h.visit_count), rank "
|
||||
"FROM ( "
|
||||
"SELECT ROUND(MAX(((i.input = ?2) + (SUBSTR(i.input, 1, LENGTH(?2)) = ?2)) * "
|
||||
"i.use_count), 1) AS rank, place_id "
|
||||
"FROM moz_inputhistory i "
|
||||
"GROUP BY i.place_id HAVING rank > 0 "
|
||||
") AS i "
|
||||
"LEFT JOIN moz_places h ON h.id = i.place_id "
|
||||
"LEFT JOIN moz_places_temp h_t ON h_t.id = i.place_id "
|
||||
"LEFT JOIN moz_favicons f ON f.id = IFNULL(h_t.favicon_id, h.favicon_id) "
|
||||
"WHERE IFNULL(h_t.url, h.url) NOTNULL "
|
||||
"ORDER BY rank DESC, IFNULL(h_t.frecency, h.frecency) DESC");
|
||||
"SELECT h.url, h.title, f.url") + BOOK_TAG_SQL + NS_LITERAL_CSTRING(", "
|
||||
"h.visit_count, "
|
||||
"ROUND(MAX(((i.input = ?2) + (SUBSTR(i.input, 1, LENGTH(?2)) = ?2)) * "
|
||||
"i.use_count), 1) rank "
|
||||
"FROM moz_inputhistory i "
|
||||
"JOIN moz_places h ON h.id = i.place_id "
|
||||
"LEFT OUTER JOIN moz_favicons f ON f.id = h.favicon_id "
|
||||
"GROUP BY i.place_id HAVING rank > 0 "
|
||||
"ORDER BY rank DESC, h.frecency DESC");
|
||||
rv = mDBConn->CreateStatement(sql, getter_AddRefs(mDBAdaptiveQuery));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
sql = NS_LITERAL_CSTRING(
|
||||
"SELECT IFNULL( "
|
||||
"(SELECT REPLACE(url, '%s', ?2) FROM moz_places_temp WHERE id = b.fk), "
|
||||
"(SELECT REPLACE(url, '%s', ?2) FROM moz_places WHERE id = b.fk) "
|
||||
") AS search_url, IFNULL(h_t.title, h.title), "
|
||||
"COALESCE(f.url, "
|
||||
BEST_FAVICON_FOR_REVHOST("moz_places_temp") ", "
|
||||
BEST_FAVICON_FOR_REVHOST("moz_places")
|
||||
"), "
|
||||
"b.parent, b.title, NULL, IFNULL(h_t.visit_count, h.visit_count) "
|
||||
"SELECT REPLACE(s.url, '%s', ?2) search_url, h.title, IFNULL(f.url, "
|
||||
"(SELECT f.url "
|
||||
"FROM moz_places r "
|
||||
"JOIN moz_favicons f ON f.id = r.favicon_id "
|
||||
"WHERE r.rev_host = s.rev_host "
|
||||
"ORDER BY r.frecency DESC LIMIT 1)), "
|
||||
"b.parent, b.title, NULL, h.visit_count "
|
||||
"FROM moz_keywords k "
|
||||
"JOIN moz_bookmarks b ON b.keyword_id = k.id "
|
||||
"LEFT JOIN moz_places AS h ON h.url = search_url "
|
||||
"LEFT JOIN moz_places_temp AS h_t ON h_t.url = search_url "
|
||||
"LEFT JOIN moz_favicons f ON f.id = IFNULL(h_t.favicon_id, h.favicon_id) "
|
||||
"JOIN moz_places s ON s.id = b.fk "
|
||||
"LEFT OUTER JOIN moz_places h ON h.url = search_url "
|
||||
"LEFT OUTER JOIN moz_favicons f ON f.id = h.favicon_id "
|
||||
"WHERE LOWER(k.keyword) = LOWER(?1) "
|
||||
"ORDER BY IFNULL(h_t.frecency, h.frecency) DESC");
|
||||
"ORDER BY h.frecency DESC");
|
||||
rv = mDBConn->CreateStatement(sql, getter_AddRefs(mDBKeywordQuery));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
sql = NS_LITERAL_CSTRING(
|
||||
// Leverage the PRIMARY KEY (place_id, input) to insert/update entries
|
||||
"INSERT OR REPLACE INTO moz_inputhistory "
|
||||
// use_count will asymptotically approach the max of 10
|
||||
"SELECT h.id, IFNULL(i.input, ?1), IFNULL(i.use_count, 0) * .9 + 1 "
|
||||
"FROM moz_places_temp h "
|
||||
"LEFT JOIN moz_inputhistory i ON i.place_id = h.id AND i.input = ?1 "
|
||||
"WHERE url = ?2 "
|
||||
"UNION ALL "
|
||||
"SELECT h.id, IFNULL(i.input, ?1), IFNULL(i.use_count, 0) * .9 + 1 "
|
||||
"FROM moz_places h "
|
||||
"LEFT JOIN moz_inputhistory i ON i.place_id = h.id AND i.input = ?1 "
|
||||
"WHERE url = ?2 "
|
||||
"AND h.id NOT IN (SELECT id FROM moz_places_temp)");
|
||||
// use_count will asymptotically approach the max of 10
|
||||
"SELECT h.id, IFNULL(i.input, ?1), IFNULL(i.use_count, 0) * .9 + 1 "
|
||||
"FROM moz_places h "
|
||||
"LEFT OUTER JOIN moz_inputhistory i ON i.place_id = h.id AND i.input = ?1 "
|
||||
"WHERE h.url = ?2");
|
||||
rv = mDBConn->CreateStatement(sql, getter_AddRefs(mDBFeedbackIncrease));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
@ -590,30 +539,23 @@ nsNavHistory::StartSearch(const nsAString & aSearchString,
|
||||
// has more than 0 results. We can continue from where the previous
|
||||
// search left off, but first we want to create an optimized query that
|
||||
// only searches through the urls that were previously found
|
||||
|
||||
// We have to do the bindings for both tables, so we build a temporary
|
||||
// string
|
||||
nsCString bindings;
|
||||
for (PRUint32 i = 0; i < prevMatchCount; i++) {
|
||||
if (i)
|
||||
bindings += NS_LITERAL_CSTRING(",");
|
||||
|
||||
// +2 to skip over the ?1 for the tag root parameter
|
||||
bindings += nsPrintfCString("?%d", i + 2);
|
||||
}
|
||||
|
||||
nsCString sql = NS_LITERAL_CSTRING(
|
||||
"SELECT h.url, h.title, f.url") + BOOK_TAG_SQL + NS_LITERAL_CSTRING(", "
|
||||
"h.visit_count "
|
||||
"FROM ( "
|
||||
"SELECT * FROM moz_places_temp "
|
||||
"WHERE url IN (") + bindings + NS_LITERAL_CSTRING(") "
|
||||
"UNION ALL "
|
||||
"SELECT * FROM moz_places "
|
||||
"WHERE id NOT IN (SELECT id FROM moz_places_temp) "
|
||||
"AND url IN (") + bindings + NS_LITERAL_CSTRING(") "
|
||||
") AS h "
|
||||
"FROM moz_places h "
|
||||
"LEFT OUTER JOIN moz_favicons f ON f.id = h.favicon_id "
|
||||
"WHERE h.url IN (");
|
||||
|
||||
// Put in bind spots for the urls
|
||||
for (PRUint32 i = 0; i < prevMatchCount; i++) {
|
||||
if (i)
|
||||
sql += NS_LITERAL_CSTRING(",");
|
||||
|
||||
// +2 to skip over the ?1 for the tag root parameter
|
||||
sql += nsPrintfCString("?%d", i + 2);
|
||||
}
|
||||
|
||||
sql += NS_LITERAL_CSTRING(") "
|
||||
"ORDER BY h.frecency DESC");
|
||||
|
||||
rv = mDBConn->CreateStatement(sql, getter_AddRefs(mDBPreviousQuery));
|
||||
|
@ -252,29 +252,20 @@ nsNavHistoryExpire::ClearHistory()
|
||||
// idle query to figure out which places to recalcuate frecency first.
|
||||
// We must do this before deleting visits
|
||||
nsresult rv = connection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
||||
"UPDATE moz_places_view SET frecency = -MAX(visit_count, 1) "
|
||||
"UPDATE moz_places SET frecency = -MAX(visit_count, 1) "
|
||||
"WHERE id IN("
|
||||
"SELECT h.id FROM moz_places_temp h "
|
||||
"WHERE "
|
||||
"SELECT h.id FROM moz_places h WHERE "
|
||||
"EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) "
|
||||
"OR EXISTS "
|
||||
"(SELECT id FROM moz_annos WHERE place_id = h.id AND expiration = ") +
|
||||
nsPrintfCString("%d", nsIAnnotationService::EXPIRE_NEVER) +
|
||||
NS_LITERAL_CSTRING(") "
|
||||
"UNION ALL "
|
||||
"SELECT h.id FROM moz_places h "
|
||||
"WHERE "
|
||||
"EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) "
|
||||
"OR EXISTS "
|
||||
"(SELECT id FROM moz_annos WHERE place_id = h.id AND expiration = ") +
|
||||
nsPrintfCString("%d", nsIAnnotationService::EXPIRE_NEVER) +
|
||||
NS_LITERAL_CSTRING(") "
|
||||
")"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
"(SELECT id FROM moz_annos WHERE place_id = h.id AND expiration = ") +
|
||||
nsPrintfCString("%d", nsIAnnotationService::EXPIRE_NEVER) +
|
||||
NS_LITERAL_CSTRING(")"));
|
||||
if (NS_FAILED(rv))
|
||||
NS_WARNING("failed to recent frecency");
|
||||
|
||||
// expire visits, then let the paranoid functions do the cleanup for us
|
||||
rv = connection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
||||
"DELETE FROM moz_historyvisits_view"));
|
||||
"DELETE FROM moz_historyvisits"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = ExpireHistoryParanoid(connection, -1);
|
||||
@ -480,38 +471,11 @@ nsNavHistoryExpire::FindVisits(PRTime aExpireThreshold, PRUint32 aNumToExpire,
|
||||
// Select a limited number of visits older than a time
|
||||
nsCOMPtr<mozIStorageStatement> selectStatement;
|
||||
nsresult rv = aConnection->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT * FROM ( "
|
||||
"SELECT v.id, v.place_id, v.visit_date, h.url, h.favicon_id, h.hidden, "
|
||||
"(SELECT fk FROM moz_bookmarks WHERE fk = h.id) "
|
||||
"FROM moz_places h "
|
||||
"JOIN moz_historyvisits AS v ON h.id = v.place_id "
|
||||
"WHERE visit_date < ?1 "
|
||||
"ORDER BY v.visit_date ASC LIMIT ?2 "
|
||||
") UNION ALL "
|
||||
"SELECT * FROM ( "
|
||||
"SELECT v.id, v.place_id, v.visit_date, h.url, h.favicon_id, h.hidden, "
|
||||
"(SELECT fk FROM moz_bookmarks WHERE fk = h.id)"
|
||||
"FROM moz_places_temp h "
|
||||
"JOIN moz_historyvisits AS v ON h.id = v.place_id "
|
||||
"WHERE visit_date < ?1 "
|
||||
"ORDER BY v.visit_date ASC LIMIT ?2 "
|
||||
") UNION ALL "
|
||||
"SELECT * FROM ( "
|
||||
"SELECT v.id, v.place_id, v.visit_date, h.url, h.favicon_id, h.hidden, "
|
||||
"(SELECT fk FROM moz_bookmarks WHERE fk = h.id) "
|
||||
"FROM moz_places h "
|
||||
"JOIN moz_historyvisits_temp AS v ON h.id = v.place_id "
|
||||
"WHERE visit_date < ?1 "
|
||||
"ORDER BY v.visit_date ASC LIMIT ?2 "
|
||||
") UNION ALL "
|
||||
"SELECT * FROM ( "
|
||||
"SELECT v.id, v.place_id, v.visit_date, h.url, h.favicon_id, h.hidden, "
|
||||
"(SELECT fk FROM moz_bookmarks WHERE fk = h.id) "
|
||||
"FROM moz_places_temp h "
|
||||
"JOIN moz_historyvisits_temp AS v ON h.id = v.place_id "
|
||||
"WHERE visit_date < ?1 "
|
||||
"ORDER BY v.visit_date ASC LIMIT ?2 "
|
||||
") GROUP BY 1 ORDER BY 3 ASC LIMIT ?2"),
|
||||
"SELECT v.id, v.place_id, v.visit_date, h.url, h.favicon_id, h.hidden, "
|
||||
"(SELECT fk FROM moz_bookmarks WHERE fk = h.id) "
|
||||
"FROM moz_places h JOIN moz_historyvisits v ON h.id = v.place_id "
|
||||
"WHERE v.visit_date < ?1 "
|
||||
"ORDER BY v.visit_date ASC LIMIT ?2"),
|
||||
getter_AddRefs(selectStatement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
@ -537,11 +501,7 @@ nsNavHistoryExpire::FindVisits(PRTime aExpireThreshold, PRUint32 aNumToExpire,
|
||||
// check the number of visited unique urls in the db.
|
||||
nsCOMPtr<mozIStorageStatement> countStatement;
|
||||
rv = aConnection->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT "
|
||||
"(SELECT count(*) FROM moz_places_temp WHERE visit_count > 0) + "
|
||||
"(SELECT count(*) FROM moz_places WHERE visit_count > 0) - "
|
||||
"(SELECT count(*) FROM moz_places WHERE id IN "
|
||||
"(SELECT id FROM moz_places_temp))"),
|
||||
"SELECT count(*) FROM moz_places WHERE visit_count > 0"),
|
||||
getter_AddRefs(countStatement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
@ -616,44 +576,23 @@ nsNavHistoryExpire::EraseVisits(mozIStorageConnection* aConnection,
|
||||
// keep the old frecencies when possible as an estimate for the new frecency
|
||||
// unless we know it has to be invalidated.
|
||||
// We must do this before deleting visits
|
||||
nsresult rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
||||
"UPDATE moz_places_view "
|
||||
"SET frecency = -MAX(visit_count, 1) "
|
||||
"WHERE id IN ( "
|
||||
"SELECT h.id FROM moz_places_temp h "
|
||||
"WHERE "
|
||||
"NOT EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) AND "
|
||||
"NOT EXISTS ( "
|
||||
"SELECT v.id FROM moz_historyvisits_temp v "
|
||||
"WHERE v.place_id = h.id "
|
||||
"AND v.id NOT IN (") + deletedVisitIds + NS_LITERAL_CSTRING(") "
|
||||
") AND "
|
||||
"NOT EXISTS ( "
|
||||
"SELECT v.id FROM moz_historyvisits v "
|
||||
"WHERE v.place_id = h.id "
|
||||
"AND v.id NOT IN (") + deletedVisitIds + NS_LITERAL_CSTRING(") "
|
||||
") AND "
|
||||
"h.id IN (") + placeIds + NS_LITERAL_CSTRING(") "
|
||||
"UNION ALL "
|
||||
"SELECT h.id FROM moz_places h "
|
||||
"WHERE "
|
||||
"NOT EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) AND "
|
||||
"NOT EXISTS ( "
|
||||
"SELECT v.id FROM moz_historyvisits_temp v "
|
||||
"WHERE v.place_id = h.id "
|
||||
"AND v.id NOT IN (") + deletedVisitIds + NS_LITERAL_CSTRING(") "
|
||||
") AND "
|
||||
"NOT EXISTS ( "
|
||||
"SELECT v.id FROM moz_historyvisits v "
|
||||
"WHERE v.place_id = h.id "
|
||||
"AND v.id NOT IN (") + deletedVisitIds + NS_LITERAL_CSTRING(") "
|
||||
") AND "
|
||||
"h.id IN (") + placeIds + NS_LITERAL_CSTRING(") "
|
||||
")"));
|
||||
nsresult rv = aConnection->ExecuteSimpleSQL(
|
||||
NS_LITERAL_CSTRING(
|
||||
"UPDATE moz_places "
|
||||
"SET frecency = -MAX(visit_count, 1) "
|
||||
"WHERE id IN ("
|
||||
"SELECT h.id FROM moz_places h "
|
||||
"WHERE NOT EXISTS (SELECT b.id FROM moz_bookmarks b WHERE b.fk = h.id) "
|
||||
"AND NOT EXISTS "
|
||||
"(SELECT v.id FROM moz_historyvisits v WHERE v.place_id = h.id AND "
|
||||
"v.id NOT IN (") + deletedVisitIds +
|
||||
NS_LITERAL_CSTRING(")) AND "
|
||||
"h.id IN (") + placeIds +
|
||||
NS_LITERAL_CSTRING("))"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = aConnection->ExecuteSimpleSQL(
|
||||
NS_LITERAL_CSTRING("DELETE FROM moz_historyvisits_view WHERE id IN (") +
|
||||
NS_LITERAL_CSTRING("DELETE FROM moz_historyvisits WHERE id IN (") +
|
||||
deletedVisitIds +
|
||||
NS_LITERAL_CSTRING(")"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -697,33 +636,17 @@ nsNavHistoryExpire::EraseHistory(mozIStorageConnection* aConnection,
|
||||
if (deletedPlaceIds.IsEmpty())
|
||||
return NS_OK;
|
||||
|
||||
nsresult rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
||||
"DELETE FROM moz_places_view WHERE id IN( "
|
||||
"SELECT h.id "
|
||||
"FROM moz_places h "
|
||||
"WHERE h.id IN(") + deletedPlaceIds + NS_LITERAL_CSTRING(") "
|
||||
return aConnection->ExecuteSimpleSQL(
|
||||
NS_LITERAL_CSTRING("DELETE FROM moz_places WHERE id IN( "
|
||||
"SELECT h.id "
|
||||
"FROM moz_places h "
|
||||
"WHERE h.id IN(") +
|
||||
deletedPlaceIds +
|
||||
NS_LITERAL_CSTRING(") AND NOT EXISTS "
|
||||
"(SELECT id FROM moz_historyvisits WHERE place_id = h.id LIMIT 1) "
|
||||
"AND NOT EXISTS "
|
||||
"(SELECT id FROM moz_historyvisits WHERE place_id = h.id LIMIT 1) "
|
||||
"AND NOT EXISTS "
|
||||
"(SELECT id FROM moz_historyvisits_temp WHERE place_id = h.id LIMIT 1) "
|
||||
"AND NOT EXISTS "
|
||||
"(SELECT id FROM moz_bookmarks WHERE fk = h.id LIMIT 1) "
|
||||
"AND SUBSTR(h.url,0,6) <> 'place:' "
|
||||
"UNION ALL "
|
||||
"SELECT h.id "
|
||||
"FROM moz_places_temp h "
|
||||
"WHERE h.id IN(") + deletedPlaceIds + NS_LITERAL_CSTRING(") "
|
||||
"AND NOT EXISTS "
|
||||
"(SELECT id FROM moz_historyvisits WHERE place_id = h.id LIMIT 1) "
|
||||
"AND NOT EXISTS "
|
||||
"(SELECT id FROM moz_historyvisits_temp WHERE place_id = h.id LIMIT 1) "
|
||||
"AND NOT EXISTS "
|
||||
"(SELECT id FROM moz_bookmarks WHERE fk = h.id LIMIT 1) "
|
||||
"AND SUBSTR(h.url,0,6) <> 'place:' "
|
||||
")"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
"(SELECT id FROM moz_bookmarks WHERE fk = h.id LIMIT 1) "
|
||||
"AND SUBSTR(h.url,0,6) <> 'place:')"));
|
||||
}
|
||||
|
||||
|
||||
@ -753,19 +676,13 @@ nsNavHistoryExpire::EraseFavicons(mozIStorageConnection* aConnection,
|
||||
if (deletedFaviconIds.IsEmpty())
|
||||
return NS_OK;
|
||||
|
||||
// delete only if favicon id is not referenced
|
||||
nsresult rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
||||
"DELETE FROM moz_favicons WHERE id IN ( "
|
||||
"SELECT f.id FROM moz_favicons f "
|
||||
"LEFT JOIN moz_places h ON f.id = h.favicon_id "
|
||||
"LEFT JOIN moz_places_temp h_t ON f.id = h_t.favicon_id "
|
||||
"WHERE f.id IN (") + deletedFaviconIds + NS_LITERAL_CSTRING(") "
|
||||
"AND h.favicon_id IS NULL "
|
||||
"AND h_t.favicon_id IS NULL "
|
||||
")"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
// delete only if id is not referenced in moz_places
|
||||
return aConnection->ExecuteSimpleSQL(
|
||||
NS_LITERAL_CSTRING("DELETE FROM moz_favicons WHERE id IN ( "
|
||||
"SELECT f.id FROM moz_favicons f "
|
||||
"LEFT OUTER JOIN moz_places h ON f.id = h.favicon_id "
|
||||
"WHERE f.id IN (") + deletedFaviconIds +
|
||||
NS_LITERAL_CSTRING(") AND h.favicon_id IS NULL)"));
|
||||
}
|
||||
|
||||
|
||||
@ -818,16 +735,12 @@ nsNavHistoryExpire::ExpireAnnotations(mozIStorageConnection* aConnection)
|
||||
PRTime now = PR_Now();
|
||||
nsCOMPtr<mozIStorageStatement> expirePagesStatement;
|
||||
nsresult rv = aConnection->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"DELETE FROM moz_annos "
|
||||
"WHERE expiration = ?1 AND "
|
||||
"(?2 > MAX(COALESCE(lastModified, 0), dateAdded))"),
|
||||
"DELETE FROM moz_annos WHERE expiration = ?1 AND (?2 > MAX(COALESCE(lastModified, 0), dateAdded))"),
|
||||
getter_AddRefs(expirePagesStatement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<mozIStorageStatement> expireItemsStatement;
|
||||
rv = aConnection->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"DELETE FROM moz_items_annos "
|
||||
"WHERE expiration = ?1 AND "
|
||||
"(?2 > MAX(COALESCE(lastModified, 0), dateAdded))"),
|
||||
"DELETE FROM moz_items_annos WHERE expiration = ?1 AND (?2 > MAX(COALESCE(lastModified, 0), dateAdded))"),
|
||||
getter_AddRefs(expireItemsStatement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
@ -884,9 +797,6 @@ nsNavHistoryExpire::ExpireAnnotations(mozIStorageConnection* aConnection)
|
||||
"DELETE FROM moz_annos WHERE expiration = ") +
|
||||
nsPrintfCString("%d", nsIAnnotationService::EXPIRE_WITH_HISTORY) +
|
||||
NS_LITERAL_CSTRING(" AND NOT EXISTS "
|
||||
"(SELECT id FROM moz_historyvisits_temp "
|
||||
"WHERE place_id = moz_annos.place_id LIMIT 1) "
|
||||
"AND NOT EXISTS "
|
||||
"(SELECT id FROM moz_historyvisits "
|
||||
"WHERE place_id = moz_annos.place_id LIMIT 1)"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -907,31 +817,16 @@ nsNavHistoryExpire::ExpireEmbeddedLinks(mozIStorageConnection* aConnection)
|
||||
nsCOMPtr<mozIStorageStatement> expireEmbeddedLinksStatement;
|
||||
// Note: This query also removes visit_type = 0 entries, for bug #375777.
|
||||
nsresult rv = aConnection->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"DELETE FROM moz_historyvisits_view WHERE id IN ("
|
||||
"SELECT * FROM ( "
|
||||
"SELECT id FROM moz_historyvisits_temp "
|
||||
"WHERE visit_date < ?1 "
|
||||
"AND visit_type IN (") +
|
||||
nsPrintfCString("%d", nsINavHistoryService::TRANSITION_EMBED) +
|
||||
NS_LITERAL_CSTRING(", 0) "
|
||||
"LIMIT ?2 "
|
||||
") "
|
||||
"UNION ALL "
|
||||
"SELECT * FROM ( "
|
||||
"SELECT id FROM moz_historyvisits "
|
||||
"WHERE visit_date < ?1 "
|
||||
"AND visit_type IN (") +
|
||||
nsPrintfCString("%d", nsINavHistoryService::TRANSITION_EMBED) +
|
||||
NS_LITERAL_CSTRING(", 0) "
|
||||
"LIMIT ?2 "
|
||||
") "
|
||||
"LIMIT ?2 "
|
||||
")"),
|
||||
"DELETE FROM moz_historyvisits WHERE id IN ("
|
||||
"SELECT id FROM moz_historyvisits WHERE visit_date < ?1 "
|
||||
"AND (visit_type = ?2 OR visit_type = 0) LIMIT ?3)"),
|
||||
getter_AddRefs(expireEmbeddedLinksStatement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = expireEmbeddedLinksStatement->BindInt64Parameter(0, maxEmbeddedAge);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = expireEmbeddedLinksStatement->BindInt32Parameter(1, EXPIRATION_CAP_EMBEDDED);
|
||||
rv = expireEmbeddedLinksStatement->BindInt32Parameter(1, nsINavHistoryService::TRANSITION_EMBED);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = expireEmbeddedLinksStatement->BindInt32Parameter(2, EXPIRATION_CAP_EMBEDDED);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = expireEmbeddedLinksStatement->Execute();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -952,24 +847,11 @@ nsNavHistoryExpire::ExpireHistoryParanoid(mozIStorageConnection* aConnection,
|
||||
PRInt32 aMaxRecords)
|
||||
{
|
||||
nsCAutoString query(
|
||||
"DELETE FROM moz_places_view WHERE id IN ("
|
||||
"DELETE FROM moz_places WHERE id IN ("
|
||||
"SELECT h.id FROM moz_places h "
|
||||
"LEFT JOIN moz_historyvisits v ON h.id = v.place_id "
|
||||
"LEFT JOIN moz_historyvisits_temp v_t ON h.id = v_t.place_id "
|
||||
"LEFT JOIN moz_bookmarks b ON h.id = b.fk "
|
||||
"WHERE v.id IS NULL "
|
||||
"AND v_t.id IS NULL "
|
||||
"AND b.id IS NULL "
|
||||
"AND SUBSTR(h.url,0,6) <> 'place:' "
|
||||
"UNION ALL "
|
||||
"SELECT h.id FROM moz_places_temp h "
|
||||
"LEFT JOIN moz_historyvisits v ON h.id = v.place_id "
|
||||
"LEFT JOIN moz_historyvisits_temp v_t ON h.id = v_t.place_id "
|
||||
"LEFT JOIN moz_bookmarks b ON h.id = b.fk "
|
||||
"WHERE v.id IS NULL "
|
||||
"AND v_t.id IS NULL "
|
||||
"AND b.id IS NULL "
|
||||
"AND SUBSTR(h.url,0,6) <> 'place:'");
|
||||
"LEFT OUTER JOIN moz_historyvisits v ON h.id = v.place_id "
|
||||
"LEFT OUTER JOIN moz_bookmarks b ON h.id = b.fk "
|
||||
"WHERE v.id IS NULL AND b.id IS NULL AND SUBSTR(h.url,0,6) <> 'place:'");
|
||||
if (aMaxRecords != -1) {
|
||||
query.AppendLiteral(" LIMIT ");
|
||||
query.AppendInt(aMaxRecords);
|
||||
@ -989,13 +871,10 @@ nsresult
|
||||
nsNavHistoryExpire::ExpireFaviconsParanoid(mozIStorageConnection* aConnection)
|
||||
{
|
||||
nsresult rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
||||
"DELETE FROM moz_favicons WHERE id IN ("
|
||||
"SELECT f.id FROM moz_favicons f "
|
||||
"LEFT JOIN moz_places h ON f.id = h.favicon_id "
|
||||
"LEFT JOIN moz_places_temp h_t ON f.id = h_t.favicon_id "
|
||||
"WHERE h.favicon_id IS NULL "
|
||||
"AND h_t.favicon_id IS NULL "
|
||||
")"));
|
||||
"DELETE FROM moz_favicons WHERE id IN "
|
||||
"(SELECT f.id FROM moz_favicons f "
|
||||
"LEFT OUTER JOIN moz_places h ON f.id = h.favicon_id "
|
||||
"WHERE h.favicon_id IS NULL)"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return rv;
|
||||
}
|
||||
@ -1019,17 +898,14 @@ nsNavHistoryExpire::ExpireAnnotationsParanoid(mozIStorageConnection* aConnection
|
||||
// delete all uri annos w/o a corresponding place id
|
||||
// or without any visits *and* not EXPIRE_NEVER.
|
||||
rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
||||
"DELETE FROM moz_annos WHERE id IN ("
|
||||
"SELECT a.id FROM moz_annos a "
|
||||
"LEFT JOIN moz_places h ON a.place_id = h.id "
|
||||
"LEFT JOIN moz_places_temp h_t ON a.place_id = h_t.id "
|
||||
"LEFT JOIN moz_historyvisits v ON a.place_id = v.place_id "
|
||||
"LEFT JOIN moz_historyvisits_temp v_t ON a.place_id = v_t.place_id "
|
||||
"WHERE (h.id IS NULL AND h_t.id IS NULL) "
|
||||
"OR (v.id IS NULL AND v_t.id IS NULL AND a.expiration != ") +
|
||||
nsPrintfCString("%d", nsIAnnotationService::EXPIRE_NEVER) +
|
||||
NS_LITERAL_CSTRING(")"
|
||||
")"));
|
||||
"DELETE FROM moz_annos WHERE id IN "
|
||||
"(SELECT a.id FROM moz_annos a "
|
||||
"LEFT OUTER JOIN moz_places p ON a.place_id = p.id "
|
||||
"LEFT OUTER JOIN moz_historyvisits v ON a.place_id = v.place_id "
|
||||
"WHERE p.id IS NULL "
|
||||
"OR (v.id IS NULL AND a.expiration != ") +
|
||||
nsPrintfCString("%d", nsIAnnotationService::EXPIRE_NEVER) +
|
||||
NS_LITERAL_CSTRING("))"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// delete item annos w/o a corresponding item id
|
||||
@ -1040,15 +916,16 @@ nsNavHistoryExpire::ExpireAnnotationsParanoid(mozIStorageConnection* aConnection
|
||||
"WHERE b.id IS NULL)"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// delete all anno names w/o a corresponding anno
|
||||
// delete all anno names w/o a corresponding uri or item entry
|
||||
rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
||||
"DELETE FROM moz_anno_attributes WHERE id IN ("
|
||||
"SELECT n.id FROM moz_anno_attributes n "
|
||||
"LEFT JOIN moz_annos a ON n.id = a.anno_attribute_id "
|
||||
"LEFT JOIN moz_items_annos t ON n.id = t.anno_attribute_id "
|
||||
"WHERE a.anno_attribute_id IS NULL "
|
||||
"AND t.anno_attribute_id IS NULL "
|
||||
")"));
|
||||
"DELETE FROM moz_anno_attributes WHERE "
|
||||
"id NOT IN (SELECT DISTINCT a.id FROM moz_anno_attributes a "
|
||||
"JOIN moz_annos b ON b.anno_attribute_id = a.id "
|
||||
"JOIN moz_places p ON b.place_id = p.id) "
|
||||
"AND "
|
||||
"id NOT IN (SELECT DISTINCT a.id FROM moz_anno_attributes a "
|
||||
"JOIN moz_items_annos c ON c.anno_attribute_id = a.id "
|
||||
"JOIN moz_bookmarks p ON c.item_id = p.id)"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1063,20 +940,17 @@ nsNavHistoryExpire::ExpireInputHistoryParanoid(mozIStorageConnection* aConnectio
|
||||
{
|
||||
// Delete dangling input history that have no associated pages
|
||||
nsresult rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
||||
"DELETE FROM moz_inputhistory WHERE place_id IN ( "
|
||||
"SELECT place_id FROM moz_inputhistory "
|
||||
"LEFT JOIN moz_places h ON h.id = place_id "
|
||||
"LEFT JOIN moz_places_temp h_t ON h_t.id = place_id "
|
||||
"WHERE h.id IS NULL "
|
||||
"AND h_t.id IS NULL "
|
||||
")"));
|
||||
"DELETE FROM moz_inputhistory WHERE place_id IN "
|
||||
"(SELECT i.place_id FROM moz_inputhistory i "
|
||||
"LEFT OUTER JOIN moz_places h ON i.place_id = h.id "
|
||||
"WHERE h.id IS NULL)"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Decay potentially unused entries (e.g. those that are at 1) to allow
|
||||
// better chances for new entries that will start at 1
|
||||
rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
||||
"UPDATE moz_inputhistory "
|
||||
"SET use_count = use_count * .9"));
|
||||
"UPDATE moz_inputhistory "
|
||||
"SET use_count = use_count * .9"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
|
@ -1,277 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=2 sts=2 expandtab
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Shawn Wilsher <me@shawnwilsher.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Components.utils.import("resource://gre/modules/PlacesBackground.jsm");
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Constants
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const Cr = Components.results;
|
||||
|
||||
const kPlacesBackgroundShutdown = "places-background-shutdown";
|
||||
|
||||
const kSyncPrefName = "syncDBTableIntervalInSecs";
|
||||
const kDefaultSyncInterval = 120;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// nsPlacesDBFlush class
|
||||
|
||||
function nsPlacesDBFlush()
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//// Smart Getters
|
||||
|
||||
this.__defineGetter__("_db", function() {
|
||||
delete this._db;
|
||||
return this._db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
});
|
||||
|
||||
this.__defineGetter__("_bh", function() {
|
||||
delete this._bh;
|
||||
return this._bh = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
});
|
||||
|
||||
|
||||
// Get our sync interval
|
||||
this._prefs = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefService).
|
||||
getBranch("places.");
|
||||
try {
|
||||
// We want to silently fail if the preference does not exist, and use a
|
||||
// default to fallback to.
|
||||
this._syncInterval = this._prefs.getIntPref(kSyncPrefName);
|
||||
if (this._syncInterval <= 0)
|
||||
this._syncInterval = kDefaultSyncInterval;
|
||||
}
|
||||
catch (e) {
|
||||
// The preference did not exist, so default to two minutes.
|
||||
this._syncInterval = kDefaultSyncInterval;
|
||||
}
|
||||
|
||||
// Register observers
|
||||
this._bh.addObserver(this, false);
|
||||
|
||||
this._prefs.QueryInterface(Ci.nsIPrefBranch2).addObserver("", this, false);
|
||||
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
os.addObserver(this, kPlacesBackgroundShutdown, false);
|
||||
|
||||
// Create our timer to update everything
|
||||
this._timer = this._newTimer();
|
||||
}
|
||||
|
||||
nsPlacesDBFlush.prototype = {
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//// nsIObserver
|
||||
|
||||
observe: function DBFlush_observe(aSubject, aTopic, aData)
|
||||
{
|
||||
if (aTopic == kPlacesBackgroundShutdown) {
|
||||
this._bh.removeObserver(this);
|
||||
this._timer.cancel();
|
||||
this._timer = null;
|
||||
this._syncAll();
|
||||
}
|
||||
else if (aTopic == "nsPref:changed" && aData == kSyncPrefName) {
|
||||
// Get the new pref value, and then update our timer
|
||||
this._syncInterval = aSubject.getIntPref(kSyncPrefName);
|
||||
if (this._syncInterval <= 0)
|
||||
this._syncInterval = kDefaultSyncInterval;
|
||||
|
||||
// We may have canceled the timer already for batch updates, so we want to
|
||||
// exit early.
|
||||
if (!this._timer)
|
||||
return;
|
||||
|
||||
this._timer.cancel();
|
||||
this._timer = this._newTimer();
|
||||
}
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//// nsINavBookmarkObserver
|
||||
|
||||
onBeginUpdateBatch: function DBFlush_onBeginUpdateBatch()
|
||||
{
|
||||
this._inBatchMode = true;
|
||||
|
||||
// We do not want to sync while we are doing batch work.
|
||||
this._timer.cancel();
|
||||
this._timer = null;
|
||||
},
|
||||
|
||||
onEndUpdateBatch: function DBFlush_onEndUpdateBatch()
|
||||
{
|
||||
this._inBatchMode = false;
|
||||
|
||||
// We need to sync and restore our timer now.
|
||||
this._syncAll();
|
||||
this._timer = this._newTimer();
|
||||
},
|
||||
|
||||
onItemAdded: function() this._syncMozPlaces(),
|
||||
|
||||
onItemChanged: function DBFlush_onItemChanged(aItemId, aProperty,
|
||||
aIsAnnotationProperty,
|
||||
aValue)
|
||||
{
|
||||
if (aProperty == "uri")
|
||||
this._syncMozPlaces();
|
||||
},
|
||||
|
||||
onItemRemoved: function() { },
|
||||
onItemVisited: function() { },
|
||||
onItemMoved: function() { },
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//// nsITimerCallback
|
||||
|
||||
notify: function() this._syncAll(),
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//// nsPlacesDBFlush
|
||||
|
||||
/**
|
||||
* Dispatches an event to the background thread to run _doSyncMozX("places").
|
||||
*/
|
||||
_syncMozPlaces: function DBFlush_syncMozPlaces()
|
||||
{
|
||||
// No need to do extra work if we are in batch mode
|
||||
if (this._inBatchMode)
|
||||
return;
|
||||
|
||||
let self = this;
|
||||
PlacesBackground.dispatch({
|
||||
run: function() self._doSyncMozX("places")
|
||||
}, Ci.nsIEventTarget.DISPATCH_NORMAL);
|
||||
},
|
||||
|
||||
/**
|
||||
* Dispatches an event to the background thread to sync all temporary tables.
|
||||
*/
|
||||
_syncAll: function DBFlush_syncAll()
|
||||
{
|
||||
let self = this;
|
||||
PlacesBackground.dispatch({
|
||||
run: function() {
|
||||
// We try to get a transaction, but if we can't don't worry
|
||||
let ourTransaction = false;
|
||||
try {
|
||||
this._db.beginTransaction();
|
||||
ourTransaction = true;
|
||||
}
|
||||
catch (e) { }
|
||||
|
||||
try {
|
||||
// This needs to also sync moz_places in order to maintain data
|
||||
// integrity
|
||||
self._doSyncMozX("places");
|
||||
self._doSyncMozX("historyvisits");
|
||||
}
|
||||
catch (e) {
|
||||
if (ourTransaction)
|
||||
this._db.rollbackTransaction();
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (ourTransaction)
|
||||
this._db.commitTransaction();
|
||||
}
|
||||
}, Ci.nsIEventTarget.DISPATCH_NORMAL);
|
||||
},
|
||||
|
||||
/**
|
||||
* Synchronizes the moz_{aName} and moz_{aName}_temp by copying all the data
|
||||
* from the temporary table into the permanent one. It then deletes the data
|
||||
* in the temporary table. All of this is done in a transaction that is
|
||||
* rolled back upon failure at any point.
|
||||
*/
|
||||
_doSyncMozX: function DBFlush_doSyncMozX(aName)
|
||||
{
|
||||
// Delete all the data in the temp table.
|
||||
// We have triggers setup that ensure that the data is transfered over
|
||||
// upon deletion.
|
||||
this._db.executeSimpleSQL("DELETE FROM moz_" + aName + "_temp");
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new timer bases on this._timerInterval.
|
||||
*
|
||||
* @returns a REPEATING_SLACK nsITimer that runs every this._timerInterval.
|
||||
*/
|
||||
_newTimer: function DBFlush_newTimer()
|
||||
{
|
||||
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||
timer.initWithCallback(this, this._syncInterval * 1000,
|
||||
Ci.nsITimer.TYPE_REPEATING_SLACK);
|
||||
return timer;
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//// nsISupports
|
||||
|
||||
classDescription: "Used to synchronize the temporary and permanent tables of Places",
|
||||
classID: Components.ID("c1751cfc-e8f1-4ade-b0bb-f74edfb8ef6a"),
|
||||
contractID: "@mozilla.org/places/sync;1",
|
||||
_xpcom_categories: [{
|
||||
category: "profile-after-change",
|
||||
}],
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([
|
||||
Ci.nsIObserver,
|
||||
Ci.nsINavBookmarkObserver,
|
||||
Ci.nsITimerCallback,
|
||||
])
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Module Registration
|
||||
|
||||
let components = [nsPlacesDBFlush];
|
||||
function NSGetModule(compMgr, fileSpec)
|
||||
{
|
||||
return XPCOMUtils.generateModule(components);
|
||||
}
|
@ -39,8 +39,8 @@
|
||||
#ifndef __nsPlacesTables_h__
|
||||
#define __nsPlacesTables_h__
|
||||
|
||||
#define CREATE_MOZ_PLACES_BASE(__name, __temporary) NS_LITERAL_CSTRING( \
|
||||
"CREATE " __temporary " TABLE " __name " ( " \
|
||||
#define CREATE_MOZ_PLACES NS_LITERAL_CSTRING( \
|
||||
"CREATE TABLE moz_places ( " \
|
||||
" id INTEGER PRIMARY KEY" \
|
||||
", url LONGVARCHAR" \
|
||||
", title LONGVARCHAR" \
|
||||
@ -52,18 +52,9 @@
|
||||
", frecency INTEGER DEFAULT -1 NOT NULL" \
|
||||
")" \
|
||||
)
|
||||
#define CREATE_MOZ_PLACES CREATE_MOZ_PLACES_BASE("moz_places", "")
|
||||
#define CREATE_MOZ_PLACES_TEMP CREATE_MOZ_PLACES_BASE("moz_places_temp", "TEMP")
|
||||
#define CREATE_MOZ_PLACES_VIEW NS_LITERAL_CSTRING( \
|
||||
"CREATE TEMPORARY VIEW moz_places_view AS " \
|
||||
"SELECT * FROM moz_places_temp " \
|
||||
"UNION ALL " \
|
||||
"SELECT * FROM moz_places " \
|
||||
"WHERE id NOT IN (SELECT id FROM moz_places_temp) " \
|
||||
)
|
||||
|
||||
#define CREATE_MOZ_HISTORYVISITS_BASE(__name, __temporary) NS_LITERAL_CSTRING( \
|
||||
"CREATE " __temporary " TABLE " __name " (" \
|
||||
#define CREATE_MOZ_HISTORYVISITS NS_LITERAL_CSTRING( \
|
||||
"CREATE TABLE moz_historyvisits (" \
|
||||
" id INTEGER PRIMARY KEY" \
|
||||
", from_visit INTEGER" \
|
||||
", place_id INTEGER" \
|
||||
@ -72,17 +63,6 @@
|
||||
", session INTEGER" \
|
||||
")" \
|
||||
)
|
||||
#define CREATE_MOZ_HISTORYVISITS \
|
||||
CREATE_MOZ_HISTORYVISITS_BASE("moz_historyvisits", "")
|
||||
#define CREATE_MOZ_HISTORYVISITS_TEMP \
|
||||
CREATE_MOZ_HISTORYVISITS_BASE("moz_historyvisits_temp", "TEMP")
|
||||
#define CREATE_MOZ_HISTORYVISITS_VIEW NS_LITERAL_CSTRING( \
|
||||
"CREATE TEMPORARY VIEW moz_historyvisits_view AS " \
|
||||
"SELECT * FROM moz_historyvisits_temp " \
|
||||
"UNION ALL " \
|
||||
"SELECT * FROM moz_historyvisits " \
|
||||
"WHERE id NOT IN (SELECT id FROM moz_historyvisits_temp) " \
|
||||
)
|
||||
|
||||
#define CREATE_MOZ_INPUTHISTORY NS_LITERAL_CSTRING( \
|
||||
"CREATE TABLE moz_inputhistory (" \
|
||||
|
@ -39,6 +39,38 @@
|
||||
#ifndef __nsPlacesTriggers_h__
|
||||
#define __nsPlacesTriggers_h__
|
||||
|
||||
/**
|
||||
* Trigger increments the visit count by one for each inserted visit that isn't
|
||||
* an invalid transition, embedded transition, or a download transition.
|
||||
*/
|
||||
#define CREATE_VISIT_COUNT_INSERT_TRIGGER NS_LITERAL_CSTRING( \
|
||||
"CREATE TRIGGER moz_historyvisits_afterinsert_v1_trigger " \
|
||||
"AFTER INSERT ON moz_historyvisits FOR EACH ROW " \
|
||||
"WHEN NEW.visit_type NOT IN (0, 4, 7) " /* invalid, EMBED, DOWNLOAD */ \
|
||||
"BEGIN " \
|
||||
"UPDATE moz_places " \
|
||||
"SET visit_count = visit_count + 1 " \
|
||||
"WHERE moz_places.id = NEW.place_id; " \
|
||||
"END" \
|
||||
)
|
||||
|
||||
/**
|
||||
* Trigger decrements the visit count by one for each removed visit that isn't
|
||||
* an invalid transition, embeded transition, or a download transition. To be
|
||||
* safe, we ensure that the visit count will not fall below zero.
|
||||
*/
|
||||
#define CREATE_VISIT_COUNT_DELETE_TRIGGER NS_LITERAL_CSTRING( \
|
||||
"CREATE TRIGGER moz_historyvisits_afterdelete_v1_trigger " \
|
||||
"AFTER DELETE ON moz_historyvisits FOR EACH ROW " \
|
||||
"WHEN OLD.visit_type NOT IN (0, 4, 7) " /* invalid, EMBED, DOWNLOAD */ \
|
||||
"BEGIN " \
|
||||
"UPDATE moz_places " \
|
||||
"SET visit_count = visit_count - 1 " \
|
||||
"WHERE moz_places.id = OLD.place_id " \
|
||||
"AND visit_count > 0; " \
|
||||
"END" \
|
||||
)
|
||||
|
||||
/**
|
||||
* Trigger checks to ensure that at least one bookmark is still using a keyword
|
||||
* when any bookmark is deleted. If there are no more bookmarks using it, the
|
||||
@ -61,181 +93,4 @@
|
||||
"END" \
|
||||
)
|
||||
|
||||
/**
|
||||
* This trigger allows for an insertion into moz_places_view. It enters the new
|
||||
* data into the temporary table, ensuring that the new id is one greater than
|
||||
* the largest id value found.
|
||||
*/
|
||||
#define CREATE_PLACES_VIEW_INSERT_TRIGGER NS_LITERAL_CSTRING( \
|
||||
"CREATE TEMPORARY TRIGGER moz_places_view_insert_trigger " \
|
||||
"INSTEAD OF INSERT " \
|
||||
"ON moz_places_view " \
|
||||
"BEGIN " \
|
||||
"INSERT INTO moz_places_temp ( " \
|
||||
"id, url, title, rev_host, visit_count, hidden, typed, favicon_id, " \
|
||||
"frecency " \
|
||||
") " \
|
||||
"VALUES (MAX((SELECT IFNULL(MAX(id), 0) FROM moz_places_temp), " \
|
||||
"(SELECT IFNULL(MAX(id), 0) FROM moz_places)) + 1, " \
|
||||
"NEW.url, NEW.title, NEW.rev_host, " \
|
||||
"IFNULL(NEW.visit_count, 0), " /* enforce having a value */ \
|
||||
"NEW.hidden, NEW.typed, NEW.favicon_id, NEW.frecency);" \
|
||||
"END" \
|
||||
)
|
||||
|
||||
/**
|
||||
* This trigger allows for the deletion of a record in moz_places_view. It
|
||||
* removes any entry in the temporary table, and any entry in the permanent
|
||||
* table as well.
|
||||
*/
|
||||
#define CREATE_PLACES_VIEW_DELETE_TRIGGER NS_LITERAL_CSTRING( \
|
||||
"CREATE TEMPORARY TRIGGER moz_places_view_delete_trigger " \
|
||||
"INSTEAD OF DELETE " \
|
||||
"ON moz_places_view " \
|
||||
"BEGIN " \
|
||||
"DELETE FROM moz_places_temp " \
|
||||
"WHERE id = OLD.id; " \
|
||||
"DELETE FROM moz_places " \
|
||||
"WHERE id = OLD.id; " \
|
||||
"END" \
|
||||
)
|
||||
|
||||
/**
|
||||
* This trigger allows for updates to a record in moz_places_view. It first
|
||||
* copies the row from the permanent table over to the temp table if it does not
|
||||
* exist in the temporary table. Then, it will update the temporary table with
|
||||
* the new data.
|
||||
* We use INSERT OR IGNORE to avoid looking if the place already exists in the
|
||||
* temp table.
|
||||
*/
|
||||
#define CREATE_PLACES_VIEW_UPDATE_TRIGGER NS_LITERAL_CSTRING( \
|
||||
"CREATE TEMPORARY TRIGGER moz_places_view_update_trigger " \
|
||||
"INSTEAD OF UPDATE " \
|
||||
"ON moz_places_view " \
|
||||
"BEGIN " \
|
||||
"INSERT OR IGNORE INTO moz_places_temp " \
|
||||
"SELECT * " \
|
||||
"FROM moz_places " \
|
||||
"WHERE id = OLD.id; " \
|
||||
"UPDATE moz_places_temp " \
|
||||
"SET url = IFNULL(NEW.url, OLD.url), " \
|
||||
"title = IFNULL(NEW.title, OLD.title), " \
|
||||
"rev_host = IFNULL(NEW.rev_host, OLD.rev_host), " \
|
||||
"visit_count = IFNULL(NEW.visit_count, OLD.visit_count), " \
|
||||
"hidden = IFNULL(NEW.hidden, OLD.hidden), " \
|
||||
"typed = IFNULL(NEW.typed, OLD.typed), " \
|
||||
"favicon_id = IFNULL(NEW.favicon_id, OLD.favicon_id), " \
|
||||
"frecency = IFNULL(NEW.frecency, OLD.frecency) " \
|
||||
"WHERE id = OLD.id; " \
|
||||
"END" \
|
||||
)
|
||||
|
||||
/**
|
||||
* This trigger allows for an insertion into moz_historyvisits_view. It enters
|
||||
* the new data into the temporary table, ensuring that the new id is one
|
||||
* greater than the largest id value found. It then updates moz_places_view
|
||||
* with the new visit count.
|
||||
* We use INSERT OR IGNORE to avoid looking if the place already exists in the
|
||||
* temp table.
|
||||
*/
|
||||
#define CREATE_HISTORYVISITS_VIEW_INSERT_TRIGGER NS_LITERAL_CSTRING( \
|
||||
"CREATE TEMPORARY TRIGGER moz_historyvisits_view_insert_trigger " \
|
||||
"INSTEAD OF INSERT " \
|
||||
"ON moz_historyvisits_view " \
|
||||
"BEGIN " \
|
||||
"INSERT INTO moz_historyvisits_temp ( " \
|
||||
"id, from_visit, place_id, visit_date, visit_type, session " \
|
||||
") " \
|
||||
"VALUES (MAX((SELECT IFNULL(MAX(id), 0) FROM moz_historyvisits_temp), " \
|
||||
"(SELECT IFNULL(MAX(id), 0) FROM moz_historyvisits)) + 1, " \
|
||||
"NEW.from_visit, NEW.place_id, NEW.visit_date, NEW.visit_type, " \
|
||||
"NEW.session); " \
|
||||
"INSERT OR IGNORE INTO moz_places_temp " \
|
||||
"SELECT * " \
|
||||
"FROM moz_places " \
|
||||
"WHERE id = NEW.place_id; " \
|
||||
"UPDATE moz_places_temp " \
|
||||
"SET visit_count = visit_count + 1 " \
|
||||
"WHERE id = NEW.place_id " \
|
||||
"AND NEW.visit_type NOT IN (0, 4, 7); " /* invalid, EMBED, DOWNLOAD */ \
|
||||
"END" \
|
||||
)
|
||||
|
||||
/**
|
||||
* This trigger allows for the deletion of a record in moz_historyvisits_view.
|
||||
* It removes any entry in the temporary table, and removes any entry in the
|
||||
* permanent table as well. It then updates moz_places_view with the new visit
|
||||
* count.
|
||||
* We use INSERT OR IGNORE to avoid looking if the place already exists in the
|
||||
* temp table.
|
||||
*/
|
||||
#define CREATE_HISTORYVISITS_VIEW_DELETE_TRIGGER NS_LITERAL_CSTRING( \
|
||||
"CREATE TEMPORARY TRIGGER moz_historyvisits_view_delete_trigger " \
|
||||
"INSTEAD OF DELETE " \
|
||||
"ON moz_historyvisits_view " \
|
||||
"BEGIN " \
|
||||
"DELETE FROM moz_historyvisits_temp " \
|
||||
"WHERE id = OLD.id; " \
|
||||
"DELETE FROM moz_historyvisits " \
|
||||
"WHERE id = OLD.id; " \
|
||||
"INSERT OR IGNORE INTO moz_places_temp " \
|
||||
"SELECT * " \
|
||||
"FROM moz_places " \
|
||||
"WHERE id = OLD.place_id; " \
|
||||
"UPDATE moz_places_temp " \
|
||||
"SET visit_count = visit_count - 1 " \
|
||||
"WHERE id = OLD.place_id " \
|
||||
"AND OLD.visit_type NOT IN (0, 4, 7); " /* invalid, EMBED, DOWNLOAD */ \
|
||||
"END" \
|
||||
)
|
||||
|
||||
/**
|
||||
* This trigger allows for updates to a record in moz_historyvisits_view. It
|
||||
* first copies the row from the permanent table over to the temp table if it
|
||||
* does not exist in the temporary table. Then it will update the temporary
|
||||
* table with the new data.
|
||||
* We use INSERT OR IGNORE to avoid looking if the visit already exists in the
|
||||
* temp table.
|
||||
*/
|
||||
#define CREATE_HISTORYVISITS_VIEW_UPDATE_TRIGGER NS_LITERAL_CSTRING( \
|
||||
"CREATE TEMPORARY TRIGGER moz_historyvisits_view_update_trigger " \
|
||||
"INSTEAD OF UPDATE " \
|
||||
"ON moz_historyvisits_view " \
|
||||
"BEGIN " \
|
||||
"INSERT OR IGNORE INTO moz_historyvisits_temp " \
|
||||
"SELECT * " \
|
||||
"FROM moz_historyvisits " \
|
||||
"WHERE id = OLD.id; " \
|
||||
"UPDATE moz_historyvisits_temp " \
|
||||
"SET from_visit = IFNULL(NEW.from_visit, OLD.from_visit), " \
|
||||
"place_id = IFNULL(NEW.place_id, OLD.place_id), " \
|
||||
"visit_date = IFNULL(NEW.visit_date, OLD.visit_date), " \
|
||||
"visit_type = IFNULL(NEW.visit_type, OLD.visit_type), " \
|
||||
"session = IFNULL(NEW.session, OLD.session) " \
|
||||
"WHERE id = OLD.id; " \
|
||||
"END" \
|
||||
)
|
||||
|
||||
/**
|
||||
* This trigger moves the data out of a temporary table into the permanent one
|
||||
* before deleting from the temporary table.
|
||||
*
|
||||
* Note - it's OK to use an INSERT OR REPLACE here because the only conflict
|
||||
* that will happen is the primary key. As a result, the row will be deleted,
|
||||
* and the replacement will be inserted with the same id.
|
||||
*/
|
||||
#define CREATE_TEMP_SYNC_TRIGGER_BASE(__table) NS_LITERAL_CSTRING( \
|
||||
"CREATE TEMPORARY TRIGGER " __table "_beforedelete_trigger " \
|
||||
"BEFORE DELETE ON " __table "_temp FOR EACH ROW " \
|
||||
"BEGIN " \
|
||||
"INSERT OR REPLACE INTO " __table " " \
|
||||
"SELECT * FROM " __table "_temp " \
|
||||
"WHERE id = OLD.id;" \
|
||||
"END" \
|
||||
)
|
||||
#define CREATE_MOZ_PLACES_SYNC_TRIGGER \
|
||||
CREATE_TEMP_SYNC_TRIGGER_BASE("moz_places")
|
||||
#define CREATE_MOZ_HISTORYVISITS_SYNC_TRIGGER \
|
||||
CREATE_TEMP_SYNC_TRIGGER_BASE("moz_historyvisits")
|
||||
|
||||
#endif // __nsPlacesTriggers_h__
|
||||
|
@ -1,275 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Places.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Google Inc.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
* Dietrich Ayala <dietrich@mozilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
|
||||
const NS_APP_HISTORY_50_FILE = "UHist";
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
const Cr = Components.results;
|
||||
|
||||
function LOG(aMsg) {
|
||||
aMsg = ("*** PLACES TESTS: " + aMsg);
|
||||
Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).
|
||||
logStringMessage(aMsg);
|
||||
print(aMsg);
|
||||
}
|
||||
|
||||
// If there's no location registered for the profile direcotry, register one now.
|
||||
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
|
||||
var profileDir = null;
|
||||
try {
|
||||
profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
|
||||
} catch (e) {}
|
||||
if (!profileDir) {
|
||||
// Register our own provider for the profile directory.
|
||||
// It will simply return the current directory.
|
||||
var provider = {
|
||||
getFile: function(prop, persistent) {
|
||||
persistent.value = true;
|
||||
if (prop == NS_APP_USER_PROFILE_50_DIR) {
|
||||
return dirSvc.get("CurProcD", Ci.nsIFile);
|
||||
}
|
||||
if (prop == NS_APP_HISTORY_50_FILE) {
|
||||
var histFile = dirSvc.get("CurProcD", Ci.nsIFile);
|
||||
histFile.append("history.dat");
|
||||
return histFile;
|
||||
}
|
||||
throw Cr.NS_ERROR_FAILURE;
|
||||
},
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
|
||||
iid.equals(Ci.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
|
||||
}
|
||||
|
||||
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||
|
||||
function uri(spec) {
|
||||
return iosvc.newURI(spec, null, null);
|
||||
}
|
||||
|
||||
// Delete a previously created sqlite file
|
||||
function clearDB() {
|
||||
try {
|
||||
var file = dirSvc.get('ProfD', Ci.nsIFile);
|
||||
file.append("places.sqlite");
|
||||
if (file.exists())
|
||||
file.remove(false);
|
||||
} catch(ex) { dump("Exception: " + ex); }
|
||||
}
|
||||
clearDB();
|
||||
|
||||
/**
|
||||
* Dumps the rows of a table out to the console.
|
||||
*
|
||||
* @param aName
|
||||
* The name of the table or view to output.
|
||||
*/
|
||||
function dump_table(aName)
|
||||
{
|
||||
let db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
let stmt = db.createStatement("SELECT * FROM " + aName);
|
||||
|
||||
dump("\n*** Printing data from " + aName + ":\n");
|
||||
let count = 0;
|
||||
while (stmt.executeStep()) {
|
||||
let columns = stmt.numEntries;
|
||||
|
||||
if (count == 0) {
|
||||
// print the column names
|
||||
for (let i = 0; i < columns; i++)
|
||||
dump(stmt.getColumnName(i) + "\t");
|
||||
dump("\n");
|
||||
}
|
||||
|
||||
// print the row
|
||||
for (let i = 0; i < columns; i++) {
|
||||
switch (stmt.getTypeOfIndex(i)) {
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_NULL:
|
||||
dump("NULL\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_INTEGER:
|
||||
dump(stmt.getInt64(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_FLOAT:
|
||||
dump(stmt.getDouble(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_TEXT:
|
||||
dump(stmt.getString(i) + "\t");
|
||||
break;
|
||||
}
|
||||
}
|
||||
dump("\n");
|
||||
|
||||
count++;
|
||||
}
|
||||
dump("*** There were a total of " + count + " rows of data.\n\n");
|
||||
|
||||
stmt.reset();
|
||||
stmt.finalize();
|
||||
stmt = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This dispatches the observer topic "quit-application" to clean up the
|
||||
* background thread.
|
||||
*/
|
||||
function finish_test()
|
||||
{
|
||||
// This next bit needs to run on the main thread
|
||||
let tm = Cc["@mozilla.org/thread-manager;1"].
|
||||
getService(Ci.nsIThreadManager);
|
||||
tm.mainThread.dispatch({
|
||||
run: function()
|
||||
{
|
||||
// xpcshell doesn't dispatch shutdown-application
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
os.notifyObservers(null, "quit-application", null);
|
||||
do_test_finished();
|
||||
}
|
||||
}, Ci.nsIEventTarget.DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function tests to see if the place associated with the bookmark with id
|
||||
* aBookmarkId has the uri aExpectedURI. The event will call finish_test() if
|
||||
* aFinish is true.
|
||||
*
|
||||
* @param aBookmarkId
|
||||
* The bookmark to check against.
|
||||
* @param aExpectedURI
|
||||
* The URI we expect to be in moz_places.
|
||||
* @param aExpected
|
||||
* Indicates if we expect to get a result or not.
|
||||
* @param [optional] aFinish
|
||||
* Indicates if the test should be completed or not.
|
||||
*/
|
||||
function new_test_bookmark_uri_event(aBookmarkId, aExpectedURI, aExpected, aFinish)
|
||||
{
|
||||
return {
|
||||
run: function()
|
||||
{
|
||||
let db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
let stmt = db.createStatement(
|
||||
"SELECT moz_places.url " +
|
||||
"FROM moz_bookmarks INNER JOIN moz_places " +
|
||||
"ON moz_bookmarks.fk = moz_places.id " +
|
||||
"WHERE moz_bookmarks.id = ?1"
|
||||
);
|
||||
stmt.bindInt64Parameter(0, aBookmarkId);
|
||||
|
||||
if (aExpected) {
|
||||
do_check_true(stmt.executeStep());
|
||||
do_check_eq(stmt.getUTF8String(0), aExpectedURI);
|
||||
}
|
||||
else {
|
||||
do_check_false(stmt.executeStep());
|
||||
}
|
||||
stmt.reset();
|
||||
stmt.finalize();
|
||||
stmt = null;
|
||||
|
||||
if (aFinish)
|
||||
finish_test();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Function tests to see if the place associated with the visit with id aVisitId
|
||||
* has the uri aExpectedURI. The event will call finish_test() if aFinish is
|
||||
* true.
|
||||
*
|
||||
* @param aVisitId
|
||||
* The visit to check against.
|
||||
* @param aExpectedURI
|
||||
* The URI we expect to be in moz_places.
|
||||
* @param aExpected
|
||||
* Indicates if we expect to get a result or not.
|
||||
* @param [optional] aFinish
|
||||
* Indicates if the test should be completed or not.
|
||||
*/
|
||||
function new_test_visit_uri_event(aVisitId, aExpectedURI, aExpected, aFinish)
|
||||
{
|
||||
return {
|
||||
run: function()
|
||||
{
|
||||
let db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
let stmt = db.createStatement(
|
||||
"SELECT moz_places.url " +
|
||||
"FROM moz_historyvisits INNER JOIN moz_places " +
|
||||
"ON moz_historyvisits.place_id = moz_places.id " +
|
||||
"WHERE moz_historyvisits.id = ?1"
|
||||
);
|
||||
stmt.bindInt64Parameter(0, aVisitId);
|
||||
|
||||
if (aExpected) {
|
||||
do_check_true(stmt.executeStep());
|
||||
do_check_eq(stmt.getUTF8String(0), aExpectedURI);
|
||||
}
|
||||
else {
|
||||
do_check_false(stmt.executeStep());
|
||||
}
|
||||
stmt.reset();
|
||||
stmt.finalize();
|
||||
stmt = null;
|
||||
|
||||
if (aFinish)
|
||||
finish_test();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// profile-after-change doesn't create components in xpcshell, so we have to do
|
||||
// it ourselves
|
||||
Cc["@mozilla.org/places/sync;1"].getService(Ci.nsISupports);
|
||||
|
@ -39,6 +39,10 @@
|
||||
|
||||
Components.utils.import("resource://gre/modules/PlacesBackground.jsm");
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const Cr = Components.results;
|
||||
|
||||
function test_service_exists()
|
||||
{
|
||||
do_check_neq(PlacesBackground, null);
|
||||
@ -83,32 +87,10 @@ function test_two_events_same_thread()
|
||||
do_check_eq(event.thread1, event.thread2);
|
||||
}
|
||||
|
||||
function test_places_background_shutdown_topic()
|
||||
{
|
||||
// Ensures that the places shutdown topic is dispatched before the thread is
|
||||
// shutdown.
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
os.addObserver({
|
||||
observe: function(aSubject, aTopic, aData)
|
||||
{
|
||||
// We should still be able to dispatch an event without throwing now!
|
||||
PlacesBackground.dispatch({
|
||||
run: function()
|
||||
{
|
||||
do_test_finished();
|
||||
}
|
||||
}, Ci.nsIEventTarget.DISPATCH_NORMAL);
|
||||
}
|
||||
}, "places-background-shutdown", false);
|
||||
do_test_pending();
|
||||
}
|
||||
|
||||
let tests = [
|
||||
test_service_exists,
|
||||
test_isOnCurrentThread,
|
||||
test_two_events_same_thread,
|
||||
test_places_background_shutdown_topic,
|
||||
];
|
||||
|
||||
function run_test()
|
||||
|
@ -1,55 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=2 sts=2 expandtab
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Shawn Wilsher <me@shawnwilsher.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
Components.utils.import("resource://gre/modules/PlacesBackground.jsm");
|
||||
|
||||
const TEST_URI = "http://test.com/";
|
||||
|
||||
function run_test()
|
||||
{
|
||||
// First insert it
|
||||
let bh = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
let id = bh.insertBookmark(bh.unfiledBookmarksFolder, uri(TEST_URI),
|
||||
bh.DEFAULT_INDEX, "test");
|
||||
|
||||
PlacesBackground.dispatch(new_test_bookmark_uri_event(id, TEST_URI, true, true),
|
||||
Ci.nsIEventTarget.DISPATCH_NORMAL);
|
||||
do_test_pending();
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=2 sts=2 expandtab
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Shawn Wilsher <me@shawnwilsher.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
Components.utils.import("resource://gre/modules/PlacesBackground.jsm");
|
||||
|
||||
const TEST_URI = "http://test.com/";
|
||||
|
||||
function run_test()
|
||||
{
|
||||
// First insert it
|
||||
let bh = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
let id = null;
|
||||
bh.runInBatchMode({
|
||||
runBatched: function(aUserData)
|
||||
{
|
||||
id = bh.insertBookmark(bh.unfiledBookmarksFolder, uri(TEST_URI),
|
||||
bh.DEFAULT_INDEX, "test");
|
||||
|
||||
PlacesBackground.dispatch(new_test_bookmark_uri_event(id, TEST_URI, false),
|
||||
Ci.nsIEventTarget.DISPATCH_SYNC);
|
||||
}
|
||||
}, null);
|
||||
do_check_neq(id, null);
|
||||
PlacesBackground.dispatch(new_test_bookmark_uri_event(id, TEST_URI, true, true),
|
||||
Ci.nsIEventTarget.DISPATCH_NORMAL);
|
||||
do_test_pending();
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=2 sts=2 expandtab
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Shawn Wilsher <me@shawnwilsher.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
Components.utils.import("resource://gre/modules/PlacesBackground.jsm");
|
||||
|
||||
const TEST_URI = "http://test.com/";
|
||||
const kSyncPrefName = "syncDBTableIntervalInSecs";
|
||||
const SYNC_INTERVAL = 1;
|
||||
|
||||
function run_test()
|
||||
{
|
||||
// First set the preference for the timer to a small value
|
||||
let prefs = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefService).
|
||||
getBranch("places.");
|
||||
prefs.setIntPref(kSyncPrefName, SYNC_INTERVAL);
|
||||
|
||||
// Now add the visit
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
let id = hs.addVisit(uri(TEST_URI), Date.now() * 1000, null,
|
||||
hs.TRANSITION_TYPED, false, 0);
|
||||
|
||||
// Check the visit, but after enough time has passed for the DB flush service
|
||||
// to have fired it's timer.
|
||||
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||
timer.initWithCallback({
|
||||
notify: function(aTimer)
|
||||
{
|
||||
PlacesBackground.dispatch(new_test_visit_uri_event(id, TEST_URI, true, true),
|
||||
Ci.nsIEventTarget.DISPATCH_NORMAL);
|
||||
}
|
||||
}, (SYNC_INTERVAL * 1000) * 2, Ci.nsITimer.TYPE_ONE_SHOT);
|
||||
do_test_pending();
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=2 sts=2 expandtab
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Shawn Wilsher <me@shawnwilsher.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
Components.utils.import("resource://gre/modules/PlacesBackground.jsm");
|
||||
|
||||
const TEST_URI = "http://test.com/";
|
||||
|
||||
function run_test()
|
||||
{
|
||||
// Now add the visit in batch mode
|
||||
let bh = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
let id = null;
|
||||
bh.runInBatchMode({
|
||||
runBatched: function(aUserData)
|
||||
{
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
|
||||
id = hs.addVisit(uri(TEST_URI), Date.now() * 1000, null,
|
||||
hs.TRANSITION_TYPED, false, 0);
|
||||
PlacesBackground.dispatch(new_test_visit_uri_event(id, TEST_URI, false),
|
||||
Ci.nsIEventTarget.DISPATCH_SYNC);
|
||||
}
|
||||
}, null);
|
||||
do_check_neq(id, null);
|
||||
PlacesBackground.dispatch(new_test_visit_uri_event(id, TEST_URI, true, true),
|
||||
Ci.nsIEventTarget.DISPATCH_NORMAL);
|
||||
do_test_pending();
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=2 sts=2 expandtab
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Shawn Wilsher <me@shawnwilsher.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
Components.utils.import("resource://gre/modules/PlacesBackground.jsm");
|
||||
|
||||
const TEST_URI = "http://test.com/";
|
||||
const MODIFIED_URI = "http://test.com/index.html";
|
||||
|
||||
function run_test()
|
||||
{
|
||||
// First insert it
|
||||
let bh = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
let id = bh.insertBookmark(bh.unfiledBookmarksFolder, uri(TEST_URI),
|
||||
bh.DEFAULT_INDEX, "test");
|
||||
|
||||
// Dispatch the check synchronously so we don't modify the data before this
|
||||
// test runs
|
||||
PlacesBackground.dispatch(new_test_bookmark_uri_event(id, TEST_URI, true),
|
||||
Ci.nsIEventTarget.DISPATCH_SYNC);
|
||||
|
||||
// Now modify the bookmark
|
||||
bh.changeBookmarkURI(id, uri(MODIFIED_URI));
|
||||
|
||||
PlacesBackground.dispatch(new_test_bookmark_uri_event(id, MODIFIED_URI, true, true),
|
||||
Ci.nsIEventTarget.DISPATCH_NORMAL);
|
||||
do_test_pending();
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=2 sts=2 expandtab
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Shawn Wilsher <me@shawnwilsher.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
Components.utils.import("resource://gre/modules/PlacesBackground.jsm");
|
||||
|
||||
const TEST_URI = "http://test.com/";
|
||||
const kSyncPrefName = "syncDBTableIntervalInSecs";
|
||||
const SYNC_INTERVAL = 600; // ten minutes
|
||||
|
||||
function run_test()
|
||||
{
|
||||
// First set the preference for the timer to a really large value so it won't
|
||||
// run before the test finishes.
|
||||
let prefs = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefService).
|
||||
getBranch("places.");
|
||||
prefs.setIntPref(kSyncPrefName, SYNC_INTERVAL);
|
||||
|
||||
// Now add the visit
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
let id = hs.addVisit(uri(TEST_URI), Date.now() * 1000, null,
|
||||
hs.TRANSITION_TYPED, false, 0);
|
||||
|
||||
// Notify that we are quitting the app - we should sync!
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
os.notifyObservers(null, "quit-application", null);
|
||||
|
||||
// Check the visit. The background thread should have joined with the main
|
||||
// thread by now if everything is working correctly.
|
||||
new_test_visit_uri_event(id, TEST_URI, true, false).run();
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=2 sts=2 expandtab
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Shawn Wilsher <me@shawnwilsher.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* This test ensures that adding a bookmark (which has an implicit sync), then
|
||||
* adding another one that has the same place, we end up with only one entry in
|
||||
* moz_places.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/PlacesBackground.jsm");
|
||||
|
||||
const TEST_URI = "http://test.com/";
|
||||
|
||||
let db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
|
||||
function run_test()
|
||||
{
|
||||
// Add the first bookmark
|
||||
let bh = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
let id1 = bh.insertBookmark(bh.unfiledBookmarksFolder, uri(TEST_URI),
|
||||
bh.DEFAULT_INDEX, "test");
|
||||
|
||||
// Ensure it was added
|
||||
PlacesBackground.dispatch(new_test_bookmark_uri_event(id1, TEST_URI, true),
|
||||
Ci.nsIEventTarget.DISPATCH_SYNC);
|
||||
|
||||
// Get the place_id
|
||||
let stmt = db.createStatement(
|
||||
"SELECT fk " +
|
||||
"FROM moz_bookmarks " +
|
||||
"WHERE id = ?"
|
||||
);
|
||||
stmt.bindInt64Parameter(0, id1);
|
||||
do_check_true(stmt.executeStep());
|
||||
let place_id = stmt.getInt64(0);
|
||||
stmt.finalize();
|
||||
stmt = null;
|
||||
|
||||
// Now we add another bookmark to a different folder
|
||||
let id2 = bh.insertBookmark(bh.toolbarFolder, uri(TEST_URI),
|
||||
bh.DEFAULT_INDEX, "test");
|
||||
do_check_neq(id1, id2);
|
||||
|
||||
// Ensure it was added
|
||||
PlacesBackground.dispatch(new_test_bookmark_uri_event(id2, TEST_URI, true),
|
||||
Ci.nsIEventTarget.DISPATCH_SYNC);
|
||||
|
||||
// Check to make sure we have the same place_id
|
||||
stmt = db.createStatement(
|
||||
"SELECT * " +
|
||||
"FROM moz_bookmarks " +
|
||||
"WHERE id = ?1 " +
|
||||
"AND fk = ?2"
|
||||
);
|
||||
stmt.bindInt64Parameter(0, id2);
|
||||
stmt.bindInt64Parameter(1, place_id);
|
||||
do_check_true(stmt.executeStep());
|
||||
stmt.finalize();
|
||||
stmt = null;
|
||||
|
||||
// finish_test() calls do_test_finished, so we call do_test_pending()...
|
||||
do_test_pending();
|
||||
finish_test();
|
||||
}
|
@ -1,127 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=2 sts=2 expandtab
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Shawn Wilsher <me@shawnwilsher.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* This test ensures that when adding a visit, then syncing, and adding another
|
||||
* visit to the same url creates two visits and that we only end up with one
|
||||
* entry in moz_places.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/PlacesBackground.jsm");
|
||||
|
||||
const TEST_URI = "http://test.com/";
|
||||
const kSyncPrefName = "syncDBTableIntervalInSecs";
|
||||
const SYNC_INTERVAL = 1;
|
||||
|
||||
function run_test()
|
||||
{
|
||||
// First set the preference for the timer to a small value
|
||||
let prefs = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefService).
|
||||
getBranch("places.");
|
||||
prefs.setIntPref(kSyncPrefName, SYNC_INTERVAL);
|
||||
|
||||
// Now add the first visit
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
let id = hs.addVisit(uri(TEST_URI), Date.now() * 1000, null,
|
||||
hs.TRANSITION_TYPED, false, 0);
|
||||
|
||||
// Check the visit, but after enough time has passed for the DB flush service
|
||||
// to have fired it's timer.
|
||||
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||
timer.initWithCallback({
|
||||
notify: function(aTimer)
|
||||
{
|
||||
PlacesBackground.dispatch(new_test_visit_uri_event(id, TEST_URI, true),
|
||||
Ci.nsIEventTarget.DISPATCH_SYNC);
|
||||
|
||||
// Get the place_id and pass it on
|
||||
let db = hs.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
|
||||
let stmt = db.createStatement(
|
||||
"SELECT place_id " +
|
||||
"FROM moz_historyvisits " +
|
||||
"WHERE id = ?"
|
||||
);
|
||||
stmt.bindInt64Parameter(0, id);
|
||||
do_check_true(stmt.executeStep());
|
||||
continue_test(id, stmt.getInt64(0));
|
||||
stmt.finalize();
|
||||
stmt = null;
|
||||
}
|
||||
}, (SYNC_INTERVAL * 1000) * 2, Ci.nsITimer.TYPE_ONE_SHOT);
|
||||
do_test_pending();
|
||||
}
|
||||
|
||||
function continue_test(aLastVisitId, aPlaceId)
|
||||
{
|
||||
// Now we add another visit
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
let id = hs.addVisit(uri(TEST_URI), Date.now() * 1000, null,
|
||||
hs.TRANSITION_TYPED, false, 0);
|
||||
do_check_neq(aLastVisitId, id);
|
||||
|
||||
// Check the visit, but after enough time has passed for the DB flush service
|
||||
// to have fired it's timer.
|
||||
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||
timer.initWithCallback({
|
||||
notify: function(aTimer)
|
||||
{
|
||||
PlacesBackground.dispatch(new_test_visit_uri_event(id, TEST_URI, true),
|
||||
Ci.nsIEventTarget.DISPATCH_SYNC);
|
||||
|
||||
// Check to make sure we have the same place_id
|
||||
let db = hs.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
|
||||
let stmt = db.createStatement(
|
||||
"SELECT * " +
|
||||
"FROM moz_historyvisits " +
|
||||
"WHERE id = ?1 " +
|
||||
"AND place_id = ?2"
|
||||
);
|
||||
stmt.bindInt64Parameter(0, id);
|
||||
stmt.bindInt64Parameter(1, aPlaceId);
|
||||
do_check_true(stmt.executeStep());
|
||||
stmt.finalize();
|
||||
stmt = null;
|
||||
|
||||
finish_test();
|
||||
}
|
||||
}, (SYNC_INTERVAL * 1000) * 2, Ci.nsITimer.TYPE_ONE_SHOT);
|
||||
}
|
@ -163,11 +163,11 @@ function checkDBOnTimeout() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
|
||||
// Get all pages visited from the original typed one
|
||||
var sql = "SELECT url FROM moz_historyvisits_view " +
|
||||
"JOIN moz_places_view h ON h.id = place_id " +
|
||||
var sql = "SELECT url FROM moz_historyvisits " +
|
||||
"JOIN moz_places h ON h.id = place_id " +
|
||||
"WHERE from_visit IN " +
|
||||
"(SELECT v.id FROM moz_historyvisits_view v " +
|
||||
"JOIN moz_places_view p ON p.id = v.place_id " +
|
||||
"(SELECT v.id FROM moz_historyvisits v " +
|
||||
"JOIN moz_places p ON p.id = v.place_id " +
|
||||
"WHERE p.url = ?1)";
|
||||
var stmt = mDBConn.createStatement(sql);
|
||||
stmt.bindUTF8StringParameter(0, typedURI.spec);
|
||||
|
@ -41,8 +41,6 @@
|
||||
// Get history service
|
||||
try {
|
||||
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
|
||||
var gh = Cc["@mozilla.org/browser/global-history;2"].
|
||||
getService(Ci.nsIGlobalHistory2);
|
||||
} catch(ex) {
|
||||
do_throw("Could not get history service\n");
|
||||
}
|
||||
@ -63,9 +61,7 @@ function add_visit(aURI, aReferrer) {
|
||||
histsvc.TRANSITION_TYPED, // user typed in URL bar
|
||||
false, // not redirect
|
||||
0);
|
||||
dump("### Added visit with id of " + placeID + "\n");
|
||||
do_check_true(placeID > 0);
|
||||
do_check_true(gh.isVisited(aURI));
|
||||
return placeID;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user