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/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
15 #include "base/process/process.h" | 15 #include "base/process/process.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "content/browser/bad_message.h" | 18 #include "content/browser/bad_message.h" |
19 #include "content/browser/child_process_security_policy_impl.h" | 19 #include "content/browser/child_process_security_policy_impl.h" |
20 #include "content/browser/indexed_db/indexed_db_callbacks.h" | 20 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
21 #include "content/browser/indexed_db/indexed_db_connection.h" | 21 #include "content/browser/indexed_db/indexed_db_connection.h" |
22 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 22 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
23 #include "content/browser/indexed_db/indexed_db_cursor.h" | 23 #include "content/browser/indexed_db/indexed_db_cursor.h" |
24 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 24 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
25 #include "content/browser/indexed_db/indexed_db_metadata.h" | 25 #include "content/browser/indexed_db/indexed_db_metadata.h" |
26 #include "content/browser/indexed_db/indexed_db_observation.h" | 26 #include "content/browser/indexed_db/indexed_db_observation.h" |
27 #include "content/browser/indexed_db/indexed_db_observation.h" | |
28 #include "content/browser/indexed_db/indexed_db_observer_changes.h" | 27 #include "content/browser/indexed_db/indexed_db_observer_changes.h" |
29 #include "content/browser/indexed_db/indexed_db_pending_connection.h" | 28 #include "content/browser/indexed_db/indexed_db_pending_connection.h" |
30 #include "content/browser/indexed_db/indexed_db_value.h" | 29 #include "content/browser/indexed_db/indexed_db_value.h" |
31 #include "content/browser/renderer_host/render_message_filter.h" | 30 #include "content/browser/renderer_host/render_message_filter.h" |
32 #include "content/common/indexed_db/indexed_db_messages.h" | 31 #include "content/common/indexed_db/indexed_db_messages.h" |
33 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
34 #include "content/public/browser/user_metrics.h" | 33 #include "content/public/browser/user_metrics.h" |
35 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
36 #include "content/public/common/result_codes.h" | 35 #include "content/public/common/result_codes.h" |
37 #include "storage/browser/blob/blob_data_builder.h" | 36 #include "storage/browser/blob/blob_data_builder.h" |
(...skipping 17 matching lines...) Expand all Loading... |
55 | 54 |
56 } // namespace | 55 } // namespace |
57 | 56 |
58 IndexedDBDispatcherHost::IndexedDBDispatcherHost( | 57 IndexedDBDispatcherHost::IndexedDBDispatcherHost( |
59 int ipc_process_id, | 58 int ipc_process_id, |
60 net::URLRequestContextGetter* request_context_getter, | 59 net::URLRequestContextGetter* request_context_getter, |
61 IndexedDBContextImpl* indexed_db_context, | 60 IndexedDBContextImpl* indexed_db_context, |
62 ChromeBlobStorageContext* blob_storage_context) | 61 ChromeBlobStorageContext* blob_storage_context) |
63 : BrowserMessageFilter(IndexedDBMsgStart), | 62 : BrowserMessageFilter(IndexedDBMsgStart), |
64 request_context_getter_(request_context_getter), | 63 request_context_getter_(request_context_getter), |
65 request_context_(NULL), | |
66 indexed_db_context_(indexed_db_context), | 64 indexed_db_context_(indexed_db_context), |
67 blob_storage_context_(blob_storage_context), | 65 blob_storage_context_(blob_storage_context), |
68 database_dispatcher_host_(base::MakeUnique<DatabaseDispatcherHost>(this)), | 66 database_dispatcher_host_(base::MakeUnique<DatabaseDispatcherHost>(this)), |
69 cursor_dispatcher_host_(base::MakeUnique<CursorDispatcherHost>(this)), | |
70 ipc_process_id_(ipc_process_id) { | |
71 DCHECK(indexed_db_context_.get()); | |
72 } | |
73 | |
74 IndexedDBDispatcherHost::IndexedDBDispatcherHost( | |
75 int ipc_process_id, | |
76 net::URLRequestContext* request_context, | |
77 IndexedDBContextImpl* indexed_db_context, | |
78 ChromeBlobStorageContext* blob_storage_context) | |
79 : BrowserMessageFilter(IndexedDBMsgStart), | |
80 request_context_(request_context), | |
81 indexed_db_context_(indexed_db_context), | |
82 blob_storage_context_(blob_storage_context), | |
83 database_dispatcher_host_(base::MakeUnique<DatabaseDispatcherHost>(this)), | |
84 cursor_dispatcher_host_(base::MakeUnique<CursorDispatcherHost>(this)), | 67 cursor_dispatcher_host_(base::MakeUnique<CursorDispatcherHost>(this)), |
85 ipc_process_id_(ipc_process_id) { | 68 ipc_process_id_(ipc_process_id) { |
86 DCHECK(indexed_db_context_.get()); | 69 DCHECK(indexed_db_context_.get()); |
87 } | 70 } |
88 | 71 |
89 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() {} | 72 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() {} |
90 | 73 |
91 void IndexedDBDispatcherHost::OnChannelConnected(int32_t peer_pid) { | |
92 BrowserMessageFilter::OnChannelConnected(peer_pid); | |
93 | |
94 if (request_context_getter_.get()) { | |
95 DCHECK(!request_context_); | |
96 request_context_ = request_context_getter_->GetURLRequestContext(); | |
97 request_context_getter_ = NULL; | |
98 DCHECK(request_context_); | |
99 } | |
100 } | |
101 | |
102 void IndexedDBDispatcherHost::OnChannelClosing() { | 74 void IndexedDBDispatcherHost::OnChannelClosing() { |
103 bool success = indexed_db_context_->TaskRunner()->PostTask( | 75 bool success = indexed_db_context_->TaskRunner()->PostTask( |
104 FROM_HERE, | 76 FROM_HERE, |
105 base::Bind(&IndexedDBDispatcherHost::ResetDispatcherHosts, this)); | 77 base::Bind(&IndexedDBDispatcherHost::ResetDispatcherHosts, this)); |
106 | 78 |
107 if (!success) | 79 if (!success) |
108 ResetDispatcherHosts(); | 80 ResetDispatcherHosts(); |
109 } | 81 } |
110 | 82 |
111 void IndexedDBDispatcherHost::OnDestruct() const { | 83 void IndexedDBDispatcherHost::OnDestruct() const { |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 | 314 |
343 if (!IsValidOrigin(params.origin)) { | 315 if (!IsValidOrigin(params.origin)) { |
344 bad_message::ReceivedBadMessage(this, bad_message::IDBDH_INVALID_ORIGIN); | 316 bad_message::ReceivedBadMessage(this, bad_message::IDBDH_INVALID_ORIGIN); |
345 return; | 317 return; |
346 } | 318 } |
347 | 319 |
348 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 320 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
349 context()->GetIDBFactory()->GetDatabaseNames( | 321 context()->GetIDBFactory()->GetDatabaseNames( |
350 new IndexedDBCallbacks(this, params.ipc_thread_id, | 322 new IndexedDBCallbacks(this, params.ipc_thread_id, |
351 params.ipc_callbacks_id), | 323 params.ipc_callbacks_id), |
352 params.origin, indexed_db_path, request_context_); | 324 params.origin, indexed_db_path, request_context_getter_); |
353 } | 325 } |
354 | 326 |
355 void IndexedDBDispatcherHost::OnIDBFactoryOpen( | 327 void IndexedDBDispatcherHost::OnIDBFactoryOpen( |
356 const IndexedDBHostMsg_FactoryOpen_Params& params) { | 328 const IndexedDBHostMsg_FactoryOpen_Params& params) { |
357 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 329 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
358 | 330 |
359 if (!IsValidOrigin(params.origin)) { | 331 if (!IsValidOrigin(params.origin)) { |
360 bad_message::ReceivedBadMessage(this, bad_message::IDBDH_INVALID_ORIGIN); | 332 bad_message::ReceivedBadMessage(this, bad_message::IDBDH_INVALID_ORIGIN); |
361 return; | 333 return; |
362 } | 334 } |
363 | 335 |
364 base::TimeTicks begin_time = base::TimeTicks::Now(); | 336 base::TimeTicks begin_time = base::TimeTicks::Now(); |
365 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 337 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
366 | 338 |
367 int64_t host_transaction_id = HostTransactionId(params.transaction_id); | 339 int64_t host_transaction_id = HostTransactionId(params.transaction_id); |
368 | 340 |
369 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore | 341 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore |
370 // created) if this origin is already over quota. | 342 // created) if this origin is already over quota. |
371 scoped_refptr<IndexedDBCallbacks> callbacks = new IndexedDBCallbacks( | 343 scoped_refptr<IndexedDBCallbacks> callbacks = new IndexedDBCallbacks( |
372 this, params.ipc_thread_id, params.ipc_callbacks_id, | 344 this, params.ipc_thread_id, params.ipc_callbacks_id, |
373 params.ipc_database_callbacks_id, host_transaction_id, params.origin); | 345 params.ipc_database_callbacks_id, host_transaction_id, params.origin); |
374 callbacks->SetConnectionOpenStartTime(begin_time); | 346 callbacks->SetConnectionOpenStartTime(begin_time); |
375 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks = | 347 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks = |
376 new IndexedDBDatabaseCallbacks( | 348 new IndexedDBDatabaseCallbacks( |
377 this, params.ipc_thread_id, params.ipc_database_callbacks_id); | 349 this, params.ipc_thread_id, params.ipc_database_callbacks_id); |
378 std::unique_ptr<IndexedDBPendingConnection> connection = | 350 std::unique_ptr<IndexedDBPendingConnection> connection = |
379 base::MakeUnique<IndexedDBPendingConnection>( | 351 base::MakeUnique<IndexedDBPendingConnection>( |
380 callbacks, database_callbacks, ipc_process_id_, host_transaction_id, | 352 callbacks, database_callbacks, ipc_process_id_, host_transaction_id, |
381 params.version); | 353 params.version); |
382 DCHECK(request_context_); | 354 DCHECK(request_context_getter_); |
383 context()->GetIDBFactory()->Open(params.name, std::move(connection), | 355 context()->GetIDBFactory()->Open(params.name, std::move(connection), |
384 request_context_, params.origin, | 356 request_context_getter_, params.origin, |
385 indexed_db_path); | 357 indexed_db_path); |
386 } | 358 } |
387 | 359 |
388 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( | 360 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( |
389 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) { | 361 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) { |
390 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 362 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
391 | 363 |
392 if (!IsValidOrigin(params.origin)) { | 364 if (!IsValidOrigin(params.origin)) { |
393 bad_message::ReceivedBadMessage(this, bad_message::IDBDH_INVALID_ORIGIN); | 365 bad_message::ReceivedBadMessage(this, bad_message::IDBDH_INVALID_ORIGIN); |
394 return; | 366 return; |
395 } | 367 } |
396 | 368 |
397 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 369 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
398 DCHECK(request_context_); | 370 DCHECK(request_context_getter_); |
399 context()->GetIDBFactory()->DeleteDatabase( | 371 context()->GetIDBFactory()->DeleteDatabase( |
400 params.name, request_context_, | 372 params.name, request_context_getter_, |
401 new IndexedDBCallbacks(this, params.ipc_thread_id, | 373 new IndexedDBCallbacks(this, params.ipc_thread_id, |
402 params.ipc_callbacks_id), | 374 params.ipc_callbacks_id), |
403 params.origin, indexed_db_path); | 375 params.origin, indexed_db_path); |
404 } | 376 } |
405 | 377 |
406 // OnPutHelper exists only to allow us to hop threads while holding a reference | 378 // OnPutHelper exists only to allow us to hop threads while holding a reference |
407 // to the IndexedDBDispatcherHost. | 379 // to the IndexedDBDispatcherHost. |
408 void IndexedDBDispatcherHost::OnPutHelper( | 380 void IndexedDBDispatcherHost::OnPutHelper( |
409 const IndexedDBHostMsg_DatabasePut_Params& params, | 381 const IndexedDBHostMsg_DatabasePut_Params& params, |
410 std::vector<storage::BlobDataHandle*> handles) { | 382 std::vector<storage::BlobDataHandle*> handles) { |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 DLOG(ERROR) << "Unable to reset prefetch"; | 1058 DLOG(ERROR) << "Unable to reset prefetch"; |
1087 } | 1059 } |
1088 | 1060 |
1089 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( | 1061 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( |
1090 int32_t ipc_object_id) { | 1062 int32_t ipc_object_id) { |
1091 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 1063 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
1092 parent_->DestroyObject(&map_, ipc_object_id); | 1064 parent_->DestroyObject(&map_, ipc_object_id); |
1093 } | 1065 } |
1094 | 1066 |
1095 } // namespace content | 1067 } // namespace content |
OLD | NEW |