| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/indexeddb/IDBObserver.h" | 5 #include "modules/indexeddb/IDBObserver.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 8 #include "bindings/modules/v8/ToV8ForModules.h" | 9 #include "bindings/modules/v8/ToV8ForModules.h" |
| 9 #include "bindings/modules/v8/V8BindingForModules.h" | 10 #include "bindings/modules/v8/V8BindingForModules.h" |
| 11 #include "core/dom/ExceptionCode.h" |
| 12 #include "modules/indexeddb/IDBDatabase.h" |
| 10 #include "modules/indexeddb/IDBObserverCallback.h" | 13 #include "modules/indexeddb/IDBObserverCallback.h" |
| 11 #include "modules/indexeddb/IDBObserverInit.h" | 14 #include "modules/indexeddb/IDBObserverInit.h" |
| 12 | 15 |
| 13 namespace blink { | 16 namespace blink { |
| 14 | 17 |
| 15 IDBObserver* IDBObserver::create(IDBObserverCallback& callback, const IDBObserve
rInit& options) | 18 IDBObserver* IDBObserver::create(IDBObserverCallback& callback, const IDBObserve
rInit& options) |
| 16 { | 19 { |
| 17 return new IDBObserver(callback, options); | 20 return new IDBObserver(callback, options); |
| 18 } | 21 } |
| 19 | 22 |
| 20 IDBObserver::IDBObserver(IDBObserverCallback& callback, const IDBObserverInit& o
ptions) | 23 IDBObserver::IDBObserver(IDBObserverCallback& callback, const IDBObserverInit& o
ptions) |
| 21 : m_callback(&callback) | 24 : m_callback(&callback) |
| 22 , m_transaction(options.transaction()) | 25 , m_transaction(options.transaction()) |
| 23 , m_values(options.values()) | 26 , m_values(options.values()) |
| 24 , m_noRecords(options.noRecords()) | 27 , m_noRecords(options.noRecords()) |
| 25 { | 28 { |
| 26 } | 29 } |
| 27 | 30 |
| 28 IDBObserver::~IDBObserver() {} | 31 IDBObserver::~IDBObserver() {} |
| 29 | 32 |
| 30 void IDBObserver::observe(IDBDatabase* database, IDBTransaction* transaction, Ex
ceptionState& exceptionState) | 33 void IDBObserver::observe(IDBDatabase* database, IDBTransaction* transaction, Ex
ceptionState& exceptionState) |
| 31 { | 34 { |
| 32 // TODO(palakj): Finish implementation. | 35 if (transaction->isFinished() || transaction->isFinishing()) { |
| 36 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 37 return; |
| 38 } |
| 39 if (!transaction->isActive()) { |
| 40 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 41 return; |
| 42 } |
| 43 if (!database->backend()) { |
| 44 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 45 return; |
| 46 } |
| 47 database->backend()->observe(this, transaction->id()); |
| 48 } |
| 49 |
| 50 void IDBObserver::unobserve(IDBDatabase* database, ExceptionState& exceptionStat
e) |
| 51 { |
| 52 if (!database->backend()) { |
| 53 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 54 return; |
| 55 } |
| 56 database->backend()->unobserve(this); |
| 33 } | 57 } |
| 34 | 58 |
| 35 DEFINE_TRACE(IDBObserver) | 59 DEFINE_TRACE(IDBObserver) |
| 36 { | 60 { |
| 37 visitor->trace(m_callback); | 61 visitor->trace(m_callback); |
| 38 } | 62 } |
| 39 | 63 |
| 40 } // namespace blink | 64 } // namespace blink |
| OLD | NEW |