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/indexed_db/indexed_db_callbacks.h"
10 #include "base/metrics/histogram.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "base/time/time.h"
13 #include "content/browser/child_process_security_policy_impl.h"
14 #include "content/browser/fileapi/fileapi_message_filter.h"
15 #include "content/browser/indexed_db/indexed_db_blob_info.h"
16 #include "content/browser/indexed_db/indexed_db_connection.h"
17 #include "content/browser/indexed_db/indexed_db_context_impl.h"
18 #include "content/browser/indexed_db/indexed_db_cursor.h"
19 #include "content/browser/indexed_db/indexed_db_database_callbacks.h"
20 #include "content/browser/indexed_db/indexed_db_database_error.h"
21 #include "content/browser/indexed_db/indexed_db_metadata.h"
22 #include "content/browser/indexed_db/indexed_db_value.h"
23 #include "content/common/indexed_db/indexed_db_constants.h"
24 #include "content/common/indexed_db/indexed_db_messages.h"
25 #include "webkit/browser/blob/blob_storage_context.h"
26 #include "webkit/browser/quota/quota_manager.h"
27 #include "webkit/common/blob/blob_data.h"
28 #include "webkit/common/blob/shareable_file_reference.h"
30 using storage::ShareableFileReference
;
35 const int32 kNoCursor
= -1;
36 const int32 kNoDatabaseCallbacks
= -1;
37 const int64 kNoTransaction
= -1;
40 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost
* dispatcher_host
,
42 int32 ipc_callbacks_id
)
43 : dispatcher_host_(dispatcher_host
),
44 ipc_callbacks_id_(ipc_callbacks_id
),
45 ipc_thread_id_(ipc_thread_id
),
46 ipc_cursor_id_(kNoCursor
),
47 host_transaction_id_(kNoTransaction
),
48 ipc_database_id_(kNoDatabase
),
49 ipc_database_callbacks_id_(kNoDatabaseCallbacks
),
50 data_loss_(blink::WebIDBDataLossNone
),
51 sent_blocked_(false) {
54 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost
* dispatcher_host
,
56 int32 ipc_callbacks_id
,
58 : dispatcher_host_(dispatcher_host
),
59 ipc_callbacks_id_(ipc_callbacks_id
),
60 ipc_thread_id_(ipc_thread_id
),
61 ipc_cursor_id_(ipc_cursor_id
),
62 host_transaction_id_(kNoTransaction
),
63 ipc_database_id_(kNoDatabase
),
64 ipc_database_callbacks_id_(kNoDatabaseCallbacks
),
65 data_loss_(blink::WebIDBDataLossNone
),
66 sent_blocked_(false) {
69 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost
* dispatcher_host
,
71 int32 ipc_callbacks_id
,
72 int32 ipc_database_callbacks_id
,
73 int64 host_transaction_id
,
74 const GURL
& origin_url
)
75 : dispatcher_host_(dispatcher_host
),
76 ipc_callbacks_id_(ipc_callbacks_id
),
77 ipc_thread_id_(ipc_thread_id
),
78 ipc_cursor_id_(kNoCursor
),
79 host_transaction_id_(host_transaction_id
),
80 origin_url_(origin_url
),
81 ipc_database_id_(kNoDatabase
),
82 ipc_database_callbacks_id_(ipc_database_callbacks_id
),
83 data_loss_(blink::WebIDBDataLossNone
),
84 sent_blocked_(false) {
87 IndexedDBCallbacks::~IndexedDBCallbacks() {}
89 void IndexedDBCallbacks::OnError(const IndexedDBDatabaseError
& error
) {
90 DCHECK(dispatcher_host_
.get());
92 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksError(
93 ipc_thread_id_
, ipc_callbacks_id_
, error
.code(), error
.message()));
94 dispatcher_host_
= NULL
;
96 if (!connection_open_start_time_
.is_null()) {
97 UMA_HISTOGRAM_MEDIUM_TIMES(
98 "WebCore.IndexedDB.OpenTime.Error",
99 base::TimeTicks::Now() - connection_open_start_time_
);
100 connection_open_start_time_
= base::TimeTicks();
104 void IndexedDBCallbacks::OnSuccess(const std::vector
<base::string16
>& value
) {
105 DCHECK(dispatcher_host_
.get());
107 DCHECK_EQ(kNoCursor
, ipc_cursor_id_
);
108 DCHECK_EQ(kNoTransaction
, host_transaction_id_
);
109 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
110 DCHECK_EQ(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
111 DCHECK_EQ(blink::WebIDBDataLossNone
, data_loss_
);
113 std::vector
<base::string16
> list
;
114 for (unsigned i
= 0; i
< value
.size(); ++i
)
115 list
.push_back(value
[i
]);
117 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksSuccessStringList(
118 ipc_thread_id_
, ipc_callbacks_id_
, list
));
119 dispatcher_host_
= NULL
;
122 void IndexedDBCallbacks::OnBlocked(int64 existing_version
) {
123 DCHECK(dispatcher_host_
.get());
125 DCHECK_EQ(kNoCursor
, ipc_cursor_id_
);
126 // No transaction/db callbacks for DeleteDatabase.
127 DCHECK_EQ(kNoTransaction
== host_transaction_id_
,
128 kNoDatabaseCallbacks
== ipc_database_callbacks_id_
);
129 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
134 sent_blocked_
= true;
135 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksIntBlocked(
136 ipc_thread_id_
, ipc_callbacks_id_
, existing_version
));
138 if (!connection_open_start_time_
.is_null()) {
139 UMA_HISTOGRAM_MEDIUM_TIMES(
140 "WebCore.IndexedDB.OpenTime.Blocked",
141 base::TimeTicks::Now() - connection_open_start_time_
);
142 connection_open_start_time_
= base::TimeTicks();
146 void IndexedDBCallbacks::OnDataLoss(blink::WebIDBDataLoss data_loss
,
147 std::string data_loss_message
) {
148 DCHECK_NE(blink::WebIDBDataLossNone
, data_loss
);
149 data_loss_
= data_loss
;
150 data_loss_message_
= data_loss_message
;
153 void IndexedDBCallbacks::OnUpgradeNeeded(
155 scoped_ptr
<IndexedDBConnection
> connection
,
156 const IndexedDBDatabaseMetadata
& metadata
) {
157 DCHECK(dispatcher_host_
.get());
159 DCHECK_EQ(kNoCursor
, ipc_cursor_id_
);
160 DCHECK_NE(kNoTransaction
, host_transaction_id_
);
161 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
162 DCHECK_NE(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
164 dispatcher_host_
->RegisterTransactionId(host_transaction_id_
, origin_url_
);
165 int32 ipc_database_id
=
166 dispatcher_host_
->Add(connection
.release(), ipc_thread_id_
, origin_url_
);
167 if (ipc_database_id
< 0)
169 ipc_database_id_
= ipc_database_id
;
170 IndexedDBMsg_CallbacksUpgradeNeeded_Params params
;
171 params
.ipc_thread_id
= ipc_thread_id_
;
172 params
.ipc_callbacks_id
= ipc_callbacks_id_
;
173 params
.ipc_database_id
= ipc_database_id
;
174 params
.ipc_database_callbacks_id
= ipc_database_callbacks_id_
;
175 params
.old_version
= old_version
;
176 params
.idb_metadata
= IndexedDBDispatcherHost::ConvertMetadata(metadata
);
177 params
.data_loss
= data_loss_
;
178 params
.data_loss_message
= data_loss_message_
;
179 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksUpgradeNeeded(params
));
181 if (!connection_open_start_time_
.is_null()) {
182 UMA_HISTOGRAM_MEDIUM_TIMES(
183 "WebCore.IndexedDB.OpenTime.UpgradeNeeded",
184 base::TimeTicks::Now() - connection_open_start_time_
);
185 connection_open_start_time_
= base::TimeTicks();
189 void IndexedDBCallbacks::OnSuccess(scoped_ptr
<IndexedDBConnection
> connection
,
190 const IndexedDBDatabaseMetadata
& metadata
) {
191 DCHECK(dispatcher_host_
.get());
193 DCHECK_EQ(kNoCursor
, ipc_cursor_id_
);
194 DCHECK_NE(kNoTransaction
, host_transaction_id_
);
195 DCHECK_NE(ipc_database_id_
== kNoDatabase
, !connection
);
196 DCHECK_NE(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
198 scoped_refptr
<IndexedDBCallbacks
> self(this);
200 int32 ipc_object_id
= kNoDatabase
;
201 // Only register if the connection was not previously sent in OnUpgradeNeeded.
202 if (ipc_database_id_
== kNoDatabase
) {
203 ipc_object_id
= dispatcher_host_
->Add(
204 connection
.release(), ipc_thread_id_
, origin_url_
);
207 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksSuccessIDBDatabase(
210 ipc_database_callbacks_id_
,
212 IndexedDBDispatcherHost::ConvertMetadata(metadata
)));
213 dispatcher_host_
= NULL
;
215 if (!connection_open_start_time_
.is_null()) {
216 UMA_HISTOGRAM_MEDIUM_TIMES(
217 "WebCore.IndexedDB.OpenTime.Success",
218 base::TimeTicks::Now() - connection_open_start_time_
);
219 connection_open_start_time_
= base::TimeTicks();
223 static std::string
CreateBlobData(
224 const IndexedDBBlobInfo
& blob_info
,
225 scoped_refptr
<IndexedDBDispatcherHost
> dispatcher_host
,
226 storage::BlobStorageContext
* blob_storage_context
,
227 base::TaskRunner
* task_runner
) {
228 std::string uuid
= blob_info
.uuid();
230 // We're sending back a live blob, not a reference into our backing store.
231 scoped_ptr
<storage::BlobDataHandle
> blob_data_handle(
232 blob_storage_context
->GetBlobDataFromUUID(uuid
));
233 dispatcher_host
->HoldBlobDataHandle(uuid
, blob_data_handle
.Pass());
236 scoped_refptr
<ShareableFileReference
> shareable_file
=
237 ShareableFileReference::Get(blob_info
.file_path());
238 if (!shareable_file
.get()) {
239 shareable_file
= ShareableFileReference::GetOrCreate(
240 blob_info
.file_path(),
241 ShareableFileReference::DONT_DELETE_ON_FINAL_RELEASE
,
243 if (!blob_info
.release_callback().is_null())
244 shareable_file
->AddFinalReleaseCallback(blob_info
.release_callback());
247 uuid
= base::GenerateGUID();
248 scoped_refptr
<storage::BlobData
> blob_data
= new storage::BlobData(uuid
);
249 blob_data
->AppendFile(
250 blob_info
.file_path(), 0, blob_info
.size(), blob_info
.last_modified());
251 scoped_ptr
<storage::BlobDataHandle
> blob_data_handle(
252 blob_storage_context
->AddFinishedBlob(blob_data
.get()));
253 dispatcher_host
->HoldBlobDataHandle(uuid
, blob_data_handle
.Pass());
258 static bool CreateAllBlobs(
259 const std::vector
<IndexedDBBlobInfo
>& blob_info
,
260 std::vector
<IndexedDBMsg_BlobOrFileInfo
>* blob_or_file_info
,
261 scoped_refptr
<IndexedDBDispatcherHost
> dispatcher_host
) {
262 DCHECK_EQ(blob_info
.size(), blob_or_file_info
->size());
264 if (!dispatcher_host
->blob_storage_context())
266 for (i
= 0; i
< blob_info
.size(); ++i
) {
267 (*blob_or_file_info
)[i
].uuid
=
268 CreateBlobData(blob_info
[i
],
270 dispatcher_host
->blob_storage_context(),
271 dispatcher_host
->Context()->TaskRunner());
276 template <class ParamType
, class MsgType
>
277 static void CreateBlobsAndSend(
279 scoped_refptr
<IndexedDBDispatcherHost
> dispatcher_host
,
280 const std::vector
<IndexedDBBlobInfo
>& blob_info
,
281 std::vector
<IndexedDBMsg_BlobOrFileInfo
>* blob_or_file_info
) {
282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
283 if (CreateAllBlobs(blob_info
, blob_or_file_info
, dispatcher_host
))
284 dispatcher_host
->Send(new MsgType(*params
));
287 static void BlobLookupForCursorPrefetch(
288 IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params
* params
,
289 scoped_refptr
<IndexedDBDispatcherHost
> dispatcher_host
,
290 const std::vector
<IndexedDBValue
>& values
) {
291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
292 DCHECK_EQ(values
.size(), params
->blob_or_file_infos
.size());
294 std::vector
<IndexedDBValue
>::const_iterator value_iter
;
295 std::vector
<std::vector
<IndexedDBMsg_BlobOrFileInfo
> >::iterator blob_iter
;
296 for (value_iter
= values
.begin(), blob_iter
=
297 params
->blob_or_file_infos
.begin(); value_iter
!= values
.end();
298 ++value_iter
, ++blob_iter
) {
299 if (!CreateAllBlobs(value_iter
->blob_info
, &*blob_iter
, dispatcher_host
))
302 dispatcher_host
->Send(
303 new IndexedDBMsg_CallbacksSuccessCursorPrefetch(*params
));
306 static void FillInBlobData(
307 const std::vector
<IndexedDBBlobInfo
>& blob_info
,
308 std::vector
<IndexedDBMsg_BlobOrFileInfo
>* blob_or_file_info
) {
309 for (std::vector
<IndexedDBBlobInfo
>::const_iterator iter
= blob_info
.begin();
310 iter
!= blob_info
.end();
312 if (iter
->is_file()) {
313 IndexedDBMsg_BlobOrFileInfo info
;
315 info
.mime_type
= iter
->type();
316 info
.file_name
= iter
->file_name();
317 info
.file_path
= iter
->file_path().AsUTF16Unsafe();
318 info
.size
= iter
->size();
319 info
.last_modified
= iter
->last_modified().ToDoubleT();
320 blob_or_file_info
->push_back(info
);
322 IndexedDBMsg_BlobOrFileInfo info
;
323 info
.mime_type
= iter
->type();
324 info
.size
= iter
->size();
325 blob_or_file_info
->push_back(info
);
330 void IndexedDBCallbacks::RegisterBlobsAndSend(
331 const std::vector
<IndexedDBBlobInfo
>& blob_info
,
332 const base::Closure
& callback
) {
333 std::vector
<IndexedDBBlobInfo
>::const_iterator iter
;
334 for (iter
= blob_info
.begin(); iter
!= blob_info
.end(); ++iter
) {
335 if (!iter
->mark_used_callback().is_null())
336 iter
->mark_used_callback().Run();
338 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO
));
339 BrowserThread::PostTask(BrowserThread::IO
, FROM_HERE
, callback
);
342 void IndexedDBCallbacks::OnSuccess(scoped_refptr
<IndexedDBCursor
> cursor
,
343 const IndexedDBKey
& key
,
344 const IndexedDBKey
& primary_key
,
345 IndexedDBValue
* value
) {
346 DCHECK(dispatcher_host_
.get());
348 DCHECK_EQ(kNoCursor
, ipc_cursor_id_
);
349 DCHECK_EQ(kNoTransaction
, host_transaction_id_
);
350 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
351 DCHECK_EQ(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
352 DCHECK_EQ(blink::WebIDBDataLossNone
, data_loss_
);
354 int32 ipc_object_id
= dispatcher_host_
->Add(cursor
.get());
355 scoped_ptr
<IndexedDBMsg_CallbacksSuccessIDBCursor_Params
> params(
356 new IndexedDBMsg_CallbacksSuccessIDBCursor_Params());
357 params
->ipc_thread_id
= ipc_thread_id_
;
358 params
->ipc_callbacks_id
= ipc_callbacks_id_
;
359 params
->ipc_cursor_id
= ipc_object_id
;
361 params
->primary_key
= primary_key
;
362 if (value
&& !value
->empty())
363 std::swap(params
->value
, value
->bits
);
364 // TODO(alecflett): Avoid a copy here: the whole params object is
365 // being copied into the message.
366 if (!value
|| value
->blob_info
.empty()) {
367 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksSuccessIDBCursor(*params
));
369 IndexedDBMsg_CallbacksSuccessIDBCursor_Params
* p
= params
.get();
370 FillInBlobData(value
->blob_info
, &p
->blob_or_file_info
);
371 RegisterBlobsAndSend(
374 CreateBlobsAndSend
<IndexedDBMsg_CallbacksSuccessIDBCursor_Params
,
375 IndexedDBMsg_CallbacksSuccessIDBCursor
>,
376 base::Owned(params
.release()),
379 base::Unretained(&p
->blob_or_file_info
)));
381 dispatcher_host_
= NULL
;
384 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey
& key
,
385 const IndexedDBKey
& primary_key
,
386 IndexedDBValue
* value
) {
387 DCHECK(dispatcher_host_
.get());
389 DCHECK_NE(kNoCursor
, ipc_cursor_id_
);
390 DCHECK_EQ(kNoTransaction
, host_transaction_id_
);
391 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
392 DCHECK_EQ(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
393 DCHECK_EQ(blink::WebIDBDataLossNone
, data_loss_
);
395 IndexedDBCursor
* idb_cursor
=
396 dispatcher_host_
->GetCursorFromId(ipc_cursor_id_
);
402 scoped_ptr
<IndexedDBMsg_CallbacksSuccessCursorContinue_Params
> params(
403 new IndexedDBMsg_CallbacksSuccessCursorContinue_Params());
404 params
->ipc_thread_id
= ipc_thread_id_
;
405 params
->ipc_callbacks_id
= ipc_callbacks_id_
;
406 params
->ipc_cursor_id
= ipc_cursor_id_
;
408 params
->primary_key
= primary_key
;
409 if (value
&& !value
->empty())
410 std::swap(params
->value
, value
->bits
);
411 // TODO(alecflett): Avoid a copy here: the whole params object is
412 // being copied into the message.
413 if (!value
|| value
->blob_info
.empty()) {
414 dispatcher_host_
->Send(
415 new IndexedDBMsg_CallbacksSuccessCursorContinue(*params
));
417 IndexedDBMsg_CallbacksSuccessCursorContinue_Params
* p
= params
.get();
418 FillInBlobData(value
->blob_info
, &p
->blob_or_file_info
);
419 RegisterBlobsAndSend(
421 base::Bind(CreateBlobsAndSend
<
422 IndexedDBMsg_CallbacksSuccessCursorContinue_Params
,
423 IndexedDBMsg_CallbacksSuccessCursorContinue
>,
424 base::Owned(params
.release()),
427 base::Unretained(&p
->blob_or_file_info
)));
429 dispatcher_host_
= NULL
;
432 void IndexedDBCallbacks::OnSuccessWithPrefetch(
433 const std::vector
<IndexedDBKey
>& keys
,
434 const std::vector
<IndexedDBKey
>& primary_keys
,
435 std::vector
<IndexedDBValue
>* values
) {
436 DCHECK_EQ(keys
.size(), primary_keys
.size());
437 DCHECK_EQ(keys
.size(), values
->size());
439 DCHECK(dispatcher_host_
.get());
441 DCHECK_NE(kNoCursor
, ipc_cursor_id_
);
442 DCHECK_EQ(kNoTransaction
, host_transaction_id_
);
443 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
444 DCHECK_EQ(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
445 DCHECK_EQ(blink::WebIDBDataLossNone
, data_loss_
);
447 std::vector
<IndexedDBKey
> msgKeys
;
448 std::vector
<IndexedDBKey
> msgPrimaryKeys
;
450 for (size_t i
= 0; i
< keys
.size(); ++i
) {
451 msgKeys
.push_back(keys
[i
]);
452 msgPrimaryKeys
.push_back(primary_keys
[i
]);
455 scoped_ptr
<IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params
> params(
456 new IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params());
457 params
->ipc_thread_id
= ipc_thread_id_
;
458 params
->ipc_callbacks_id
= ipc_callbacks_id_
;
459 params
->ipc_cursor_id
= ipc_cursor_id_
;
460 params
->keys
= msgKeys
;
461 params
->primary_keys
= msgPrimaryKeys
;
462 std::vector
<std::string
>& values_bits
= params
->values
;
463 values_bits
.resize(values
->size());
464 std::vector
<std::vector
<IndexedDBMsg_BlobOrFileInfo
> >& values_blob_infos
=
465 params
->blob_or_file_infos
;
466 values_blob_infos
.resize(values
->size());
468 bool found_blob_info
= false;
469 std::vector
<IndexedDBValue
>::iterator iter
= values
->begin();
470 for (size_t i
= 0; iter
!= values
->end(); ++iter
, ++i
) {
471 values_bits
[i
].swap(iter
->bits
);
472 if (iter
->blob_info
.size()) {
473 found_blob_info
= true;
474 FillInBlobData(iter
->blob_info
, &values_blob_infos
[i
]);
475 std::vector
<IndexedDBBlobInfo
>::const_iterator blob_iter
;
476 for (blob_iter
= iter
->blob_info
.begin();
477 blob_iter
!= iter
->blob_info
.end();
479 if (!blob_iter
->mark_used_callback().is_null())
480 blob_iter
->mark_used_callback().Run();
485 if (found_blob_info
) {
486 BrowserThread::PostTask(BrowserThread::IO
,
488 base::Bind(BlobLookupForCursorPrefetch
,
489 base::Owned(params
.release()),
493 dispatcher_host_
->Send(
494 new IndexedDBMsg_CallbacksSuccessCursorPrefetch(*params
.get()));
496 dispatcher_host_
= NULL
;
499 void IndexedDBCallbacks::OnSuccess(IndexedDBValue
* value
,
500 const IndexedDBKey
& key
,
501 const IndexedDBKeyPath
& key_path
) {
502 DCHECK(dispatcher_host_
.get());
504 DCHECK_EQ(kNoCursor
, ipc_cursor_id_
);
505 DCHECK_EQ(kNoTransaction
, host_transaction_id_
);
506 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
507 DCHECK_EQ(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
508 DCHECK_EQ(blink::WebIDBDataLossNone
, data_loss_
);
510 scoped_ptr
<IndexedDBMsg_CallbacksSuccessValueWithKey_Params
> params(
511 new IndexedDBMsg_CallbacksSuccessValueWithKey_Params());
512 params
->ipc_thread_id
= ipc_thread_id_
;
513 params
->ipc_callbacks_id
= ipc_callbacks_id_
;
514 params
->primary_key
= key
;
515 params
->key_path
= key_path
;
516 if (value
&& !value
->empty())
517 std::swap(params
->value
, value
->bits
);
518 if (!value
|| value
->blob_info
.empty()) {
519 dispatcher_host_
->Send(
520 new IndexedDBMsg_CallbacksSuccessValueWithKey(*params
));
522 IndexedDBMsg_CallbacksSuccessValueWithKey_Params
* p
= params
.get();
523 FillInBlobData(value
->blob_info
, &p
->blob_or_file_info
);
524 RegisterBlobsAndSend(
527 CreateBlobsAndSend
<IndexedDBMsg_CallbacksSuccessValueWithKey_Params
,
528 IndexedDBMsg_CallbacksSuccessValueWithKey
>,
529 base::Owned(params
.release()),
532 base::Unretained(&p
->blob_or_file_info
)));
534 dispatcher_host_
= NULL
;
537 void IndexedDBCallbacks::OnSuccess(IndexedDBValue
* value
) {
538 DCHECK(dispatcher_host_
.get());
539 DCHECK(kNoCursor
== ipc_cursor_id_
|| value
== NULL
);
540 DCHECK_EQ(kNoTransaction
, host_transaction_id_
);
541 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
542 DCHECK_EQ(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
543 DCHECK_EQ(blink::WebIDBDataLossNone
, data_loss_
);
545 scoped_ptr
<IndexedDBMsg_CallbacksSuccessValue_Params
> params(
546 new IndexedDBMsg_CallbacksSuccessValue_Params());
547 params
->ipc_thread_id
= ipc_thread_id_
;
548 params
->ipc_callbacks_id
= ipc_callbacks_id_
;
549 if (value
&& !value
->empty())
550 std::swap(params
->value
, value
->bits
);
551 if (!value
|| value
->blob_info
.empty()) {
552 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksSuccessValue(*params
));
554 IndexedDBMsg_CallbacksSuccessValue_Params
* p
= params
.get();
555 FillInBlobData(value
->blob_info
, &p
->blob_or_file_info
);
556 RegisterBlobsAndSend(
558 base::Bind(CreateBlobsAndSend
<IndexedDBMsg_CallbacksSuccessValue_Params
,
559 IndexedDBMsg_CallbacksSuccessValue
>,
560 base::Owned(params
.release()),
563 base::Unretained(&p
->blob_or_file_info
)));
565 dispatcher_host_
= NULL
;
568 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey
& value
) {
569 DCHECK(dispatcher_host_
.get());
571 DCHECK_EQ(kNoCursor
, ipc_cursor_id_
);
572 DCHECK_EQ(kNoTransaction
, host_transaction_id_
);
573 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
574 DCHECK_EQ(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
575 DCHECK_EQ(blink::WebIDBDataLossNone
, data_loss_
);
577 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksSuccessIndexedDBKey(
578 ipc_thread_id_
, ipc_callbacks_id_
, value
));
579 dispatcher_host_
= NULL
;
582 void IndexedDBCallbacks::OnSuccess(int64 value
) {
583 DCHECK(dispatcher_host_
.get());
585 DCHECK_EQ(kNoCursor
, ipc_cursor_id_
);
586 DCHECK_EQ(kNoTransaction
, host_transaction_id_
);
587 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
588 DCHECK_EQ(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
589 DCHECK_EQ(blink::WebIDBDataLossNone
, data_loss_
);
591 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksSuccessInteger(
592 ipc_thread_id_
, ipc_callbacks_id_
, value
));
593 dispatcher_host_
= NULL
;
596 void IndexedDBCallbacks::OnSuccess() {
597 DCHECK(dispatcher_host_
.get());
599 DCHECK_EQ(kNoCursor
, ipc_cursor_id_
);
600 DCHECK_EQ(kNoTransaction
, host_transaction_id_
);
601 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
602 DCHECK_EQ(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
603 DCHECK_EQ(blink::WebIDBDataLossNone
, data_loss_
);
605 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksSuccessUndefined(
606 ipc_thread_id_
, ipc_callbacks_id_
));
607 dispatcher_host_
= NULL
;
610 void IndexedDBCallbacks::SetConnectionOpenStartTime(
611 const base::TimeTicks
& start_time
) {
612 connection_open_start_time_
= start_time
;
615 } // namespace content