OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" | 5 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/guid.h" | 12 #include "base/guid.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/process/process.h" | 14 #include "base/process/process.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "content/browser/bad_message.h" | 17 #include "content/browser/bad_message.h" |
18 #include "content/browser/child_process_security_policy_impl.h" | |
19 #include "content/browser/indexed_db/indexed_db_callbacks.h" | 18 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
20 #include "content/browser/indexed_db/indexed_db_connection.h" | 19 #include "content/browser/indexed_db/indexed_db_connection.h" |
21 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 20 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
22 #include "content/browser/indexed_db/indexed_db_cursor.h" | 21 #include "content/browser/indexed_db/indexed_db_cursor.h" |
23 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 22 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
24 #include "content/browser/indexed_db/indexed_db_observation.h" | 23 #include "content/browser/indexed_db/indexed_db_observation.h" |
25 #include "content/browser/indexed_db/indexed_db_observer_changes.h" | 24 #include "content/browser/indexed_db/indexed_db_observer_changes.h" |
26 #include "content/browser/indexed_db/indexed_db_pending_connection.h" | 25 #include "content/browser/indexed_db/indexed_db_pending_connection.h" |
27 #include "content/browser/indexed_db/indexed_db_value.h" | 26 #include "content/browser/indexed_db/indexed_db_value.h" |
28 #include "content/browser/renderer_host/render_message_filter.h" | 27 #include "content/browser/renderer_host/render_message_filter.h" |
29 #include "content/common/indexed_db/indexed_db_messages.h" | 28 #include "content/common/indexed_db/indexed_db_messages.h" |
30 #include "content/common/indexed_db/indexed_db_metadata.h" | 29 #include "content/common/indexed_db/indexed_db_metadata.h" |
31 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/user_metrics.h" | 31 #include "content/public/browser/user_metrics.h" |
33 #include "content/public/common/content_switches.h" | 32 #include "content/public/common/content_switches.h" |
34 #include "content/public/common/result_codes.h" | 33 #include "content/public/common/result_codes.h" |
35 #include "storage/browser/blob/blob_data_builder.h" | 34 #include "storage/browser/blob/blob_data_builder.h" |
36 #include "storage/browser/blob/blob_storage_context.h" | 35 #include "storage/browser/blob/blob_storage_context.h" |
37 #include "storage/browser/database/database_util.h" | 36 #include "storage/browser/database/database_util.h" |
38 #include "storage/browser/quota/quota_manager_proxy.h" | |
39 #include "storage/common/database/database_identifier.h" | 37 #include "storage/common/database/database_identifier.h" |
40 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h" | 38 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h" |
41 #include "url/origin.h" | 39 #include "url/origin.h" |
42 | 40 |
43 using storage::DatabaseUtil; | 41 using storage::DatabaseUtil; |
44 using blink::WebIDBKey; | 42 using blink::WebIDBKey; |
45 | 43 |
46 namespace content { | 44 namespace content { |
47 | 45 |
48 namespace { | 46 namespace { |
49 | 47 |
50 const char kInvalidOrigin[] = "Origin is invalid"; | 48 const char kInvalidOrigin[] = "Origin is invalid"; |
51 | 49 |
52 bool IsValidOrigin(const url::Origin& origin) { | 50 bool IsValidOrigin(const url::Origin& origin) { |
53 return !origin.unique(); | 51 return !origin.unique(); |
54 } | 52 } |
55 | 53 |
56 } // namespace | 54 } // namespace |
57 | 55 |
58 IndexedDBDispatcherHost::IndexedDBDispatcherHost( | 56 IndexedDBDispatcherHost::IndexedDBDispatcherHost( |
59 int ipc_process_id, | 57 int ipc_process_id, |
60 net::URLRequestContextGetter* request_context_getter, | 58 net::URLRequestContextGetter* request_context_getter, |
61 IndexedDBContextImpl* indexed_db_context, | 59 IndexedDBContextImpl* indexed_db_context, |
62 ChromeBlobStorageContext* blob_storage_context) | 60 ChromeBlobStorageContext* blob_storage_context) |
63 : BrowserMessageFilter(IndexedDBMsgStart), | 61 : BrowserMessageFilter(IndexedDBMsgStart), |
64 BrowserAssociatedInterface(this, this), | 62 BrowserAssociatedInterface(this, this), |
65 request_context_getter_(request_context_getter), | 63 request_context_getter_(request_context_getter), |
66 indexed_db_context_(indexed_db_context), | 64 indexed_db_context_(indexed_db_context), |
67 blob_storage_context_(blob_storage_context), | 65 blob_storage_context_(blob_storage_context), |
68 database_dispatcher_host_(base::MakeUnique<DatabaseDispatcherHost>(this)), | |
69 cursor_dispatcher_host_(base::MakeUnique<CursorDispatcherHost>(this)), | 66 cursor_dispatcher_host_(base::MakeUnique<CursorDispatcherHost>(this)), |
70 ipc_process_id_(ipc_process_id) { | 67 ipc_process_id_(ipc_process_id) { |
71 DCHECK(indexed_db_context_.get()); | 68 DCHECK(indexed_db_context_.get()); |
72 } | 69 } |
73 | 70 |
74 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() {} | 71 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() { |
72 // TODO(alecflett): uncomment these when we find the source of these leaks. | |
73 // DCHECK(transaction_size_map_.empty()); | |
74 // DCHECK(transaction_origin_map_.empty()); | |
75 } | |
75 | 76 |
76 void IndexedDBDispatcherHost::OnChannelClosing() { | 77 void IndexedDBDispatcherHost::OnChannelClosing() { |
77 bool success = indexed_db_context_->TaskRunner()->PostTask( | 78 bool success = indexed_db_context_->TaskRunner()->PostTask( |
78 FROM_HERE, | 79 FROM_HERE, |
79 base::Bind(&IndexedDBDispatcherHost::ResetDispatcherHosts, this)); | 80 base::Bind(&IndexedDBDispatcherHost::ResetDispatcherHosts, this)); |
80 | 81 |
81 if (!success) | 82 if (!success) |
82 ResetDispatcherHosts(); | 83 ResetDispatcherHosts(); |
83 } | 84 } |
84 | 85 |
85 void IndexedDBDispatcherHost::OnDestruct() const { | 86 void IndexedDBDispatcherHost::OnDestruct() const { |
86 // The last reference to the dispatcher may be a posted task, which would | 87 // The last reference to the dispatcher may be a posted task, which would |
87 // be destructed on the IndexedDB thread. Without this override, that would | 88 // be destructed on the IndexedDB thread. Without this override, that would |
88 // take the dispatcher with it. Since the dispatcher may be keeping the | 89 // take the dispatcher with it. Since the dispatcher may be keeping the |
89 // IndexedDBContext alive, it might be destructed to on its own thread, | 90 // IndexedDBContext alive, it might be destructed to on its own thread, |
90 // which is not supported. Ensure destruction runs on the IO thread instead. | 91 // which is not supported. Ensure destruction runs on the IO thread instead. |
91 BrowserThread::DeleteOnIOThread::Destruct(this); | 92 BrowserThread::DeleteOnIOThread::Destruct(this); |
92 } | 93 } |
93 | 94 |
94 void IndexedDBDispatcherHost::ResetDispatcherHosts() { | 95 void IndexedDBDispatcherHost::ResetDispatcherHosts() { |
95 // It is important that the various *_dispatcher_host_ members are reset | 96 // It is important that the various *_dispatcher_host_ members are reset |
96 // on the IndexedDB thread, since there might be incoming messages on that | 97 // on the IndexedDB thread, since there might be incoming messages on that |
97 // thread, and we must not reset the dispatcher hosts until after those | 98 // thread, and we must not reset the dispatcher hosts until after those |
98 // messages are processed. | 99 // messages are processed. |
99 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 100 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
100 | 101 |
101 // Prevent any pending connections from being processed. | 102 // Prevent any pending connections from being processed. |
102 is_open_ = false; | 103 is_open_ = false; |
103 | 104 |
104 // Note that we explicitly separate CloseAll() from destruction of the | |
105 // DatabaseDispatcherHost, since CloseAll() can invoke callbacks which need to | |
106 // be dispatched through database_dispatcher_host_. | |
107 database_dispatcher_host_->CloseAll(); | |
108 database_dispatcher_host_.reset(); | |
109 cursor_dispatcher_host_.reset(); | 105 cursor_dispatcher_host_.reset(); |
110 } | 106 } |
111 | 107 |
112 base::TaskRunner* IndexedDBDispatcherHost::OverrideTaskRunnerForMessage( | 108 base::TaskRunner* IndexedDBDispatcherHost::OverrideTaskRunnerForMessage( |
113 const IPC::Message& message) { | 109 const IPC::Message& message) { |
114 if (IPC_MESSAGE_CLASS(message) != IndexedDBMsgStart) | 110 if (IPC_MESSAGE_CLASS(message) != IndexedDBMsgStart) |
115 return NULL; | 111 return NULL; |
116 | 112 |
117 switch (message.type()) { | 113 switch (message.type()) { |
118 case IndexedDBHostMsg_DatabasePut::ID: | |
119 case IndexedDBHostMsg_AckReceivedBlobs::ID: | 114 case IndexedDBHostMsg_AckReceivedBlobs::ID: |
120 return NULL; | 115 return NULL; |
121 default: | 116 default: |
122 return indexed_db_context_->TaskRunner(); | 117 return indexed_db_context_->TaskRunner(); |
123 } | 118 } |
124 } | 119 } |
125 | 120 |
126 bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message) { | 121 bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message) { |
127 if (IPC_MESSAGE_CLASS(message) != IndexedDBMsgStart) | 122 if (IPC_MESSAGE_CLASS(message) != IndexedDBMsgStart) |
128 return false; | 123 return false; |
129 | 124 |
130 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread() || | 125 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread() || |
131 (message.type() == IndexedDBHostMsg_DatabasePut::ID || | 126 message.type() == IndexedDBHostMsg_AckReceivedBlobs::ID); |
132 message.type() == IndexedDBHostMsg_AckReceivedBlobs::ID)); | |
133 | 127 |
134 bool handled = database_dispatcher_host_->OnMessageReceived(message) || | 128 bool handled = cursor_dispatcher_host_->OnMessageReceived(message); |
135 cursor_dispatcher_host_->OnMessageReceived(message); | |
136 | 129 |
137 if (!handled) { | 130 if (!handled) { |
138 handled = true; | 131 handled = true; |
139 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcherHost, message) | 132 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcherHost, message) |
140 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_AckReceivedBlobs, OnAckReceivedBlobs) | 133 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_AckReceivedBlobs, OnAckReceivedBlobs) |
141 IPC_MESSAGE_UNHANDLED(handled = false) | 134 IPC_MESSAGE_UNHANDLED(handled = false) |
142 IPC_END_MESSAGE_MAP() | 135 IPC_END_MESSAGE_MAP() |
143 } | 136 } |
144 return handled; | 137 return handled; |
145 } | 138 } |
146 | 139 |
147 int32_t IndexedDBDispatcherHost::Add(IndexedDBCursor* cursor) { | 140 int32_t IndexedDBDispatcherHost::Add(IndexedDBCursor* cursor) { |
148 if (!cursor_dispatcher_host_) { | 141 if (!cursor_dispatcher_host_) { |
149 return 0; | 142 return 0; |
150 } | 143 } |
151 return cursor_dispatcher_host_->map_.Add(cursor); | 144 return cursor_dispatcher_host_->map_.Add(cursor); |
152 } | 145 } |
153 | 146 |
154 int32_t IndexedDBDispatcherHost::Add(IndexedDBConnection* connection, | 147 bool IndexedDBDispatcherHost::RegisterTransactionId(int64_t host_transaction_id, |
155 const url::Origin& origin) { | 148 const url::Origin& origin) { |
156 if (!database_dispatcher_host_) { | 149 if (base::ContainsKey(transaction_size_map_, host_transaction_id)) |
157 connection->Close(); | 150 return false; |
158 delete connection; | 151 transaction_size_map_[host_transaction_id] = 0; |
159 return -1; | 152 transaction_origin_map_[host_transaction_id] = origin; |
160 } | 153 return true; |
161 int32_t ipc_database_id = database_dispatcher_host_->map_.Add(connection); | |
162 context()->ConnectionOpened(origin, connection); | |
163 database_dispatcher_host_->database_origin_map_[ipc_database_id] = origin; | |
164 return ipc_database_id; | |
165 } | 154 } |
166 | 155 |
167 void IndexedDBDispatcherHost::RegisterTransactionId(int64_t host_transaction_id, | 156 bool IndexedDBDispatcherHost::GetTransactionSize(int64_t host_transaction_id, |
168 const url::Origin& origin) { | 157 int64_t* transaction_size) { |
169 if (!database_dispatcher_host_) | 158 const auto it = transaction_size_map_.find(host_transaction_id); |
170 return; | 159 if (it == transaction_size_map_.end()) |
171 database_dispatcher_host_->transaction_size_map_[host_transaction_id] = 0; | 160 return false; |
172 database_dispatcher_host_->transaction_origin_map_[host_transaction_id] = | 161 *transaction_size = it->second; |
173 origin; | 162 return true; |
163 } | |
164 | |
165 void IndexedDBDispatcherHost::AddToTransaction(int64_t host_transaction_id, | |
166 int64_t value_length) { | |
167 transaction_size_map_[host_transaction_id] += value_length; | |
174 } | 168 } |
175 | 169 |
176 int64_t IndexedDBDispatcherHost::HostTransactionId(int64_t transaction_id) { | 170 int64_t IndexedDBDispatcherHost::HostTransactionId(int64_t transaction_id) { |
177 // Inject the renderer process id into the transaction id, to | 171 // Inject the renderer process id into the transaction id, to |
178 // uniquely identify this transaction, and effectively bind it to | 172 // uniquely identify this transaction, and effectively bind it to |
179 // the renderer that initiated it. The lower 32 bits of | 173 // the renderer that initiated it. The lower 32 bits of |
180 // transaction_id are guaranteed to be unique within that renderer. | 174 // transaction_id are guaranteed to be unique within that renderer. |
181 base::ProcessId pid = peer_pid(); | 175 base::ProcessId pid = peer_pid(); |
182 DCHECK(!(transaction_id >> 32)) << "Transaction ids can only be 32 bits"; | 176 DCHECK(!(transaction_id >> 32)) << "Transaction ids can only be 32 bits"; |
183 static_assert(sizeof(base::ProcessId) <= sizeof(int32_t), | 177 static_assert(sizeof(base::ProcessId) <= sizeof(int32_t), |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 const url::Origin& origin, | 378 const url::Origin& origin, |
385 const base::string16& name) { | 379 const base::string16& name) { |
386 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 380 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
387 | 381 |
388 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 382 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
389 DCHECK(request_context_getter_); | 383 DCHECK(request_context_getter_); |
390 context()->GetIDBFactory()->DeleteDatabase( | 384 context()->GetIDBFactory()->DeleteDatabase( |
391 name, request_context_getter_, callbacks, origin, indexed_db_path); | 385 name, request_context_getter_, callbacks, origin, indexed_db_path); |
392 } | 386 } |
393 | 387 |
394 // OnPutHelper exists only to allow us to hop threads while holding a reference | |
395 // to the IndexedDBDispatcherHost. | |
396 void IndexedDBDispatcherHost::OnPutHelper( | |
397 const IndexedDBHostMsg_DatabasePut_Params& params, | |
398 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles) { | |
399 database_dispatcher_host_->OnPut(params, std::move(handles)); | |
400 } | |
401 | |
402 void IndexedDBDispatcherHost::OnAckReceivedBlobs( | 388 void IndexedDBDispatcherHost::OnAckReceivedBlobs( |
403 const std::vector<std::string>& uuids) { | 389 const std::vector<std::string>& uuids) { |
404 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 390 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
405 for (const auto& uuid : uuids) | 391 for (const auto& uuid : uuids) |
406 DropBlobData(uuid); | 392 DropBlobData(uuid); |
407 } | 393 } |
408 | 394 |
409 void IndexedDBDispatcherHost::FinishTransaction(int64_t host_transaction_id, | 395 void IndexedDBDispatcherHost::FinishTransaction(int64_t host_transaction_id, |
410 bool committed) { | 396 bool committed) { |
411 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 397 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
412 if (!database_dispatcher_host_) | |
413 return; | |
414 TransactionIDToOriginMap& transaction_origin_map = | |
415 database_dispatcher_host_->transaction_origin_map_; | |
416 TransactionIDToSizeMap& transaction_size_map = | |
417 database_dispatcher_host_->transaction_size_map_; | |
418 TransactionIDToDatabaseIDMap& transaction_database_map = | |
419 database_dispatcher_host_->transaction_database_map_; | |
420 if (committed) | 398 if (committed) |
421 context()->TransactionComplete(transaction_origin_map[host_transaction_id]); | 399 context()->TransactionComplete( |
cmumford
2016/10/28 18:40:53
Nested statement is now multi-line so wrap in brac
Reilly Grant (use Gerrit)
2016/11/03 21:32:21
Done.
| |
422 transaction_origin_map.erase(host_transaction_id); | 400 transaction_origin_map_[host_transaction_id]); |
423 transaction_size_map.erase(host_transaction_id); | 401 transaction_origin_map_.erase(host_transaction_id); |
424 transaction_database_map.erase(host_transaction_id); | 402 transaction_size_map_.erase(host_transaction_id); |
425 } | 403 } |
426 | 404 |
427 ////////////////////////////////////////////////////////////////////// | 405 ////////////////////////////////////////////////////////////////////// |
428 // Helper templates. | 406 // Helper templates. |
429 // | 407 // |
430 | 408 |
431 template <typename ObjectType> | 409 template <typename ObjectType> |
432 ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess( | 410 ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess( |
433 IDMap<ObjectType, IDMapOwnPointer>* map, | |
434 int32_t ipc_return_object_id) { | |
435 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | |
436 ObjectType* return_object = map->Lookup(ipc_return_object_id); | |
437 if (!return_object) { | |
438 NOTREACHED() << "Uh oh, couldn't find object with id " | |
439 << ipc_return_object_id; | |
440 bad_message::ReceivedBadMessage(this, bad_message::IDBDH_GET_OR_TERMINATE); | |
441 } | |
442 return return_object; | |
443 } | |
444 | |
445 template <typename ObjectType> | |
446 ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess( | |
447 RefIDMap<ObjectType>* map, | 411 RefIDMap<ObjectType>* map, |
448 int32_t ipc_return_object_id) { | 412 int32_t ipc_return_object_id) { |
449 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 413 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
450 ObjectType* return_object = map->Lookup(ipc_return_object_id); | 414 ObjectType* return_object = map->Lookup(ipc_return_object_id); |
451 if (!return_object) { | 415 if (!return_object) { |
452 NOTREACHED() << "Uh oh, couldn't find object with id " | 416 NOTREACHED() << "Uh oh, couldn't find object with id " |
453 << ipc_return_object_id; | 417 << ipc_return_object_id; |
454 bad_message::ReceivedBadMessage(this, bad_message::IDBDH_GET_OR_TERMINATE); | 418 bad_message::ReceivedBadMessage(this, bad_message::IDBDH_GET_OR_TERMINATE); |
455 } | 419 } |
456 return return_object; | 420 return return_object; |
457 } | 421 } |
458 | 422 |
459 template <typename MapType> | 423 template <typename MapType> |
460 void IndexedDBDispatcherHost::DestroyObject(MapType* map, | 424 void IndexedDBDispatcherHost::DestroyObject(MapType* map, |
461 int32_t ipc_object_id) { | 425 int32_t ipc_object_id) { |
462 GetOrTerminateProcess(map, ipc_object_id); | 426 GetOrTerminateProcess(map, ipc_object_id); |
463 map->Remove(ipc_object_id); | 427 map->Remove(ipc_object_id); |
464 } | 428 } |
465 | 429 |
466 ////////////////////////////////////////////////////////////////////// | 430 ////////////////////////////////////////////////////////////////////// |
467 // IndexedDBDispatcherHost::DatabaseDispatcherHost | |
468 // | |
469 | |
470 IndexedDBDispatcherHost::DatabaseDispatcherHost::DatabaseDispatcherHost( | |
471 IndexedDBDispatcherHost* parent) | |
472 : parent_(parent), weak_factory_(this) { | |
473 map_.set_check_on_null_data(true); | |
474 } | |
475 | |
476 IndexedDBDispatcherHost::DatabaseDispatcherHost::~DatabaseDispatcherHost() { | |
477 // TODO(alecflett): uncomment these when we find the source of these leaks. | |
478 // DCHECK(transaction_size_map_.empty()); | |
479 // DCHECK(transaction_origin_map_.empty()); | |
480 } | |
481 | |
482 void IndexedDBDispatcherHost::DatabaseDispatcherHost::CloseAll() { | |
483 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
484 // Abort outstanding transactions started by connections in the associated | |
485 // front-end to unblock later transactions. This should only occur on unclean | |
486 // (crash) or abrupt (process-kill) shutdowns. | |
487 for (TransactionIDToDatabaseIDMap::iterator iter = | |
488 transaction_database_map_.begin(); | |
489 iter != transaction_database_map_.end();) { | |
490 int64_t transaction_id = iter->first; | |
491 int32_t ipc_database_id = iter->second; | |
492 ++iter; | |
493 IndexedDBConnection* connection = map_.Lookup(ipc_database_id); | |
494 if (connection && connection->IsConnected()) { | |
495 connection->database()->Abort( | |
496 transaction_id, | |
497 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError)); | |
498 } | |
499 } | |
500 DCHECK(transaction_database_map_.empty()); | |
501 | |
502 for (const auto& iter : database_origin_map_) { | |
503 IndexedDBConnection* connection = map_.Lookup(iter.first); | |
504 if (connection && connection->IsConnected()) { | |
505 connection->Close(); | |
506 parent_->context()->ConnectionClosed(iter.second, connection); | |
507 } | |
508 } | |
509 } | |
510 | |
511 bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived( | |
512 const IPC::Message& message) { | |
513 DCHECK((message.type() == IndexedDBHostMsg_DatabasePut::ID || | |
514 message.type() == IndexedDBHostMsg_AckReceivedBlobs::ID) || | |
515 parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
516 | |
517 bool handled = true; | |
518 IPC_BEGIN_MESSAGE_MAP( | |
519 IndexedDBDispatcherHost::DatabaseDispatcherHost, message) | |
520 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore, | |
521 OnCreateObjectStore) | |
522 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore, | |
523 OnDeleteObjectStore) | |
524 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseRenameObjectStore, | |
525 OnRenameObjectStore) | |
526 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction, | |
527 OnCreateTransaction) | |
528 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose) | |
529 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseVersionChangeIgnored, | |
530 OnVersionChangeIgnored) | |
531 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed) | |
532 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseObserve, OnObserve) | |
533 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseUnobserve, OnUnobserve) | |
534 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGet, OnGet) | |
535 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGetAll, OnGetAll) | |
536 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabasePut, OnPutWrapper) | |
537 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexKeys, OnSetIndexKeys) | |
538 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexesReady, | |
539 OnSetIndexesReady) | |
540 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseOpenCursor, OnOpenCursor) | |
541 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCount, OnCount) | |
542 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteRange, OnDeleteRange) | |
543 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClear, OnClear) | |
544 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateIndex, OnCreateIndex) | |
545 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteIndex, OnDeleteIndex) | |
546 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseRenameIndex, OnRenameIndex) | |
547 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseAbort, OnAbort) | |
548 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCommit, OnCommit) | |
549 IPC_MESSAGE_UNHANDLED(handled = false) | |
550 IPC_END_MESSAGE_MAP() | |
551 | |
552 return handled; | |
553 } | |
554 | |
555 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore( | |
556 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params) { | |
557 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
558 IndexedDBConnection* connection = | |
559 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | |
560 if (!connection || !connection->IsConnected()) | |
561 return; | |
562 | |
563 int64_t host_transaction_id = | |
564 parent_->HostTransactionId(params.transaction_id); | |
565 connection->database()->CreateObjectStore(host_transaction_id, | |
566 params.object_store_id, | |
567 params.name, | |
568 params.key_path, | |
569 params.auto_increment); | |
570 } | |
571 | |
572 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore( | |
573 int32_t ipc_database_id, | |
574 int64_t transaction_id, | |
575 int64_t object_store_id) { | |
576 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
577 IndexedDBConnection* connection = | |
578 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | |
579 if (!connection || !connection->IsConnected()) | |
580 return; | |
581 | |
582 connection->database()->DeleteObjectStore( | |
583 parent_->HostTransactionId(transaction_id), object_store_id); | |
584 } | |
585 | |
586 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnRenameObjectStore( | |
587 int32_t ipc_database_id, | |
588 int64_t transaction_id, | |
589 int64_t object_store_id, | |
590 const base::string16& new_name) { | |
591 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
592 IndexedDBConnection* connection = | |
593 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | |
594 if (!connection || !connection->IsConnected()) | |
595 return; | |
596 | |
597 connection->database()->RenameObjectStore( | |
598 parent_->HostTransactionId(transaction_id), object_store_id, new_name); | |
599 } | |
600 | |
601 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateTransaction( | |
602 const IndexedDBHostMsg_DatabaseCreateTransaction_Params& params) { | |
603 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
604 IndexedDBConnection* connection = | |
605 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | |
606 if (!connection || !connection->IsConnected()) | |
607 return; | |
608 | |
609 int64_t host_transaction_id = | |
610 parent_->HostTransactionId(params.transaction_id); | |
611 | |
612 if (base::ContainsKey(transaction_database_map_, host_transaction_id)) { | |
613 DLOG(ERROR) << "Duplicate host_transaction_id."; | |
614 return; | |
615 } | |
616 | |
617 connection->database()->CreateTransaction( | |
618 host_transaction_id, connection, params.object_store_ids, params.mode); | |
619 transaction_database_map_[host_transaction_id] = params.ipc_database_id; | |
620 parent_->RegisterTransactionId(host_transaction_id, | |
621 database_origin_map_[params.ipc_database_id]); | |
622 } | |
623 | |
624 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClose( | |
625 int32_t ipc_database_id) { | |
626 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
627 IndexedDBConnection* connection = | |
628 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | |
629 if (!connection || !connection->IsConnected()) | |
630 return; | |
631 connection->Close(); | |
632 } | |
633 | |
634 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnVersionChangeIgnored( | |
635 int32_t ipc_database_id) { | |
636 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
637 IndexedDBConnection* connection = | |
638 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | |
639 if (!connection || !connection->IsConnected()) | |
640 return; | |
641 connection->VersionChangeIgnored(); | |
642 } | |
643 | |
644 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed( | |
645 int32_t ipc_object_id) { | |
646 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
647 IndexedDBConnection* connection = | |
648 parent_->GetOrTerminateProcess(&map_, ipc_object_id); | |
649 if (!connection) | |
650 return; | |
651 if (connection->IsConnected()) | |
652 connection->Close(); | |
653 parent_->context()->ConnectionClosed(database_origin_map_[ipc_object_id], | |
654 connection); | |
655 database_origin_map_.erase(ipc_object_id); | |
656 parent_->DestroyObject(&map_, ipc_object_id); | |
657 } | |
658 | |
659 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnObserve( | |
660 const IndexedDBHostMsg_DatabaseObserve_Params& params) { | |
661 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
662 IndexedDBConnection* connection = | |
663 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | |
664 if (!connection || !connection->IsConnected()) | |
665 return; | |
666 IndexedDBObserver::Options options(params.include_transaction, | |
667 params.no_records, params.values, | |
668 params.operation_types); | |
669 connection->database()->AddPendingObserver( | |
670 parent_->HostTransactionId(params.transaction_id), params.observer_id, | |
671 options); | |
672 } | |
673 | |
674 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnUnobserve( | |
675 int32_t ipc_database_id, | |
676 const std::vector<int32_t>& observer_ids_to_remove) { | |
677 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
678 DCHECK(!observer_ids_to_remove.empty()); | |
679 IndexedDBConnection* connection = | |
680 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | |
681 if (!connection || !connection->IsConnected()) | |
682 return; | |
683 connection->RemoveObservers(observer_ids_to_remove); | |
684 } | |
685 | |
686 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet( | |
687 const IndexedDBHostMsg_DatabaseGet_Params& params) { | |
688 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
689 IndexedDBConnection* connection = | |
690 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | |
691 if (!connection || !connection->IsConnected()) | |
692 return; | |
693 | |
694 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | |
695 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | |
696 connection->database()->Get( | |
697 parent_->HostTransactionId(params.transaction_id), params.object_store_id, | |
698 params.index_id, base::MakeUnique<IndexedDBKeyRange>(params.key_range), | |
699 params.key_only, callbacks); | |
700 } | |
701 | |
702 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGetAll( | |
703 const IndexedDBHostMsg_DatabaseGetAll_Params& params) { | |
704 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
705 IndexedDBConnection* connection = | |
706 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | |
707 if (!connection || !connection->IsConnected()) | |
708 return; | |
709 | |
710 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | |
711 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | |
712 connection->database()->GetAll( | |
713 parent_->HostTransactionId(params.transaction_id), params.object_store_id, | |
714 params.index_id, base::MakeUnique<IndexedDBKeyRange>(params.key_range), | |
715 params.key_only, params.max_count, callbacks); | |
716 } | |
717 | |
718 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPutWrapper( | |
719 const IndexedDBHostMsg_DatabasePut_Params& params) { | |
720 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; | |
721 for (const auto& info : params.value.blob_or_file_info) { | |
722 handles.push_back( | |
723 parent_->blob_storage_context_->context()->GetBlobDataFromUUID( | |
724 info.uuid)); | |
725 } | |
726 parent_->context()->TaskRunner()->PostTask( | |
727 FROM_HERE, base::Bind(&IndexedDBDispatcherHost::OnPutHelper, parent_, | |
728 params, base::Passed(&handles))); | |
729 } | |
730 | |
731 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( | |
732 const IndexedDBHostMsg_DatabasePut_Params& params, | |
733 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles) { | |
734 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
735 | |
736 std::vector<std::unique_ptr<storage::BlobDataHandle>> scoped_handles; | |
737 scoped_handles.swap(handles); | |
738 | |
739 IndexedDBConnection* connection = | |
740 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | |
741 if (!connection || !connection->IsConnected()) | |
742 return; | |
743 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | |
744 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | |
745 | |
746 int64_t host_transaction_id = | |
747 parent_->HostTransactionId(params.transaction_id); | |
748 | |
749 std::vector<IndexedDBBlobInfo> blob_info( | |
750 params.value.blob_or_file_info.size()); | |
751 | |
752 ChildProcessSecurityPolicyImpl* policy = | |
753 ChildProcessSecurityPolicyImpl::GetInstance(); | |
754 | |
755 size_t i = 0; | |
756 for (const auto& info : params.value.blob_or_file_info) { | |
757 if (info.is_file) { | |
758 base::FilePath path; | |
759 if (!info.file_path.empty()) { | |
760 path = base::FilePath::FromUTF16Unsafe(info.file_path); | |
761 if (!policy->CanReadFile(parent_->ipc_process_id_, path)) { | |
762 bad_message::ReceivedBadMessage(parent_, | |
763 bad_message::IDBDH_CAN_READ_FILE); | |
764 return; | |
765 } | |
766 } | |
767 blob_info[i] = | |
768 IndexedDBBlobInfo(info.uuid, path, info.file_name, info.mime_type); | |
769 if (info.size != static_cast<uint64_t>(-1)) { | |
770 blob_info[i].set_last_modified( | |
771 base::Time::FromDoubleT(info.last_modified)); | |
772 blob_info[i].set_size(info.size); | |
773 } | |
774 } else { | |
775 blob_info[i] = IndexedDBBlobInfo(info.uuid, info.mime_type, info.size); | |
776 } | |
777 ++i; | |
778 } | |
779 | |
780 // TODO(alecflett): Avoid a copy here. | |
781 IndexedDBValue value; | |
782 value.bits = params.value.bits; | |
783 value.blob_info.swap(blob_info); | |
784 connection->database()->Put(host_transaction_id, params.object_store_id, | |
785 &value, &scoped_handles, | |
786 base::MakeUnique<IndexedDBKey>(params.key), | |
787 params.put_mode, callbacks, params.index_keys); | |
788 // Size can't be big enough to overflow because it represents the | |
789 // actual bytes passed through IPC. | |
790 transaction_size_map_[host_transaction_id] += params.value.bits.size(); | |
791 } | |
792 | |
793 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexKeys( | |
794 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params) { | |
795 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
796 IndexedDBConnection* connection = | |
797 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | |
798 if (!connection || !connection->IsConnected()) | |
799 return; | |
800 | |
801 int64_t host_transaction_id = | |
802 parent_->HostTransactionId(params.transaction_id); | |
803 connection->database()->SetIndexKeys( | |
804 host_transaction_id, params.object_store_id, | |
805 base::MakeUnique<IndexedDBKey>(params.primary_key), params.index_keys); | |
806 } | |
807 | |
808 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexesReady( | |
809 int32_t ipc_database_id, | |
810 int64_t transaction_id, | |
811 int64_t object_store_id, | |
812 const std::vector<int64_t>& index_ids) { | |
813 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
814 IndexedDBConnection* connection = | |
815 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | |
816 if (!connection || !connection->IsConnected()) | |
817 return; | |
818 | |
819 connection->database()->SetIndexesReady( | |
820 parent_->HostTransactionId(transaction_id), object_store_id, index_ids); | |
821 } | |
822 | |
823 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor( | |
824 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) { | |
825 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
826 IndexedDBConnection* connection = | |
827 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | |
828 if (!connection || !connection->IsConnected()) | |
829 return; | |
830 | |
831 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | |
832 parent_, params.ipc_thread_id, params.ipc_callbacks_id, -1)); | |
833 connection->database()->OpenCursor( | |
834 parent_->HostTransactionId(params.transaction_id), params.object_store_id, | |
835 params.index_id, base::MakeUnique<IndexedDBKeyRange>(params.key_range), | |
836 params.direction, params.key_only, params.task_type, callbacks); | |
837 } | |
838 | |
839 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCount( | |
840 const IndexedDBHostMsg_DatabaseCount_Params& params) { | |
841 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
842 IndexedDBConnection* connection = | |
843 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | |
844 if (!connection || !connection->IsConnected()) | |
845 return; | |
846 | |
847 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | |
848 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | |
849 connection->database()->Count( | |
850 parent_->HostTransactionId(params.transaction_id), params.object_store_id, | |
851 params.index_id, base::MakeUnique<IndexedDBKeyRange>(params.key_range), | |
852 callbacks); | |
853 } | |
854 | |
855 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteRange( | |
856 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params) { | |
857 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
858 IndexedDBConnection* connection = | |
859 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | |
860 if (!connection || !connection->IsConnected()) | |
861 return; | |
862 | |
863 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | |
864 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | |
865 connection->database()->DeleteRange( | |
866 parent_->HostTransactionId(params.transaction_id), params.object_store_id, | |
867 base::MakeUnique<IndexedDBKeyRange>(params.key_range), callbacks); | |
868 } | |
869 | |
870 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClear( | |
871 int32_t ipc_thread_id, | |
872 int32_t ipc_callbacks_id, | |
873 int32_t ipc_database_id, | |
874 int64_t transaction_id, | |
875 int64_t object_store_id) { | |
876 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
877 IndexedDBConnection* connection = | |
878 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | |
879 if (!connection || !connection->IsConnected()) | |
880 return; | |
881 | |
882 scoped_refptr<IndexedDBCallbacks> callbacks( | |
883 new IndexedDBCallbacks(parent_, ipc_thread_id, ipc_callbacks_id)); | |
884 | |
885 connection->database()->Clear( | |
886 parent_->HostTransactionId(transaction_id), object_store_id, callbacks); | |
887 } | |
888 | |
889 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnAbort( | |
890 int32_t ipc_database_id, | |
891 int64_t transaction_id) { | |
892 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
893 IndexedDBConnection* connection = | |
894 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | |
895 if (!connection || !connection->IsConnected()) | |
896 return; | |
897 | |
898 connection->database()->Abort(parent_->HostTransactionId(transaction_id)); | |
899 } | |
900 | |
901 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCommit( | |
902 int32_t ipc_database_id, | |
903 int64_t transaction_id) { | |
904 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
905 IndexedDBConnection* connection = | |
906 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | |
907 if (!connection || !connection->IsConnected()) | |
908 return; | |
909 | |
910 int64_t host_transaction_id = parent_->HostTransactionId(transaction_id); | |
911 // May have been aborted by back end before front-end could request commit. | |
912 if (!base::ContainsKey(transaction_size_map_, host_transaction_id)) | |
913 return; | |
914 int64_t transaction_size = transaction_size_map_[host_transaction_id]; | |
915 | |
916 // Always allow empty or delete-only transactions. | |
917 if (!transaction_size) { | |
918 connection->database()->Commit(host_transaction_id); | |
919 return; | |
920 } | |
921 | |
922 parent_->context()->quota_manager_proxy()->GetUsageAndQuota( | |
923 parent_->context()->TaskRunner(), | |
924 GURL(transaction_origin_map_[host_transaction_id].Serialize()), | |
925 storage::kStorageTypeTemporary, | |
926 base::Bind(&IndexedDBDispatcherHost::DatabaseDispatcherHost:: | |
927 OnGotUsageAndQuotaForCommit, | |
928 weak_factory_.GetWeakPtr(), ipc_database_id, transaction_id)); | |
929 } | |
930 | |
931 void IndexedDBDispatcherHost::DatabaseDispatcherHost:: | |
932 OnGotUsageAndQuotaForCommit(int32_t ipc_database_id, | |
933 int64_t transaction_id, | |
934 storage::QuotaStatusCode status, | |
935 int64_t usage, | |
936 int64_t quota) { | |
937 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
938 IndexedDBConnection* connection = map_.Lookup(ipc_database_id); | |
939 // May have disconnected while quota check was pending. | |
940 if (!connection || !connection->IsConnected()) | |
941 return; | |
942 int64_t host_transaction_id = parent_->HostTransactionId(transaction_id); | |
943 // May have aborted while quota check was pending. | |
944 if (!base::ContainsKey(transaction_size_map_, host_transaction_id)) | |
945 return; | |
946 int64_t transaction_size = transaction_size_map_[host_transaction_id]; | |
947 | |
948 if (status == storage::kQuotaStatusOk && | |
949 usage + transaction_size <= quota) { | |
950 connection->database()->Commit(host_transaction_id); | |
951 } else { | |
952 connection->database()->Abort( | |
953 host_transaction_id, | |
954 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError)); | |
955 } | |
956 } | |
957 | |
958 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex( | |
959 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) { | |
960 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
961 IndexedDBConnection* connection = | |
962 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | |
963 if (!connection || !connection->IsConnected()) | |
964 return; | |
965 | |
966 int64_t host_transaction_id = | |
967 parent_->HostTransactionId(params.transaction_id); | |
968 connection->database()->CreateIndex(host_transaction_id, | |
969 params.object_store_id, | |
970 params.index_id, | |
971 params.name, | |
972 params.key_path, | |
973 params.unique, | |
974 params.multi_entry); | |
975 } | |
976 | |
977 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex( | |
978 int32_t ipc_database_id, | |
979 int64_t transaction_id, | |
980 int64_t object_store_id, | |
981 int64_t index_id) { | |
982 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
983 IndexedDBConnection* connection = | |
984 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | |
985 if (!connection || !connection->IsConnected()) | |
986 return; | |
987 | |
988 connection->database()->DeleteIndex( | |
989 parent_->HostTransactionId(transaction_id), object_store_id, index_id); | |
990 } | |
991 | |
992 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnRenameIndex( | |
993 int32_t ipc_database_id, | |
994 int64_t transaction_id, | |
995 int64_t object_store_id, | |
996 int64_t index_id, | |
997 const base::string16& new_name) { | |
998 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
999 IndexedDBConnection* connection = | |
1000 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | |
1001 if (!connection || !connection->IsConnected()) | |
1002 return; | |
1003 | |
1004 connection->database()->RenameIndex( | |
1005 parent_->HostTransactionId(transaction_id), object_store_id, index_id, | |
1006 new_name); | |
1007 } | |
1008 | |
1009 ////////////////////////////////////////////////////////////////////// | |
1010 // IndexedDBDispatcherHost::CursorDispatcherHost | 431 // IndexedDBDispatcherHost::CursorDispatcherHost |
1011 // | 432 // |
1012 | 433 |
1013 IndexedDBDispatcherHost::CursorDispatcherHost::CursorDispatcherHost( | 434 IndexedDBDispatcherHost::CursorDispatcherHost::CursorDispatcherHost( |
1014 IndexedDBDispatcherHost* parent) | 435 IndexedDBDispatcherHost* parent) |
1015 : parent_(parent) { | 436 : parent_(parent) { |
1016 map_.set_check_on_null_data(true); | |
1017 } | 437 } |
1018 | 438 |
1019 IndexedDBDispatcherHost::CursorDispatcherHost::~CursorDispatcherHost() {} | 439 IndexedDBDispatcherHost::CursorDispatcherHost::~CursorDispatcherHost() {} |
1020 | 440 |
1021 bool IndexedDBDispatcherHost::CursorDispatcherHost::OnMessageReceived( | 441 bool IndexedDBDispatcherHost::CursorDispatcherHost::OnMessageReceived( |
1022 const IPC::Message& message) { | 442 const IPC::Message& message) { |
1023 bool handled = true; | 443 bool handled = true; |
1024 IPC_BEGIN_MESSAGE_MAP( | 444 IPC_BEGIN_MESSAGE_MAP( |
1025 IndexedDBDispatcherHost::CursorDispatcherHost, message) | 445 IndexedDBDispatcherHost::CursorDispatcherHost, message) |
1026 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorAdvance, OnAdvance) | 446 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorAdvance, OnAdvance) |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1109 DLOG(ERROR) << "Unable to reset prefetch"; | 529 DLOG(ERROR) << "Unable to reset prefetch"; |
1110 } | 530 } |
1111 | 531 |
1112 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( | 532 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( |
1113 int32_t ipc_object_id) { | 533 int32_t ipc_object_id) { |
1114 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 534 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
1115 parent_->DestroyObject(&map_, ipc_object_id); | 535 parent_->DestroyObject(&map_, ipc_object_id); |
1116 } | 536 } |
1117 | 537 |
1118 } // namespace content | 538 } // namespace content |
OLD | NEW |