| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/process/process.h" | 10 #include "base/process/process.h" |
| 11 #include "base/stl_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "content/browser/indexed_db/indexed_db_callbacks.h" | 13 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
| 13 #include "content/browser/indexed_db/indexed_db_connection.h" | 14 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 14 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 15 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 15 #include "content/browser/indexed_db/indexed_db_cursor.h" | 16 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 16 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 17 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
| 17 #include "content/browser/indexed_db/indexed_db_metadata.h" | 18 #include "content/browser/indexed_db/indexed_db_metadata.h" |
| 18 #include "content/browser/renderer_host/render_message_filter.h" | 19 #include "content/browser/renderer_host/render_message_filter.h" |
| 19 #include "content/common/indexed_db/indexed_db_messages.h" | 20 #include "content/common/indexed_db/indexed_db_messages.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 33 | 34 |
| 34 IndexedDBDispatcherHost::IndexedDBDispatcherHost( | 35 IndexedDBDispatcherHost::IndexedDBDispatcherHost( |
| 35 IndexedDBContextImpl* indexed_db_context) | 36 IndexedDBContextImpl* indexed_db_context) |
| 36 : BrowserMessageFilter(IndexedDBMsgStart), | 37 : BrowserMessageFilter(IndexedDBMsgStart), |
| 37 indexed_db_context_(indexed_db_context), | 38 indexed_db_context_(indexed_db_context), |
| 38 database_dispatcher_host_(new DatabaseDispatcherHost(this)), | 39 database_dispatcher_host_(new DatabaseDispatcherHost(this)), |
| 39 cursor_dispatcher_host_(new CursorDispatcherHost(this)) { | 40 cursor_dispatcher_host_(new CursorDispatcherHost(this)) { |
| 40 DCHECK(indexed_db_context_); | 41 DCHECK(indexed_db_context_); |
| 41 } | 42 } |
| 42 | 43 |
| 43 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() {} | 44 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() { |
| 45 STLDeleteValues(&blob_data_handle_map_); |
| 46 } |
| 44 | 47 |
| 45 void IndexedDBDispatcherHost::OnChannelClosing() { | 48 void IndexedDBDispatcherHost::OnChannelClosing() { |
| 46 bool success = indexed_db_context_->TaskRunner()->PostTask( | 49 bool success = indexed_db_context_->TaskRunner()->PostTask( |
| 47 FROM_HERE, | 50 FROM_HERE, |
| 48 base::Bind(&IndexedDBDispatcherHost::ResetDispatcherHosts, this)); | 51 base::Bind(&IndexedDBDispatcherHost::ResetDispatcherHosts, this)); |
| 49 | 52 |
| 50 if (!success) | 53 if (!success) |
| 51 ResetDispatcherHosts(); | 54 ResetDispatcherHosts(); |
| 52 } | 55 } |
| 53 | 56 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 cursor_dispatcher_host_->OnMessageReceived(message, message_was_ok); | 97 cursor_dispatcher_host_->OnMessageReceived(message, message_was_ok); |
| 95 | 98 |
| 96 if (!handled) { | 99 if (!handled) { |
| 97 handled = true; | 100 handled = true; |
| 98 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost, message, *message_was_ok) | 101 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost, message, *message_was_ok) |
| 99 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryGetDatabaseNames, | 102 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryGetDatabaseNames, |
| 100 OnIDBFactoryGetDatabaseNames) | 103 OnIDBFactoryGetDatabaseNames) |
| 101 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryOpen, OnIDBFactoryOpen) | 104 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryOpen, OnIDBFactoryOpen) |
| 102 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryDeleteDatabase, | 105 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryDeleteDatabase, |
| 103 OnIDBFactoryDeleteDatabase) | 106 OnIDBFactoryDeleteDatabase) |
| 107 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_AckReceivedBlobs, OnAckReceivedBlobs) |
| 104 IPC_MESSAGE_UNHANDLED(handled = false) | 108 IPC_MESSAGE_UNHANDLED(handled = false) |
| 105 IPC_END_MESSAGE_MAP() | 109 IPC_END_MESSAGE_MAP() |
| 106 } | 110 } |
| 107 return handled; | 111 return handled; |
| 108 } | 112 } |
| 109 | 113 |
| 110 int32 IndexedDBDispatcherHost::Add(IndexedDBCursor* cursor) { | 114 int32 IndexedDBDispatcherHost::Add(IndexedDBCursor* cursor) { |
| 111 if (!cursor_dispatcher_host_) { | 115 if (!cursor_dispatcher_host_) { |
| 112 return 0; | 116 return 0; |
| 113 } | 117 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 int64 host_transaction_id) { | 164 int64 host_transaction_id) { |
| 161 return host_transaction_id & 0xffffffff; | 165 return host_transaction_id & 0xffffffff; |
| 162 } | 166 } |
| 163 | 167 |
| 164 // static | 168 // static |
| 165 uint32 IndexedDBDispatcherHost::TransactionIdToProcessId( | 169 uint32 IndexedDBDispatcherHost::TransactionIdToProcessId( |
| 166 int64 host_transaction_id) { | 170 int64 host_transaction_id) { |
| 167 return (host_transaction_id >> 32) & 0xffffffff; | 171 return (host_transaction_id >> 32) & 0xffffffff; |
| 168 } | 172 } |
| 169 | 173 |
| 174 void IndexedDBDispatcherHost::HoldBlobDataHandle( |
| 175 const std::string& uuid, |
| 176 scoped_ptr<webkit_blob::BlobDataHandle>& blob_data_handle) { |
| 177 DCHECK(ContainsKey(blob_data_handle_map_, uuid)); |
| 178 blob_data_handle_map_[uuid] = blob_data_handle.release(); |
| 179 } |
| 180 |
| 181 void IndexedDBDispatcherHost::DropBlobDataHandle(const std::string& uuid) { |
| 182 BlobDataHandleMap::iterator iter = blob_data_handle_map_.find(uuid); |
| 183 if (iter != blob_data_handle_map_.end()) { |
| 184 delete iter->second; |
| 185 blob_data_handle_map_.erase(iter); |
| 186 } else { |
| 187 DLOG(FATAL) << "Failed to find blob UUID in map:" << uuid; |
| 188 } |
| 189 } |
| 170 | 190 |
| 171 IndexedDBCursor* IndexedDBDispatcherHost::GetCursorFromId(int32 ipc_cursor_id) { | 191 IndexedDBCursor* IndexedDBDispatcherHost::GetCursorFromId(int32 ipc_cursor_id) { |
| 172 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 192 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 173 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id); | 193 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id); |
| 174 } | 194 } |
| 175 | 195 |
| 176 ::IndexedDBDatabaseMetadata IndexedDBDispatcherHost::ConvertMetadata( | 196 ::IndexedDBDatabaseMetadata IndexedDBDispatcherHost::ConvertMetadata( |
| 177 const content::IndexedDBDatabaseMetadata& web_metadata) { | 197 const content::IndexedDBDatabaseMetadata& web_metadata) { |
| 178 ::IndexedDBDatabaseMetadata metadata; | 198 ::IndexedDBDatabaseMetadata metadata; |
| 179 metadata.id = web_metadata.id; | 199 metadata.id = web_metadata.id; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 webkit_database::GetOriginFromIdentifier(params.database_identifier); | 288 webkit_database::GetOriginFromIdentifier(params.database_identifier); |
| 269 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 289 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 270 Context()->GetIDBFactory()->DeleteDatabase( | 290 Context()->GetIDBFactory()->DeleteDatabase( |
| 271 params.name, | 291 params.name, |
| 272 new IndexedDBCallbacks( | 292 new IndexedDBCallbacks( |
| 273 this, params.ipc_thread_id, params.ipc_callbacks_id), | 293 this, params.ipc_thread_id, params.ipc_callbacks_id), |
| 274 origin_url, | 294 origin_url, |
| 275 indexed_db_path); | 295 indexed_db_path); |
| 276 } | 296 } |
| 277 | 297 |
| 298 void IndexedDBDispatcherHost::OnAckReceivedBlobs( |
| 299 const std::vector<std::string>& uuids) { |
| 300 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 301 std::vector<std::string>::const_iterator iter; |
| 302 for (iter = uuids.begin(); iter != uuids.end(); ++iter) |
| 303 DropBlobDataHandle(*iter); |
| 304 } |
| 305 |
| 278 void IndexedDBDispatcherHost::FinishTransaction(int64 host_transaction_id, | 306 void IndexedDBDispatcherHost::FinishTransaction(int64 host_transaction_id, |
| 279 bool committed) { | 307 bool committed) { |
| 280 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 308 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 281 if (!database_dispatcher_host_) | 309 if (!database_dispatcher_host_) |
| 282 return; | 310 return; |
| 283 TransactionIDToURLMap& transaction_url_map = | 311 TransactionIDToURLMap& transaction_url_map = |
| 284 database_dispatcher_host_->transaction_url_map_; | 312 database_dispatcher_host_->transaction_url_map_; |
| 285 TransactionIDToSizeMap& transaction_size_map = | 313 TransactionIDToSizeMap& transaction_size_map = |
| 286 database_dispatcher_host_->transaction_size_map_; | 314 database_dispatcher_host_->transaction_size_map_; |
| 287 TransactionIDToDatabaseIDMap& transaction_database_map = | 315 TransactionIDToDatabaseIDMap& transaction_database_map = |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 } | 873 } |
| 846 | 874 |
| 847 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( | 875 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( |
| 848 int32 ipc_object_id) { | 876 int32 ipc_object_id) { |
| 849 DCHECK( | 877 DCHECK( |
| 850 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 878 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 851 parent_->DestroyObject(&map_, ipc_object_id); | 879 parent_->DestroyObject(&map_, ipc_object_id); |
| 852 } | 880 } |
| 853 | 881 |
| 854 } // namespace content | 882 } // namespace content |
| OLD | NEW |