Bug Summary

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