storage/src/mozStoragePrivateHelpers.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial