Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef mozStoragePrivateHelpers_h |
michael@0 | 8 | #define mozStoragePrivateHelpers_h |
michael@0 | 9 | |
michael@0 | 10 | /** |
michael@0 | 11 | * This file contains convenience methods for mozStorage. |
michael@0 | 12 | */ |
michael@0 | 13 | |
michael@0 | 14 | #include "sqlite3.h" |
michael@0 | 15 | #include "nsIVariant.h" |
michael@0 | 16 | #include "nsError.h" |
michael@0 | 17 | #include "nsAutoPtr.h" |
michael@0 | 18 | #include "js/TypeDecls.h" |
michael@0 | 19 | |
michael@0 | 20 | class mozIStorageCompletionCallback; |
michael@0 | 21 | class mozIStorageBaseStatement; |
michael@0 | 22 | class mozIStorageBindingParams; |
michael@0 | 23 | class nsIRunnable; |
michael@0 | 24 | |
michael@0 | 25 | namespace mozilla { |
michael@0 | 26 | namespace storage { |
michael@0 | 27 | |
michael@0 | 28 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 29 | //// Macros |
michael@0 | 30 | |
michael@0 | 31 | #define ENSURE_INDEX_VALUE(aIndex, aCount) \ |
michael@0 | 32 | NS_ENSURE_TRUE(aIndex < aCount, NS_ERROR_INVALID_ARG) |
michael@0 | 33 | |
michael@0 | 34 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 35 | //// Functions |
michael@0 | 36 | |
michael@0 | 37 | /** |
michael@0 | 38 | * Converts a SQLite return code to an nsresult return code. |
michael@0 | 39 | * |
michael@0 | 40 | * @param aSQLiteResultCode |
michael@0 | 41 | * The SQLite return code to convert. |
michael@0 | 42 | * @returns the corresponding nsresult code for aSQLiteResultCode. |
michael@0 | 43 | */ |
michael@0 | 44 | nsresult convertResultCode(int aSQLiteResultCode); |
michael@0 | 45 | |
michael@0 | 46 | /** |
michael@0 | 47 | * Checks the performance of a SQLite statement and logs a warning with |
michael@0 | 48 | * NS_WARNING. Currently this only checks the number of sort operations done |
michael@0 | 49 | * on a statement, and if more than zero have been done, the statement can be |
michael@0 | 50 | * made faster with the careful use of an index. |
michael@0 | 51 | * |
michael@0 | 52 | * @param aStatement |
michael@0 | 53 | * The sqlite3_stmt object to check. |
michael@0 | 54 | */ |
michael@0 | 55 | void checkAndLogStatementPerformance(sqlite3_stmt *aStatement); |
michael@0 | 56 | |
michael@0 | 57 | /** |
michael@0 | 58 | * Convert the provided JS::Value into a variant representation if possible. |
michael@0 | 59 | * |
michael@0 | 60 | * @param aCtx |
michael@0 | 61 | * The JSContext the value is from. |
michael@0 | 62 | * @param aValue |
michael@0 | 63 | * The JavaScript value to convert. All primitive types are supported, |
michael@0 | 64 | * but only Date objects are supported from the Date family. Date |
michael@0 | 65 | * objects are coerced to PRTime (nanoseconds since epoch) values. |
michael@0 | 66 | * @return the variant if conversion was successful, nullptr if conversion |
michael@0 | 67 | * failed. The caller is responsible for addref'ing if non-null. |
michael@0 | 68 | */ |
michael@0 | 69 | nsIVariant *convertJSValToVariant(JSContext *aCtx, JS::Value aValue); |
michael@0 | 70 | |
michael@0 | 71 | /** |
michael@0 | 72 | * Obtains an event that will notify a completion callback about completion. |
michael@0 | 73 | * |
michael@0 | 74 | * @param aCallback |
michael@0 | 75 | * The callback to be notified. |
michael@0 | 76 | * @return an nsIRunnable that can be dispatched to the calling thread. |
michael@0 | 77 | */ |
michael@0 | 78 | already_AddRefed<nsIRunnable> newCompletionEvent( |
michael@0 | 79 | mozIStorageCompletionCallback *aCallback |
michael@0 | 80 | ); |
michael@0 | 81 | |
michael@0 | 82 | } // namespace storage |
michael@0 | 83 | } // namespace mozilla |
michael@0 | 84 | |
michael@0 | 85 | #endif // mozStoragePrivateHelpers_h |