| 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/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 request_context_(request_context), | 62 request_context_(request_context), |
| 63 indexed_db_context_(indexed_db_context), | 63 indexed_db_context_(indexed_db_context), |
| 64 blob_storage_context_(blob_storage_context), | 64 blob_storage_context_(blob_storage_context), |
| 65 database_dispatcher_host_(new DatabaseDispatcherHost(this)), | 65 database_dispatcher_host_(new DatabaseDispatcherHost(this)), |
| 66 cursor_dispatcher_host_(new CursorDispatcherHost(this)), | 66 cursor_dispatcher_host_(new CursorDispatcherHost(this)), |
| 67 ipc_process_id_(ipc_process_id) { | 67 ipc_process_id_(ipc_process_id) { |
| 68 DCHECK(indexed_db_context_.get()); | 68 DCHECK(indexed_db_context_.get()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() { | 71 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() { |
| 72 STLDeleteValues(&blob_data_handle_map_); | 72 for (auto& iter : blob_data_handle_map_) |
| 73 delete iter.second.first; |
| 73 } | 74 } |
| 74 | 75 |
| 75 void IndexedDBDispatcherHost::OnChannelConnected(int32 peer_pid) { | 76 void IndexedDBDispatcherHost::OnChannelConnected(int32 peer_pid) { |
| 76 BrowserMessageFilter::OnChannelConnected(peer_pid); | 77 BrowserMessageFilter::OnChannelConnected(peer_pid); |
| 77 | 78 |
| 78 if (request_context_getter_.get()) { | 79 if (request_context_getter_.get()) { |
| 79 DCHECK(!request_context_); | 80 DCHECK(!request_context_); |
| 80 request_context_ = request_context_getter_->GetURLRequestContext(); | 81 request_context_ = request_context_getter_->GetURLRequestContext(); |
| 81 request_context_getter_ = NULL; | 82 request_context_getter_ = NULL; |
| 82 DCHECK(request_context_); | 83 DCHECK(request_context_); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 int64 host_transaction_id) { | 203 int64 host_transaction_id) { |
| 203 return host_transaction_id & 0xffffffff; | 204 return host_transaction_id & 0xffffffff; |
| 204 } | 205 } |
| 205 | 206 |
| 206 // static | 207 // static |
| 207 uint32 IndexedDBDispatcherHost::TransactionIdToProcessId( | 208 uint32 IndexedDBDispatcherHost::TransactionIdToProcessId( |
| 208 int64 host_transaction_id) { | 209 int64 host_transaction_id) { |
| 209 return (host_transaction_id >> 32) & 0xffffffff; | 210 return (host_transaction_id >> 32) & 0xffffffff; |
| 210 } | 211 } |
| 211 | 212 |
| 213 bool IndexedDBDispatcherHost::IncrementBlobDataIfHeld(const std::string& uuid) { |
| 214 base::AutoLock lock(blob_data_map_lock_); |
| 215 BlobDataHandleMap::iterator iter = blob_data_handle_map_.find(uuid); |
| 216 if (iter != blob_data_handle_map_.end()) { |
| 217 iter->second.second += 1; |
| 218 return true; |
| 219 } |
| 220 return false; |
| 221 } |
| 222 |
| 212 void IndexedDBDispatcherHost::HoldBlobDataHandle( | 223 void IndexedDBDispatcherHost::HoldBlobDataHandle( |
| 213 const std::string& uuid, | 224 const std::string& uuid, |
| 214 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { | 225 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { |
| 226 base::AutoLock lock(blob_data_map_lock_); |
| 215 DCHECK(!ContainsKey(blob_data_handle_map_, uuid)); | 227 DCHECK(!ContainsKey(blob_data_handle_map_, uuid)); |
| 216 blob_data_handle_map_[uuid] = blob_data_handle.release(); | 228 blob_data_handle_map_[uuid] = |
| 229 std::pair<storage::BlobDataHandle*, int>(blob_data_handle.release(), 1); |
| 217 } | 230 } |
| 218 | 231 |
| 219 void IndexedDBDispatcherHost::DropBlobDataHandle(const std::string& uuid) { | 232 void IndexedDBDispatcherHost::DropBlobDataHandle(const std::string& uuid) { |
| 233 base::AutoLock lock(blob_data_map_lock_); |
| 220 BlobDataHandleMap::iterator iter = blob_data_handle_map_.find(uuid); | 234 BlobDataHandleMap::iterator iter = blob_data_handle_map_.find(uuid); |
| 221 if (iter != blob_data_handle_map_.end()) { | 235 if (iter != blob_data_handle_map_.end()) { |
| 222 delete iter->second; | 236 DCHECK_GE(iter->second.second, 1); |
| 223 blob_data_handle_map_.erase(iter); | 237 if (iter->second.second == 1) { |
| 238 delete iter->second.first; |
| 239 blob_data_handle_map_.erase(iter); |
| 240 } else { |
| 241 iter->second.second -= 1; |
| 242 } |
| 224 } else { | 243 } else { |
| 225 DLOG(FATAL) << "Failed to find blob UUID in map:" << uuid; | 244 DLOG(FATAL) << "Failed to find blob UUID in map:" << uuid; |
| 226 } | 245 } |
| 227 } | 246 } |
| 228 | 247 |
| 229 IndexedDBCursor* IndexedDBDispatcherHost::GetCursorFromId(int32 ipc_cursor_id) { | 248 IndexedDBCursor* IndexedDBDispatcherHost::GetCursorFromId(int32 ipc_cursor_id) { |
| 230 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 249 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 231 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id); | 250 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id); |
| 232 } | 251 } |
| 233 | 252 |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 } | 1005 } |
| 987 | 1006 |
| 988 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( | 1007 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( |
| 989 int32 ipc_object_id) { | 1008 int32 ipc_object_id) { |
| 990 DCHECK( | 1009 DCHECK( |
| 991 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 1010 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 992 parent_->DestroyObject(&map_, ipc_object_id); | 1011 parent_->DestroyObject(&map_, ipc_object_id); |
| 993 } | 1012 } |
| 994 | 1013 |
| 995 } // namespace content | 1014 } // namespace content |
| OLD | NEW |