1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=2 et sw=2 tw=80: */
3 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
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/
10 : *
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.
15 : *
16 : * The Original Code is Indexed Database.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * The Mozilla Foundation.
20 : * Portions created by the Initial Developer are Copyright (C) 2010
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Ben Turner <bent.mozilla@gmail.com>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #ifndef mozilla_dom_indexeddb_idbdatabase_h__
41 : #define mozilla_dom_indexeddb_idbdatabase_h__
42 :
43 : #include "mozilla/dom/indexedDB/IndexedDatabase.h"
44 :
45 : #include "nsIDocument.h"
46 : #include "nsIIDBDatabase.h"
47 : #include "nsDOMEventTargetHelper.h"
48 : #include "mozilla/dom/indexedDB/IDBWrapperCache.h"
49 : #include "mozilla/dom/indexedDB/FileManager.h"
50 :
51 : class nsIScriptContext;
52 : class nsPIDOMWindow;
53 :
54 : BEGIN_INDEXEDDB_NAMESPACE
55 :
56 : class AsyncConnectionHelper;
57 : struct DatabaseInfo;
58 : class IDBIndex;
59 : class IDBObjectStore;
60 : class IDBTransaction;
61 : class IndexedDatabaseManager;
62 :
63 : class IDBDatabase : public IDBWrapperCache,
64 : public nsIIDBDatabase
65 : {
66 : friend class AsyncConnectionHelper;
67 : friend class IndexedDatabaseManager;
68 :
69 : public:
70 : NS_DECL_ISUPPORTS_INHERITED
71 : NS_DECL_NSIIDBDATABASE
72 :
73 1587 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBDatabase, IDBWrapperCache)
74 :
75 : static already_AddRefed<IDBDatabase>
76 : Create(IDBWrapperCache* aOwnerCache,
77 : already_AddRefed<DatabaseInfo> aDatabaseInfo,
78 : const nsACString& aASCIIOrigin,
79 : FileManager* aFileManager);
80 :
81 : // nsIDOMEventTarget
82 : virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
83 :
84 : nsIAtom* Id() const
85 : {
86 : return mDatabaseId;
87 : }
88 :
89 1323 : DatabaseInfo* Info() const
90 : {
91 1323 : return mDatabaseInfo;
92 : }
93 :
94 : const nsString& Name()
95 : {
96 : return mName;
97 : }
98 :
99 : const nsString& FilePath()
100 : {
101 : return mFilePath;
102 : }
103 :
104 : already_AddRefed<nsIDocument> GetOwnerDocument()
105 : {
106 : if (!GetOwner()) {
107 : return nsnull;
108 : }
109 :
110 : nsCOMPtr<nsIDocument> doc =
111 : do_QueryInterface(GetOwner()->GetExtantDocument());
112 : return doc.forget();
113 : }
114 :
115 : nsCString& Origin()
116 : {
117 : return mASCIIOrigin;
118 : }
119 :
120 : void Invalidate();
121 :
122 : // Whether or not the database has been invalidated. If it has then no further
123 : // transactions for this database will be allowed to run.
124 : bool IsInvalidated();
125 :
126 : void CloseInternal(bool aIsDead);
127 :
128 : // Whether or not the database has had Close called on it.
129 : bool IsClosed();
130 :
131 : void EnterSetVersionTransaction();
132 : void ExitSetVersionTransaction();
133 :
134 : FileManager* Manager() const
135 : {
136 : return mFileManager;
137 : }
138 :
139 : private:
140 : IDBDatabase();
141 : ~IDBDatabase();
142 :
143 : void OnUnlink();
144 :
145 : nsRefPtr<DatabaseInfo> mDatabaseInfo;
146 : nsCOMPtr<nsIAtom> mDatabaseId;
147 : nsString mName;
148 : nsString mFilePath;
149 : nsCString mASCIIOrigin;
150 :
151 : PRInt32 mInvalidated;
152 : bool mRegistered;
153 : bool mClosed;
154 : bool mRunningVersionChange;
155 :
156 : nsRefPtr<FileManager> mFileManager;
157 :
158 : // Only touched on the main thread.
159 : NS_DECL_EVENT_HANDLER(abort)
160 : NS_DECL_EVENT_HANDLER(error)
161 : NS_DECL_EVENT_HANDLER(versionchange)
162 : };
163 :
164 : END_INDEXEDDB_NAMESPACE
165 :
166 : #endif // mozilla_dom_indexeddb_idbdatabase_h__
|