Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: content/child/indexed_db/indexed_db_dispatcher.h

Issue 2511403003: Send IndexedDB observations through IDBDatabaseCallbacks. (Closed)
Patch Set: Rebased. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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);
79 void RegisterMojoOwnedDatabaseCallbacks( 53 void RegisterMojoOwnedDatabaseCallbacks(
80 blink::WebIDBDatabaseCallbacks* callback_state); 54 blink::WebIDBDatabaseCallbacks* callback_state);
81 void UnregisterMojoOwnedDatabaseCallbacks( 55 void UnregisterMojoOwnedDatabaseCallbacks(
82 blink::WebIDBDatabaseCallbacks* callback_state); 56 blink::WebIDBDatabaseCallbacks* callback_state);
83 57
84 private: 58 private:
85 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorReset); 59 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorReset);
86 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorTransactionId); 60 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorTransactionId);
87 61
88 static int32_t CurrentWorkerId() { return WorkerThread::GetCurrentId(); } 62 static int32_t CurrentWorkerId() { return WorkerThread::GetCurrentId(); }
89 63
90 // IDBCallback message handlers.
91 void OnDatabaseChanges(int32_t ipc_thread_id,
92 const IndexedDBMsg_ObserverChanges&);
93
94 IDMap<blink::WebIDBObserver, IDMapOwnPointer> observers_;
95 std::unordered_set<WebIDBCursorImpl*> cursors_; 64 std::unordered_set<WebIDBCursorImpl*> cursors_;
96 65
97 // Holds pointers to the worker-thread owned state of IndexedDBCallbacksImpl 66 // Holds pointers to the worker-thread owned state of IndexedDBCallbacksImpl
98 // and IndexedDBDatabaseCallbacksImpl objects to makes sure that it is 67 // and IndexedDBDatabaseCallbacksImpl objects to makes sure that it is
99 // destroyed on thread exit if the Mojo pipe is not yet closed. Otherwise the 68 // destroyed on thread exit if the Mojo pipe is not yet closed. Otherwise the
100 // object will leak because the thread's task runner is no longer executing 69 // object will leak because the thread's task runner is no longer executing
101 // tasks. 70 // tasks.
102 std::unordered_set<IndexedDBCallbacksImpl::InternalState*> 71 std::unordered_set<IndexedDBCallbacksImpl::InternalState*>
103 mojo_owned_callback_state_; 72 mojo_owned_callback_state_;
104 std::unordered_set<blink::WebIDBDatabaseCallbacks*> 73 std::unordered_set<blink::WebIDBDatabaseCallbacks*>
105 mojo_owned_database_callback_state_; 74 mojo_owned_database_callback_state_;
106 75
107 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); 76 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher);
108 }; 77 };
109 78
110 } // namespace content 79 } // namespace content
111 80
112 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ 81 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698