storage/src/mozStoragePrivateHelpers.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial