Bug Summary

File:root/firefox-clang/obj-x86_64-pc-linux-gnu/toolkit/components/places/./../../../../toolkit/components/places/Database.cpp
Warning:line 956, column 12
Value stored to 'rv' during its initialization is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Unified_cpp_components_places0.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/toolkit/components/places -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/toolkit/components/places -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -D _GLIBCXX_ASSERTIONS=1 -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D MOZ_SUPPORT_LEAKCHECKING -D STATIC_EXPORTABLE_JS_API -I /root/firefox-clang/toolkit/components/places -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/toolkit/components/places -I /root/firefox-clang/toolkit/components/build -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /root/firefox-clang/ipc/chromium/src -I /root/firefox-clang/third_party/abseil-cpp -I /root/firefox-clang/toolkit/components/telemetry -I /root/firefox-clang/xpcom/base -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/x86_64-linux-gnu/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16/backward -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=pessimizing-move -Wno-error=large-by-value-copy=128 -Wno-error=implicit-int-float-conversion -Wno-error=thread-safety-analysis -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -Wno-character-conversion -std=gnu++20 -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fno-sized-deallocation -fno-aligned-allocation -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-09-01-224014-2642839-1 -x c++ Unified_cpp_components_places0.cpp
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5#include "mozilla/DebugOnly.h"
6#include "mozilla/ScopeExit.h"
7#include "mozilla/SpinEventLoopUntil.h"
8#include "mozilla/StaticPrefs_places.h"
9#include "mozilla/StaticPrefs_security.h"
10#include "mozilla/glean/PlacesMetrics.h"
11#include "mozilla/storage/SQLiteEncryption.h"
12#include "mozilla/storage/StoragePathUtil.h"
13
14#include "Database.h"
15
16#include "nsIInterfaceRequestorUtils.h"
17#include "nsIFile.h"
18
19#include "nsLocalFile.h"
20#include "nsNavBookmarks.h"
21#include "nsNavHistory.h"
22#include "nsPlacesTables.h"
23#include "nsPlacesIndexes.h"
24#include "nsPlacesTriggers.h"
25#include "nsPlacesMacros.h"
26#include "nsVariant.h"
27#include "SQLFunctions.h"
28#include "ScopedNSSTypes.h"
29#include "Helpers.h"
30#include "nsFaviconService.h"
31
32#include "nsAppDirectoryServiceDefs.h"
33#include "nsDirectoryServiceUtils.h"
34#include "prenv.h"
35#include "prsystem.h"
36#include "nsPrintfCString.h"
37#include "mozilla/Components.h"
38#include "mozilla/Preferences.h"
39#include "mozilla/Services.h"
40#include "mozIStorageService.h"
41#include "prtime.h"
42
43#include "nsXULAppAPI.h"
44
45// Time between corrupt database backups.
46#define RECENT_BACKUP_TIME_MICROSEC(int64_t)86400 * 1000000L (int64_t)86400 * PR_USEC_PER_SEC1000000L // 24H
47
48// Set to the database file name when it was found corrupt by a previous
49// maintenance run.
50#define PREF_FORCE_DATABASE_REPLACEMENT"places.database.replaceDatabaseOnStartup" \
51 "places.database.replaceDatabaseOnStartup"
52
53// Whether on corruption we should try to fix the database by cloning it.
54#define PREF_DATABASE_CLONEONCORRUPTION"places.database.cloneOnCorruption" "places.database.cloneOnCorruption"
55
56#define PREF_DATABASE_FAVICONS_LASTCORRUPTION"places.database.lastFaviconsCorruptionInDaysFromEpoch" \
57 "places.database.lastFaviconsCorruptionInDaysFromEpoch"
58#define PREF_DATABASE_PLACES_LASTCORRUPTION"places.database.lastPlacesCorruptionInDaysFromEpoch" \
59 "places.database.lastPlacesCorruptionInDaysFromEpoch"
60
61// Set to specify the size of the places database growth increments in kibibytes
62#define PREF_GROWTH_INCREMENT_KIB"places.database.growthIncrementKiB" "places.database.growthIncrementKiB"
63
64// Set to disable the default robust storage and use volatile, in-memory
65// storage without robust transaction flushing guarantees. This makes
66// SQLite use much less I/O at the cost of losing data when things crash.
67// The pref is only honored if an environment variable is set. The env
68// variable is intentionally named something scary to help prevent someone
69// from thinking it is a useful performance optimization they should enable.
70#define PREF_DISABLE_DURABILITY"places.database.disableDurability" "places.database.disableDurability"
71
72#define PREF_PREVIEWS_ENABLED"places.previews.enabled" "places.previews.enabled"
73
74#define ENV_ALLOW_CORRUPTION"ALLOW_PLACES_DATABASE_TO_LOSE_DATA_AND_BECOME_CORRUPT" \
75 "ALLOW_PLACES_DATABASE_TO_LOSE_DATA_AND_BECOME_CORRUPT"
76
77// Maximum size for the WAL file.
78// For performance reasons this should be as large as possible, so that more
79// transactions can fit into it, and the checkpoint cost is paid less often.
80// At the same time, since we use synchronous = NORMAL, an fsync happens only
81// at checkpoint time, so we don't want the WAL to grow too much and risk to
82// lose all the contained transactions on a crash.
83#define DATABASE_MAX_WAL_BYTES2048000 2048000
84
85// Since exceeding the journal limit will cause a truncate, we allow a slightly
86// larger limit than DATABASE_MAX_WAL_BYTES to reduce the number of truncates.
87// This is the number of bytes the journal can grow over the maximum wal size
88// before being truncated.
89#define DATABASE_JOURNAL_OVERHEAD_BYTES2048000 2048000
90
91#define BYTES_PER_KIBIBYTE1024 1024
92
93// This annotation is no longer used & is obsolete, but here for migration.
94#define LAST_USED_ANNO"bookmarkPropertiesDialog/folderLastUsed"_ns "bookmarkPropertiesDialog/folderLastUsed"_ns
95// This is key in the meta table that the LAST_USED_ANNO is migrated to.
96#define LAST_USED_FOLDERS_META_KEY"places/bookmarks/edit/lastusedfolder"_ns "places/bookmarks/edit/lastusedfolder"_ns
97
98// We use a fixed title for the mobile root to avoid marking the database as
99// corrupt if we can't look up the localized title in the string bundle. Sync
100// sets the title to the localized version when it creates the left pane query.
101#define MOBILE_ROOT_TITLE"mobile" "mobile"
102
103// Legacy item annotation used by the old Sync engine.
104#define SYNC_PARENT_ANNO"sync/parent" "sync/parent"
105
106#define USEC_PER_DAY86400000000LL 86400000000LL
107
108using namespace mozilla;
109
110namespace mozilla::places {
111
112namespace {
113
114////////////////////////////////////////////////////////////////////////////////
115//// Helpers
116
117/**
118 * Get the filename for a corrupt database.
119 */
120nsString getCorruptFilename(const nsString& aDbFilename) {
121 return aDbFilename + u".corrupt"_ns;
122}
123/**
124 * Get the filename for a recover database.
125 */
126nsString getRecoverFilename(const nsString& aDbFilename) {
127 return aDbFilename + u".recover"_ns;
128}
129
130/**
131 * Checks whether exists a corrupt database file created not longer than
132 * RECENT_BACKUP_TIME_MICROSEC ago.
133 */
134bool isRecentCorruptFile(const nsCOMPtr<nsIFile>& aCorruptFile) {
135 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../../toolkit/components/places/Database.cpp", 135
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { MOZ_CrashSequence(__null, 135); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
136 bool fileExists = false;
137 if (NS_FAILED(aCorruptFile->Exists(&fileExists))((bool)(__builtin_expect(!!(NS_FAILED_impl(aCorruptFile->Exists
(&fileExists))), 0)))
|| !fileExists) {
138 return false;
139 }
140 PRTime lastMod = 0;
141 return NS_SUCCEEDED(aCorruptFile->GetLastModifiedTime(&lastMod))((bool)(__builtin_expect(!!(!NS_FAILED_impl(aCorruptFile->
GetLastModifiedTime(&lastMod))), 1)))
&&
142 lastMod > 0 && (PR_Now() - lastMod) <= RECENT_BACKUP_TIME_MICROSEC(int64_t)86400 * 1000000L;
143}
144
145// Defines the stages in the process of replacing a corrupt database.
146enum eCorruptDBReplaceStage : int8_t {
147 stage_closing = 0,
148 stage_removing,
149 stage_reopening,
150 stage_replaced,
151 stage_cloning,
152 stage_cloned,
153 stage_count
154};
155
156/**
157 * Maps a database replacement stage (eCorruptDBReplaceStage) to its string
158 * representation.
159 */
160static constexpr nsLiteralCString sCorruptDBStages[stage_count] = {
161 "stage_closing"_ns, "stage_removing"_ns, "stage_reopening"_ns,
162 "stage_replaced"_ns, "stage_cloning"_ns, "stage_cloned"_ns};
163
164/**
165 * Removes a file, optionally adding a suffix to the file name.
166 */
167void RemoveFileSwallowsErrors(const nsCOMPtr<nsIFile>& aFile,
168 const nsString& aSuffix = u""_ns) {
169 nsCOMPtr<nsIFile> file;
170 MOZ_ALWAYS_SUCCEEDS(aFile->Clone(getter_AddRefs(file)))do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(aFile->Clone(getter_AddRefs(file)))), 1)))), 1))) { } else
{ do { do { } while (false); MOZ_ReportCrash("" "NS_SUCCEEDED(aFile->Clone(getter_AddRefs(file)))"
, "./../../../../toolkit/components/places/Database.cpp", 170
); AnnotateMozCrashReason("MOZ_CRASH(" "NS_SUCCEEDED(aFile->Clone(getter_AddRefs(file)))"
")"); do { MOZ_CrashSequence(__null, 170); __attribute__((nomerge
)) ::abort(); } while (false); } while (false); } } while (false
)
;
171 if (!aSuffix.IsEmpty()) {
172 nsAutoString newFileName;
173 file->GetLeafName(newFileName);
174 newFileName.Append(aSuffix);
175 MOZ_ALWAYS_SUCCEEDS(file->SetLeafName(newFileName))do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(file->SetLeafName(newFileName))), 1)))), 1))) { } else { do
{ do { } while (false); MOZ_ReportCrash("" "NS_SUCCEEDED(file->SetLeafName(newFileName))"
, "./../../../../toolkit/components/places/Database.cpp", 175
); AnnotateMozCrashReason("MOZ_CRASH(" "NS_SUCCEEDED(file->SetLeafName(newFileName))"
")"); do { MOZ_CrashSequence(__null, 175); __attribute__((nomerge
)) ::abort(); } while (false); } while (false); } } while (false
)
;
176 }
177 DebugOnly<nsresult> rv = file->Remove(false);
178 NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to remove file.")do { if (!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1
))))) { NS_DebugBreak(NS_DEBUG_WARNING, "Failed to remove file."
, "NS_SUCCEEDED(rv)", "./../../../../toolkit/components/places/Database.cpp"
, 178); } } while (false)
;
179}
180
181/**
182 * Sets the connection journal mode to one of the JOURNAL_* types.
183 *
184 * @param aDBConn
185 * The database connection.
186 * @param aJournalMode
187 * One of the JOURNAL_* types.
188 * @returns the current journal mode.
189 * @note this may return a different journal mode than the required one, since
190 * setting it may fail.
191 */
192enum JournalMode SetJournalMode(nsCOMPtr<mozIStorageConnection>& aDBConn,
193 enum JournalMode aJournalMode) {
194 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../../toolkit/components/places/Database.cpp", 194
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { MOZ_CrashSequence(__null, 194); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
195 nsAutoCString journalMode;
196 switch (aJournalMode) {
197 default:
198 MOZ_FALLTHROUGH_ASSERT("Trying to set an unknown journal mode.")do { do { } while (false); MOZ_ReportCrash("" "MOZ_FALLTHROUGH_ASSERT: "
"Trying to set an unknown journal mode.", "./../../../../toolkit/components/places/Database.cpp"
, 198); AnnotateMozCrashReason("MOZ_CRASH(" "MOZ_FALLTHROUGH_ASSERT: "
"Trying to set an unknown journal mode." ")"); do { MOZ_CrashSequence
(__null, 198); __attribute__((nomerge)) ::abort(); } while (false
); } while (false)
;
199 // Fall through to the default DELETE journal.
200 case JOURNAL_DELETE:
201 journalMode.AssignLiteral("delete");
202 break;
203 case JOURNAL_TRUNCATE:
204 journalMode.AssignLiteral("truncate");
205 break;
206 case JOURNAL_MEMORY:
207 journalMode.AssignLiteral("memory");
208 break;
209 case JOURNAL_WAL:
210 journalMode.AssignLiteral("wal");
211 break;
212 }
213
214 nsCOMPtr<mozIStorageStatement> statement;
215 nsAutoCString query(MOZ_STORAGE_UNIQUIFY_QUERY_STR"/* " "./../../../../toolkit/components/places/Database.cpp" " */ " "PRAGMA journal_mode = ");
216 query.Append(journalMode);
217 aDBConn->CreateStatement(query, getter_AddRefs(statement));
218 NS_ENSURE_TRUE(statement, JOURNAL_DELETE)do { if ((__builtin_expect(!!(!(statement)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "statement" ") failed", nullptr
, "./../../../../toolkit/components/places/Database.cpp", 218
); return JOURNAL_DELETE; } } while (false)
;
219
220 bool hasResult = false;
221 if (NS_SUCCEEDED(statement->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(statement->ExecuteStep
(&hasResult))), 1)))
&& hasResult &&
222 NS_SUCCEEDED(statement->GetUTF8String(0, journalMode))((bool)(__builtin_expect(!!(!NS_FAILED_impl(statement->GetUTF8String
(0, journalMode))), 1)))
) {
223 if (journalMode.EqualsLiteral("delete")) {
224 return JOURNAL_DELETE;
225 }
226 if (journalMode.EqualsLiteral("truncate")) {
227 return JOURNAL_TRUNCATE;
228 }
229 if (journalMode.EqualsLiteral("memory")) {
230 return JOURNAL_MEMORY;
231 }
232 if (journalMode.EqualsLiteral("wal")) {
233 return JOURNAL_WAL;
234 }
235 MOZ_ASSERT(false, "Got an unknown journal mode.")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Got an unknown journal mode."
")", "./../../../../toolkit/components/places/Database.cpp",
235); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Got an unknown journal mode."
")"); do { MOZ_CrashSequence(__null, 235); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
236 }
237
238 return JOURNAL_DELETE;
239}
240
241nsresult CreateRoot(nsCOMPtr<mozIStorageConnection>& aDBConn,
242 const nsCString& aRootName, const nsCString& aGuid,
243 const nsCString& titleString, const int32_t position,
244 int64_t& newId) {
245 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../../toolkit/components/places/Database.cpp", 245
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { MOZ_CrashSequence(__null, 245); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
246
247 // A single creation timestamp for all roots so that the root folder's
248 // last modification time isn't earlier than its childrens' creation time.
249 static PRTime timestamp = 0;
250 if (!timestamp) timestamp = RoundedPRNow();
251
252 // Create a new bookmark folder for the root.
253 nsCOMPtr<mozIStorageStatement> stmt;
254 nsresult rv = aDBConn->CreateStatement(
255 nsLiteralCString(
256 "INSERT INTO moz_bookmarks "
257 "(type, position, title, dateAdded, lastModified, guid, parent, "
258 "syncChangeCounter, syncStatus) "
259 "VALUES (:item_type, :item_position, :item_title,"
260 ":date_added, :last_modified, :guid, "
261 "IFNULL((SELECT id FROM moz_bookmarks WHERE parent = 0), 0), "
262 "1, :sync_status)"),
263 getter_AddRefs(stmt));
264 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
265
266 rv = stmt->BindInt32ByName("item_type"_ns,
267 nsINavBookmarksService::TYPE_FOLDER);
268 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
269 rv = stmt->BindInt32ByName("item_position"_ns, position);
270 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
271 rv = stmt->BindUTF8StringByName("item_title"_ns, titleString);
272 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
273 rv = stmt->BindInt64ByName("date_added"_ns, timestamp);
274 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
275 rv = stmt->BindInt64ByName("last_modified"_ns, timestamp);
276 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
277 rv = stmt->BindUTF8StringByName("guid"_ns, aGuid);
278 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
279 rv = stmt->BindInt32ByName("sync_status"_ns,
280 nsINavBookmarksService::SYNC_STATUS_NEW);
281 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
282 rv = stmt->Execute();
283 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
284
285 newId = nsNavBookmarks::sLastInsertedItemId;
286 return NS_OK;
287}
288
289nsresult SetupDurability(nsCOMPtr<mozIStorageConnection>& aDBConn,
290 int32_t aDBPageSize) {
291 nsresult rv;
292 if (PR_GetEnv(ENV_ALLOW_CORRUPTION"ALLOW_PLACES_DATABASE_TO_LOSE_DATA_AND_BECOME_CORRUPT") &&
293 Preferences::GetBool(PREF_DISABLE_DURABILITY"places.database.disableDurability", false)) {
294 // Volatile storage was requested. Use the in-memory journal (no
295 // filesystem I/O) and don't sync the filesystem after writing.
296 SetJournalMode(aDBConn, JOURNAL_MEMORY);
297 rv = aDBConn->ExecuteSimpleSQL("PRAGMA synchronous = OFF"_ns);
298 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 298); return rv; } } while (false)
;
299 } else {
300 // Be sure to set journal mode after page_size. WAL would prevent the
301 // change otherwise.
302 if (JOURNAL_WAL == SetJournalMode(aDBConn, JOURNAL_WAL)) {
303 // Set the WAL journal size limit.
304 int32_t checkpointPages =
305 static_cast<int32_t>(DATABASE_MAX_WAL_BYTES2048000 / aDBPageSize);
306 nsAutoCString checkpointPragma("PRAGMA wal_autocheckpoint = ");
307 checkpointPragma.AppendInt(checkpointPages);
308 rv = aDBConn->ExecuteSimpleSQL(checkpointPragma);
309 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 309); return rv; } } while (false)
;
310 } else {
311 // Ignore errors, if we fail here the database could be considered corrupt
312 // and we won't be able to go on, even if it's just matter of a bogus file
313 // system. The default mode (DELETE) will be fine in such a case.
314 (void)SetJournalMode(aDBConn, JOURNAL_TRUNCATE);
315
316 // Set synchronous to FULL to ensure maximum data integrity, even in
317 // case of crashes or unclean shutdowns.
318 rv = aDBConn->ExecuteSimpleSQL("PRAGMA synchronous = FULL"_ns);
319 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 319); return rv; } } while (false)
;
320 }
321 }
322
323 // The journal is usually free to grow for performance reasons, but it never
324 // shrinks back. Since the space taken may be problematic, limit its size.
325 nsAutoCString journalSizePragma("PRAGMA journal_size_limit = ");
326 journalSizePragma.AppendInt(DATABASE_MAX_WAL_BYTES2048000 +
327 DATABASE_JOURNAL_OVERHEAD_BYTES2048000);
328 (void)aDBConn->ExecuteSimpleSQL(journalSizePragma);
329
330 // Grow places in |growthIncrementKiB| increments to limit fragmentation on
331 // disk. By default, it's 5 MB.
332 int32_t growthIncrementKiB =
333 Preferences::GetInt(PREF_GROWTH_INCREMENT_KIB"places.database.growthIncrementKiB", 5 * BYTES_PER_KIBIBYTE1024);
334 if (growthIncrementKiB > 0) {
335 (void)aDBConn->SetGrowthIncrement(growthIncrementKiB * BYTES_PER_KIBIBYTE1024,
336 ""_ns);
337 }
338 return NS_OK;
339}
340
341nsresult AttachDatabase(nsCOMPtr<mozIStorageConnection>& aDBConn,
342 const nsACString& aPath, const nsACString& aName) {
343 nsresult rv;
344 nsCString path;
345 path = aPath;
346
347 bool encryptionEnabled =
348 StaticPrefs::security_storage_encryption_sqlite_enabled();
349 if (encryptionEnabled) {
350 storage::EncryptionStatus encStatus;
351 rv = storage::GetDatabaseEncryptionStatus(path, encStatus);
352 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 352); return rv; } } while (false)
;
353
354 // Outside-profile DBs attach unencrypted. In-profile attach targets always
355 // pre-exist, so load the DEK (never create one).
356 if (encStatus == storage::EncryptionStatus::Encrypted) {
357 nsCString dbKey;
358 rv = storage::GetEncryptionKey(path, storage::OpenIntent::LoadExisting,
359 dbKey);
360 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 360); return rv; } } while (false)
;
361
362 storage::PreparePathForURI(path);
363 path = nsPrintfCString("file:%s?key=%s", path.get(), dbKey.get());
364 }
365 }
366
367 nsCOMPtr<mozIStorageStatement> stmt;
368 rv = aDBConn->CreateStatement("ATTACH DATABASE :path AS "_ns + aName,
369 getter_AddRefs(stmt));
370 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 370); return rv; } } while (false)
;
371
372 rv = stmt->BindUTF8StringByName("path"_ns, path);
373 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 373); return rv; } } while (false)
;
374
375 rv = stmt->Execute();
376 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 376); return rv; } } while (false)
;
377
378 // The journal limit must be set apart for each database.
379 nsAutoCString journalSizePragma("PRAGMA favicons.journal_size_limit = ");
380 journalSizePragma.AppendInt(DATABASE_MAX_WAL_BYTES2048000 +
381 DATABASE_JOURNAL_OVERHEAD_BYTES2048000);
382 (void)aDBConn->ExecuteSimpleSQL(journalSizePragma);
383
384 return NS_OK;
385}
386
387PRTime GetNow() {
388 nsNavHistory* history = nsNavHistory::GetHistoryService();
389 PRTime now;
390 if (history) {
391 // Optimization to avoid calling PR_Now() too often.
392 now = history->GetNow();
393 } else {
394 now = PR_Now();
395 }
396 return now;
397}
398
399} // namespace
400
401////////////////////////////////////////////////////////////////////////////////
402//// Database
403
404PLACES_FACTORY_SINGLETON_IMPLEMENTATION(Database, gDatabase)Database* Database::gDatabase = nullptr; already_AddRefed<
Database> Database::GetSingleton() { if (!XRE_IsParentProcess
()) { return nullptr; } if (gDatabase) { RefPtr<Database>
ret = gDatabase; return ret.forget(); } if (!NS_IsMainThread
()) { return nullptr; } gDatabase = new Database(); RefPtr<
Database> ret = gDatabase; if (((bool)(__builtin_expect(!!
(NS_FAILED_impl(gDatabase->Init())), 0)))) { ret = nullptr
; gDatabase = nullptr; return nullptr; } return ret.forget();
}
405
406NS_IMPL_ISUPPORTS(Database, nsIObserver, nsISupportsWeakReference)MozExternalRefCountType Database::AddRef(void) { static_assert
(!std::is_destructible_v<Database>, "Reference-counted class "
"Database" " should not have a public destructor. " "Make this class's destructor non-public"
); do { static_assert( mozilla::detail::AssertionConditionType
<decltype(int32_t(mRefCnt) >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0"
" (" "illegal refcnt" ")", "./../../../../toolkit/components/places/Database.cpp"
, 406); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 406
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("Database" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("Database" != nullptr))), 0)
)) { do { } while (false); MOZ_ReportAssertionFailure("\"Database\" != nullptr"
" (" "Must specify a name" ")", "./../../../../toolkit/components/places/Database.cpp"
, 406); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"Database\" != nullptr"
") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null
, 406); __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("Database" " not thread-safe"); nsrefcnt count = ++mRefCnt; NS_LogAddRef
((this), (count), ("Database"), (uint32_t)(sizeof(*this))); return
count; } MozExternalRefCountType Database::Release(void) { do
{ static_assert( mozilla::detail::AssertionConditionType<
decltype(int32_t(mRefCnt) > 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) > 0))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0"
" (" "dup release" ")", "./../../../../toolkit/components/places/Database.cpp"
, 406); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 406
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("Database" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("Database" != nullptr))), 0)
)) { do { } while (false); MOZ_ReportAssertionFailure("\"Database\" != nullptr"
" (" "Must specify a name" ")", "./../../../../toolkit/components/places/Database.cpp"
, 406); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"Database\" != nullptr"
") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null
, 406); __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("Database" " not thread-safe"); const char* const nametmp = "Database"
; nsrefcnt count = --mRefCnt; NS_LogRelease((this), (count), (
nametmp)); if (count == 0) { mRefCnt = 1; delete (this); return
0; } return count; } nsresult Database::QueryInterface(const
nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr
)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!"
, "aInstancePtr", "./../../../../toolkit/components/places/Database.cpp"
, 406); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(2 > 0, "Need more arguments to NS_INTERFACE_TABLE"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<Database, nsIObserver>, int32_t( reinterpret_cast
<char*>(static_cast<nsIObserver*>((Database*)0x1000
)) - reinterpret_cast<char*>((Database*)0x1000))}, {&
mozilla::detail::kImplementedIID<Database, nsISupportsWeakReference
>, int32_t( reinterpret_cast<char*>(static_cast<nsISupportsWeakReference
*>((Database*)0x1000)) - reinterpret_cast<char*>((Database
*)0x1000))}, {&mozilla::detail::kImplementedIID<Database
, nsISupports>, int32_t(reinterpret_cast<char*>(static_cast
<nsISupports*>( static_cast<nsIObserver*>((Database
*)0x1000))) - reinterpret_cast<char*>((Database*)0x1000
))}, { nullptr, 0 } } ; static_assert(std::size(table) > 1
, "need at least 1 interface"); rv = NS_TableDrivenQI(static_cast
<void*>(this), aIID, aInstancePtr, table); return rv; }
407
408Database::Database()
409 : mMainThreadStatements(mMainConn),
410 mMainThreadAsyncStatements(mMainConn),
411 mAsyncThreadStatements(mMainConn),
412 mDBPageSize(0),
413 mDatabaseStatus(nsINavHistoryService::DATABASE_STATUS_OK),
414 mClosed(false),
415 mClientsShutdown(new ClientsShutdownBlocker()),
416 mConnectionShutdown(new ConnectionShutdownBlocker(this)),
417 mMaxUrlLength(0),
418 mCacheObservers(TOPIC_PLACES_INIT_COMPLETE"places-init-complete"),
419 mRootId(-1),
420 mMenuRootId(-1),
421 mTagsRootId(-1),
422 mUnfiledRootId(-1),
423 mToolbarRootId(-1),
424 mMobileRootId(-1) {
425 MOZ_ASSERT(!XRE_IsContentProcess(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!XRE_IsContentProcess())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!XRE_IsContentProcess()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!XRE_IsContentProcess()"
" (" "Cannot instantiate Places in the content process" ")",
"./../../../../toolkit/components/places/Database.cpp", 426)
; AnnotateMozCrashReason("MOZ_ASSERT" "(" "!XRE_IsContentProcess()"
") (" "Cannot instantiate Places in the content process" ")"
); do { MOZ_CrashSequence(__null, 426); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
426 "Cannot instantiate Places in the content process")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!XRE_IsContentProcess())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!XRE_IsContentProcess()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!XRE_IsContentProcess()"
" (" "Cannot instantiate Places in the content process" ")",
"./../../../../toolkit/components/places/Database.cpp", 426)
; AnnotateMozCrashReason("MOZ_ASSERT" "(" "!XRE_IsContentProcess()"
") (" "Cannot instantiate Places in the content process" ")"
); do { MOZ_CrashSequence(__null, 426); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
427 // Attempting to create two instances of the service?
428 MOZ_ASSERT(!gDatabase)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!gDatabase)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!gDatabase))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("!gDatabase", "./../../../../toolkit/components/places/Database.cpp"
, 428); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!gDatabase" ")"
); do { MOZ_CrashSequence(__null, 428); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
429 gDatabase = this;
430}
431
432already_AddRefed<nsIAsyncShutdownClient>
433Database::GetProfileChangeTeardownPhase() {
434 nsCOMPtr<nsIAsyncShutdownService> asyncShutdownSvc =
435 components::AsyncShutdown::Service();
436 MOZ_ASSERT(asyncShutdownSvc)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(asyncShutdownSvc)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(asyncShutdownSvc))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("asyncShutdownSvc"
, "./../../../../toolkit/components/places/Database.cpp", 436
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "asyncShutdownSvc"
")"); do { MOZ_CrashSequence(__null, 436); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
437 if (NS_WARN_IF(!asyncShutdownSvc)NS_warn_if_impl(!asyncShutdownSvc, "!asyncShutdownSvc", "./../../../../toolkit/components/places/Database.cpp"
, 437)
) {
438 return nullptr;
439 }
440
441 // Consumers of Places should shutdown before us, at profile-change-teardown.
442 nsCOMPtr<nsIAsyncShutdownClient> shutdownPhase;
443 DebugOnly<nsresult> rv =
444 asyncShutdownSvc->GetProfileChangeTeardown(getter_AddRefs(shutdownPhase));
445 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "./../../../../toolkit/components/places/Database.cpp"
, 445); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { MOZ_CrashSequence(__null, 445); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
446 return shutdownPhase.forget();
447}
448
449already_AddRefed<nsIAsyncShutdownClient>
450Database::GetProfileBeforeChangePhase() {
451 nsCOMPtr<nsIAsyncShutdownService> asyncShutdownSvc =
452 components::AsyncShutdown::Service();
453 MOZ_ASSERT(asyncShutdownSvc)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(asyncShutdownSvc)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(asyncShutdownSvc))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("asyncShutdownSvc"
, "./../../../../toolkit/components/places/Database.cpp", 453
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "asyncShutdownSvc"
")"); do { MOZ_CrashSequence(__null, 453); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
454 if (NS_WARN_IF(!asyncShutdownSvc)NS_warn_if_impl(!asyncShutdownSvc, "!asyncShutdownSvc", "./../../../../toolkit/components/places/Database.cpp"
, 454)
) {
455 return nullptr;
456 }
457
458 // Consumers of Places should shutdown before us, at profile-change-teardown.
459 nsCOMPtr<nsIAsyncShutdownClient> shutdownPhase;
460 DebugOnly<nsresult> rv =
461 asyncShutdownSvc->GetProfileBeforeChange(getter_AddRefs(shutdownPhase));
462 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "./../../../../toolkit/components/places/Database.cpp"
, 462); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { MOZ_CrashSequence(__null, 462); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
463 return shutdownPhase.forget();
464}
465
466Database::~Database() = default;
467
468already_AddRefed<mozIStorageAsyncStatement> Database::GetAsyncStatement(
469 const nsACString& aQuery) {
470 if (PlacesShutdownBlocker::sIsStarted || NS_FAILED(EnsureConnection())((bool)(__builtin_expect(!!(NS_FAILED_impl(EnsureConnection()
)), 0)))
) {
471 return nullptr;
472 }
473
474 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../../toolkit/components/places/Database.cpp", 474
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { MOZ_CrashSequence(__null, 474); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
475 return mMainThreadAsyncStatements.GetCachedStatement(aQuery);
476}
477
478already_AddRefed<mozIStorageStatement> Database::GetStatement(
479 const nsACString& aQuery) {
480 if (PlacesShutdownBlocker::sIsStarted) {
481 return nullptr;
482 }
483 if (NS_IsMainThread()) {
484 if (NS_FAILED(EnsureConnection())((bool)(__builtin_expect(!!(NS_FAILED_impl(EnsureConnection()
)), 0)))
) {
485 return nullptr;
486 }
487 return mMainThreadStatements.GetCachedStatement(aQuery);
488 }
489 // In the async case, the connection must have been started on the main-thread
490 // already.
491 MOZ_ASSERT(mMainConn)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mMainConn)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mMainConn))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("mMainConn", "./../../../../toolkit/components/places/Database.cpp"
, 491); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mMainConn" ")"
); do { MOZ_CrashSequence(__null, 491); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
492 return mAsyncThreadStatements.GetCachedStatement(aQuery);
493}
494
495already_AddRefed<nsIAsyncShutdownClient> Database::GetClientsShutdown() {
496 if (mClientsShutdown) return mClientsShutdown->GetClient();
497 return nullptr;
498}
499
500already_AddRefed<nsIAsyncShutdownClient> Database::GetConnectionShutdown() {
501 if (mConnectionShutdown) return mConnectionShutdown->GetClient();
502 return nullptr;
503}
504
505// static
506already_AddRefed<Database> Database::GetDatabase() {
507 if (PlacesShutdownBlocker::sIsStarted) {
508 return nullptr;
509 }
510 return GetSingleton();
511}
512
513nsresult Database::Init() {
514 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../../toolkit/components/places/Database.cpp", 514
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { MOZ_CrashSequence(__null, 514); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
515
516 // DO NOT FAIL HERE, otherwise we would never break the cycle between this
517 // object and the shutdown blockers, causing unexpected leaks.
518
519 {
520 // First of all Places clients should block profile-change-teardown.
521 nsCOMPtr<nsIAsyncShutdownClient> shutdownPhase =
522 GetProfileChangeTeardownPhase();
523 MOZ_ASSERT(shutdownPhase)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(shutdownPhase)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(shutdownPhase))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("shutdownPhase",
"./../../../../toolkit/components/places/Database.cpp", 523)
; AnnotateMozCrashReason("MOZ_ASSERT" "(" "shutdownPhase" ")"
); do { MOZ_CrashSequence(__null, 523); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
524 if (shutdownPhase) {
525 nsresult rv = shutdownPhase->AddBlocker(
526 static_cast<nsIAsyncShutdownBlocker*>(mClientsShutdown.get()),
527 NS_LITERAL_STRING_FROM_CSTRING(__FILE__)static_cast<const nsLiteralString&>( nsLiteralString
(u"" "./../../../../toolkit/components/places/Database.cpp"))
, __LINE__527, u""_ns);
528 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
529 // Might occur if we're already shutting down, see bug#1753165
530 PlacesShutdownBlocker::sIsStarted = true;
531 NS_WARNING("Cannot add shutdown blocker for profile-change-teardown")NS_DebugBreak(NS_DEBUG_WARNING, "Cannot add shutdown blocker for profile-change-teardown"
, nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 531)
;
532 }
533 }
534 }
535
536 {
537 // Then connection closing should block profile-before-change.
538 nsCOMPtr<nsIAsyncShutdownClient> shutdownPhase =
539 GetProfileBeforeChangePhase();
540 MOZ_ASSERT(shutdownPhase)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(shutdownPhase)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(shutdownPhase))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("shutdownPhase",
"./../../../../toolkit/components/places/Database.cpp", 540)
; AnnotateMozCrashReason("MOZ_ASSERT" "(" "shutdownPhase" ")"
); do { MOZ_CrashSequence(__null, 540); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
541 if (shutdownPhase) {
542 nsresult rv = shutdownPhase->AddBlocker(
543 static_cast<nsIAsyncShutdownBlocker*>(mConnectionShutdown.get()),
544 NS_LITERAL_STRING_FROM_CSTRING(__FILE__)static_cast<const nsLiteralString&>( nsLiteralString
(u"" "./../../../../toolkit/components/places/Database.cpp"))
, __LINE__544, u""_ns);
545 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
546 // Might occur if we're already shutting down, see bug#1753165
547 PlacesShutdownBlocker::sIsStarted = true;
548 NS_WARNING("Cannot add shutdown blocker for profile-before-change")NS_DebugBreak(NS_DEBUG_WARNING, "Cannot add shutdown blocker for profile-before-change"
, nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 548)
;
549 }
550 }
551 }
552
553 // Finally observe profile shutdown notifications.
554 nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
555 if (os) {
556 (void)os->AddObserver(this, TOPIC_PROFILE_CHANGE_TEARDOWN"profile-change-teardown", true);
557 }
558 return NS_OK;
559}
560
561nsresult Database::EnsureConnection() {
562 // Run this only once.
563 if (mMainConn ||
564 mDatabaseStatus == nsINavHistoryService::DATABASE_STATUS_LOCKED) {
565 return NS_OK;
566 }
567 // Don't try to create a database too late.
568 if (PlacesShutdownBlocker::sIsStarted) {
569 return NS_ERROR_FAILURE;
570 }
571
572 MOZ_ASSERT(NS_IsMainThread(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
" (" "Database initialization must happen on the main-thread"
")", "./../../../../toolkit/components/places/Database.cpp",
573); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
") (" "Database initialization must happen on the main-thread"
")"); do { MOZ_CrashSequence(__null, 573); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
573 "Database initialization must happen on the main-thread")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
" (" "Database initialization must happen on the main-thread"
")", "./../../../../toolkit/components/places/Database.cpp",
573); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
") (" "Database initialization must happen on the main-thread"
")"); do { MOZ_CrashSequence(__null, 573); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
574
575 {
576 bool initSucceeded = false;
577 auto notify = MakeScopeExit([&]() {
578 // If the database connection cannot be opened, it may just be locked
579 // by third parties. Set a locked state.
580 if (!initSucceeded) {
581 mMainConn = nullptr;
582 mDatabaseStatus = nsINavHistoryService::DATABASE_STATUS_LOCKED;
583 }
584 // Notify at the next tick, to avoid re-entrancy problems.
585 NS_DispatchToMainThread(
586 NewRunnableMethod("places::Database::EnsureConnection()", this,
587 &Database::NotifyConnectionInitalized));
588 });
589
590 nsCOMPtr<mozIStorageService> storage =
591 do_GetService(MOZ_STORAGE_SERVICE_CONTRACTID"@mozilla.org/storage/service;1");
592 NS_ENSURE_STATE(storage)do { if ((__builtin_expect(!!(!(storage)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "storage" ") failed", nullptr
, "./../../../../toolkit/components/places/Database.cpp", 592
); return NS_ERROR_UNEXPECTED; } } while (false)
;
593
594 nsCOMPtr<nsIFile> profileDir;
595 nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR"ProfD",
596 getter_AddRefs(profileDir));
597 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 597); return rv; } } while (false)
;
598
599 nsCOMPtr<nsIFile> databaseFile;
600 rv = profileDir->Clone(getter_AddRefs(databaseFile));
601 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 601); return rv; } } while (false)
;
602 rv = databaseFile->Append(DATABASE_FILENAMEu"places.sqlite"_ns);
603 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 603); return rv; } } while (false)
;
604 bool databaseExisted = false;
605 rv = databaseFile->Exists(&databaseExisted);
606 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 606); return rv; } } while (false)
;
607
608 nsAutoString corruptDbName;
609 if (NS_SUCCEEDED(Preferences::GetString(PREF_FORCE_DATABASE_REPLACEMENT,((bool)(__builtin_expect(!!(!NS_FAILED_impl(Preferences::GetString
("places.database.replaceDatabaseOnStartup", corruptDbName)))
, 1)))
610 corruptDbName))((bool)(__builtin_expect(!!(!NS_FAILED_impl(Preferences::GetString
("places.database.replaceDatabaseOnStartup", corruptDbName)))
, 1)))
&&
611 !corruptDbName.IsEmpty()) {
612 // If this pref is set, maintenance required a database replacement, due
613 // to integrity corruption. Be sure to clear the pref to avoid handling it
614 // more than once.
615 (void)Preferences::ClearUser(PREF_FORCE_DATABASE_REPLACEMENT"places.database.replaceDatabaseOnStartup");
616
617 // The database is corrupt, backup and replace it with a new one.
618 nsCOMPtr<nsIFile> fileToBeReplaced;
619 bool fileExists = false;
620 if (NS_SUCCEEDED(profileDir->Clone(getter_AddRefs(fileToBeReplaced)))((bool)(__builtin_expect(!!(!NS_FAILED_impl(profileDir->Clone
(getter_AddRefs(fileToBeReplaced)))), 1)))
&&
621 NS_SUCCEEDED(fileToBeReplaced->Exists(&fileExists))((bool)(__builtin_expect(!!(!NS_FAILED_impl(fileToBeReplaced->
Exists(&fileExists))), 1)))
&& fileExists) {
622 rv = BackupAndReplaceDatabaseFile(storage, corruptDbName, true, false);
623 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 623); return rv; } } while (false)
;
624 }
625 }
626
627 // Open the database file. If it does not exist a new one will be created.
628 // Use an unshared connection, it will consume more memory but avoid shared
629 // cache contentions across threads.
630 rv = storage->OpenUnsharedDatabase(databaseFile,
631 mozIStorageService::CONNECTION_DEFAULT,
632 getter_AddRefs(mMainConn));
633 if (rv == NS_ERROR_STORAGE_IOERR || rv == NS_ERROR_FILE_IS_LOCKED ||
634 rv == NS_ERROR_STORAGE_BUSY) {
635 // Transient lock or I/O error (e.g. network filesystem, AV software):
636 // retry once before giving up.
637 rv = storage->OpenUnsharedDatabase(databaseFile,
638 mozIStorageService::CONNECTION_DEFAULT,
639 getter_AddRefs(mMainConn));
640 }
641 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && !databaseExisted) {
642 mDatabaseStatus = nsINavHistoryService::DATABASE_STATUS_CREATE;
643 } else if (rv == NS_ERROR_FILE_CORRUPTED) {
644 // Set places last corruption time in prefs for troubleshooting.
645 CheckedInt<int32_t> daysSinceEpoch = GetNow() / USEC_PER_DAY86400000000LL;
646 if (daysSinceEpoch.isValid()) {
647 Preferences::SetInt(PREF_DATABASE_PLACES_LASTCORRUPTION"places.database.lastPlacesCorruptionInDaysFromEpoch",
648 daysSinceEpoch.value());
649 }
650 // The database is corrupt, backup and replace it with a new one.
651 rv = BackupAndReplaceDatabaseFile(storage, DATABASE_FILENAMEu"places.sqlite"_ns, true, true);
652 // Fallback to catch-all handler.
653 }
654 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 654); return rv; } } while (false)
;
655
656 // Initialize the database schema. In case of failure the existing schema
657 // is is corrupt or incoherent, thus the database should be replaced.
658 bool databaseMigrated = false;
659 rv = SetupDatabaseConnection(storage);
660 bool shouldTryToCloneDb = true;
661 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
662 // Failing to initialize the schema may indicate a corruption.
663 rv = InitSchema(&databaseMigrated);
664 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
665 // Cloning the db on a schema migration may not be a good idea, since we
666 // may end up cloning the schema problems.
667 shouldTryToCloneDb = false;
668 if (rv == NS_ERROR_STORAGE_BUSY || rv == NS_ERROR_FILE_IS_LOCKED ||
669 rv == NS_ERROR_FILE_NO_DEVICE_SPACE ||
670 rv == NS_ERROR_OUT_OF_MEMORY) {
671 // The database is not corrupt, though some migration step failed.
672 // This may be caused by concurrent use of sync and async Storage APIs
673 // or by a system issue.
674 // The best we can do is trying again. If it should still fail, Places
675 // won't work properly and will be handled as LOCKED.
676 rv = InitSchema(&databaseMigrated);
677 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
678 rv = NS_ERROR_FILE_IS_LOCKED;
679 }
680 } else {
681 rv = NS_ERROR_FILE_CORRUPTED;
682 }
683 }
684 }
685 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../../toolkit/components/places/Database.cpp"
, 685)
) {
686 if (rv != NS_ERROR_FILE_IS_LOCKED) {
687 mDatabaseStatus = nsINavHistoryService::DATABASE_STATUS_CORRUPT;
688 }
689 // Some errors may not indicate a database corruption, for those cases we
690 // just bail out without throwing away a possibly valid places.sqlite.
691 if (rv == NS_ERROR_FILE_CORRUPTED) {
692 // Set places and favicons last corruption time in prefs for
693 // troubleshooting.
694 CheckedInt<int32_t> daysSinceEpoch = GetNow() / USEC_PER_DAY86400000000LL;
695 if (daysSinceEpoch.isValid()) {
696 Preferences::SetInt(PREF_DATABASE_PLACES_LASTCORRUPTION"places.database.lastPlacesCorruptionInDaysFromEpoch",
697 daysSinceEpoch.value());
698 Preferences::SetInt(PREF_DATABASE_FAVICONS_LASTCORRUPTION"places.database.lastFaviconsCorruptionInDaysFromEpoch",
699 daysSinceEpoch.value());
700 }
701
702 // Since we don't know which database is corrupt, we must replace both.
703 rv = BackupAndReplaceDatabaseFile(storage, DATABASE_FAVICONS_FILENAMEu"favicons.sqlite"_ns,
704 false, false);
705 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 705); return rv; } } while (false)
;
706 rv = BackupAndReplaceDatabaseFile(storage, DATABASE_FILENAMEu"places.sqlite"_ns,
707 shouldTryToCloneDb, true);
708 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 708); return rv; } } while (false)
;
709 // Try to initialize the new database again.
710 rv = SetupDatabaseConnection(storage);
711 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 711); return rv; } } while (false)
;
712 rv = InitSchema(&databaseMigrated);
713 }
714 // Bail out if we couldn't fix the database.
715 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 715); return rv; } } while (false)
;
716 }
717
718 if (databaseMigrated) {
719 mDatabaseStatus = nsINavHistoryService::DATABASE_STATUS_UPGRADED;
720 }
721
722 // Initialize here all the items that are not part of the on-disk database,
723 // like views, temp triggers or temp tables. The database should not be
724 // considered corrupt if any of the following fails.
725
726 rv = InitTempEntities();
727 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 727); return rv; } } while (false)
;
728
729 rv = CheckRoots();
730 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 730); return rv; } } while (false)
;
731
732 initSucceeded = true;
733 }
734 return NS_OK;
735}
736
737nsresult Database::NotifyConnectionInitalized() {
738 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../../toolkit/components/places/Database.cpp", 738
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { MOZ_CrashSequence(__null, 738); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
739 // Notify about Places initialization.
740 nsCOMArray<nsIObserver> entries;
741 mCacheObservers.GetEntries(entries);
742 for (int32_t idx = 0; idx < entries.Count(); ++idx) {
743 MOZ_ALWAYS_SUCCEEDS(do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(entries[idx]->Observe(nullptr, "places-init-complete", nullptr
))), 1)))), 1))) { } else { do { do { } while (false); MOZ_ReportCrash
("" "NS_SUCCEEDED(entries[idx]->Observe(nullptr, \"places-init-complete\", nullptr))"
, "./../../../../toolkit/components/places/Database.cpp", 744
); AnnotateMozCrashReason("MOZ_CRASH(" "NS_SUCCEEDED(entries[idx]->Observe(nullptr, \"places-init-complete\", nullptr))"
")"); do { MOZ_CrashSequence(__null, 744); __attribute__((nomerge
)) ::abort(); } while (false); } while (false); } } while (false
)
744 entries[idx]->Observe(nullptr, TOPIC_PLACES_INIT_COMPLETE, nullptr))do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(entries[idx]->Observe(nullptr, "places-init-complete", nullptr
))), 1)))), 1))) { } else { do { do { } while (false); MOZ_ReportCrash
("" "NS_SUCCEEDED(entries[idx]->Observe(nullptr, \"places-init-complete\", nullptr))"
, "./../../../../toolkit/components/places/Database.cpp", 744
); AnnotateMozCrashReason("MOZ_CRASH(" "NS_SUCCEEDED(entries[idx]->Observe(nullptr, \"places-init-complete\", nullptr))"
")"); do { MOZ_CrashSequence(__null, 744); __attribute__((nomerge
)) ::abort(); } while (false); } while (false); } } while (false
)
;
745 }
746 nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
747 if (obs) {
748 MOZ_ALWAYS_SUCCEEDS(do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(obs->NotifyObservers(nullptr, "places-init-complete", nullptr
))), 1)))), 1))) { } else { do { do { } while (false); MOZ_ReportCrash
("" "NS_SUCCEEDED(obs->NotifyObservers(nullptr, \"places-init-complete\", nullptr))"
, "./../../../../toolkit/components/places/Database.cpp", 749
); AnnotateMozCrashReason("MOZ_CRASH(" "NS_SUCCEEDED(obs->NotifyObservers(nullptr, \"places-init-complete\", nullptr))"
")"); do { MOZ_CrashSequence(__null, 749); __attribute__((nomerge
)) ::abort(); } while (false); } while (false); } } while (false
)
749 obs->NotifyObservers(nullptr, TOPIC_PLACES_INIT_COMPLETE, nullptr))do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(obs->NotifyObservers(nullptr, "places-init-complete", nullptr
))), 1)))), 1))) { } else { do { do { } while (false); MOZ_ReportCrash
("" "NS_SUCCEEDED(obs->NotifyObservers(nullptr, \"places-init-complete\", nullptr))"
, "./../../../../toolkit/components/places/Database.cpp", 749
); AnnotateMozCrashReason("MOZ_CRASH(" "NS_SUCCEEDED(obs->NotifyObservers(nullptr, \"places-init-complete\", nullptr))"
")"); do { MOZ_CrashSequence(__null, 749); __attribute__((nomerge
)) ::abort(); } while (false); } while (false); } } while (false
)
;
750 }
751 return NS_OK;
752}
753
754nsresult Database::EnsureFaviconsDatabaseAttached(
755 const nsCOMPtr<mozIStorageService>& aStorage) {
756 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../../toolkit/components/places/Database.cpp", 756
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { MOZ_CrashSequence(__null, 756); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
757
758 nsCOMPtr<nsIFile> databaseFile;
759 NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR"ProfD",
760 getter_AddRefs(databaseFile));
761 NS_ENSURE_STATE(databaseFile)do { if ((__builtin_expect(!!(!(databaseFile)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "databaseFile" ") failed"
, nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 761); return NS_ERROR_UNEXPECTED; } } while (false)
;
762 nsresult rv = databaseFile->Append(DATABASE_FAVICONS_FILENAMEu"favicons.sqlite"_ns);
763 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 763); return rv; } } while (false)
;
764 nsString iconsPath;
765 rv = databaseFile->GetPath(iconsPath);
766 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 766); return rv; } } while (false)
;
767
768 bool fileExists = false;
769 if (NS_SUCCEEDED(databaseFile->Exists(&fileExists))((bool)(__builtin_expect(!!(!NS_FAILED_impl(databaseFile->
Exists(&fileExists))), 1)))
&& fileExists) {
770 return AttachDatabase(mMainConn, NS_ConvertUTF16toUTF8(iconsPath),
771 DATABASE_FAVICONS_SCHEMANAME"favicons"_ns);
772 }
773
774 // Open the database file, this will also create it.
775 nsCOMPtr<mozIStorageConnection> conn;
776 rv = aStorage->OpenUnsharedDatabase(databaseFile,
777 mozIStorageService::CONNECTION_DEFAULT,
778 getter_AddRefs(conn));
779 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 779); return rv; } } while (false)
;
780
781 {
782 // Ensure we'll close the connection when done.
783 auto cleanup = MakeScopeExit([&]() {
784 // We cannot use AsyncClose() here, because by the time we try to ATTACH
785 // this database, its transaction could be still be running and that would
786 // cause the ATTACH query to fail.
787 MOZ_ALWAYS_TRUE(NS_SUCCEEDED(conn->Close()))do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(conn->Close())), 1)))), 1))) { } else { do { do { } while
(false); MOZ_ReportCrash("" "NS_SUCCEEDED(conn->Close())"
, "./../../../../toolkit/components/places/Database.cpp", 787
); AnnotateMozCrashReason("MOZ_CRASH(" "NS_SUCCEEDED(conn->Close())"
")"); do { MOZ_CrashSequence(__null, 787); __attribute__((nomerge
)) ::abort(); } while (false); } while (false); } } while (false
)
;
788 });
789
790 // Enable incremental vacuum for this database. Since it will contain even
791 // large blobs and can be cleared with history, it's worth to have it.
792 // Note that it will be necessary to manually use PRAGMA incremental_vacuum.
793 rv = conn->ExecuteSimpleSQL("PRAGMA auto_vacuum = INCREMENTAL"_ns);
794 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 794); return rv; } } while (false)
;
795
796#if !defined(HAVE_64BIT_BUILD1)
797 // Ensure that temp tables are held in memory, not on disk, on 32 bit
798 // platforms.
799 rv = conn->ExecuteSimpleSQL("PRAGMA temp_store = MEMORY"_ns);
800 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 800); return rv; } } while (false)
;
801#endif
802
803 int32_t defaultPageSize;
804 rv = conn->GetDefaultPageSize(&defaultPageSize);
805 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 805); return rv; } } while (false)
;
806 rv = SetupDurability(conn, defaultPageSize);
807 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 807); return rv; } } while (false)
;
808
809 // We are going to update the database, so everything from now on should be
810 // in a transaction for performances.
811 mozStorageTransaction transaction(conn, false);
812 // XXX Handle the error, bug 1696133.
813 (void)NS_WARN_IF(NS_FAILED(transaction.Start()))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(transaction
.Start())), 0))), "NS_FAILED(transaction.Start())", "./../../../../toolkit/components/places/Database.cpp"
, 813)
;
814 rv = conn->ExecuteSimpleSQL(CREATE_MOZ_ICONSnsLiteralCString( "CREATE TABLE moz_icons ( " "id INTEGER PRIMARY KEY, "
"icon_url TEXT NOT NULL, " "fixed_icon_url_hash INTEGER NOT NULL, "
"width INTEGER NOT NULL DEFAULT 0, " "root INTEGER NOT NULL DEFAULT 0, "
"color INTEGER, " "expire_ms INTEGER NOT NULL DEFAULT 0, " "flags INTEGER NOT NULL DEFAULT 0, "
"data BLOB " ") ")
);
815 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 815); return rv; } } while (false)
;
816 rv = conn->ExecuteSimpleSQL(CREATE_IDX_MOZ_ICONS_ICONURLHASHnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_icons"
"_" "iconurlhashindex" " ON " "moz_icons" " (" "fixed_icon_url_hash"
")")
);
817 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 817); return rv; } } while (false)
;
818 rv = conn->ExecuteSimpleSQL(CREATE_MOZ_PAGES_W_ICONSnsLiteralCString( "CREATE TABLE moz_pages_w_icons ( " "id INTEGER PRIMARY KEY, "
"page_url TEXT NOT NULL, " "page_url_hash INTEGER NOT NULL "
") ")
);
819 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 819); return rv; } } while (false)
;
820 rv = conn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PAGES_W_ICONS_ICONURLHASHnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_pages_w_icons"
"_" "urlhashindex" " ON " "moz_pages_w_icons" " (" "page_url_hash"
")")
);
821 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 821); return rv; } } while (false)
;
822 rv = conn->ExecuteSimpleSQL(CREATE_MOZ_ICONS_TO_PAGESnsLiteralCString( "CREATE TABLE moz_icons_to_pages ( " "page_id INTEGER NOT NULL, "
"icon_id INTEGER NOT NULL, " "expire_ms INTEGER NOT NULL DEFAULT 0, "
"PRIMARY KEY (page_id, icon_id), " "FOREIGN KEY (page_id) REFERENCES moz_pages_w_icons ON DELETE CASCADE, "
"FOREIGN KEY (icon_id) REFERENCES moz_icons ON DELETE CASCADE "
") WITHOUT ROWID ")
);
823 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 823); return rv; } } while (false)
;
824 rv = transaction.Commit();
825 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 825); return rv; } } while (false)
;
826
827 // The scope exit will take care of closing the connection.
828 }
829
830 rv = AttachDatabase(mMainConn, NS_ConvertUTF16toUTF8(iconsPath),
831 DATABASE_FAVICONS_SCHEMANAME"favicons"_ns);
832 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 832); return rv; } } while (false)
;
833
834 return NS_OK;
835}
836
837nsresult Database::BackupAndReplaceDatabaseFile(
838 nsCOMPtr<mozIStorageService>& aStorage, const nsString& aDbFilename,
839 bool aTryToClone, bool aReopenConnection) {
840 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../../toolkit/components/places/Database.cpp", 840
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { MOZ_CrashSequence(__null, 840); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
841
842 if (aDbFilename.Equals(DATABASE_FILENAMEu"places.sqlite"_ns)) {
843 mDatabaseStatus = nsINavHistoryService::DATABASE_STATUS_CORRUPT;
844 } else {
845 // Due to OS file lockings, attached databases can't be cloned properly,
846 // otherwise trying to reattach them later would fail.
847 aTryToClone = false;
848 }
849
850 nsCOMPtr<nsIFile> profDir;
851 nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR"ProfD",
852 getter_AddRefs(profDir));
853 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 853); return rv; } } while (false)
;
854 nsCOMPtr<nsIFile> databaseFile;
855 rv = profDir->Clone(getter_AddRefs(databaseFile));
856 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 856); return rv; } } while (false)
;
857 rv = databaseFile->Append(aDbFilename);
858 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 858); return rv; } } while (false)
;
859
860 // If we already failed in the last 24 hours avoid to create another corrupt
861 // file, since doing so, in some situation, could cause us to create a new
862 // corrupt file at every try to access any Places service. That is bad
863 // because it would quickly fill the user's disk space without any notice.
864 nsCOMPtr<nsIFile> corruptFile;
865 rv = profDir->Clone(getter_AddRefs(corruptFile));
866 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 866); return rv; } } while (false)
;
867 nsString corruptFilename = getCorruptFilename(aDbFilename);
868 rv = corruptFile->Append(corruptFilename);
869 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 869); return rv; } } while (false)
;
870 if (!isRecentCorruptFile(corruptFile)) {
871 // Ensure we never create more than one corrupt file.
872 nsCOMPtr<nsIFile> corruptFile;
873 rv = profDir->Clone(getter_AddRefs(corruptFile));
874 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 874); return rv; } } while (false)
;
875 nsString corruptFilename = getCorruptFilename(aDbFilename);
876 rv = corruptFile->Append(corruptFilename);
877 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 877); return rv; } } while (false)
;
878 rv = corruptFile->Remove(false);
879 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) && rv != NS_ERROR_FILE_NOT_FOUND) {
880 return rv;
881 }
882
883 nsCOMPtr<nsIFile> backup;
884 (void)BackupDatabaseFile(databaseFile, corruptFilename, profDir,
885 getter_AddRefs(backup));
886 }
887
888 // If anything fails from this point on, we have a stale connection or
889 // database file, and there's not much more we can do.
890 // The only thing we can try to do is to replace the database on the next
891 // startup, and report the problem through telemetry.
892 {
893 eCorruptDBReplaceStage stage = stage_closing;
894 auto guard = MakeScopeExit([&]() {
895 // In case we failed to close the connection or remove the database file,
896 // we want to try again at the next startup.
897 if (stage == stage_closing || stage == stage_removing) {
898 Preferences::SetString(PREF_FORCE_DATABASE_REPLACEMENT"places.database.replaceDatabaseOnStartup", aDbFilename);
899 }
900 // Report the corruption through telemetry.
901 glean::places::places_database_corruption_handling_stage
902 .Get(NS_ConvertUTF16toUTF8(aDbFilename))
903 .Set(sCorruptDBStages[stage]);
904 });
905
906 // Close database connection if open.
907 if (mMainConn) {
908 rv = mMainConn->SpinningSynchronousClose();
909 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 909); return rv; } } while (false)
;
910 mMainConn = nullptr;
911 }
912
913 // Remove the broken database.
914 stage = stage_removing;
915 rv = databaseFile->Remove(false);
916 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) && rv != NS_ERROR_FILE_NOT_FOUND) {
917 return rv;
918 }
919
920 // Create a new database file and try to clone tables from the corrupt one.
921 bool cloned = false;
922 if (aTryToClone &&
923 Preferences::GetBool(PREF_DATABASE_CLONEONCORRUPTION"places.database.cloneOnCorruption", true)) {
924 stage = stage_cloning;
925 rv = TryToCloneTablesFromCorruptDatabase(aStorage, databaseFile);
926 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
927 // If we cloned successfully, we should not consider the database
928 // corrupt anymore, otherwise we could reimport default bookmarks.
929 mDatabaseStatus = nsINavHistoryService::DATABASE_STATUS_OK;
930 cloned = true;
931 }
932 }
933
934 if (aReopenConnection) {
935 // Use an unshared connection, it will consume more memory but avoid
936 // shared cache contentions across threads.
937 stage = stage_reopening;
938 rv = aStorage->OpenUnsharedDatabase(
939 databaseFile, mozIStorageService::CONNECTION_DEFAULT,
940 getter_AddRefs(mMainConn));
941 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 941); return rv; } } while (false)
;
942 }
943
944 stage = cloned ? stage_cloned : stage_replaced;
945 }
946
947 return NS_OK;
948}
949
950nsresult Database::TryToCloneTablesFromCorruptDatabase(
951 const nsCOMPtr<mozIStorageService>& aStorage,
952 const nsCOMPtr<nsIFile>& aDatabaseFile) {
953 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../../toolkit/components/places/Database.cpp", 953
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { MOZ_CrashSequence(__null, 953); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
954
955 nsAutoString filename;
956 nsresult rv = aDatabaseFile->GetLeafName(filename);
Value stored to 'rv' during its initialization is never read
957
958 nsCOMPtr<nsIFile> corruptFile;
959 rv = aDatabaseFile->Clone(getter_AddRefs(corruptFile));
960 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 960); return rv; } } while (false)
;
961 rv = corruptFile->SetLeafName(getCorruptFilename(filename));
962 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 962); return rv; } } while (false)
;
963 nsAutoString path;
964 rv = corruptFile->GetPath(path);
965 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 965); return rv; } } while (false)
;
966
967 nsCOMPtr<nsIFile> recoverFile;
968 rv = aDatabaseFile->Clone(getter_AddRefs(recoverFile));
969 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 969); return rv; } } while (false)
;
970 rv = recoverFile->SetLeafName(getRecoverFilename(filename));
971 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 971); return rv; } } while (false)
;
972 // Ensure there's no previous recover file.
973 rv = recoverFile->Remove(false);
974 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) && rv != NS_ERROR_FILE_NOT_FOUND) {
975 return rv;
976 }
977
978 nsCOMPtr<mozIStorageConnection> conn;
979 auto guard = MakeScopeExit([&]() {
980 if (conn) {
981 (void)conn->Close();
982 }
983 RemoveFileSwallowsErrors(recoverFile);
984 });
985
986 rv = aStorage->OpenUnsharedDatabase(recoverFile,
987 mozIStorageService::CONNECTION_DEFAULT,
988 getter_AddRefs(conn));
989 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 989); return rv; } } while (false)
;
990 rv = AttachDatabase(conn, NS_ConvertUTF16toUTF8(path), "corrupt"_ns);
991 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 991); return rv; } } while (false)
;
992
993 mozStorageTransaction transaction(conn, false);
994
995 // XXX Handle the error, bug 1696133.
996 (void)NS_WARN_IF(NS_FAILED(transaction.Start()))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(transaction
.Start())), 0))), "NS_FAILED(transaction.Start())", "./../../../../toolkit/components/places/Database.cpp"
, 996)
;
997
998 // Copy the schema version.
999 nsCOMPtr<mozIStorageStatement> stmt;
1000 (void)conn->CreateStatement("PRAGMA corrupt.user_version"_ns,
1001 getter_AddRefs(stmt));
1002 NS_ENSURE_TRUE(stmt, NS_ERROR_OUT_OF_MEMORY)do { if ((__builtin_expect(!!(!(stmt)), 0))) { NS_DebugBreak(
NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "stmt" ") failed", nullptr
, "./../../../../toolkit/components/places/Database.cpp", 1002
); return NS_ERROR_OUT_OF_MEMORY; } } while (false)
;
1003 bool hasResult;
1004 rv = stmt->ExecuteStep(&hasResult);
1005 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1005); return rv; } } while (false)
;
1006 int32_t schemaVersion = stmt->AsInt32(0);
1007 rv = conn->SetSchemaVersion(schemaVersion);
1008 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1008); return rv; } } while (false)
;
1009
1010 // Recreate the tables.
1011 rv = conn->CreateStatement(
1012 nsLiteralCString(
1013 "SELECT name, sql FROM corrupt.sqlite_master "
1014 "WHERE type = 'table' AND name BETWEEN 'moz_' AND 'moza'"),
1015 getter_AddRefs(stmt));
1016 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1016); return rv; } } while (false)
;
1017 while (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(stmt->ExecuteStep
(&hasResult))), 1)))
&& hasResult) {
1018 nsAutoCString name;
1019 rv = stmt->GetUTF8String(0, name);
1020 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1020); return rv; } } while (false)
;
1021 nsAutoCString query;
1022 rv = stmt->GetUTF8String(1, query);
1023 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1023); return rv; } } while (false)
;
1024 rv = conn->ExecuteSimpleSQL(query);
1025 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1025); return rv; } } while (false)
;
1026 // Copy the table contents.
1027 rv = conn->ExecuteSimpleSQL("INSERT INTO main."_ns + name +
1028 " SELECT * FROM corrupt."_ns + name);
1029 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1030 rv = conn->ExecuteSimpleSQL("INSERT INTO main."_ns + name +
1031 " SELECT * FROM corrupt."_ns + name +
1032 " ORDER BY rowid DESC"_ns);
1033 }
1034 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1034); return rv; } } while (false)
;
1035 }
1036
1037 // Recreate the indices. Doing this after data addition is faster.
1038 rv = conn->CreateStatement(
1039 nsLiteralCString(
1040 "SELECT sql FROM corrupt.sqlite_master "
1041 "WHERE type <> 'table' AND name BETWEEN 'moz_' AND 'moza'"),
1042 getter_AddRefs(stmt));
1043 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1043); return rv; } } while (false)
;
1044 hasResult = false;
1045 while (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(stmt->ExecuteStep
(&hasResult))), 1)))
&& hasResult) {
1046 nsAutoCString query;
1047 rv = stmt->GetUTF8String(0, query);
1048 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1048); return rv; } } while (false)
;
1049 rv = conn->ExecuteSimpleSQL(query);
1050 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1050); return rv; } } while (false)
;
1051 }
1052 rv = stmt->Finalize();
1053 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1053); return rv; } } while (false)
;
1054
1055 rv = transaction.Commit();
1056 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1056); return rv; } } while (false)
;
1057
1058 MOZ_ALWAYS_SUCCEEDS(conn->Close())do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(conn->Close())), 1)))), 1))) { } else { do { do { } while
(false); MOZ_ReportCrash("" "NS_SUCCEEDED(conn->Close())"
, "./../../../../toolkit/components/places/Database.cpp", 1058
); AnnotateMozCrashReason("MOZ_CRASH(" "NS_SUCCEEDED(conn->Close())"
")"); do { MOZ_CrashSequence(__null, 1058); __attribute__((nomerge
)) ::abort(); } while (false); } while (false); } } while (false
)
;
1059 conn = nullptr;
1060 rv = recoverFile->RenameTo(nullptr, filename);
1061 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1061); return rv; } } while (false)
;
1062
1063 RemoveFileSwallowsErrors(corruptFile);
1064 RemoveFileSwallowsErrors(corruptFile, u"-wal"_ns);
1065 RemoveFileSwallowsErrors(corruptFile, u"-shm"_ns);
1066
1067 guard.release();
1068 return NS_OK;
1069}
1070
1071nsresult Database::SetupDatabaseConnection(
1072 nsCOMPtr<mozIStorageService>& aStorage) {
1073 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../../toolkit/components/places/Database.cpp", 1073
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { MOZ_CrashSequence(__null, 1073); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1074
1075 // Using immediate transactions allows the main connection to retry writes
1076 // that fail with `SQLITE_BUSY` because a cloned connection has locked the
1077 // database for writing.
1078 nsresult rv = mMainConn->SetDefaultTransactionType(
1079 mozIStorageConnection::TRANSACTION_IMMEDIATE);
1080 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1080); return rv; } } while (false)
;
1081
1082 // WARNING: any statement executed before setting the journal mode must be
1083 // finalized, since SQLite doesn't allow changing the journal mode if there
1084 // is any outstanding statement.
1085
1086 {
1087 // Get the page size. This may be different than the default if the
1088 // database file already existed with a different page size.
1089 nsCOMPtr<mozIStorageStatement> statement;
1090 rv = mMainConn->CreateStatement(
1091 nsLiteralCString(MOZ_STORAGE_UNIQUIFY_QUERY_STR"/* " "./../../../../toolkit/components/places/Database.cpp" " */ " "PRAGMA page_size"),
1092 getter_AddRefs(statement));
1093 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1093); return rv; } } while (false)
;
1094 bool hasResult = false;
1095 rv = statement->ExecuteStep(&hasResult);
1096 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1096); return rv; } } while (false)
;
1097 NS_ENSURE_TRUE(hasResult, NS_ERROR_FILE_CORRUPTED)do { if ((__builtin_expect(!!(!(hasResult)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "hasResult" ") failed", nullptr
, "./../../../../toolkit/components/places/Database.cpp", 1097
); return NS_ERROR_FILE_CORRUPTED; } } while (false)
;
1098 rv = statement->GetInt32(0, &mDBPageSize);
1099 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1099); return rv; } } while (false)
;
1100 NS_ENSURE_TRUE(mDBPageSize > 0, NS_ERROR_FILE_CORRUPTED)do { if ((__builtin_expect(!!(!(mDBPageSize > 0)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "mDBPageSize > 0" ") failed"
, nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1100); return NS_ERROR_FILE_CORRUPTED; } } while (false)
;
1101 }
1102
1103#if !defined(HAVE_64BIT_BUILD1)
1104 // Ensure that temp tables are held in memory, not on disk, on 32 bit
1105 // platforms.
1106 rv = mMainConn->ExecuteSimpleSQL(nsLiteralCString(
1107 MOZ_STORAGE_UNIQUIFY_QUERY_STR"/* " "./../../../../toolkit/components/places/Database.cpp" " */ " "PRAGMA temp_store = MEMORY"));
1108 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1108); return rv; } } while (false)
;
1109#endif
1110
1111 rv = SetupDurability(mMainConn, mDBPageSize);
1112 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1112); return rv; } } while (false)
;
1113
1114 nsAutoCString busyTimeoutPragma("PRAGMA busy_timeout = ");
1115 busyTimeoutPragma.AppendInt(DATABASE_BUSY_TIMEOUT_MS100);
1116 (void)mMainConn->ExecuteSimpleSQL(busyTimeoutPragma);
1117
1118 // Enable FOREIGN KEY support. This is a strict requirement.
1119 rv = mMainConn->ExecuteSimpleSQL(nsLiteralCString(
1120 MOZ_STORAGE_UNIQUIFY_QUERY_STR"/* " "./../../../../toolkit/components/places/Database.cpp" " */ " "PRAGMA foreign_keys = ON"));
1121 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1121); return rv; } } while (false)
;
1122#ifdef DEBUG1
1123 {
1124 // There are a few cases where setting foreign_keys doesn't work:
1125 // * in the middle of a multi-statement transaction
1126 // * if the SQLite library in use doesn't support them
1127 // Since we need foreign_keys, let's at least assert in debug mode.
1128 nsCOMPtr<mozIStorageStatement> stmt;
1129 mMainConn->CreateStatement("PRAGMA foreign_keys"_ns, getter_AddRefs(stmt));
1130 bool hasResult = false;
1131 if (stmt && NS_SUCCEEDED(stmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(stmt->ExecuteStep
(&hasResult))), 1)))
&& hasResult) {
1132 int32_t fkState = stmt->AsInt32(0);
1133 MOZ_ASSERT(fkState, "Foreign keys should be enabled")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(fkState)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(fkState))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("fkState" " (" "Foreign keys should be enabled"
")", "./../../../../toolkit/components/places/Database.cpp",
1133); AnnotateMozCrashReason("MOZ_ASSERT" "(" "fkState" ") ("
"Foreign keys should be enabled" ")"); do { MOZ_CrashSequence
(__null, 1133); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1134 }
1135 }
1136#endif
1137
1138 // Note: attaching new databases may require updating `ConcurrentConnection`.
1139
1140 // Attach the favicons database to the main connection.
1141 rv = EnsureFaviconsDatabaseAttached(aStorage);
1142 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1143 if (rv != NS_ERROR_FILE_CORRUPTED) {
1144 // The failure is not due to corruption; retry once before giving up.
1145 rv = EnsureFaviconsDatabaseAttached(aStorage);
1146 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1146); return rv; } } while (false)
;
1147 } else {
1148 // The favicons database is corrupt.
1149 // Set last corruption time in prefs for troubleshooting.
1150 CheckedInt<int32_t> daysSinceEpoch = GetNow() / USEC_PER_DAY86400000000LL;
1151 if (daysSinceEpoch.isValid()) {
1152 Preferences::SetInt(PREF_DATABASE_FAVICONS_LASTCORRUPTION"places.database.lastFaviconsCorruptionInDaysFromEpoch",
1153 daysSinceEpoch.value());
1154 }
1155
1156 // Replace and reattach it.
1157 nsCOMPtr<nsIFile> iconsFile;
1158 rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR"ProfD",
1159 getter_AddRefs(iconsFile));
1160 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1160); return rv; } } while (false)
;
1161 rv = iconsFile->Append(DATABASE_FAVICONS_FILENAMEu"favicons.sqlite"_ns);
1162 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1162); return rv; } } while (false)
;
1163 rv = iconsFile->Remove(false);
1164 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) && rv != NS_ERROR_FILE_NOT_FOUND) {
1165 return rv;
1166 }
1167 rv = EnsureFaviconsDatabaseAttached(aStorage);
1168 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1168); return rv; } } while (false)
;
1169 }
1170 }
1171
1172 // Create favicons temp entities.
1173 rv = mMainConn->ExecuteSimpleSQL(CREATE_ICONS_AFTERINSERT_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_icons_afterinsert_v1_trigger "
"AFTER INSERT ON moz_icons FOR EACH ROW " "BEGIN " "SELECT store_last_inserted_id('moz_icons', NEW.id); "
"END")
);
1174 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1174); return rv; } } while (false)
;
1175
1176 // We use our functions during migration, so initialize them now.
1177 rv = InitFunctions(mMainConn);
1178 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1178); return rv; } } while (false)
;
1179
1180 return NS_OK;
1181}
1182
1183nsresult Database::InitSchema(bool* aDatabaseMigrated) {
1184 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../../toolkit/components/places/Database.cpp", 1184
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { MOZ_CrashSequence(__null, 1184); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1185 *aDatabaseMigrated = false;
1186
1187 // Get the database schema version.
1188 int32_t currentSchemaVersion;
1189 nsresult rv = mMainConn->GetSchemaVersion(&currentSchemaVersion);
1190 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1190); return rv; } } while (false)
;
1191 bool databaseInitialized = currentSchemaVersion > 0;
1192
1193 if (databaseInitialized &&
1194 currentSchemaVersion == nsINavHistoryService::DATABASE_SCHEMA_VERSION) {
1195 // The database is up to date and ready to go.
1196 return NS_OK;
1197 }
1198
1199 // We are going to update the database, so everything from now on should be in
1200 // a transaction for performances.
1201 mozStorageTransaction transaction(mMainConn, false);
1202
1203 // XXX Handle the error, bug 1696133.
1204 (void)NS_WARN_IF(NS_FAILED(transaction.Start()))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(transaction
.Start())), 0))), "NS_FAILED(transaction.Start())", "./../../../../toolkit/components/places/Database.cpp"
, 1204)
;
1205
1206 if (databaseInitialized) {
1207 // Migration How-to:
1208 //
1209 // 1. increment PLACES_SCHEMA_VERSION.
1210 // 2. implement a method that performs upgrade to your version from the
1211 // previous one.
1212 //
1213 // NOTE: The downgrade process is pretty much complicated by the fact old
1214 // versions cannot know what a new version is going to implement.
1215 // The only thing we will do for downgrades is setting back the schema
1216 // version, so that next upgrades will run again the migration step.
1217
1218 if (currentSchemaVersion < nsINavHistoryService::DATABASE_SCHEMA_VERSION) {
1219 *aDatabaseMigrated = true;
1220
1221 if (currentSchemaVersion < 52) {
1222 // These are versions older than Firefox 68 ESR that are not supported
1223 // anymore. In this case it's safer to just replace the database.
1224 return NS_ERROR_FILE_CORRUPTED;
1225 }
1226
1227 // Firefox 62 uses schema version 52.
1228 // Firefox 68 uses schema version 52. - This is an ESR.
1229
1230 if (currentSchemaVersion < 53) {
1231 rv = MigrateV53Up();
1232 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1232); return rv; } } while (false)
;
1233 }
1234
1235 // Firefox 69 uses schema version 53
1236 // Firefox 72 is a watershed release.
1237
1238 if (currentSchemaVersion < 54) {
1239 rv = MigrateV54Up();
1240 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1240); return rv; } } while (false)
;
1241 }
1242
1243 // Firefox 81 uses schema version 54
1244
1245 if (currentSchemaVersion < 55) {
1246 rv = MigrateV55Up();
1247 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1247); return rv; } } while (false)
;
1248 }
1249
1250 if (currentSchemaVersion < 56) {
1251 rv = MigrateV56Up();
1252 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1252); return rv; } } while (false)
;
1253 }
1254
1255 if (currentSchemaVersion < 57) {
1256 rv = MigrateV57Up();
1257 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1257); return rv; } } while (false)
;
1258 }
1259
1260 // Firefox 91 uses schema version 57
1261
1262 // The schema 58 migration is no longer needed.
1263
1264 // Firefox 92 uses schema version 58
1265
1266 // The schema 59 migration is no longer needed.
1267
1268 // Firefox 94 uses schema version 59
1269
1270 if (currentSchemaVersion < 60) {
1271 rv = MigrateV60Up();
1272 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1272); return rv; } } while (false)
;
1273 }
1274
1275 // Firefox 96 uses schema version 60
1276
1277 if (currentSchemaVersion < 61) {
1278 rv = MigrateV61Up();
1279 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1279); return rv; } } while (false)
;
1280 }
1281
1282 // The schema 62 migration is no longer needed.
1283
1284 // Firefox 97 uses schema version 62
1285
1286 // The schema 63 migration is no longer needed.
1287
1288 // Firefox 98 uses schema version 63
1289
1290 // The schema 64 migration is no longer needed.
1291
1292 // Firefox 99 uses schema version 64
1293
1294 // The schema 65 migration is no longer needed.
1295
1296 // The schema 66 migration is no longer needed.
1297
1298 // Firefox 100 uses schema version 66
1299
1300 if (currentSchemaVersion < 67) {
1301 rv = MigrateV67Up();
1302 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1302); return rv; } } while (false)
;
1303 }
1304
1305 // The schema 68 migration is no longer needed.
1306
1307 // Firefox 103 uses schema version 68
1308
1309 if (currentSchemaVersion < 69) {
1310 rv = MigrateV69Up();
1311 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1311); return rv; } } while (false)
;
1312 }
1313
1314 // Firefox 104 uses schema version 69
1315
1316 if (currentSchemaVersion < 70) {
1317 rv = MigrateV70Up();
1318 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1318); return rv; } } while (false)
;
1319 }
1320
1321 if (currentSchemaVersion < 71) {
1322 rv = MigrateV71Up();
1323 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1323); return rv; } } while (false)
;
1324 }
1325
1326 // Firefox 110 uses schema version 71
1327
1328 if (currentSchemaVersion < 72) {
1329 rv = MigrateV72Up();
1330 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1330); return rv; } } while (false)
;
1331 }
1332
1333 // Firefox 111 uses schema version 72
1334
1335 if (currentSchemaVersion < 73) {
1336 rv = MigrateV73Up();
1337 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1337); return rv; } } while (false)
;
1338 }
1339
1340 // Firefox 114 uses schema version 73
1341
1342 if (currentSchemaVersion < 74) {
1343 rv = MigrateV74Up();
1344 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1344); return rv; } } while (false)
;
1345 }
1346
1347 // Firefox 115 uses schema version 74
1348
1349 if (currentSchemaVersion < 75) {
1350 rv = MigrateV75Up();
1351 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1351); return rv; } } while (false)
;
1352 }
1353
1354 // Firefox 118 uses schema version 75
1355
1356 // Version 76 was not correctly invoked and thus removed.
1357
1358 if (currentSchemaVersion < 77) {
1359 rv = MigrateV77Up();
1360 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1360); return rv; } } while (false)
;
1361 }
1362
1363 // Firefox 125 uses schema version 77
1364
1365 if (currentSchemaVersion < 78) {
1366 rv = MigrateV78Up();
1367 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1367); return rv; } } while (false)
;
1368 }
1369
1370 // Firefox 132 uses schema version 78
1371
1372 if (currentSchemaVersion < 79) {
1373 rv = MigrateV79Up();
1374 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1374); return rv; } } while (false)
;
1375 }
1376
1377 // Firefox 140 uses schema version 79
1378
1379 if (currentSchemaVersion < 80) {
1380 rv = MigrateV80Up();
1381 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1381); return rv; } } while (false)
;
1382 }
1383
1384 // Firefox 140 uses schema version 80
1385
1386 if (currentSchemaVersion < 81) {
1387 rv = MigrateV81Up();
1388 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1388); return rv; } } while (false)
;
1389 }
1390
1391 if (currentSchemaVersion < 82) {
1392 rv = MigrateV82Up();
1393 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1393); return rv; } } while (false)
;
1394 }
1395
1396 // Firefox 141 uses schema version 82
1397
1398 if (currentSchemaVersion < 83) {
1399 rv = MigrateV83Up();
1400 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1400); return rv; } } while (false)
;
1401 }
1402
1403 // The schema 84 migration was the same as 85, we had to re-run it to
1404 // correct issues with origin frecency.
1405
1406 // Firefox 147 uses schema version 84
1407
1408 if (currentSchemaVersion < 85) {
1409 rv = MigrateV85Up();
1410 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1410); return rv; } } while (false)
;
1411 }
1412
1413 // Firefox 148 uses schema version 85
1414
1415 if (currentSchemaVersion < 86) {
1416 rv = MigrateV86Up();
1417 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1417); return rv; } } while (false)
;
1418 }
1419
1420 // Firefox 150 uses schema version 86
1421
1422 if (currentSchemaVersion < 87) {
1423 rv = MigrateV87Up();
1424 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1424); return rv; } } while (false)
;
1425 }
1426
1427 // Firefox 155 uses schema version 87
1428
1429 // Schema Upgrades must add migration code here.
1430 // >>> IMPORTANT! <<<
1431 // NEVER MIX UP SYNC AND ASYNC EXECUTION IN MIGRATORS, YOU MAY LOCK THE
1432 // CONNECTION AND CAUSE FURTHER STEPS TO FAIL.
1433 // In case, set a bool and do the async work in the ScopeExit guard just
1434 // before the migration steps.
1435 }
1436 } else {
1437 // This is a new database, so we have to create all the tables and indices.
1438
1439 // moz_origins.
1440 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_ORIGINSnsLiteralCString( "CREATE TABLE moz_origins ( " "id INTEGER PRIMARY KEY, "
"prefix TEXT NOT NULL, " "host TEXT NOT NULL, " "frecency INTEGER NOT NULL, "
"recalc_frecency INTEGER NOT NULL DEFAULT 0, " "alt_frecency INTEGER, "
"recalc_alt_frecency INTEGER NOT NULL DEFAULT 0, " "block_until_ms INTEGER, "
"block_pages_until_ms INTEGER, " "UNIQUE (host, prefix) " ")"
)
);
1441 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1441); return rv; } } while (false)
;
1442
1443 // moz_places.
1444 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_PLACESnsLiteralCString( "CREATE TABLE moz_places ( " " id INTEGER PRIMARY KEY"
", url LONGVARCHAR" ", title LONGVARCHAR" ", rev_host LONGVARCHAR"
", visit_count INTEGER DEFAULT 0" ", hidden INTEGER DEFAULT 0 NOT NULL"
", typed INTEGER DEFAULT 0 NOT NULL" ", frecency INTEGER DEFAULT -1 NOT NULL"
", last_visit_date INTEGER " ", guid TEXT" ", foreign_count INTEGER DEFAULT 0 NOT NULL"
", url_hash INTEGER DEFAULT 0 NOT NULL " ", description TEXT"
", preview_image_url TEXT" ", site_name TEXT" ", origin_id INTEGER REFERENCES moz_origins(id)"
", recalc_frecency INTEGER NOT NULL DEFAULT 0" ", alt_frecency INTEGER"
", recalc_alt_frecency INTEGER NOT NULL DEFAULT 0" ")")
);
1445 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1445); return rv; } } while (false)
;
1446 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_PLACES_EXTRAnsLiteralCString( "CREATE TABLE moz_places_extra (" " place_id INTEGER PRIMARY KEY NOT NULL"
", sync_json TEXT" ", FOREIGN KEY (place_id) REFERENCES moz_places(id) ON DELETE CASCADE "
")")
);
1447 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1447); return rv; } } while (false)
;
1448 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_URL_HASHnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_places"
"_" "url_hashindex" " ON " "moz_places" " (" "url_hash" ")")
);
1449 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1449); return rv; } } while (false)
;
1450 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_REVHOSTnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_places"
"_" "hostindex" " ON " "moz_places" " (" "rev_host" ")")
);
1451 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1451); return rv; } } while (false)
;
1452 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_VISITCOUNTnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_places"
"_" "visitcount" " ON " "moz_places" " (" "visit_count" ")")
);
1453 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1453); return rv; } } while (false)
;
1454 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_FRECENCYnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_places"
"_" "frecencyindex" " ON " "moz_places" " (" "frecency" ")")
);
1455 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1455); return rv; } } while (false)
;
1456 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_LASTVISITDATEnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_places"
"_" "lastvisitdateindex" " ON " "moz_places" " (" "last_visit_date"
")")
);
1457 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1457); return rv; } } while (false)
;
1458 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_GUIDnsLiteralCString("CREATE " "UNIQUE" " INDEX IF NOT EXISTS " "moz_places"
"_" "guid_uniqueindex" " ON " "moz_places" " (" "guid" ")")
);
1459 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1459); return rv; } } while (false)
;
1460 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_ORIGIN_IDnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_places"
"_" "originidindex" " ON " "moz_places" " (" "origin_id" ")"
)
);
1461 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1461); return rv; } } while (false)
;
1462 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_ALT_FRECENCYnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_places"
"_" "altfrecencyindex" " ON " "moz_places" " (" "alt_frecency"
")")
);
1463 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1463); return rv; } } while (false)
;
1464
1465 // moz_historyvisits.
1466 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_HISTORYVISITSnsLiteralCString( "CREATE TABLE moz_historyvisits (" " id INTEGER PRIMARY KEY"
", from_visit INTEGER" ", place_id INTEGER" ", visit_date INTEGER"
", visit_type INTEGER" ", session INTEGER" ", source INTEGER DEFAULT 0 NOT NULL"
", triggeringPlaceId INTEGER" ")")
);
1467 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1467); return rv; } } while (false)
;
1468 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_HISTORYVISITS_EXTRAnsLiteralCString( "CREATE TABLE moz_historyvisits_extra (" " visit_id INTEGER PRIMARY KEY NOT NULL"
", sync_json TEXT" ", FOREIGN KEY (visit_id) REFERENCES moz_historyvisits(id) ON "
" DELETE CASCADE" ")")
);
1469 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1469); return rv; } } while (false)
;
1470 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_PLACEDATEnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_historyvisits"
"_" "placedateindex" " ON " "moz_historyvisits" " (" "place_id, visit_date"
")")
);
1471 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1471); return rv; } } while (false)
;
1472 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_FROMVISITnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_historyvisits"
"_" "fromindex" " ON " "moz_historyvisits" " (" "from_visit"
")")
);
1473 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1473); return rv; } } while (false)
;
1474 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_VISITDATEnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_historyvisits"
"_" "dateindex" " ON " "moz_historyvisits" " (" "visit_date"
")")
);
1475 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1475); return rv; } } while (false)
;
1476
1477 // moz_inputhistory.
1478 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_INPUTHISTORYnsLiteralCString( "CREATE TABLE moz_inputhistory (" " place_id INTEGER NOT NULL"
", input LONGVARCHAR NOT NULL" ", use_count INTEGER" ", PRIMARY KEY (place_id, input)"
")")
);
1479 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1479); return rv; } } while (false)
;
1480
1481 // moz_bookmarks.
1482 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_BOOKMARKSnsLiteralCString( "CREATE TABLE moz_bookmarks (" " id INTEGER PRIMARY KEY"
", type INTEGER" ", fk INTEGER DEFAULT NULL" ", parent INTEGER"
", position INTEGER" ", title LONGVARCHAR" ", keyword_id INTEGER"
", folder_type TEXT" ", dateAdded INTEGER" ", lastModified INTEGER"
", guid TEXT" ", syncStatus INTEGER NOT NULL DEFAULT 0" ", syncChangeCounter INTEGER NOT NULL DEFAULT 1"
")")
);
1483 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1483); return rv; } } while (false)
;
1484 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_BOOKMARKS_DELETEDnsLiteralCString( "CREATE TABLE moz_bookmarks_deleted (" " guid TEXT PRIMARY KEY"
", dateRemoved INTEGER NOT NULL DEFAULT 0" ")")
);
1485 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1485); return rv; } } while (false)
;
1486 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_BOOKMARKS_PLACETYPEnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_bookmarks"
"_" "itemindex" " ON " "moz_bookmarks" " (" "fk, type" ")")
);
1487 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1487); return rv; } } while (false)
;
1488 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_BOOKMARKS_PARENTPOSITIONnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_bookmarks"
"_" "parentindex" " ON " "moz_bookmarks" " (" "parent, position"
")")
);
1489 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1489); return rv; } } while (false)
;
1490 rv =
1491 mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_BOOKMARKS_PLACELASTMODIFIEDnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_bookmarks"
"_" "itemlastmodifiedindex" " ON " "moz_bookmarks" " (" "fk, lastModified"
")")
);
1492 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1492); return rv; } } while (false)
;
1493 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_BOOKMARKS_DATEADDEDnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_bookmarks"
"_" "dateaddedindex" " ON " "moz_bookmarks" " (" "dateAdded"
")")
);
1494 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1494); return rv; } } while (false)
;
1495 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_BOOKMARKS_GUIDnsLiteralCString("CREATE " "UNIQUE" " INDEX IF NOT EXISTS " "moz_bookmarks"
"_" "guid_uniqueindex" " ON " "moz_bookmarks" " (" "guid" ")"
)
);
1496 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1496); return rv; } } while (false)
;
1497
1498 // moz_keywords.
1499 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_KEYWORDSnsLiteralCString( "CREATE TABLE moz_keywords (" " id INTEGER PRIMARY KEY AUTOINCREMENT"
", keyword TEXT UNIQUE" ", place_id INTEGER" ", post_data TEXT"
")")
);
1500 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1500); return rv; } } while (false)
;
1501 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_KEYWORDS_PLACEPOSTDATAnsLiteralCString("CREATE " "UNIQUE" " INDEX IF NOT EXISTS " "moz_keywords"
"_" "placepostdata_uniqueindex" " ON " "moz_keywords" " (" "place_id, post_data"
")")
);
1502 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1502); return rv; } } while (false)
;
1503
1504 // moz_anno_attributes.
1505 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_ANNO_ATTRIBUTESnsLiteralCString( "CREATE TABLE moz_anno_attributes (" " id INTEGER PRIMARY KEY"
", name VARCHAR(32) UNIQUE NOT NULL" ")")
);
1506 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1506); return rv; } } while (false)
;
1507
1508 // moz_annos.
1509 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_ANNOSnsLiteralCString( "CREATE TABLE moz_annos (" " id INTEGER PRIMARY KEY"
", place_id INTEGER NOT NULL" ", anno_attribute_id INTEGER" ", content LONGVARCHAR"
", flags INTEGER DEFAULT 0" ", expiration INTEGER DEFAULT 0"
", type INTEGER DEFAULT 0" ", dateAdded INTEGER DEFAULT 0" ", lastModified INTEGER DEFAULT 0"
")")
);
1510 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1510); return rv; } } while (false)
;
1511 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_ANNOS_PLACEATTRIBUTEnsLiteralCString("CREATE " "UNIQUE" " INDEX IF NOT EXISTS " "moz_annos"
"_" "placeattributeindex" " ON " "moz_annos" " (" "place_id, anno_attribute_id"
")")
);
1512 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1512); return rv; } } while (false)
;
1513
1514 // moz_items_annos.
1515 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_ITEMS_ANNOSnsLiteralCString( "CREATE TABLE moz_items_annos (" " id INTEGER PRIMARY KEY"
", item_id INTEGER NOT NULL" ", anno_attribute_id INTEGER" ", content LONGVARCHAR"
", flags INTEGER DEFAULT 0" ", expiration INTEGER DEFAULT 0"
", type INTEGER DEFAULT 0" ", dateAdded INTEGER DEFAULT 0" ", lastModified INTEGER DEFAULT 0"
")")
);
1516 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1516); return rv; } } while (false)
;
1517 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_ITEMSANNOS_PLACEATTRIBUTEnsLiteralCString("CREATE " "UNIQUE" " INDEX IF NOT EXISTS " "moz_items_annos"
"_" "itemattributeindex" " ON " "moz_items_annos" " (" "item_id, anno_attribute_id"
")")
);
1518 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1518); return rv; } } while (false)
;
1519
1520 // moz_meta.
1521 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_METAnsLiteralCString( "CREATE TABLE moz_meta (" "key TEXT PRIMARY KEY, "
"value NOT NULL" ") WITHOUT ROWID ")
);
1522 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1522); return rv; } } while (false)
;
1523
1524 // moz_places_metadata
1525 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_PLACES_METADATAnsLiteralCString( "CREATE TABLE moz_places_metadata (" "id INTEGER PRIMARY KEY, "
"place_id INTEGER NOT NULL, " "referrer_place_id INTEGER, " "created_at INTEGER NOT NULL DEFAULT 0, "
"updated_at INTEGER NOT NULL DEFAULT 0, " "total_view_time INTEGER NOT NULL DEFAULT 0, "
"typing_time INTEGER NOT NULL DEFAULT 0, " "key_presses INTEGER NOT NULL DEFAULT 0, "
"scrolling_time INTEGER NOT NULL DEFAULT 0, " "scrolling_distance INTEGER NOT NULL DEFAULT 0, "
"document_type INTEGER NOT NULL DEFAULT 0, " "search_query_id INTEGER, "
"FOREIGN KEY (place_id) REFERENCES moz_places(id) ON DELETE CASCADE, "
"FOREIGN KEY (referrer_place_id) REFERENCES moz_places(id) ON DELETE "
"CASCADE, " "FOREIGN KEY(search_query_id) REFERENCES " "moz_places_metadata_search_queries(id) ON DELETE CASCADE "
"CHECK(place_id != referrer_place_id) " ")")
);
1526 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1526); return rv; } } while (false)
;
1527 rv = mMainConn->ExecuteSimpleSQL(
1528 CREATE_IDX_MOZ_PLACES_METADATA_PLACECREATEDnsLiteralCString("CREATE " "UNIQUE" " INDEX IF NOT EXISTS " "moz_places_metadata"
"_" "placecreated_uniqueindex" " ON " "moz_places_metadata" " ("
"place_id, created_at" ")")
);
1529 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1529); return rv; } } while (false)
;
1530 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_METADATA_REFERRERnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_places_metadata"
"_" "referrerindex" " ON " "moz_places_metadata" " (" "referrer_place_id"
")")
);
1531 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1531); return rv; } } while (false)
;
1532
1533 // moz_places_metadata_search_queries
1534 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_PLACES_METADATA_SEARCH_QUERIESnsLiteralCString( "CREATE TABLE IF NOT EXISTS moz_places_metadata_search_queries ( "
"id INTEGER PRIMARY KEY, " "terms TEXT NOT NULL UNIQUE " ")"
)
);
1535 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1535); return rv; } } while (false)
;
1536
1537 // moz_previews_tombstones
1538 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_PREVIEWS_TOMBSTONESnsLiteralCString( "CREATE TABLE IF NOT EXISTS moz_previews_tombstones ( "
" hash TEXT PRIMARY KEY " ") WITHOUT ROWID")
);
1539 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1539); return rv; } } while (false)
;
1540
1541 // moz_newtab_story
1542 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_NEWTAB_STORY_CLICKnsLiteralCString( "CREATE TABLE moz_newtab_story_click ( " " feature TEXT NOT NULL, "
" timestamp_s INTEGER NOT NULL, " " card_format_enum INTEGER NOT NULL, "
" position INTEGER NOT NULL, " " section_position INTEGER NOT NULL, "
" feature_value REAL NOT NULL DEFAULT 1 " ")")
);
1543 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1543); return rv; } } while (false)
;
1544 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_NEWTAB_STORY_IMPRESSIONnsLiteralCString( "CREATE TABLE moz_newtab_story_impression ( "
" feature TEXT NOT NULL, " " timestamp_s INTEGER NOT NULL, "
" card_format_enum INTEGER NOT NULL, " " position INTEGER NOT NULL, "
" section_position INTEGER NOT NULL, " " feature_value REAL NOT NULL DEFAULT 1 "
")")
);
1545 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1545); return rv; } } while (false)
;
1546 // Add newtab_story timestamp index.
1547 rv = mMainConn->ExecuteSimpleSQL(
1548 CREATE_IDX_MOZ_NEWTAB_STORY_CLICK_TIMESTAMPnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_newtab_story_click"
"_" "newtab_click_timestampindex" " ON " "moz_newtab_story_click"
" (" "timestamp_s" ")")
);
1549 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1549); return rv; } } while (false)
;
1550 rv =
1551 mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_NEWTAB_IMPRESSION_TIMESTAMPnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_newtab_story_impression"
"_" "newtab_impression_timestampindex" " ON " "moz_newtab_story_impression"
" (" "timestamp_s" ")")
);
1552 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1552); return rv; } } while (false)
;
1553
1554 // moz_newtab_shortcuts_interaction
1555 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_NEWTAB_SHORTCUTS_INTERACTIONnsLiteralCString( "CREATE TABLE moz_newtab_shortcuts_interaction ( "
" id INTEGER PRIMARY KEY, " " place_id INTEGER NOT NULL REFERENCES moz_places(id) ON DELETE "
"CASCADE, " " event_type INTEGER NOT NULL, " " timestamp_s INTEGER NOT NULL, "
" pinned INTEGER NOT NULL CHECK (pinned IN (0, 1)), " " tile_position INTEGER NOT NULL"
")")
);
1556 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1556); return rv; } } while (false)
;
1557 // Add moz_newtab_shortcuts_interaction timestamp index.
1558 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_NEWTAB_SHORTCUTS_TIMESTAMPnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_newtab_shortcuts_interaction"
"_" "timestampindex" " ON " "moz_newtab_shortcuts_interaction"
" (" "timestamp_s" ")")
);
1559 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1559); return rv; } } while (false)
;
1560 // Add moz_newtab_shortcuts_interaction place_id index
1561 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_NEWTAB_SHORTCUTS_PLACEIDnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_newtab_shortcuts_interaction"
"_" "placeidindex" " ON " "moz_newtab_shortcuts_interaction"
" (" "place_id" ")")
);
1562 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1562); return rv; } } while (false)
;
1563
1564 // The bookmarks roots get initialized in CheckRoots().
1565 }
1566
1567 // Set the schema version to the current one.
1568 rv = mMainConn->SetSchemaVersion(
1569 nsINavHistoryService::DATABASE_SCHEMA_VERSION);
1570 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1570); return rv; } } while (false)
;
1571
1572 rv = transaction.Commit();
1573 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1573); return rv; } } while (false)
;
1574
1575 // ANY FAILURE IN THIS METHOD WILL CAUSE US TO MARK THE DATABASE AS CORRUPT
1576 // AND TRY TO REPLACE IT.
1577 // DO NOT PUT HERE ANYTHING THAT IS NOT RELATED TO INITIALIZATION OR MODIFYING
1578 // THE DISK DATABASE.
1579
1580 return NS_OK;
1581}
1582
1583nsresult Database::CheckRoots() {
1584 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../../toolkit/components/places/Database.cpp", 1584
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { MOZ_CrashSequence(__null, 1584); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1585
1586 // If the database has just been created, skip straight to the part where
1587 // we create the roots.
1588 if (mDatabaseStatus == nsINavHistoryService::DATABASE_STATUS_CREATE) {
1589 return EnsureBookmarkRoots(0, /* shouldReparentRoots */ false);
1590 }
1591
1592 nsCOMPtr<mozIStorageStatement> stmt;
1593 nsresult rv = mMainConn->CreateStatement(
1594 nsLiteralCString("SELECT guid, id, position, parent FROM moz_bookmarks "
1595 "WHERE guid IN ( "
1596 "'" ROOT_GUID"root________" "', '" MENU_ROOT_GUID"menu________"
1597 "', '" TOOLBAR_ROOT_GUID"toolbar_____" "', "
1598 "'" TAGS_ROOT_GUID"tags________" "', '" UNFILED_ROOT_GUID"unfiled_____"
1599 "', '" MOBILE_ROOT_GUID"mobile______" "' )"),
1600 getter_AddRefs(stmt));
1601 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1601); return rv; } } while (false)
;
1602
1603 bool hasResult;
1604 nsAutoCString guid;
1605 int32_t maxPosition = 0;
1606 bool shouldReparentRoots = false;
1607 while (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(stmt->ExecuteStep
(&hasResult))), 1)))
&& hasResult) {
1608 rv = stmt->GetUTF8String(0, guid);
1609 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1609); return rv; } } while (false)
;
1610
1611 int64_t parentId = stmt->AsInt64(3);
1612
1613 if (guid.EqualsLiteral(ROOT_GUID"root________")) {
1614 mRootId = stmt->AsInt64(1);
1615 shouldReparentRoots |= parentId != 0;
1616 } else {
1617 maxPosition = std::max(stmt->AsInt32(2), maxPosition);
1618
1619 if (guid.EqualsLiteral(MENU_ROOT_GUID"menu________")) {
1620 mMenuRootId = stmt->AsInt64(1);
1621 } else if (guid.EqualsLiteral(TOOLBAR_ROOT_GUID"toolbar_____")) {
1622 mToolbarRootId = stmt->AsInt64(1);
1623 } else if (guid.EqualsLiteral(TAGS_ROOT_GUID"tags________")) {
1624 mTagsRootId = stmt->AsInt64(1);
1625 } else if (guid.EqualsLiteral(UNFILED_ROOT_GUID"unfiled_____")) {
1626 mUnfiledRootId = stmt->AsInt64(1);
1627 } else if (guid.EqualsLiteral(MOBILE_ROOT_GUID"mobile______")) {
1628 mMobileRootId = stmt->AsInt64(1);
1629 }
1630 shouldReparentRoots |= parentId != mRootId;
1631 }
1632 }
1633
1634 rv = EnsureBookmarkRoots(maxPosition + 1, shouldReparentRoots);
1635 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1635); return rv; } } while (false)
;
1636
1637 return NS_OK;
1638}
1639
1640nsresult Database::EnsureBookmarkRoots(const int32_t startPosition,
1641 bool shouldReparentRoots) {
1642 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../../toolkit/components/places/Database.cpp", 1642
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { MOZ_CrashSequence(__null, 1642); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1643
1644 nsresult rv;
1645
1646 if (mRootId < 1) {
1647 // The first root's title is an empty string.
1648 rv = CreateRoot(mMainConn, "places"_ns, "root________"_ns, ""_ns, 0,
1649 mRootId);
1650
1651 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1652 }
1653
1654 int32_t position = startPosition;
1655
1656 // For the other roots, the UI doesn't rely on the value in the database, so
1657 // just set it to something simple to make it easier for humans to read.
1658 if (mMenuRootId < 1) {
1659 rv = CreateRoot(mMainConn, "menu"_ns, "menu________"_ns, "menu"_ns,
1660 position, mMenuRootId);
1661 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1662 position++;
1663 }
1664
1665 if (mToolbarRootId < 1) {
1666 rv = CreateRoot(mMainConn, "toolbar"_ns, "toolbar_____"_ns, "toolbar"_ns,
1667 position, mToolbarRootId);
1668 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1669 position++;
1670 }
1671
1672 if (mTagsRootId < 1) {
1673 rv = CreateRoot(mMainConn, "tags"_ns, "tags________"_ns, "tags"_ns,
1674 position, mTagsRootId);
1675 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1676 position++;
1677 }
1678
1679 if (mUnfiledRootId < 1) {
1680 rv = CreateRoot(mMainConn, "unfiled"_ns, "unfiled_____"_ns, "unfiled"_ns,
1681 position, mUnfiledRootId);
1682 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1683 position++;
1684 }
1685
1686 if (mMobileRootId < 1) {
1687 int64_t mobileRootId = CreateMobileRoot();
1688 if (mobileRootId <= 0) return NS_ERROR_FAILURE;
1689 {
1690 nsCOMPtr<mozIStorageStatement> mobileRootSyncStatusStmt;
1691 rv = mMainConn->CreateStatement(
1692 nsLiteralCString("UPDATE moz_bookmarks SET syncStatus = "
1693 ":sync_status WHERE id = :id"),
1694 getter_AddRefs(mobileRootSyncStatusStmt));
1695 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1696
1697 rv = mobileRootSyncStatusStmt->BindInt32ByName(
1698 "sync_status"_ns, nsINavBookmarksService::SYNC_STATUS_NEW);
1699 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1700 rv = mobileRootSyncStatusStmt->BindInt64ByName("id"_ns, mobileRootId);
1701 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1702
1703 rv = mobileRootSyncStatusStmt->Execute();
1704 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1705
1706 mMobileRootId = mobileRootId;
1707 }
1708 }
1709
1710 if (!shouldReparentRoots) {
1711 return NS_OK;
1712 }
1713
1714 // At least one root had the wrong parent, so we need to ensure that
1715 // all roots are parented correctly, fix their positions, and bump the
1716 // Sync change counter.
1717 rv = mMainConn->ExecuteSimpleSQL(nsLiteralCString(
1718 "CREATE TEMP TRIGGER moz_ensure_bookmark_roots_trigger "
1719 "AFTER UPDATE OF parent ON moz_bookmarks FOR EACH ROW "
1720 "WHEN OLD.parent <> NEW.parent "
1721 "BEGIN "
1722 "UPDATE moz_bookmarks SET "
1723 "syncChangeCounter = syncChangeCounter + 1 "
1724 "WHERE id IN (OLD.parent, NEW.parent, NEW.id); "
1725
1726 "UPDATE moz_bookmarks SET "
1727 "position = position - 1 "
1728 "WHERE parent = OLD.parent AND position >= OLD.position; "
1729
1730 // Fix the positions of the root's old siblings. Since we've already
1731 // moved the root, we need to exclude it from the subquery.
1732 "UPDATE moz_bookmarks SET "
1733 "position = IFNULL((SELECT MAX(position) + 1 FROM moz_bookmarks "
1734 "WHERE parent = NEW.parent AND "
1735 "id <> NEW.id), 0)"
1736 "WHERE id = NEW.id; "
1737 "END"));
1738 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1739 auto guard = MakeScopeExit([&]() {
1740 (void)mMainConn->ExecuteSimpleSQL(
1741 "DROP TRIGGER moz_ensure_bookmark_roots_trigger"_ns);
1742 });
1743
1744 nsCOMPtr<mozIStorageStatement> reparentStmt;
1745 rv = mMainConn->CreateStatement(
1746 nsLiteralCString(
1747 "UPDATE moz_bookmarks SET "
1748 "parent = CASE id WHEN :root_id THEN 0 ELSE :root_id END "
1749 "WHERE id IN (:root_id, :menu_root_id, :toolbar_root_id, "
1750 ":tags_root_id, "
1751 ":unfiled_root_id, :mobile_root_id)"),
1752 getter_AddRefs(reparentStmt));
1753 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1754
1755 rv = reparentStmt->BindInt64ByName("root_id"_ns, mRootId);
1756 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1757 rv = reparentStmt->BindInt64ByName("menu_root_id"_ns, mMenuRootId);
1758 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1759 rv = reparentStmt->BindInt64ByName("toolbar_root_id"_ns, mToolbarRootId);
1760 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1761 rv = reparentStmt->BindInt64ByName("tags_root_id"_ns, mTagsRootId);
1762 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1763 rv = reparentStmt->BindInt64ByName("unfiled_root_id"_ns, mUnfiledRootId);
1764 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1765 rv = reparentStmt->BindInt64ByName("mobile_root_id"_ns, mMobileRootId);
1766 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1767
1768 rv = reparentStmt->Execute();
1769 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1770
1771 return NS_OK;
1772}
1773
1774// static
1775nsresult Database::InitFunctions(mozIStorageConnection* aMainConn) {
1776 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../../toolkit/components/places/Database.cpp", 1776
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { MOZ_CrashSequence(__null, 1776); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1777
1778 nsresult rv = GetUnreversedHostFunction::create(aMainConn);
1779 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1779); return rv; } } while (false)
;
1780 rv = MatchAutoCompleteFunction::create(aMainConn);
1781 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1781); return rv; } } while (false)
;
1782 rv = CalculateFrecencyFunction::create(aMainConn);
1783 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1783); return rv; } } while (false)
;
1784 rv = GenerateGUIDFunction::create(aMainConn);
1785 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1785); return rv; } } while (false)
;
1786 rv = IsValidGUIDFunction::create(aMainConn);
1787 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1787); return rv; } } while (false)
;
1788 rv = FixupURLFunction::create(aMainConn);
1789 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1789); return rv; } } while (false)
;
1790 rv = StoreLastInsertedIdFunction::create(aMainConn);
1791 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1791); return rv; } } while (false)
;
1792 rv = HashFunction::create(aMainConn);
1793 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1793); return rv; } } while (false)
;
1794 rv = GetQueryParamFunction::create(aMainConn);
1795 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1795); return rv; } } while (false)
;
1796 rv = GetPrefixFunction::create(aMainConn);
1797 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1797); return rv; } } while (false)
;
1798 rv = GetHostAndPortFunction::create(aMainConn);
1799 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1799); return rv; } } while (false)
;
1800 rv = StripPrefixAndUserinfoFunction::create(aMainConn);
1801 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1801); return rv; } } while (false)
;
1802 rv = NoteSyncChangeFunction::create(aMainConn);
1803 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1803); return rv; } } while (false)
;
1804 rv = InvalidateDaysOfHistoryFunction::create(aMainConn);
1805 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1805); return rv; } } while (false)
;
1806 rv = SHA256HexFunction::create(aMainConn);
1807 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1807); return rv; } } while (false)
;
1808 rv = SetShouldStartFrecencyRecalculationFunction::create(aMainConn);
1809 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1809); return rv; } } while (false)
;
1810 rv = TargetFolderGuidFunction::create(aMainConn);
1811 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1811); return rv; } } while (false)
;
1812
1813 if (StaticPrefs::places_frecency_pages_alternative_featureGate_AtStartup()) {
1814 rv = CalculateAltFrecencyFunction::create(aMainConn);
1815 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1815); return rv; } } while (false)
;
1816 }
1817
1818 return NS_OK;
1819}
1820
1821nsresult Database::InitTempEntities() {
1822 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../../toolkit/components/places/Database.cpp", 1822
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { MOZ_CrashSequence(__null, 1822); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1823
1824 nsresult rv =
1825 mMainConn->ExecuteSimpleSQL(CREATE_HISTORYVISITS_AFTERINSERT_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_historyvisits_afterinsert_v2_trigger "
"AFTER INSERT ON moz_historyvisits FOR EACH ROW " "BEGIN " "SELECT invalidate_days_of_history();"
"SELECT store_last_inserted_id('moz_historyvisits', NEW.id); "
"UPDATE moz_places SET " "visit_count = visit_count + " "(CASE WHEN "
"NEW.visit_type" " IN (0, 4, 7, 8, 9) THEN 0 ELSE 1 END) " ", "
"recalc_frecency = 1, " "recalc_alt_frecency = 1, " "last_visit_date = MAX(IFNULL(last_visit_date, 0), NEW.visit_date) "
"WHERE id = NEW.place_id;" "END")
);
1826 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1826); return rv; } } while (false)
;
1827 rv = mMainConn->ExecuteSimpleSQL(CREATE_HISTORYVISITS_AFTERDELETE_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_historyvisits_afterdelete_v2_trigger "
"AFTER DELETE ON moz_historyvisits FOR EACH ROW " "BEGIN " "SELECT invalidate_days_of_history();"
"UPDATE moz_places SET " "visit_count = visit_count - " "(CASE WHEN "
"OLD.visit_type" " IN (0, 4, 7, 8, 9) THEN 0 ELSE 1 END) " ", "
"recalc_frecency = (frecency <> 0), " "recalc_alt_frecency = (frecency <> 0), "
"last_visit_date = (SELECT visit_date FROM moz_historyvisits "
"WHERE place_id = OLD.place_id " "ORDER BY visit_date DESC LIMIT 1) "
"WHERE id = OLD.place_id;" "END")
);
1828 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1828); return rv; } } while (false)
;
1829
1830 rv = mMainConn->ExecuteSimpleSQL(CREATE_PLACES_AFTERINSERT_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_places_afterinsert_trigger "
"AFTER INSERT ON moz_places FOR EACH ROW " "BEGIN " "SELECT store_last_inserted_id('moz_places', NEW.id); "
"INSERT INTO moz_origins " " (prefix, host, frecency, recalc_frecency, recalc_alt_frecency) "
"VALUES (get_prefix(NEW.url), get_host_and_port(NEW.url), " " NEW.frecency, 1, 1) "
"ON CONFLICT(host, prefix) DO UPDATE " " SET recalc_frecency = 1, recalc_alt_frecency = 1 "
" WHERE EXCLUDED.recalc_frecency = 0 OR " " EXCLUDED.recalc_alt_frecency = 0; "
"UPDATE moz_places SET origin_id = ( " " SELECT id " " FROM moz_origins "
" WHERE prefix = get_prefix(NEW.url) " " AND host = get_host_and_port(NEW.url) "
") " "WHERE id = NEW.id; " "END")
);
1831 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1831); return rv; } } while (false)
;
1832 rv = mMainConn->ExecuteSimpleSQL(CREATE_UPDATEORIGINSDELETE_TEMPnsLiteralCString( "CREATE TEMP TABLE moz_updateoriginsdelete_temp ( "
" prefix TEXT NOT NULL, " " host TEXT NOT NULL, " " PRIMARY KEY (prefix, host) "
") WITHOUT ROWID")
);
1833 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1833); return rv; } } while (false)
;
1834 rv = mMainConn->ExecuteSimpleSQL(
1835 CREATE_UPDATEORIGINSDELETE_AFTERDELETE_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_updateoriginsdelete_afterdelete_trigger "
"AFTER DELETE ON moz_updateoriginsdelete_temp FOR EACH ROW "
"BEGIN " "DELETE FROM moz_origins " "WHERE prefix = OLD.prefix AND host = OLD.host "
"AND NOT EXISTS ( " " SELECT id FROM moz_places " " WHERE origin_id = moz_origins.id "
"); " "END")
);
1836 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1836); return rv; } } while (false)
;
1837
1838 if (Preferences::GetBool(PREF_PREVIEWS_ENABLED"places.previews.enabled", false)) {
1839 rv = mMainConn->ExecuteSimpleSQL(
1840 CREATE_PLACES_AFTERDELETE_WPREVIEWS_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_places_afterdelete_wpreviews_trigger "
"AFTER DELETE ON moz_places FOR EACH ROW " "BEGIN " "INSERT OR IGNORE INTO moz_updateoriginsdelete_temp (prefix, host) "
"VALUES (get_prefix(OLD.url), get_host_and_port(OLD.url)); "
"UPDATE moz_origins SET recalc_frecency = 1, recalc_alt_frecency = 1 "
"WHERE id = OLD.origin_id; " "INSERT OR IGNORE INTO moz_previews_tombstones VALUES "
"(sha256hex(OLD.url));" "END ")
);
1841 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1841); return rv; } } while (false)
;
1842 } else {
1843 rv = mMainConn->ExecuteSimpleSQL(CREATE_PLACES_AFTERDELETE_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_places_afterdelete_trigger "
"AFTER DELETE ON moz_places FOR EACH ROW " "BEGIN " "INSERT OR IGNORE INTO moz_updateoriginsdelete_temp (prefix, host) "
"VALUES (get_prefix(OLD.url), get_host_and_port(OLD.url)); "
"UPDATE moz_origins SET recalc_frecency = 1, recalc_alt_frecency = 1 "
"WHERE id = OLD.origin_id; " "END ")
);
1844 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1844); return rv; } } while (false)
;
1845 }
1846
1847 rv = mMainConn->ExecuteSimpleSQL(CREATE_PLACES_AFTERUPDATE_FRECENCY_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_places_afterupdate_frecency_trigger "
"AFTER UPDATE OF frecency ON moz_places FOR EACH ROW " "BEGIN "
"UPDATE moz_places SET recalc_frecency = 0 WHERE id = NEW.id; "
"UPDATE moz_origins SET recalc_frecency = 1, recalc_alt_frecency = 1 "
"WHERE id = NEW.origin_id; " "END ")
);
1848 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1848); return rv; } } while (false)
;
1849 rv = mMainConn->ExecuteSimpleSQL(
1850 CREATE_PLACES_AFTERUPDATE_RECALC_FRECENCY_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_places_afterupdate_recalc_frecency_trigger "
"AFTER UPDATE OF recalc_frecency ON moz_places FOR EACH ROW "
"WHEN NEW.recalc_frecency = 1 " "BEGIN " " SELECT set_should_start_frecency_recalculation();"
"END")
);
1851 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1851); return rv; } } while (false)
;
1852 rv = mMainConn->ExecuteSimpleSQL(
1853 CREATE_ORIGINS_AFTERUPDATE_RECALC_FRECENCY_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_origins_afterupdate_recalc_frecency_trigger "
"AFTER UPDATE OF recalc_frecency ON moz_origins FOR EACH ROW "
"WHEN NEW.recalc_frecency = 1 " "BEGIN " " SELECT set_should_start_frecency_recalculation();"
"END")
);
1854 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1854); return rv; } } while (false)
;
1855 rv = mMainConn->ExecuteSimpleSQL(CREATE_ORIGINS_AFTERUPDATE_FRECENCY_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_origins_afterupdate_frecency_trigger "
"AFTER UPDATE OF recalc_frecency ON moz_origins FOR EACH ROW "
"WHEN NEW.frecency = 0 AND OLD.frecency > 0 " "BEGIN " "DELETE FROM moz_origins "
"WHERE id = NEW.id AND NOT EXISTS ( " " SELECT id FROM moz_places WHERE origin_id = NEW.id "
"); " "END")
);
1856 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1856); return rv; } } while (false)
;
1857
1858 rv = mMainConn->ExecuteSimpleSQL(
1859 CREATE_BOOKMARKS_FOREIGNCOUNT_AFTERDELETE_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_bookmarks_foreign_count_afterdelete_trigger "
"AFTER DELETE ON moz_bookmarks FOR EACH ROW " "BEGIN " "UPDATE moz_places "
"SET foreign_count = foreign_count - 1 " ", recalc_frecency = NOT "
" url_hash BETWEEN hash('place', 'prefix_lo') " " AND hash('place', 'prefix_hi') "
", recalc_alt_frecency = NOT " " url_hash BETWEEN hash('place', 'prefix_lo') "
" AND hash('place', 'prefix_hi') " "WHERE id = OLD.fk;"
"END")
);
1860 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1860); return rv; } } while (false)
;
1861 rv = mMainConn->ExecuteSimpleSQL(
1862 CREATE_BOOKMARKS_FOREIGNCOUNT_AFTERINSERT_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_bookmarks_foreign_count_afterinsert_trigger "
"AFTER INSERT ON moz_bookmarks FOR EACH ROW " "BEGIN " "SELECT store_last_inserted_id('moz_bookmarks', NEW.id); "
"SELECT note_sync_change() WHERE NEW.syncChangeCounter > 0; "
"UPDATE moz_places " "SET frecency = (CASE WHEN " " url_hash BETWEEN hash('place', 'prefix_lo') "
" AND hash('place', 'prefix_hi') " " THEN 0 ELSE 1 END) "
"WHERE frecency = -1 AND id = NEW.fk;" "UPDATE moz_places " "SET foreign_count = foreign_count + 1 "
", hidden = " " url_hash BETWEEN hash('place', 'prefix_lo') "
" AND hash('place', 'prefix_hi') " ", recalc_frecency = NOT "
" url_hash BETWEEN hash('place', 'prefix_lo') " " AND hash('place', 'prefix_hi') "
", recalc_alt_frecency = NOT " " url_hash BETWEEN hash('place', 'prefix_lo') "
" AND hash('place', 'prefix_hi') " "WHERE id = NEW.fk;"
"END")
);
1863 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1863); return rv; } } while (false)
;
1864 rv = mMainConn->ExecuteSimpleSQL(
1865 CREATE_BOOKMARKS_FOREIGNCOUNT_AFTERUPDATE_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_bookmarks_foreign_count_afterupdate_trigger "
"AFTER UPDATE OF fk, syncChangeCounter ON moz_bookmarks FOR EACH ROW "
"BEGIN " "SELECT note_sync_change() " "WHERE NEW.syncChangeCounter <> OLD.syncChangeCounter; "
"UPDATE moz_places " "SET foreign_count = foreign_count + 1 "
", hidden = " " url_hash BETWEEN hash('place', 'prefix_lo') "
" AND hash('place', 'prefix_hi') " ", recalc_frecency = NOT "
" url_hash BETWEEN hash('place', 'prefix_lo') " " AND hash('place', 'prefix_hi') "
", recalc_alt_frecency = NOT " " url_hash BETWEEN hash('place', 'prefix_lo') "
" AND hash('place', 'prefix_hi') " "WHERE OLD.fk <> NEW.fk AND id = NEW.fk;"
"UPDATE moz_places " "SET foreign_count = foreign_count - 1 "
", recalc_frecency = NOT " " url_hash BETWEEN hash('place', 'prefix_lo') "
" AND hash('place', 'prefix_hi') " ", recalc_alt_frecency = NOT "
" url_hash BETWEEN hash('place', 'prefix_lo') " " AND hash('place', 'prefix_hi') "
"WHERE OLD.fk <> NEW.fk AND id = OLD.fk;" "END")
);
1866 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1866); return rv; } } while (false)
;
1867
1868 rv = mMainConn->ExecuteSimpleSQL(
1869 CREATE_KEYWORDS_FOREIGNCOUNT_AFTERDELETE_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_keywords_foreign_count_afterdelete_trigger "
"AFTER DELETE ON moz_keywords FOR EACH ROW " "BEGIN " "UPDATE moz_places "
"SET foreign_count = foreign_count - 1 " "WHERE id = OLD.place_id;"
"END")
);
1870 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1870); return rv; } } while (false)
;
1871 rv = mMainConn->ExecuteSimpleSQL(
1872 CREATE_KEYWORDS_FOREIGNCOUNT_AFTERINSERT_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_keywords_foreign_count_afterinsert_trigger "
"AFTER INSERT ON moz_keywords FOR EACH ROW " "BEGIN " "UPDATE moz_places "
"SET foreign_count = foreign_count + 1 " "WHERE id = NEW.place_id;"
"END")
);
1873 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1873); return rv; } } while (false)
;
1874 rv = mMainConn->ExecuteSimpleSQL(
1875 CREATE_KEYWORDS_FOREIGNCOUNT_AFTERUPDATE_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_keywords_foreign_count_afterupdate_trigger "
"AFTER UPDATE OF place_id ON moz_keywords FOR EACH ROW " "BEGIN "
"UPDATE moz_places " "SET foreign_count = foreign_count + 1 "
"WHERE id = NEW.place_id; " "UPDATE moz_places " "SET foreign_count = foreign_count - 1 "
"WHERE id = OLD.place_id; " "END")
);
1876 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1876); return rv; } } while (false)
;
1877 rv =
1878 mMainConn->ExecuteSimpleSQL(CREATE_BOOKMARKS_DELETED_AFTERINSERT_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_bookmarks_deleted_afterinsert_v1_trigger "
"AFTER INSERT ON moz_bookmarks_deleted FOR EACH ROW " "BEGIN "
"SELECT note_sync_change(); " "END")
);
1879 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1879); return rv; } } while (false)
;
1880 rv =
1881 mMainConn->ExecuteSimpleSQL(CREATE_BOOKMARKS_DELETED_AFTERDELETE_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_bookmarks_deleted_afterdelete_v1_trigger "
"AFTER DELETE ON moz_bookmarks_deleted FOR EACH ROW " "BEGIN "
"SELECT note_sync_change(); " "END")
);
1882 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1882); return rv; } } while (false)
;
1883
1884 rv = mMainConn->ExecuteSimpleSQL(CREATE_PLACES_METADATA_AFTERDELETE_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_places_metadata_afterdelete_trigger "
"AFTER DELETE ON moz_places_metadata " "FOR EACH ROW " "BEGIN "
"DELETE FROM moz_places_metadata_search_queries " "WHERE id = OLD.search_query_id AND NOT EXISTS ("
"SELECT id FROM moz_places_metadata " "WHERE search_query_id = OLD.search_query_id "
"); " "END")
);
1885 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1885); return rv; } } while (false)
;
1886
1887 // Thresholds chosen for elevating a visit to a higher bucket.
1888 bool useAlternative =
1889 StaticPrefs::places_frecency_pages_alternative_featureGate_AtStartup();
1890 int32_t viewTimeMs =
1891 (useAlternative
1892 ? StaticPrefs::
1893 places_frecency_pages_alternative_interactions_viewTimeSeconds_AtStartup() *
1894 1000
1895 : StaticPrefs::
1896 places_frecency_pages_interactions_viewTimeSeconds_AtStartup() *
1897 1000);
1898 int32_t viewTimeIfManyKeypressesMs =
1899 (useAlternative
1900 ? StaticPrefs::
1901 places_frecency_pages_alternative_interactions_viewTimeIfManyKeypressesSeconds_AtStartup() *
1902 1000
1903 : StaticPrefs::
1904 places_frecency_pages_interactions_viewTimeIfManyKeypressesSeconds_AtStartup() *
1905 1000);
1906 int32_t manyKeypresses =
1907 (useAlternative
1908 ? StaticPrefs::
1909 places_frecency_pages_alternative_interactions_manyKeypresses_AtStartup()
1910 : StaticPrefs::
1911 places_frecency_pages_interactions_manyKeypresses_AtStartup());
1912 rv = mMainConn->ExecuteSimpleSQL(CREATE_PLACES_METADATA_AFTERINSERT_TRIGGER(nsPrintfCString( "CREATE TEMP TRIGGER moz_places_metadata_afterinsert_trigger "
"AFTER INSERT ON moz_places_metadata " "FOR EACH ROW " "WHEN NEW.total_view_time >= %d "
"OR (NEW.total_view_time >= %d " "AND NEW.key_presses >= %d) "
"BEGIN " "UPDATE moz_places " "SET recalc_frecency = 1, recalc_alt_frecency = 1 "
"WHERE id = NEW.place_id AND frecency > 0; " "END", viewTimeMs
, viewTimeIfManyKeypressesMs, manyKeypresses)
1913 viewTimeMs, viewTimeIfManyKeypressesMs, manyKeypresses)nsPrintfCString( "CREATE TEMP TRIGGER moz_places_metadata_afterinsert_trigger "
"AFTER INSERT ON moz_places_metadata " "FOR EACH ROW " "WHEN NEW.total_view_time >= %d "
"OR (NEW.total_view_time >= %d " "AND NEW.key_presses >= %d) "
"BEGIN " "UPDATE moz_places " "SET recalc_frecency = 1, recalc_alt_frecency = 1 "
"WHERE id = NEW.place_id AND frecency > 0; " "END", viewTimeMs
, viewTimeIfManyKeypressesMs, manyKeypresses)
);
1914 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1914); return rv; } } while (false)
;
1915
1916 rv = mMainConn->ExecuteSimpleSQL(CREATE_PLACES_METADATA_AFTERUPDATE_TRIGGER(nsPrintfCString( "CREATE TEMP TRIGGER moz_places_metadata_afterupdate_trigger "
"AFTER UPDATE ON moz_places_metadata " "FOR EACH ROW " "WHEN "
" (OLD.total_view_time < %d AND NEW.total_view_time >= %d) "
" OR (OLD.total_view_time < %d AND NEW.total_view_time >= %d "
" AND OLD.key_presses >= %d) " " OR (OLD.total_view_time >= %d "
" AND OLD.key_presses < %d AND NEW.key_presses >= %d) "
" OR (OLD.total_view_time < %d AND NEW.total_view_time >= %d "
" AND OLD.key_presses < %d AND NEW.key_presses >= %d) "
"BEGIN " "UPDATE moz_places " "SET recalc_frecency = 1, recalc_alt_frecency = 1 "
"WHERE id = NEW.place_id AND frecency > 0; " "END", viewTimeMs
, viewTimeMs, viewTimeIfManyKeypressesMs, viewTimeIfManyKeypressesMs
, manyKeypresses, viewTimeIfManyKeypressesMs, manyKeypresses,
manyKeypresses, viewTimeIfManyKeypressesMs, viewTimeIfManyKeypressesMs
, manyKeypresses, manyKeypresses)
1917 viewTimeMs, viewTimeIfManyKeypressesMs, manyKeypresses)nsPrintfCString( "CREATE TEMP TRIGGER moz_places_metadata_afterupdate_trigger "
"AFTER UPDATE ON moz_places_metadata " "FOR EACH ROW " "WHEN "
" (OLD.total_view_time < %d AND NEW.total_view_time >= %d) "
" OR (OLD.total_view_time < %d AND NEW.total_view_time >= %d "
" AND OLD.key_presses >= %d) " " OR (OLD.total_view_time >= %d "
" AND OLD.key_presses < %d AND NEW.key_presses >= %d) "
" OR (OLD.total_view_time < %d AND NEW.total_view_time >= %d "
" AND OLD.key_presses < %d AND NEW.key_presses >= %d) "
"BEGIN " "UPDATE moz_places " "SET recalc_frecency = 1, recalc_alt_frecency = 1 "
"WHERE id = NEW.place_id AND frecency > 0; " "END", viewTimeMs
, viewTimeMs, viewTimeIfManyKeypressesMs, viewTimeIfManyKeypressesMs
, manyKeypresses, viewTimeIfManyKeypressesMs, manyKeypresses,
manyKeypresses, viewTimeIfManyKeypressesMs, viewTimeIfManyKeypressesMs
, manyKeypresses, manyKeypresses)
);
1918 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1918); return rv; } } while (false)
;
1919
1920 // Create triggers to remove rows with empty json
1921 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_PLACES_EXTRA_AFTERUPDATE_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_places_extra_trigger "
"AFTER UPDATE ON moz_places_extra FOR EACH ROW " "WHEN (NEW.sync_json = '' OR NEW.sync_json = '{}')"
"BEGIN " "DELETE FROM moz_places_extra WHERE place_id = NEW.place_id;"
"END")
);
1922 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1922); return rv; } } while (false)
;
1923 rv =
1924 mMainConn->ExecuteSimpleSQL(CREATE_MOZ_HISTORYVISITS_AFTERUPDATE_TRIGGERnsLiteralCString( "CREATE TEMP TRIGGER moz_historyvisits_extra_trigger "
"AFTER UPDATE ON moz_historyvisits_extra FOR EACH ROW " "WHEN (NEW.sync_json = '' OR NEW.sync_json = '{}')"
"BEGIN " "DELETE FROM moz_historyvisits_extra WHERE visit_id = NEW.visit_id;"
"END")
);
1925 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1925); return rv; } } while (false)
;
1926
1927 return NS_OK;
1928}
1929
1930nsresult Database::MigrateV53Up() {
1931 nsCOMPtr<mozIStorageStatement> stmt;
1932 nsresult rv = mMainConn->CreateStatement("SELECT 1 FROM moz_items_annos"_ns,
1933 getter_AddRefs(stmt));
1934 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1935 // Likely we removed the table.
1936 return NS_OK;
1937 }
1938
1939 // Remove all item annotations but SYNC_PARENT_ANNO.
1940 rv = mMainConn->CreateStatement(
1941 nsLiteralCString(
1942 "DELETE FROM moz_items_annos "
1943 "WHERE anno_attribute_id NOT IN ( "
1944 " SELECT id FROM moz_anno_attributes WHERE name = :anno_name "
1945 ") "),
1946 getter_AddRefs(stmt));
1947 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1947); return rv; } } while (false)
;
1948 rv = stmt->BindUTF8StringByName("anno_name"_ns,
1949 nsLiteralCString(SYNC_PARENT_ANNO"sync/parent"));
1950 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1950); return rv; } } while (false)
;
1951 rv = stmt->Execute();
1952 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1952); return rv; } } while (false)
;
1953
1954 rv = mMainConn->ExecuteSimpleSQL(nsLiteralCString(
1955 "DELETE FROM moz_anno_attributes WHERE id IN ( "
1956 " SELECT id FROM moz_anno_attributes "
1957 " EXCEPT "
1958 " SELECT DISTINCT anno_attribute_id FROM moz_annos "
1959 " EXCEPT "
1960 " SELECT DISTINCT anno_attribute_id FROM moz_items_annos "
1961 ")"));
1962 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1962); return rv; } } while (false)
;
1963
1964 return NS_OK;
1965}
1966
1967nsresult Database::MigrateV54Up() {
1968 // Add an expiration column to moz_icons_to_pages.
1969 nsCOMPtr<mozIStorageStatement> stmt;
1970 nsresult rv = mMainConn->CreateStatement(
1971 "SELECT expire_ms FROM moz_icons_to_pages"_ns, getter_AddRefs(stmt));
1972 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1973 rv = mMainConn->ExecuteSimpleSQL(
1974 "ALTER TABLE moz_icons_to_pages "
1975 "ADD COLUMN expire_ms INTEGER NOT NULL DEFAULT 0 "_ns);
1976 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1976); return rv; } } while (false)
;
1977 }
1978
1979 // Set all the zero-ed entries as expired today, they won't be removed until
1980 // the next related page load.
1981 rv = mMainConn->ExecuteSimpleSQL(
1982 "UPDATE moz_icons_to_pages "
1983 "SET expire_ms = strftime('%s','now','localtime','start "
1984 "of day','utc') * 1000 "
1985 "WHERE expire_ms = 0 "_ns);
1986 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1986); return rv; } } while (false)
;
1987
1988 return NS_OK;
1989}
1990
1991nsresult Database::MigrateV55Up() {
1992 // Add places metadata tables.
1993 nsCOMPtr<mozIStorageStatement> stmt;
1994 nsresult rv = mMainConn->CreateStatement(
1995 "SELECT id FROM moz_places_metadata"_ns, getter_AddRefs(stmt));
1996 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1997 // Create the tables.
1998 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_PLACES_METADATAnsLiteralCString( "CREATE TABLE moz_places_metadata (" "id INTEGER PRIMARY KEY, "
"place_id INTEGER NOT NULL, " "referrer_place_id INTEGER, " "created_at INTEGER NOT NULL DEFAULT 0, "
"updated_at INTEGER NOT NULL DEFAULT 0, " "total_view_time INTEGER NOT NULL DEFAULT 0, "
"typing_time INTEGER NOT NULL DEFAULT 0, " "key_presses INTEGER NOT NULL DEFAULT 0, "
"scrolling_time INTEGER NOT NULL DEFAULT 0, " "scrolling_distance INTEGER NOT NULL DEFAULT 0, "
"document_type INTEGER NOT NULL DEFAULT 0, " "search_query_id INTEGER, "
"FOREIGN KEY (place_id) REFERENCES moz_places(id) ON DELETE CASCADE, "
"FOREIGN KEY (referrer_place_id) REFERENCES moz_places(id) ON DELETE "
"CASCADE, " "FOREIGN KEY(search_query_id) REFERENCES " "moz_places_metadata_search_queries(id) ON DELETE CASCADE "
"CHECK(place_id != referrer_place_id) " ")")
);
1999 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 1999); return rv; } } while (false)
;
2000 // moz_places_metadata_search_queries.
2001 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_PLACES_METADATA_SEARCH_QUERIESnsLiteralCString( "CREATE TABLE IF NOT EXISTS moz_places_metadata_search_queries ( "
"id INTEGER PRIMARY KEY, " "terms TEXT NOT NULL UNIQUE " ")"
)
);
2002 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2002); return rv; } } while (false)
;
2003 }
2004
2005 return NS_OK;
2006}
2007
2008nsresult Database::MigrateV56Up() {
2009 // Add places metadata (place_id, created_at) index.
2010 return mMainConn->ExecuteSimpleSQL(
2011 CREATE_IDX_MOZ_PLACES_METADATA_PLACECREATEDnsLiteralCString("CREATE " "UNIQUE" " INDEX IF NOT EXISTS " "moz_places_metadata"
"_" "placecreated_uniqueindex" " ON " "moz_places_metadata" " ("
"place_id, created_at" ")")
);
2012}
2013
2014nsresult Database::MigrateV57Up() {
2015 // Add the scrolling columns to the metadata.
2016 nsCOMPtr<mozIStorageStatement> stmt;
2017 nsresult rv = mMainConn->CreateStatement(
2018 "SELECT scrolling_time FROM moz_places_metadata"_ns,
2019 getter_AddRefs(stmt));
2020 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2021 rv = mMainConn->ExecuteSimpleSQL(
2022 "ALTER TABLE moz_places_metadata "
2023 "ADD COLUMN scrolling_time INTEGER NOT NULL DEFAULT 0 "_ns);
2024 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2024); return rv; } } while (false)
;
2025 }
2026
2027 rv = mMainConn->CreateStatement(
2028 "SELECT scrolling_distance FROM moz_places_metadata"_ns,
2029 getter_AddRefs(stmt));
2030 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2031 rv = mMainConn->ExecuteSimpleSQL(
2032 "ALTER TABLE moz_places_metadata "
2033 "ADD COLUMN scrolling_distance INTEGER NOT NULL DEFAULT 0 "_ns);
2034 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2034); return rv; } } while (false)
;
2035 }
2036 return NS_OK;
2037}
2038
2039nsresult Database::MigrateV60Up() {
2040 // Add the site_name column to moz_places.
2041 nsCOMPtr<mozIStorageStatement> stmt;
2042 nsresult rv = mMainConn->CreateStatement(
2043 "SELECT site_name FROM moz_places"_ns, getter_AddRefs(stmt));
2044 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2045 rv = mMainConn->ExecuteSimpleSQL(
2046 "ALTER TABLE moz_places ADD COLUMN site_name TEXT"_ns);
2047 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2047); return rv; } } while (false)
;
2048 }
2049 return NS_OK;
2050}
2051
2052nsresult Database::MigrateV61Up() {
2053 // Add previews tombstones table if necessary.
2054 nsCOMPtr<mozIStorageStatement> stmt;
2055 nsresult rv = mMainConn->CreateStatement(
2056 "SELECT hash FROM moz_previews_tombstones"_ns, getter_AddRefs(stmt));
2057 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2058 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_PREVIEWS_TOMBSTONESnsLiteralCString( "CREATE TABLE IF NOT EXISTS moz_previews_tombstones ( "
" hash TEXT PRIMARY KEY " ") WITHOUT ROWID")
);
2059 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2059); return rv; } } while (false)
;
2060 }
2061 return NS_OK;
2062}
2063
2064nsresult Database::MigrateV67Up() {
2065 // Align all input field in moz_inputhistory to lowercase. If there are
2066 // multiple records that expresses the same input, use maximum use_count from
2067 // them to carry on the experience of the past.
2068 nsCOMPtr<mozIStorageStatement> stmt;
2069 nsresult rv = mMainConn->ExecuteSimpleSQL(
2070 "INSERT INTO moz_inputhistory "
2071 "SELECT place_id, LOWER(input), use_count FROM moz_inputhistory "
2072 " WHERE LOWER(input) <> input "
2073 "ON CONFLICT DO "
2074 " UPDATE SET use_count = MAX(use_count, EXCLUDED.use_count)"_ns);
2075 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2075); return rv; } } while (false)
;
2076 rv = mMainConn->ExecuteSimpleSQL(
2077 "DELETE FROM moz_inputhistory WHERE LOWER(input) <> input"_ns);
2078 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2078); return rv; } } while (false)
;
2079
2080 return NS_OK;
2081}
2082
2083nsresult Database::MigrateV69Up() {
2084 // Add source and annotation column to places table.
2085 nsCOMPtr<mozIStorageStatement> stmt;
2086 nsresult rv = mMainConn->CreateStatement(
2087 "SELECT source FROM moz_historyvisits"_ns, getter_AddRefs(stmt));
2088 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2089 rv = mMainConn->ExecuteSimpleSQL(
2090 "ALTER TABLE moz_historyvisits "
2091 "ADD COLUMN source INTEGER DEFAULT 0 NOT NULL"_ns);
2092 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2092); return rv; } } while (false)
;
2093 rv = mMainConn->ExecuteSimpleSQL(
2094 "ALTER TABLE moz_historyvisits "
2095 "ADD COLUMN triggeringPlaceId INTEGER"_ns);
2096 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2096); return rv; } } while (false)
;
2097 }
2098
2099 return NS_OK;
2100}
2101
2102nsresult Database::MigrateV70Up() {
2103 nsCOMPtr<mozIStorageStatement> stmt;
2104 nsresult rv = mMainConn->CreateStatement(
2105 "SELECT recalc_frecency FROM moz_places LIMIT 1 "_ns,
2106 getter_AddRefs(stmt));
2107 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2108 // Add recalc_frecency column, indicating frecency has to be recalculated.
2109 rv = mMainConn->ExecuteSimpleSQL(
2110 "ALTER TABLE moz_places "
2111 "ADD COLUMN recalc_frecency INTEGER NOT NULL DEFAULT 0 "_ns);
2112 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2112); return rv; } } while (false)
;
2113 }
2114
2115 // We must do the following updates regardless, for downgrade/upgrade cases.
2116
2117 // moz_origins frecency is, at the time of this migration, the sum of all the
2118 // positive frecencies of pages linked to that origin. Frecencies that were
2119 // set to negative to request recalculation are thus not accounted for, and
2120 // since we're about to flip them to positive we should add them to their
2121 // origin. Then we must also update origins stats.
2122 // We ignore frecency = -1 because it's just an indication to recalculate
2123 // frecency and not an actual frecency value that was flipped, thus it would
2124 // not make sense to count it for the origin.
2125 rv = mMainConn->ExecuteSimpleSQL(
2126 "UPDATE moz_origins "
2127 "SET frecency = frecency + abs_frecency "
2128 "FROM (SELECT origin_id, ABS(frecency) AS abs_frecency FROM moz_places "
2129 "WHERE frecency < -1) AS places "
2130 "WHERE moz_origins.id = places.origin_id"_ns);
2131 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2131); return rv; } } while (false)
;
2132 rv = mMainConn->ExecuteSimpleSQL(
2133 "INSERT OR REPLACE INTO moz_meta(key, value) VALUES "
2134 "('origin_frecency_count', "
2135 "(SELECT COUNT(*) FROM moz_origins WHERE frecency > 0) "
2136 "), "
2137 "('origin_frecency_sum', "
2138 "(SELECT TOTAL(frecency) FROM moz_origins WHERE frecency > 0) "
2139 "), "
2140 "('origin_frecency_sum_of_squares', "
2141 "(SELECT TOTAL(frecency * frecency) FROM moz_origins WHERE frecency > 0) "
2142 ") "_ns);
2143 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2143); return rv; } } while (false)
;
2144
2145 // Now set recalc_frecency = 1 and positive frecency to any page having a
2146 // negative frecency.
2147 // Note we don't flip frecency = -1, since we skipped it above when updating
2148 // origins, and it remains an acceptable value yet, until the recalculation.
2149 rv = mMainConn->ExecuteSimpleSQL(
2150 "UPDATE moz_places "
2151 "SET recalc_frecency = 1, "
2152 " frecency = CASE WHEN frecency = -1 THEN -1 ELSE ABS(frecency) END "
2153 "WHERE frecency < 0 "_ns);
2154 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2154); return rv; } } while (false)
;
2155
2156 return NS_OK;
2157}
2158
2159nsresult Database::MigrateV71Up() {
2160 // Fix the foreign counts. We ignore failures as the tables may not exist.
2161 mMainConn->ExecuteSimpleSQL(
2162 "UPDATE moz_places "
2163 "SET foreign_count = foreign_count - 1 "
2164 "WHERE id in (SELECT place_id FROM moz_places_metadata_snapshots)"_ns);
2165 mMainConn->ExecuteSimpleSQL(
2166 "UPDATE moz_places "
2167 "SET foreign_count = foreign_count - 1 "
2168 "WHERE id in (SELECT place_id FROM moz_session_to_places)"_ns);
2169
2170 // Remove unused snapshots and session tables and indexes.
2171 nsresult rv = mMainConn->ExecuteSimpleSQL(
2172 "DROP INDEX IF EXISTS moz_places_metadata_snapshots_pinnedindex"_ns);
2173 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2173); return rv; } } while (false)
;
2174 rv = mMainConn->ExecuteSimpleSQL(
2175 "DROP INDEX IF EXISTS moz_places_metadata_snapshots_extra_typeindex"_ns);
2176 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2176); return rv; } } while (false)
;
2177 rv = mMainConn->ExecuteSimpleSQL(
2178 "DROP TABLE IF EXISTS moz_places_metadata_groups_to_snapshots"_ns);
2179 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2179); return rv; } } while (false)
;
2180 rv = mMainConn->ExecuteSimpleSQL(
2181 "DROP TABLE IF EXISTS moz_places_metadata_snapshots_groups"_ns);
2182 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2182); return rv; } } while (false)
;
2183 rv = mMainConn->ExecuteSimpleSQL(
2184 "DROP TABLE IF EXISTS moz_places_metadata_snapshots_extra"_ns);
2185 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2185); return rv; } } while (false)
;
2186 rv = mMainConn->ExecuteSimpleSQL(
2187 "DROP TABLE IF EXISTS moz_places_metadata_snapshots"_ns);
2188 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2188); return rv; } } while (false)
;
2189 rv = mMainConn->ExecuteSimpleSQL(
2190 "DROP TABLE IF EXISTS moz_session_to_places"_ns);
2191 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2191); return rv; } } while (false)
;
2192 rv = mMainConn->ExecuteSimpleSQL(
2193 "DROP TABLE IF EXISTS moz_session_metadata"_ns);
2194 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2194); return rv; } } while (false)
;
2195
2196 return NS_OK;
2197}
2198
2199nsresult Database::MigrateV72Up() {
2200 // Recalculate frecency of unvisited bookmarks.
2201 nsresult rv = mMainConn->ExecuteSimpleSQL(
2202 "UPDATE moz_places "
2203 "SET recalc_frecency = 1 "
2204 "WHERE foreign_count > 0 AND visit_count = 0"_ns);
2205 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2205); return rv; } } while (false)
;
2206 return NS_OK;
2207}
2208
2209nsresult Database::MigrateV73Up() {
2210 // Add recalc_frecency, alt_frecency and recalc_alt_frecency to moz_origins.
2211 nsCOMPtr<mozIStorageStatement> stmt;
2212 nsresult rv = mMainConn->CreateStatement(
2213 "SELECT recalc_frecency FROM moz_origins"_ns, getter_AddRefs(stmt));
2214 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2215 rv = mMainConn->ExecuteSimpleSQL(
2216 "ALTER TABLE moz_origins "
2217 "ADD COLUMN recalc_frecency INTEGER NOT NULL DEFAULT 0"_ns);
2218 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2218); return rv; } } while (false)
;
2219 rv = mMainConn->ExecuteSimpleSQL(
2220 "ALTER TABLE moz_origins "
2221 "ADD COLUMN alt_frecency INTEGER"_ns);
2222 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2222); return rv; } } while (false)
;
2223 rv = mMainConn->ExecuteSimpleSQL(
2224 "ALTER TABLE moz_origins "
2225 "ADD COLUMN recalc_alt_frecency INTEGER NOT NULL DEFAULT 0"_ns);
2226 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2226); return rv; } } while (false)
;
2227 }
2228 return NS_OK;
2229}
2230
2231nsresult Database::MigrateV74Up() {
2232 // Add alt_frecency and recalc_alt_frecency to moz_places.
2233 nsCOMPtr<mozIStorageStatement> stmt;
2234 nsresult rv = mMainConn->CreateStatement(
2235 "SELECT alt_frecency FROM moz_places"_ns, getter_AddRefs(stmt));
2236 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2237 rv = mMainConn->ExecuteSimpleSQL(
2238 "ALTER TABLE moz_places "
2239 "ADD COLUMN alt_frecency INTEGER"_ns);
2240 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2240); return rv; } } while (false)
;
2241 rv = mMainConn->ExecuteSimpleSQL(
2242 "ALTER TABLE moz_places "
2243 "ADD COLUMN recalc_alt_frecency INTEGER NOT NULL DEFAULT 0"_ns);
2244 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2244); return rv; } } while (false)
;
2245 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_ALT_FRECENCYnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_places"
"_" "altfrecencyindex" " ON " "moz_places" " (" "alt_frecency"
")")
);
2246 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2246); return rv; } } while (false)
;
2247 }
2248 return NS_OK;
2249}
2250
2251nsresult Database::MigrateV75Up() {
2252 // Add *_extra tables for moz_places and moz_historyvisits
2253 nsCOMPtr<mozIStorageStatement> stmt;
2254 nsresult rv = mMainConn->CreateStatement(
2255 "SELECT sync_json FROM moz_places_extra"_ns, getter_AddRefs(stmt));
2256 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2257 nsresult rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_PLACES_EXTRAnsLiteralCString( "CREATE TABLE moz_places_extra (" " place_id INTEGER PRIMARY KEY NOT NULL"
", sync_json TEXT" ", FOREIGN KEY (place_id) REFERENCES moz_places(id) ON DELETE CASCADE "
")")
);
2258 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2258); return rv; } } while (false)
;
2259 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_HISTORYVISITS_EXTRAnsLiteralCString( "CREATE TABLE moz_historyvisits_extra (" " visit_id INTEGER PRIMARY KEY NOT NULL"
", sync_json TEXT" ", FOREIGN KEY (visit_id) REFERENCES moz_historyvisits(id) ON "
" DELETE CASCADE" ")")
);
2260 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2260); return rv; } } while (false)
;
2261 }
2262 return NS_OK;
2263}
2264
2265nsresult Database::MigrateV77Up() {
2266 // Recalculate origins frecency.
2267 nsCOMPtr<mozIStorageStatement> stmt;
2268 nsresult rv = mMainConn->ExecuteSimpleSQL(
2269 "UPDATE moz_origins SET recalc_frecency = 1"_ns);
2270 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2270); return rv; } } while (false)
;
2271 return NS_OK;
2272}
2273
2274nsresult Database::MigrateV78Up() {
2275 // Add flags to moz_icons.
2276 nsCOMPtr<mozIStorageStatement> stmt;
2277 nsresult rv = mMainConn->CreateStatement("SELECT flags FROM moz_icons"_ns,
2278 getter_AddRefs(stmt));
2279 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2280 rv = mMainConn->ExecuteSimpleSQL(
2281 "ALTER TABLE moz_icons "
2282 "ADD COLUMN flags INTEGER NOT NULL DEFAULT 0"_ns);
2283 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2283); return rv; } } while (false)
;
2284 }
2285 return NS_OK;
2286}
2287
2288nsresult Database::MigrateV79Up() {
2289 // Add newtab_story tables for moz_newtab_story_click and
2290 // moz_newtab_story_impression
2291 nsCOMPtr<mozIStorageStatement> stmt;
2292 nsresult rv = mMainConn->CreateStatement(
2293 "SELECT feature FROM moz_newtab_story_click"_ns, getter_AddRefs(stmt));
2294 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2295 nsresult rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_NEWTAB_STORY_CLICKnsLiteralCString( "CREATE TABLE moz_newtab_story_click ( " " feature TEXT NOT NULL, "
" timestamp_s INTEGER NOT NULL, " " card_format_enum INTEGER NOT NULL, "
" position INTEGER NOT NULL, " " section_position INTEGER NOT NULL, "
" feature_value REAL NOT NULL DEFAULT 1 " ")")
);
2296 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2296); return rv; } } while (false)
;
2297 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_NEWTAB_STORY_IMPRESSIONnsLiteralCString( "CREATE TABLE moz_newtab_story_impression ( "
" feature TEXT NOT NULL, " " timestamp_s INTEGER NOT NULL, "
" card_format_enum INTEGER NOT NULL, " " position INTEGER NOT NULL, "
" section_position INTEGER NOT NULL, " " feature_value REAL NOT NULL DEFAULT 1 "
")")
);
2298 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2298); return rv; } } while (false)
;
2299 }
2300 return NS_OK;
2301}
2302
2303nsresult Database::MigrateV80Up() {
2304 // v79 indices had a typo so we're recreating them here.
2305 nsresult rv =
2306 mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_NEWTAB_STORY_CLICK_TIMESTAMPnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_newtab_story_click"
"_" "newtab_click_timestampindex" " ON " "moz_newtab_story_click"
" (" "timestamp_s" ")")
);
2307 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2307); return rv; } } while (false)
;
2308 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_NEWTAB_IMPRESSION_TIMESTAMPnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_newtab_story_impression"
"_" "newtab_impression_timestampindex" " ON " "moz_newtab_story_impression"
" (" "timestamp_s" ")")
);
2309 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2309); return rv; } } while (false)
;
2310 return NS_OK;
2311}
2312
2313nsresult Database::MigrateV81Up() {
2314 // v79 indices had a typo, v80 tried to remove them but it got the names
2315 // wrong, so we're effectively removing them here.
2316 nsresult rv = mMainConn->ExecuteSimpleSQL(
2317 "DROP INDEX IF EXISTS moz_newtab_story_click_idx_newtab_click_timestamp"_ns);
2318 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2318); return rv; } } while (false)
;
2319 rv = mMainConn->ExecuteSimpleSQL(
2320 "DROP INDEX IF EXISTS moz_newtab_story_click_idx_newtab_impression_timestamp"_ns);
2321 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2321); return rv; } } while (false)
;
2322 return NS_OK;
2323}
2324
2325nsresult Database::MigrateV82Up() {
2326 // Create moz_newtab_shortcuts_interaction table and associated indexes.
2327 nsCOMPtr<mozIStorageStatement> stmt;
2328 nsresult rv = mMainConn->CreateStatement(
2329 "SELECT id FROM moz_newtab_shortcuts_interaction"_ns,
2330 getter_AddRefs(stmt));
2331 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2332 rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_NEWTAB_SHORTCUTS_INTERACTIONnsLiteralCString( "CREATE TABLE moz_newtab_shortcuts_interaction ( "
" id INTEGER PRIMARY KEY, " " place_id INTEGER NOT NULL REFERENCES moz_places(id) ON DELETE "
"CASCADE, " " event_type INTEGER NOT NULL, " " timestamp_s INTEGER NOT NULL, "
" pinned INTEGER NOT NULL CHECK (pinned IN (0, 1)), " " tile_position INTEGER NOT NULL"
")")
);
2333 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2333); return rv; } } while (false)
;
2334
2335 // Add moz_newtab_shortcuts_interaction timestamp index
2336 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_NEWTAB_SHORTCUTS_TIMESTAMPnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_newtab_shortcuts_interaction"
"_" "timestampindex" " ON " "moz_newtab_shortcuts_interaction"
" (" "timestamp_s" ")")
);
2337 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2337); return rv; } } while (false)
;
2338
2339 // Add moz_newtab_shortcuts_interaction place_id index
2340 rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_NEWTAB_SHORTCUTS_PLACEIDnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_newtab_shortcuts_interaction"
"_" "placeidindex" " ON " "moz_newtab_shortcuts_interaction"
" (" "place_id" ")")
);
2341 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2341); return rv; } } while (false)
;
2342 }
2343 return NS_OK;
2344}
2345
2346nsresult Database::MigrateV83Up() {
2347 // Recalculate frecency due to changing calculate_frecency.
2348 nsresult rv = mMainConn->ExecuteSimpleSQL(
2349 "UPDATE moz_places SET recalc_frecency = 1 WHERE frecency > 0"_ns);
2350 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2350); return rv; } } while (false)
;
2351 return NS_OK;
2352}
2353
2354nsresult Database::MigrateV85Up() {
2355 // Recalculate frecency due to changing frecency and giving too high a bonus
2356 // for non-typed URLs.
2357 nsresult rv = mMainConn->ExecuteSimpleSQL(
2358 "UPDATE moz_origins "
2359 "SET recalc_frecency = 1 "
2360 "WHERE frecency > 1"_ns);
2361 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2361); return rv; } } while (false)
;
2362 return NS_OK;
2363}
2364
2365nsresult Database::MigrateV86Up() {
2366 nsCOMPtr<mozIStorageStatement> stmt;
2367
2368 // Check and add block_until_ms if missing.
2369 nsresult rv = mMainConn->CreateStatement(
2370 "SELECT block_until_ms FROM moz_origins"_ns, getter_AddRefs(stmt));
2371 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2372 rv = mMainConn->ExecuteSimpleSQL(
2373 "ALTER TABLE moz_origins "
2374 "ADD COLUMN block_until_ms INTEGER"_ns);
2375 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2375); return rv; } } while (false)
;
2376 }
2377
2378 // Check and add block_pages_until_ms if missing.
2379 rv = mMainConn->CreateStatement(
2380 "SELECT block_pages_until_ms FROM moz_origins"_ns, getter_AddRefs(stmt));
2381 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2382 rv = mMainConn->ExecuteSimpleSQL(
2383 "ALTER TABLE moz_origins "
2384 "ADD COLUMN block_pages_until_ms INTEGER"_ns);
2385 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2385); return rv; } } while (false)
;
2386 }
2387 return NS_OK;
2388}
2389
2390nsresult Database::MigrateV87Up() {
2391 // Invert the moz_origins UNIQUE constraint to (host, prefix), so the higher
2392 // cardinality column comes first and queries only filtering on host, like the
2393 // address bar ones, can use the index.
2394
2395 {
2396 // The statement must be finalized before the table it reads is dropped.
2397 nsCOMPtr<mozIStorageStatement> stmt;
2398 nsresult rv = mMainConn->CreateStatement(
2399 nsLiteralCString("SELECT 1 FROM sqlite_master "
2400 "WHERE type = 'table' AND name = 'moz_origins' "
2401 "AND sql LIKE '%UNIQUE (host, prefix)%'"),
2402 getter_AddRefs(stmt));
2403 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2403); return rv; } } while (false)
;
2404 bool hasResult = false;
2405 if (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(stmt->ExecuteStep
(&hasResult))), 1)))
&& hasResult) {
2406 // The constraint has already been inverted.
2407 return NS_OK;
2408 }
2409 }
2410
2411 // The table must be rebuilt, but it can't be dropped while moz_places
2412 // references it. Deferring the foreign keys allows the drop: it leaves every
2413 // referencing page orphaned until the table is refilled, which resolves them
2414 // again before the transaction commits.
2415 nsresult rv =
2416 mMainConn->ExecuteSimpleSQL("PRAGMA defer_foreign_keys = ON"_ns);
2417 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2417); return rv; } } while (false)
;
2418
2419 rv = mMainConn->ExecuteSimpleSQL(
2420 "CREATE TEMP TABLE moz_origins_stash_temp AS "
2421 "SELECT * FROM moz_origins"_ns);
2422 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2422); return rv; } } while (false)
;
2423
2424 rv = mMainConn->ExecuteSimpleSQL("DROP TABLE moz_origins"_ns);
2425 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2425); return rv; } } while (false)
;
2426
2427 rv = mMainConn->ExecuteSimpleSQL(
2428 "CREATE TABLE moz_origins ( "
2429 "id INTEGER PRIMARY KEY, "
2430 "prefix TEXT NOT NULL, "
2431 "host TEXT NOT NULL, "
2432 "frecency INTEGER NOT NULL, "
2433 "recalc_frecency INTEGER NOT NULL DEFAULT 0, "
2434 "alt_frecency INTEGER, "
2435 "recalc_alt_frecency INTEGER NOT NULL DEFAULT 0, "
2436 "block_until_ms INTEGER, "
2437 "block_pages_until_ms INTEGER, "
2438 "UNIQUE (host, prefix) "
2439 ")"_ns);
2440 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2440); return rv; } } while (false)
;
2441
2442 // Inserting the rows into a table with the same name as the original resolves
2443 // the deferred constraint violations accumulated during the DROP.
2444 rv = mMainConn->ExecuteSimpleSQL(
2445 "INSERT INTO moz_origins "
2446 "(id, prefix, host, frecency, recalc_frecency, alt_frecency, "
2447 "recalc_alt_frecency, block_until_ms, block_pages_until_ms) "
2448 "SELECT id, prefix, host, frecency, recalc_frecency, alt_frecency, "
2449 "recalc_alt_frecency, block_until_ms, block_pages_until_ms "
2450 "FROM moz_origins_stash_temp"_ns);
2451 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2451); return rv; } } while (false)
;
2452
2453 rv = mMainConn->ExecuteSimpleSQL("DROP TABLE moz_origins_stash_temp"_ns);
2454 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2454); return rv; } } while (false)
;
2455
2456 return NS_OK;
2457}
2458
2459int64_t Database::CreateMobileRoot() {
2460 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../../toolkit/components/places/Database.cpp", 2460
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { MOZ_CrashSequence(__null, 2460); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2461
2462 // Create the mobile root, ignoring conflicts if one already exists (for
2463 // example, if the user downgraded to an earlier release channel).
2464 nsCOMPtr<mozIStorageStatement> createStmt;
2465 nsresult rv = mMainConn->CreateStatement(
2466 nsLiteralCString(
2467 "INSERT OR IGNORE INTO moz_bookmarks "
2468 "(type, title, dateAdded, lastModified, guid, position, parent) "
2469 "SELECT :item_type, :item_title, :timestamp, :timestamp, :guid, "
2470 "IFNULL((SELECT MAX(position) + 1 FROM moz_bookmarks p WHERE "
2471 "p.parent = b.id), 0), b.id "
2472 "FROM moz_bookmarks b WHERE b.parent = 0"),
2473 getter_AddRefs(createStmt));
2474 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return -1;
2475
2476 rv = createStmt->BindInt32ByName("item_type"_ns,
2477 nsINavBookmarksService::TYPE_FOLDER);
2478 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return -1;
2479 rv = createStmt->BindUTF8StringByName("item_title"_ns,
2480 nsLiteralCString(MOBILE_ROOT_TITLE"mobile"));
2481 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return -1;
2482 rv = createStmt->BindInt64ByName("timestamp"_ns, RoundedPRNow());
2483 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return -1;
2484 rv = createStmt->BindUTF8StringByName("guid"_ns,
2485 nsLiteralCString(MOBILE_ROOT_GUID"mobile______"));
2486 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return -1;
2487
2488 rv = createStmt->Execute();
2489 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return -1;
2490
2491 // Find the mobile root ID. We can't use the last inserted ID because the
2492 // root might already exist, and we ignore on conflict.
2493 nsCOMPtr<mozIStorageStatement> findIdStmt;
2494 rv = mMainConn->CreateStatement(
2495 "SELECT id FROM moz_bookmarks WHERE guid = :guid"_ns,
2496 getter_AddRefs(findIdStmt));
2497 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return -1;
2498
2499 rv = findIdStmt->BindUTF8StringByName("guid"_ns,
2500 nsLiteralCString(MOBILE_ROOT_GUID"mobile______"));
2501 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return -1;
2502
2503 bool hasResult = false;
2504 rv = findIdStmt->ExecuteStep(&hasResult);
2505 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) || !hasResult) return -1;
2506
2507 int64_t rootId;
2508 rv = findIdStmt->GetInt64(0, &rootId);
2509 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return -1;
2510
2511 return rootId;
2512}
2513
2514void Database::Shutdown() {
2515 // As the last step in the shutdown path, finalize the database handle.
2516 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../../toolkit/components/places/Database.cpp", 2516
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { MOZ_CrashSequence(__null, 2516); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2517 MOZ_ASSERT(!mClosed)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mClosed)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mClosed))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("!mClosed", "./../../../../toolkit/components/places/Database.cpp"
, 2517); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mClosed" ")"
); do { MOZ_CrashSequence(__null, 2517); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2518
2519 // Break cycles with the shutdown blockers.
2520 mClientsShutdown = nullptr;
2521 nsCOMPtr<mozIStorageCompletionCallback> connectionShutdown =
2522 std::move(mConnectionShutdown);
2523
2524 if (!mMainConn) {
2525 // The connection has never been initialized. Just mark it as closed.
2526 mClosed = true;
2527 (void)connectionShutdown->Complete(NS_OK, nullptr);
2528 return;
2529 }
2530
2531#ifdef DEBUG1
2532 {
2533 bool hasResult;
2534 nsCOMPtr<mozIStorageStatement> stmt;
2535
2536 // Sanity check for missing guids.
2537 nsresult rv =
2538 mMainConn->CreateStatement(nsLiteralCString("SELECT 1 "
2539 "FROM moz_places "
2540 "WHERE guid IS NULL "),
2541 getter_AddRefs(stmt));
2542 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "./../../../../toolkit/components/places/Database.cpp"
, 2542); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { MOZ_CrashSequence(__null, 2542); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2543 rv = stmt->ExecuteStep(&hasResult);
2544 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "./../../../../toolkit/components/places/Database.cpp"
, 2544); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { MOZ_CrashSequence(__null, 2544); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2545 MOZ_ASSERT(!hasResult, "Found a page without a GUID!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!hasResult)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!hasResult))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("!hasResult" " (" "Found a page without a GUID!"
")", "./../../../../toolkit/components/places/Database.cpp",
2545); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!hasResult" ") ("
"Found a page without a GUID!" ")"); do { MOZ_CrashSequence(
__null, 2545); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
2546 rv = mMainConn->CreateStatement(nsLiteralCString("SELECT 1 "
2547 "FROM moz_bookmarks "
2548 "WHERE guid IS NULL "),
2549 getter_AddRefs(stmt));
2550 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "./../../../../toolkit/components/places/Database.cpp"
, 2550); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { MOZ_CrashSequence(__null, 2550); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2551 rv = stmt->ExecuteStep(&hasResult);
2552 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "./../../../../toolkit/components/places/Database.cpp"
, 2552); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { MOZ_CrashSequence(__null, 2552); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2553 MOZ_ASSERT(!hasResult, "Found a bookmark without a GUID!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!hasResult)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!hasResult))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("!hasResult" " (" "Found a bookmark without a GUID!"
")", "./../../../../toolkit/components/places/Database.cpp",
2553); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!hasResult" ") ("
"Found a bookmark without a GUID!" ")"); do { MOZ_CrashSequence
(__null, 2553); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2554
2555 // Sanity check for unrounded dateAdded and lastModified values (bug
2556 // 1107308).
2557 rv = mMainConn->CreateStatement(
2558 nsLiteralCString(
2559 "SELECT 1 "
2560 "FROM moz_bookmarks "
2561 "WHERE dateAdded % 1000 > 0 OR lastModified % 1000 > 0 LIMIT 1"),
2562 getter_AddRefs(stmt));
2563 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "./../../../../toolkit/components/places/Database.cpp"
, 2563); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { MOZ_CrashSequence(__null, 2563); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2564 rv = stmt->ExecuteStep(&hasResult);
2565 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "./../../../../toolkit/components/places/Database.cpp"
, 2565); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { MOZ_CrashSequence(__null, 2565); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2566 MOZ_ASSERT(!hasResult, "Found unrounded dates!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!hasResult)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!hasResult))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("!hasResult" " (" "Found unrounded dates!"
")", "./../../../../toolkit/components/places/Database.cpp",
2566); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!hasResult" ") ("
"Found unrounded dates!" ")"); do { MOZ_CrashSequence(__null
, 2566); __attribute__((nomerge)) ::abort(); } while (false);
} } while (false)
;
2567
2568 // Sanity check url_hash
2569 rv = mMainConn->CreateStatement(
2570 "SELECT 1 FROM moz_places WHERE url_hash = 0"_ns, getter_AddRefs(stmt));
2571 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "./../../../../toolkit/components/places/Database.cpp"
, 2571); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { MOZ_CrashSequence(__null, 2571); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2572 rv = stmt->ExecuteStep(&hasResult);
2573 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "./../../../../toolkit/components/places/Database.cpp"
, 2573); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { MOZ_CrashSequence(__null, 2573); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2574 MOZ_ASSERT(!hasResult, "Found a place without a hash!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!hasResult)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!hasResult))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("!hasResult" " (" "Found a place without a hash!"
")", "./../../../../toolkit/components/places/Database.cpp",
2574); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!hasResult" ") ("
"Found a place without a hash!" ")"); do { MOZ_CrashSequence
(__null, 2574); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2575
2576 // Sanity check unique urls
2577 rv = mMainConn->CreateStatement(
2578 nsLiteralCString(
2579 "SELECT 1 FROM moz_places GROUP BY url HAVING count(*) > 1 "),
2580 getter_AddRefs(stmt));
2581 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "./../../../../toolkit/components/places/Database.cpp"
, 2581); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { MOZ_CrashSequence(__null, 2581); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2582 rv = stmt->ExecuteStep(&hasResult);
2583 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "./../../../../toolkit/components/places/Database.cpp"
, 2583); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { MOZ_CrashSequence(__null, 2583); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2584 MOZ_ASSERT(!hasResult, "Found a duplicate url!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!hasResult)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!hasResult))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("!hasResult" " (" "Found a duplicate url!"
")", "./../../../../toolkit/components/places/Database.cpp",
2584); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!hasResult" ") ("
"Found a duplicate url!" ")"); do { MOZ_CrashSequence(__null
, 2584); __attribute__((nomerge)) ::abort(); } while (false);
} } while (false)
;
2585
2586 // Sanity check NULL urls
2587 rv = mMainConn->CreateStatement(
2588 "SELECT 1 FROM moz_places WHERE url ISNULL "_ns, getter_AddRefs(stmt));
2589 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "./../../../../toolkit/components/places/Database.cpp"
, 2589); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { MOZ_CrashSequence(__null, 2589); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2590 rv = stmt->ExecuteStep(&hasResult);
2591 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "./../../../../toolkit/components/places/Database.cpp"
, 2591); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { MOZ_CrashSequence(__null, 2591); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2592 MOZ_ASSERT(!hasResult, "Found a NULL url!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!hasResult)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!hasResult))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("!hasResult" " (" "Found a NULL url!"
")", "./../../../../toolkit/components/places/Database.cpp",
2592); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!hasResult" ") ("
"Found a NULL url!" ")"); do { MOZ_CrashSequence(__null, 2592
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
2593 }
2594#endif
2595
2596 mMainThreadStatements.FinalizeStatements();
2597 mMainThreadAsyncStatements.FinalizeStatements();
2598
2599 RefPtr<FinalizeStatementCacheProxy<mozIStorageStatement>> event =
2600 new FinalizeStatementCacheProxy<mozIStorageStatement>(
2601 mAsyncThreadStatements, NS_ISUPPORTS_CAST(nsIObserver*, this)static_cast<nsISupports*>(static_cast<nsIObserver*>
(this))
);
2602 DispatchToAsyncThread(event);
2603
2604 mClosed = true;
2605
2606 // Execute PRAGMA optimize as last step, this will ensure proper database
2607 // performance across restarts. The 0x12 flags mean: run ANALYZE on tables
2608 // that might benefit (0x02), with a row limit to keep runtime bounded (0x10).
2609 nsCOMPtr<mozIStoragePendingStatement> ps;
2610 MOZ_ALWAYS_SUCCEEDS(mMainConn->ExecuteSimpleSQLAsync(do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(mMainConn->ExecuteSimpleSQLAsync( "PRAGMA optimize(0x12)"_ns
, nullptr, getter_AddRefs(ps)))), 1)))), 1))) { } else { do {
do { } while (false); MOZ_ReportCrash("" "NS_SUCCEEDED(mMainConn->ExecuteSimpleSQLAsync( \"PRAGMA optimize(0x12)\"_ns, nullptr, getter_AddRefs(ps)))"
, "./../../../../toolkit/components/places/Database.cpp", 2611
); AnnotateMozCrashReason("MOZ_CRASH(" "NS_SUCCEEDED(mMainConn->ExecuteSimpleSQLAsync( \"PRAGMA optimize(0x12)\"_ns, nullptr, getter_AddRefs(ps)))"
")"); do { MOZ_CrashSequence(__null, 2611); __attribute__((nomerge
)) ::abort(); } while (false); } while (false); } } while (false
)
2611 "PRAGMA optimize(0x12)"_ns, nullptr, getter_AddRefs(ps)))do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(mMainConn->ExecuteSimpleSQLAsync( "PRAGMA optimize(0x12)"_ns
, nullptr, getter_AddRefs(ps)))), 1)))), 1))) { } else { do {
do { } while (false); MOZ_ReportCrash("" "NS_SUCCEEDED(mMainConn->ExecuteSimpleSQLAsync( \"PRAGMA optimize(0x12)\"_ns, nullptr, getter_AddRefs(ps)))"
, "./../../../../toolkit/components/places/Database.cpp", 2611
); AnnotateMozCrashReason("MOZ_CRASH(" "NS_SUCCEEDED(mMainConn->ExecuteSimpleSQLAsync( \"PRAGMA optimize(0x12)\"_ns, nullptr, getter_AddRefs(ps)))"
")"); do { MOZ_CrashSequence(__null, 2611); __attribute__((nomerge
)) ::abort(); } while (false); } while (false); } } while (false
)
;
2612
2613 if (NS_FAILED(mMainConn->AsyncClose(connectionShutdown))((bool)(__builtin_expect(!!(NS_FAILED_impl(mMainConn->AsyncClose
(connectionShutdown))), 0)))
) {
2614 (void)connectionShutdown->Complete(NS_ERROR_UNEXPECTED, nullptr);
2615 }
2616 mMainConn = nullptr;
2617}
2618
2619////////////////////////////////////////////////////////////////////////////////
2620//// nsIObserver
2621
2622NS_IMETHODIMPnsresult
2623Database::Observe(nsISupports* aSubject, const char* aTopic,
2624 const char16_t* aData) {
2625 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "./../../../../toolkit/components/places/Database.cpp", 2625
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { MOZ_CrashSequence(__null, 2625); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2626 if (strcmp(aTopic, TOPIC_PROFILE_CHANGE_TEARDOWN"profile-change-teardown") == 0) {
2627 // Tests simulating shutdown may cause multiple notifications.
2628 if (PlacesShutdownBlocker::sIsStarted) {
2629 return NS_OK;
2630 }
2631
2632 nsCOMPtr<nsIObserverService> os = services::GetObserverService();
2633 NS_ENSURE_STATE(os)do { if ((__builtin_expect(!!(!(os)), 0))) { NS_DebugBreak(NS_DEBUG_WARNING
, "NS_ENSURE_TRUE(" "os" ") failed", nullptr, "./../../../../toolkit/components/places/Database.cpp"
, 2633); return NS_ERROR_UNEXPECTED; } } while (false)
;
2634
2635 // If shutdown happens in the same mainthread loop as init, observers could
2636 // handle the places-init-complete notification after xpcom-shutdown, when
2637 // the connection does not exist anymore. Removing those observers would
2638 // be less expensive but may cause their RemoveObserver calls to throw.
2639 // Thus notify the topic now, so they stop listening for it.
2640 nsCOMPtr<nsISimpleEnumerator> e;
2641 if (NS_SUCCEEDED(os->EnumerateObservers(TOPIC_PLACES_INIT_COMPLETE,((bool)(__builtin_expect(!!(!NS_FAILED_impl(os->EnumerateObservers
("places-init-complete", getter_AddRefs(e)))), 1)))
2642 getter_AddRefs(e)))((bool)(__builtin_expect(!!(!NS_FAILED_impl(os->EnumerateObservers
("places-init-complete", getter_AddRefs(e)))), 1)))
&&
2643 e) {
2644 bool hasMore = false;
2645 while (NS_SUCCEEDED(e->HasMoreElements(&hasMore))((bool)(__builtin_expect(!!(!NS_FAILED_impl(e->HasMoreElements
(&hasMore))), 1)))
&& hasMore) {
2646 nsCOMPtr<nsISupports> supports;
2647 if (NS_SUCCEEDED(e->GetNext(getter_AddRefs(supports)))((bool)(__builtin_expect(!!(!NS_FAILED_impl(e->GetNext(getter_AddRefs
(supports)))), 1)))
) {
2648 nsCOMPtr<nsIObserver> observer = do_QueryInterface(supports);
2649 (void)observer->Observe(observer, TOPIC_PLACES_INIT_COMPLETE"places-init-complete",
2650 nullptr);
2651 }
2652 }
2653 }
2654
2655 // Notify all Places users that we are about to shutdown.
2656 (void)os->NotifyObservers(nullptr, TOPIC_PLACES_SHUTDOWN"places-shutdown", nullptr);
2657 } else if (strcmp(aTopic, TOPIC_SIMULATE_PLACES_SHUTDOWN"test-simulate-places-shutdown") == 0) {
2658 // This notification is (and must be) only used by tests that are trying
2659 // to simulate Places shutdown out of the normal shutdown path.
2660
2661 // Tests simulating shutdown may cause re-entrance.
2662 if (PlacesShutdownBlocker::sIsStarted) {
2663 return NS_OK;
2664 }
2665
2666 // We are simulating a shutdown, so invoke the shutdown blockers,
2667 // wait for them, then proceed with connection shutdown.
2668 // Since we are already going through shutdown, but it's not the real one,
2669 // we won't need to block the real one anymore, so we can unblock it.
2670 {
2671 nsCOMPtr<nsIAsyncShutdownClient> shutdownPhase =
2672 GetProfileChangeTeardownPhase();
2673 if (shutdownPhase) {
2674 shutdownPhase->RemoveBlocker(mClientsShutdown.get());
2675 }
2676 (void)mClientsShutdown->BlockShutdown(nullptr);
2677 }
2678
2679 // Spin the events loop until the clients are done.
2680 // Note, this is just for tests, specifically test_clearHistory_shutdown.js
2681 SpinEventLoopUntil("places:Database::Observe(SIMULATE_PLACES_SHUTDOWN)"_ns,
2682 [&]() {
2683 return mClientsShutdown->State() ==
2684 PlacesShutdownBlocker::States::RECEIVED_DONE;
2685 });
2686
2687 {
2688 nsCOMPtr<nsIAsyncShutdownClient> shutdownPhase =
2689 GetProfileBeforeChangePhase();
2690 if (shutdownPhase) {
2691 shutdownPhase->RemoveBlocker(mConnectionShutdown.get());
2692 }
2693 (void)mConnectionShutdown->BlockShutdown(nullptr);
2694 }
2695 }
2696 return NS_OK;
2697}
2698
2699} // namespace mozilla::places