OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "content/browser/browser_thread.h" | 9 #include "content/browser/browser_thread.h" |
10 #include "content/browser/in_process_webkit/indexed_db_callbacks.h" | 10 #include "content/browser/in_process_webkit/indexed_db_callbacks.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabaseError.h
" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabaseError.h
" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBKeyRange.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBKeyRange.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBIndex.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBIndex.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBFactory.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBFactory.h" |
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBObjectStore.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBObjectStore.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransaction.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransaction.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" |
30 #include "webkit/glue/webkit_glue.h" | 30 #include "webkit/glue/webkit_glue.h" |
31 #include "webkit/quota/quota_manager.h" | |
32 | 31 |
33 using WebKit::WebDOMStringList; | 32 using WebKit::WebDOMStringList; |
34 using WebKit::WebExceptionCode; | 33 using WebKit::WebExceptionCode; |
35 using WebKit::WebIDBCallbacks; | 34 using WebKit::WebIDBCallbacks; |
36 using WebKit::WebIDBCursor; | 35 using WebKit::WebIDBCursor; |
37 using WebKit::WebIDBDatabase; | 36 using WebKit::WebIDBDatabase; |
38 using WebKit::WebIDBDatabaseError; | 37 using WebKit::WebIDBDatabaseError; |
39 using WebKit::WebIDBIndex; | 38 using WebKit::WebIDBIndex; |
40 using WebKit::WebIDBKey; | 39 using WebKit::WebIDBKey; |
41 using WebKit::WebIDBKeyRange; | 40 using WebKit::WebIDBKeyRange; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 return cursor_dispatcher_host_->map_.Add(idb_cursor); | 147 return cursor_dispatcher_host_->map_.Add(idb_cursor); |
149 } | 148 } |
150 | 149 |
151 int32 IndexedDBDispatcherHost::Add(WebIDBDatabase* idb_database, | 150 int32 IndexedDBDispatcherHost::Add(WebIDBDatabase* idb_database, |
152 const GURL& origin_url) { | 151 const GURL& origin_url) { |
153 if (!database_dispatcher_host_.get()) { | 152 if (!database_dispatcher_host_.get()) { |
154 delete idb_database; | 153 delete idb_database; |
155 return 0; | 154 return 0; |
156 } | 155 } |
157 int32 idb_database_id = database_dispatcher_host_->map_.Add(idb_database); | 156 int32 idb_database_id = database_dispatcher_host_->map_.Add(idb_database); |
158 database_dispatcher_host_->url_map_[idb_database_id] = origin_url; | 157 Context()->ConnectionOpened(origin_url); |
| 158 database_dispatcher_host_->database_url_map_[idb_database_id] = origin_url; |
159 return idb_database_id; | 159 return idb_database_id; |
160 } | 160 } |
161 | 161 |
162 int32 IndexedDBDispatcherHost::Add(WebIDBIndex* idb_index) { | 162 int32 IndexedDBDispatcherHost::Add(WebIDBIndex* idb_index) { |
163 if (!index_dispatcher_host_.get()) { | 163 if (!index_dispatcher_host_.get()) { |
164 delete idb_index; | 164 delete idb_index; |
165 return 0; | 165 return 0; |
166 } | 166 } |
167 if (!idb_index) | 167 if (!idb_index) |
168 return 0; | 168 return 0; |
169 return index_dispatcher_host_->map_.Add(idb_index); | 169 return index_dispatcher_host_->map_.Add(idb_index); |
170 } | 170 } |
171 | 171 |
172 int32 IndexedDBDispatcherHost::Add(WebIDBObjectStore* idb_object_store) { | 172 int32 IndexedDBDispatcherHost::Add(WebIDBObjectStore* idb_object_store) { |
173 if (!object_store_dispatcher_host_.get()) { | 173 if (!object_store_dispatcher_host_.get()) { |
174 delete idb_object_store; | 174 delete idb_object_store; |
175 return 0; | 175 return 0; |
176 } | 176 } |
177 if (!idb_object_store) | 177 if (!idb_object_store) |
178 return 0; | 178 return 0; |
179 return object_store_dispatcher_host_->map_.Add(idb_object_store); | 179 return object_store_dispatcher_host_->map_.Add(idb_object_store); |
180 } | 180 } |
181 | 181 |
182 int32 IndexedDBDispatcherHost::Add(WebIDBTransaction* idb_transaction) { | 182 int32 IndexedDBDispatcherHost::Add(WebIDBTransaction* idb_transaction, |
| 183 const GURL& url) { |
183 if (!transaction_dispatcher_host_.get()) { | 184 if (!transaction_dispatcher_host_.get()) { |
184 delete idb_transaction; | 185 delete idb_transaction; |
185 return 0; | 186 return 0; |
186 } | 187 } |
187 int32 id = transaction_dispatcher_host_->map_.Add(idb_transaction); | 188 int32 id = transaction_dispatcher_host_->map_.Add(idb_transaction); |
188 idb_transaction->setCallbacks(new IndexedDBTransactionCallbacks(this, id)); | 189 idb_transaction->setCallbacks(new IndexedDBTransactionCallbacks(this, id)); |
| 190 transaction_dispatcher_host_->transaction_url_map_[id] = url; |
189 return id; | 191 return id; |
190 } | 192 } |
191 | 193 |
192 void IndexedDBDispatcherHost::OnIDBFactoryOpen( | 194 void IndexedDBDispatcherHost::OnIDBFactoryOpen( |
193 const IndexedDBHostMsg_FactoryOpen_Params& params) { | 195 const IndexedDBHostMsg_FactoryOpen_Params& params) { |
| 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
194 FilePath base_path = webkit_context_->data_path(); | 197 FilePath base_path = webkit_context_->data_path(); |
195 FilePath indexed_db_path; | 198 FilePath indexed_db_path; |
196 if (!base_path.empty()) { | 199 if (!base_path.empty()) { |
197 indexed_db_path = base_path.Append( | 200 indexed_db_path = base_path.Append( |
198 IndexedDBContext::kIndexedDBDirectory); | 201 IndexedDBContext::kIndexedDBDirectory); |
199 } | 202 } |
200 | 203 |
201 // TODO(jorlow): This doesn't support file:/// urls properly. We probably need | 204 // TODO(jorlow): This doesn't support file:/// urls properly. We probably need |
202 // to add some toString method to WebSecurityOrigin that doesn't | 205 // to add some toString method to WebSecurityOrigin that doesn't |
203 // return null for them. | 206 // return null for them. |
(...skipping 15 matching lines...) Expand all Loading... |
219 } | 222 } |
220 | 223 |
221 WebKit::WebIDBFactory::BackingStoreType backingStoreType = | 224 WebKit::WebIDBFactory::BackingStoreType backingStoreType = |
222 WebKit::WebIDBFactory::LevelDBBackingStore; | 225 WebKit::WebIDBFactory::LevelDBBackingStore; |
223 | 226 |
224 if (CommandLine::ForCurrentProcess()->HasSwitch( | 227 if (CommandLine::ForCurrentProcess()->HasSwitch( |
225 switches::kSQLiteIndexedDatabase)) { | 228 switches::kSQLiteIndexedDatabase)) { |
226 backingStoreType = WebKit::WebIDBFactory::SQLiteBackingStore; | 229 backingStoreType = WebKit::WebIDBFactory::SQLiteBackingStore; |
227 } | 230 } |
228 | 231 |
| 232 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore |
| 233 // created) if this origin is already over quota. |
229 Context()->GetIDBFactory()->open( | 234 Context()->GetIDBFactory()->open( |
230 params.name, | 235 params.name, |
231 new IndexedDBCallbacks<WebIDBDatabase>(this, params.response_id, | 236 new IndexedDBCallbacks<WebIDBDatabase>(this, params.response_id, |
232 origin_url), | 237 origin_url), |
233 origin, NULL, webkit_glue::FilePathToWebString(indexed_db_path), quota, | 238 origin, NULL, webkit_glue::FilePathToWebString(indexed_db_path), quota, |
234 backingStoreType); | 239 backingStoreType); |
235 } | 240 } |
236 | 241 |
237 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( | 242 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( |
238 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) { | 243 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) { |
239 FilePath base_path = webkit_context_->data_path(); | 244 FilePath base_path = webkit_context_->data_path(); |
240 FilePath indexed_db_path; | 245 FilePath indexed_db_path; |
241 if (!base_path.empty()) { | 246 if (!base_path.empty()) { |
242 indexed_db_path = base_path.Append( | 247 indexed_db_path = base_path.Append( |
243 IndexedDBContext::kIndexedDBDirectory); | 248 IndexedDBContext::kIndexedDBDirectory); |
244 } | 249 } |
245 | 250 |
246 WebSecurityOrigin origin( | 251 WebSecurityOrigin origin( |
247 WebSecurityOrigin::createFromDatabaseIdentifier(params.origin)); | 252 WebSecurityOrigin::createFromDatabaseIdentifier(params.origin)); |
248 GURL url(origin.toString()); | 253 GURL url(origin.toString()); |
249 | 254 |
250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); | 255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
251 Context()->GetIDBFactory()->deleteDatabase( | 256 Context()->GetIDBFactory()->deleteDatabase( |
252 params.name, | 257 params.name, |
253 new IndexedDBCallbacks<WebIDBDatabase>(this, params.response_id, url), | 258 new IndexedDBCallbacks<WebIDBDatabase>(this, params.response_id, url), |
254 WebSecurityOrigin::createFromDatabaseIdentifier(params.origin), NULL, | 259 WebSecurityOrigin::createFromDatabaseIdentifier(params.origin), NULL, |
255 webkit_glue::FilePathToWebString(indexed_db_path)); | 260 webkit_glue::FilePathToWebString(indexed_db_path)); |
256 } | 261 } |
257 | 262 |
| 263 void IndexedDBDispatcherHost::TransactionComplete(int32 transaction_id) { |
| 264 Context()->TransactionComplete( |
| 265 transaction_dispatcher_host_->transaction_url_map_[transaction_id]); |
| 266 } |
| 267 |
258 ////////////////////////////////////////////////////////////////////// | 268 ////////////////////////////////////////////////////////////////////// |
259 // Helper templates. | 269 // Helper templates. |
260 // | 270 // |
261 | 271 |
262 template <typename ObjectType> | 272 template <typename ObjectType> |
263 ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess( | 273 ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess( |
264 IDMap<ObjectType, IDMapOwnPointer>* map, int32 return_object_id) { | 274 IDMap<ObjectType, IDMapOwnPointer>* map, int32 return_object_id) { |
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); | 275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
266 ObjectType* return_object = map->Lookup(return_object_id); | 276 ObjectType* return_object = map->Lookup(return_object_id); |
267 if (!return_object) { | 277 if (!return_object) { |
(...skipping 26 matching lines...) Expand all Loading... |
294 // IndexedDBDispatcherHost::DatabaseDispatcherHost | 304 // IndexedDBDispatcherHost::DatabaseDispatcherHost |
295 // | 305 // |
296 | 306 |
297 IndexedDBDispatcherHost::DatabaseDispatcherHost::DatabaseDispatcherHost( | 307 IndexedDBDispatcherHost::DatabaseDispatcherHost::DatabaseDispatcherHost( |
298 IndexedDBDispatcherHost* parent) | 308 IndexedDBDispatcherHost* parent) |
299 : parent_(parent) { | 309 : parent_(parent) { |
300 map_.set_check_on_null_data(true); | 310 map_.set_check_on_null_data(true); |
301 } | 311 } |
302 | 312 |
303 IndexedDBDispatcherHost::DatabaseDispatcherHost::~DatabaseDispatcherHost() { | 313 IndexedDBDispatcherHost::DatabaseDispatcherHost::~DatabaseDispatcherHost() { |
| 314 for (WebIDBObjectIDToURLMap::iterator iter = database_url_map_.begin(); |
| 315 iter != database_url_map_.end(); iter++) { |
| 316 parent_->Context()->ConnectionClosed(iter->second); |
| 317 } |
304 } | 318 } |
305 | 319 |
306 bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived( | 320 bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived( |
307 const IPC::Message& message, bool* msg_is_ok) { | 321 const IPC::Message& message, bool* msg_is_ok) { |
308 bool handled = true; | 322 bool handled = true; |
309 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost::DatabaseDispatcherHost, | 323 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost::DatabaseDispatcherHost, |
310 message, *msg_is_ok) | 324 message, *msg_is_ok) |
311 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseName, OnName) | 325 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseName, OnName) |
312 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseVersion, OnVersion) | 326 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseVersion, OnVersion) |
313 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseObjectStoreNames, | 327 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseObjectStoreNames, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess( | 378 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess( |
365 &parent_->transaction_dispatcher_host_->map_, params.transaction_id); | 379 &parent_->transaction_dispatcher_host_->map_, params.transaction_id); |
366 if (!idb_database || !idb_transaction) | 380 if (!idb_database || !idb_transaction) |
367 return; | 381 return; |
368 | 382 |
369 *ec = 0; | 383 *ec = 0; |
370 WebIDBObjectStore* object_store = idb_database->createObjectStore( | 384 WebIDBObjectStore* object_store = idb_database->createObjectStore( |
371 params.name, params.key_path, params.auto_increment, | 385 params.name, params.key_path, params.auto_increment, |
372 *idb_transaction, *ec); | 386 *idb_transaction, *ec); |
373 *object_store_id = *ec ? 0 : parent_->Add(object_store); | 387 *object_store_id = *ec ? 0 : parent_->Add(object_store); |
| 388 if (parent_->Context()->IsOverQuota( |
| 389 database_url_map_[params.idb_database_id])) { |
| 390 idb_transaction->abort(); |
| 391 } |
374 } | 392 } |
375 | 393 |
376 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore( | 394 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore( |
377 int32 idb_database_id, | 395 int32 idb_database_id, |
378 const string16& name, | 396 const string16& name, |
379 int32 transaction_id, | 397 int32 transaction_id, |
380 WebKit::WebExceptionCode* ec) { | 398 WebKit::WebExceptionCode* ec) { |
381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); | 399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
382 WebIDBDatabase* idb_database = parent_->GetOrTerminateProcess( | 400 WebIDBDatabase* idb_database = parent_->GetOrTerminateProcess( |
383 &map_, idb_database_id); | 401 &map_, idb_database_id); |
(...skipping 13 matching lines...) Expand all Loading... |
397 WebKit::WebExceptionCode* ec) { | 415 WebKit::WebExceptionCode* ec) { |
398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); | 416 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
399 WebIDBDatabase* idb_database = parent_->GetOrTerminateProcess( | 417 WebIDBDatabase* idb_database = parent_->GetOrTerminateProcess( |
400 &map_, idb_database_id); | 418 &map_, idb_database_id); |
401 if (!idb_database) | 419 if (!idb_database) |
402 return; | 420 return; |
403 | 421 |
404 *ec = 0; | 422 *ec = 0; |
405 idb_database->setVersion( | 423 idb_database->setVersion( |
406 version, | 424 version, |
407 new IndexedDBCallbacks<WebIDBTransaction>(parent_, response_id), | 425 new IndexedDBCallbacks<WebIDBTransaction>(parent_, response_id, |
| 426 database_url_map_[idb_database_id]), |
408 *ec); | 427 *ec); |
409 } | 428 } |
410 | 429 |
411 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnTransaction( | 430 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnTransaction( |
412 int32 idb_database_id, | 431 int32 idb_database_id, |
413 const std::vector<string16>& names, | 432 const std::vector<string16>& names, |
414 int32 mode, | 433 int32 mode, |
415 int32 timeout, | 434 int32 timeout, |
416 int32* idb_transaction_id, | 435 int32* idb_transaction_id, |
417 WebKit::WebExceptionCode* ec) { | 436 WebKit::WebExceptionCode* ec) { |
418 WebIDBDatabase* database = parent_->GetOrTerminateProcess( | 437 WebIDBDatabase* database = parent_->GetOrTerminateProcess( |
419 &map_, idb_database_id); | 438 &map_, idb_database_id); |
420 if (!database) | 439 if (!database) |
421 return; | 440 return; |
422 | 441 |
423 WebDOMStringList object_stores; | 442 WebDOMStringList object_stores; |
424 for (std::vector<string16>::const_iterator it = names.begin(); | 443 for (std::vector<string16>::const_iterator it = names.begin(); |
425 it != names.end(); ++it) { | 444 it != names.end(); ++it) { |
426 object_stores.append(*it); | 445 object_stores.append(*it); |
427 } | 446 } |
428 | 447 |
429 *ec = 0; | 448 *ec = 0; |
430 WebIDBTransaction* transaction = database->transaction( | 449 WebIDBTransaction* transaction = database->transaction( |
431 object_stores, mode, timeout, *ec); | 450 object_stores, mode, timeout, *ec); |
432 DCHECK(!transaction != !*ec); | 451 DCHECK(!transaction != !*ec); |
433 *idb_transaction_id = *ec ? 0 : parent_->Add(transaction); | 452 *idb_transaction_id = |
| 453 *ec ? 0 : parent_->Add(transaction, database_url_map_[idb_database_id]); |
434 } | 454 } |
435 | 455 |
436 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpen( | 456 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpen( |
437 int32 idb_database_id, int32 response_id) { | 457 int32 idb_database_id, int32 response_id) { |
438 WebIDBDatabase* database = parent_->GetOrTerminateProcess( | 458 WebIDBDatabase* database = parent_->GetOrTerminateProcess( |
439 &map_, idb_database_id); | 459 &map_, idb_database_id); |
440 database->open(new IndexedDBDatabaseCallbacks(parent_, response_id)); | 460 database->open(new IndexedDBDatabaseCallbacks(parent_, response_id)); |
441 } | 461 } |
442 | 462 |
443 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClose( | 463 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClose( |
444 int32 idb_database_id) { | 464 int32 idb_database_id) { |
445 WebIDBDatabase* database = parent_->GetOrTerminateProcess( | 465 WebIDBDatabase* database = parent_->GetOrTerminateProcess( |
446 &map_, idb_database_id); | 466 &map_, idb_database_id); |
447 database->close(); | 467 database->close(); |
448 parent_->Context()->quota_manager_proxy()->NotifyStorageAccessed( | |
449 quota::QuotaClient::kIndexedDatabase, url_map_[idb_database_id], | |
450 quota::kStorageTypeTemporary); | |
451 url_map_.erase(idb_database_id); | |
452 } | 468 } |
453 | 469 |
454 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed( | 470 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed( |
455 int32 object_id) { | 471 int32 object_id) { |
| 472 parent_->Context()->ConnectionClosed(database_url_map_[object_id]); |
| 473 database_url_map_.erase(object_id); |
456 parent_->DestroyObject(&map_, object_id); | 474 parent_->DestroyObject(&map_, object_id); |
457 } | 475 } |
458 | 476 |
459 | 477 |
460 ////////////////////////////////////////////////////////////////////// | 478 ////////////////////////////////////////////////////////////////////// |
461 // IndexedDBDispatcherHost::IndexDispatcherHost | 479 // IndexedDBDispatcherHost::IndexDispatcherHost |
462 // | 480 // |
463 | 481 |
464 IndexedDBDispatcherHost::IndexDispatcherHost::IndexDispatcherHost( | 482 IndexedDBDispatcherHost::IndexDispatcherHost::IndexDispatcherHost( |
465 IndexedDBDispatcherHost* parent) | 483 IndexedDBDispatcherHost* parent) |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess( | 715 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess( |
698 &parent_->transaction_dispatcher_host_->map_, params.transaction_id); | 716 &parent_->transaction_dispatcher_host_->map_, params.transaction_id); |
699 if (!idb_transaction || !idb_object_store) | 717 if (!idb_transaction || !idb_object_store) |
700 return; | 718 return; |
701 | 719 |
702 *ec = 0; | 720 *ec = 0; |
703 scoped_ptr<WebIDBCallbacks> callbacks( | 721 scoped_ptr<WebIDBCallbacks> callbacks( |
704 new IndexedDBCallbacks<WebIDBKey>(parent_, params.response_id)); | 722 new IndexedDBCallbacks<WebIDBKey>(parent_, params.response_id)); |
705 idb_object_store->put(params.serialized_value, params.key, params.put_mode, | 723 idb_object_store->put(params.serialized_value, params.key, params.put_mode, |
706 callbacks.release(), *idb_transaction, *ec); | 724 callbacks.release(), *idb_transaction, *ec); |
| 725 if (*ec) |
| 726 return; |
| 727 int64 size = UTF16ToUTF8(params.serialized_value.data()).size(); |
| 728 WebIDBTransactionIDToSizeMap* map = |
| 729 &parent_->transaction_dispatcher_host_->transaction_size_map_; |
| 730 (*map)[params.transaction_id] += size; |
707 } | 731 } |
708 | 732 |
709 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnDelete( | 733 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnDelete( |
710 int idb_object_store_id, | 734 int idb_object_store_id, |
711 int32 response_id, | 735 int32 response_id, |
712 const IndexedDBKey& key, | 736 const IndexedDBKey& key, |
713 int32 transaction_id, | 737 int32 transaction_id, |
714 WebKit::WebExceptionCode* ec) { | 738 WebKit::WebExceptionCode* ec) { |
715 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); | 739 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
716 WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess( | 740 WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 &map_, params.idb_object_store_id); | 778 &map_, params.idb_object_store_id); |
755 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess( | 779 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess( |
756 &parent_->transaction_dispatcher_host_->map_, params.transaction_id); | 780 &parent_->transaction_dispatcher_host_->map_, params.transaction_id); |
757 if (!idb_object_store || !idb_transaction) | 781 if (!idb_object_store || !idb_transaction) |
758 return; | 782 return; |
759 | 783 |
760 *ec = 0; | 784 *ec = 0; |
761 WebIDBIndex* index = idb_object_store->createIndex( | 785 WebIDBIndex* index = idb_object_store->createIndex( |
762 params.name, params.key_path, params.unique, *idb_transaction, *ec); | 786 params.name, params.key_path, params.unique, *idb_transaction, *ec); |
763 *index_id = *ec ? 0 : parent_->Add(index); | 787 *index_id = *ec ? 0 : parent_->Add(index); |
| 788 WebIDBObjectIDToURLMap* transaction_url_map = |
| 789 &parent_->transaction_dispatcher_host_->transaction_url_map_; |
| 790 if (parent_->Context()->IsOverQuota( |
| 791 (*transaction_url_map)[params.transaction_id])) { |
| 792 idb_transaction->abort(); |
| 793 } |
764 } | 794 } |
765 | 795 |
766 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnIndex( | 796 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnIndex( |
767 int32 idb_object_store_id, | 797 int32 idb_object_store_id, |
768 const string16& name, | 798 const string16& name, |
769 int32* idb_index_id, | 799 int32* idb_index_id, |
770 WebKit::WebExceptionCode* ec) { | 800 WebKit::WebExceptionCode* ec) { |
771 WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess( | 801 WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess( |
772 &map_, idb_object_store_id); | 802 &map_, idb_object_store_id); |
773 if (!idb_object_store) | 803 if (!idb_object_store) |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 } | 1056 } |
1027 | 1057 |
1028 void IndexedDBDispatcherHost:: | 1058 void IndexedDBDispatcherHost:: |
1029 TransactionDispatcherHost::OnDidCompleteTaskEvents(int transaction_id) { | 1059 TransactionDispatcherHost::OnDidCompleteTaskEvents(int transaction_id) { |
1030 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); | 1060 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
1031 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess( | 1061 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess( |
1032 &map_, transaction_id); | 1062 &map_, transaction_id); |
1033 if (!idb_transaction) | 1063 if (!idb_transaction) |
1034 return; | 1064 return; |
1035 | 1065 |
| 1066 // TODO(dgrogan): Tell the page the transaction aborted because of quota. |
| 1067 if (parent_->Context()->WouldBeOverQuota( |
| 1068 transaction_url_map_[transaction_id], |
| 1069 transaction_size_map_[transaction_id])) { |
| 1070 idb_transaction->abort(); |
| 1071 return; |
| 1072 } |
1036 idb_transaction->didCompleteTaskEvents(); | 1073 idb_transaction->didCompleteTaskEvents(); |
1037 } | 1074 } |
1038 | 1075 |
1039 void IndexedDBDispatcherHost::TransactionDispatcherHost::OnDestroyed( | 1076 void IndexedDBDispatcherHost::TransactionDispatcherHost::OnDestroyed( |
1040 int32 object_id) { | 1077 int32 object_id) { |
| 1078 transaction_size_map_.erase(object_id); |
| 1079 transaction_url_map_.erase(object_id); |
1041 parent_->DestroyObject(&map_, object_id); | 1080 parent_->DestroyObject(&map_, object_id); |
1042 } | 1081 } |
OLD | NEW |