Bug 1454293 [wpt PR 10484] - null is not the correct origin for createDocument()...
[gecko.git] / storage / mozStorageBindingParams.h
blobd38bbf3160327c8c081c8cbf2d4f178c2421d87e
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 mozStorageBindingParams_h
8 #define mozStorageBindingParams_h
10 #include "nsCOMArray.h"
11 #include "nsIVariant.h"
12 #include "nsInterfaceHashtable.h"
14 #include "mozStorageBindingParamsArray.h"
15 #include "mozStorageStatement.h"
16 #include "mozStorageAsyncStatement.h"
17 #include "Variant.h"
19 #include "mozIStorageBindingParams.h"
20 #include "IStorageBindingParamsInternal.h"
22 namespace mozilla {
23 namespace storage {
25 class BindingParams : public mozIStorageBindingParams
26 , public IStorageBindingParamsInternal
28 public:
29 NS_DECL_THREADSAFE_ISUPPORTS
30 NS_DECL_MOZISTORAGEBINDINGPARAMS
31 NS_DECL_ISTORAGEBINDINGPARAMSINTERNAL
33 /**
34 * Locks the parameters and prevents further modification to it (such as
35 * binding more elements to it).
37 void lock();
39 /**
40 * Unlocks the parameters and allows modification to it again.
42 * @param aOwningStatement
43 * The statement that owns us. We cleared this when we were locked,
44 * and our invariant requires us to have this, so you need to tell us
45 * again.
47 void unlock(Statement *aOwningStatement);
49 /**
50 * @returns the pointer to the owning BindingParamsArray. Used by a
51 * BindingParamsArray to verify that we belong to it when added.
53 const mozIStorageBindingParamsArray *getOwner() const;
55 BindingParams(mozIStorageBindingParamsArray *aOwningArray,
56 Statement *aOwningStatement);
57 protected:
58 virtual ~BindingParams() {}
60 explicit BindingParams(mozIStorageBindingParamsArray *aOwningArray);
61 // Note that this is managed as a sparse array, so particular caution should
62 // be used for out-of-bounds usage.
63 nsTArray<RefPtr<Variant_base> > mParameters;
64 bool mLocked;
66 private:
68 /**
69 * Track the BindingParamsArray that created us until we are added to it.
70 * (Once we are added we are locked and no one needs to look up our owner.)
71 * Ref-counted since there is no invariant that guarantees it stays alive
72 * otherwise. This keeps mOwningStatement alive for us too since the array
73 * also holds a reference.
75 nsCOMPtr<mozIStorageBindingParamsArray> mOwningArray;
76 /**
77 * Used in the synchronous binding case to map parameter names to indices.
78 * Not reference-counted because this is only non-null as long as mOwningArray
79 * is non-null and mOwningArray also holds a statement reference.
81 Statement *mOwningStatement;
82 uint32_t mParamCount;
85 /**
86 * Adds late resolution of named parameters so they don't get resolved until we
87 * try and bind the parameters on the async thread. We also stop checking
88 * parameter indices for being too big since we just just don't know how many
89 * there are.
91 * We support *either* binding by name or binding by index. Trying to do both
92 * results in only binding by name at sqlite3_stmt bind time.
94 class AsyncBindingParams : public BindingParams
96 public:
97 NS_IMETHOD BindByName(const nsACString & aName,
98 nsIVariant *aValue) override;
99 NS_IMETHOD BindByIndex(uint32_t aIndex, nsIVariant *aValue) override;
101 virtual already_AddRefed<mozIStorageError> bind(sqlite3_stmt * aStatement) override;
103 explicit AsyncBindingParams(mozIStorageBindingParamsArray *aOwningArray);
104 virtual ~AsyncBindingParams() {}
106 private:
107 nsInterfaceHashtable<nsCStringHashKey, nsIVariant> mNamedParameters;
110 } // namespace storage
111 } // namespace mozilla
113 #endif // mozStorageBindingParams_h