Bug Summary

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