| 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" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 93 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 94 | 94 |
| 95 // Prevent any pending connections from being processed. | 95 // Prevent any pending connections from being processed. |
| 96 is_open_ = false; | 96 is_open_ = false; |
| 97 } | 97 } |
| 98 | 98 |
| 99 bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message) { | 99 bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message) { |
| 100 return false; | 100 return false; |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool IndexedDBDispatcherHost::RegisterTransactionId(int64_t host_transaction_id, | |
| 104 const url::Origin& origin) { | |
| 105 if (base::ContainsKey(transaction_size_map_, host_transaction_id)) | |
| 106 return false; | |
| 107 transaction_size_map_[host_transaction_id] = 0; | |
| 108 transaction_origin_map_[host_transaction_id] = origin; | |
| 109 return true; | |
| 110 } | |
| 111 | |
| 112 bool IndexedDBDispatcherHost::GetTransactionSize(int64_t host_transaction_id, | |
| 113 int64_t* transaction_size) { | |
| 114 const auto it = transaction_size_map_.find(host_transaction_id); | |
| 115 if (it == transaction_size_map_.end()) | |
| 116 return false; | |
| 117 *transaction_size = it->second; | |
| 118 return true; | |
| 119 } | |
| 120 | |
| 121 void IndexedDBDispatcherHost::AddToTransaction(int64_t host_transaction_id, | |
| 122 int64_t value_length) { | |
| 123 transaction_size_map_[host_transaction_id] += value_length; | |
| 124 } | |
| 125 | |
| 126 int64_t IndexedDBDispatcherHost::HostTransactionId(int64_t transaction_id) { | |
| 127 // Inject the renderer process id into the transaction id, to | |
| 128 // uniquely identify this transaction, and effectively bind it to | |
| 129 // the renderer that initiated it. The lower 32 bits of | |
| 130 // transaction_id are guaranteed to be unique within that renderer. | |
| 131 base::ProcessId pid = peer_pid(); | |
| 132 DCHECK(!(transaction_id >> 32)) << "Transaction ids can only be 32 bits"; | |
| 133 static_assert(sizeof(base::ProcessId) <= sizeof(int32_t), | |
| 134 "Process ID must fit in 32 bits"); | |
| 135 | |
| 136 return transaction_id | (static_cast<uint64_t>(pid) << 32); | |
| 137 } | |
| 138 | |
| 139 int64_t IndexedDBDispatcherHost::RendererTransactionId( | |
| 140 int64_t host_transaction_id) { | |
| 141 DCHECK(host_transaction_id >> 32 == peer_pid()) | |
| 142 << "Invalid renderer target for transaction id"; | |
| 143 return host_transaction_id & 0xffffffff; | |
| 144 } | |
| 145 | |
| 146 // static | |
| 147 uint32_t IndexedDBDispatcherHost::TransactionIdToRendererTransactionId( | |
| 148 int64_t host_transaction_id) { | |
| 149 return host_transaction_id & 0xffffffff; | |
| 150 } | |
| 151 | |
| 152 // static | |
| 153 uint32_t IndexedDBDispatcherHost::TransactionIdToProcessId( | |
| 154 int64_t host_transaction_id) { | |
| 155 return (host_transaction_id >> 32) & 0xffffffff; | |
| 156 } | |
| 157 | |
| 158 std::string IndexedDBDispatcherHost::HoldBlobData( | 103 std::string IndexedDBDispatcherHost::HoldBlobData( |
| 159 const IndexedDBBlobInfo& blob_info) { | 104 const IndexedDBBlobInfo& blob_info) { |
| 160 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 105 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 161 std::string uuid = blob_info.uuid(); | 106 std::string uuid = blob_info.uuid(); |
| 162 storage::BlobStorageContext* context = blob_storage_context_->context(); | 107 storage::BlobStorageContext* context = blob_storage_context_->context(); |
| 163 std::unique_ptr<storage::BlobDataHandle> blob_data_handle; | 108 std::unique_ptr<storage::BlobDataHandle> blob_data_handle; |
| 164 if (uuid.empty()) { | 109 if (uuid.empty()) { |
| 165 uuid = base::GenerateGUID(); | 110 uuid = base::GenerateGUID(); |
| 166 storage::BlobDataBuilder blob_data_builder(uuid); | 111 storage::BlobDataBuilder blob_data_builder(uuid); |
| 167 blob_data_builder.set_content_type(base::UTF16ToUTF8(blob_info.type())); | 112 blob_data_builder.set_content_type(base::UTF16ToUTF8(blob_info.type())); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 224 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
| 280 const url::Origin& origin, | 225 const url::Origin& origin, |
| 281 const base::string16& name, | 226 const base::string16& name, |
| 282 int64_t version, | 227 int64_t version, |
| 283 int64_t transaction_id) { | 228 int64_t transaction_id) { |
| 284 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 229 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 285 | 230 |
| 286 base::TimeTicks begin_time = base::TimeTicks::Now(); | 231 base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 287 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 232 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 288 | 233 |
| 289 int64_t host_transaction_id = HostTransactionId(transaction_id); | |
| 290 | |
| 291 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore | 234 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore |
| 292 // created) if this origin is already over quota. | 235 // created) if this origin is already over quota. |
| 293 callbacks->SetConnectionOpenStartTime(begin_time); | 236 callbacks->SetConnectionOpenStartTime(begin_time); |
| 294 callbacks->set_host_transaction_id(host_transaction_id); | |
| 295 std::unique_ptr<IndexedDBPendingConnection> connection = | 237 std::unique_ptr<IndexedDBPendingConnection> connection = |
| 296 base::MakeUnique<IndexedDBPendingConnection>( | 238 base::MakeUnique<IndexedDBPendingConnection>( |
| 297 callbacks, database_callbacks, ipc_process_id_, host_transaction_id, | 239 callbacks, database_callbacks, ipc_process_id_, transaction_id, |
| 298 version); | 240 version); |
| 299 DCHECK(request_context_getter_); | 241 DCHECK(request_context_getter_); |
| 300 context()->GetIDBFactory()->Open(name, std::move(connection), | 242 context()->GetIDBFactory()->Open(name, std::move(connection), |
| 301 request_context_getter_, origin, | 243 request_context_getter_, origin, |
| 302 indexed_db_path); | 244 indexed_db_path); |
| 303 } | 245 } |
| 304 | 246 |
| 305 void IndexedDBDispatcherHost::DeleteDatabaseOnIDBThread( | 247 void IndexedDBDispatcherHost::DeleteDatabaseOnIDBThread( |
| 306 scoped_refptr<IndexedDBCallbacks> callbacks, | 248 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 307 const url::Origin& origin, | 249 const url::Origin& origin, |
| 308 const base::string16& name) { | 250 const base::string16& name) { |
| 309 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 251 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 310 | 252 |
| 311 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 253 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 312 DCHECK(request_context_getter_); | 254 DCHECK(request_context_getter_); |
| 313 context()->GetIDBFactory()->DeleteDatabase( | 255 context()->GetIDBFactory()->DeleteDatabase( |
| 314 name, request_context_getter_, callbacks, origin, indexed_db_path); | 256 name, request_context_getter_, callbacks, origin, indexed_db_path); |
| 315 } | 257 } |
| 316 | 258 |
| 317 void IndexedDBDispatcherHost::FinishTransaction(int64_t host_transaction_id, | |
| 318 bool committed) { | |
| 319 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | |
| 320 if (committed) { | |
| 321 context()->TransactionComplete( | |
| 322 transaction_origin_map_[host_transaction_id]); | |
| 323 } | |
| 324 transaction_origin_map_.erase(host_transaction_id); | |
| 325 transaction_size_map_.erase(host_transaction_id); | |
| 326 } | |
| 327 | |
| 328 } // namespace content | 259 } // namespace content |
| OLD | NEW |