| 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/common/indexed_db/indexed_db_dispatcher.h" | 5 #include "content/common/indexed_db/indexed_db_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/threading/thread_local.h" | 8 #include "base/threading/thread_local.h" |
| 9 #include "content/common/child_thread.h" | 9 #include "content/common/child_thread.h" |
| 10 #include "content/common/indexed_db/indexed_db_messages.h" | 10 #include "content/common/indexed_db/indexed_db_messages.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; | 41 g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 IndexedDBDispatcher* const kHasBeenDeleted = | 45 IndexedDBDispatcher* const kHasBeenDeleted = |
| 46 reinterpret_cast<IndexedDBDispatcher*>(0x1); | 46 reinterpret_cast<IndexedDBDispatcher*>(0x1); |
| 47 | 47 |
| 48 int32 CurrentWorkerId() { | 48 int32 CurrentWorkerId() { |
| 49 return WorkerTaskRunner::Instance()->CurrentWorkerId(); | 49 return WorkerTaskRunner::Instance()->CurrentWorkerId(); |
| 50 } | 50 } |
| 51 | 51 } // unnamed namespace |
| 52 } // unnamed namespace | |
| 53 | 52 |
| 54 const size_t kMaxIDBValueSizeInBytes = 64 * 1024 * 1024; | 53 const size_t kMaxIDBValueSizeInBytes = 64 * 1024 * 1024; |
| 55 | 54 |
| 56 IndexedDBDispatcher::IndexedDBDispatcher() { | 55 IndexedDBDispatcher::IndexedDBDispatcher() { |
| 57 g_idb_dispatcher_tls.Pointer()->Set(this); | 56 g_idb_dispatcher_tls.Pointer()->Set(this); |
| 58 } | 57 } |
| 59 | 58 |
| 60 IndexedDBDispatcher::~IndexedDBDispatcher() { | 59 IndexedDBDispatcher::~IndexedDBDispatcher() { |
| 61 g_idb_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); | 60 g_idb_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); |
| 62 } | 61 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 | 121 |
| 123 bool IndexedDBDispatcher::Send(IPC::Message* msg) { | 122 bool IndexedDBDispatcher::Send(IPC::Message* msg) { |
| 124 if (CurrentWorkerId()) { | 123 if (CurrentWorkerId()) { |
| 125 scoped_refptr<IPC::SyncMessageFilter> filter( | 124 scoped_refptr<IPC::SyncMessageFilter> filter( |
| 126 ChildThread::current()->sync_message_filter()); | 125 ChildThread::current()->sync_message_filter()); |
| 127 return filter->Send(msg); | 126 return filter->Send(msg); |
| 128 } | 127 } |
| 129 return ChildThread::current()->Send(msg); | 128 return ChildThread::current()->Send(msg); |
| 130 } | 129 } |
| 131 | 130 |
| 132 void IndexedDBDispatcher::RequestIDBCursorUpdate( | |
| 133 const SerializedScriptValue& value, | |
| 134 WebIDBCallbacks* callbacks_ptr, | |
| 135 int32 idb_cursor_id, | |
| 136 WebExceptionCode* ec) { | |
| 137 ResetCursorPrefetchCaches(); | |
| 138 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | |
| 139 if (!value.is_null() && | |
| 140 (value.data().length() * sizeof(char16)) > kMaxIDBValueSizeInBytes) { | |
| 141 *ec = WebKit::WebIDBDatabaseExceptionDataError; | |
| 142 return; | |
| 143 } | |
| 144 int32 response_id = pending_callbacks_.Add(callbacks.release()); | |
| 145 Send( | |
| 146 new IndexedDBHostMsg_CursorUpdate(idb_cursor_id, CurrentWorkerId(), | |
| 147 response_id, value, ec)); | |
| 148 if (*ec) | |
| 149 pending_callbacks_.Remove(response_id); | |
| 150 } | |
| 151 | |
| 152 void IndexedDBDispatcher::RequestIDBCursorAdvance( | 131 void IndexedDBDispatcher::RequestIDBCursorAdvance( |
| 153 unsigned long count, | 132 unsigned long count, |
| 154 WebIDBCallbacks* callbacks_ptr, | 133 WebIDBCallbacks* callbacks_ptr, |
| 155 int32 idb_cursor_id, | 134 int32 idb_cursor_id, |
| 156 WebExceptionCode* ec) { | 135 WebExceptionCode* ec) { |
| 157 // Reset all cursor prefetch caches except for this cursor. | 136 // Reset all cursor prefetch caches except for this cursor. |
| 158 ResetCursorPrefetchCaches(idb_cursor_id); | 137 ResetCursorPrefetchCaches(idb_cursor_id); |
| 159 | 138 |
| 160 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 139 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); |
| 161 | 140 |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 } | 769 } |
| 791 | 770 |
| 792 void IndexedDBDispatcher::ResetCursorPrefetchCaches(int32 exception_cursor_id) { | 771 void IndexedDBDispatcher::ResetCursorPrefetchCaches(int32 exception_cursor_id) { |
| 793 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator; | 772 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator; |
| 794 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { | 773 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { |
| 795 if (i->first == exception_cursor_id) | 774 if (i->first == exception_cursor_id) |
| 796 continue; | 775 continue; |
| 797 i->second->ResetPrefetchCache(); | 776 i->second->ResetPrefetchCache(); |
| 798 } | 777 } |
| 799 } | 778 } |
| OLD | NEW |