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 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ |
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/id_map.h" | 12 #include "base/id_map.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
14 #include "content/public/browser/browser_message_filter.h" | 15 #include "content/public/browser/browser_message_filter.h" |
| 16 #include "net/url_request/url_request_context_getter.h" |
15 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 18 #include "webkit/browser/blob/blob_data_handle.h" |
16 | 19 |
17 struct IndexedDBDatabaseMetadata; | 20 struct IndexedDBDatabaseMetadata; |
18 struct IndexedDBHostMsg_DatabaseCount_Params; | 21 struct IndexedDBHostMsg_DatabaseCount_Params; |
19 struct IndexedDBHostMsg_DatabaseCreateIndex_Params; | 22 struct IndexedDBHostMsg_DatabaseCreateIndex_Params; |
20 struct IndexedDBHostMsg_DatabaseCreateObjectStore_Params; | 23 struct IndexedDBHostMsg_DatabaseCreateObjectStore_Params; |
21 struct IndexedDBHostMsg_DatabaseCreateTransaction_Params; | 24 struct IndexedDBHostMsg_DatabaseCreateTransaction_Params; |
22 struct IndexedDBHostMsg_DatabaseDeleteRange_Params; | 25 struct IndexedDBHostMsg_DatabaseDeleteRange_Params; |
23 struct IndexedDBHostMsg_DatabaseGet_Params; | 26 struct IndexedDBHostMsg_DatabaseGet_Params; |
24 struct IndexedDBHostMsg_DatabaseOpenCursor_Params; | 27 struct IndexedDBHostMsg_DatabaseOpenCursor_Params; |
25 struct IndexedDBHostMsg_DatabasePut_Params; | 28 struct IndexedDBHostMsg_DatabasePut_Params; |
26 struct IndexedDBHostMsg_DatabaseSetIndexKeys_Params; | 29 struct IndexedDBHostMsg_DatabaseSetIndexKeys_Params; |
27 struct IndexedDBHostMsg_FactoryDeleteDatabase_Params; | 30 struct IndexedDBHostMsg_FactoryDeleteDatabase_Params; |
28 struct IndexedDBHostMsg_FactoryGetDatabaseNames_Params; | 31 struct IndexedDBHostMsg_FactoryGetDatabaseNames_Params; |
29 struct IndexedDBHostMsg_FactoryOpen_Params; | 32 struct IndexedDBHostMsg_FactoryOpen_Params; |
30 | 33 |
31 namespace content { | 34 namespace content { |
32 class IndexedDBConnection; | 35 class IndexedDBConnection; |
33 class IndexedDBContextImpl; | 36 class IndexedDBContextImpl; |
34 class IndexedDBCursor; | 37 class IndexedDBCursor; |
35 class IndexedDBKey; | 38 class IndexedDBKey; |
36 class IndexedDBKeyPath; | 39 class IndexedDBKeyPath; |
37 class IndexedDBKeyRange; | 40 class IndexedDBKeyRange; |
38 struct IndexedDBDatabaseMetadata; | 41 struct IndexedDBDatabaseMetadata; |
39 | 42 |
40 // Handles all IndexedDB related messages from a particular renderer process. | 43 // Handles all IndexedDB related messages from a particular renderer process. |
41 class IndexedDBDispatcherHost : public BrowserMessageFilter { | 44 class IndexedDBDispatcherHost : public BrowserMessageFilter { |
42 public: | 45 public: |
43 // Only call the constructor from the UI thread. | 46 // Only call the constructor from the UI thread. |
44 explicit IndexedDBDispatcherHost(IndexedDBContextImpl* indexed_db_context); | 47 IndexedDBDispatcherHost(int ipc_process_id, |
| 48 net::URLRequestContextGetter* request_context_getter, |
| 49 IndexedDBContextImpl* indexed_db_context, |
| 50 ChromeBlobStorageContext* blob_storage_context); |
| 51 IndexedDBDispatcherHost(int ipc_process_id, |
| 52 net::URLRequestContext* request_context, |
| 53 IndexedDBContextImpl* indexed_db_context, |
| 54 ChromeBlobStorageContext* blob_storage_context); |
45 | 55 |
46 static ::IndexedDBDatabaseMetadata ConvertMetadata( | 56 static ::IndexedDBDatabaseMetadata ConvertMetadata( |
47 const content::IndexedDBDatabaseMetadata& metadata); | 57 const content::IndexedDBDatabaseMetadata& metadata); |
48 | 58 |
49 // BrowserMessageFilter implementation. | 59 // BrowserMessageFilter implementation. |
| 60 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
50 virtual void OnChannelClosing() OVERRIDE; | 61 virtual void OnChannelClosing() OVERRIDE; |
51 virtual void OnDestruct() const OVERRIDE; | 62 virtual void OnDestruct() const OVERRIDE; |
52 virtual base::TaskRunner* OverrideTaskRunnerForMessage( | 63 virtual base::TaskRunner* OverrideTaskRunnerForMessage( |
53 const IPC::Message& message) OVERRIDE; | 64 const IPC::Message& message) OVERRIDE; |
54 virtual bool OnMessageReceived(const IPC::Message& message, | 65 virtual bool OnMessageReceived(const IPC::Message& message, |
55 bool* message_was_ok) OVERRIDE; | 66 bool* message_was_ok) OVERRIDE; |
56 | 67 |
57 void FinishTransaction(int64 host_transaction_id, bool committed); | 68 void FinishTransaction(int64 host_transaction_id, bool committed); |
58 | 69 |
59 // A shortcut for accessing our context. | 70 // A shortcut for accessing our context. |
60 IndexedDBContextImpl* Context() { return indexed_db_context_; } | 71 IndexedDBContextImpl* Context() { return indexed_db_context_; } |
| 72 webkit_blob::BlobStorageContext* blob_storage_context() { |
| 73 return blob_storage_context_->context(); |
| 74 } |
61 | 75 |
62 // IndexedDBCallbacks call these methods to add the results into the | 76 // IndexedDBCallbacks call these methods to add the results into the |
63 // applicable map. See below for more details. | 77 // applicable map. See below for more details. |
64 int32 Add(IndexedDBCursor* cursor); | 78 int32 Add(IndexedDBCursor* cursor); |
65 int32 Add(IndexedDBConnection* connection, | 79 int32 Add(IndexedDBConnection* connection, |
66 int32 ipc_thread_id, | 80 int32 ipc_thread_id, |
67 const GURL& origin_url); | 81 const GURL& origin_url); |
68 | 82 |
69 void RegisterTransactionId(int64 host_transaction_id, const GURL& origin_url); | 83 void RegisterTransactionId(int64 host_transaction_id, const GURL& origin_url); |
70 | 84 |
71 IndexedDBCursor* GetCursorFromId(int32 ipc_cursor_id); | 85 IndexedDBCursor* GetCursorFromId(int32 ipc_cursor_id); |
72 | 86 |
73 // These are called to map a 32-bit front-end (renderer-specific) transaction | 87 // These are called to map a 32-bit front-end (renderer-specific) transaction |
74 // id to and from a back-end ("host") transaction id that encodes the process | 88 // id to and from a back-end ("host") transaction id that encodes the process |
75 // id in the high 32 bits. The mapping is host-specific and ids are validated. | 89 // id in the high 32 bits. The mapping is host-specific and ids are validated. |
76 int64 HostTransactionId(int64 transaction_id); | 90 int64 HostTransactionId(int64 transaction_id); |
77 int64 RendererTransactionId(int64 host_transaction_id); | 91 int64 RendererTransactionId(int64 host_transaction_id); |
78 | 92 |
79 // These are called to decode a host transaction ID, for diagnostic purposes. | 93 // These are called to decode a host transaction ID, for diagnostic purposes. |
80 static uint32 TransactionIdToRendererTransactionId(int64 host_transaction_id); | 94 static uint32 TransactionIdToRendererTransactionId(int64 host_transaction_id); |
81 static uint32 TransactionIdToProcessId(int64 host_transaction_id); | 95 static uint32 TransactionIdToProcessId(int64 host_transaction_id); |
82 | 96 |
| 97 void HoldBlobDataHandle( |
| 98 const std::string& uuid, |
| 99 scoped_ptr<webkit_blob::BlobDataHandle>& blob_data_handle); |
| 100 void DropBlobDataHandle(const std::string& uuid); |
| 101 |
83 private: | 102 private: |
84 // Friends to enable OnDestruct() delegation. | 103 // Friends to enable OnDestruct() delegation. |
85 friend class BrowserThread; | 104 friend class BrowserThread; |
86 friend class base::DeleteHelper<IndexedDBDispatcherHost>; | 105 friend class base::DeleteHelper<IndexedDBDispatcherHost>; |
87 | 106 |
88 virtual ~IndexedDBDispatcherHost(); | 107 virtual ~IndexedDBDispatcherHost(); |
89 | 108 |
90 // Message processing. Most of the work is delegated to the dispatcher hosts | 109 // Message processing. Most of the work is delegated to the dispatcher hosts |
91 // below. | 110 // below. |
92 void OnIDBFactoryGetDatabaseNames( | 111 void OnIDBFactoryGetDatabaseNames( |
93 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& p); | 112 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& p); |
94 void OnIDBFactoryOpen(const IndexedDBHostMsg_FactoryOpen_Params& p); | 113 void OnIDBFactoryOpen(const IndexedDBHostMsg_FactoryOpen_Params& p); |
95 | 114 |
96 void OnIDBFactoryDeleteDatabase( | 115 void OnIDBFactoryDeleteDatabase( |
97 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& p); | 116 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& p); |
98 | 117 |
| 118 void OnAckReceivedBlobs(const std::vector<std::string>& uuids); |
| 119 void OnPutHelper(const IndexedDBHostMsg_DatabasePut_Params& params, |
| 120 std::vector<webkit_blob::BlobDataHandle*> handles); |
| 121 |
99 void ResetDispatcherHosts(); | 122 void ResetDispatcherHosts(); |
100 | 123 |
101 // IDMap for RefCounted types | 124 // IDMap for RefCounted types |
102 template <typename RefCountedType> | 125 template <typename RefCountedType> |
103 class RefIDMap { | 126 class RefIDMap { |
104 private: | 127 private: |
105 typedef int32 KeyType; | 128 typedef int32 KeyType; |
106 | 129 |
107 public: | 130 public: |
108 RefIDMap() {} | 131 RefIDMap() {} |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params); | 182 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params); |
160 void OnDeleteObjectStore(int32 ipc_database_id, | 183 void OnDeleteObjectStore(int32 ipc_database_id, |
161 int64 transaction_id, | 184 int64 transaction_id, |
162 int64 object_store_id); | 185 int64 object_store_id); |
163 void OnCreateTransaction( | 186 void OnCreateTransaction( |
164 const IndexedDBHostMsg_DatabaseCreateTransaction_Params&); | 187 const IndexedDBHostMsg_DatabaseCreateTransaction_Params&); |
165 void OnClose(int32 ipc_database_id); | 188 void OnClose(int32 ipc_database_id); |
166 void OnDestroyed(int32 ipc_database_id); | 189 void OnDestroyed(int32 ipc_database_id); |
167 | 190 |
168 void OnGet(const IndexedDBHostMsg_DatabaseGet_Params& params); | 191 void OnGet(const IndexedDBHostMsg_DatabaseGet_Params& params); |
169 void OnPut(const IndexedDBHostMsg_DatabasePut_Params& params); | 192 // OnPutWrapper starts on the IO thread so that it can grab BlobDataHandles |
| 193 // before posting to the IDB TaskRunner for the rest of the job. |
| 194 void OnPutWrapper(const IndexedDBHostMsg_DatabasePut_Params& params); |
| 195 void OnPut(const IndexedDBHostMsg_DatabasePut_Params& params, |
| 196 std::vector<webkit_blob::BlobDataHandle*> handles); |
170 void OnSetIndexKeys( | 197 void OnSetIndexKeys( |
171 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params); | 198 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params); |
172 void OnSetIndexesReady(int32 ipc_database_id, | 199 void OnSetIndexesReady(int32 ipc_database_id, |
173 int64 transaction_id, | 200 int64 transaction_id, |
174 int64 object_store_id, | 201 int64 object_store_id, |
175 const std::vector<int64>& ids); | 202 const std::vector<int64>& ids); |
176 void OnOpenCursor(const IndexedDBHostMsg_DatabaseOpenCursor_Params& params); | 203 void OnOpenCursor(const IndexedDBHostMsg_DatabaseOpenCursor_Params& params); |
177 void OnCount(const IndexedDBHostMsg_DatabaseCount_Params& params); | 204 void OnCount(const IndexedDBHostMsg_DatabaseCount_Params& params); |
178 void OnDeleteRange( | 205 void OnDeleteRange( |
179 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params); | 206 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 int n); | 248 int n); |
222 void OnPrefetchReset(int32 ipc_cursor_id, | 249 void OnPrefetchReset(int32 ipc_cursor_id, |
223 int used_prefetches, | 250 int used_prefetches, |
224 int unused_prefetches); | 251 int unused_prefetches); |
225 void OnDestroyed(int32 ipc_cursor_id); | 252 void OnDestroyed(int32 ipc_cursor_id); |
226 | 253 |
227 IndexedDBDispatcherHost* parent_; | 254 IndexedDBDispatcherHost* parent_; |
228 RefIDMap<IndexedDBCursor> map_; | 255 RefIDMap<IndexedDBCursor> map_; |
229 }; | 256 }; |
230 | 257 |
| 258 // The getter holds the context until OnChannelConnected() can be called from |
| 259 // the IO thread, which will extract the net::URLRequestContext from it. |
| 260 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 261 net::URLRequestContext* request_context_; |
231 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; | 262 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; |
| 263 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
| 264 |
| 265 typedef std::map<std::string, webkit_blob::BlobDataHandle*> BlobDataHandleMap; |
| 266 BlobDataHandleMap blob_data_handle_map_; |
232 | 267 |
233 // Only access on IndexedDB thread. | 268 // Only access on IndexedDB thread. |
234 scoped_ptr<DatabaseDispatcherHost> database_dispatcher_host_; | 269 scoped_ptr<DatabaseDispatcherHost> database_dispatcher_host_; |
235 scoped_ptr<CursorDispatcherHost> cursor_dispatcher_host_; | 270 scoped_ptr<CursorDispatcherHost> cursor_dispatcher_host_; |
236 | 271 |
| 272 // Used to set file permissions for blob storage. |
| 273 int ipc_process_id_; |
| 274 |
237 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); | 275 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); |
238 }; | 276 }; |
239 | 277 |
240 } // namespace content | 278 } // namespace content |
241 | 279 |
242 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ | 280 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ |
OLD | NEW |