Bug 628949 - Update visible region / glass regions after we paint. r=roc a=2.0.
[mozilla-central.git] / storage / src / mozStoragePrivateHelpers.h
blob8bd9ed376bd07e550e9710f438b9f0b7c39b763b
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is Oracle Corporation code.
18 * The Initial Developer of the Original Code is
19 * Oracle Corporation
20 * Portions created by the Initial Developer are Copyright (C) 2004
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
25 * Shawn Wilsher <me@shawnwilsher.com>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 #ifndef mozStoragePrivateHelpers_h
42 #define mozStoragePrivateHelpers_h
44 /**
45 * This file contains convenience methods for mozStorage.
48 #include "sqlite3.h"
49 #include "nsIVariant.h"
50 #include "mozStorage.h"
51 #include "jsapi.h"
52 #include "nsAutoPtr.h"
54 class mozIStorageCompletionCallback;
55 class mozIStorageBaseStatement;
56 class mozIStorageBindingParams;
57 class nsIRunnable;
59 namespace mozilla {
60 namespace storage {
62 ////////////////////////////////////////////////////////////////////////////////
63 //// Macros
65 #define ENSURE_INDEX_VALUE(aIndex, aCount) \
66 NS_ENSURE_TRUE(aIndex < aCount, NS_ERROR_INVALID_ARG)
68 ////////////////////////////////////////////////////////////////////////////////
69 //// Functions
71 /**
72 * Converts a SQLite return code to an nsresult return code.
74 * @param aSQLiteResultCode
75 * The SQLite return code to convert.
76 * @returns the corresponding nsresult code for aSQLiteResultCode.
78 nsresult convertResultCode(int aSQLiteResultCode);
80 /**
81 * Checks the performance of a SQLite statement and logs a warning with
82 * NS_WARNING. Currently this only checks the number of sort operations done
83 * on a statement, and if more than zero have been done, the statement can be
84 * made faster with the careful use of an index.
86 * @param aStatement
87 * The sqlite3_stmt object to check.
89 void checkAndLogStatementPerformance(sqlite3_stmt *aStatement);
91 /**
92 * Convert the provided jsval into a variant representation if possible.
94 * @param aCtx
95 * The JSContext the value is from.
96 * @param aValue
97 * The JavaScript value to convert. All primitive types are supported,
98 * but only Date objects are supported from the Date family. Date
99 * objects are coerced to PRTime (nanoseconds since epoch) values.
100 * @return the variant if conversion was successful, nsnull if conversion
101 * failed. The caller is responsible for addref'ing if non-null.
103 nsIVariant *convertJSValToVariant(JSContext *aCtx, jsval aValue);
106 * Obtains an event that will notify a completion callback about completion.
108 * @param aCallback
109 * The callback to be notified.
110 * @return an nsIRunnable that can be dispatched to the calling thread.
112 already_AddRefed<nsIRunnable> newCompletionEvent(
113 mozIStorageCompletionCallback *aCallback
118 * Performs a sqlite3_step on aStatement, while properly handling SQLITE_LOCKED
119 * when not on the main thread by waiting until we are notified.
121 * @param aStatement
122 * A pointer to a sqlite3_stmt object.
123 * @return the result from sqlite3_step.
125 int stepStmt(sqlite3_stmt *aStatement);
128 * Obtains a prepared sqlite3_stmt object for aDatabase from aSQL.
130 * @param aDatabase
131 * The database the statement will execute on.
132 * @param aSQL
133 * The SQL statement to compile.
134 * @return the result from sqlite3_prepare_v2.
136 int prepareStmt(sqlite3 *aDatabase, const nsCString &aSQL,
137 sqlite3_stmt **_stmt);
139 } // namespace storage
140 } // namespace mozilla
142 #endif // mozStoragePrivateHelpers_h