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

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

Issue 235933013: Add the backchannel for Blobs to be received into Blink from the database backend. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rolled in feedback Created 6 years, 8 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
« no previous file with comments | « Source/modules/indexeddb/IDBCursor.h ('k') | Source/modules/indexeddb/IDBDatabase.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 20 matching lines...) Expand all
31 #include "bindings/v8/NewScriptState.h" 31 #include "bindings/v8/NewScriptState.h"
32 #include "core/dom/ExceptionCode.h" 32 #include "core/dom/ExceptionCode.h"
33 #include "core/dom/ExecutionContext.h" 33 #include "core/dom/ExecutionContext.h"
34 #include "core/inspector/ScriptCallStack.h" 34 #include "core/inspector/ScriptCallStack.h"
35 #include "modules/indexeddb/IDBAny.h" 35 #include "modules/indexeddb/IDBAny.h"
36 #include "modules/indexeddb/IDBDatabase.h" 36 #include "modules/indexeddb/IDBDatabase.h"
37 #include "modules/indexeddb/IDBObjectStore.h" 37 #include "modules/indexeddb/IDBObjectStore.h"
38 #include "modules/indexeddb/IDBTracing.h" 38 #include "modules/indexeddb/IDBTracing.h"
39 #include "modules/indexeddb/IDBTransaction.h" 39 #include "modules/indexeddb/IDBTransaction.h"
40 #include "modules/indexeddb/WebIDBCallbacksImpl.h" 40 #include "modules/indexeddb/WebIDBCallbacksImpl.h"
41 #include "public/platform/WebBlobInfo.h"
41 #include "public/platform/WebIDBDatabase.h" 42 #include "public/platform/WebIDBDatabase.h"
42 #include "public/platform/WebIDBKeyRange.h" 43 #include "public/platform/WebIDBKeyRange.h"
43 #include <limits> 44 #include <limits>
44 45
45 using blink::WebIDBCursor; 46 using blink::WebIDBCursor;
46 using blink::WebIDBDatabase; 47 using blink::WebIDBDatabase;
47 48
48 namespace WebCore { 49 namespace WebCore {
49 50
50 PassRefPtr<IDBCursor> IDBCursor::create(PassOwnPtr<blink::WebIDBCursor> backend, WebIDBCursor::Direction direction, IDBRequest* request, IDBAny* source, IDBTran saction* transaction) 51 PassRefPtr<IDBCursor> IDBCursor::create(PassOwnPtr<blink::WebIDBCursor> backend, WebIDBCursor::Direction direction, IDBRequest* request, IDBAny* source, IDBTran saction* transaction)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 { 90 {
90 ASSERT(m_backend); 91 ASSERT(m_backend);
91 ASSERT(m_request); 92 ASSERT(m_request);
92 ASSERT(m_source->type() == IDBAny::IDBObjectStoreType || m_source->type() == IDBAny::IDBIndexType); 93 ASSERT(m_source->type() == IDBAny::IDBObjectStoreType || m_source->type() == IDBAny::IDBIndexType);
93 ASSERT(m_transaction); 94 ASSERT(m_transaction);
94 ScriptWrappable::init(this); 95 ScriptWrappable::init(this);
95 } 96 }
96 97
97 IDBCursor::~IDBCursor() 98 IDBCursor::~IDBCursor()
98 { 99 {
100 handleBlobAcks();
99 } 101 }
100 102
101 PassRefPtr<IDBRequest> IDBCursor::update(ExecutionContext* executionContext, Scr iptValue& value, ExceptionState& exceptionState) 103 PassRefPtr<IDBRequest> IDBCursor::update(ExecutionContext* executionContext, Scr iptValue& value, ExceptionState& exceptionState)
102 { 104 {
103 IDB_TRACE("IDBCursor::update"); 105 IDB_TRACE("IDBCursor::update");
104 106
105 if (!m_gotValue) { 107 if (!m_gotValue) {
106 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValue ErrorMessage); 108 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValue ErrorMessage);
107 return nullptr; 109 return nullptr;
108 } 110 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 void IDBCursor::postSuccessHandlerCallback() 286 void IDBCursor::postSuccessHandlerCallback()
285 { 287 {
286 if (m_backend) 288 if (m_backend)
287 m_backend->postSuccessHandlerCallback(); 289 m_backend->postSuccessHandlerCallback();
288 } 290 }
289 291
290 void IDBCursor::close() 292 void IDBCursor::close()
291 { 293 {
292 // The notifier may be the last reference to this cursor. 294 // The notifier may be the last reference to this cursor.
293 RefPtr<IDBCursor> protect(this); 295 RefPtr<IDBCursor> protect(this);
296 handleBlobAcks();
294 m_request.clear(); 297 m_request.clear();
295 m_backend.clear(); 298 m_backend.clear();
296 } 299 }
297 300
298 void IDBCursor::checkForReferenceCycle() 301 void IDBCursor::checkForReferenceCycle()
299 { 302 {
300 // If this cursor and its request have the only references 303 // If this cursor and its request have the only references
301 // to each other, then explicitly break the cycle. 304 // to each other, then explicitly break the cycle.
302 if (!m_request || m_request->getResultCursor() != this) 305 if (!m_request || m_request->getResultCursor() != this)
303 return; 306 return;
304 307
305 if (!hasOneRef() || !m_request->hasOneRef()) 308 if (!hasOneRef() || !m_request->hasOneRef())
306 return; 309 return;
307 310
311 handleBlobAcks();
308 m_request.clear(); 312 m_request.clear();
309 } 313 }
310 314
311 ScriptValue IDBCursor::key(NewScriptState* scriptState) 315 ScriptValue IDBCursor::key(NewScriptState* scriptState)
312 { 316 {
313 m_keyDirty = false; 317 m_keyDirty = false;
314 return idbKeyToScriptValue(scriptState, m_key); 318 return idbKeyToScriptValue(scriptState, m_key);
315 } 319 }
316 320
317 ScriptValue IDBCursor::primaryKey(NewScriptState* scriptState) 321 ScriptValue IDBCursor::primaryKey(NewScriptState* scriptState)
318 { 322 {
319 m_primaryKeyDirty = false; 323 m_primaryKeyDirty = false;
320 return idbKeyToScriptValue(scriptState, m_primaryKey); 324 return idbKeyToScriptValue(scriptState, m_primaryKey);
321 } 325 }
322 326
323 ScriptValue IDBCursor::value(NewScriptState* scriptState) 327 ScriptValue IDBCursor::value(NewScriptState* scriptState)
324 { 328 {
325 ASSERT(isCursorWithValue()); 329 ASSERT(isCursorWithValue());
326 330
327 RefPtr<IDBObjectStore> objectStore = effectiveObjectStore(); 331 RefPtr<IDBObjectStore> objectStore = effectiveObjectStore();
328 const IDBObjectStoreMetadata& metadata = objectStore->metadata(); 332 const IDBObjectStoreMetadata& metadata = objectStore->metadata();
329 RefPtr<IDBAny> value; 333 RefPtr<IDBAny> value;
330 if (metadata.autoIncrement && !metadata.keyPath.isNull()) { 334 if (metadata.autoIncrement && !metadata.keyPath.isNull()) {
331 value = IDBAny::create(m_value, m_primaryKey, metadata.keyPath); 335 value = IDBAny::create(m_value, m_blobInfo.get(), m_primaryKey, metadata .keyPath);
332 #ifndef NDEBUG 336 #ifndef NDEBUG
333 assertPrimaryKeyValidOrInjectable(scriptState, m_value, m_primaryKey, me tadata.keyPath); 337 assertPrimaryKeyValidOrInjectable(scriptState, m_value, m_blobInfo.get() , m_primaryKey, metadata.keyPath);
334 #endif 338 #endif
335 } else { 339 } else {
336 value = IDBAny::create(m_value); 340 value = IDBAny::create(m_value, m_blobInfo.get());
337 } 341 }
338 342
339 m_valueDirty = false; 343 m_valueDirty = false;
340 return idbAnyToScriptValue(scriptState, value); 344 ScriptValue scriptValue = idbAnyToScriptValue(scriptState, value);
345 handleBlobAcks();
346 return scriptValue;
341 } 347 }
342 348
343 ScriptValue IDBCursor::source(NewScriptState* scriptState) const 349 ScriptValue IDBCursor::source(NewScriptState* scriptState) const
344 { 350 {
345 return idbAnyToScriptValue(scriptState, m_source); 351 return idbAnyToScriptValue(scriptState, m_source);
346 } 352 }
347 353
348 void IDBCursor::setValueReady(PassRefPtr<IDBKey> key, PassRefPtr<IDBKey> primary Key, PassRefPtr<SharedBuffer> value) 354 void IDBCursor::setValueReady(PassRefPtr<IDBKey> key, PassRefPtr<IDBKey> primary Key, PassRefPtr<SharedBuffer> value, PassOwnPtr<Vector<blink::WebBlobInfo> > blo bInfo)
349 { 355 {
350 m_key = key; 356 m_key = key;
351 m_keyDirty = true; 357 m_keyDirty = true;
352 358
353 m_primaryKey = primaryKey; 359 m_primaryKey = primaryKey;
354 m_primaryKeyDirty = true; 360 m_primaryKeyDirty = true;
355 361
356 if (isCursorWithValue()) { 362 if (isCursorWithValue()) {
357 m_value = value; 363 m_value = value;
364 m_blobInfo = blobInfo;
jsbell 2014/04/17 19:00:33 If `value` is never accessed, the blobs remain una
ericu 2014/04/17 19:30:14 Right, thanks; I've added a handleBlobAcks() call
jsbell 2014/04/17 20:19:28 Yeah. See comment on another review about propagat
358 m_valueDirty = true; 365 m_valueDirty = true;
359 } 366 }
360 367
361 m_gotValue = true; 368 m_gotValue = true;
362 } 369 }
363 370
364 PassRefPtr<IDBObjectStore> IDBCursor::effectiveObjectStore() const 371 PassRefPtr<IDBObjectStore> IDBCursor::effectiveObjectStore() const
365 { 372 {
366 if (m_source->type() == IDBAny::IDBObjectStoreType) 373 if (m_source->type() == IDBAny::IDBObjectStoreType)
367 return m_source->idbObjectStore(); 374 return m_source->idbObjectStore();
368 RefPtr<IDBIndex> index = m_source->idbIndex(); 375 RefPtr<IDBIndex> index = m_source->idbIndex();
369 return index->objectStore(); 376 return index->objectStore();
370 } 377 }
371 378
372 bool IDBCursor::isDeleted() const 379 bool IDBCursor::isDeleted() const
373 { 380 {
374 if (m_source->type() == IDBAny::IDBObjectStoreType) 381 if (m_source->type() == IDBAny::IDBObjectStoreType)
375 return m_source->idbObjectStore()->isDeleted(); 382 return m_source->idbObjectStore()->isDeleted();
376 return m_source->idbIndex()->isDeleted(); 383 return m_source->idbIndex()->isDeleted();
377 } 384 }
378 385
386 void IDBCursor::handleBlobAcks()
387 {
388 if (m_blobInfo.get() && m_blobInfo->size()) {
389 ASSERT(m_request);
jsbell 2014/04/17 19:00:33 Can we add a complementary ASSERT (outside the if)
ericu 2014/04/17 19:30:14 Done.
390 m_request->transaction()->db()->ackReceivedBlobs(m_blobInfo.get());
jsbell 2014/04/17 19:00:33 Can use m_transaction
ericu 2014/04/17 19:30:14 Done.
391 m_blobInfo.clear();
392 }
393 }
394
379 WebIDBCursor::Direction IDBCursor::stringToDirection(const String& directionStri ng, ExceptionState& exceptionState) 395 WebIDBCursor::Direction IDBCursor::stringToDirection(const String& directionStri ng, ExceptionState& exceptionState)
380 { 396 {
381 if (directionString.isNull() || directionString == IDBCursor::directionNext( )) 397 if (directionString.isNull() || directionString == IDBCursor::directionNext( ))
382 return WebIDBCursor::Next; 398 return WebIDBCursor::Next;
383 if (directionString == IDBCursor::directionNextUnique()) 399 if (directionString == IDBCursor::directionNextUnique())
384 return WebIDBCursor::NextNoDuplicate; 400 return WebIDBCursor::NextNoDuplicate;
385 if (directionString == IDBCursor::directionPrev()) 401 if (directionString == IDBCursor::directionPrev())
386 return WebIDBCursor::Prev; 402 return WebIDBCursor::Prev;
387 if (directionString == IDBCursor::directionPrevUnique()) 403 if (directionString == IDBCursor::directionPrevUnique())
388 return WebIDBCursor::PrevNoDuplicate; 404 return WebIDBCursor::PrevNoDuplicate;
(...skipping 17 matching lines...) Expand all
406 case WebIDBCursor::PrevNoDuplicate: 422 case WebIDBCursor::PrevNoDuplicate:
407 return IDBCursor::directionPrevUnique(); 423 return IDBCursor::directionPrevUnique();
408 424
409 default: 425 default:
410 ASSERT_NOT_REACHED(); 426 ASSERT_NOT_REACHED();
411 return IDBCursor::directionNext(); 427 return IDBCursor::directionNext();
412 } 428 }
413 } 429 }
414 430
415 } // namespace WebCore 431 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/indexeddb/IDBCursor.h ('k') | Source/modules/indexeddb/IDBDatabase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698