OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/indexed_db/database_factory_impl.h" |
| 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
| 9 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 10 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
| 11 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" |
| 12 #include "content/browser/indexed_db/indexed_db_pending_connection.h" |
| 13 #include "mojo/public/cpp/bindings/message.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 namespace { |
| 18 |
| 19 bool IsValidOrigin(const url::Origin& origin) { |
| 20 return !origin.unique(); |
| 21 } |
| 22 |
| 23 } // namespace |
| 24 |
| 25 class DatabaseFactoryImpl::IDBThreadHelper { |
| 26 public: |
| 27 IDBThreadHelper(IndexedDBContextImpl* indexed_db_context, |
| 28 net::URLRequestContextGetter* request_context_getter, |
| 29 int ipc_process_id, |
| 30 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host); |
| 31 ~IDBThreadHelper(); |
| 32 |
| 33 void Open(const std::string& name, |
| 34 int64_t version, |
| 35 int64_t transaction_id, |
| 36 const url::Origin& origin, |
| 37 ::indexed_db::mojom::DatabaseClientAssociatedPtr client, |
| 38 int64_t thread_id, |
| 39 int64_t callbacks_id); |
| 40 |
| 41 private: |
| 42 IndexedDBContextImpl* indexed_db_context_; |
| 43 net::URLRequestContextGetter* request_context_getter_; |
| 44 int ipc_process_id_; |
| 45 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; |
| 46 }; |
| 47 |
| 48 DatabaseFactoryImpl::DatabaseFactoryImpl( |
| 49 net::URLRequestContextGetter* request_context_getter, |
| 50 IndexedDBContextImpl* indexed_db_context, |
| 51 int ipc_process_id, |
| 52 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) |
| 53 : BrowserAssociatedInterface<::indexed_db::mojom::DatabaseFactory>( |
| 54 dispatcher_host.get(), |
| 55 this), |
| 56 idb_task_runner_(indexed_db_context->TaskRunner()) { |
| 57 idb_thread_helper_ = |
| 58 new IDBThreadHelper(indexed_db_context, request_context_getter, |
| 59 ipc_process_id, dispatcher_host); |
| 60 } |
| 61 |
| 62 DatabaseFactoryImpl::~DatabaseFactoryImpl() { |
| 63 idb_task_runner_->DeleteSoon(FROM_HERE, idb_thread_helper_); |
| 64 } |
| 65 |
| 66 void DatabaseFactoryImpl::Open( |
| 67 const std::string& name, |
| 68 int64_t version, |
| 69 int64_t transaction_id, |
| 70 const url::Origin& origin, |
| 71 ::indexed_db::mojom::DatabaseClientAssociatedPtrInfo clientInfo, |
| 72 int64_t thread_id, |
| 73 int64_t callbacks_id) { |
| 74 if (!IsValidOrigin(origin)) { |
| 75 mojo::ReportBadMessage("Origin is not valid."); |
| 76 return; |
| 77 } |
| 78 |
| 79 ::indexed_db::mojom::DatabaseClientAssociatedPtr client; |
| 80 client.Bind(std::move(clientInfo)); |
| 81 |
| 82 idb_task_runner_->PostTask( |
| 83 FROM_HERE, |
| 84 base::Bind(&IDBThreadHelper::Open, base::Unretained(idb_thread_helper_), |
| 85 name, version, transaction_id, origin, base::Passed(&client), |
| 86 thread_id, callbacks_id)); |
| 87 } |
| 88 |
| 89 DatabaseFactoryImpl::IDBThreadHelper::IDBThreadHelper( |
| 90 IndexedDBContextImpl* indexed_db_context, |
| 91 net::URLRequestContextGetter* request_context_getter, |
| 92 int ipc_process_id, |
| 93 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) |
| 94 : indexed_db_context_(indexed_db_context), |
| 95 request_context_getter_(request_context_getter), |
| 96 ipc_process_id_(ipc_process_id), |
| 97 dispatcher_host_(dispatcher_host) {} |
| 98 |
| 99 DatabaseFactoryImpl::IDBThreadHelper::~IDBThreadHelper() = default; |
| 100 |
| 101 void DatabaseFactoryImpl::IDBThreadHelper::Open( |
| 102 const std::string& name, |
| 103 int64_t version, |
| 104 int64_t transaction_id, |
| 105 const url::Origin& origin, |
| 106 ::indexed_db::mojom::DatabaseClientAssociatedPtr client, |
| 107 int64_t thread_id, |
| 108 int64_t callbacks_id) { |
| 109 base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 110 int64_t host_transaction_id = |
| 111 dispatcher_host_->HostTransactionId(transaction_id); |
| 112 |
| 113 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore |
| 114 // created) if this origin is already over quota. |
| 115 scoped_refptr<IndexedDBCallbacks> callbacks = |
| 116 new IndexedDBCallbacks(dispatcher_host_.get(), thread_id, callbacks_id, |
| 117 host_transaction_id, origin); |
| 118 callbacks->SetConnectionOpenStartTime(begin_time); |
| 119 |
| 120 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks = |
| 121 new IndexedDBDatabaseCallbacks(dispatcher_host_.get(), thread_id, |
| 122 std::move(client)); |
| 123 |
| 124 std::unique_ptr<IndexedDBPendingConnection> connection = |
| 125 base::MakeUnique<IndexedDBPendingConnection>( |
| 126 callbacks, database_callbacks, ipc_process_id_, host_transaction_id, |
| 127 version); |
| 128 |
| 129 indexed_db_context_->GetIDBFactory()->Open( |
| 130 base::UTF8ToUTF16(name), std::move(connection), request_context_getter_, |
| 131 origin, indexed_db_context_->data_path()); |
| 132 } |
| 133 |
| 134 } // namespace content |
OLD | NEW |