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 |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 | |
113 | using namespace mozilla; |
114 | |
115 | namespace mozilla::places { |
116 | |
117 | namespace { |
118 | |
119 | //////////////////////////////////////////////////////////////////////////////// |
120 | //// Helpers |
121 | |
122 | /** |
123 | * Get the filename for a corrupt database. |
124 | */ |
125 | nsString getCorruptFilename(const nsString& aDbFilename) { |
126 | return aDbFilename + u".corrupt"_ns; |
127 | } |
128 | /** |
129 | * Get the filename for a recover database. |
130 | */ |
131 | nsString 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 | */ |
139 | bool 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. |
151 | enum 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 | */ |
165 | static 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 | */ |
172 | void 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 | */ |
197 | enum 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 | |
246 | nsresult 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 | |
294 | nsresult 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 | |
346 | nsresult 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 | |
366 | PRTime 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 | |
383 | PLACES_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 | |
385 | NS_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 | |
387 | Database::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 | |
411 | already_AddRefed<nsIAsyncShutdownClient> |
412 | Database::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 | |
428 | already_AddRefed<nsIAsyncShutdownClient> |
429 | Database::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 | |
445 | Database::~Database() = default; |
446 | |
447 | already_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 | |
457 | already_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 | |
474 | already_AddRefed<nsIAsyncShutdownClient> Database::GetClientsShutdown() { |
475 | if (mClientsShutdown) return mClientsShutdown->GetClient(); |
476 | return nullptr; |
477 | } |
478 | |
479 | already_AddRefed<nsIAsyncShutdownClient> Database::GetConnectionShutdown() { |
480 | if (mConnectionShutdown) return mConnectionShutdown->GetClient(); |
481 | return nullptr; |
482 | } |
483 | |
484 | // static |
485 | already_AddRefed<Database> Database::GetDatabase() { |
486 | if (PlacesShutdownBlocker::sIsStarted) { |
487 | return nullptr; |
488 | } |
489 | return GetSingleton(); |
490 | } |
491 | |
492 | nsresult 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 | |
540 | nsresult 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 | |
708 | nsresult 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 | |
725 | nsresult 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, " "flags 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 | |
808 | nsresult 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 | |
925 | nsresult 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 | |
1046 | nsresult 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 | |
1149 | nsresult 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(¤tSchemaVersion); |
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 | if (currentSchemaVersion < 78) { |
1332 | rv = MigrateV78Up(); |
1333 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1333); return rv; } } while (false); |
1334 | } |
1335 | |
1336 | // Firefox 132 uses schema version 78 |
1337 | |
1338 | // Schema Upgrades must add migration code here. |
1339 | // >>> IMPORTANT! <<< |
1340 | // NEVER MIX UP SYNC AND ASYNC EXECUTION IN MIGRATORS, YOU MAY LOCK THE |
1341 | // CONNECTION AND CAUSE FURTHER STEPS TO FAIL. |
1342 | // In case, set a bool and do the async work in the ScopeExit guard just |
1343 | // before the migration steps. |
1344 | } |
1345 | } else { |
1346 | // This is a new database, so we have to create all the tables and indices. |
1347 | |
1348 | // moz_origins. |
1349 | 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) " ")")); |
1350 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1350); return rv; } } while (false); |
1351 | |
1352 | // moz_places. |
1353 | 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" ")")); |
1354 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1354); return rv; } } while (false); |
1355 | 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 " ")")); |
1356 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1356); return rv; } } while (false); |
1357 | rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_URL_HASHnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_places" "_" "url_hashindex" " ON " "moz_places" " (" "url_hash" ")")); |
1358 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1358); return rv; } } while (false); |
1359 | rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_REVHOSTnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_places" "_" "hostindex" " ON " "moz_places" " (" "rev_host" ")")); |
1360 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1360); return rv; } } while (false); |
1361 | rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_VISITCOUNTnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_places" "_" "visitcount" " ON " "moz_places" " (" "visit_count" ")")); |
1362 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1362); return rv; } } while (false); |
1363 | rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_FRECENCYnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_places" "_" "frecencyindex" " ON " "moz_places" " (" "frecency" ")")); |
1364 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1364); return rv; } } while (false); |
1365 | rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_LASTVISITDATEnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_places" "_" "lastvisitdateindex" " ON " "moz_places" " (" "last_visit_date" ")")); |
1366 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1366); return rv; } } while (false); |
1367 | rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_GUIDnsLiteralCString("CREATE " "UNIQUE" " INDEX IF NOT EXISTS " "moz_places" "_" "guid_uniqueindex" " ON " "moz_places" " (" "guid" ")")); |
1368 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1368); return rv; } } while (false); |
1369 | rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_ORIGIN_IDnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_places" "_" "originidindex" " ON " "moz_places" " (" "origin_id" ")" )); |
1370 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1370); return rv; } } while (false); |
1371 | rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_ALT_FRECENCYnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_places" "_" "altfrecencyindex" " ON " "moz_places" " (" "alt_frecency" ")")); |
1372 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1372); return rv; } } while (false); |
1373 | |
1374 | // moz_historyvisits. |
1375 | 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" ")")); |
1376 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1376); return rv; } } while (false); |
1377 | 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" ")")); |
1378 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1378); return rv; } } while (false); |
1379 | rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_PLACEDATEnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_historyvisits" "_" "placedateindex" " ON " "moz_historyvisits" " (" "place_id, visit_date" ")")); |
1380 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1380); return rv; } } while (false); |
1381 | rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_FROMVISITnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_historyvisits" "_" "fromindex" " ON " "moz_historyvisits" " (" "from_visit" ")")); |
1382 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1382); return rv; } } while (false); |
1383 | rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_VISITDATEnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_historyvisits" "_" "dateindex" " ON " "moz_historyvisits" " (" "visit_date" ")")); |
1384 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1384); return rv; } } while (false); |
1385 | |
1386 | // moz_inputhistory. |
1387 | 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)" ")")); |
1388 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1388); return rv; } } while (false); |
1389 | |
1390 | // moz_bookmarks. |
1391 | 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" ")")); |
1392 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1392); return rv; } } while (false); |
1393 | rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_BOOKMARKS_DELETEDnsLiteralCString( "CREATE TABLE moz_bookmarks_deleted (" " guid TEXT PRIMARY KEY" ", dateRemoved INTEGER NOT NULL DEFAULT 0" ")")); |
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_PLACETYPEnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_bookmarks" "_" "itemindex" " ON " "moz_bookmarks" " (" "fk, type" ")")); |
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_PARENTPOSITIONnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_bookmarks" "_" "parentindex" " ON " "moz_bookmarks" " (" "parent, position" ")")); |
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 | rv = |
1400 | mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_BOOKMARKS_PLACELASTMODIFIEDnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_bookmarks" "_" "itemlastmodifiedindex" " ON " "moz_bookmarks" " (" "fk, lastModified" ")")); |
1401 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1401); return rv; } } while (false); |
1402 | rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_BOOKMARKS_DATEADDEDnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_bookmarks" "_" "dateaddedindex" " ON " "moz_bookmarks" " (" "dateAdded" ")")); |
1403 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1403); return rv; } } while (false); |
1404 | rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_BOOKMARKS_GUIDnsLiteralCString("CREATE " "UNIQUE" " INDEX IF NOT EXISTS " "moz_bookmarks" "_" "guid_uniqueindex" " ON " "moz_bookmarks" " (" "guid" ")" )); |
1405 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1405); return rv; } } while (false); |
1406 | |
1407 | // moz_keywords. |
1408 | rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_KEYWORDSnsLiteralCString( "CREATE TABLE moz_keywords (" " id INTEGER PRIMARY KEY AUTOINCREMENT" ", keyword TEXT UNIQUE" ", place_id INTEGER" ", post_data TEXT" ")")); |
1409 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1409); return rv; } } while (false); |
1410 | 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" ")")); |
1411 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1411); return rv; } } while (false); |
1412 | |
1413 | // moz_anno_attributes. |
1414 | rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_ANNO_ATTRIBUTESnsLiteralCString( "CREATE TABLE moz_anno_attributes (" " id INTEGER PRIMARY KEY" ", name VARCHAR(32) UNIQUE NOT NULL" ")")); |
1415 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1415); return rv; } } while (false); |
1416 | |
1417 | // moz_annos. |
1418 | 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" ")")); |
1419 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1419); return rv; } } while (false); |
1420 | 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" ")")); |
1421 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1421); return rv; } } while (false); |
1422 | |
1423 | // moz_items_annos. |
1424 | 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" ")")); |
1425 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1425); return rv; } } while (false); |
1426 | 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" ")")); |
1427 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1427); return rv; } } while (false); |
1428 | |
1429 | // moz_meta. |
1430 | rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_METAnsLiteralCString( "CREATE TABLE moz_meta (" "key TEXT PRIMARY KEY, " "value NOT NULL" ") WITHOUT ROWID ")); |
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 | |
1433 | // moz_places_metadata |
1434 | 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) " ")")); |
1435 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1435); return rv; } } while (false); |
1436 | rv = mMainConn->ExecuteSimpleSQL( |
1437 | 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" ")")); |
1438 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1438); return rv; } } while (false); |
1439 | 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" ")")); |
1440 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1440); return rv; } } while (false); |
1441 | |
1442 | // moz_places_metadata_search_queries |
1443 | 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 " ")" )); |
1444 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1444); return rv; } } while (false); |
1445 | |
1446 | // moz_previews_tombstones |
1447 | rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_PREVIEWS_TOMBSTONESnsLiteralCString( "CREATE TABLE IF NOT EXISTS moz_previews_tombstones ( " " hash TEXT PRIMARY KEY " ") WITHOUT ROWID")); |
1448 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1448); return rv; } } while (false); |
1449 | |
1450 | // The bookmarks roots get initialized in CheckRoots(). |
1451 | } |
1452 | |
1453 | // Set the schema version to the current one. |
1454 | rv = mMainConn->SetSchemaVersion( |
1455 | nsINavHistoryService::DATABASE_SCHEMA_VERSION); |
1456 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1456); return rv; } } while (false); |
1457 | |
1458 | rv = transaction.Commit(); |
1459 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1459); return rv; } } while (false); |
1460 | |
1461 | // ANY FAILURE IN THIS METHOD WILL CAUSE US TO MARK THE DATABASE AS CORRUPT |
1462 | // AND TRY TO REPLACE IT. |
1463 | // DO NOT PUT HERE ANYTHING THAT IS NOT RELATED TO INITIALIZATION OR MODIFYING |
1464 | // THE DISK DATABASE. |
1465 | |
1466 | return NS_OK; |
1467 | } |
1468 | |
1469 | nsresult Database::CheckRoots() { |
1470 | 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" , 1470); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { *((volatile int*)__null) = 1470; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1471 | |
1472 | // If the database has just been created, skip straight to the part where |
1473 | // we create the roots. |
1474 | if (mDatabaseStatus == nsINavHistoryService::DATABASE_STATUS_CREATE) { |
1475 | return EnsureBookmarkRoots(0, /* shouldReparentRoots */ false); |
1476 | } |
1477 | |
1478 | nsCOMPtr<mozIStorageStatement> stmt; |
1479 | nsresult rv = mMainConn->CreateStatement( |
1480 | nsLiteralCString("SELECT guid, id, position, parent FROM moz_bookmarks " |
1481 | "WHERE guid IN ( " |
1482 | "'" ROOT_GUID"root________" "', '" MENU_ROOT_GUID"menu________" |
1483 | "', '" TOOLBAR_ROOT_GUID"toolbar_____" "', " |
1484 | "'" TAGS_ROOT_GUID"tags________" "', '" UNFILED_ROOT_GUID"unfiled_____" |
1485 | "', '" MOBILE_ROOT_GUID"mobile______" "' )"), |
1486 | getter_AddRefs(stmt)); |
1487 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1487); return rv; } } while (false); |
1488 | |
1489 | bool hasResult; |
1490 | nsAutoCString guid; |
1491 | int32_t maxPosition = 0; |
1492 | bool shouldReparentRoots = false; |
1493 | while (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(stmt->ExecuteStep (&hasResult))), 1))) && hasResult) { |
1494 | rv = stmt->GetUTF8String(0, guid); |
1495 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1495); return rv; } } while (false); |
1496 | |
1497 | int64_t parentId = stmt->AsInt64(3); |
1498 | |
1499 | if (guid.EqualsLiteral(ROOT_GUID"root________")) { |
1500 | mRootId = stmt->AsInt64(1); |
1501 | shouldReparentRoots |= parentId != 0; |
1502 | } else { |
1503 | maxPosition = std::max(stmt->AsInt32(2), maxPosition); |
1504 | |
1505 | if (guid.EqualsLiteral(MENU_ROOT_GUID"menu________")) { |
1506 | mMenuRootId = stmt->AsInt64(1); |
1507 | } else if (guid.EqualsLiteral(TOOLBAR_ROOT_GUID"toolbar_____")) { |
1508 | mToolbarRootId = stmt->AsInt64(1); |
1509 | } else if (guid.EqualsLiteral(TAGS_ROOT_GUID"tags________")) { |
1510 | mTagsRootId = stmt->AsInt64(1); |
1511 | } else if (guid.EqualsLiteral(UNFILED_ROOT_GUID"unfiled_____")) { |
1512 | mUnfiledRootId = stmt->AsInt64(1); |
1513 | } else if (guid.EqualsLiteral(MOBILE_ROOT_GUID"mobile______")) { |
1514 | mMobileRootId = stmt->AsInt64(1); |
1515 | } |
1516 | shouldReparentRoots |= parentId != mRootId; |
1517 | } |
1518 | } |
1519 | |
1520 | rv = EnsureBookmarkRoots(maxPosition + 1, shouldReparentRoots); |
1521 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1521); return rv; } } while (false); |
1522 | |
1523 | return NS_OK; |
1524 | } |
1525 | |
1526 | nsresult Database::EnsureBookmarkRoots(const int32_t startPosition, |
1527 | bool shouldReparentRoots) { |
1528 | 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" , 1528); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { *((volatile int*)__null) = 1528; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1529 | |
1530 | nsresult rv; |
1531 | |
1532 | if (mRootId < 1) { |
1533 | // The first root's title is an empty string. |
1534 | rv = CreateRoot(mMainConn, "places"_ns, "root________"_ns, ""_ns, 0, |
1535 | mRootId); |
1536 | |
1537 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
1538 | } |
1539 | |
1540 | int32_t position = startPosition; |
1541 | |
1542 | // For the other roots, the UI doesn't rely on the value in the database, so |
1543 | // just set it to something simple to make it easier for humans to read. |
1544 | if (mMenuRootId < 1) { |
1545 | rv = CreateRoot(mMainConn, "menu"_ns, "menu________"_ns, "menu"_ns, |
1546 | position, mMenuRootId); |
1547 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
1548 | position++; |
1549 | } |
1550 | |
1551 | if (mToolbarRootId < 1) { |
1552 | rv = CreateRoot(mMainConn, "toolbar"_ns, "toolbar_____"_ns, "toolbar"_ns, |
1553 | position, mToolbarRootId); |
1554 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
1555 | position++; |
1556 | } |
1557 | |
1558 | if (mTagsRootId < 1) { |
1559 | rv = CreateRoot(mMainConn, "tags"_ns, "tags________"_ns, "tags"_ns, |
1560 | position, mTagsRootId); |
1561 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
1562 | position++; |
1563 | } |
1564 | |
1565 | if (mUnfiledRootId < 1) { |
1566 | rv = CreateRoot(mMainConn, "unfiled"_ns, "unfiled_____"_ns, "unfiled"_ns, |
1567 | position, mUnfiledRootId); |
1568 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
1569 | position++; |
1570 | } |
1571 | |
1572 | if (mMobileRootId < 1) { |
1573 | int64_t mobileRootId = CreateMobileRoot(); |
1574 | if (mobileRootId <= 0) return NS_ERROR_FAILURE; |
1575 | { |
1576 | nsCOMPtr<mozIStorageStatement> mobileRootSyncStatusStmt; |
1577 | rv = mMainConn->CreateStatement( |
1578 | nsLiteralCString("UPDATE moz_bookmarks SET syncStatus = " |
1579 | ":sync_status WHERE id = :id"), |
1580 | getter_AddRefs(mobileRootSyncStatusStmt)); |
1581 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
1582 | |
1583 | rv = mobileRootSyncStatusStmt->BindInt32ByName( |
1584 | "sync_status"_ns, nsINavBookmarksService::SYNC_STATUS_NEW); |
1585 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
1586 | rv = mobileRootSyncStatusStmt->BindInt64ByName("id"_ns, mobileRootId); |
1587 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
1588 | |
1589 | rv = mobileRootSyncStatusStmt->Execute(); |
1590 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
1591 | |
1592 | mMobileRootId = mobileRootId; |
1593 | } |
1594 | } |
1595 | |
1596 | if (!shouldReparentRoots) { |
1597 | return NS_OK; |
1598 | } |
1599 | |
1600 | // At least one root had the wrong parent, so we need to ensure that |
1601 | // all roots are parented correctly, fix their positions, and bump the |
1602 | // Sync change counter. |
1603 | rv = mMainConn->ExecuteSimpleSQL(nsLiteralCString( |
1604 | "CREATE TEMP TRIGGER moz_ensure_bookmark_roots_trigger " |
1605 | "AFTER UPDATE OF parent ON moz_bookmarks FOR EACH ROW " |
1606 | "WHEN OLD.parent <> NEW.parent " |
1607 | "BEGIN " |
1608 | "UPDATE moz_bookmarks SET " |
1609 | "syncChangeCounter = syncChangeCounter + 1 " |
1610 | "WHERE id IN (OLD.parent, NEW.parent, NEW.id); " |
1611 | |
1612 | "UPDATE moz_bookmarks SET " |
1613 | "position = position - 1 " |
1614 | "WHERE parent = OLD.parent AND position >= OLD.position; " |
1615 | |
1616 | // Fix the positions of the root's old siblings. Since we've already |
1617 | // moved the root, we need to exclude it from the subquery. |
1618 | "UPDATE moz_bookmarks SET " |
1619 | "position = IFNULL((SELECT MAX(position) + 1 FROM moz_bookmarks " |
1620 | "WHERE parent = NEW.parent AND " |
1621 | "id <> NEW.id), 0)" |
1622 | "WHERE id = NEW.id; " |
1623 | "END")); |
1624 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
1625 | auto guard = MakeScopeExit([&]() { |
1626 | Unused << mMainConn->ExecuteSimpleSQL( |
1627 | "DROP TRIGGER moz_ensure_bookmark_roots_trigger"_ns); |
1628 | }); |
1629 | |
1630 | nsCOMPtr<mozIStorageStatement> reparentStmt; |
1631 | rv = mMainConn->CreateStatement( |
1632 | nsLiteralCString( |
1633 | "UPDATE moz_bookmarks SET " |
1634 | "parent = CASE id WHEN :root_id THEN 0 ELSE :root_id END " |
1635 | "WHERE id IN (:root_id, :menu_root_id, :toolbar_root_id, " |
1636 | ":tags_root_id, " |
1637 | ":unfiled_root_id, :mobile_root_id)"), |
1638 | getter_AddRefs(reparentStmt)); |
1639 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
1640 | |
1641 | rv = reparentStmt->BindInt64ByName("root_id"_ns, mRootId); |
1642 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
1643 | rv = reparentStmt->BindInt64ByName("menu_root_id"_ns, mMenuRootId); |
1644 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
1645 | rv = reparentStmt->BindInt64ByName("toolbar_root_id"_ns, mToolbarRootId); |
1646 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
1647 | rv = reparentStmt->BindInt64ByName("tags_root_id"_ns, mTagsRootId); |
1648 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
1649 | rv = reparentStmt->BindInt64ByName("unfiled_root_id"_ns, mUnfiledRootId); |
1650 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
1651 | rv = reparentStmt->BindInt64ByName("mobile_root_id"_ns, mMobileRootId); |
1652 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
1653 | |
1654 | rv = reparentStmt->Execute(); |
1655 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
1656 | |
1657 | return NS_OK; |
1658 | } |
1659 | |
1660 | nsresult Database::InitFunctions() { |
1661 | 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" , 1661); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { *((volatile int*)__null) = 1661; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1662 | |
1663 | nsresult rv = GetUnreversedHostFunction::create(mMainConn); |
1664 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1664); return rv; } } while (false); |
1665 | rv = MatchAutoCompleteFunction::create(mMainConn); |
1666 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1666); return rv; } } while (false); |
1667 | rv = CalculateFrecencyFunction::create(mMainConn); |
1668 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1668); return rv; } } while (false); |
1669 | rv = GenerateGUIDFunction::create(mMainConn); |
1670 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1670); return rv; } } while (false); |
1671 | rv = IsValidGUIDFunction::create(mMainConn); |
1672 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1672); return rv; } } while (false); |
1673 | rv = FixupURLFunction::create(mMainConn); |
1674 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1674); return rv; } } while (false); |
1675 | rv = StoreLastInsertedIdFunction::create(mMainConn); |
1676 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1676); return rv; } } while (false); |
1677 | rv = HashFunction::create(mMainConn); |
1678 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1678); return rv; } } while (false); |
1679 | rv = GetQueryParamFunction::create(mMainConn); |
1680 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1680); return rv; } } while (false); |
1681 | rv = GetPrefixFunction::create(mMainConn); |
1682 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1682); return rv; } } while (false); |
1683 | rv = GetHostAndPortFunction::create(mMainConn); |
1684 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1684); return rv; } } while (false); |
1685 | rv = StripPrefixAndUserinfoFunction::create(mMainConn); |
1686 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1686); return rv; } } while (false); |
1687 | rv = IsFrecencyDecayingFunction::create(mMainConn); |
1688 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1688); return rv; } } while (false); |
1689 | rv = NoteSyncChangeFunction::create(mMainConn); |
1690 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1690); return rv; } } while (false); |
1691 | rv = InvalidateDaysOfHistoryFunction::create(mMainConn); |
1692 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1692); return rv; } } while (false); |
1693 | rv = SHA256HexFunction::create(mMainConn); |
1694 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1694); return rv; } } while (false); |
1695 | rv = SetShouldStartFrecencyRecalculationFunction::create(mMainConn); |
1696 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1696); return rv; } } while (false); |
1697 | rv = TargetFolderGuidFunction::create(mMainConn); |
1698 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1698); return rv; } } while (false); |
1699 | |
1700 | if (StaticPrefs::places_frecency_pages_alternative_featureGate_AtStartup()) { |
1701 | rv = CalculateAltFrecencyFunction::create(mMainConn); |
1702 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1702); return rv; } } while (false); |
1703 | } |
1704 | |
1705 | return NS_OK; |
1706 | } |
1707 | |
1708 | nsresult Database::InitTempEntities() { |
1709 | 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" , 1709); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { *((volatile int*)__null) = 1709; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1710 | |
1711 | nsresult rv = |
1712 | 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")); |
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(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")); |
1715 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1715); return rv; } } while (false); |
1716 | |
1717 | 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")); |
1718 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1718); return rv; } } while (false); |
1719 | 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")); |
1720 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1720); return rv; } } while (false); |
1721 | rv = mMainConn->ExecuteSimpleSQL( |
1722 | 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")); |
1723 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1723); return rv; } } while (false); |
1724 | |
1725 | if (Preferences::GetBool(PREF_PREVIEWS_ENABLED"places.previews.enabled", false)) { |
1726 | rv = mMainConn->ExecuteSimpleSQL( |
1727 | 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 ")); |
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 | } else { |
1730 | 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 ")); |
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 | } |
1733 | |
1734 | 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 ")); |
1735 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1735); return rv; } } while (false); |
1736 | rv = mMainConn->ExecuteSimpleSQL( |
1737 | 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")); |
1738 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1738); return rv; } } while (false); |
1739 | rv = mMainConn->ExecuteSimpleSQL( |
1740 | 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")); |
1741 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1741); return rv; } } while (false); |
1742 | 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")); |
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 | |
1745 | rv = mMainConn->ExecuteSimpleSQL( |
1746 | 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")); |
1747 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1747); return rv; } } while (false); |
1748 | rv = mMainConn->ExecuteSimpleSQL( |
1749 | 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")); |
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_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")); |
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 | |
1755 | rv = mMainConn->ExecuteSimpleSQL( |
1756 | 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")); |
1757 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1757); return rv; } } while (false); |
1758 | rv = mMainConn->ExecuteSimpleSQL( |
1759 | 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")); |
1760 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1760); return rv; } } while (false); |
1761 | rv = mMainConn->ExecuteSimpleSQL( |
1762 | 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")); |
1763 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1763); return rv; } } while (false); |
1764 | rv = |
1765 | 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")); |
1766 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1766); return rv; } } while (false); |
1767 | rv = |
1768 | 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")); |
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 | |
1771 | 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")); |
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 | // Create triggers to remove rows with empty json |
1775 | 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")); |
1776 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1776); return rv; } } while (false); |
1777 | rv = |
1778 | 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")); |
1779 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1779); return rv; } } while (false); |
1780 | |
1781 | return NS_OK; |
1782 | } |
1783 | |
1784 | nsresult Database::MigrateV53Up() { |
1785 | nsCOMPtr<mozIStorageStatement> stmt; |
1786 | nsresult rv = mMainConn->CreateStatement("SELECT 1 FROM moz_items_annos"_ns, |
1787 | getter_AddRefs(stmt)); |
1788 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1789 | // Likely we removed the table. |
1790 | return NS_OK; |
1791 | } |
1792 | |
1793 | // Remove all item annotations but SYNC_PARENT_ANNO. |
1794 | rv = mMainConn->CreateStatement( |
1795 | nsLiteralCString( |
1796 | "DELETE FROM moz_items_annos " |
1797 | "WHERE anno_attribute_id NOT IN ( " |
1798 | " SELECT id FROM moz_anno_attributes WHERE name = :anno_name " |
1799 | ") "), |
1800 | getter_AddRefs(stmt)); |
1801 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1801); return rv; } } while (false); |
1802 | rv = stmt->BindUTF8StringByName("anno_name"_ns, |
1803 | nsLiteralCString(SYNC_PARENT_ANNO"sync/parent")); |
1804 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1804); return rv; } } while (false); |
1805 | rv = stmt->Execute(); |
1806 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1806); return rv; } } while (false); |
1807 | |
1808 | rv = mMainConn->ExecuteSimpleSQL(nsLiteralCString( |
1809 | "DELETE FROM moz_anno_attributes WHERE id IN ( " |
1810 | " SELECT id FROM moz_anno_attributes " |
1811 | " EXCEPT " |
1812 | " SELECT DISTINCT anno_attribute_id FROM moz_annos " |
1813 | " EXCEPT " |
1814 | " SELECT DISTINCT anno_attribute_id FROM moz_items_annos " |
1815 | ")")); |
1816 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1816); return rv; } } while (false); |
1817 | |
1818 | return NS_OK; |
1819 | } |
1820 | |
1821 | nsresult Database::MigrateV54Up() { |
1822 | // Add an expiration column to moz_icons_to_pages. |
1823 | nsCOMPtr<mozIStorageStatement> stmt; |
1824 | nsresult rv = mMainConn->CreateStatement( |
1825 | "SELECT expire_ms FROM moz_icons_to_pages"_ns, getter_AddRefs(stmt)); |
1826 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1827 | rv = mMainConn->ExecuteSimpleSQL( |
1828 | "ALTER TABLE moz_icons_to_pages " |
1829 | "ADD COLUMN expire_ms INTEGER NOT NULL DEFAULT 0 "_ns); |
1830 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1830); return rv; } } while (false); |
1831 | } |
1832 | |
1833 | // Set all the zero-ed entries as expired today, they won't be removed until |
1834 | // the next related page load. |
1835 | rv = mMainConn->ExecuteSimpleSQL( |
1836 | "UPDATE moz_icons_to_pages " |
1837 | "SET expire_ms = strftime('%s','now','localtime','start " |
1838 | "of day','utc') * 1000 " |
1839 | "WHERE expire_ms = 0 "_ns); |
1840 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1840); return rv; } } while (false); |
1841 | |
1842 | return NS_OK; |
1843 | } |
1844 | |
1845 | nsresult Database::MigrateV55Up() { |
1846 | // Add places metadata tables. |
1847 | nsCOMPtr<mozIStorageStatement> stmt; |
1848 | nsresult rv = mMainConn->CreateStatement( |
1849 | "SELECT id FROM moz_places_metadata"_ns, getter_AddRefs(stmt)); |
1850 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1851 | // Create the tables. |
1852 | 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) " ")")); |
1853 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1853); return rv; } } while (false); |
1854 | // moz_places_metadata_search_queries. |
1855 | 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 " ")" )); |
1856 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1856); return rv; } } while (false); |
1857 | } |
1858 | |
1859 | return NS_OK; |
1860 | } |
1861 | |
1862 | nsresult Database::MigrateV56Up() { |
1863 | // Add places metadata (place_id, created_at) index. |
1864 | return mMainConn->ExecuteSimpleSQL( |
1865 | 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" ")")); |
1866 | } |
1867 | |
1868 | nsresult Database::MigrateV57Up() { |
1869 | // Add the scrolling columns to the metadata. |
1870 | nsCOMPtr<mozIStorageStatement> stmt; |
1871 | nsresult rv = mMainConn->CreateStatement( |
1872 | "SELECT scrolling_time FROM moz_places_metadata"_ns, |
1873 | getter_AddRefs(stmt)); |
1874 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1875 | rv = mMainConn->ExecuteSimpleSQL( |
1876 | "ALTER TABLE moz_places_metadata " |
1877 | "ADD COLUMN scrolling_time INTEGER NOT NULL DEFAULT 0 "_ns); |
1878 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1878); return rv; } } while (false); |
1879 | } |
1880 | |
1881 | rv = mMainConn->CreateStatement( |
1882 | "SELECT scrolling_distance FROM moz_places_metadata"_ns, |
1883 | getter_AddRefs(stmt)); |
1884 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1885 | rv = mMainConn->ExecuteSimpleSQL( |
1886 | "ALTER TABLE moz_places_metadata " |
1887 | "ADD COLUMN scrolling_distance INTEGER NOT NULL DEFAULT 0 "_ns); |
1888 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1888); return rv; } } while (false); |
1889 | } |
1890 | return NS_OK; |
1891 | } |
1892 | |
1893 | nsresult Database::MigrateV60Up() { |
1894 | // Add the site_name column to moz_places. |
1895 | nsCOMPtr<mozIStorageStatement> stmt; |
1896 | nsresult rv = mMainConn->CreateStatement( |
1897 | "SELECT site_name FROM moz_places"_ns, getter_AddRefs(stmt)); |
1898 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1899 | rv = mMainConn->ExecuteSimpleSQL( |
1900 | "ALTER TABLE moz_places ADD COLUMN site_name TEXT"_ns); |
1901 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1901); return rv; } } while (false); |
1902 | } |
1903 | return NS_OK; |
1904 | } |
1905 | |
1906 | nsresult Database::MigrateV61Up() { |
1907 | // Add previews tombstones table if necessary. |
1908 | nsCOMPtr<mozIStorageStatement> stmt; |
1909 | nsresult rv = mMainConn->CreateStatement( |
1910 | "SELECT hash FROM moz_previews_tombstones"_ns, getter_AddRefs(stmt)); |
1911 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1912 | rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_PREVIEWS_TOMBSTONESnsLiteralCString( "CREATE TABLE IF NOT EXISTS moz_previews_tombstones ( " " hash TEXT PRIMARY KEY " ") WITHOUT ROWID")); |
1913 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1913); return rv; } } while (false); |
1914 | } |
1915 | return NS_OK; |
1916 | } |
1917 | |
1918 | nsresult Database::MigrateV67Up() { |
1919 | // Align all input field in moz_inputhistory to lowercase. If there are |
1920 | // multiple records that expresses the same input, use maximum use_count from |
1921 | // them to carry on the experience of the past. |
1922 | nsCOMPtr<mozIStorageStatement> stmt; |
1923 | nsresult rv = mMainConn->ExecuteSimpleSQL( |
1924 | "INSERT INTO moz_inputhistory " |
1925 | "SELECT place_id, LOWER(input), use_count FROM moz_inputhistory " |
1926 | " WHERE LOWER(input) <> input " |
1927 | "ON CONFLICT DO " |
1928 | " UPDATE SET use_count = MAX(use_count, EXCLUDED.use_count)"_ns); |
1929 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1929); return rv; } } while (false); |
1930 | rv = mMainConn->ExecuteSimpleSQL( |
1931 | "DELETE FROM moz_inputhistory WHERE LOWER(input) <> input"_ns); |
1932 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1932); return rv; } } while (false); |
1933 | |
1934 | return NS_OK; |
1935 | } |
1936 | |
1937 | nsresult Database::MigrateV69Up() { |
1938 | // Add source and annotation column to places table. |
1939 | nsCOMPtr<mozIStorageStatement> stmt; |
1940 | nsresult rv = mMainConn->CreateStatement( |
1941 | "SELECT source FROM moz_historyvisits"_ns, getter_AddRefs(stmt)); |
1942 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1943 | rv = mMainConn->ExecuteSimpleSQL( |
1944 | "ALTER TABLE moz_historyvisits " |
1945 | "ADD COLUMN source INTEGER DEFAULT 0 NOT NULL"_ns); |
1946 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1946); return rv; } } while (false); |
1947 | rv = mMainConn->ExecuteSimpleSQL( |
1948 | "ALTER TABLE moz_historyvisits " |
1949 | "ADD COLUMN triggeringPlaceId INTEGER"_ns); |
1950 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1950); return rv; } } while (false); |
1951 | } |
1952 | |
1953 | return NS_OK; |
1954 | } |
1955 | |
1956 | nsresult Database::MigrateV70Up() { |
1957 | nsCOMPtr<mozIStorageStatement> stmt; |
1958 | nsresult rv = mMainConn->CreateStatement( |
1959 | "SELECT recalc_frecency FROM moz_places LIMIT 1 "_ns, |
1960 | getter_AddRefs(stmt)); |
1961 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1962 | // Add recalc_frecency column, indicating frecency has to be recalculated. |
1963 | rv = mMainConn->ExecuteSimpleSQL( |
1964 | "ALTER TABLE moz_places " |
1965 | "ADD COLUMN recalc_frecency INTEGER NOT NULL DEFAULT 0 "_ns); |
1966 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1966); return rv; } } while (false); |
1967 | } |
1968 | |
1969 | // We must do the following updates regardless, for downgrade/upgrade cases. |
1970 | |
1971 | // moz_origins frecency is, at the time of this migration, the sum of all the |
1972 | // positive frecencies of pages linked to that origin. Frecencies that were |
1973 | // set to negative to request recalculation are thus not accounted for, and |
1974 | // since we're about to flip them to positive we should add them to their |
1975 | // origin. Then we must also update origins stats. |
1976 | // We ignore frecency = -1 because it's just an indication to recalculate |
1977 | // frecency and not an actual frecency value that was flipped, thus it would |
1978 | // not make sense to count it for the origin. |
1979 | rv = mMainConn->ExecuteSimpleSQL( |
1980 | "UPDATE moz_origins " |
1981 | "SET frecency = frecency + abs_frecency " |
1982 | "FROM (SELECT origin_id, ABS(frecency) AS abs_frecency FROM moz_places " |
1983 | "WHERE frecency < -1) AS places " |
1984 | "WHERE moz_origins.id = places.origin_id"_ns); |
1985 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1985); return rv; } } while (false); |
1986 | rv = mMainConn->ExecuteSimpleSQL( |
1987 | "INSERT OR REPLACE INTO moz_meta(key, value) VALUES " |
1988 | "('origin_frecency_count', " |
1989 | "(SELECT COUNT(*) FROM moz_origins WHERE frecency > 0) " |
1990 | "), " |
1991 | "('origin_frecency_sum', " |
1992 | "(SELECT TOTAL(frecency) FROM moz_origins WHERE frecency > 0) " |
1993 | "), " |
1994 | "('origin_frecency_sum_of_squares', " |
1995 | "(SELECT TOTAL(frecency * frecency) FROM moz_origins WHERE frecency > 0) " |
1996 | ") "_ns); |
1997 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 1997); return rv; } } while (false); |
1998 | |
1999 | // Now set recalc_frecency = 1 and positive frecency to any page having a |
2000 | // negative frecency. |
2001 | // Note we don't flip frecency = -1, since we skipped it above when updating |
2002 | // origins, and it remains an acceptable value yet, until the recalculation. |
2003 | rv = mMainConn->ExecuteSimpleSQL( |
2004 | "UPDATE moz_places " |
2005 | "SET recalc_frecency = 1, " |
2006 | " frecency = CASE WHEN frecency = -1 THEN -1 ELSE ABS(frecency) END " |
2007 | "WHERE frecency < 0 "_ns); |
2008 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2008); return rv; } } while (false); |
2009 | |
2010 | return NS_OK; |
2011 | } |
2012 | |
2013 | nsresult Database::MigrateV71Up() { |
2014 | // Fix the foreign counts. We ignore failures as the tables may not exist. |
2015 | mMainConn->ExecuteSimpleSQL( |
2016 | "UPDATE moz_places " |
2017 | "SET foreign_count = foreign_count - 1 " |
2018 | "WHERE id in (SELECT place_id FROM moz_places_metadata_snapshots)"_ns); |
2019 | mMainConn->ExecuteSimpleSQL( |
2020 | "UPDATE moz_places " |
2021 | "SET foreign_count = foreign_count - 1 " |
2022 | "WHERE id in (SELECT place_id FROM moz_session_to_places)"_ns); |
2023 | |
2024 | // Remove unused snapshots and session tables and indexes. |
2025 | nsresult rv = mMainConn->ExecuteSimpleSQL( |
2026 | "DROP INDEX IF EXISTS moz_places_metadata_snapshots_pinnedindex"_ns); |
2027 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2027); return rv; } } while (false); |
2028 | rv = mMainConn->ExecuteSimpleSQL( |
2029 | "DROP INDEX IF EXISTS moz_places_metadata_snapshots_extra_typeindex"_ns); |
2030 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2030); return rv; } } while (false); |
2031 | rv = mMainConn->ExecuteSimpleSQL( |
2032 | "DROP TABLE IF EXISTS moz_places_metadata_groups_to_snapshots"_ns); |
2033 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2033); return rv; } } while (false); |
2034 | rv = mMainConn->ExecuteSimpleSQL( |
2035 | "DROP TABLE IF EXISTS moz_places_metadata_snapshots_groups"_ns); |
2036 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2036); return rv; } } while (false); |
2037 | rv = mMainConn->ExecuteSimpleSQL( |
2038 | "DROP TABLE IF EXISTS moz_places_metadata_snapshots_extra"_ns); |
2039 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2039); return rv; } } while (false); |
2040 | rv = mMainConn->ExecuteSimpleSQL( |
2041 | "DROP TABLE IF EXISTS moz_places_metadata_snapshots"_ns); |
2042 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2042); return rv; } } while (false); |
2043 | rv = mMainConn->ExecuteSimpleSQL( |
2044 | "DROP TABLE IF EXISTS moz_session_to_places"_ns); |
2045 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2045); return rv; } } while (false); |
2046 | rv = mMainConn->ExecuteSimpleSQL( |
2047 | "DROP TABLE IF EXISTS moz_session_metadata"_ns); |
2048 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2048); return rv; } } while (false); |
2049 | |
2050 | return NS_OK; |
2051 | } |
2052 | |
2053 | nsresult Database::MigrateV72Up() { |
2054 | // Recalculate frecency of unvisited bookmarks. |
2055 | nsresult rv = mMainConn->ExecuteSimpleSQL( |
2056 | "UPDATE moz_places " |
2057 | "SET recalc_frecency = 1 " |
2058 | "WHERE foreign_count > 0 AND visit_count = 0"_ns); |
2059 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2059); return rv; } } while (false); |
2060 | return NS_OK; |
2061 | } |
2062 | |
2063 | nsresult Database::MigrateV73Up() { |
2064 | // Add recalc_frecency, alt_frecency and recalc_alt_frecency to moz_origins. |
2065 | nsCOMPtr<mozIStorageStatement> stmt; |
2066 | nsresult rv = mMainConn->CreateStatement( |
2067 | "SELECT recalc_frecency FROM moz_origins"_ns, getter_AddRefs(stmt)); |
2068 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2069 | rv = mMainConn->ExecuteSimpleSQL( |
2070 | "ALTER TABLE moz_origins " |
2071 | "ADD COLUMN recalc_frecency INTEGER NOT NULL DEFAULT 0"_ns); |
2072 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2072); return rv; } } while (false); |
2073 | rv = mMainConn->ExecuteSimpleSQL( |
2074 | "ALTER TABLE moz_origins " |
2075 | "ADD COLUMN alt_frecency INTEGER"_ns); |
2076 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2076); return rv; } } while (false); |
2077 | rv = mMainConn->ExecuteSimpleSQL( |
2078 | "ALTER TABLE moz_origins " |
2079 | "ADD COLUMN recalc_alt_frecency INTEGER NOT NULL DEFAULT 0"_ns); |
2080 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2080); return rv; } } while (false); |
2081 | } |
2082 | return NS_OK; |
2083 | } |
2084 | |
2085 | nsresult Database::MigrateV74Up() { |
2086 | // Add alt_frecency and recalc_alt_frecency to moz_places. |
2087 | nsCOMPtr<mozIStorageStatement> stmt; |
2088 | nsresult rv = mMainConn->CreateStatement( |
2089 | "SELECT alt_frecency FROM moz_places"_ns, getter_AddRefs(stmt)); |
2090 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2091 | rv = mMainConn->ExecuteSimpleSQL( |
2092 | "ALTER TABLE moz_places " |
2093 | "ADD COLUMN alt_frecency INTEGER"_ns); |
2094 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2094); return rv; } } while (false); |
2095 | rv = mMainConn->ExecuteSimpleSQL( |
2096 | "ALTER TABLE moz_places " |
2097 | "ADD COLUMN recalc_alt_frecency INTEGER NOT NULL DEFAULT 0"_ns); |
2098 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2098); return rv; } } while (false); |
2099 | rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_ALT_FRECENCYnsLiteralCString("CREATE " "" " INDEX IF NOT EXISTS " "moz_places" "_" "altfrecencyindex" " ON " "moz_places" " (" "alt_frecency" ")")); |
2100 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2100); return rv; } } while (false); |
2101 | } |
2102 | return NS_OK; |
2103 | } |
2104 | |
2105 | nsresult Database::MigrateV75Up() { |
2106 | // Add *_extra tables for moz_places and moz_historyvisits |
2107 | nsCOMPtr<mozIStorageStatement> stmt; |
2108 | nsresult rv = mMainConn->CreateStatement( |
2109 | "SELECT sync_json FROM moz_places_extra"_ns, getter_AddRefs(stmt)); |
2110 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2111 | 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 " ")")); |
2112 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2112); return rv; } } while (false); |
2113 | 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" ")")); |
2114 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2114); return rv; } } while (false); |
2115 | } |
2116 | return NS_OK; |
2117 | } |
2118 | |
2119 | nsresult Database::MigrateV77Up() { |
2120 | // Recalculate origins frecency. |
2121 | nsCOMPtr<mozIStorageStatement> stmt; |
2122 | nsresult rv = mMainConn->ExecuteSimpleSQL( |
2123 | "UPDATE moz_origins SET recalc_frecency = 1"_ns); |
2124 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2124); return rv; } } while (false); |
2125 | return NS_OK; |
2126 | } |
2127 | |
2128 | nsresult Database::MigrateV78Up() { |
2129 | // Add flags to moz_icons. |
2130 | nsCOMPtr<mozIStorageStatement> stmt; |
2131 | nsresult rv = mMainConn->CreateStatement("SELECT flags FROM moz_icons"_ns, |
2132 | getter_AddRefs(stmt)); |
2133 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2134 | rv = mMainConn->ExecuteSimpleSQL( |
2135 | "ALTER TABLE moz_icons " |
2136 | "ADD COLUMN flags INTEGER NOT NULL DEFAULT 0"_ns); |
2137 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/Database.cpp" , 2137); return rv; } } while (false); |
2138 | } |
2139 | return NS_OK; |
2140 | } |
2141 | |
2142 | int64_t Database::CreateMobileRoot() { |
2143 | 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" , 2143); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { *((volatile int*)__null) = 2143; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2144 | |
2145 | // Create the mobile root, ignoring conflicts if one already exists (for |
2146 | // example, if the user downgraded to an earlier release channel). |
2147 | nsCOMPtr<mozIStorageStatement> createStmt; |
2148 | nsresult rv = mMainConn->CreateStatement( |
2149 | nsLiteralCString( |
2150 | "INSERT OR IGNORE INTO moz_bookmarks " |
2151 | "(type, title, dateAdded, lastModified, guid, position, parent) " |
2152 | "SELECT :item_type, :item_title, :timestamp, :timestamp, :guid, " |
2153 | "IFNULL((SELECT MAX(position) + 1 FROM moz_bookmarks p WHERE " |
2154 | "p.parent = b.id), 0), b.id " |
2155 | "FROM moz_bookmarks b WHERE b.parent = 0"), |
2156 | getter_AddRefs(createStmt)); |
2157 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return -1; |
2158 | |
2159 | rv = createStmt->BindInt32ByName("item_type"_ns, |
2160 | nsINavBookmarksService::TYPE_FOLDER); |
2161 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return -1; |
2162 | rv = createStmt->BindUTF8StringByName("item_title"_ns, |
2163 | nsLiteralCString(MOBILE_ROOT_TITLE"mobile")); |
2164 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return -1; |
2165 | rv = createStmt->BindInt64ByName("timestamp"_ns, RoundedPRNow()); |
2166 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return -1; |
2167 | rv = createStmt->BindUTF8StringByName("guid"_ns, |
2168 | nsLiteralCString(MOBILE_ROOT_GUID"mobile______")); |
2169 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return -1; |
2170 | |
2171 | rv = createStmt->Execute(); |
2172 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return -1; |
2173 | |
2174 | // Find the mobile root ID. We can't use the last inserted ID because the |
2175 | // root might already exist, and we ignore on conflict. |
2176 | nsCOMPtr<mozIStorageStatement> findIdStmt; |
2177 | rv = mMainConn->CreateStatement( |
2178 | "SELECT id FROM moz_bookmarks WHERE guid = :guid"_ns, |
2179 | getter_AddRefs(findIdStmt)); |
2180 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return -1; |
2181 | |
2182 | rv = findIdStmt->BindUTF8StringByName("guid"_ns, |
2183 | nsLiteralCString(MOBILE_ROOT_GUID"mobile______")); |
2184 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return -1; |
2185 | |
2186 | bool hasResult = false; |
2187 | rv = findIdStmt->ExecuteStep(&hasResult); |
2188 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) || !hasResult) return -1; |
2189 | |
2190 | int64_t rootId; |
2191 | rv = findIdStmt->GetInt64(0, &rootId); |
2192 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return -1; |
2193 | |
2194 | return rootId; |
2195 | } |
2196 | |
2197 | void Database::Shutdown() { |
2198 | // As the last step in the shutdown path, finalize the database handle. |
2199 | 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" , 2199); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { *((volatile int*)__null) = 2199; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2200 | 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" , 2200); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mClosed" ")" ); do { *((volatile int*)__null) = 2200; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2201 | |
2202 | // Break cycles with the shutdown blockers. |
2203 | mClientsShutdown = nullptr; |
2204 | nsCOMPtr<mozIStorageCompletionCallback> connectionShutdown = |
2205 | std::move(mConnectionShutdown); |
2206 | |
2207 | if (!mMainConn) { |
2208 | // The connection has never been initialized. Just mark it as closed. |
2209 | mClosed = true; |
2210 | (void)connectionShutdown->Complete(NS_OK, nullptr); |
2211 | return; |
2212 | } |
2213 | |
2214 | #ifdef DEBUG1 |
2215 | { |
2216 | bool hasResult; |
2217 | nsCOMPtr<mozIStorageStatement> stmt; |
2218 | |
2219 | // Sanity check for missing guids. |
2220 | nsresult rv = |
2221 | mMainConn->CreateStatement(nsLiteralCString("SELECT 1 " |
2222 | "FROM moz_places " |
2223 | "WHERE guid IS NULL "), |
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 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" , 2228); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!hasResult" ") (" "Found a page without a GUID!" ")"); do { *((volatile int *)__null) = 2228; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
2229 | rv = mMainConn->CreateStatement(nsLiteralCString("SELECT 1 " |
2230 | "FROM moz_bookmarks " |
2231 | "WHERE guid IS NULL "), |
2232 | 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 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" , 2236); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!hasResult" ") (" "Found a bookmark without a GUID!" ")"); do { *((volatile int*)__null) = 2236; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
2237 | |
2238 | // Sanity check for unrounded dateAdded and lastModified values (bug |
2239 | // 1107308). |
2240 | rv = mMainConn->CreateStatement( |
2241 | nsLiteralCString( |
2242 | "SELECT 1 " |
2243 | "FROM moz_bookmarks " |
2244 | "WHERE dateAdded % 1000 > 0 OR lastModified % 1000 > 0 LIMIT 1"), |
2245 | getter_AddRefs(stmt)); |
2246 | 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" , 2246); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { *((volatile int*)__null) = 2246; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2247 | rv = stmt->ExecuteStep(&hasResult); |
2248 | 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" , 2248); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { *((volatile int*)__null) = 2248; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2249 | 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" , 2249); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!hasResult" ") (" "Found unrounded dates!" ")"); do { *((volatile int*)__null ) = 2249; __attribute__((nomerge)) ::abort(); } while (false) ; } } while (false); |
2250 | |
2251 | // Sanity check url_hash |
2252 | rv = mMainConn->CreateStatement( |
2253 | "SELECT 1 FROM moz_places WHERE url_hash = 0"_ns, getter_AddRefs(stmt)); |
2254 | 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" , 2254); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { *((volatile int*)__null) = 2254; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2255 | rv = stmt->ExecuteStep(&hasResult); |
2256 | 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" , 2256); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { *((volatile int*)__null) = 2256; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2257 | 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" , 2257); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!hasResult" ") (" "Found a place without a hash!" ")"); do { *((volatile int*)__null) = 2257; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
2258 | |
2259 | // Sanity check unique urls |
2260 | rv = mMainConn->CreateStatement( |
2261 | nsLiteralCString( |
2262 | "SELECT 1 FROM moz_places GROUP BY url HAVING count(*) > 1 "), |
2263 | getter_AddRefs(stmt)); |
2264 | 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" , 2264); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { *((volatile int*)__null) = 2264; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2265 | rv = stmt->ExecuteStep(&hasResult); |
2266 | 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" , 2266); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { *((volatile int*)__null) = 2266; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2267 | 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" , 2267); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!hasResult" ") (" "Found a duplicate url!" ")"); do { *((volatile int*)__null ) = 2267; __attribute__((nomerge)) ::abort(); } while (false) ; } } while (false); |
2268 | |
2269 | // Sanity check NULL urls |
2270 | rv = mMainConn->CreateStatement( |
2271 | "SELECT 1 FROM moz_places WHERE url ISNULL "_ns, getter_AddRefs(stmt)); |
2272 | 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" , 2272); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { *((volatile int*)__null) = 2272; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2273 | rv = stmt->ExecuteStep(&hasResult); |
2274 | 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" , 2274); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { *((volatile int*)__null) = 2274; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2275 | 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" , 2275); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!hasResult" ") (" "Found a NULL url!" ")"); do { *((volatile int*)__null ) = 2275; __attribute__((nomerge)) ::abort(); } while (false) ; } } while (false); |
2276 | } |
2277 | #endif |
2278 | |
2279 | mMainThreadStatements.FinalizeStatements(); |
2280 | mMainThreadAsyncStatements.FinalizeStatements(); |
2281 | |
2282 | RefPtr<FinalizeStatementCacheProxy<mozIStorageStatement>> event = |
2283 | new FinalizeStatementCacheProxy<mozIStorageStatement>( |
2284 | mAsyncThreadStatements, NS_ISUPPORTS_CAST(nsIObserver*, this)static_cast<nsISupports*>(static_cast<nsIObserver*> (this))); |
2285 | DispatchToAsyncThread(event); |
2286 | |
2287 | mClosed = true; |
2288 | |
2289 | // Execute PRAGMA optimized as last step, this will ensure proper database |
2290 | // performance across restarts. |
2291 | nsCOMPtr<mozIStoragePendingStatement> ps; |
2292 | 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" , 2293); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "NS_SUCCEEDED(mMainConn->ExecuteSimpleSQLAsync( \"PRAGMA optimize(0x02)\"_ns, nullptr, getter_AddRefs(ps)))" ")"); do { *((volatile int*)__null) = 2293; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
2293 | "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" , 2293); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "NS_SUCCEEDED(mMainConn->ExecuteSimpleSQLAsync( \"PRAGMA optimize(0x02)\"_ns, nullptr, getter_AddRefs(ps)))" ")"); do { *((volatile int*)__null) = 2293; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); |
2294 | |
2295 | if (NS_FAILED(mMainConn->AsyncClose(connectionShutdown))((bool)(__builtin_expect(!!(NS_FAILED_impl(mMainConn->AsyncClose (connectionShutdown))), 0)))) { |
2296 | mozilla::Unused << connectionShutdown->Complete(NS_ERROR_UNEXPECTED, |
2297 | nullptr); |
2298 | } |
2299 | mMainConn = nullptr; |
2300 | } |
2301 | |
2302 | //////////////////////////////////////////////////////////////////////////////// |
2303 | //// nsIObserver |
2304 | |
2305 | NS_IMETHODIMPnsresult |
2306 | Database::Observe(nsISupports* aSubject, const char* aTopic, |
2307 | const char16_t* aData) { |
2308 | 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" , 2308); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { *((volatile int*)__null) = 2308; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2309 | if (strcmp(aTopic, TOPIC_PROFILE_CHANGE_TEARDOWN"profile-change-teardown") == 0) { |
2310 | // Tests simulating shutdown may cause multiple notifications. |
2311 | if (PlacesShutdownBlocker::sIsStarted) { |
2312 | return NS_OK; |
2313 | } |
2314 | |
2315 | nsCOMPtr<nsIObserverService> os = services::GetObserverService(); |
2316 | 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" , 2316); return NS_ERROR_UNEXPECTED; } } while (false); |
2317 | |
2318 | // If shutdown happens in the same mainthread loop as init, observers could |
2319 | // handle the places-init-complete notification after xpcom-shutdown, when |
2320 | // the connection does not exist anymore. Removing those observers would |
2321 | // be less expensive but may cause their RemoveObserver calls to throw. |
2322 | // Thus notify the topic now, so they stop listening for it. |
2323 | nsCOMPtr<nsISimpleEnumerator> e; |
2324 | if (NS_SUCCEEDED(os->EnumerateObservers(TOPIC_PLACES_INIT_COMPLETE,((bool)(__builtin_expect(!!(!NS_FAILED_impl(os->EnumerateObservers ("places-init-complete", getter_AddRefs(e)))), 1))) |
2325 | getter_AddRefs(e)))((bool)(__builtin_expect(!!(!NS_FAILED_impl(os->EnumerateObservers ("places-init-complete", getter_AddRefs(e)))), 1))) && |
2326 | e) { |
2327 | bool hasMore = false; |
2328 | while (NS_SUCCEEDED(e->HasMoreElements(&hasMore))((bool)(__builtin_expect(!!(!NS_FAILED_impl(e->HasMoreElements (&hasMore))), 1))) && hasMore) { |
2329 | nsCOMPtr<nsISupports> supports; |
2330 | if (NS_SUCCEEDED(e->GetNext(getter_AddRefs(supports)))((bool)(__builtin_expect(!!(!NS_FAILED_impl(e->GetNext(getter_AddRefs (supports)))), 1)))) { |
2331 | nsCOMPtr<nsIObserver> observer = do_QueryInterface(supports); |
2332 | (void)observer->Observe(observer, TOPIC_PLACES_INIT_COMPLETE"places-init-complete", |
2333 | nullptr); |
2334 | } |
2335 | } |
2336 | } |
2337 | |
2338 | // Notify all Places users that we are about to shutdown. |
2339 | (void)os->NotifyObservers(nullptr, TOPIC_PLACES_SHUTDOWN"places-shutdown", nullptr); |
2340 | } else if (strcmp(aTopic, TOPIC_SIMULATE_PLACES_SHUTDOWN"test-simulate-places-shutdown") == 0) { |
2341 | // This notification is (and must be) only used by tests that are trying |
2342 | // to simulate Places shutdown out of the normal shutdown path. |
2343 | |
2344 | // Tests simulating shutdown may cause re-entrance. |
2345 | if (PlacesShutdownBlocker::sIsStarted) { |
2346 | return NS_OK; |
2347 | } |
2348 | |
2349 | // We are simulating a shutdown, so invoke the shutdown blockers, |
2350 | // wait for them, then proceed with connection shutdown. |
2351 | // Since we are already going through shutdown, but it's not the real one, |
2352 | // we won't need to block the real one anymore, so we can unblock it. |
2353 | { |
2354 | nsCOMPtr<nsIAsyncShutdownClient> shutdownPhase = |
2355 | GetProfileChangeTeardownPhase(); |
2356 | if (shutdownPhase) { |
2357 | shutdownPhase->RemoveBlocker(mClientsShutdown.get()); |
2358 | } |
2359 | (void)mClientsShutdown->BlockShutdown(nullptr); |
2360 | } |
2361 | |
2362 | // Spin the events loop until the clients are done. |
2363 | // Note, this is just for tests, specifically test_clearHistory_shutdown.js |
2364 | SpinEventLoopUntil("places:Database::Observe(SIMULATE_PLACES_SHUTDOWN)"_ns, |
2365 | [&]() { |
2366 | return mClientsShutdown->State() == |
2367 | PlacesShutdownBlocker::States::RECEIVED_DONE; |
2368 | }); |
2369 | |
2370 | { |
2371 | nsCOMPtr<nsIAsyncShutdownClient> shutdownPhase = |
2372 | GetProfileBeforeChangePhase(); |
2373 | if (shutdownPhase) { |
2374 | shutdownPhase->RemoveBlocker(mConnectionShutdown.get()); |
2375 | } |
2376 | (void)mConnectionShutdown->BlockShutdown(nullptr); |
2377 | } |
2378 | } |
2379 | return NS_OK; |
2380 | } |
2381 | |
2382 | } // namespace mozilla::places |