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 <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/id_map.h" | 13 #include "base/id_map.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 15 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
16 #include "content/public/browser/browser_message_filter.h" | 16 #include "content/public/browser/browser_message_filter.h" |
17 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
19 #include "webkit/browser/blob/blob_data_handle.h" | 19 #include "storage/browser/blob/blob_data_handle.h" |
20 | 20 |
21 struct IndexedDBDatabaseMetadata; | 21 struct IndexedDBDatabaseMetadata; |
22 struct IndexedDBHostMsg_DatabaseCount_Params; | 22 struct IndexedDBHostMsg_DatabaseCount_Params; |
23 struct IndexedDBHostMsg_DatabaseCreateIndex_Params; | 23 struct IndexedDBHostMsg_DatabaseCreateIndex_Params; |
24 struct IndexedDBHostMsg_DatabaseCreateObjectStore_Params; | 24 struct IndexedDBHostMsg_DatabaseCreateObjectStore_Params; |
25 struct IndexedDBHostMsg_DatabaseCreateTransaction_Params; | 25 struct IndexedDBHostMsg_DatabaseCreateTransaction_Params; |
26 struct IndexedDBHostMsg_DatabaseDeleteRange_Params; | 26 struct IndexedDBHostMsg_DatabaseDeleteRange_Params; |
27 struct IndexedDBHostMsg_DatabaseGet_Params; | 27 struct IndexedDBHostMsg_DatabaseGet_Params; |
28 struct IndexedDBHostMsg_DatabaseOpenCursor_Params; | 28 struct IndexedDBHostMsg_DatabaseOpenCursor_Params; |
29 struct IndexedDBHostMsg_DatabasePut_Params; | 29 struct IndexedDBHostMsg_DatabasePut_Params; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 virtual void OnChannelClosing() OVERRIDE; | 62 virtual void OnChannelClosing() OVERRIDE; |
63 virtual void OnDestruct() const OVERRIDE; | 63 virtual void OnDestruct() const OVERRIDE; |
64 virtual base::TaskRunner* OverrideTaskRunnerForMessage( | 64 virtual base::TaskRunner* OverrideTaskRunnerForMessage( |
65 const IPC::Message& message) OVERRIDE; | 65 const IPC::Message& message) OVERRIDE; |
66 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 66 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
67 | 67 |
68 void FinishTransaction(int64 host_transaction_id, bool committed); | 68 void FinishTransaction(int64 host_transaction_id, bool committed); |
69 | 69 |
70 // A shortcut for accessing our context. | 70 // A shortcut for accessing our context. |
71 IndexedDBContextImpl* Context() { return indexed_db_context_; } | 71 IndexedDBContextImpl* Context() { return indexed_db_context_; } |
72 webkit_blob::BlobStorageContext* blob_storage_context() const { | 72 storage::BlobStorageContext* blob_storage_context() const { |
73 return blob_storage_context_->context(); | 73 return blob_storage_context_->context(); |
74 } | 74 } |
75 | 75 |
76 // IndexedDBCallbacks call these methods to add the results into the | 76 // IndexedDBCallbacks call these methods to add the results into the |
77 // applicable map. See below for more details. | 77 // applicable map. See below for more details. |
78 int32 Add(IndexedDBCursor* cursor); | 78 int32 Add(IndexedDBCursor* cursor); |
79 int32 Add(IndexedDBConnection* connection, | 79 int32 Add(IndexedDBConnection* connection, |
80 int32 ipc_thread_id, | 80 int32 ipc_thread_id, |
81 const GURL& origin_url); | 81 const GURL& origin_url); |
82 | 82 |
83 void RegisterTransactionId(int64 host_transaction_id, const GURL& origin_url); | 83 void RegisterTransactionId(int64 host_transaction_id, const GURL& origin_url); |
84 | 84 |
85 IndexedDBCursor* GetCursorFromId(int32 ipc_cursor_id); | 85 IndexedDBCursor* GetCursorFromId(int32 ipc_cursor_id); |
86 | 86 |
87 // 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 |
88 // 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 |
89 // 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. |
90 int64 HostTransactionId(int64 transaction_id); | 90 int64 HostTransactionId(int64 transaction_id); |
91 int64 RendererTransactionId(int64 host_transaction_id); | 91 int64 RendererTransactionId(int64 host_transaction_id); |
92 | 92 |
93 // 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. |
94 static uint32 TransactionIdToRendererTransactionId(int64 host_transaction_id); | 94 static uint32 TransactionIdToRendererTransactionId(int64 host_transaction_id); |
95 static uint32 TransactionIdToProcessId(int64 host_transaction_id); | 95 static uint32 TransactionIdToProcessId(int64 host_transaction_id); |
96 | 96 |
97 void HoldBlobDataHandle( | 97 void HoldBlobDataHandle(const std::string& uuid, |
98 const std::string& uuid, | 98 scoped_ptr<storage::BlobDataHandle> blob_data_handle); |
99 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle); | |
100 void DropBlobDataHandle(const std::string& uuid); | 99 void DropBlobDataHandle(const std::string& uuid); |
101 | 100 |
102 private: | 101 private: |
103 // Friends to enable OnDestruct() delegation. | 102 // Friends to enable OnDestruct() delegation. |
104 friend class BrowserThread; | 103 friend class BrowserThread; |
105 friend class base::DeleteHelper<IndexedDBDispatcherHost>; | 104 friend class base::DeleteHelper<IndexedDBDispatcherHost>; |
106 | 105 |
107 virtual ~IndexedDBDispatcherHost(); | 106 virtual ~IndexedDBDispatcherHost(); |
108 | 107 |
109 // Message processing. Most of the work is delegated to the dispatcher hosts | 108 // Message processing. Most of the work is delegated to the dispatcher hosts |
110 // below. | 109 // below. |
111 void OnIDBFactoryGetDatabaseNames( | 110 void OnIDBFactoryGetDatabaseNames( |
112 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& p); | 111 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& p); |
113 void OnIDBFactoryOpen(const IndexedDBHostMsg_FactoryOpen_Params& p); | 112 void OnIDBFactoryOpen(const IndexedDBHostMsg_FactoryOpen_Params& p); |
114 | 113 |
115 void OnIDBFactoryDeleteDatabase( | 114 void OnIDBFactoryDeleteDatabase( |
116 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& p); | 115 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& p); |
117 | 116 |
118 void OnAckReceivedBlobs(const std::vector<std::string>& uuids); | 117 void OnAckReceivedBlobs(const std::vector<std::string>& uuids); |
119 void OnPutHelper(const IndexedDBHostMsg_DatabasePut_Params& params, | 118 void OnPutHelper(const IndexedDBHostMsg_DatabasePut_Params& params, |
120 std::vector<webkit_blob::BlobDataHandle*> handles); | 119 std::vector<storage::BlobDataHandle*> handles); |
121 | 120 |
122 void ResetDispatcherHosts(); | 121 void ResetDispatcherHosts(); |
123 | 122 |
124 // IDMap for RefCounted types | 123 // IDMap for RefCounted types |
125 template <typename RefCountedType> | 124 template <typename RefCountedType> |
126 class RefIDMap { | 125 class RefIDMap { |
127 private: | 126 private: |
128 typedef int32 KeyType; | 127 typedef int32 KeyType; |
129 | 128 |
130 public: | 129 public: |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 const IndexedDBHostMsg_DatabaseCreateTransaction_Params&); | 188 const IndexedDBHostMsg_DatabaseCreateTransaction_Params&); |
190 void OnClose(int32 ipc_database_id); | 189 void OnClose(int32 ipc_database_id); |
191 void OnVersionChangeIgnored(int32 ipc_database_id); | 190 void OnVersionChangeIgnored(int32 ipc_database_id); |
192 void OnDestroyed(int32 ipc_database_id); | 191 void OnDestroyed(int32 ipc_database_id); |
193 | 192 |
194 void OnGet(const IndexedDBHostMsg_DatabaseGet_Params& params); | 193 void OnGet(const IndexedDBHostMsg_DatabaseGet_Params& params); |
195 // OnPutWrapper starts on the IO thread so that it can grab BlobDataHandles | 194 // OnPutWrapper starts on the IO thread so that it can grab BlobDataHandles |
196 // before posting to the IDB TaskRunner for the rest of the job. | 195 // before posting to the IDB TaskRunner for the rest of the job. |
197 void OnPutWrapper(const IndexedDBHostMsg_DatabasePut_Params& params); | 196 void OnPutWrapper(const IndexedDBHostMsg_DatabasePut_Params& params); |
198 void OnPut(const IndexedDBHostMsg_DatabasePut_Params& params, | 197 void OnPut(const IndexedDBHostMsg_DatabasePut_Params& params, |
199 std::vector<webkit_blob::BlobDataHandle*> handles); | 198 std::vector<storage::BlobDataHandle*> handles); |
200 void OnSetIndexKeys( | 199 void OnSetIndexKeys( |
201 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params); | 200 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params); |
202 void OnSetIndexesReady(int32 ipc_database_id, | 201 void OnSetIndexesReady(int32 ipc_database_id, |
203 int64 transaction_id, | 202 int64 transaction_id, |
204 int64 object_store_id, | 203 int64 object_store_id, |
205 const std::vector<int64>& ids); | 204 const std::vector<int64>& ids); |
206 void OnOpenCursor(const IndexedDBHostMsg_DatabaseOpenCursor_Params& params); | 205 void OnOpenCursor(const IndexedDBHostMsg_DatabaseOpenCursor_Params& params); |
207 void OnCount(const IndexedDBHostMsg_DatabaseCount_Params& params); | 206 void OnCount(const IndexedDBHostMsg_DatabaseCount_Params& params); |
208 void OnDeleteRange( | 207 void OnDeleteRange( |
209 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params); | 208 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 DISALLOW_COPY_AND_ASSIGN(CursorDispatcherHost); | 263 DISALLOW_COPY_AND_ASSIGN(CursorDispatcherHost); |
265 }; | 264 }; |
266 | 265 |
267 // The getter holds the context until OnChannelConnected() can be called from | 266 // The getter holds the context until OnChannelConnected() can be called from |
268 // the IO thread, which will extract the net::URLRequestContext from it. | 267 // the IO thread, which will extract the net::URLRequestContext from it. |
269 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 268 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
270 net::URLRequestContext* request_context_; | 269 net::URLRequestContext* request_context_; |
271 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; | 270 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; |
272 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; | 271 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
273 | 272 |
274 typedef std::map<std::string, webkit_blob::BlobDataHandle*> BlobDataHandleMap; | 273 typedef std::map<std::string, storage::BlobDataHandle*> BlobDataHandleMap; |
275 BlobDataHandleMap blob_data_handle_map_; | 274 BlobDataHandleMap blob_data_handle_map_; |
276 | 275 |
277 // Only access on IndexedDB thread. | 276 // Only access on IndexedDB thread. |
278 scoped_ptr<DatabaseDispatcherHost> database_dispatcher_host_; | 277 scoped_ptr<DatabaseDispatcherHost> database_dispatcher_host_; |
279 scoped_ptr<CursorDispatcherHost> cursor_dispatcher_host_; | 278 scoped_ptr<CursorDispatcherHost> cursor_dispatcher_host_; |
280 | 279 |
281 // Used to set file permissions for blob storage. | 280 // Used to set file permissions for blob storage. |
282 int ipc_process_id_; | 281 int ipc_process_id_; |
283 | 282 |
284 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); | 283 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); |
285 }; | 284 }; |
286 | 285 |
287 } // namespace content | 286 } // namespace content |
288 | 287 |
289 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ | 288 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ |
OLD | NEW |