Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(425)

Side by Side Diff: Source/modules/indexeddb/IDBRequest.cpp

Issue 18590006: Blob support for IDB [Blink] (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Merge fixes [builds, untested] Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 { 195 {
196 if (!m_result) 196 if (!m_result)
197 return 0; 197 return 0;
198 if (m_result->type() == IDBAny::IDBCursorType) 198 if (m_result->type() == IDBAny::IDBCursorType)
199 return m_result->idbCursor(); 199 return m_result->idbCursor();
200 if (m_result->type() == IDBAny::IDBCursorWithValueType) 200 if (m_result->type() == IDBAny::IDBCursorWithValueType)
201 return m_result->idbCursorWithValue(); 201 return m_result->idbCursorWithValue();
202 return 0; 202 return 0;
203 } 203 }
204 204
205 void IDBRequest::setResultCursor(PassRefPtr<IDBCursor> cursor, PassRefPtr<IDBKey > key, PassRefPtr<IDBKey> primaryKey, PassRefPtr<SharedBuffer> value) 205 void IDBRequest::setResultCursor(PassRefPtr<IDBCursor> cursor, PassRefPtr<IDBKey > key, PassRefPtr<IDBKey> primaryKey, PassRefPtr<SharedBuffer> value, const Vect or<BlobInfo>& blobInfo)
206 { 206 {
207 ASSERT(m_readyState == PENDING); 207 ASSERT(m_readyState == PENDING);
208 m_cursorKey = key; 208 m_cursorKey = key;
209 m_cursorPrimaryKey = primaryKey; 209 m_cursorPrimaryKey = primaryKey;
210 m_cursorValue = value; 210 m_cursorValue = value;
211 m_cursorBlobInfo = blobInfo; // TODO(ericu): Swap?
211 212
212 if (m_cursorType == IndexedDB::CursorKeyOnly) { 213 if (m_cursorType == IndexedDB::CursorKeyOnly) {
213 m_result = IDBAny::create(cursor); 214 m_result = IDBAny::create(cursor);
214 return; 215 return;
215 } 216 }
216 217
217 m_result = IDBAny::create(IDBCursorWithValue::fromCursor(cursor)); 218 m_result = IDBAny::create(IDBCursorWithValue::fromCursor(cursor));
218 } 219 }
219 220
220 void IDBRequest::checkForReferenceCycle() 221 void IDBRequest::checkForReferenceCycle()
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 if (!shouldEnqueueEvent()) 266 if (!shouldEnqueueEvent())
266 return; 267 return;
267 268
268 RefPtr<DOMStringList> domStringList = DOMStringList::create(); 269 RefPtr<DOMStringList> domStringList = DOMStringList::create();
269 for (size_t i = 0; i < stringList.size(); ++i) 270 for (size_t i = 0; i < stringList.size(); ++i)
270 domStringList->append(stringList[i]); 271 domStringList->append(stringList[i]);
271 m_result = IDBAny::create(domStringList.release()); 272 m_result = IDBAny::create(domStringList.release());
272 enqueueEvent(createSuccessEvent()); 273 enqueueEvent(createSuccessEvent());
273 } 274 }
274 275
275 void IDBRequest::onSuccess(PassRefPtr<IDBCursorBackendInterface> backend, PassRe fPtr<IDBKey> key, PassRefPtr<IDBKey> primaryKey, PassRefPtr<SharedBuffer> value) 276 void IDBRequest::onSuccess(PassRefPtr<IDBCursorBackendInterface> backend, PassRe fPtr<IDBKey> key, PassRefPtr<IDBKey> primaryKey, PassRefPtr<SharedBuffer> value, const Vector<BlobInfo>& blobInfo)
276 { 277 {
277 IDB_TRACE("IDBRequest::onSuccess(IDBCursor)"); 278 IDB_TRACE("IDBRequest::onSuccess(IDBCursor)");
278 if (!shouldEnqueueEvent()) 279 if (!shouldEnqueueEvent())
279 return; 280 return;
280 281
281 ASSERT(!m_pendingCursor); 282 ASSERT(!m_pendingCursor);
282 RefPtr<IDBCursor> cursor; 283 RefPtr<IDBCursor> cursor;
283 switch (m_cursorType) { 284 switch (m_cursorType) {
284 case IndexedDB::CursorKeyOnly: 285 case IndexedDB::CursorKeyOnly:
285 cursor = IDBCursor::create(backend, m_cursorDirection, this, m_source.ge t(), m_transaction.get()); 286 cursor = IDBCursor::create(backend, m_cursorDirection, this, m_source.ge t(), m_transaction.get());
286 break; 287 break;
287 case IndexedDB::CursorKeyAndValue: 288 case IndexedDB::CursorKeyAndValue:
288 cursor = IDBCursorWithValue::create(backend, m_cursorDirection, this, m_ source.get(), m_transaction.get()); 289 cursor = IDBCursorWithValue::create(backend, m_cursorDirection, this, m_ source.get(), m_transaction.get());
289 break; 290 break;
290 default: 291 default:
291 ASSERT_NOT_REACHED(); 292 ASSERT_NOT_REACHED();
292 } 293 }
293 setResultCursor(cursor, key, primaryKey, value); 294 setResultCursor(cursor, key, primaryKey, value, blobInfo);
294 295
295 enqueueEvent(createSuccessEvent()); 296 enqueueEvent(createSuccessEvent());
296 } 297 }
297 298
298 void IDBRequest::onSuccess(PassRefPtr<IDBKey> idbKey) 299 void IDBRequest::onSuccess(PassRefPtr<IDBKey> idbKey)
299 { 300 {
300 IDB_TRACE("IDBRequest::onSuccess(IDBKey)"); 301 IDB_TRACE("IDBRequest::onSuccess(IDBKey)");
301 if (!shouldEnqueueEvent()) 302 if (!shouldEnqueueEvent())
302 return; 303 return;
303 304
304 if (idbKey && idbKey->isValid()) { 305 if (idbKey && idbKey->isValid()) {
305 DOMRequestState::Scope scope(m_requestState); 306 DOMRequestState::Scope scope(m_requestState);
306 m_result = IDBAny::create(idbKeyToScriptValue(requestState(), idbKey)); 307 m_result = IDBAny::create(idbKeyToScriptValue(requestState(), idbKey));
307 } else 308 } else
308 m_result = IDBAny::createInvalid(); 309 m_result = IDBAny::createInvalid();
309 enqueueEvent(createSuccessEvent()); 310 enqueueEvent(createSuccessEvent());
310 } 311 }
311 312
312 void IDBRequest::onSuccess(PassRefPtr<SharedBuffer> valueBuffer) 313 void IDBRequest::onSuccess(PassRefPtr<SharedBuffer> valueBuffer, const Vector<Bl obInfo>& blobInfo)
313 { 314 {
314 IDB_TRACE("IDBRequest::onSuccess(SharedBuffer)"); 315 IDB_TRACE("IDBRequest::onSuccess(SharedBuffer)");
315 if (!shouldEnqueueEvent()) 316 if (!shouldEnqueueEvent())
316 return; 317 return;
317 318
318 if (m_pendingCursor) { 319 if (m_pendingCursor) {
319 m_pendingCursor->close(); 320 m_pendingCursor->close();
320 m_pendingCursor.clear(); 321 m_pendingCursor.clear();
321 } 322 }
322 323
323 DOMRequestState::Scope scope(m_requestState); 324 DOMRequestState::Scope scope(m_requestState);
324 ScriptValue value = deserializeIDBValueBuffer(requestState(), valueBuffer); 325 ScriptValue value = deserializeIDBValueBuffer(requestState(), valueBuffer, & blobInfo);
325 onSuccessInternal(value); 326 onSuccessInternal(value);
326 } 327 }
327 328
328 #ifndef NDEBUG 329 #ifndef NDEBUG
329 static PassRefPtr<IDBObjectStore> effectiveObjectStore(PassRefPtr<IDBAny> source ) 330 static PassRefPtr<IDBObjectStore> effectiveObjectStore(PassRefPtr<IDBAny> source )
330 { 331 {
331 if (source->type() == IDBAny::IDBObjectStoreType) 332 if (source->type() == IDBAny::IDBObjectStoreType)
332 return source->idbObjectStore(); 333 return source->idbObjectStore();
333 if (source->type() == IDBAny::IDBIndexType) 334 if (source->type() == IDBAny::IDBIndexType)
334 return source->idbIndex()->objectStore(); 335 return source->idbIndex()->objectStore();
335 336
336 ASSERT_NOT_REACHED(); 337 ASSERT_NOT_REACHED();
337 return 0; 338 return 0;
338 } 339 }
339 #endif 340 #endif
340 341
341 void IDBRequest::onSuccess(PassRefPtr<SharedBuffer> valueBuffer, PassRefPtr<IDBK ey> prpPrimaryKey, const IDBKeyPath& keyPath) 342 void IDBRequest::onSuccess(PassRefPtr<SharedBuffer> valueBuffer, const Vector<Bl obInfo>& blobInfo, PassRefPtr<IDBKey> prpPrimaryKey, const IDBKeyPath& keyPath)
342 { 343 {
343 IDB_TRACE("IDBRequest::onSuccess(SharedBuffer, IDBKey, IDBKeyPath)"); 344 IDB_TRACE("IDBRequest::onSuccess(SharedBuffer, IDBKey, IDBKeyPath)");
344 if (!shouldEnqueueEvent()) 345 if (!shouldEnqueueEvent())
345 return; 346 return;
346 347
347 #ifndef NDEBUG 348 #ifndef NDEBUG
348 ASSERT(keyPath == effectiveObjectStore(m_source)->keyPath()); 349 ASSERT(keyPath == effectiveObjectStore(m_source)->keyPath());
349 #endif 350 #endif
350 DOMRequestState::Scope scope(m_requestState); 351 DOMRequestState::Scope scope(m_requestState);
351 ScriptValue value = deserializeIDBValueBuffer(requestState(), valueBuffer); 352 ScriptValue value = deserializeIDBValueBuffer(requestState(), valueBuffer, & blobInfo);
352 353
353 RefPtr<IDBKey> primaryKey = prpPrimaryKey; 354 RefPtr<IDBKey> primaryKey = prpPrimaryKey;
354 #ifndef NDEBUG 355 #ifndef NDEBUG
355 RefPtr<IDBKey> expectedKey = createIDBKeyFromScriptValueAndKeyPath(requestSt ate(), value, keyPath); 356 RefPtr<IDBKey> expectedKey = createIDBKeyFromScriptValueAndKeyPath(requestSt ate(), value, keyPath);
356 ASSERT(!expectedKey || expectedKey->isEqual(primaryKey.get())); 357 ASSERT(!expectedKey || expectedKey->isEqual(primaryKey.get()));
357 #endif 358 #endif
358 bool injected = injectIDBKeyIntoScriptValue(requestState(), primaryKey, valu e, keyPath); 359 bool injected = injectIDBKeyIntoScriptValue(requestState(), primaryKey, valu e, keyPath);
359 ASSERT_UNUSED(injected, injected); 360 ASSERT_UNUSED(injected, injected);
360 onSuccessInternal(value); 361 onSuccessInternal(value);
361 } 362 }
(...skipping 21 matching lines...) Expand all
383 return onSuccessInternal(deserializeIDBValue(requestState(), value)); 384 return onSuccessInternal(deserializeIDBValue(requestState(), value));
384 } 385 }
385 386
386 void IDBRequest::onSuccessInternal(const ScriptValue& value) 387 void IDBRequest::onSuccessInternal(const ScriptValue& value)
387 { 388 {
388 m_result = IDBAny::create(value); 389 m_result = IDBAny::create(value);
389 ASSERT(!m_pendingCursor); 390 ASSERT(!m_pendingCursor);
390 enqueueEvent(createSuccessEvent()); 391 enqueueEvent(createSuccessEvent());
391 } 392 }
392 393
393 void IDBRequest::onSuccess(PassRefPtr<IDBKey> key, PassRefPtr<IDBKey> primaryKey , PassRefPtr<SharedBuffer> value) 394 void IDBRequest::onSuccess(PassRefPtr<IDBKey> key, PassRefPtr<IDBKey> primaryKey , PassRefPtr<SharedBuffer> value, const Vector<BlobInfo>& blobInfo)
394 { 395 {
395 IDB_TRACE("IDBRequest::onSuccess(key, primaryKey, value)"); 396 IDB_TRACE("IDBRequest::onSuccess(key, primaryKey, value)");
396 if (!shouldEnqueueEvent()) 397 if (!shouldEnqueueEvent())
397 return; 398 return;
398 399
399 ASSERT(m_pendingCursor); 400 ASSERT(m_pendingCursor);
400 setResultCursor(m_pendingCursor.release(), key, primaryKey, value); 401 setResultCursor(m_pendingCursor.release(), key, primaryKey, value, blobInfo) ;
401 enqueueEvent(createSuccessEvent()); 402 enqueueEvent(createSuccessEvent());
402 } 403 }
403 404
404 bool IDBRequest::hasPendingActivity() const 405 bool IDBRequest::hasPendingActivity() const
405 { 406 {
406 // FIXME: In an ideal world, we should return true as long as anyone has a o r can 407 // FIXME: In an ideal world, we should return true as long as anyone has a o r can
407 // get a handle to us and we have event listeners. This is order to h andle 408 // get a handle to us and we have event listeners. This is order to h andle
408 // user generated events properly. 409 // user generated events properly.
409 return m_hasPendingActivity && !m_contextStopped; 410 return m_hasPendingActivity && !m_contextStopped;
410 } 411 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 // this object to actually hold a reference to the database (to ensure 461 // this object to actually hold a reference to the database (to ensure
461 // it stays alive). 462 // it stays alive).
462 targets.append(m_transaction->db()); 463 targets.append(m_transaction->db());
463 } 464 }
464 465
465 // Cursor properties should not updated until the success event is being dis patched. 466 // Cursor properties should not updated until the success event is being dis patched.
466 RefPtr<IDBCursor> cursorToNotify; 467 RefPtr<IDBCursor> cursorToNotify;
467 if (event->type() == eventNames().successEvent) { 468 if (event->type() == eventNames().successEvent) {
468 cursorToNotify = getResultCursor(); 469 cursorToNotify = getResultCursor();
469 if (cursorToNotify) 470 if (cursorToNotify)
470 cursorToNotify->setValueReady(m_cursorKey.release(), m_cursorPrimary Key.release(), m_cursorValue.release()); 471 cursorToNotify->setValueReady(m_cursorKey.release(), m_cursorPrimary Key.release(), m_cursorValue.release(), m_cursorBlobInfo);
471 } 472 }
472 473
473 if (event->type() == eventNames().upgradeneededEvent) { 474 if (event->type() == eventNames().upgradeneededEvent) {
474 ASSERT(!m_didFireUpgradeNeededEvent); 475 ASSERT(!m_didFireUpgradeNeededEvent);
475 m_didFireUpgradeNeededEvent = true; 476 m_didFireUpgradeNeededEvent = true;
476 } 477 }
477 478
478 // FIXME: When we allow custom event dispatching, this will probably need to change. 479 // FIXME: When we allow custom event dispatching, this will probably need to change.
479 ASSERT_WITH_MESSAGE(event->type() == eventNames().successEvent || event->typ e() == eventNames().errorEvent || event->type() == eventNames().blockedEvent || event->type() == eventNames().upgradeneededEvent, "event type was %s", event->ty pe().string().utf8().data()); 480 ASSERT_WITH_MESSAGE(event->type() == eventNames().successEvent || event->typ e() == eventNames().errorEvent || event->type() == eventNames().blockedEvent || event->type() == eventNames().upgradeneededEvent, "event type was %s", event->ty pe().string().utf8().data());
480 const bool setTransactionActive = m_transaction && (event->type() == eventNa mes().successEvent || event->type() == eventNames().upgradeneededEvent || (event ->type() == eventNames().errorEvent && !m_requestAborted)); 481 const bool setTransactionActive = m_transaction && (event->type() == eventNa mes().successEvent || event->type() == eventNames().upgradeneededEvent || (event ->type() == eventNames().errorEvent && !m_requestAborted));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 { 548 {
548 return &m_eventTargetData; 549 return &m_eventTargetData;
549 } 550 }
550 551
551 EventTargetData* IDBRequest::ensureEventTargetData() 552 EventTargetData* IDBRequest::ensureEventTargetData()
552 { 553 {
553 return &m_eventTargetData; 554 return &m_eventTargetData;
554 } 555 }
555 556
556 } // namespace WebCore 557 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698