OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_ | |
6 #define CONTENT_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_ | |
7 | |
8 #include <map> | |
9 #include <vector> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/id_map.h" | |
13 #include "content/public/browser/browser_message_filter.h" | |
14 | |
15 class GURL; | |
16 struct IndexedDBDatabaseMetadata; | |
17 struct IndexedDBHostMsg_DatabaseCount_Params; | |
18 struct IndexedDBHostMsg_DatabaseCreateIndex_Params; | |
19 struct IndexedDBHostMsg_DatabaseCreateObjectStore_Params; | |
20 struct IndexedDBHostMsg_DatabaseCreateTransaction_Params; | |
21 struct IndexedDBHostMsg_DatabaseDeleteRange_Params; | |
22 struct IndexedDBHostMsg_DatabaseGet_Params; | |
23 struct IndexedDBHostMsg_DatabaseOpenCursor_Params; | |
24 struct IndexedDBHostMsg_DatabasePut_Params; | |
25 struct IndexedDBHostMsg_DatabaseSetIndexKeys_Params; | |
26 struct IndexedDBHostMsg_FactoryDeleteDatabase_Params; | |
27 struct IndexedDBHostMsg_FactoryGetDatabaseNames_Params; | |
28 struct IndexedDBHostMsg_FactoryOpen_Params; | |
29 | |
30 namespace content { | |
31 class IndexedDBContextImpl; | |
32 class IndexedDBKey; | |
33 class IndexedDBKeyPath; | |
34 class IndexedDBKeyRange; | |
35 class WebIDBCursorImpl; | |
36 class WebIDBDatabaseImpl; | |
37 struct IndexedDBDatabaseMetadata; | |
38 | |
39 // Handles all IndexedDB related messages from a particular renderer process. | |
40 class IndexedDBDispatcherHost : public BrowserMessageFilter { | |
41 public: | |
42 // Only call the constructor from the UI thread. | |
43 IndexedDBDispatcherHost(int ipc_process_id, | |
44 IndexedDBContextImpl* indexed_db_context); | |
45 | |
46 static ::IndexedDBDatabaseMetadata ConvertMetadata( | |
47 const content::IndexedDBDatabaseMetadata& metadata); | |
48 | |
49 // BrowserMessageFilter implementation. | |
50 virtual void OnChannelClosing() OVERRIDE; | |
51 virtual void OnDestruct() const OVERRIDE; | |
52 virtual base::TaskRunner* OverrideTaskRunnerForMessage( | |
53 const IPC::Message& message) OVERRIDE; | |
54 virtual bool OnMessageReceived(const IPC::Message& message, | |
55 bool* message_was_ok) OVERRIDE; | |
56 | |
57 void FinishTransaction(int64 host_transaction_id, bool committed); | |
58 | |
59 // A shortcut for accessing our context. | |
60 IndexedDBContextImpl* Context() { return indexed_db_context_.get(); } | |
61 | |
62 // The various IndexedDBCallbacks children call these methods to add the | |
63 // results into the applicable map. See below for more details. | |
64 int32 Add(WebIDBCursorImpl* idb_cursor); | |
65 int32 Add(WebIDBDatabaseImpl* idb_database, | |
66 int32 ipc_thread_id, | |
67 const GURL& origin_url); | |
68 | |
69 void RegisterTransactionId(int64 host_transaction_id, const GURL& origin_url); | |
70 | |
71 WebIDBCursorImpl* GetCursorFromId(int32 ipc_cursor_id); | |
72 | |
73 int64 HostTransactionId(int64 transaction_id); | |
74 int64 RendererTransactionId(int64 host_transaction_id); | |
75 | |
76 private: | |
77 // Friends to enable OnDestruct() delegation. | |
78 friend class BrowserThread; | |
79 friend class base::DeleteHelper<IndexedDBDispatcherHost>; | |
80 | |
81 virtual ~IndexedDBDispatcherHost(); | |
82 | |
83 // Message processing. Most of the work is delegated to the dispatcher hosts | |
84 // below. | |
85 void OnIDBFactoryGetDatabaseNames( | |
86 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& p); | |
87 void OnIDBFactoryOpen(const IndexedDBHostMsg_FactoryOpen_Params& p); | |
88 | |
89 void OnIDBFactoryDeleteDatabase( | |
90 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& p); | |
91 | |
92 void ResetDispatcherHosts(); | |
93 | |
94 // Helper templates. | |
95 template <class ReturnType> | |
96 ReturnType* GetOrTerminateProcess(IDMap<ReturnType, IDMapOwnPointer>* map, | |
97 int32 ipc_return_object_id); | |
98 | |
99 template <typename ObjectType> | |
100 void DestroyObject(IDMap<ObjectType, IDMapOwnPointer>* map, | |
101 int32 ipc_object_id); | |
102 | |
103 // Used in nested classes. | |
104 typedef std::map<int32, GURL> WebIDBObjectIDToURLMap; | |
105 | |
106 typedef std::map<int64, GURL> TransactionIDToURLMap; | |
107 typedef std::map<int64, uint64> TransactionIDToSizeMap; | |
108 typedef std::map<int64, int64> TransactionIDToDatabaseIDMap; | |
109 | |
110 class DatabaseDispatcherHost { | |
111 public: | |
112 explicit DatabaseDispatcherHost(IndexedDBDispatcherHost* parent); | |
113 ~DatabaseDispatcherHost(); | |
114 | |
115 void CloseAll(); | |
116 bool OnMessageReceived(const IPC::Message& message, bool* msg_is_ok); | |
117 void Send(IPC::Message* message); | |
118 | |
119 void OnCreateObjectStore( | |
120 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params); | |
121 void OnDeleteObjectStore(int32 ipc_database_id, | |
122 int64 transaction_id, | |
123 int64 object_store_id); | |
124 void OnCreateTransaction( | |
125 const IndexedDBHostMsg_DatabaseCreateTransaction_Params&); | |
126 void OnOpen(int32 ipc_database_id, | |
127 int32 ipc_thread_id, | |
128 int32 ipc_callbacks_id); | |
129 void OnClose(int32 ipc_database_id); | |
130 void OnDestroyed(int32 ipc_database_id); | |
131 | |
132 void OnGet(const IndexedDBHostMsg_DatabaseGet_Params& params); | |
133 void OnPut(const IndexedDBHostMsg_DatabasePut_Params& params); | |
134 void OnSetIndexKeys( | |
135 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params); | |
136 void OnSetIndexesReady(int32 ipc_database_id, | |
137 int64 transaction_id, | |
138 int64 object_store_id, | |
139 const std::vector<int64>& ids); | |
140 void OnOpenCursor(const IndexedDBHostMsg_DatabaseOpenCursor_Params& params); | |
141 void OnCount(const IndexedDBHostMsg_DatabaseCount_Params& params); | |
142 void OnDeleteRange( | |
143 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params); | |
144 void OnClear(int32 ipc_thread_id, | |
145 int32 ipc_callbacks_id, | |
146 int32 ipc_database_id, | |
147 int64 transaction_id, | |
148 int64 object_store_id); | |
149 void OnCreateIndex( | |
150 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params); | |
151 void OnDeleteIndex(int32 ipc_database_id, | |
152 int64 transaction_id, | |
153 int64 object_store_id, | |
154 int64 index_id); | |
155 | |
156 void OnAbort(int32 ipc_database_id, int64 transaction_id); | |
157 void OnCommit(int32 ipc_database_id, int64 transaction_id); | |
158 IndexedDBDispatcherHost* parent_; | |
159 IDMap<WebIDBDatabaseImpl, IDMapOwnPointer> map_; | |
160 WebIDBObjectIDToURLMap database_url_map_; | |
161 TransactionIDToSizeMap transaction_size_map_; | |
162 TransactionIDToURLMap transaction_url_map_; | |
163 TransactionIDToDatabaseIDMap transaction_database_map_; | |
164 }; | |
165 | |
166 class CursorDispatcherHost { | |
167 public: | |
168 explicit CursorDispatcherHost(IndexedDBDispatcherHost* parent); | |
169 ~CursorDispatcherHost(); | |
170 | |
171 bool OnMessageReceived(const IPC::Message& message, bool* msg_is_ok); | |
172 void Send(IPC::Message* message); | |
173 | |
174 void OnAdvance(int32 ipc_object_store_id, | |
175 int32 ipc_thread_id, | |
176 int32 ipc_callbacks_id, | |
177 unsigned long count); | |
178 void OnContinue(int32 ipc_object_store_id, | |
179 int32 ipc_thread_id, | |
180 int32 ipc_callbacks_id, | |
181 const IndexedDBKey& key); | |
182 void OnPrefetch(int32 ipc_cursor_id, | |
183 int32 ipc_thread_id, | |
184 int32 ipc_callbacks_id, | |
185 int n); | |
186 void OnPrefetchReset(int32 ipc_cursor_id, | |
187 int used_prefetches, | |
188 int unused_prefetches); | |
189 void OnDestroyed(int32 ipc_cursor_id); | |
190 | |
191 IndexedDBDispatcherHost* parent_; | |
192 IDMap<WebIDBCursorImpl, IDMapOwnPointer> map_; | |
193 }; | |
194 | |
195 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; | |
196 | |
197 // Only access on IndexedDB thread. | |
198 scoped_ptr<DatabaseDispatcherHost> database_dispatcher_host_; | |
199 scoped_ptr<CursorDispatcherHost> cursor_dispatcher_host_; | |
200 | |
201 // Used to dispatch messages to the correct view host. | |
202 int ipc_process_id_; | |
203 | |
204 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); | |
205 }; | |
206 | |
207 } // namespace content | |
208 | |
209 #endif // CONTENT_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_ | |
OLD | NEW |