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

Side by Side Diff: content/browser/in_process_webkit/indexed_db_dispatcher_host.cc

Issue 15659013: Revert "Migrate the IndexedDB backend from Blink to Chromium" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months 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 #include "content/browser/in_process_webkit/indexed_db_dispatcher_host.h" 5 #include "content/browser/in_process_webkit/indexed_db_dispatcher_host.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 23 matching lines...) Expand all
34 #include "webkit/base/file_path_string_conversions.h" 34 #include "webkit/base/file_path_string_conversions.h"
35 #include "webkit/base/origin_url_conversions.h" 35 #include "webkit/base/origin_url_conversions.h"
36 #include "webkit/browser/database/database_util.h" 36 #include "webkit/browser/database/database_util.h"
37 37
38 using webkit_database::DatabaseUtil; 38 using webkit_database::DatabaseUtil;
39 using WebKit::WebData; 39 using WebKit::WebData;
40 using WebKit::WebIDBCallbacks; 40 using WebKit::WebIDBCallbacks;
41 using WebKit::WebIDBCursor; 41 using WebKit::WebIDBCursor;
42 using WebKit::WebIDBDatabase; 42 using WebKit::WebIDBDatabase;
43 using WebKit::WebIDBDatabaseError; 43 using WebKit::WebIDBDatabaseError;
44 using WebKit::WebIDBIndex;
44 using WebKit::WebIDBKey; 45 using WebKit::WebIDBKey;
45 using WebKit::WebIDBMetadata; 46 using WebKit::WebIDBMetadata;
47 using WebKit::WebIDBObjectStore;
46 using WebKit::WebString; 48 using WebKit::WebString;
47 using WebKit::WebVector; 49 using WebKit::WebVector;
48 50
49 namespace content { 51 namespace content {
50 namespace { 52 namespace {
51 53
52 template <class T> void DeleteOnWebKitThread(T* obj) { 54 template <class T>
53 if (!BrowserThread::DeleteSoon( 55 void DeleteOnWebKitThread(T* obj) {
54 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, obj)) 56 if (!BrowserThread::DeleteSoon(BrowserThread::WEBKIT_DEPRECATED,
57 FROM_HERE, obj))
55 delete obj; 58 delete obj;
56 } 59 }
57 } 60 }
58 61
59 IndexedDBDispatcherHost::IndexedDBDispatcherHost( 62 IndexedDBDispatcherHost::IndexedDBDispatcherHost(
60 int ipc_process_id, 63 int ipc_process_id, IndexedDBContextImpl* indexed_db_context)
61 IndexedDBContextImpl* indexed_db_context)
62 : indexed_db_context_(indexed_db_context), 64 : indexed_db_context_(indexed_db_context),
63 database_dispatcher_host_(new DatabaseDispatcherHost(this)), 65 database_dispatcher_host_(new DatabaseDispatcherHost(this)),
64 cursor_dispatcher_host_(new CursorDispatcherHost(this)), 66 cursor_dispatcher_host_(new CursorDispatcherHost(this)),
65 ipc_process_id_(ipc_process_id) { 67 ipc_process_id_(ipc_process_id) {
66 DCHECK(indexed_db_context_.get()); 68 DCHECK(indexed_db_context_.get());
67 } 69 }
68 70
69 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() {} 71 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() {
72 }
70 73
71 void IndexedDBDispatcherHost::OnChannelClosing() { 74 void IndexedDBDispatcherHost::OnChannelClosing() {
72 BrowserMessageFilter::OnChannelClosing(); 75 BrowserMessageFilter::OnChannelClosing();
73 76
74 bool success = BrowserThread::PostTask( 77 bool success = BrowserThread::PostTask(
75 BrowserThread::WEBKIT_DEPRECATED, 78 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
76 FROM_HERE,
77 base::Bind(&IndexedDBDispatcherHost::ResetDispatcherHosts, this)); 79 base::Bind(&IndexedDBDispatcherHost::ResetDispatcherHosts, this));
78 80
79 if (!success) 81 if (!success)
80 ResetDispatcherHosts(); 82 ResetDispatcherHosts();
81 } 83 }
82 84
83 void IndexedDBDispatcherHost::ResetDispatcherHosts() { 85 void IndexedDBDispatcherHost::ResetDispatcherHosts() {
84 // It is important that the various *_dispatcher_host_ members are reset 86 // It is important that the various *_dispatcher_host_ members are reset
85 // on the WebKit thread, since there might be incoming messages on that 87 // on the WebKit thread, since there might be incoming messages on that
86 // thread, and we must not reset the dispatcher hosts until after those 88 // thread, and we must not reset the dispatcher hosts until after those
(...skipping 23 matching lines...) Expand all
110 112
111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
112 114
113 bool handled = 115 bool handled =
114 database_dispatcher_host_->OnMessageReceived(message, message_was_ok) || 116 database_dispatcher_host_->OnMessageReceived(message, message_was_ok) ||
115 cursor_dispatcher_host_->OnMessageReceived(message, message_was_ok); 117 cursor_dispatcher_host_->OnMessageReceived(message, message_was_ok);
116 118
117 if (!handled) { 119 if (!handled) {
118 handled = true; 120 handled = true;
119 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost, message, *message_was_ok) 121 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost, message, *message_was_ok)
120 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryGetDatabaseNames, 122 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryGetDatabaseNames,
121 OnIDBFactoryGetDatabaseNames) 123 OnIDBFactoryGetDatabaseNames)
122 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryOpen, OnIDBFactoryOpen) 124 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryOpen, OnIDBFactoryOpen)
123 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryDeleteDatabase, 125 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryDeleteDatabase,
124 OnIDBFactoryDeleteDatabase) 126 OnIDBFactoryDeleteDatabase)
125 IPC_MESSAGE_UNHANDLED(handled = false) 127 IPC_MESSAGE_UNHANDLED(handled = false)
126 IPC_END_MESSAGE_MAP() 128 IPC_END_MESSAGE_MAP()
127 } 129 }
128 return handled; 130 return handled;
129 } 131 }
130 132
131 int32 IndexedDBDispatcherHost::Add(WebIDBCursor* idb_cursor) { 133 int32 IndexedDBDispatcherHost::Add(WebIDBCursor* idb_cursor) {
132 if (!cursor_dispatcher_host_) { 134 if (!cursor_dispatcher_host_) {
133 delete idb_cursor; 135 delete idb_cursor;
134 return 0; 136 return 0;
135 } 137 }
136 return cursor_dispatcher_host_->map_.Add(idb_cursor); 138 return cursor_dispatcher_host_->map_.Add(idb_cursor);
137 } 139 }
138 140
139 int32 IndexedDBDispatcherHost::Add(WebIDBDatabase* idb_database, 141 int32 IndexedDBDispatcherHost::Add(WebIDBDatabase* idb_database,
140 int32 ipc_thread_id, 142 int32 ipc_thread_id,
141 const GURL& origin_url) { 143 const GURL& origin_url) {
142 if (!database_dispatcher_host_) { 144 if (!database_dispatcher_host_) {
143 delete idb_database; 145 delete idb_database;
144 return 0; 146 return 0;
145 } 147 }
146 int32 ipc_database_id = database_dispatcher_host_->map_.Add(idb_database); 148 int32 ipc_database_id = database_dispatcher_host_->map_.Add(idb_database);
147 Context()->ConnectionOpened(origin_url, idb_database); 149 Context()->ConnectionOpened(origin_url, idb_database);
148 database_dispatcher_host_->database_url_map_[ipc_database_id] = origin_url; 150 database_dispatcher_host_->database_url_map_[ipc_database_id] = origin_url;
149 return ipc_database_id; 151 return ipc_database_id;
150 } 152 }
151 153
152 void IndexedDBDispatcherHost::RegisterTransactionId(int64 host_transaction_id, 154 void IndexedDBDispatcherHost::RegisterTransactionId(
153 const GURL& url) { 155 int64 host_transaction_id,
156 const GURL& url)
157 {
154 if (!database_dispatcher_host_) 158 if (!database_dispatcher_host_)
155 return; 159 return;
156 database_dispatcher_host_->transaction_url_map_[host_transaction_id] = url; 160 database_dispatcher_host_->transaction_url_map_[host_transaction_id] = url;
157 } 161 }
158 162
159 int64 IndexedDBDispatcherHost::HostTransactionId(int64 transaction_id) { 163 int64 IndexedDBDispatcherHost::HostTransactionId(int64 transaction_id) {
160 // Inject the renderer process id into the transaction id, to 164 // Inject the renderer process id into the transaction id, to
161 // uniquely identify this transaction, and effectively bind it to 165 // uniquely identify this transaction, and effectively bind it to
162 // the renderer that initiated it. The lower 32 bits of 166 // the renderer that initiated it. The lower 32 bits of
163 // transaction_id are guaranteed to be unique within that renderer. 167 // transaction_id are guaranteed to be unique within that renderer.
164 base::ProcessId pid = base::GetProcId(peer_handle()); 168 base::ProcessId pid = base::GetProcId(peer_handle());
165 DCHECK(!(transaction_id >> 32)) << "Transaction ids can only be 32 bits"; 169 DCHECK(!(transaction_id >> 32)) << "Transaction ids can only be 32 bits";
166 COMPILE_ASSERT(sizeof(base::ProcessId) <= sizeof(int32), 170 COMPILE_ASSERT(sizeof(base::ProcessId) <= sizeof(int32),
167 Process_ID_must_fit_in_32_bits); 171 Process_ID_must_fit_in_32_bits);
168 172
169 return transaction_id | (static_cast<uint64>(pid) << 32); 173 return transaction_id | (static_cast<uint64>(pid) << 32);
170 } 174 }
171 175
172 int64 IndexedDBDispatcherHost::RendererTransactionId( 176 int64 IndexedDBDispatcherHost::RendererTransactionId(
173 int64 host_transaction_id) { 177 int64 host_transaction_id) {
174 DCHECK(host_transaction_id >> 32 == base::GetProcId(peer_handle())) 178 DCHECK(host_transaction_id >> 32 == base::GetProcId(peer_handle())) <<
175 << "Invalid renderer target for transaction id"; 179 "Invalid renderer target for transaction id";
176 return host_transaction_id & 0xffffffff; 180 return host_transaction_id & 0xffffffff;
177 } 181 }
178 182
179 WebIDBCursor* IndexedDBDispatcherHost::GetCursorFromId(int32 ipc_cursor_id) { 183 WebIDBCursor* IndexedDBDispatcherHost::GetCursorFromId(int32 ipc_cursor_id) {
180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
181 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id); 185 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id);
182 } 186 }
183 187
184 IndexedDBDatabaseMetadata IndexedDBDispatcherHost::ConvertMetadata( 188 IndexedDBDatabaseMetadata IndexedDBDispatcherHost::ConvertMetadata(
185 const WebIDBMetadata& web_metadata) { 189 const WebIDBMetadata& web_metadata)
190 {
186 IndexedDBDatabaseMetadata metadata; 191 IndexedDBDatabaseMetadata metadata;
187 metadata.id = web_metadata.id; 192 metadata.id = web_metadata.id;
188 metadata.name = web_metadata.name; 193 metadata.name = web_metadata.name;
189 metadata.version = web_metadata.version; 194 metadata.version = web_metadata.version;
190 metadata.int_version = web_metadata.intVersion; 195 metadata.int_version = web_metadata.intVersion;
191 metadata.max_object_store_id = web_metadata.maxObjectStoreId; 196 metadata.max_object_store_id = web_metadata.maxObjectStoreId;
192 197
193 for (size_t i = 0; i < web_metadata.objectStores.size(); ++i) { 198 for (size_t i = 0; i < web_metadata.objectStores.size(); ++i) {
194 const WebIDBMetadata::ObjectStore& web_store_metadata = 199 const WebIDBMetadata::ObjectStore& web_store_metadata =
195 web_metadata.objectStores[i]; 200 web_metadata.objectStores[i];
(...skipping 19 matching lines...) Expand all
215 } 220 }
216 return metadata; 221 return metadata;
217 } 222 }
218 223
219 void IndexedDBDispatcherHost::OnIDBFactoryGetDatabaseNames( 224 void IndexedDBDispatcherHost::OnIDBFactoryGetDatabaseNames(
220 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& params) { 225 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& params) {
221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
222 base::FilePath indexed_db_path = indexed_db_context_->data_path(); 227 base::FilePath indexed_db_path = indexed_db_context_->data_path();
223 228
224 Context()->GetIDBFactory()->getDatabaseNames( 229 Context()->GetIDBFactory()->getDatabaseNames(
225 new IndexedDBCallbacks<WebVector<WebString> >( 230 new IndexedDBCallbacks<WebVector<WebString> >(this, params.ipc_thread_id,
226 this, params.ipc_thread_id, params.ipc_callbacks_id), 231 params.ipc_callbacks_id), params.database_identifier,
227 params.database_identifier,
228 webkit_base::FilePathToWebString(indexed_db_path)); 232 webkit_base::FilePathToWebString(indexed_db_path));
229 } 233 }
230 234
231 void IndexedDBDispatcherHost::OnIDBFactoryOpen( 235 void IndexedDBDispatcherHost::OnIDBFactoryOpen(
232 const IndexedDBHostMsg_FactoryOpen_Params& params) { 236 const IndexedDBHostMsg_FactoryOpen_Params& params) {
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
234 base::FilePath indexed_db_path = indexed_db_context_->data_path(); 238 base::FilePath indexed_db_path = indexed_db_context_->data_path();
235 239
236 GURL origin_url = 240 GURL origin_url =
237 webkit_base::GetOriginURLFromIdentifier(params.database_identifier); 241 webkit_base::GetOriginURLFromIdentifier(params.database_identifier);
238 242
239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
240 244
241 int64 host_transaction_id = HostTransactionId(params.transaction_id); 245 int64 host_transaction_id = HostTransactionId(params.transaction_id);
242 246
243 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore 247 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore
244 // created) if this origin is already over quota. 248 // created) if this origin is already over quota.
245 Context()->GetIDBFactory() 249 Context()->GetIDBFactory()->open(
246 ->open(params.name, 250 params.name,
247 params.version, 251 params.version,
248 host_transaction_id, 252 host_transaction_id,
249 new IndexedDBCallbacksDatabase(this, 253 new IndexedDBCallbacksDatabase(this, params.ipc_thread_id,
250 params.ipc_thread_id, 254 params.ipc_callbacks_id,
251 params.ipc_callbacks_id, 255 params.ipc_database_callbacks_id,
252 params.ipc_database_callbacks_id, 256 host_transaction_id,
253 host_transaction_id, 257 origin_url),
254 origin_url), 258 new IndexedDBDatabaseCallbacks(this, params.ipc_thread_id,
255 new IndexedDBDatabaseCallbacks( 259 params.ipc_database_callbacks_id),
256 this, params.ipc_thread_id, params.ipc_database_callbacks_id), 260 params.database_identifier,
257 params.database_identifier, 261 webkit_base::FilePathToWebString(indexed_db_path));
258 webkit_base::FilePathToWebString(indexed_db_path));
259 } 262 }
260 263
261 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( 264 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase(
262 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) { 265 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) {
263 base::FilePath indexed_db_path = indexed_db_context_->data_path(); 266 base::FilePath indexed_db_path = indexed_db_context_->data_path();
264 267
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
266 Context()->GetIDBFactory() 269 Context()->GetIDBFactory()->deleteDatabase(
267 ->deleteDatabase(params.name, 270 params.name,
268 new IndexedDBCallbacks<WebData>( 271 new IndexedDBCallbacks<WebData>(this,
269 this, params.ipc_thread_id, params.ipc_callbacks_id), 272 params.ipc_thread_id,
270 params.database_identifier, 273 params.ipc_callbacks_id),
271 webkit_base::FilePathToWebString(indexed_db_path)); 274 params.database_identifier,
275 webkit_base::FilePathToWebString(indexed_db_path));
272 } 276 }
273 277
274 void IndexedDBDispatcherHost::FinishTransaction(int64 host_transaction_id, 278 void IndexedDBDispatcherHost::FinishTransaction(
275 bool committed) { 279 int64 host_transaction_id, bool committed) {
276 TransactionIDToURLMap& transaction_url_map = 280 TransactionIDToURLMap& transaction_url_map =
277 database_dispatcher_host_->transaction_url_map_; 281 database_dispatcher_host_->transaction_url_map_;
278 TransactionIDToSizeMap& transaction_size_map = 282 TransactionIDToSizeMap& transaction_size_map =
279 database_dispatcher_host_->transaction_size_map_; 283 database_dispatcher_host_->transaction_size_map_;
280 TransactionIDToDatabaseIDMap& transaction_database_map = 284 TransactionIDToDatabaseIDMap& transaction_database_map =
281 database_dispatcher_host_->transaction_database_map_; 285 database_dispatcher_host_->transaction_database_map_;
282 if (committed) 286 if (committed)
283 Context()->TransactionComplete(transaction_url_map[host_transaction_id]); 287 Context()->TransactionComplete(transaction_url_map[host_transaction_id]);
284 // It's unclear if std::map::erase(key) has defined behavior if the 288 // It's unclear if std::map::erase(key) has defined behavior if the
285 // key is not found. 289 // key is not found.
286 // TODO(alecflett): Remove if it is proven that it is safe. 290 // TODO(alecflett): Remove if it is proven that it is safe.
287 if (transaction_url_map.find(host_transaction_id) != 291 if (transaction_url_map.find(host_transaction_id) !=
288 transaction_url_map.end()) 292 transaction_url_map.end())
289 transaction_url_map.erase(host_transaction_id); 293 transaction_url_map.erase(host_transaction_id);
290 if (transaction_size_map.find(host_transaction_id) != 294 if (transaction_size_map.find(host_transaction_id) !=
291 transaction_size_map.end()) 295 transaction_size_map.end())
292 transaction_size_map.erase(host_transaction_id); 296 transaction_size_map.erase(host_transaction_id);
293 if (transaction_database_map.find(host_transaction_id) != 297 if (transaction_database_map.find(host_transaction_id) !=
294 transaction_database_map.end()) 298 transaction_database_map.end())
295 transaction_database_map.erase(host_transaction_id); 299 transaction_database_map.erase(host_transaction_id);
296 } 300 }
297 301
298 ////////////////////////////////////////////////////////////////////// 302 //////////////////////////////////////////////////////////////////////
299 // Helper templates. 303 // Helper templates.
300 // 304 //
301 305
302 template <typename ObjectType> 306 template <typename ObjectType>
303 ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess( 307 ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess(
304 IDMap<ObjectType, IDMapOwnPointer>* map, 308 IDMap<ObjectType, IDMapOwnPointer>* map, int32 ipc_return_object_id) {
305 int32 ipc_return_object_id) {
306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
307 ObjectType* return_object = map->Lookup(ipc_return_object_id); 310 ObjectType* return_object = map->Lookup(ipc_return_object_id);
308 if (!return_object) { 311 if (!return_object) {
309 NOTREACHED() << "Uh oh, couldn't find object with id " 312 NOTREACHED() << "Uh oh, couldn't find object with id "
310 << ipc_return_object_id; 313 << ipc_return_object_id;
311 RecordAction(UserMetricsAction("BadMessageTerminate_IDBMF")); 314 RecordAction(UserMetricsAction("BadMessageTerminate_IDBMF"));
312 BadMessageReceived(); 315 BadMessageReceived();
313 } 316 }
314 return return_object; 317 return return_object;
315 } 318 }
316 319
317 template <typename ObjectType> 320 template <typename ObjectType>
318 void IndexedDBDispatcherHost::DestroyObject( 321 void IndexedDBDispatcherHost::DestroyObject(
319 IDMap<ObjectType, IDMapOwnPointer>* map, 322 IDMap<ObjectType, IDMapOwnPointer>* map, int32 ipc_object_id) {
320 int32 ipc_object_id) {
321 GetOrTerminateProcess(map, ipc_object_id); 323 GetOrTerminateProcess(map, ipc_object_id);
322 map->Remove(ipc_object_id); 324 map->Remove(ipc_object_id);
323 } 325 }
324 326
327
325 ////////////////////////////////////////////////////////////////////// 328 //////////////////////////////////////////////////////////////////////
326 // IndexedDBDispatcherHost::DatabaseDispatcherHost 329 // IndexedDBDispatcherHost::DatabaseDispatcherHost
327 // 330 //
328 331
329 IndexedDBDispatcherHost::DatabaseDispatcherHost::DatabaseDispatcherHost( 332 IndexedDBDispatcherHost::DatabaseDispatcherHost::DatabaseDispatcherHost(
330 IndexedDBDispatcherHost* parent) 333 IndexedDBDispatcherHost* parent)
331 : parent_(parent) { 334 : parent_(parent) {
332 map_.set_check_on_null_data(true); 335 map_.set_check_on_null_data(true);
333 } 336 }
334 337
335 IndexedDBDispatcherHost::DatabaseDispatcherHost::~DatabaseDispatcherHost() { 338 IndexedDBDispatcherHost::DatabaseDispatcherHost::~DatabaseDispatcherHost() {
336 // TODO(alecflett): uncomment these when we find the source of these leaks. 339 // TODO(alecflett): uncomment these when we find the source of these leaks.
337 // DCHECK(transaction_size_map_.empty()); 340 // DCHECK(transaction_size_map_.empty());
338 // DCHECK(transaction_url_map_.empty()); 341 // DCHECK(transaction_url_map_.empty());
339 } 342 }
340 343
341 void IndexedDBDispatcherHost::DatabaseDispatcherHost::CloseAll() { 344 void IndexedDBDispatcherHost::DatabaseDispatcherHost::CloseAll() {
342 // Abort outstanding transactions started by connections in the associated 345 // Abort outstanding transactions started by connections in the associated
343 // front-end to unblock later transactions. This should only occur on unclean 346 // front-end to unblock later transactions. This should only occur on unclean
344 // (crash) or abrupt (process-kill) shutdowns. 347 // (crash) or abrupt (process-kill) shutdowns.
345 for (TransactionIDToDatabaseIDMap::iterator iter = 348 for (TransactionIDToDatabaseIDMap::iterator iter =
346 transaction_database_map_.begin(); 349 transaction_database_map_.begin();
347 iter != transaction_database_map_.end();) { 350 iter != transaction_database_map_.end();) {
348 int64 transaction_id = iter->first; 351 int64 transaction_id = iter->first;
349 int32 ipc_database_id = iter->second; 352 int32 ipc_database_id = iter->second;
350 ++iter; 353 ++iter;
351 WebIDBDatabase* database = map_.Lookup(ipc_database_id); 354 WebIDBDatabase* database = map_.Lookup(ipc_database_id);
352 if (database) { 355 if (database) {
353 database->abort( 356 database->abort(transaction_id, WebIDBDatabaseError(
354 transaction_id, 357 WebKit::WebIDBDatabaseExceptionUnknownError));
355 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError));
356 } 358 }
357 } 359 }
358 DCHECK(transaction_database_map_.empty()); 360 DCHECK(transaction_database_map_.empty());
359 361
360 for (WebIDBObjectIDToURLMap::iterator iter = database_url_map_.begin(); 362 for (WebIDBObjectIDToURLMap::iterator iter = database_url_map_.begin();
361 iter != database_url_map_.end(); 363 iter != database_url_map_.end(); iter++) {
362 iter++) {
363 WebIDBDatabase* database = map_.Lookup(iter->first); 364 WebIDBDatabase* database = map_.Lookup(iter->first);
364 if (database) { 365 if (database) {
365 database->close(); 366 database->close();
366 parent_->Context()->ConnectionClosed(iter->second, database); 367 parent_->Context()->ConnectionClosed(iter->second, database);
367 } 368 }
368 } 369 }
369 } 370 }
370 371
371 bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived( 372 bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived(
372 const IPC::Message& message, 373 const IPC::Message& message, bool* msg_is_ok) {
373 bool* msg_is_ok) {
374 bool handled = true; 374 bool handled = true;
375 IPC_BEGIN_MESSAGE_MAP_EX( 375 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost::DatabaseDispatcherHost,
376 IndexedDBDispatcherHost::DatabaseDispatcherHost, message, *msg_is_ok) 376 message, *msg_is_ok)
377 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore, 377 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore,
378 OnCreateObjectStore) 378 OnCreateObjectStore)
379 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore, 379 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore,
380 OnDeleteObjectStore) 380 OnDeleteObjectStore)
381 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction, 381 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction,
382 OnCreateTransaction) 382 OnCreateTransaction)
383 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose) 383 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose)
384 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed) 384 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed)
385 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGet, OnGet) 385 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGet, OnGet)
386 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabasePut, OnPut) 386 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabasePut, OnPut)
387 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexKeys, OnSetIndexKeys) 387 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexKeys,
388 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexesReady, 388 OnSetIndexKeys)
389 OnSetIndexesReady) 389 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexesReady,
390 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseOpenCursor, OnOpenCursor) 390 OnSetIndexesReady)
391 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCount, OnCount) 391 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseOpenCursor, OnOpenCursor)
392 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteRange, OnDeleteRange) 392 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCount, OnCount)
393 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClear, OnClear) 393 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteRange, OnDeleteRange)
394 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateIndex, OnCreateIndex) 394 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClear, OnClear)
395 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteIndex, OnDeleteIndex) 395 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateIndex,
396 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseAbort, OnAbort) 396 OnCreateIndex)
397 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCommit, OnCommit) 397 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteIndex,
398 IPC_MESSAGE_UNHANDLED(handled = false) 398 OnDeleteIndex)
399 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseAbort,
400 OnAbort)
401 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCommit,
402 OnCommit)
403 IPC_MESSAGE_UNHANDLED(handled = false)
399 IPC_END_MESSAGE_MAP() 404 IPC_END_MESSAGE_MAP()
400 return handled; 405 return handled;
401 } 406 }
402 407
403 void IndexedDBDispatcherHost::DatabaseDispatcherHost::Send( 408 void IndexedDBDispatcherHost::DatabaseDispatcherHost::Send(
404 IPC::Message* message) { 409 IPC::Message* message) {
405 parent_->Send(message); 410 parent_->Send(message);
406 } 411 }
407 412
408 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore( 413 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore(
409 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params) { 414 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params) {
410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
411 WebIDBDatabase* database = 416 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
412 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 417 &map_, params.ipc_database_id);
413 if (!database) 418 if (!database)
414 return; 419 return;
415 420
416 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 421 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
417 database->createObjectStore(host_transaction_id, 422 database->createObjectStore(
418 params.object_store_id, 423 host_transaction_id,
419 params.name, 424 params.object_store_id,
420 params.key_path, 425 params.name, params.key_path, params.auto_increment);
421 params.auto_increment);
422 if (parent_->Context()->IsOverQuota( 426 if (parent_->Context()->IsOverQuota(
423 database_url_map_[params.ipc_database_id])) { 427 database_url_map_[params.ipc_database_id])) {
424 database->abort( 428 database->abort(host_transaction_id, WebIDBDatabaseError(
425 host_transaction_id, 429 WebKit::WebIDBDatabaseExceptionQuotaError));
426 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError));
427 } 430 }
428 } 431 }
429 432
430 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore( 433 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore(
431 int32 ipc_database_id, 434 int32 ipc_database_id,
432 int64 transaction_id, 435 int64 transaction_id,
433 int64 object_store_id) { 436 int64 object_store_id) {
434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 437 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
435 WebIDBDatabase* database = 438 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
436 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 439 &map_, ipc_database_id);
437 if (!database) 440 if (!database)
438 return; 441 return;
439 442
440 database->deleteObjectStore(parent_->HostTransactionId(transaction_id), 443 database->deleteObjectStore(parent_->HostTransactionId(transaction_id),
441 object_store_id); 444 object_store_id);
442 } 445 }
443 446
444 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateTransaction( 447 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateTransaction(
445 const IndexedDBHostMsg_DatabaseCreateTransaction_Params& params) { 448 const IndexedDBHostMsg_DatabaseCreateTransaction_Params& params) {
446 WebIDBDatabase* database = 449 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
447 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 450 &map_, params.ipc_database_id);
448 if (!database) 451 if (!database)
449 return; 452 return;
450 453
451 WebVector<long long> object_stores(params.object_store_ids.size()); 454 WebVector<long long> object_stores(params.object_store_ids.size());
452 for (size_t i = 0; i < params.object_store_ids.size(); ++i) 455 for (size_t i = 0; i < params.object_store_ids.size(); ++i)
453 object_stores[i] = params.object_store_ids[i]; 456 object_stores[i] = params.object_store_ids[i];
454 457
455 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 458 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
456 459
457 database->createTransaction( 460 database->createTransaction(
458 host_transaction_id, 461 host_transaction_id,
459 new IndexedDBDatabaseCallbacks( 462 new IndexedDBDatabaseCallbacks(parent_, params.ipc_thread_id,
460 parent_, params.ipc_thread_id, params.ipc_database_callbacks_id), 463 params.ipc_database_callbacks_id),
461 object_stores, 464 object_stores, params.mode);
462 params.mode);
463 transaction_database_map_[host_transaction_id] = params.ipc_database_id; 465 transaction_database_map_[host_transaction_id] = params.ipc_database_id;
464 parent_->RegisterTransactionId(host_transaction_id, 466 parent_->RegisterTransactionId(host_transaction_id,
465 database_url_map_[params.ipc_database_id]); 467 database_url_map_[params.ipc_database_id]);
466 } 468 }
467 469
468 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClose( 470 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClose(
469 int32 ipc_database_id) { 471 int32 ipc_database_id) {
470 WebIDBDatabase* database = 472 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
471 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 473 &map_, ipc_database_id);
472 if (!database) 474 if (!database)
473 return; 475 return;
474 database->close(); 476 database->close();
475 } 477 }
476 478
477 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed( 479 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed(
478 int32 ipc_object_id) { 480 int32 ipc_object_id) {
479 WebIDBDatabase* database = map_.Lookup(ipc_object_id); 481 WebIDBDatabase* database = map_.Lookup(ipc_object_id);
480 parent_->Context() 482 parent_->Context()->ConnectionClosed(database_url_map_[ipc_object_id],
481 ->ConnectionClosed(database_url_map_[ipc_object_id], database); 483 database);
482 database_url_map_.erase(ipc_object_id); 484 database_url_map_.erase(ipc_object_id);
483 parent_->DestroyObject(&map_, ipc_object_id); 485 parent_->DestroyObject(&map_, ipc_object_id);
484 } 486 }
485 487
486 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet( 488 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet(
487 const IndexedDBHostMsg_DatabaseGet_Params& params) { 489 const IndexedDBHostMsg_DatabaseGet_Params& params) {
488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
489 WebIDBDatabase* database = 491 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
490 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 492 &map_, params.ipc_database_id);
491 if (!database) 493 if (!database)
492 return; 494 return;
493 495
494 scoped_ptr<WebIDBCallbacks> callbacks(new IndexedDBCallbacks<WebData>( 496 scoped_ptr<WebIDBCallbacks> callbacks(
495 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 497 new IndexedDBCallbacks<WebData>(
498 parent_, params.ipc_thread_id,
499 params.ipc_callbacks_id));
496 database->get(parent_->HostTransactionId(params.transaction_id), 500 database->get(parent_->HostTransactionId(params.transaction_id),
497 params.object_store_id, 501 params.object_store_id,
498 params.index_id, 502 params.index_id,
499 params.key_range, 503 params.key_range, params.key_only, callbacks.release());
500 params.key_only,
501 callbacks.release());
502 } 504 }
503 505
504 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( 506 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut(
505 const IndexedDBHostMsg_DatabasePut_Params& params) { 507 const IndexedDBHostMsg_DatabasePut_Params& params) {
506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 508 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
507 509
508 WebIDBDatabase* database = 510 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
509 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 511 &map_, params.ipc_database_id);
510 if (!database) 512 if (!database)
511 return; 513 return;
512 scoped_ptr<WebIDBCallbacks> callbacks(new IndexedDBCallbacks<WebIDBKey>( 514 scoped_ptr<WebIDBCallbacks> callbacks(
513 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 515 new IndexedDBCallbacks<WebIDBKey>(parent_, params.ipc_thread_id,
516 params.ipc_callbacks_id));
514 // Be careful with empty vectors. 517 // Be careful with empty vectors.
515 WebData value; 518 WebData value;
516 if (params.value.size()) 519 if (params.value.size())
517 value.assign(&params.value.front(), params.value.size()); 520 value.assign(&params.value.front(), params.value.size());
518 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 521 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
519 database->put(host_transaction_id, 522 database->put(host_transaction_id,
520 params.object_store_id, 523 params.object_store_id,
521 value, 524 value, params.key,
522 params.key, 525 params.put_mode, callbacks.release(),
523 params.put_mode,
524 callbacks.release(),
525 params.index_ids, 526 params.index_ids,
526 params.index_keys); 527 params.index_keys);
527 TransactionIDToSizeMap* map = 528 TransactionIDToSizeMap* map =
528 &parent_->database_dispatcher_host_->transaction_size_map_; 529 &parent_->database_dispatcher_host_->transaction_size_map_;
529 // Size can't be big enough to overflow because it represents the 530 // Size can't be big enough to overflow because it represents the
530 // actual bytes passed through IPC. 531 // actual bytes passed through IPC.
531 (*map)[host_transaction_id] += params.value.size(); 532 (*map)[host_transaction_id] += params.value.size();
532 } 533 }
533 534
534 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexKeys( 535 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexKeys(
535 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params) { 536 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params) {
536 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 537 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
537 WebIDBDatabase* database = 538 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
538 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 539 &map_, params.ipc_database_id);
539 if (!database) 540 if (!database)
540 return; 541 return;
541 542
542 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 543 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
543 if (params.index_ids.size() != params.index_keys.size()) { 544 if (params.index_ids.size() != params.index_keys.size()) {
544 database->abort( 545 database->abort(host_transaction_id, WebIDBDatabaseError(
545 host_transaction_id, 546 WebKit::WebIDBDatabaseExceptionUnknownError,
546 WebIDBDatabaseError( 547 "Malformed IPC message: index_ids.size() != index_keys.size()"));
547 WebKit::WebIDBDatabaseExceptionUnknownError,
548 "Malformed IPC message: index_ids.size() != index_keys.size()"));
549 return; 548 return;
550 } 549 }
551 550
552 database->setIndexKeys(host_transaction_id, 551 database->setIndexKeys(host_transaction_id,
553 params.object_store_id, 552 params.object_store_id,
554 params.primary_key, 553 params.primary_key, params.index_ids,
555 params.index_ids,
556 params.index_keys); 554 params.index_keys);
557 } 555 }
558 556
559 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexesReady( 557 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexesReady(
560 int32 ipc_database_id, 558 int32 ipc_database_id,
561 int64 transaction_id, 559 int64 transaction_id,
562 int64 object_store_id, 560 int64 object_store_id,
563 const std::vector<int64>& index_ids) { 561 const std::vector<int64>& index_ids) {
564 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 562 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
565 WebIDBDatabase* database = 563 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
566 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 564 &map_, ipc_database_id);
567 if (!database) 565 if (!database)
568 return; 566 return;
569 567
570 database->setIndexesReady(parent_->HostTransactionId(transaction_id), 568 database->setIndexesReady(parent_->HostTransactionId(transaction_id),
571 object_store_id, 569 object_store_id,
572 WebVector<long long>(index_ids)); 570 WebVector<long long>(index_ids));
573 } 571 }
574 572
575 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor( 573 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor(
576 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) { 574 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) {
577 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
578 WebIDBDatabase* database = 576 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
579 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 577 &map_, params.ipc_database_id);
580 if (!database) 578 if (!database)
581 return; 579 return;
582 580
583 scoped_ptr<WebIDBCallbacks> callbacks(new IndexedDBCallbacks<WebIDBCursor>( 581 scoped_ptr<WebIDBCallbacks> callbacks(
584 parent_, params.ipc_thread_id, params.ipc_callbacks_id, -1)); 582 new IndexedDBCallbacks<WebIDBCursor>(parent_, params.ipc_thread_id,
585 database->openCursor(parent_->HostTransactionId(params.transaction_id), 583 params.ipc_callbacks_id, -1));
586 params.object_store_id, 584 database->openCursor(
587 params.index_id, 585 parent_->HostTransactionId(params.transaction_id),
588 params.key_range, 586 params.object_store_id, params.index_id,
589 params.direction, 587 params.key_range, params.direction, params.key_only, params.task_type,
590 params.key_only, 588 callbacks.release());
591 params.task_type,
592 callbacks.release());
593 } 589 }
594 590
595 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCount( 591 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCount(
596 const IndexedDBHostMsg_DatabaseCount_Params& params) { 592 const IndexedDBHostMsg_DatabaseCount_Params& params) {
597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 593 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
598 WebIDBDatabase* database = 594 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
599 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 595 &map_, params.ipc_database_id);
600 if (!database) 596 if (!database)
601 return; 597 return;
602 598
603 scoped_ptr<WebIDBCallbacks> callbacks(new IndexedDBCallbacks<WebData>( 599 scoped_ptr<WebIDBCallbacks> callbacks(
604 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 600 new IndexedDBCallbacks<WebData>(
605 database->count(parent_->HostTransactionId(params.transaction_id), 601 parent_, params.ipc_thread_id,
606 params.object_store_id, 602 params.ipc_callbacks_id));
607 params.index_id, 603 database->count(
608 params.key_range, 604 parent_->HostTransactionId(params.transaction_id),
609 callbacks.release()); 605 params.object_store_id, params.index_id,
606 params.key_range, callbacks.release());
610 } 607 }
611 608
612 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteRange( 609 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteRange(
613 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params) { 610 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params) {
614 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 611 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
615 WebIDBDatabase* database = 612 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
616 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 613 &map_, params.ipc_database_id);
617 if (!database) 614 if (!database)
618 return; 615 return;
619 616
620 scoped_ptr<WebIDBCallbacks> callbacks(new IndexedDBCallbacks<WebData>( 617 scoped_ptr<WebIDBCallbacks> callbacks(
621 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 618 new IndexedDBCallbacks<WebData>(
619 parent_, params.ipc_thread_id,
620 params.ipc_callbacks_id));
622 database->deleteRange(parent_->HostTransactionId(params.transaction_id), 621 database->deleteRange(parent_->HostTransactionId(params.transaction_id),
623 params.object_store_id, 622 params.object_store_id,
624 params.key_range, 623 params.key_range, callbacks.release());
625 callbacks.release());
626 } 624 }
627 625
628 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClear( 626 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClear(
629 int32 ipc_thread_id, 627 int32 ipc_thread_id,
630 int32 ipc_callbacks_id, 628 int32 ipc_callbacks_id,
631 int32 ipc_database_id, 629 int32 ipc_database_id,
632 int64 transaction_id, 630 int64 transaction_id,
633 int64 object_store_id) { 631 int64 object_store_id) {
634 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 632 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
635 WebIDBDatabase* database = 633 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
636 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 634 &map_, ipc_database_id);
637 if (!database) 635 if (!database)
638 return; 636 return;
639 637
640 scoped_ptr<WebIDBCallbacks> callbacks(new IndexedDBCallbacks<WebData>( 638 scoped_ptr<WebIDBCallbacks> callbacks(
641 parent_, ipc_thread_id, ipc_callbacks_id)); 639 new IndexedDBCallbacks<WebData>(
640 parent_, ipc_thread_id,
641 ipc_callbacks_id));
642 642
643 database->clear(parent_->HostTransactionId(transaction_id), 643 database->clear(parent_->HostTransactionId(transaction_id),
644 object_store_id, 644 object_store_id, callbacks.release());
645 callbacks.release());
646 } 645 }
647 646
648 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnAbort( 647 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnAbort(
649 int32 ipc_database_id, 648 int32 ipc_database_id,
650 int64 transaction_id) { 649 int64 transaction_id) {
651 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
652 WebIDBDatabase* database = 651 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
653 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 652 &map_, ipc_database_id);
654 if (!database) 653 if (!database)
655 return; 654 return;
656 655
657 database->abort(parent_->HostTransactionId(transaction_id)); 656 database->abort(parent_->HostTransactionId(transaction_id));
658 } 657 }
659 658
660 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCommit( 659 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCommit(
661 int32 ipc_database_id, 660 int32 ipc_database_id,
662 int64 transaction_id) { 661 int64 transaction_id) {
663 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
664 WebIDBDatabase* database = 663 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
665 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 664 &map_, ipc_database_id);
666 if (!database) 665 if (!database)
667 return; 666 return;
668 667
669 int64 host_transaction_id = parent_->HostTransactionId(transaction_id); 668 int64 host_transaction_id = parent_->HostTransactionId(transaction_id);
670 int64 transaction_size = transaction_size_map_[host_transaction_id]; 669 int64 transaction_size = transaction_size_map_[host_transaction_id];
671 if (transaction_size && 670 if (transaction_size && parent_->Context()->WouldBeOverQuota(
672 parent_->Context()->WouldBeOverQuota( 671 transaction_url_map_[host_transaction_id], transaction_size)) {
673 transaction_url_map_[host_transaction_id], transaction_size)) { 672 database->abort(host_transaction_id, WebIDBDatabaseError(
674 database->abort( 673 WebKit::WebIDBDatabaseExceptionQuotaError));
675 host_transaction_id,
676 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError));
677 return; 674 return;
678 } 675 }
679 676
680 database->commit(host_transaction_id); 677 database->commit(host_transaction_id);
681 } 678 }
682 679
683 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex( 680 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex(
684 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) { 681 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) {
685 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 682 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
686 WebIDBDatabase* database = 683 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
687 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 684 &map_, params.ipc_database_id);
688 if (!database) 685 if (!database)
689 return; 686 return;
690 687
691 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 688 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
692 database->createIndex(host_transaction_id, 689 database->createIndex(
693 params.object_store_id, 690 host_transaction_id,
694 params.index_id, 691 params.object_store_id,
695 params.name, 692 params.index_id,
696 params.key_path, 693 params.name,
697 params.unique, 694 params.key_path,
698 params.multi_entry); 695 params.unique,
696 params.multi_entry);
699 if (parent_->Context()->IsOverQuota( 697 if (parent_->Context()->IsOverQuota(
700 database_url_map_[params.ipc_database_id])) { 698 database_url_map_[params.ipc_database_id])) {
701 database->abort( 699 database->abort(host_transaction_id, WebIDBDatabaseError(
702 host_transaction_id, 700 WebKit::WebIDBDatabaseExceptionQuotaError));
703 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError));
704 } 701 }
705 } 702 }
706 703
707 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex( 704 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex(
708 int32 ipc_database_id, 705 int32 ipc_database_id,
709 int64 transaction_id, 706 int64 transaction_id,
710 int64 object_store_id, 707 int64 object_store_id,
711 int64 index_id) { 708 int64 index_id) {
712 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 709 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
713 WebIDBDatabase* database = 710 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
714 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 711 &map_, ipc_database_id);
715 if (!database) 712 if (!database)
716 return; 713 return;
717 714
718 database->deleteIndex( 715 database->deleteIndex(parent_->HostTransactionId(transaction_id),
719 parent_->HostTransactionId(transaction_id), object_store_id, index_id); 716 object_store_id, index_id);
720 } 717 }
721 718
722 ////////////////////////////////////////////////////////////////////// 719 //////////////////////////////////////////////////////////////////////
723 // IndexedDBDispatcherHost::CursorDispatcherHost 720 // IndexedDBDispatcherHost::CursorDispatcherHost
724 // 721 //
725 722
726 IndexedDBDispatcherHost::CursorDispatcherHost::CursorDispatcherHost( 723 IndexedDBDispatcherHost::CursorDispatcherHost::CursorDispatcherHost(
727 IndexedDBDispatcherHost* parent) 724 IndexedDBDispatcherHost* parent)
728 : parent_(parent) { 725 : parent_(parent) {
729 map_.set_check_on_null_data(true); 726 map_.set_check_on_null_data(true);
730 } 727 }
731 728
732 IndexedDBDispatcherHost::CursorDispatcherHost::~CursorDispatcherHost() {} 729 IndexedDBDispatcherHost::CursorDispatcherHost::~CursorDispatcherHost() {
730 }
733 731
734 bool IndexedDBDispatcherHost::CursorDispatcherHost::OnMessageReceived( 732 bool IndexedDBDispatcherHost::CursorDispatcherHost::OnMessageReceived(
735 const IPC::Message& message, 733 const IPC::Message& message, bool* msg_is_ok) {
736 bool* msg_is_ok) {
737 bool handled = true; 734 bool handled = true;
738 IPC_BEGIN_MESSAGE_MAP_EX( 735 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost::CursorDispatcherHost,
739 IndexedDBDispatcherHost::CursorDispatcherHost, message, *msg_is_ok) 736 message, *msg_is_ok)
740 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorAdvance, OnAdvance) 737 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorAdvance, OnAdvance)
741 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorContinue, OnContinue) 738 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorContinue, OnContinue)
742 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetch, OnPrefetch) 739 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetch, OnPrefetch)
743 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetchReset, OnPrefetchReset) 740 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetchReset, OnPrefetchReset)
744 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorDelete, OnDelete) 741 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorDelete, OnDelete)
745 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorDestroyed, OnDestroyed) 742 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorDestroyed, OnDestroyed)
746 IPC_MESSAGE_UNHANDLED(handled = false) 743 IPC_MESSAGE_UNHANDLED(handled = false)
747 IPC_END_MESSAGE_MAP() 744 IPC_END_MESSAGE_MAP()
748 return handled; 745 return handled;
749 } 746 }
750 747
748
751 void IndexedDBDispatcherHost::CursorDispatcherHost::Send( 749 void IndexedDBDispatcherHost::CursorDispatcherHost::Send(
752 IPC::Message* message) { 750 IPC::Message* message) {
753 parent_->Send(message); 751 parent_->Send(message);
754 } 752 }
755 753
754
756 void IndexedDBDispatcherHost::CursorDispatcherHost::OnAdvance( 755 void IndexedDBDispatcherHost::CursorDispatcherHost::OnAdvance(
757 int32 ipc_cursor_id, 756 int32 ipc_cursor_id,
758 int32 ipc_thread_id, 757 int32 ipc_thread_id,
759 int32 ipc_callbacks_id, 758 int32 ipc_callbacks_id,
760 unsigned long count) { 759 unsigned long count) {
761 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 760 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
762 WebIDBCursor* idb_cursor = 761 WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(
763 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); 762 &map_, ipc_cursor_id);
764 if (!idb_cursor) 763 if (!idb_cursor)
765 return; 764 return;
766 765
767 idb_cursor->advance( 766 idb_cursor->advance(count,
768 count, 767 new IndexedDBCallbacks<WebIDBCursor>(parent_,
769 new IndexedDBCallbacks<WebIDBCursor>( 768 ipc_thread_id,
770 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id)); 769 ipc_callbacks_id,
770 ipc_cursor_id));
771 } 771 }
772 772
773 void IndexedDBDispatcherHost::CursorDispatcherHost::OnContinue( 773 void IndexedDBDispatcherHost::CursorDispatcherHost::OnContinue(
774 int32 ipc_cursor_id, 774 int32 ipc_cursor_id,
775 int32 ipc_thread_id, 775 int32 ipc_thread_id,
776 int32 ipc_callbacks_id, 776 int32 ipc_callbacks_id,
777 const IndexedDBKey& key) { 777 const IndexedDBKey& key) {
778 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 778 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
779 WebIDBCursor* idb_cursor = 779 WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(&map_,
780 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); 780 ipc_cursor_id);
781 if (!idb_cursor) 781 if (!idb_cursor)
782 return; 782 return;
783 783
784 idb_cursor->continueFunction( 784 idb_cursor->continueFunction(
785 key, 785 key, new IndexedDBCallbacks<WebIDBCursor>(parent_, ipc_thread_id,
786 new IndexedDBCallbacks<WebIDBCursor>( 786 ipc_callbacks_id,
787 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id)); 787 ipc_cursor_id));
788 } 788 }
789 789
790 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetch( 790 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetch(
791 int32 ipc_cursor_id, 791 int32 ipc_cursor_id,
792 int32 ipc_thread_id, 792 int32 ipc_thread_id,
793 int32 ipc_callbacks_id, 793 int32 ipc_callbacks_id,
794 int n) { 794 int n) {
795 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 795 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
796 WebIDBCursor* idb_cursor = 796 WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(&map_,
797 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); 797 ipc_cursor_id);
798 if (!idb_cursor) 798 if (!idb_cursor)
799 return; 799 return;
800 800
801 idb_cursor->prefetchContinue( 801 idb_cursor->prefetchContinue(
802 n, 802 n, new IndexedDBCallbacks<WebIDBCursor>(parent_, ipc_thread_id,
803 new IndexedDBCallbacks<WebIDBCursor>( 803 ipc_callbacks_id,
804 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id)); 804 ipc_cursor_id));
805 } 805 }
806 806
807 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetchReset( 807 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetchReset(
808 int32 ipc_cursor_id, 808 int32 ipc_cursor_id, int used_prefetches, int unused_prefetches) {
809 int used_prefetches,
810 int unused_prefetches) {
811 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 809 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
812 WebIDBCursor* idb_cursor = 810 WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(&map_,
813 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); 811 ipc_cursor_id);
814 if (!idb_cursor) 812 if (!idb_cursor)
815 return; 813 return;
816 814
817 idb_cursor->prefetchReset(used_prefetches, unused_prefetches); 815 idb_cursor->prefetchReset(used_prefetches, unused_prefetches);
818 } 816 }
819 817
820 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDelete( 818 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDelete(
821 int32 ipc_cursor_id, 819 int32 ipc_cursor_id,
822 int32 ipc_thread_id, 820 int32 ipc_thread_id,
823 int32 ipc_callbacks_id) { 821 int32 ipc_callbacks_id) {
824 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 822 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
825 WebIDBCursor* idb_cursor = 823 WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(&map_,
826 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); 824 ipc_cursor_id);
827 if (!idb_cursor) 825 if (!idb_cursor)
828 return; 826 return;
829 827
830 idb_cursor->deleteFunction(new IndexedDBCallbacks<WebData>( 828 idb_cursor->deleteFunction(
831 parent_, ipc_thread_id, ipc_callbacks_id)); 829 new IndexedDBCallbacks<WebData>(parent_, ipc_thread_id,
830 ipc_callbacks_id));
832 } 831 }
833 832
834 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( 833 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed(
835 int32 ipc_object_id) { 834 int32 ipc_object_id) {
836 parent_->DestroyObject(&map_, ipc_object_id); 835 parent_->DestroyObject(&map_, ipc_object_id);
837 } 836 }
838 837
839 } // namespace content 838 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/in_process_webkit/indexed_db_dispatcher_host.h ('k') | content/browser/indexed_db/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698