| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/indexed_db/indexed_db_database_callbacks.h" | 5 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
| 6 | 6 |
| 7 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 7 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 8 #include "content/browser/indexed_db/indexed_db_database_error.h" | 8 #include "content/browser/indexed_db/indexed_db_database_error.h" |
| 9 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" | 9 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" |
| 10 #include "content/browser/indexed_db/indexed_db_transaction.h" | 10 #include "content/browser/indexed_db/indexed_db_transaction.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper); | 31 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper); |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 IndexedDBDatabaseCallbacks::IndexedDBDatabaseCallbacks( | 34 IndexedDBDatabaseCallbacks::IndexedDBDatabaseCallbacks( |
| 35 scoped_refptr<IndexedDBContextImpl> context, | 35 scoped_refptr<IndexedDBContextImpl> context, |
| 36 DatabaseCallbacksAssociatedPtrInfo callbacks_info) | 36 DatabaseCallbacksAssociatedPtrInfo callbacks_info) |
| 37 : indexed_db_context_(std::move(context)), | 37 : indexed_db_context_(std::move(context)), |
| 38 io_helper_(new IOThreadHelper(std::move(callbacks_info))) { | 38 io_helper_(new IOThreadHelper(std::move(callbacks_info))) { |
| 39 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 39 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 40 thread_checker_.DetachFromThread(); | 40 DETACH_FROM_SEQUENCE(sequence_checker_); |
| 41 } | 41 } |
| 42 | 42 |
| 43 IndexedDBDatabaseCallbacks::~IndexedDBDatabaseCallbacks() { | 43 IndexedDBDatabaseCallbacks::~IndexedDBDatabaseCallbacks() { |
| 44 DCHECK(thread_checker_.CalledOnValidThread()); | 44 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void IndexedDBDatabaseCallbacks::OnForcedClose() { | 47 void IndexedDBDatabaseCallbacks::OnForcedClose() { |
| 48 DCHECK(thread_checker_.CalledOnValidThread()); | 48 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 49 if (complete_) | 49 if (complete_) |
| 50 return; | 50 return; |
| 51 | 51 |
| 52 DCHECK(io_helper_); | 52 DCHECK(io_helper_); |
| 53 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 53 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 54 base::Bind(&IOThreadHelper::SendForcedClose, | 54 base::Bind(&IOThreadHelper::SendForcedClose, |
| 55 base::Unretained(io_helper_.get()))); | 55 base::Unretained(io_helper_.get()))); |
| 56 complete_ = true; | 56 complete_ = true; |
| 57 } | 57 } |
| 58 | 58 |
| 59 void IndexedDBDatabaseCallbacks::OnVersionChange(int64_t old_version, | 59 void IndexedDBDatabaseCallbacks::OnVersionChange(int64_t old_version, |
| 60 int64_t new_version) { | 60 int64_t new_version) { |
| 61 DCHECK(thread_checker_.CalledOnValidThread()); | 61 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 62 if (complete_) | 62 if (complete_) |
| 63 return; | 63 return; |
| 64 | 64 |
| 65 DCHECK(io_helper_); | 65 DCHECK(io_helper_); |
| 66 BrowserThread::PostTask( | 66 BrowserThread::PostTask( |
| 67 BrowserThread::IO, FROM_HERE, | 67 BrowserThread::IO, FROM_HERE, |
| 68 base::Bind(&IOThreadHelper::SendVersionChange, | 68 base::Bind(&IOThreadHelper::SendVersionChange, |
| 69 base::Unretained(io_helper_.get()), old_version, new_version)); | 69 base::Unretained(io_helper_.get()), old_version, new_version)); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void IndexedDBDatabaseCallbacks::OnAbort( | 72 void IndexedDBDatabaseCallbacks::OnAbort( |
| 73 const IndexedDBTransaction& transaction, | 73 const IndexedDBTransaction& transaction, |
| 74 const IndexedDBDatabaseError& error) { | 74 const IndexedDBDatabaseError& error) { |
| 75 DCHECK(thread_checker_.CalledOnValidThread()); | 75 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 76 if (complete_) | 76 if (complete_) |
| 77 return; | 77 return; |
| 78 | 78 |
| 79 DCHECK(io_helper_); | 79 DCHECK(io_helper_); |
| 80 BrowserThread::PostTask( | 80 BrowserThread::PostTask( |
| 81 BrowserThread::IO, FROM_HERE, | 81 BrowserThread::IO, FROM_HERE, |
| 82 base::Bind(&IOThreadHelper::SendAbort, base::Unretained(io_helper_.get()), | 82 base::Bind(&IOThreadHelper::SendAbort, base::Unretained(io_helper_.get()), |
| 83 transaction.id(), error)); | 83 transaction.id(), error)); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void IndexedDBDatabaseCallbacks::OnComplete( | 86 void IndexedDBDatabaseCallbacks::OnComplete( |
| 87 const IndexedDBTransaction& transaction) { | 87 const IndexedDBTransaction& transaction) { |
| 88 DCHECK(thread_checker_.CalledOnValidThread()); | 88 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 89 if (complete_) | 89 if (complete_) |
| 90 return; | 90 return; |
| 91 | 91 |
| 92 indexed_db_context_->TransactionComplete(transaction.database()->origin()); | 92 indexed_db_context_->TransactionComplete(transaction.database()->origin()); |
| 93 DCHECK(io_helper_); | 93 DCHECK(io_helper_); |
| 94 BrowserThread::PostTask( | 94 BrowserThread::PostTask( |
| 95 BrowserThread::IO, FROM_HERE, | 95 BrowserThread::IO, FROM_HERE, |
| 96 base::Bind(&IOThreadHelper::SendComplete, | 96 base::Bind(&IOThreadHelper::SendComplete, |
| 97 base::Unretained(io_helper_.get()), transaction.id())); | 97 base::Unretained(io_helper_.get()), transaction.id())); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void IndexedDBDatabaseCallbacks::OnDatabaseChange( | 100 void IndexedDBDatabaseCallbacks::OnDatabaseChange( |
| 101 ::indexed_db::mojom::ObserverChangesPtr changes) { | 101 ::indexed_db::mojom::ObserverChangesPtr changes) { |
| 102 DCHECK(thread_checker_.CalledOnValidThread()); | 102 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 103 DCHECK(io_helper_); | 103 DCHECK(io_helper_); |
| 104 BrowserThread::PostTask( | 104 BrowserThread::PostTask( |
| 105 BrowserThread::IO, FROM_HERE, | 105 BrowserThread::IO, FROM_HERE, |
| 106 base::Bind(&IOThreadHelper::SendChanges, | 106 base::Bind(&IOThreadHelper::SendChanges, |
| 107 base::Unretained(io_helper_.get()), base::Passed(&changes))); | 107 base::Unretained(io_helper_.get()), base::Passed(&changes))); |
| 108 } | 108 } |
| 109 | 109 |
| 110 IndexedDBDatabaseCallbacks::IOThreadHelper::IOThreadHelper( | 110 IndexedDBDatabaseCallbacks::IOThreadHelper::IOThreadHelper( |
| 111 DatabaseCallbacksAssociatedPtrInfo callbacks_info) { | 111 DatabaseCallbacksAssociatedPtrInfo callbacks_info) { |
| 112 if (!callbacks_info.is_valid()) | 112 if (!callbacks_info.is_valid()) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 ::indexed_db::mojom::ObserverChangesPtr changes) { | 147 ::indexed_db::mojom::ObserverChangesPtr changes) { |
| 148 if (callbacks_) | 148 if (callbacks_) |
| 149 callbacks_->Changes(std::move(changes)); | 149 callbacks_->Changes(std::move(changes)); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void IndexedDBDatabaseCallbacks::IOThreadHelper::OnConnectionError() { | 152 void IndexedDBDatabaseCallbacks::IOThreadHelper::OnConnectionError() { |
| 153 callbacks_.reset(); | 153 callbacks_.reset(); |
| 154 } | 154 } |
| 155 | 155 |
| 156 } // namespace content | 156 } // namespace content |
| OLD | NEW |