| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 const char kInvalidOrigin[] = "Origin is invalid"; | 30 const char kInvalidOrigin[] = "Origin is invalid"; |
| 31 | 31 |
| 32 bool IsValidOrigin(const url::Origin& origin) { | 32 bool IsValidOrigin(const url::Origin& origin) { |
| 33 return !origin.unique(); | 33 return !origin.unique(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 class IndexedDBDispatcherHost::IDBThreadHelper { | 38 class IndexedDBDispatcherHost::IDBSequenceHelper { |
| 39 public: | 39 public: |
| 40 IDBThreadHelper( | 40 IDBSequenceHelper( |
| 41 int ipc_process_id, | 41 int ipc_process_id, |
| 42 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 42 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 43 scoped_refptr<IndexedDBContextImpl> indexed_db_context) | 43 scoped_refptr<IndexedDBContextImpl> indexed_db_context) |
| 44 : ipc_process_id_(ipc_process_id), | 44 : ipc_process_id_(ipc_process_id), |
| 45 request_context_getter_(std::move(request_context_getter)), | 45 request_context_getter_(std::move(request_context_getter)), |
| 46 indexed_db_context_(std::move(indexed_db_context)) {} | 46 indexed_db_context_(std::move(indexed_db_context)) {} |
| 47 ~IDBThreadHelper() {} | 47 ~IDBSequenceHelper() {} |
| 48 | 48 |
| 49 void GetDatabaseNamesOnIDBThread(scoped_refptr<IndexedDBCallbacks> callbacks, | 49 void GetDatabaseNamesOnIDBThread(scoped_refptr<IndexedDBCallbacks> callbacks, |
| 50 const url::Origin& origin); | 50 const url::Origin& origin); |
| 51 void OpenOnIDBThread( | 51 void OpenOnIDBThread( |
| 52 scoped_refptr<IndexedDBCallbacks> callbacks, | 52 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 53 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 53 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
| 54 const url::Origin& origin, | 54 const url::Origin& origin, |
| 55 const base::string16& name, | 55 const base::string16& name, |
| 56 int64_t version, | 56 int64_t version, |
| 57 int64_t transaction_id); | 57 int64_t transaction_id); |
| 58 void DeleteDatabaseOnIDBThread(scoped_refptr<IndexedDBCallbacks> callbacks, | 58 void DeleteDatabaseOnIDBThread(scoped_refptr<IndexedDBCallbacks> callbacks, |
| 59 const url::Origin& origin, | 59 const url::Origin& origin, |
| 60 const base::string16& name, | 60 const base::string16& name, |
| 61 bool force_close); | 61 bool force_close); |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 const int ipc_process_id_; | 64 const int ipc_process_id_; |
| 65 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 65 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 66 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; | 66 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; |
| 67 | 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(IDBThreadHelper); | 68 DISALLOW_COPY_AND_ASSIGN(IDBSequenceHelper); |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 IndexedDBDispatcherHost::IndexedDBDispatcherHost( | 71 IndexedDBDispatcherHost::IndexedDBDispatcherHost( |
| 72 int ipc_process_id, | 72 int ipc_process_id, |
| 73 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 73 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 74 scoped_refptr<IndexedDBContextImpl> indexed_db_context, | 74 scoped_refptr<IndexedDBContextImpl> indexed_db_context, |
| 75 scoped_refptr<ChromeBlobStorageContext> blob_storage_context) | 75 scoped_refptr<ChromeBlobStorageContext> blob_storage_context) |
| 76 : indexed_db_context_(std::move(indexed_db_context)), | 76 : indexed_db_context_(std::move(indexed_db_context)), |
| 77 blob_storage_context_(std::move(blob_storage_context)), | 77 blob_storage_context_(std::move(blob_storage_context)), |
| 78 idb_runner_(indexed_db_context_->TaskRunner()), | 78 idb_runner_(indexed_db_context_->TaskRunner()), |
| 79 ipc_process_id_(ipc_process_id), | 79 ipc_process_id_(ipc_process_id), |
| 80 weak_factory_(this) { | 80 weak_factory_(this) { |
| 81 // Can be null in unittests. | 81 // Can be null in unittests. |
| 82 idb_helper_ = idb_runner_ | 82 idb_helper_ = idb_runner_ |
| 83 ? new IDBThreadHelper(ipc_process_id_, | 83 ? new IDBSequenceHelper(ipc_process_id_, |
| 84 std::move(request_context_getter), | 84 std::move(request_context_getter), |
| 85 indexed_db_context_) | 85 indexed_db_context_) |
| 86 : nullptr; | 86 : nullptr; |
| 87 DCHECK(indexed_db_context_.get()); | 87 DCHECK(indexed_db_context_.get()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() { | 90 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() { |
| 91 if (idb_helper_) | 91 if (idb_helper_) |
| 92 idb_runner_->DeleteSoon(FROM_HERE, idb_helper_); | 92 idb_runner_->DeleteSoon(FROM_HERE, idb_helper_); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void IndexedDBDispatcherHost::AddBinding( | 95 void IndexedDBDispatcherHost::AddBinding( |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 167 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 168 | 168 |
| 169 if (!IsValidOrigin(origin)) { | 169 if (!IsValidOrigin(origin)) { |
| 170 mojo::ReportBadMessage(kInvalidOrigin); | 170 mojo::ReportBadMessage(kInvalidOrigin); |
| 171 return; | 171 return; |
| 172 } | 172 } |
| 173 | 173 |
| 174 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 174 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 175 this->AsWeakPtr(), origin, std::move(callbacks_info), idb_runner_)); | 175 this->AsWeakPtr(), origin, std::move(callbacks_info), idb_runner_)); |
| 176 idb_runner_->PostTask( | 176 idb_runner_->PostTask( |
| 177 FROM_HERE, base::Bind(&IDBThreadHelper::GetDatabaseNamesOnIDBThread, | 177 FROM_HERE, base::Bind(&IDBSequenceHelper::GetDatabaseNamesOnIDBThread, |
| 178 base::Unretained(idb_helper_), | 178 base::Unretained(idb_helper_), |
| 179 base::Passed(&callbacks), origin)); | 179 base::Passed(&callbacks), origin)); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void IndexedDBDispatcherHost::Open( | 182 void IndexedDBDispatcherHost::Open( |
| 183 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, | 183 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, |
| 184 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo | 184 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo |
| 185 database_callbacks_info, | 185 database_callbacks_info, |
| 186 const url::Origin& origin, | 186 const url::Origin& origin, |
| 187 const base::string16& name, | 187 const base::string16& name, |
| 188 int64_t version, | 188 int64_t version, |
| 189 int64_t transaction_id) { | 189 int64_t transaction_id) { |
| 190 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 190 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 191 | 191 |
| 192 if (!IsValidOrigin(origin)) { | 192 if (!IsValidOrigin(origin)) { |
| 193 mojo::ReportBadMessage(kInvalidOrigin); | 193 mojo::ReportBadMessage(kInvalidOrigin); |
| 194 return; | 194 return; |
| 195 } | 195 } |
| 196 | 196 |
| 197 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 197 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 198 this->AsWeakPtr(), origin, std::move(callbacks_info), idb_runner_)); | 198 this->AsWeakPtr(), origin, std::move(callbacks_info), idb_runner_)); |
| 199 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks( | 199 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks( |
| 200 new IndexedDBDatabaseCallbacks(indexed_db_context_, | 200 new IndexedDBDatabaseCallbacks(indexed_db_context_, |
| 201 std::move(database_callbacks_info))); | 201 std::move(database_callbacks_info))); |
| 202 idb_runner_->PostTask( | 202 idb_runner_->PostTask( |
| 203 FROM_HERE, | 203 FROM_HERE, |
| 204 base::Bind(&IDBThreadHelper::OpenOnIDBThread, | 204 base::Bind(&IDBSequenceHelper::OpenOnIDBThread, |
| 205 base::Unretained(idb_helper_), base::Passed(&callbacks), | 205 base::Unretained(idb_helper_), base::Passed(&callbacks), |
| 206 base::Passed(&database_callbacks), origin, name, version, | 206 base::Passed(&database_callbacks), origin, name, version, |
| 207 transaction_id)); | 207 transaction_id)); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void IndexedDBDispatcherHost::DeleteDatabase( | 210 void IndexedDBDispatcherHost::DeleteDatabase( |
| 211 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, | 211 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, |
| 212 const url::Origin& origin, | 212 const url::Origin& origin, |
| 213 const base::string16& name, | 213 const base::string16& name, |
| 214 bool force_close) { | 214 bool force_close) { |
| 215 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 215 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 216 | 216 |
| 217 if (!IsValidOrigin(origin)) { | 217 if (!IsValidOrigin(origin)) { |
| 218 mojo::ReportBadMessage(kInvalidOrigin); | 218 mojo::ReportBadMessage(kInvalidOrigin); |
| 219 return; | 219 return; |
| 220 } | 220 } |
| 221 | 221 |
| 222 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 222 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 223 this->AsWeakPtr(), origin, std::move(callbacks_info), idb_runner_)); | 223 this->AsWeakPtr(), origin, std::move(callbacks_info), idb_runner_)); |
| 224 idb_runner_->PostTask( | 224 idb_runner_->PostTask( |
| 225 FROM_HERE, | 225 FROM_HERE, |
| 226 base::Bind(&IDBThreadHelper::DeleteDatabaseOnIDBThread, | 226 base::Bind(&IDBSequenceHelper::DeleteDatabaseOnIDBThread, |
| 227 base::Unretained(idb_helper_), base::Passed(&callbacks), | 227 base::Unretained(idb_helper_), base::Passed(&callbacks), |
| 228 origin, name, force_close)); | 228 origin, name, force_close)); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void IndexedDBDispatcherHost::InvalidateWeakPtrsAndClearBindings() { | 231 void IndexedDBDispatcherHost::InvalidateWeakPtrsAndClearBindings() { |
| 232 weak_factory_.InvalidateWeakPtrs(); | 232 weak_factory_.InvalidateWeakPtrs(); |
| 233 cursor_bindings_.CloseAllBindings(); | 233 cursor_bindings_.CloseAllBindings(); |
| 234 database_bindings_.CloseAllBindings(); | 234 database_bindings_.CloseAllBindings(); |
| 235 } | 235 } |
| 236 | 236 |
| 237 void IndexedDBDispatcherHost::IDBThreadHelper::GetDatabaseNamesOnIDBThread( | 237 void IndexedDBDispatcherHost::IDBSequenceHelper::GetDatabaseNamesOnIDBThread( |
| 238 scoped_refptr<IndexedDBCallbacks> callbacks, | 238 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 239 const url::Origin& origin) { | 239 const url::Origin& origin) { |
| 240 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksInCurrentSequence()); | 240 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksInCurrentSequence()); |
| 241 | 241 |
| 242 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 242 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 243 indexed_db_context_->GetIDBFactory()->GetDatabaseNames( | 243 indexed_db_context_->GetIDBFactory()->GetDatabaseNames( |
| 244 callbacks, origin, indexed_db_path, request_context_getter_); | 244 callbacks, origin, indexed_db_path, request_context_getter_); |
| 245 } | 245 } |
| 246 | 246 |
| 247 void IndexedDBDispatcherHost::IDBThreadHelper::OpenOnIDBThread( | 247 void IndexedDBDispatcherHost::IDBSequenceHelper::OpenOnIDBThread( |
| 248 scoped_refptr<IndexedDBCallbacks> callbacks, | 248 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 249 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 249 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
| 250 const url::Origin& origin, | 250 const url::Origin& origin, |
| 251 const base::string16& name, | 251 const base::string16& name, |
| 252 int64_t version, | 252 int64_t version, |
| 253 int64_t transaction_id) { | 253 int64_t transaction_id) { |
| 254 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksInCurrentSequence()); | 254 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksInCurrentSequence()); |
| 255 | 255 |
| 256 base::TimeTicks begin_time = base::TimeTicks::Now(); | 256 base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 257 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 257 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 258 | 258 |
| 259 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore | 259 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore |
| 260 // created) if this origin is already over quota. | 260 // created) if this origin is already over quota. |
| 261 callbacks->SetConnectionOpenStartTime(begin_time); | 261 callbacks->SetConnectionOpenStartTime(begin_time); |
| 262 std::unique_ptr<IndexedDBPendingConnection> connection = | 262 std::unique_ptr<IndexedDBPendingConnection> connection = |
| 263 base::MakeUnique<IndexedDBPendingConnection>( | 263 base::MakeUnique<IndexedDBPendingConnection>( |
| 264 callbacks, database_callbacks, ipc_process_id_, transaction_id, | 264 callbacks, database_callbacks, ipc_process_id_, transaction_id, |
| 265 version); | 265 version); |
| 266 DCHECK(request_context_getter_); | 266 DCHECK(request_context_getter_); |
| 267 indexed_db_context_->GetIDBFactory()->Open(name, std::move(connection), | 267 indexed_db_context_->GetIDBFactory()->Open(name, std::move(connection), |
| 268 request_context_getter_, origin, | 268 request_context_getter_, origin, |
| 269 indexed_db_path); | 269 indexed_db_path); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void IndexedDBDispatcherHost::IDBThreadHelper::DeleteDatabaseOnIDBThread( | 272 void IndexedDBDispatcherHost::IDBSequenceHelper::DeleteDatabaseOnIDBThread( |
| 273 scoped_refptr<IndexedDBCallbacks> callbacks, | 273 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 274 const url::Origin& origin, | 274 const url::Origin& origin, |
| 275 const base::string16& name, | 275 const base::string16& name, |
| 276 bool force_close) { | 276 bool force_close) { |
| 277 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksInCurrentSequence()); | 277 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksInCurrentSequence()); |
| 278 | 278 |
| 279 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 279 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 280 DCHECK(request_context_getter_); | 280 DCHECK(request_context_getter_); |
| 281 indexed_db_context_->GetIDBFactory()->DeleteDatabase( | 281 indexed_db_context_->GetIDBFactory()->DeleteDatabase( |
| 282 name, request_context_getter_, callbacks, origin, indexed_db_path, | 282 name, request_context_getter_, callbacks, origin, indexed_db_path, |
| 283 force_close); | 283 force_close); |
| 284 } | 284 } |
| 285 | 285 |
| 286 } // namespace content | 286 } // namespace content |
| OLD | NEW |