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

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

Issue 18590006: Blob support for IDB [Blink] (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: small cleanup Created 7 years 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 23 matching lines...) Expand all
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/IDBKey.h" 37 #include "modules/indexeddb/IDBKey.h"
38 #include "modules/indexeddb/IDBObjectStore.h" 38 #include "modules/indexeddb/IDBObjectStore.h"
39 #include "modules/indexeddb/IDBRequest.h" 39 #include "modules/indexeddb/IDBRequest.h"
40 #include "modules/indexeddb/IDBTracing.h" 40 #include "modules/indexeddb/IDBTracing.h"
41 #include "modules/indexeddb/IDBTransaction.h" 41 #include "modules/indexeddb/IDBTransaction.h"
42 #include "modules/indexeddb/WebIDBCallbacksImpl.h" 42 #include "modules/indexeddb/WebIDBCallbacksImpl.h"
43 #include "platform/SharedBuffer.h" 43 #include "platform/SharedBuffer.h"
44 #include "platform/SharedBuffer.h" 44 #include "platform/blob/BlobInfo.h"
45 #include "public/platform/WebIDBCursor.h" 45 #include "public/platform/WebIDBCursor.h"
46 #include "public/platform/WebIDBDatabase.h" 46 #include "public/platform/WebIDBDatabase.h"
47 #include "public/platform/WebIDBKeyRange.h" 47 #include "public/platform/WebIDBKeyRange.h"
48 #include <limits> 48 #include <limits>
49 49
50 using blink::WebIDBDatabase; 50 using blink::WebIDBDatabase;
51 51
52 namespace WebCore { 52 namespace WebCore {
53 53
54 PassRefPtr<IDBCursor> IDBCursor::create(PassOwnPtr<blink::WebIDBCursor> backend, IndexedDB::CursorDirection direction, IDBRequest* request, IDBAny* source, IDBT ransaction* transaction) 54 PassRefPtr<IDBCursor> IDBCursor::create(PassOwnPtr<blink::WebIDBCursor> backend, IndexedDB::CursorDirection direction, IDBRequest* request, IDBAny* source, IDBT ransaction* transaction)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 { 94 {
95 ASSERT(m_backend); 95 ASSERT(m_backend);
96 ASSERT(m_request); 96 ASSERT(m_request);
97 ASSERT(m_source->type() == IDBAny::IDBObjectStoreType || m_source->type() == IDBAny::IDBIndexType); 97 ASSERT(m_source->type() == IDBAny::IDBObjectStoreType || m_source->type() == IDBAny::IDBIndexType);
98 ASSERT(m_transaction); 98 ASSERT(m_transaction);
99 ScriptWrappable::init(this); 99 ScriptWrappable::init(this);
100 } 100 }
101 101
102 IDBCursor::~IDBCursor() 102 IDBCursor::~IDBCursor()
103 { 103 {
104 handleBlobAcks();
104 } 105 }
105 106
106 PassRefPtr<IDBRequest> IDBCursor::update(ScriptState* state, ScriptValue& value, ExceptionState& exceptionState) 107 PassRefPtr<IDBRequest> IDBCursor::update(ScriptState* state, ScriptValue& value, ExceptionState& exceptionState)
107 { 108 {
108 IDB_TRACE("IDBCursor::update"); 109 IDB_TRACE("IDBCursor::update");
109 110
110 if (!m_gotValue) { 111 if (!m_gotValue) {
111 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f ailedToExecute("update", "IDBCursor", IDBDatabase::noValueErrorMessage)); 112 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f ailedToExecute("update", "IDBCursor", IDBDatabase::noValueErrorMessage));
112 return 0; 113 return 0;
113 } 114 }
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 314
314 ScriptValue IDBCursor::value(ExecutionContext* context) 315 ScriptValue IDBCursor::value(ExecutionContext* context)
315 { 316 {
316 ASSERT(isCursorWithValue()); 317 ASSERT(isCursorWithValue());
317 318
318 DOMRequestState requestState(context); 319 DOMRequestState requestState(context);
319 RefPtr<IDBObjectStore> objectStore = effectiveObjectStore(); 320 RefPtr<IDBObjectStore> objectStore = effectiveObjectStore();
320 const IDBObjectStoreMetadata& metadata = objectStore->metadata(); 321 const IDBObjectStoreMetadata& metadata = objectStore->metadata();
321 RefPtr<IDBAny> value; 322 RefPtr<IDBAny> value;
322 if (metadata.autoIncrement && !metadata.keyPath.isNull()) { 323 if (metadata.autoIncrement && !metadata.keyPath.isNull()) {
323 value = IDBAny::create(m_value, m_primaryKey, metadata.keyPath); 324 value = IDBAny::create(m_value, m_blobInfo.get(), m_primaryKey, metadata .keyPath);
324 #ifndef NDEBUG 325 #ifndef NDEBUG
325 assertPrimaryKeyValidOrInjectable(&requestState, m_value, m_primaryKey, metadata.keyPath); 326 assertPrimaryKeyValidOrInjectable(&requestState, m_value, m_blobInfo.get (), m_primaryKey, metadata.keyPath);
326 #endif 327 #endif
327 } else { 328 } else {
328 value = IDBAny::create(m_value); 329 value = IDBAny::create(m_value, m_blobInfo.get());
329 } 330 }
330 331
331 m_valueDirty = false; 332 m_valueDirty = false;
332 return idbAnyToScriptValue(&requestState, value); 333 ScriptValue scriptValue = idbAnyToScriptValue(&requestState, value);
334 handleBlobAcks();
335 return scriptValue;
333 } 336 }
334 337
335 void IDBCursor::setValueReady(PassRefPtr<IDBKey> key, PassRefPtr<IDBKey> primary Key, PassRefPtr<SharedBuffer> value) 338 void IDBCursor::setValueReady(PassRefPtr<IDBKey> key, PassRefPtr<IDBKey> primary Key, PassRefPtr<SharedBuffer> value, PassOwnPtr<Vector<BlobInfo> > blobInfo)
336 { 339 {
337 m_key = key; 340 m_key = key;
338 m_keyDirty = true; 341 m_keyDirty = true;
339 342
340 m_primaryKey = primaryKey; 343 m_primaryKey = primaryKey;
341 m_primaryKeyDirty = true; 344 m_primaryKeyDirty = true;
342 345
343 if (isCursorWithValue()) { 346 if (isCursorWithValue()) {
344 m_value = value; 347 m_value = value;
348 m_blobInfo = blobInfo;
345 m_valueDirty = true; 349 m_valueDirty = true;
346 } 350 }
347 351
348 m_gotValue = true; 352 m_gotValue = true;
349 } 353 }
350 354
351 PassRefPtr<IDBObjectStore> IDBCursor::effectiveObjectStore() 355 PassRefPtr<IDBObjectStore> IDBCursor::effectiveObjectStore()
352 { 356 {
353 if (m_source->type() == IDBAny::IDBObjectStoreType) 357 if (m_source->type() == IDBAny::IDBObjectStoreType)
354 return m_source->idbObjectStore(); 358 return m_source->idbObjectStore();
355 RefPtr<IDBIndex> index = m_source->idbIndex(); 359 RefPtr<IDBIndex> index = m_source->idbIndex();
356 return index->objectStore(); 360 return index->objectStore();
357 } 361 }
358 362
359 bool IDBCursor::isDeleted() const 363 bool IDBCursor::isDeleted() const
360 { 364 {
361 if (m_source->type() == IDBAny::IDBObjectStoreType) 365 if (m_source->type() == IDBAny::IDBObjectStoreType)
362 return m_source->idbObjectStore()->isDeleted(); 366 return m_source->idbObjectStore()->isDeleted();
363 return m_source->idbIndex()->isDeleted(); 367 return m_source->idbIndex()->isDeleted();
364 } 368 }
365 369
370 void IDBCursor::handleBlobAcks()
371 {
372 if (m_blobInfo.get() && m_blobInfo->size()) {
373 m_request->ackReceivedBlobs(m_blobInfo.get());
374 m_blobInfo.clear();
375 }
376 }
377
366 IndexedDB::CursorDirection IDBCursor::stringToDirection(const String& directionS tring, ExceptionState& exceptionState) 378 IndexedDB::CursorDirection IDBCursor::stringToDirection(const String& directionS tring, ExceptionState& exceptionState)
367 { 379 {
368 if (directionString.isNull() || directionString == IDBCursor::directionNext( )) 380 if (directionString.isNull() || directionString == IDBCursor::directionNext( ))
369 return IndexedDB::CursorNext; 381 return IndexedDB::CursorNext;
370 if (directionString == IDBCursor::directionNextUnique()) 382 if (directionString == IDBCursor::directionNextUnique())
371 return IndexedDB::CursorNextNoDuplicate; 383 return IndexedDB::CursorNextNoDuplicate;
372 if (directionString == IDBCursor::directionPrev()) 384 if (directionString == IDBCursor::directionPrev())
373 return IndexedDB::CursorPrev; 385 return IndexedDB::CursorPrev;
374 if (directionString == IDBCursor::directionPrevUnique()) 386 if (directionString == IDBCursor::directionPrevUnique())
375 return IndexedDB::CursorPrevNoDuplicate; 387 return IndexedDB::CursorPrevNoDuplicate;
(...skipping 17 matching lines...) Expand all
393 case IndexedDB::CursorPrevNoDuplicate: 405 case IndexedDB::CursorPrevNoDuplicate:
394 return IDBCursor::directionPrevUnique(); 406 return IDBCursor::directionPrevUnique();
395 407
396 default: 408 default:
397 ASSERT_NOT_REACHED(); 409 ASSERT_NOT_REACHED();
398 return IDBCursor::directionNext(); 410 return IDBCursor::directionNext();
399 } 411 }
400 } 412 }
401 413
402 } // namespace WebCore 414 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698