| 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" |
| 15 #include "modules/indexeddb/WebIDBObserverImpl.h" |
| 12 | 16 |
| 13 namespace blink { | 17 namespace blink { |
| 14 | 18 |
| 15 IDBObserver* IDBObserver::create(IDBObserverCallback& callback, const IDBObserve
rInit& options) | 19 IDBObserver* IDBObserver::create(IDBObserverCallback& callback, const IDBObserve
rInit& options) |
| 16 { | 20 { |
| 17 return new IDBObserver(callback, options); | 21 return new IDBObserver(callback, options); |
| 18 } | 22 } |
| 19 | 23 |
| 20 IDBObserver::IDBObserver(IDBObserverCallback& callback, const IDBObserverInit& o
ptions) | 24 IDBObserver::IDBObserver(IDBObserverCallback& callback, const IDBObserverInit& o
ptions) |
| 21 : m_callback(&callback) | 25 : m_callback(&callback) |
| 22 , m_transaction(options.transaction()) | 26 , m_transaction(options.transaction()) |
| 23 , m_values(options.values()) | 27 , m_values(options.values()) |
| 24 , m_noRecords(options.noRecords()) | 28 , m_noRecords(options.noRecords()) |
| 25 { | 29 { |
| 26 } | 30 } |
| 27 | 31 |
| 28 IDBObserver::~IDBObserver() {} | 32 IDBObserver::~IDBObserver() {} |
| 29 | 33 |
| 30 void IDBObserver::observe(IDBDatabase* database, IDBTransaction* transaction, Ex
ceptionState& exceptionState) | 34 void IDBObserver::observe(IDBDatabase* database, IDBTransaction* transaction, Ex
ceptionState& exceptionState) |
| 31 { | 35 { |
| 32 // TODO(palakj): Finish implementation. | 36 if (transaction->isFinished() || transaction->isFinishing()) { |
| 37 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 38 return; |
| 39 } |
| 40 if (!transaction->isActive()) { |
| 41 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 42 return; |
| 43 } |
| 44 if (!database->backend()) { |
| 45 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 46 return; |
| 47 } |
| 48 database->backend()->observe(WebIDBObserverImpl::create(this).leakPtr(), tra
nsaction->id()); |
| 49 } |
| 50 |
| 51 void IDBObserver::unobserve(IDBDatabase* database, ExceptionState& exceptionStat
e) |
| 52 { |
| 53 if (!database->backend()) { |
| 54 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 55 return; |
| 56 } |
| 57 database->backend()->unobserve(WebIDBObserverImpl::create(this).leakPtr()); |
| 33 } | 58 } |
| 34 | 59 |
| 35 DEFINE_TRACE(IDBObserver) | 60 DEFINE_TRACE(IDBObserver) |
| 36 { | 61 { |
| 37 visitor->trace(m_callback); | 62 visitor->trace(m_callback); |
| 38 } | 63 } |
| 39 | 64 |
| 40 } // namespace blink | 65 } // namespace blink |
| OLD | NEW |