Chromium Code Reviews| 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/indexed_db/indexed_db_callbacks.h" | 18 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
| 19 #include "content/browser/indexed_db/indexed_db_connection.h" | 19 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 20 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 20 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 21 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 21 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
| 22 #include "content/browser/indexed_db/indexed_db_pending_connection.h" | 22 #include "content/browser/indexed_db/indexed_db_pending_connection.h" |
| 23 #include "content/browser/indexed_db/indexed_db_transaction.h" | |
| 23 #include "content/browser/indexed_db/indexed_db_value.h" | 24 #include "content/browser/indexed_db/indexed_db_value.h" |
| 24 #include "content/browser/renderer_host/render_message_filter.h" | 25 #include "content/browser/renderer_host/render_message_filter.h" |
| 25 #include "content/common/indexed_db/indexed_db_messages.h" | 26 #include "content/common/indexed_db/indexed_db_messages.h" |
| 26 #include "content/common/indexed_db/indexed_db_metadata.h" | 27 #include "content/common/indexed_db/indexed_db_metadata.h" |
| 27 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/browser/user_metrics.h" | 29 #include "content/public/browser/user_metrics.h" |
| 29 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
| 30 #include "content/public/common/result_codes.h" | 31 #include "content/public/common/result_codes.h" |
| 31 #include "storage/browser/blob/blob_data_builder.h" | 32 #include "storage/browser/blob/blob_data_builder.h" |
| 32 #include "storage/browser/blob/blob_storage_context.h" | 33 #include "storage/browser/blob/blob_storage_context.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 97 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 97 | 98 |
| 98 // Prevent any pending connections from being processed. | 99 // Prevent any pending connections from being processed. |
| 99 is_open_ = false; | 100 is_open_ = false; |
| 100 } | 101 } |
| 101 | 102 |
| 102 bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message) { | 103 bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message) { |
| 103 return false; | 104 return false; |
| 104 } | 105 } |
| 105 | 106 |
| 106 bool IndexedDBDispatcherHost::RegisterTransactionId(int64_t host_transaction_id, | |
| 107 const url::Origin& origin) { | |
| 108 if (base::ContainsKey(transaction_size_map_, host_transaction_id)) | |
| 109 return false; | |
| 110 transaction_size_map_[host_transaction_id] = 0; | |
| 111 transaction_origin_map_[host_transaction_id] = origin; | |
| 112 return true; | |
| 113 } | |
| 114 | |
| 115 bool IndexedDBDispatcherHost::GetTransactionSize(int64_t host_transaction_id, | |
| 116 int64_t* transaction_size) { | |
| 117 const auto it = transaction_size_map_.find(host_transaction_id); | |
| 118 if (it == transaction_size_map_.end()) | |
| 119 return false; | |
| 120 *transaction_size = it->second; | |
| 121 return true; | |
| 122 } | |
| 123 | |
| 124 void IndexedDBDispatcherHost::AddToTransaction(int64_t host_transaction_id, | |
| 125 int64_t value_length) { | |
| 126 transaction_size_map_[host_transaction_id] += value_length; | |
| 127 } | |
| 128 | |
| 129 int64_t IndexedDBDispatcherHost::HostTransactionId(int64_t transaction_id) { | |
| 130 // Inject the renderer process id into the transaction id, to | |
| 131 // uniquely identify this transaction, and effectively bind it to | |
| 132 // the renderer that initiated it. The lower 32 bits of | |
| 133 // transaction_id are guaranteed to be unique within that renderer. | |
| 134 base::ProcessId pid = peer_pid(); | |
| 135 DCHECK(!(transaction_id >> 32)) << "Transaction ids can only be 32 bits"; | |
| 136 static_assert(sizeof(base::ProcessId) <= sizeof(int32_t), | |
| 137 "Process ID must fit in 32 bits"); | |
| 138 | |
| 139 return transaction_id | (static_cast<uint64_t>(pid) << 32); | |
| 140 } | |
| 141 | |
| 142 int64_t IndexedDBDispatcherHost::RendererTransactionId( | |
| 143 int64_t host_transaction_id) { | |
| 144 DCHECK(host_transaction_id >> 32 == peer_pid()) | |
| 145 << "Invalid renderer target for transaction id"; | |
| 146 return host_transaction_id & 0xffffffff; | |
| 147 } | |
| 148 | |
| 149 // static | |
| 150 uint32_t IndexedDBDispatcherHost::TransactionIdToRendererTransactionId( | |
| 151 int64_t host_transaction_id) { | |
| 152 return host_transaction_id & 0xffffffff; | |
| 153 } | |
| 154 | |
| 155 // static | |
| 156 uint32_t IndexedDBDispatcherHost::TransactionIdToProcessId( | |
| 157 int64_t host_transaction_id) { | |
| 158 return (host_transaction_id >> 32) & 0xffffffff; | |
| 159 } | |
| 160 | |
| 161 std::string IndexedDBDispatcherHost::HoldBlobData( | 107 std::string IndexedDBDispatcherHost::HoldBlobData( |
| 162 const IndexedDBBlobInfo& blob_info) { | 108 const IndexedDBBlobInfo& blob_info) { |
| 163 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 109 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 164 std::string uuid = blob_info.uuid(); | 110 std::string uuid = blob_info.uuid(); |
| 165 storage::BlobStorageContext* context = blob_storage_context_->context(); | 111 storage::BlobStorageContext* context = blob_storage_context_->context(); |
| 166 std::unique_ptr<storage::BlobDataHandle> blob_data_handle; | 112 std::unique_ptr<storage::BlobDataHandle> blob_data_handle; |
| 167 if (uuid.empty()) { | 113 if (uuid.empty()) { |
| 168 uuid = base::GenerateGUID(); | 114 uuid = base::GenerateGUID(); |
| 169 storage::BlobDataBuilder blob_data_builder(uuid); | 115 storage::BlobDataBuilder blob_data_builder(uuid); |
| 170 blob_data_builder.set_content_type(base::UTF16ToUTF8(blob_info.type())); | 116 blob_data_builder.set_content_type(base::UTF16ToUTF8(blob_info.type())); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 228 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
| 283 const url::Origin& origin, | 229 const url::Origin& origin, |
| 284 const base::string16& name, | 230 const base::string16& name, |
| 285 int64_t version, | 231 int64_t version, |
| 286 int64_t transaction_id) { | 232 int64_t transaction_id) { |
| 287 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 233 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 288 | 234 |
| 289 base::TimeTicks begin_time = base::TimeTicks::Now(); | 235 base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 290 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 236 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 291 | 237 |
| 292 int64_t host_transaction_id = HostTransactionId(transaction_id); | |
| 293 | |
| 294 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore | 238 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore |
| 295 // created) if this origin is already over quota. | 239 // created) if this origin is already over quota. |
| 296 callbacks->SetConnectionOpenStartTime(begin_time); | 240 callbacks->SetConnectionOpenStartTime(begin_time); |
| 297 callbacks->set_host_transaction_id(host_transaction_id); | 241 callbacks->set_host_transaction_id(transaction_id); |
|
Reilly Grant (use Gerrit)
2016/11/30 16:32:26
This isn't necessary anymore now that OnUpgradeNee
dmurph
2016/11/30 23:13:07
Done.
| |
| 298 std::unique_ptr<IndexedDBPendingConnection> connection = | 242 std::unique_ptr<IndexedDBPendingConnection> connection = |
| 299 base::MakeUnique<IndexedDBPendingConnection>( | 243 base::MakeUnique<IndexedDBPendingConnection>( |
| 300 callbacks, database_callbacks, ipc_process_id_, host_transaction_id, | 244 callbacks, database_callbacks, ipc_process_id_, transaction_id, |
| 301 version); | 245 version); |
| 302 DCHECK(request_context_getter_); | 246 DCHECK(request_context_getter_); |
| 303 context()->GetIDBFactory()->Open(name, std::move(connection), | 247 context()->GetIDBFactory()->Open(name, std::move(connection), |
| 304 request_context_getter_, origin, | 248 request_context_getter_, origin, |
| 305 indexed_db_path); | 249 indexed_db_path); |
| 306 } | 250 } |
| 307 | 251 |
| 308 void IndexedDBDispatcherHost::DeleteDatabaseOnIDBThread( | 252 void IndexedDBDispatcherHost::DeleteDatabaseOnIDBThread( |
| 309 scoped_refptr<IndexedDBCallbacks> callbacks, | 253 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 310 const url::Origin& origin, | 254 const url::Origin& origin, |
| 311 const base::string16& name) { | 255 const base::string16& name) { |
| 312 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 256 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 313 | 257 |
| 314 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 258 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 315 DCHECK(request_context_getter_); | 259 DCHECK(request_context_getter_); |
| 316 context()->GetIDBFactory()->DeleteDatabase( | 260 context()->GetIDBFactory()->DeleteDatabase( |
| 317 name, request_context_getter_, callbacks, origin, indexed_db_path); | 261 name, request_context_getter_, callbacks, origin, indexed_db_path); |
| 318 } | 262 } |
| 319 | 263 |
| 320 void IndexedDBDispatcherHost::FinishTransaction(int64_t host_transaction_id, | 264 void IndexedDBDispatcherHost::NotifyTransactionCommitted( |
| 321 bool committed) { | 265 const url::Origin& transaction_origin) { |
| 322 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 266 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 323 if (committed) { | 267 context()->TransactionComplete(transaction_origin); |
| 324 context()->TransactionComplete( | |
| 325 transaction_origin_map_[host_transaction_id]); | |
| 326 } | |
| 327 transaction_origin_map_.erase(host_transaction_id); | |
| 328 transaction_size_map_.erase(host_transaction_id); | |
| 329 } | 268 } |
| 330 | 269 |
| 331 } // namespace content | 270 } // namespace content |
| OLD | NEW |