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"
9 #include "base/metrics/histogram.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "base/time/time.h"
12 #include "content/browser/child_process_security_policy_impl.h"
13 #include "content/browser/fileapi/fileapi_message_filter.h"
14 #include "content/browser/indexed_db/indexed_db_blob_info.h"
15 #include "content/browser/indexed_db/indexed_db_connection.h"
16 #include "content/browser/indexed_db/indexed_db_context_impl.h"
17 #include "content/browser/indexed_db/indexed_db_cursor.h"
18 #include "content/browser/indexed_db/indexed_db_database_callbacks.h"
19 #include "content/browser/indexed_db/indexed_db_database_error.h"
20 #include "content/browser/indexed_db/indexed_db_metadata.h"
21 #include "content/browser/indexed_db/indexed_db_value.h"
22 #include "content/common/indexed_db/indexed_db_constants.h"
23 #include "content/common/indexed_db/indexed_db_messages.h"
24 #include "storage/browser/blob/blob_storage_context.h"
25 #include "storage/browser/quota/quota_manager.h"
26 #include "storage/common/blob/blob_data.h"
27 #include "storage/common/blob/shareable_file_reference.h"
29 using storage::ShareableFileReference
;
34 const int32 kNoCursor
= -1;
35 const int32 kNoDatabaseCallbacks
= -1;
36 const int64 kNoTransaction
= -1;
39 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost
* dispatcher_host
,
41 int32 ipc_callbacks_id
)
42 : dispatcher_host_(dispatcher_host
),
43 ipc_callbacks_id_(ipc_callbacks_id
),
44 ipc_thread_id_(ipc_thread_id
),
45 ipc_cursor_id_(kNoCursor
),
46 host_transaction_id_(kNoTransaction
),
47 ipc_database_id_(kNoDatabase
),
48 ipc_database_callbacks_id_(kNoDatabaseCallbacks
),
49 data_loss_(blink::WebIDBDataLossNone
),
50 sent_blocked_(false) {
53 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost
* dispatcher_host
,
55 int32 ipc_callbacks_id
,
57 : dispatcher_host_(dispatcher_host
),
58 ipc_callbacks_id_(ipc_callbacks_id
),
59 ipc_thread_id_(ipc_thread_id
),
60 ipc_cursor_id_(ipc_cursor_id
),
61 host_transaction_id_(kNoTransaction
),
62 ipc_database_id_(kNoDatabase
),
63 ipc_database_callbacks_id_(kNoDatabaseCallbacks
),
64 data_loss_(blink::WebIDBDataLossNone
),
65 sent_blocked_(false) {
68 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost
* dispatcher_host
,
70 int32 ipc_callbacks_id
,
71 int32 ipc_database_callbacks_id
,
72 int64 host_transaction_id
,
73 const GURL
& origin_url
)
74 : dispatcher_host_(dispatcher_host
),
75 ipc_callbacks_id_(ipc_callbacks_id
),
76 ipc_thread_id_(ipc_thread_id
),
77 ipc_cursor_id_(kNoCursor
),
78 host_transaction_id_(host_transaction_id
),
79 origin_url_(origin_url
),
80 ipc_database_id_(kNoDatabase
),
81 ipc_database_callbacks_id_(ipc_database_callbacks_id
),
82 data_loss_(blink::WebIDBDataLossNone
),
83 sent_blocked_(false) {
86 IndexedDBCallbacks::~IndexedDBCallbacks() {}
88 void IndexedDBCallbacks::OnError(const IndexedDBDatabaseError
& error
) {
89 DCHECK(dispatcher_host_
.get());
91 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksError(
92 ipc_thread_id_
, ipc_callbacks_id_
, error
.code(), error
.message()));
93 dispatcher_host_
= NULL
;
95 if (!connection_open_start_time_
.is_null()) {
96 UMA_HISTOGRAM_MEDIUM_TIMES(
97 "WebCore.IndexedDB.OpenTime.Error",
98 base::TimeTicks::Now() - connection_open_start_time_
);
99 connection_open_start_time_
= base::TimeTicks();
103 void IndexedDBCallbacks::OnSuccess(const std::vector
<base::string16
>& value
) {
104 DCHECK(dispatcher_host_
.get());
106 DCHECK_EQ(kNoCursor
, ipc_cursor_id_
);
107 DCHECK_EQ(kNoTransaction
, host_transaction_id_
);
108 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
109 DCHECK_EQ(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
110 DCHECK_EQ(blink::WebIDBDataLossNone
, data_loss_
);
112 std::vector
<base::string16
> list
;
113 for (unsigned i
= 0; i
< value
.size(); ++i
)
114 list
.push_back(value
[i
]);
116 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksSuccessStringList(
117 ipc_thread_id_
, ipc_callbacks_id_
, list
));
118 dispatcher_host_
= NULL
;
121 void IndexedDBCallbacks::OnBlocked(int64 existing_version
) {
122 DCHECK(dispatcher_host_
.get());
124 DCHECK_EQ(kNoCursor
, ipc_cursor_id_
);
125 // No transaction/db callbacks for DeleteDatabase.
126 DCHECK_EQ(kNoTransaction
== host_transaction_id_
,
127 kNoDatabaseCallbacks
== ipc_database_callbacks_id_
);
128 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
133 sent_blocked_
= true;
134 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksIntBlocked(
135 ipc_thread_id_
, ipc_callbacks_id_
, existing_version
));
137 if (!connection_open_start_time_
.is_null()) {
138 UMA_HISTOGRAM_MEDIUM_TIMES(
139 "WebCore.IndexedDB.OpenTime.Blocked",
140 base::TimeTicks::Now() - connection_open_start_time_
);
141 connection_open_start_time_
= base::TimeTicks();
145 void IndexedDBCallbacks::OnDataLoss(blink::WebIDBDataLoss data_loss
,
146 std::string data_loss_message
) {
147 DCHECK_NE(blink::WebIDBDataLossNone
, data_loss
);
148 data_loss_
= data_loss
;
149 data_loss_message_
= data_loss_message
;
152 void IndexedDBCallbacks::OnUpgradeNeeded(
154 scoped_ptr
<IndexedDBConnection
> connection
,
155 const IndexedDBDatabaseMetadata
& metadata
) {
156 DCHECK(dispatcher_host_
.get());
158 DCHECK_EQ(kNoCursor
, ipc_cursor_id_
);
159 DCHECK_NE(kNoTransaction
, host_transaction_id_
);
160 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
161 DCHECK_NE(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
163 dispatcher_host_
->RegisterTransactionId(host_transaction_id_
, origin_url_
);
164 int32 ipc_database_id
=
165 dispatcher_host_
->Add(connection
.release(), ipc_thread_id_
, origin_url_
);
166 if (ipc_database_id
< 0)
168 ipc_database_id_
= ipc_database_id
;
169 IndexedDBMsg_CallbacksUpgradeNeeded_Params params
;
170 params
.ipc_thread_id
= ipc_thread_id_
;
171 params
.ipc_callbacks_id
= ipc_callbacks_id_
;
172 params
.ipc_database_id
= ipc_database_id
;
173 params
.ipc_database_callbacks_id
= ipc_database_callbacks_id_
;
174 params
.old_version
= old_version
;
175 params
.idb_metadata
= IndexedDBDispatcherHost::ConvertMetadata(metadata
);
176 params
.data_loss
= data_loss_
;
177 params
.data_loss_message
= data_loss_message_
;
178 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksUpgradeNeeded(params
));
180 if (!connection_open_start_time_
.is_null()) {
181 UMA_HISTOGRAM_MEDIUM_TIMES(
182 "WebCore.IndexedDB.OpenTime.UpgradeNeeded",
183 base::TimeTicks::Now() - connection_open_start_time_
);
184 connection_open_start_time_
= base::TimeTicks();
188 void IndexedDBCallbacks::OnSuccess(scoped_ptr
<IndexedDBConnection
> connection
,
189 const IndexedDBDatabaseMetadata
& metadata
) {
190 DCHECK(dispatcher_host_
.get());
192 DCHECK_EQ(kNoCursor
, ipc_cursor_id_
);
193 DCHECK_NE(kNoTransaction
, host_transaction_id_
);
194 DCHECK_NE(ipc_database_id_
== kNoDatabase
, !connection
);
195 DCHECK_NE(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
197 scoped_refptr
<IndexedDBCallbacks
> self(this);
199 int32 ipc_object_id
= kNoDatabase
;
200 // Only register if the connection was not previously sent in OnUpgradeNeeded.
201 if (ipc_database_id_
== kNoDatabase
) {
202 ipc_object_id
= dispatcher_host_
->Add(
203 connection
.release(), ipc_thread_id_
, origin_url_
);
206 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksSuccessIDBDatabase(
209 ipc_database_callbacks_id_
,
211 IndexedDBDispatcherHost::ConvertMetadata(metadata
)));
212 dispatcher_host_
= NULL
;
214 if (!connection_open_start_time_
.is_null()) {
215 UMA_HISTOGRAM_MEDIUM_TIMES(
216 "WebCore.IndexedDB.OpenTime.Success",
217 base::TimeTicks::Now() - connection_open_start_time_
);
218 connection_open_start_time_
= base::TimeTicks();
222 static std::string
CreateBlobData(
223 const IndexedDBBlobInfo
& blob_info
,
224 scoped_refptr
<IndexedDBDispatcherHost
> dispatcher_host
,
225 base::TaskRunner
* task_runner
) {
226 if (!blob_info
.uuid().empty()) {
227 // We're sending back a live blob, not a reference into our backing store.
228 return dispatcher_host
->HoldBlobData(blob_info
);
230 scoped_refptr
<ShareableFileReference
> shareable_file
=
231 ShareableFileReference::Get(blob_info
.file_path());
232 if (!shareable_file
.get()) {
233 shareable_file
= ShareableFileReference::GetOrCreate(
234 blob_info
.file_path(),
235 ShareableFileReference::DONT_DELETE_ON_FINAL_RELEASE
,
237 if (!blob_info
.release_callback().is_null())
238 shareable_file
->AddFinalReleaseCallback(blob_info
.release_callback());
240 return dispatcher_host
->HoldBlobData(blob_info
);
243 static bool CreateAllBlobs(
244 const std::vector
<IndexedDBBlobInfo
>& blob_info
,
245 std::vector
<IndexedDBMsg_BlobOrFileInfo
>* blob_or_file_info
,
246 scoped_refptr
<IndexedDBDispatcherHost
> dispatcher_host
) {
247 DCHECK_EQ(blob_info
.size(), blob_or_file_info
->size());
249 if (!dispatcher_host
->blob_storage_context())
251 for (i
= 0; i
< blob_info
.size(); ++i
) {
252 (*blob_or_file_info
)[i
].uuid
=
253 CreateBlobData(blob_info
[i
],
255 dispatcher_host
->Context()->TaskRunner());
260 template <class ParamType
, class MsgType
>
261 static void CreateBlobsAndSend(
263 scoped_refptr
<IndexedDBDispatcherHost
> dispatcher_host
,
264 const std::vector
<IndexedDBBlobInfo
>& blob_info
,
265 std::vector
<IndexedDBMsg_BlobOrFileInfo
>* blob_or_file_info
) {
266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
267 if (CreateAllBlobs(blob_info
, blob_or_file_info
, dispatcher_host
))
268 dispatcher_host
->Send(new MsgType(*params
));
271 static void BlobLookupForCursorPrefetch(
272 IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params
* params
,
273 scoped_refptr
<IndexedDBDispatcherHost
> dispatcher_host
,
274 const std::vector
<IndexedDBValue
>& values
) {
275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
276 DCHECK_EQ(values
.size(), params
->blob_or_file_infos
.size());
278 std::vector
<IndexedDBValue
>::const_iterator value_iter
;
279 std::vector
<std::vector
<IndexedDBMsg_BlobOrFileInfo
> >::iterator blob_iter
;
280 for (value_iter
= values
.begin(), blob_iter
=
281 params
->blob_or_file_infos
.begin(); value_iter
!= values
.end();
282 ++value_iter
, ++blob_iter
) {
283 if (!CreateAllBlobs(value_iter
->blob_info
, &*blob_iter
, dispatcher_host
))
286 dispatcher_host
->Send(
287 new IndexedDBMsg_CallbacksSuccessCursorPrefetch(*params
));
290 static void FillInBlobData(
291 const std::vector
<IndexedDBBlobInfo
>& blob_info
,
292 std::vector
<IndexedDBMsg_BlobOrFileInfo
>* blob_or_file_info
) {
293 for (const auto& iter
: blob_info
) {
294 if (iter
.is_file()) {
295 IndexedDBMsg_BlobOrFileInfo info
;
297 info
.mime_type
= iter
.type();
298 info
.file_name
= iter
.file_name();
299 info
.file_path
= iter
.file_path().AsUTF16Unsafe();
300 info
.size
= iter
.size();
301 info
.last_modified
= iter
.last_modified().ToDoubleT();
302 blob_or_file_info
->push_back(info
);
304 IndexedDBMsg_BlobOrFileInfo info
;
305 info
.mime_type
= iter
.type();
306 info
.size
= iter
.size();
307 blob_or_file_info
->push_back(info
);
312 void IndexedDBCallbacks::RegisterBlobsAndSend(
313 const std::vector
<IndexedDBBlobInfo
>& blob_info
,
314 const base::Closure
& callback
) {
315 for (const auto& iter
: blob_info
) {
316 if (!iter
.mark_used_callback().is_null())
317 iter
.mark_used_callback().Run();
319 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO
));
320 BrowserThread::PostTask(BrowserThread::IO
, FROM_HERE
, callback
);
323 void IndexedDBCallbacks::OnSuccess(scoped_refptr
<IndexedDBCursor
> cursor
,
324 const IndexedDBKey
& key
,
325 const IndexedDBKey
& primary_key
,
326 IndexedDBValue
* value
) {
327 DCHECK(dispatcher_host_
.get());
329 DCHECK_EQ(kNoCursor
, ipc_cursor_id_
);
330 DCHECK_EQ(kNoTransaction
, host_transaction_id_
);
331 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
332 DCHECK_EQ(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
333 DCHECK_EQ(blink::WebIDBDataLossNone
, data_loss_
);
335 int32 ipc_object_id
= dispatcher_host_
->Add(cursor
.get());
336 scoped_ptr
<IndexedDBMsg_CallbacksSuccessIDBCursor_Params
> params(
337 new IndexedDBMsg_CallbacksSuccessIDBCursor_Params());
338 params
->ipc_thread_id
= ipc_thread_id_
;
339 params
->ipc_callbacks_id
= ipc_callbacks_id_
;
340 params
->ipc_cursor_id
= ipc_object_id
;
342 params
->primary_key
= primary_key
;
343 if (value
&& !value
->empty())
344 std::swap(params
->value
, value
->bits
);
345 // TODO(alecflett): Avoid a copy here: the whole params object is
346 // being copied into the message.
347 if (!value
|| value
->blob_info
.empty()) {
348 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksSuccessIDBCursor(*params
));
350 IndexedDBMsg_CallbacksSuccessIDBCursor_Params
* p
= params
.get();
351 FillInBlobData(value
->blob_info
, &p
->blob_or_file_info
);
352 RegisterBlobsAndSend(
355 CreateBlobsAndSend
<IndexedDBMsg_CallbacksSuccessIDBCursor_Params
,
356 IndexedDBMsg_CallbacksSuccessIDBCursor
>,
357 base::Owned(params
.release()),
360 base::Unretained(&p
->blob_or_file_info
)));
362 dispatcher_host_
= NULL
;
365 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey
& key
,
366 const IndexedDBKey
& primary_key
,
367 IndexedDBValue
* value
) {
368 DCHECK(dispatcher_host_
.get());
370 DCHECK_NE(kNoCursor
, ipc_cursor_id_
);
371 DCHECK_EQ(kNoTransaction
, host_transaction_id_
);
372 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
373 DCHECK_EQ(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
374 DCHECK_EQ(blink::WebIDBDataLossNone
, data_loss_
);
376 IndexedDBCursor
* idb_cursor
=
377 dispatcher_host_
->GetCursorFromId(ipc_cursor_id_
);
383 scoped_ptr
<IndexedDBMsg_CallbacksSuccessCursorContinue_Params
> params(
384 new IndexedDBMsg_CallbacksSuccessCursorContinue_Params());
385 params
->ipc_thread_id
= ipc_thread_id_
;
386 params
->ipc_callbacks_id
= ipc_callbacks_id_
;
387 params
->ipc_cursor_id
= ipc_cursor_id_
;
389 params
->primary_key
= primary_key
;
390 if (value
&& !value
->empty())
391 std::swap(params
->value
, value
->bits
);
392 // TODO(alecflett): Avoid a copy here: the whole params object is
393 // being copied into the message.
394 if (!value
|| value
->blob_info
.empty()) {
395 dispatcher_host_
->Send(
396 new IndexedDBMsg_CallbacksSuccessCursorContinue(*params
));
398 IndexedDBMsg_CallbacksSuccessCursorContinue_Params
* p
= params
.get();
399 FillInBlobData(value
->blob_info
, &p
->blob_or_file_info
);
400 RegisterBlobsAndSend(
402 base::Bind(CreateBlobsAndSend
<
403 IndexedDBMsg_CallbacksSuccessCursorContinue_Params
,
404 IndexedDBMsg_CallbacksSuccessCursorContinue
>,
405 base::Owned(params
.release()),
408 base::Unretained(&p
->blob_or_file_info
)));
410 dispatcher_host_
= NULL
;
413 void IndexedDBCallbacks::OnSuccessWithPrefetch(
414 const std::vector
<IndexedDBKey
>& keys
,
415 const std::vector
<IndexedDBKey
>& primary_keys
,
416 std::vector
<IndexedDBValue
>* values
) {
417 DCHECK_EQ(keys
.size(), primary_keys
.size());
418 DCHECK_EQ(keys
.size(), values
->size());
420 DCHECK(dispatcher_host_
.get());
422 DCHECK_NE(kNoCursor
, ipc_cursor_id_
);
423 DCHECK_EQ(kNoTransaction
, host_transaction_id_
);
424 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
425 DCHECK_EQ(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
426 DCHECK_EQ(blink::WebIDBDataLossNone
, data_loss_
);
428 std::vector
<IndexedDBKey
> msgKeys
;
429 std::vector
<IndexedDBKey
> msgPrimaryKeys
;
431 for (size_t i
= 0; i
< keys
.size(); ++i
) {
432 msgKeys
.push_back(keys
[i
]);
433 msgPrimaryKeys
.push_back(primary_keys
[i
]);
436 scoped_ptr
<IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params
> params(
437 new IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params());
438 params
->ipc_thread_id
= ipc_thread_id_
;
439 params
->ipc_callbacks_id
= ipc_callbacks_id_
;
440 params
->ipc_cursor_id
= ipc_cursor_id_
;
441 params
->keys
= msgKeys
;
442 params
->primary_keys
= msgPrimaryKeys
;
443 std::vector
<std::string
>& values_bits
= params
->values
;
444 values_bits
.resize(values
->size());
445 std::vector
<std::vector
<IndexedDBMsg_BlobOrFileInfo
> >& values_blob_infos
=
446 params
->blob_or_file_infos
;
447 values_blob_infos
.resize(values
->size());
449 bool found_blob_info
= false;
450 std::vector
<IndexedDBValue
>::iterator iter
= values
->begin();
451 for (size_t i
= 0; iter
!= values
->end(); ++iter
, ++i
) {
452 values_bits
[i
].swap(iter
->bits
);
453 if (iter
->blob_info
.size()) {
454 found_blob_info
= true;
455 FillInBlobData(iter
->blob_info
, &values_blob_infos
[i
]);
456 for (const auto& blob_iter
: iter
->blob_info
) {
457 if (!blob_iter
.mark_used_callback().is_null())
458 blob_iter
.mark_used_callback().Run();
463 if (found_blob_info
) {
464 BrowserThread::PostTask(BrowserThread::IO
,
466 base::Bind(BlobLookupForCursorPrefetch
,
467 base::Owned(params
.release()),
471 dispatcher_host_
->Send(
472 new IndexedDBMsg_CallbacksSuccessCursorPrefetch(*params
.get()));
474 dispatcher_host_
= NULL
;
477 void IndexedDBCallbacks::OnSuccess(IndexedDBValue
* value
,
478 const IndexedDBKey
& key
,
479 const IndexedDBKeyPath
& key_path
) {
480 DCHECK(dispatcher_host_
.get());
482 DCHECK_EQ(kNoCursor
, ipc_cursor_id_
);
483 DCHECK_EQ(kNoTransaction
, host_transaction_id_
);
484 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
485 DCHECK_EQ(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
486 DCHECK_EQ(blink::WebIDBDataLossNone
, data_loss_
);
488 scoped_ptr
<IndexedDBMsg_CallbacksSuccessValueWithKey_Params
> params(
489 new IndexedDBMsg_CallbacksSuccessValueWithKey_Params());
490 params
->ipc_thread_id
= ipc_thread_id_
;
491 params
->ipc_callbacks_id
= ipc_callbacks_id_
;
492 params
->primary_key
= key
;
493 params
->key_path
= key_path
;
494 if (value
&& !value
->empty())
495 std::swap(params
->value
, value
->bits
);
496 if (!value
|| value
->blob_info
.empty()) {
497 dispatcher_host_
->Send(
498 new IndexedDBMsg_CallbacksSuccessValueWithKey(*params
));
500 IndexedDBMsg_CallbacksSuccessValueWithKey_Params
* p
= params
.get();
501 FillInBlobData(value
->blob_info
, &p
->blob_or_file_info
);
502 RegisterBlobsAndSend(
505 CreateBlobsAndSend
<IndexedDBMsg_CallbacksSuccessValueWithKey_Params
,
506 IndexedDBMsg_CallbacksSuccessValueWithKey
>,
507 base::Owned(params
.release()),
510 base::Unretained(&p
->blob_or_file_info
)));
512 dispatcher_host_
= NULL
;
515 void IndexedDBCallbacks::OnSuccess(IndexedDBValue
* value
) {
516 DCHECK(dispatcher_host_
.get());
517 DCHECK(kNoCursor
== ipc_cursor_id_
|| value
== NULL
);
518 DCHECK_EQ(kNoTransaction
, host_transaction_id_
);
519 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
520 DCHECK_EQ(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
521 DCHECK_EQ(blink::WebIDBDataLossNone
, data_loss_
);
523 scoped_ptr
<IndexedDBMsg_CallbacksSuccessValue_Params
> params(
524 new IndexedDBMsg_CallbacksSuccessValue_Params());
525 params
->ipc_thread_id
= ipc_thread_id_
;
526 params
->ipc_callbacks_id
= ipc_callbacks_id_
;
527 if (value
&& !value
->empty())
528 std::swap(params
->value
, value
->bits
);
529 if (!value
|| value
->blob_info
.empty()) {
530 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksSuccessValue(*params
));
532 IndexedDBMsg_CallbacksSuccessValue_Params
* p
= params
.get();
533 FillInBlobData(value
->blob_info
, &p
->blob_or_file_info
);
534 RegisterBlobsAndSend(
536 base::Bind(CreateBlobsAndSend
<IndexedDBMsg_CallbacksSuccessValue_Params
,
537 IndexedDBMsg_CallbacksSuccessValue
>,
538 base::Owned(params
.release()),
541 base::Unretained(&p
->blob_or_file_info
)));
543 dispatcher_host_
= NULL
;
546 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey
& value
) {
547 DCHECK(dispatcher_host_
.get());
549 DCHECK_EQ(kNoCursor
, ipc_cursor_id_
);
550 DCHECK_EQ(kNoTransaction
, host_transaction_id_
);
551 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
552 DCHECK_EQ(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
553 DCHECK_EQ(blink::WebIDBDataLossNone
, data_loss_
);
555 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksSuccessIndexedDBKey(
556 ipc_thread_id_
, ipc_callbacks_id_
, value
));
557 dispatcher_host_
= NULL
;
560 void IndexedDBCallbacks::OnSuccess(int64 value
) {
561 DCHECK(dispatcher_host_
.get());
563 DCHECK_EQ(kNoCursor
, ipc_cursor_id_
);
564 DCHECK_EQ(kNoTransaction
, host_transaction_id_
);
565 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
566 DCHECK_EQ(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
567 DCHECK_EQ(blink::WebIDBDataLossNone
, data_loss_
);
569 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksSuccessInteger(
570 ipc_thread_id_
, ipc_callbacks_id_
, value
));
571 dispatcher_host_
= NULL
;
574 void IndexedDBCallbacks::OnSuccess() {
575 DCHECK(dispatcher_host_
.get());
577 DCHECK_EQ(kNoCursor
, ipc_cursor_id_
);
578 DCHECK_EQ(kNoTransaction
, host_transaction_id_
);
579 DCHECK_EQ(kNoDatabase
, ipc_database_id_
);
580 DCHECK_EQ(kNoDatabaseCallbacks
, ipc_database_callbacks_id_
);
581 DCHECK_EQ(blink::WebIDBDataLossNone
, data_loss_
);
583 dispatcher_host_
->Send(new IndexedDBMsg_CallbacksSuccessUndefined(
584 ipc_thread_id_
, ipc_callbacks_id_
));
585 dispatcher_host_
= NULL
;
588 void IndexedDBCallbacks::SetConnectionOpenStartTime(
589 const base::TimeTicks
& start_time
) {
590 connection_open_start_time_
= start_time
;
593 } // namespace content