| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ | 5 #ifndef CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ |
| 6 #define CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ | 6 #define CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <map> | |
| 12 #include <string> | |
| 13 #include <vector> | |
| 14 | |
| 15 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 16 #include "base/id_map.h" | |
| 17 #include "base/macros.h" | 12 #include "base/macros.h" |
| 18 #include "base/memory/ref_counted.h" | |
| 19 #include "base/strings/nullable_string16.h" | 13 #include "base/strings/nullable_string16.h" |
| 20 #include "content/child/indexed_db/indexed_db_callbacks_impl.h" | 14 #include "content/child/indexed_db/indexed_db_callbacks_impl.h" |
| 21 #include "content/child/indexed_db/indexed_db_database_callbacks_impl.h" | 15 #include "content/child/indexed_db/indexed_db_database_callbacks_impl.h" |
| 22 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 23 #include "content/common/indexed_db/indexed_db_constants.h" | 17 #include "content/common/indexed_db/indexed_db_constants.h" |
| 24 #include "content/public/child/worker_thread.h" | 18 #include "content/public/child/worker_thread.h" |
| 25 #include "ipc/ipc_sync_message_filter.h" | 19 #include "ipc/ipc_sync_message_filter.h" |
| 26 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBCallbacks.h
" | 20 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBCallbacks.h
" |
| 27 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBObserver.h" | |
| 28 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" | 21 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" |
| 29 #include "url/origin.h" | 22 #include "url/origin.h" |
| 30 | 23 |
| 31 struct IndexedDBMsg_Observation; | |
| 32 struct IndexedDBMsg_ObserverChanges; | |
| 33 | |
| 34 namespace blink { | |
| 35 struct WebIDBObservation; | |
| 36 } | |
| 37 | |
| 38 namespace content { | 24 namespace content { |
| 39 class WebIDBCursorImpl; | 25 class WebIDBCursorImpl; |
| 40 | 26 |
| 41 // Handle the indexed db related communication for this context thread - the | 27 // Handle the indexed db related communication for this context thread - the |
| 42 // main thread and each worker thread have their own copies. | 28 // main thread and each worker thread have their own copies. |
| 43 class CONTENT_EXPORT IndexedDBDispatcher : public WorkerThread::Observer { | 29 class CONTENT_EXPORT IndexedDBDispatcher : public WorkerThread::Observer { |
| 44 public: | 30 public: |
| 45 // Constructor made public to allow RenderThreadImpl to own a copy without | 31 // Constructor made public to allow RenderThreadImpl to own a copy without |
| 46 // failing a NOTREACHED in ThreadSpecificInstance in tests that instantiate | 32 // failing a NOTREACHED in ThreadSpecificInstance in tests that instantiate |
| 47 // two copies of RenderThreadImpl on the same thread. Everyone else probably | 33 // two copies of RenderThreadImpl on the same thread. Everyone else probably |
| 48 // wants to use ThreadSpecificInstance(). | 34 // wants to use ThreadSpecificInstance(). |
| 49 IndexedDBDispatcher(); | 35 IndexedDBDispatcher(); |
| 50 ~IndexedDBDispatcher() override; | 36 ~IndexedDBDispatcher() override; |
| 51 | 37 |
| 52 static IndexedDBDispatcher* ThreadSpecificInstance(); | 38 static IndexedDBDispatcher* ThreadSpecificInstance(); |
| 53 | 39 |
| 54 // WorkerThread::Observer implementation. | 40 // WorkerThread::Observer implementation. |
| 55 void WillStopCurrentWorkerThread() override; | 41 void WillStopCurrentWorkerThread() override; |
| 56 | 42 |
| 57 static std::vector<blink::WebIDBObservation> ConvertObservations( | |
| 58 const std::vector<IndexedDBMsg_Observation>& idb_observation); | |
| 59 | |
| 60 void OnMessageReceived(const IPC::Message& msg); | |
| 61 | |
| 62 int32_t RegisterObserver(std::unique_ptr<blink::WebIDBObserver> observer); | |
| 63 | |
| 64 // Removes observers from our local map observers_. | |
| 65 void RemoveObservers(const std::vector<int32_t>& observer_ids_to_remove); | |
| 66 | |
| 67 enum { kAllCursors = -1 }; | |
| 68 | |
| 69 void RegisterCursor(WebIDBCursorImpl* cursor); | 43 void RegisterCursor(WebIDBCursorImpl* cursor); |
| 70 void UnregisterCursor(WebIDBCursorImpl* cursor); | 44 void UnregisterCursor(WebIDBCursorImpl* cursor); |
| 71 // Reset cursor prefetch caches for all cursors except exception_cursor. | 45 // Reset cursor prefetch caches for all cursors except exception_cursor. |
| 72 void ResetCursorPrefetchCaches(int64_t transaction_id, | 46 void ResetCursorPrefetchCaches(int64_t transaction_id, |
| 73 WebIDBCursorImpl* exception_cursor); | 47 WebIDBCursorImpl* exception_cursor); |
| 74 | 48 |
| 75 void RegisterMojoOwnedCallbacks( | 49 void RegisterMojoOwnedCallbacks( |
| 76 IndexedDBCallbacksImpl::InternalState* callback_state); | 50 IndexedDBCallbacksImpl::InternalState* callback_state); |
| 77 void UnregisterMojoOwnedCallbacks( | 51 void UnregisterMojoOwnedCallbacks( |
| 78 IndexedDBCallbacksImpl::InternalState* callback_state); | 52 IndexedDBCallbacksImpl::InternalState* callback_state); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 90 // the key type can remain a raw pointer. | 64 // the key type can remain a raw pointer. |
| 91 using CallbackStateSet = std::unordered_map< | 65 using CallbackStateSet = std::unordered_map< |
| 92 IndexedDBCallbacksImpl::InternalState*, | 66 IndexedDBCallbacksImpl::InternalState*, |
| 93 std::unique_ptr<IndexedDBCallbacksImpl::InternalState>>; | 67 std::unique_ptr<IndexedDBCallbacksImpl::InternalState>>; |
| 94 using DatabaseCallbackStateSet = | 68 using DatabaseCallbackStateSet = |
| 95 std::unordered_map<blink::WebIDBDatabaseCallbacks*, | 69 std::unordered_map<blink::WebIDBDatabaseCallbacks*, |
| 96 std::unique_ptr<blink::WebIDBDatabaseCallbacks>>; | 70 std::unique_ptr<blink::WebIDBDatabaseCallbacks>>; |
| 97 | 71 |
| 98 static int32_t CurrentWorkerId() { return WorkerThread::GetCurrentId(); } | 72 static int32_t CurrentWorkerId() { return WorkerThread::GetCurrentId(); } |
| 99 | 73 |
| 100 // IDBCallback message handlers. | |
| 101 void OnDatabaseChanges(int32_t ipc_thread_id, | |
| 102 const IndexedDBMsg_ObserverChanges&); | |
| 103 | |
| 104 IDMap<blink::WebIDBObserver, IDMapOwnPointer> observers_; | |
| 105 std::unordered_set<WebIDBCursorImpl*> cursors_; | 74 std::unordered_set<WebIDBCursorImpl*> cursors_; |
| 106 | 75 |
| 107 // Holds pointers to the worker-thread owned state of IndexedDBCallbacksImpl | 76 // Holds pointers to the worker-thread owned state of IndexedDBCallbacksImpl |
| 108 // and IndexedDBDatabaseCallbacksImpl objects to makes sure that it is | 77 // and IndexedDBDatabaseCallbacksImpl objects to makes sure that it is |
| 109 // destroyed on thread exit if the Mojo pipe is not yet closed. Otherwise the | 78 // destroyed on thread exit if the Mojo pipe is not yet closed. Otherwise the |
| 110 // object will leak because the thread's task runner is no longer executing | 79 // object will leak because the thread's task runner is no longer executing |
| 111 // tasks. | 80 // tasks. |
| 112 CallbackStateSet mojo_owned_callback_state_; | 81 CallbackStateSet mojo_owned_callback_state_; |
| 113 DatabaseCallbackStateSet mojo_owned_database_callback_state_; | 82 DatabaseCallbackStateSet mojo_owned_database_callback_state_; |
| 114 bool in_destructor_ = false; | 83 bool in_destructor_ = false; |
| 115 | 84 |
| 116 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); | 85 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); |
| 117 }; | 86 }; |
| 118 | 87 |
| 119 } // namespace content | 88 } // namespace content |
| 120 | 89 |
| 121 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ | 90 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ |
| OLD | NEW |