| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_ | 5 #ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_ |
| 6 #define CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_ | 6 #define CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/id_map.h" | 10 #include "base/id_map.h" |
| 11 #include "base/process.h" | 11 #include "chrome/browser/browser_message_filter.h" |
| 12 #include "base/ref_counted.h" | |
| 13 #include "chrome/browser/in_process_webkit/webkit_context.h" | 12 #include "chrome/browser/in_process_webkit/webkit_context.h" |
| 14 #include "ipc/ipc_message.h" | |
| 15 | 13 |
| 16 class HostContentSettingsMap; | 14 class HostContentSettingsMap; |
| 17 class IndexedDBKey; | 15 class IndexedDBKey; |
| 18 class Profile; | 16 class Profile; |
| 19 class SerializedScriptValue; | 17 class SerializedScriptValue; |
| 20 struct ViewHostMsg_IDBDatabaseCreateObjectStore_Params; | 18 struct IndexedDBHostMsg_DatabaseCreateObjectStore_Params; |
| 21 struct ViewHostMsg_IDBFactoryOpen_Params; | 19 struct IndexedDBHostMsg_FactoryOpen_Params; |
| 22 struct ViewHostMsg_IDBIndexOpenCursor_Params; | 20 struct IndexedDBHostMsg_IndexOpenCursor_Params; |
| 23 struct ViewHostMsg_IDBObjectStoreCreateIndex_Params; | 21 struct IndexedDBHostMsg_ObjectStoreCreateIndex_Params; |
| 24 struct ViewHostMsg_IDBObjectStoreOpenCursor_Params; | 22 struct IndexedDBHostMsg_ObjectStoreOpenCursor_Params; |
| 25 struct ViewHostMsg_IDBObjectStorePut_Params; | 23 struct IndexedDBHostMsg_ObjectStorePut_Params; |
| 26 | 24 |
| 27 namespace WebKit { | 25 namespace WebKit { |
| 28 class WebIDBCursor; | 26 class WebIDBCursor; |
| 29 class WebIDBDatabase; | 27 class WebIDBDatabase; |
| 30 class WebIDBIndex; | 28 class WebIDBIndex; |
| 31 class WebIDBObjectStore; | 29 class WebIDBObjectStore; |
| 32 class WebIDBTransaction; | 30 class WebIDBTransaction; |
| 33 } | 31 } |
| 34 | 32 |
| 35 // Handles all IndexedDB related messages from a particular renderer process. | 33 // Handles all IndexedDB related messages from a particular renderer process. |
| 36 class IndexedDBDispatcherHost | 34 class IndexedDBDispatcherHost : public BrowserMessageFilter { |
| 37 : public base::RefCountedThreadSafe<IndexedDBDispatcherHost> { | |
| 38 public: | 35 public: |
| 39 // Only call the constructor from the UI thread. | 36 // Only call the constructor from the UI thread. |
| 40 IndexedDBDispatcherHost(IPC::Message::Sender* sender, Profile* profile); | 37 IndexedDBDispatcherHost(int process_id, Profile* profile); |
| 41 | 38 |
| 42 // Only call from ResourceMessageFilter on the IO thread. | 39 // BrowserMessageFilter implementation. |
| 43 void Init(int process_id, base::ProcessHandle process_handle); | 40 virtual void OnChannelClosing(); |
| 44 | 41 virtual void OverrideThreadForMessage(const IPC::Message& message, |
| 45 // Only call from ResourceMessageFilter on the IO thread. Calls self on the | 42 BrowserThread::ID* thread); |
| 46 // WebKit thread in some cases. | 43 virtual bool OnMessageReceived(const IPC::Message& message, |
| 47 void Shutdown(); | 44 bool* message_was_ok); |
| 48 | |
| 49 // Only call from ResourceMessageFilter on the IO thread. | |
| 50 bool OnMessageReceived(const IPC::Message& message); | |
| 51 | |
| 52 // Send a message to the renderer process associated with our sender_ via the | |
| 53 // IO thread. May be called from any thread. | |
| 54 void Send(IPC::Message* message); | |
| 55 | 45 |
| 56 // A shortcut for accessing our context. | 46 // A shortcut for accessing our context. |
| 57 IndexedDBContext* Context() { | 47 IndexedDBContext* Context() { |
| 58 return webkit_context_->indexed_db_context(); | 48 return webkit_context_->indexed_db_context(); |
| 59 } | 49 } |
| 60 | 50 |
| 61 // The various IndexedDBCallbacks children call these methods to add the | 51 // The various IndexedDBCallbacks children call these methods to add the |
| 62 // results into the applicable map. See below for more details. | 52 // results into the applicable map. See below for more details. |
| 63 int32 Add(WebKit::WebIDBCursor* idb_cursor); | 53 int32 Add(WebKit::WebIDBCursor* idb_cursor); |
| 64 int32 Add(WebKit::WebIDBDatabase* idb_database); | 54 int32 Add(WebKit::WebIDBDatabase* idb_database); |
| 65 int32 Add(WebKit::WebIDBIndex* idb_index); | 55 int32 Add(WebKit::WebIDBIndex* idb_index); |
| 66 int32 Add(WebKit::WebIDBObjectStore* idb_object_store); | 56 int32 Add(WebKit::WebIDBObjectStore* idb_object_store); |
| 67 int32 Add(WebKit::WebIDBTransaction* idb_transaction); | 57 int32 Add(WebKit::WebIDBTransaction* idb_transaction); |
| 68 | 58 |
| 69 private: | 59 private: |
| 70 friend class base::RefCountedThreadSafe<IndexedDBDispatcherHost>; | |
| 71 ~IndexedDBDispatcherHost(); | 60 ~IndexedDBDispatcherHost(); |
| 72 | 61 |
| 73 // Message processing. Most of the work is delegated to the dispatcher hosts | 62 // Message processing. Most of the work is delegated to the dispatcher hosts |
| 74 // below. | 63 // below. |
| 75 void OnMessageReceivedWebKit(const IPC::Message& message); | 64 void OnIDBFactoryOpen(const IndexedDBHostMsg_FactoryOpen_Params& p); |
| 76 void OnIDBFactoryOpen(const ViewHostMsg_IDBFactoryOpen_Params& p); | |
| 77 | 65 |
| 78 // Helper templates. | 66 // Helper templates. |
| 79 template <class ReturnType> | 67 template <class ReturnType> |
| 80 ReturnType* GetOrTerminateProcess( | 68 ReturnType* GetOrTerminateProcess( |
| 81 IDMap<ReturnType, IDMapOwnPointer>* map, int32 return_object_id, | 69 IDMap<ReturnType, IDMapOwnPointer>* map, int32 return_object_id, |
| 82 IPC::Message* reply_msg, uint32 message_type); | 70 IPC::Message* reply_msg, uint32 message_type); |
| 83 | 71 |
| 84 template <typename ReplyType, typename MessageType, | 72 template <typename ReplyType, typename MessageType, |
| 85 typename WebObjectType, typename Method> | 73 typename WebObjectType, typename Method> |
| 86 void SyncGetter(IDMap<WebObjectType, IDMapOwnPointer>* map, int32 object_id, | 74 void SyncGetter(IDMap<WebObjectType, IDMapOwnPointer>* map, int32 object_id, |
| 87 IPC::Message* reply_msg, Method method); | 75 IPC::Message* reply_msg, Method method); |
| 88 | 76 |
| 89 template <typename ObjectType> | 77 template <typename ObjectType> |
| 90 void DestroyObject(IDMap<ObjectType, IDMapOwnPointer>* map, int32 object_id, | 78 void DestroyObject(IDMap<ObjectType, IDMapOwnPointer>* map, int32 object_id, |
| 91 uint32 message_type); | 79 uint32 message_type); |
| 92 | 80 |
| 93 class DatabaseDispatcherHost { | 81 class DatabaseDispatcherHost { |
| 94 public: | 82 public: |
| 95 explicit DatabaseDispatcherHost(IndexedDBDispatcherHost* parent); | 83 explicit DatabaseDispatcherHost(IndexedDBDispatcherHost* parent); |
| 96 ~DatabaseDispatcherHost(); | 84 ~DatabaseDispatcherHost(); |
| 97 | 85 |
| 98 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok); | 86 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok); |
| 99 void Send(IPC::Message* message); | 87 void Send(IPC::Message* message); |
| 100 | 88 |
| 101 void OnName(int32 idb_database_id, IPC::Message* reply_msg); | 89 void OnName(int32 idb_database_id, IPC::Message* reply_msg); |
| 102 void OnVersion(int32 idb_database_id, IPC::Message* reply_msg); | 90 void OnVersion(int32 idb_database_id, IPC::Message* reply_msg); |
| 103 void OnObjectStoreNames(int32 idb_database_id, IPC::Message* reply_msg); | 91 void OnObjectStoreNames(int32 idb_database_id, IPC::Message* reply_msg); |
| 104 void OnCreateObjectStore( | 92 void OnCreateObjectStore( |
| 105 const ViewHostMsg_IDBDatabaseCreateObjectStore_Params& params, | 93 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params, |
| 106 IPC::Message* reply_msg); | 94 IPC::Message* reply_msg); |
| 107 void OnDeleteObjectStore(int32 idb_database_id, | 95 void OnDeleteObjectStore(int32 idb_database_id, |
| 108 const string16& name, | 96 const string16& name, |
| 109 int32 transaction_id, | 97 int32 transaction_id, |
| 110 IPC::Message* reply_msg); | 98 IPC::Message* reply_msg); |
| 111 void OnSetVersion(int32 idb_database_id, | 99 void OnSetVersion(int32 idb_database_id, |
| 112 int32 response_id, | 100 int32 response_id, |
| 113 const string16& version, | 101 const string16& version, |
| 114 IPC::Message* reply_msg); | 102 IPC::Message* reply_msg); |
| 115 void OnTransaction(int32 idb_database_id, | 103 void OnTransaction(int32 idb_database_id, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 128 ~IndexDispatcherHost(); | 116 ~IndexDispatcherHost(); |
| 129 | 117 |
| 130 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok); | 118 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok); |
| 131 void Send(IPC::Message* message); | 119 void Send(IPC::Message* message); |
| 132 | 120 |
| 133 void OnName(int32 idb_index_id, IPC::Message* reply_msg); | 121 void OnName(int32 idb_index_id, IPC::Message* reply_msg); |
| 134 void OnStoreName(int32 idb_index_id, IPC::Message* reply_msg); | 122 void OnStoreName(int32 idb_index_id, IPC::Message* reply_msg); |
| 135 void OnKeyPath(int32 idb_index_id, IPC::Message* reply_msg); | 123 void OnKeyPath(int32 idb_index_id, IPC::Message* reply_msg); |
| 136 void OnUnique(int32 idb_index_id, IPC::Message* reply_msg); | 124 void OnUnique(int32 idb_index_id, IPC::Message* reply_msg); |
| 137 void OnOpenObjectCursor( | 125 void OnOpenObjectCursor( |
| 138 const ViewHostMsg_IDBIndexOpenCursor_Params& params, | 126 const IndexedDBHostMsg_IndexOpenCursor_Params& params, |
| 139 IPC::Message* reply_msg); | 127 IPC::Message* reply_msg); |
| 140 void OnOpenKeyCursor(const ViewHostMsg_IDBIndexOpenCursor_Params& params, | 128 void OnOpenKeyCursor(const IndexedDBHostMsg_IndexOpenCursor_Params& params, |
| 141 IPC::Message* reply_msg); | 129 IPC::Message* reply_msg); |
| 142 void OnGetObject(int idb_index_id, | 130 void OnGetObject(int idb_index_id, |
| 143 int32 response_id, | 131 int32 response_id, |
| 144 const IndexedDBKey& key, | 132 const IndexedDBKey& key, |
| 145 int32 transaction_id, | 133 int32 transaction_id, |
| 146 IPC::Message* reply_msg); | 134 IPC::Message* reply_msg); |
| 147 void OnGetKey(int idb_index_id, | 135 void OnGetKey(int idb_index_id, |
| 148 int32 response_id, | 136 int32 response_id, |
| 149 const IndexedDBKey& key, | 137 const IndexedDBKey& key, |
| 150 int32 transaction_id, | 138 int32 transaction_id, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 164 void Send(IPC::Message* message); | 152 void Send(IPC::Message* message); |
| 165 | 153 |
| 166 void OnName(int32 idb_object_store_id, IPC::Message* reply_msg); | 154 void OnName(int32 idb_object_store_id, IPC::Message* reply_msg); |
| 167 void OnKeyPath(int32 idb_object_store_id, IPC::Message* reply_msg); | 155 void OnKeyPath(int32 idb_object_store_id, IPC::Message* reply_msg); |
| 168 void OnIndexNames(int32 idb_object_store_id, IPC::Message* reply_msg); | 156 void OnIndexNames(int32 idb_object_store_id, IPC::Message* reply_msg); |
| 169 void OnGet(int idb_object_store_id, | 157 void OnGet(int idb_object_store_id, |
| 170 int32 response_id, | 158 int32 response_id, |
| 171 const IndexedDBKey& key, | 159 const IndexedDBKey& key, |
| 172 int32 transaction_id, | 160 int32 transaction_id, |
| 173 IPC::Message* reply_msg); | 161 IPC::Message* reply_msg); |
| 174 void OnPut(const ViewHostMsg_IDBObjectStorePut_Params& params, | 162 void OnPut(const IndexedDBHostMsg_ObjectStorePut_Params& params, |
| 175 IPC::Message* reply_msg); | 163 IPC::Message* reply_msg); |
| 176 void OnDelete(int idb_object_store_id, | 164 void OnDelete(int idb_object_store_id, |
| 177 int32 response_id, | 165 int32 response_id, |
| 178 const IndexedDBKey& key, | 166 const IndexedDBKey& key, |
| 179 int32 transaction_id, | 167 int32 transaction_id, |
| 180 IPC::Message* reply_msg); | 168 IPC::Message* reply_msg); |
| 181 void OnCreateIndex( | 169 void OnCreateIndex( |
| 182 const ViewHostMsg_IDBObjectStoreCreateIndex_Params& params, | 170 const IndexedDBHostMsg_ObjectStoreCreateIndex_Params& params, |
| 183 IPC::Message* reply_msg); | 171 IPC::Message* reply_msg); |
| 184 void OnIndex(int32 idb_object_store_id, | 172 void OnIndex(int32 idb_object_store_id, |
| 185 const string16& name, | 173 const string16& name, |
| 186 IPC::Message* reply_msg); | 174 IPC::Message* reply_msg); |
| 187 void OnDeleteIndex(int32 idb_object_store_id, | 175 void OnDeleteIndex(int32 idb_object_store_id, |
| 188 const string16& name, | 176 const string16& name, |
| 189 int32 transaction_id, | 177 int32 transaction_id, |
| 190 IPC::Message* reply_msg); | 178 IPC::Message* reply_msg); |
| 191 void OnOpenCursor( | 179 void OnOpenCursor( |
| 192 const ViewHostMsg_IDBObjectStoreOpenCursor_Params& params, | 180 const IndexedDBHostMsg_ObjectStoreOpenCursor_Params& params, |
| 193 IPC::Message* reply_msg); | 181 IPC::Message* reply_msg); |
| 194 void OnDestroyed(int32 idb_object_store_id); | 182 void OnDestroyed(int32 idb_object_store_id); |
| 195 | 183 |
| 196 IndexedDBDispatcherHost* parent_; | 184 IndexedDBDispatcherHost* parent_; |
| 197 IDMap<WebKit::WebIDBObjectStore, IDMapOwnPointer> map_; | 185 IDMap<WebKit::WebIDBObjectStore, IDMapOwnPointer> map_; |
| 198 }; | 186 }; |
| 199 | 187 |
| 200 class CursorDispatcherHost { | 188 class CursorDispatcherHost { |
| 201 public: | 189 public: |
| 202 explicit CursorDispatcherHost(IndexedDBDispatcherHost* parent); | 190 explicit CursorDispatcherHost(IndexedDBDispatcherHost* parent); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 const string16& name, | 228 const string16& name, |
| 241 IPC::Message* reply_msg); | 229 IPC::Message* reply_msg); |
| 242 void OnDidCompleteTaskEvents(int transaction_id); | 230 void OnDidCompleteTaskEvents(int transaction_id); |
| 243 void OnDestroyed(int32 idb_transaction_id); | 231 void OnDestroyed(int32 idb_transaction_id); |
| 244 | 232 |
| 245 IndexedDBDispatcherHost* parent_; | 233 IndexedDBDispatcherHost* parent_; |
| 246 typedef IDMap<WebKit::WebIDBTransaction, IDMapOwnPointer> MapType; | 234 typedef IDMap<WebKit::WebIDBTransaction, IDMapOwnPointer> MapType; |
| 247 MapType map_; | 235 MapType map_; |
| 248 }; | 236 }; |
| 249 | 237 |
| 250 // Only use on the IO thread. | |
| 251 IPC::Message::Sender* sender_; | |
| 252 | |
| 253 // Data shared between renderer processes with the same profile. | 238 // Data shared between renderer processes with the same profile. |
| 254 scoped_refptr<WebKitContext> webkit_context_; | 239 scoped_refptr<WebKitContext> webkit_context_; |
| 255 | 240 |
| 256 // Tells us whether the user wants to allow databases to be opened. | 241 // Tells us whether the user wants to allow databases to be opened. |
| 257 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; | 242 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; |
| 258 | 243 |
| 259 // Only access on WebKit thread. | 244 // Only access on WebKit thread. |
| 260 scoped_ptr<DatabaseDispatcherHost> database_dispatcher_host_; | 245 scoped_ptr<DatabaseDispatcherHost> database_dispatcher_host_; |
| 261 scoped_ptr<IndexDispatcherHost> index_dispatcher_host_; | 246 scoped_ptr<IndexDispatcherHost> index_dispatcher_host_; |
| 262 scoped_ptr<ObjectStoreDispatcherHost> object_store_dispatcher_host_; | 247 scoped_ptr<ObjectStoreDispatcherHost> object_store_dispatcher_host_; |
| 263 scoped_ptr<CursorDispatcherHost> cursor_dispatcher_host_; | 248 scoped_ptr<CursorDispatcherHost> cursor_dispatcher_host_; |
| 264 scoped_ptr<TransactionDispatcherHost> transaction_dispatcher_host_; | 249 scoped_ptr<TransactionDispatcherHost> transaction_dispatcher_host_; |
| 265 | 250 |
| 266 // If we get a corrupt message from a renderer, we need to kill it using this | |
| 267 // handle. | |
| 268 base::ProcessHandle process_handle_; | |
| 269 | |
| 270 // Used to dispatch messages to the correct view host. | 251 // Used to dispatch messages to the correct view host. |
| 271 int process_id_; | 252 int process_id_; |
| 272 | 253 |
| 273 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); | 254 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); |
| 274 }; | 255 }; |
| 275 | 256 |
| 276 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_ | 257 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_ |
| OLD | NEW |