/src/mozilla-central/storage/mozStorageBindingParamsArray.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "mozStorageBindingParamsArray.h" |
8 | | #include "mozStorageBindingParams.h" |
9 | | #include "StorageBaseStatementInternal.h" |
10 | | |
11 | | namespace mozilla { |
12 | | namespace storage { |
13 | | |
14 | | //////////////////////////////////////////////////////////////////////////////// |
15 | | //// BindingParamsArray |
16 | | |
17 | | BindingParamsArray::BindingParamsArray( |
18 | | StorageBaseStatementInternal *aOwningStatement |
19 | | ) |
20 | | : mOwningStatement(aOwningStatement) |
21 | | , mLocked(false) |
22 | 0 | { |
23 | 0 | } |
24 | | |
25 | | void |
26 | | BindingParamsArray::lock() |
27 | 0 | { |
28 | 0 | NS_ASSERTION(mLocked == false, "Array has already been locked!"); |
29 | 0 | mLocked = true; |
30 | 0 |
|
31 | 0 | // We also no longer need to hold a reference to our statement since it owns |
32 | 0 | // us. |
33 | 0 | mOwningStatement = nullptr; |
34 | 0 | } |
35 | | |
36 | | const StorageBaseStatementInternal * |
37 | | BindingParamsArray::getOwner() const |
38 | 0 | { |
39 | 0 | return mOwningStatement; |
40 | 0 | } |
41 | | |
42 | | NS_IMPL_ISUPPORTS( |
43 | | BindingParamsArray, |
44 | | mozIStorageBindingParamsArray |
45 | | ) |
46 | | |
47 | | /////////////////////////////////////////////////////////////////////////////// |
48 | | //// mozIStorageBindingParamsArray |
49 | | |
50 | | NS_IMETHODIMP |
51 | | BindingParamsArray::NewBindingParams(mozIStorageBindingParams **_params) |
52 | 0 | { |
53 | 0 | NS_ENSURE_FALSE(mLocked, NS_ERROR_UNEXPECTED); |
54 | 0 |
|
55 | 0 | nsCOMPtr<mozIStorageBindingParams> params( |
56 | 0 | mOwningStatement->newBindingParams(this)); |
57 | 0 | NS_ENSURE_TRUE(params, NS_ERROR_UNEXPECTED); |
58 | 0 |
|
59 | 0 | params.forget(_params); |
60 | 0 | return NS_OK; |
61 | 0 | } |
62 | | |
63 | | NS_IMETHODIMP |
64 | | BindingParamsArray::AddParams(mozIStorageBindingParams *aParameters) |
65 | 0 | { |
66 | 0 | NS_ENSURE_FALSE(mLocked, NS_ERROR_UNEXPECTED); |
67 | 0 |
|
68 | 0 | BindingParams *params = static_cast<BindingParams *>(aParameters); |
69 | 0 |
|
70 | 0 | // Check to make sure that this set of parameters was created with us. |
71 | 0 | if (params->getOwner() != this) |
72 | 0 | return NS_ERROR_UNEXPECTED; |
73 | 0 | |
74 | 0 | NS_ENSURE_TRUE(mArray.AppendElement(params), NS_ERROR_OUT_OF_MEMORY); |
75 | 0 |
|
76 | 0 | // Lock the parameters only after we've successfully added them. |
77 | 0 | params->lock(); |
78 | 0 |
|
79 | 0 | return NS_OK; |
80 | 0 | } |
81 | | |
82 | | NS_IMETHODIMP |
83 | | BindingParamsArray::GetLength(uint32_t *_length) |
84 | 0 | { |
85 | 0 | *_length = length(); |
86 | 0 | return NS_OK; |
87 | 0 | } |
88 | | |
89 | | } // namespace storage |
90 | | } // namespace mozilla |