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

Side by Side Diff: content/browser/indexed_db/indexed_db_dispatcher_host.h

Issue 18023022: Blob support for IDB [Chromium] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: small cleanup Created 7 years 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 | Annotate | Revision Log
OLDNEW
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(
48 int ipc_process_id,
49 net::URLRequestContextGetter* request_context_getter,
50 IndexedDBContextImpl* indexed_db_context,
51 ChromeBlobStorageContext* blob_storage_context);
52 IndexedDBDispatcherHost(
53 int ipc_process_id,
54 net::URLRequestContext* request_context,
55 IndexedDBContextImpl* indexed_db_context,
56 ChromeBlobStorageContext* blob_storage_context);
45 57
46 static ::IndexedDBDatabaseMetadata ConvertMetadata( 58 static ::IndexedDBDatabaseMetadata ConvertMetadata(
47 const content::IndexedDBDatabaseMetadata& metadata); 59 const content::IndexedDBDatabaseMetadata& metadata);
48 60
49 // BrowserMessageFilter implementation. 61 // BrowserMessageFilter implementation.
62 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
50 virtual void OnChannelClosing() OVERRIDE; 63 virtual void OnChannelClosing() OVERRIDE;
51 virtual void OnDestruct() const OVERRIDE; 64 virtual void OnDestruct() const OVERRIDE;
52 virtual base::TaskRunner* OverrideTaskRunnerForMessage( 65 virtual base::TaskRunner* OverrideTaskRunnerForMessage(
53 const IPC::Message& message) OVERRIDE; 66 const IPC::Message& message) OVERRIDE;
54 virtual bool OnMessageReceived(const IPC::Message& message, 67 virtual bool OnMessageReceived(const IPC::Message& message,
55 bool* message_was_ok) OVERRIDE; 68 bool* message_was_ok) OVERRIDE;
56 69
57 void FinishTransaction(int64 host_transaction_id, bool committed); 70 void FinishTransaction(int64 host_transaction_id, bool committed);
58 71
59 // A shortcut for accessing our context. 72 // A shortcut for accessing our context.
60 IndexedDBContextImpl* Context() { return indexed_db_context_; } 73 IndexedDBContextImpl* Context() { return indexed_db_context_; }
74 webkit_blob::BlobStorageContext* blob_storage_context() {
75 return blob_storage_context_->context();
76 }
61 77
62 // IndexedDBCallbacks call these methods to add the results into the 78 // IndexedDBCallbacks call these methods to add the results into the
63 // applicable map. See below for more details. 79 // applicable map. See below for more details.
64 int32 Add(IndexedDBCursor* cursor); 80 int32 Add(IndexedDBCursor* cursor);
65 int32 Add(IndexedDBConnection* connection, 81 int32 Add(IndexedDBConnection* connection,
66 int32 ipc_thread_id, 82 int32 ipc_thread_id,
67 const GURL& origin_url); 83 const GURL& origin_url);
68 84
69 void RegisterTransactionId(int64 host_transaction_id, const GURL& origin_url); 85 void RegisterTransactionId(int64 host_transaction_id, const GURL& origin_url);
70 86
71 IndexedDBCursor* GetCursorFromId(int32 ipc_cursor_id); 87 IndexedDBCursor* GetCursorFromId(int32 ipc_cursor_id);
72 88
73 // These are called to map a 32-bit front-end (renderer-specific) transaction 89 // 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 90 // 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. 91 // id in the high 32 bits. The mapping is host-specific and ids are validated.
76 int64 HostTransactionId(int64 transaction_id); 92 int64 HostTransactionId(int64 transaction_id);
77 int64 RendererTransactionId(int64 host_transaction_id); 93 int64 RendererTransactionId(int64 host_transaction_id);
78 94
79 // These are called to decode a host transaction ID, for diagnostic purposes. 95 // These are called to decode a host transaction ID, for diagnostic purposes.
80 static uint32 TransactionIdToRendererTransactionId(int64 host_transaction_id); 96 static uint32 TransactionIdToRendererTransactionId(int64 host_transaction_id);
81 static uint32 TransactionIdToProcessId(int64 host_transaction_id); 97 static uint32 TransactionIdToProcessId(int64 host_transaction_id);
82 98
99 void HoldBlobDataHandle(
100 const std::string& uuid,
101 scoped_ptr<webkit_blob::BlobDataHandle>& blob_data_handle);
102 void DropBlobDataHandle(const std::string& uuid);
103
83 private: 104 private:
84 // Friends to enable OnDestruct() delegation. 105 // Friends to enable OnDestruct() delegation.
85 friend class BrowserThread; 106 friend class BrowserThread;
86 friend class base::DeleteHelper<IndexedDBDispatcherHost>; 107 friend class base::DeleteHelper<IndexedDBDispatcherHost>;
87 108
88 virtual ~IndexedDBDispatcherHost(); 109 virtual ~IndexedDBDispatcherHost();
89 110
90 // Message processing. Most of the work is delegated to the dispatcher hosts 111 // Message processing. Most of the work is delegated to the dispatcher hosts
91 // below. 112 // below.
92 void OnIDBFactoryGetDatabaseNames( 113 void OnIDBFactoryGetDatabaseNames(
93 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& p); 114 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& p);
94 void OnIDBFactoryOpen(const IndexedDBHostMsg_FactoryOpen_Params& p); 115 void OnIDBFactoryOpen(const IndexedDBHostMsg_FactoryOpen_Params& p);
95 116
96 void OnIDBFactoryDeleteDatabase( 117 void OnIDBFactoryDeleteDatabase(
97 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& p); 118 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& p);
98 119
120 void OnAckReceivedBlobs(const std::vector<std::string>& uuids);
121 void OnPutHelper(const IndexedDBHostMsg_DatabasePut_Params& params,
122 std::vector<webkit_blob::BlobDataHandle*> handles);
123
99 void ResetDispatcherHosts(); 124 void ResetDispatcherHosts();
100 125
101 // IDMap for RefCounted types 126 // IDMap for RefCounted types
102 template <typename RefCountedType> 127 template <typename RefCountedType>
103 class RefIDMap { 128 class RefIDMap {
104 private: 129 private:
105 typedef int32 KeyType; 130 typedef int32 KeyType;
106 131
107 public: 132 public:
108 RefIDMap() {} 133 RefIDMap() {}
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params); 184 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params);
160 void OnDeleteObjectStore(int32 ipc_database_id, 185 void OnDeleteObjectStore(int32 ipc_database_id,
161 int64 transaction_id, 186 int64 transaction_id,
162 int64 object_store_id); 187 int64 object_store_id);
163 void OnCreateTransaction( 188 void OnCreateTransaction(
164 const IndexedDBHostMsg_DatabaseCreateTransaction_Params&); 189 const IndexedDBHostMsg_DatabaseCreateTransaction_Params&);
165 void OnClose(int32 ipc_database_id); 190 void OnClose(int32 ipc_database_id);
166 void OnDestroyed(int32 ipc_database_id); 191 void OnDestroyed(int32 ipc_database_id);
167 192
168 void OnGet(const IndexedDBHostMsg_DatabaseGet_Params& params); 193 void OnGet(const IndexedDBHostMsg_DatabaseGet_Params& params);
169 void OnPut(const IndexedDBHostMsg_DatabasePut_Params& params); 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
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698