| 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_observation.h" | |
| 23 #include "content/browser/indexed_db/indexed_db_observer_changes.h" | |
| 24 #include "content/browser/indexed_db/indexed_db_pending_connection.h" | 22 #include "content/browser/indexed_db/indexed_db_pending_connection.h" |
| 25 #include "content/browser/indexed_db/indexed_db_value.h" | 23 #include "content/browser/indexed_db/indexed_db_value.h" |
| 26 #include "content/browser/renderer_host/render_message_filter.h" | 24 #include "content/browser/renderer_host/render_message_filter.h" |
| 27 #include "content/common/indexed_db/indexed_db_messages.h" | 25 #include "content/common/indexed_db/indexed_db_messages.h" |
| 28 #include "content/common/indexed_db/indexed_db_metadata.h" | 26 #include "content/common/indexed_db/indexed_db_metadata.h" |
| 29 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/user_metrics.h" | 28 #include "content/public/browser/user_metrics.h" |
| 31 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
| 32 #include "content/public/common/result_codes.h" | 30 #include "content/public/common/result_codes.h" |
| 33 #include "storage/browser/blob/blob_data_builder.h" | 31 #include "storage/browser/blob/blob_data_builder.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 blob_data_handle_map_.erase(iter); | 198 blob_data_handle_map_.erase(iter); |
| 201 else | 199 else |
| 202 --iter->second.second; | 200 --iter->second.second; |
| 203 } | 201 } |
| 204 | 202 |
| 205 bool IndexedDBDispatcherHost::IsOpen() const { | 203 bool IndexedDBDispatcherHost::IsOpen() const { |
| 206 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 204 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 207 return is_open_; | 205 return is_open_; |
| 208 } | 206 } |
| 209 | 207 |
| 210 IndexedDBMsg_ObserverChanges IndexedDBDispatcherHost::ConvertObserverChanges( | |
| 211 std::unique_ptr<IndexedDBObserverChanges> changes) { | |
| 212 IndexedDBMsg_ObserverChanges idb_changes; | |
| 213 idb_changes.observation_index = changes->release_observation_indices_map(); | |
| 214 for (const auto& observation : changes->release_observations()) | |
| 215 idb_changes.observations.push_back(ConvertObservation(observation.get())); | |
| 216 return idb_changes; | |
| 217 } | |
| 218 | |
| 219 IndexedDBMsg_Observation IndexedDBDispatcherHost::ConvertObservation( | |
| 220 const IndexedDBObservation* observation) { | |
| 221 // TODO(palakj): Modify function for indexed_db_value. Issue crbug.com/609934. | |
| 222 IndexedDBMsg_Observation idb_observation; | |
| 223 idb_observation.object_store_id = observation->object_store_id(); | |
| 224 idb_observation.type = observation->type(); | |
| 225 idb_observation.key_range = observation->key_range(); | |
| 226 return idb_observation; | |
| 227 } | |
| 228 | |
| 229 void IndexedDBDispatcherHost::GetDatabaseNames( | 208 void IndexedDBDispatcherHost::GetDatabaseNames( |
| 230 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, | 209 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, |
| 231 const url::Origin& origin) { | 210 const url::Origin& origin) { |
| 232 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 211 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 233 | 212 |
| 234 if (!IsValidOrigin(origin)) { | 213 if (!IsValidOrigin(origin)) { |
| 235 mojo::ReportBadMessage(kInvalidOrigin); | 214 mojo::ReportBadMessage(kInvalidOrigin); |
| 236 return; | 215 return; |
| 237 } | 216 } |
| 238 | 217 |
| 239 scoped_refptr<IndexedDBCallbacks> callbacks( | 218 scoped_refptr<IndexedDBCallbacks> callbacks( |
| 240 new IndexedDBCallbacks(this, origin, std::move(callbacks_info))); | 219 new IndexedDBCallbacks(this, origin, std::move(callbacks_info))); |
| 241 indexed_db_context_->TaskRunner()->PostTask( | 220 indexed_db_context_->TaskRunner()->PostTask( |
| 242 FROM_HERE, | 221 FROM_HERE, |
| 243 base::Bind(&IndexedDBDispatcherHost::GetDatabaseNamesOnIDBThread, this, | 222 base::Bind(&IndexedDBDispatcherHost::GetDatabaseNamesOnIDBThread, this, |
| 244 base::Passed(&callbacks), origin)); | 223 base::Passed(&callbacks), origin)); |
| 245 } | 224 } |
| 246 | 225 |
| 247 void IndexedDBDispatcherHost::Open( | 226 void IndexedDBDispatcherHost::Open( |
| 248 int32_t worker_thread, | |
| 249 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, | 227 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, |
| 250 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo | 228 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo |
| 251 database_callbacks_info, | 229 database_callbacks_info, |
| 252 const url::Origin& origin, | 230 const url::Origin& origin, |
| 253 const base::string16& name, | 231 const base::string16& name, |
| 254 int64_t version, | 232 int64_t version, |
| 255 int64_t transaction_id) { | 233 int64_t transaction_id) { |
| 256 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 234 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 257 | 235 |
| 258 if (!IsValidOrigin(origin)) { | 236 if (!IsValidOrigin(origin)) { |
| 259 mojo::ReportBadMessage(kInvalidOrigin); | 237 mojo::ReportBadMessage(kInvalidOrigin); |
| 260 return; | 238 return; |
| 261 } | 239 } |
| 262 | 240 |
| 263 scoped_refptr<IndexedDBCallbacks> callbacks( | 241 scoped_refptr<IndexedDBCallbacks> callbacks( |
| 264 new IndexedDBCallbacks(this, origin, std::move(callbacks_info))); | 242 new IndexedDBCallbacks(this, origin, std::move(callbacks_info))); |
| 265 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks( | 243 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks( |
| 266 new IndexedDBDatabaseCallbacks(this, worker_thread, | 244 new IndexedDBDatabaseCallbacks(this, std::move(database_callbacks_info))); |
| 267 std::move(database_callbacks_info))); | |
| 268 indexed_db_context_->TaskRunner()->PostTask( | 245 indexed_db_context_->TaskRunner()->PostTask( |
| 269 FROM_HERE, | 246 FROM_HERE, |
| 270 base::Bind(&IndexedDBDispatcherHost::OpenOnIDBThread, this, | 247 base::Bind(&IndexedDBDispatcherHost::OpenOnIDBThread, this, |
| 271 base::Passed(&callbacks), base::Passed(&database_callbacks), | 248 base::Passed(&callbacks), base::Passed(&database_callbacks), |
| 272 origin, name, version, transaction_id)); | 249 origin, name, version, transaction_id)); |
| 273 } | 250 } |
| 274 | 251 |
| 275 void IndexedDBDispatcherHost::DeleteDatabase( | 252 void IndexedDBDispatcherHost::DeleteDatabase( |
| 276 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, | 253 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, |
| 277 const url::Origin& origin, | 254 const url::Origin& origin, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 322 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 346 if (committed) { | 323 if (committed) { |
| 347 context()->TransactionComplete( | 324 context()->TransactionComplete( |
| 348 transaction_origin_map_[host_transaction_id]); | 325 transaction_origin_map_[host_transaction_id]); |
| 349 } | 326 } |
| 350 transaction_origin_map_.erase(host_transaction_id); | 327 transaction_origin_map_.erase(host_transaction_id); |
| 351 transaction_size_map_.erase(host_transaction_id); | 328 transaction_size_map_.erase(host_transaction_id); |
| 352 } | 329 } |
| 353 | 330 |
| 354 } // namespace content | 331 } // namespace content |
| OLD | NEW |