1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/in_process_webkit/indexed_db_callbacks.h"
9 #include "content/common/indexed_db/indexed_db_messages.h"
10 #include "webkit/quota/quota_manager.h"
15 const int32 kDatabaseNotAdded
= -1;
18 IndexedDBCallbacksBase::IndexedDBCallbacksBase(
19 IndexedDBDispatcherHost
* dispatcher_host
,
21 int32 ipc_response_id
)
22 : dispatcher_host_(dispatcher_host
),
23 ipc_response_id_(ipc_response_id
),
24 ipc_thread_id_(ipc_thread_id
) {
27 IndexedDBCallbacksBase::~IndexedDBCallbacksBase() {}
29 void IndexedDBCallbacksBase::onError(const WebKit::WebIDBDatabaseError
& error
) {
30 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksError(
31 ipc_thread_id_
, ipc_response_id_
, error
.code(), error
.message()));
34 void IndexedDBCallbacksBase::onBlocked(long long old_version
) {
35 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksIntBlocked(
36 ipc_thread_id_
, ipc_response_id_
, old_version
));
39 void IndexedDBCallbacksBase::onBlocked() {
40 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksBlocked(ipc_thread_id_
,
44 IndexedDBCallbacksDatabase::IndexedDBCallbacksDatabase(
45 IndexedDBDispatcherHost
* dispatcher_host
,
47 int32 ipc_response_id
,
48 const GURL
& origin_url
)
49 : IndexedDBCallbacksBase(dispatcher_host
, ipc_thread_id
, ipc_response_id
),
50 origin_url_(origin_url
),
51 ipc_database_id_(kDatabaseNotAdded
) {
54 void IndexedDBCallbacksDatabase::onSuccess(
55 WebKit::WebIDBDatabase
* idb_object
) {
56 int32 ipc_object_id
= ipc_database_id_
;
57 if (ipc_object_id
== kDatabaseNotAdded
) {
58 ipc_object_id
= dispatcher_host()->Add(idb_object
, ipc_thread_id(),
61 // We already have this database and don't need a new copy of it.
64 dispatcher_host()->Send(
65 new IndexedDBMsg_CallbacksSuccessIDBDatabase(ipc_thread_id(),
70 void IndexedDBCallbacksDatabase::onUpgradeNeeded(
71 long long old_version
,
72 WebKit::WebIDBTransaction
* transaction
,
73 WebKit::WebIDBDatabase
* database
) {
74 int32 ipc_transaction_id
= dispatcher_host()->Add(transaction
,
77 int32 ipc_database_id
= dispatcher_host()->Add(database
, ipc_thread_id(),
79 ipc_database_id_
= ipc_database_id
;
80 dispatcher_host()->Send(
81 new IndexedDBMsg_CallbacksUpgradeNeeded(
82 ipc_thread_id(), ipc_response_id(), ipc_transaction_id
,
87 void IndexedDBCallbacks
<WebKit::WebIDBCursor
>::onSuccess(
88 WebKit::WebIDBCursor
* idb_object
,
89 const WebKit::WebIDBKey
& key
,
90 const WebKit::WebIDBKey
& primaryKey
,
91 const WebKit::WebSerializedScriptValue
& value
) {
92 int32 ipc_object_id
= dispatcher_host()->Add(idb_object
);
93 IndexedDBMsg_CallbacksSuccessIDBCursor_Params params
;
94 params
.ipc_thread_id
= ipc_thread_id();
95 params
.ipc_response_id
= ipc_response_id();
96 params
.ipc_cursor_id
= ipc_object_id
;
97 params
.key
= IndexedDBKey(key
);
98 params
.primary_key
= IndexedDBKey(primaryKey
);
99 params
.serialized_value
= SerializedScriptValue(value
);
100 dispatcher_host()->Send(new IndexedDBMsg_CallbacksSuccessIDBCursor(params
));
103 void IndexedDBCallbacks
<WebKit::WebIDBCursor
>::onSuccess(
104 const WebKit::WebSerializedScriptValue
& value
) {
105 dispatcher_host()->Send(
106 new IndexedDBMsg_CallbacksSuccessSerializedScriptValue(
107 ipc_thread_id(), ipc_response_id(), SerializedScriptValue(value
)));
110 void IndexedDBCallbacks
<WebKit::WebIDBCursor
>::onSuccess(
111 const WebKit::WebIDBKey
& key
,
112 const WebKit::WebIDBKey
& primaryKey
,
113 const WebKit::WebSerializedScriptValue
& value
) {
114 DCHECK_NE(ipc_cursor_id_
, -1);
115 WebKit::WebIDBCursor
* idb_cursor
= dispatcher_host()->GetCursorFromId(
121 IndexedDBMsg_CallbacksSuccessCursorContinue_Params params
;
122 params
.ipc_thread_id
= ipc_thread_id();
123 params
.ipc_response_id
= ipc_response_id();
124 params
.ipc_cursor_id
= ipc_cursor_id_
;
125 params
.key
= IndexedDBKey(key
);
126 params
.primary_key
= IndexedDBKey(primaryKey
);
127 params
.serialized_value
= SerializedScriptValue(value
);
128 dispatcher_host()->Send(
129 new IndexedDBMsg_CallbacksSuccessCursorContinue(params
));
132 void IndexedDBCallbacks
<WebKit::WebIDBCursor
>::onSuccessWithPrefetch(
133 const WebKit::WebVector
<WebKit::WebIDBKey
>& keys
,
134 const WebKit::WebVector
<WebKit::WebIDBKey
>& primaryKeys
,
135 const WebKit::WebVector
<WebKit::WebSerializedScriptValue
>& values
) {
136 DCHECK_NE(ipc_cursor_id_
, -1);
138 std::vector
<IndexedDBKey
> msgKeys
;
139 std::vector
<IndexedDBKey
> msgPrimaryKeys
;
140 std::vector
<SerializedScriptValue
> msgValues
;
142 for (size_t i
= 0; i
< keys
.size(); ++i
) {
143 msgKeys
.push_back(IndexedDBKey(keys
[i
]));
144 msgPrimaryKeys
.push_back(IndexedDBKey(primaryKeys
[i
]));
145 msgValues
.push_back(SerializedScriptValue(values
[i
]));
148 IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params params
;
149 params
.ipc_thread_id
= ipc_thread_id();
150 params
.ipc_response_id
= ipc_response_id();
151 params
.ipc_cursor_id
= ipc_cursor_id_
;
152 params
.keys
= msgKeys
;
153 params
.primary_keys
= msgPrimaryKeys
;
154 params
.values
= msgValues
;
155 dispatcher_host()->Send(
156 new IndexedDBMsg_CallbacksSuccessCursorPrefetch(params
));
159 void IndexedDBCallbacks
<WebKit::WebIDBKey
>::onSuccess(
160 const WebKit::WebIDBKey
& value
) {
161 dispatcher_host()->Send(
162 new IndexedDBMsg_CallbacksSuccessIndexedDBKey(
163 ipc_thread_id(), ipc_response_id(), IndexedDBKey(value
)));
166 void IndexedDBCallbacks
<WebKit::WebDOMStringList
>::onSuccess(
167 const WebKit::WebDOMStringList
& value
) {
169 std::vector
<string16
> list
;
170 for (unsigned i
= 0; i
< value
.length(); ++i
)
171 list
.push_back(value
.item(i
));
173 dispatcher_host()->Send(
174 new IndexedDBMsg_CallbacksSuccessStringList(
175 ipc_thread_id(), ipc_response_id(), list
));
178 void IndexedDBCallbacks
<WebKit::WebSerializedScriptValue
>::onSuccess(
179 const WebKit::WebSerializedScriptValue
& value
) {
180 dispatcher_host()->Send(
181 new IndexedDBMsg_CallbacksSuccessSerializedScriptValue(
182 ipc_thread_id(), ipc_response_id(), SerializedScriptValue(value
)));
185 void IndexedDBCallbacks
<WebKit::WebSerializedScriptValue
>::onSuccess(
186 const WebKit::WebSerializedScriptValue
& value
,
187 const WebKit::WebIDBKey
& primaryKey
,
188 const WebKit::WebIDBKeyPath
& keyPath
) {
189 dispatcher_host()->Send(
190 new IndexedDBMsg_CallbacksSuccessSerializedScriptValueWithKey(
191 ipc_thread_id(), ipc_response_id(), SerializedScriptValue(value
),
192 IndexedDBKey(primaryKey
), IndexedDBKeyPath(keyPath
)));
195 void IndexedDBCallbacks
<WebKit::WebSerializedScriptValue
>::onSuccess(
197 dispatcher_host()->Send(
198 new IndexedDBMsg_CallbacksSuccessInteger(ipc_thread_id(),
203 void IndexedDBCallbacks
<WebKit::WebSerializedScriptValue
>::onSuccess() {
204 dispatcher_host()->Send(
205 new IndexedDBMsg_CallbacksSuccessUndefined(ipc_thread_id(),
209 } // namespace content