| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_database.h" | 5 #include "content/browser/indexed_db/indexed_db_database.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 callbacks_->OnBlocked(db_->metadata_.version); | 304 callbacks_->OnBlocked(db_->metadata_.version); |
| 305 } | 305 } |
| 306 | 306 |
| 307 void OnConnectionClosed(IndexedDBConnection* connection) override { | 307 void OnConnectionClosed(IndexedDBConnection* connection) override { |
| 308 if (!db_->connections_.empty()) | 308 if (!db_->connections_.empty()) |
| 309 return; | 309 return; |
| 310 DoDelete(); | 310 DoDelete(); |
| 311 } | 311 } |
| 312 | 312 |
| 313 void DoDelete() { | 313 void DoDelete() { |
| 314 leveldb::Status s = | 314 leveldb::Status s; |
| 315 db_->backing_store_->DeleteDatabase(db_->metadata_.name); | 315 if (db_->backing_store_) |
| 316 s = db_->backing_store_->DeleteDatabase(db_->metadata_.name); |
| 316 if (!s.ok()) { | 317 if (!s.ok()) { |
| 317 // TODO(jsbell): Consider including sanitized leveldb status message. | 318 // TODO(jsbell): Consider including sanitized leveldb status message. |
| 318 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 319 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 319 "Internal error deleting database."); | 320 "Internal error deleting database."); |
| 320 callbacks_->OnError(error); | 321 callbacks_->OnError(error); |
| 321 if (s.IsCorruption()) { | 322 if (s.IsCorruption()) { |
| 322 url::Origin origin = db_->backing_store_->origin(); | 323 url::Origin origin = db_->backing_store_->origin(); |
| 323 db_->backing_store_ = nullptr; | 324 db_->backing_store_ = nullptr; |
| 324 db_->factory_->HandleBackingStoreCorruption(origin, error); | 325 db_->factory_->HandleBackingStoreCorruption(origin, error); |
| 325 } | 326 } |
| (...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1840 transaction_count_++; | 1841 transaction_count_++; |
| 1841 transaction_coordinator_.DidCreateTransaction(transaction); | 1842 transaction_coordinator_.DidCreateTransaction(transaction); |
| 1842 } | 1843 } |
| 1843 | 1844 |
| 1844 void IndexedDBDatabase::OpenConnection( | 1845 void IndexedDBDatabase::OpenConnection( |
| 1845 std::unique_ptr<IndexedDBPendingConnection> connection) { | 1846 std::unique_ptr<IndexedDBPendingConnection> connection) { |
| 1846 AppendRequest(base::MakeUnique<OpenRequest>(this, std::move(connection))); | 1847 AppendRequest(base::MakeUnique<OpenRequest>(this, std::move(connection))); |
| 1847 } | 1848 } |
| 1848 | 1849 |
| 1849 void IndexedDBDatabase::DeleteDatabase( | 1850 void IndexedDBDatabase::DeleteDatabase( |
| 1850 scoped_refptr<IndexedDBCallbacks> callbacks) { | 1851 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 1852 bool force_close) { |
| 1851 AppendRequest(base::MakeUnique<DeleteRequest>(this, callbacks)); | 1853 AppendRequest(base::MakeUnique<DeleteRequest>(this, callbacks)); |
| 1854 // Close the connections only after the request is queued to make sure |
| 1855 // the store is still open. |
| 1856 if (force_close) |
| 1857 ForceClose(); |
| 1852 } | 1858 } |
| 1853 | 1859 |
| 1854 void IndexedDBDatabase::ForceClose() { | 1860 void IndexedDBDatabase::ForceClose() { |
| 1855 // IndexedDBConnection::ForceClose() may delete this database, so hold ref. | 1861 // IndexedDBConnection::ForceClose() may delete this database, so hold ref. |
| 1856 scoped_refptr<IndexedDBDatabase> protect(this); | 1862 scoped_refptr<IndexedDBDatabase> protect(this); |
| 1857 auto it = connections_.begin(); | 1863 auto it = connections_.begin(); |
| 1858 while (it != connections_.end()) { | 1864 while (it != connections_.end()) { |
| 1859 IndexedDBConnection* connection = *it++; | 1865 IndexedDBConnection* connection = *it++; |
| 1860 connection->ForceClose(); | 1866 connection->ForceClose(); |
| 1861 } | 1867 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1943 if (status.IsCorruption()) { | 1949 if (status.IsCorruption()) { |
| 1944 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1950 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 1945 message); | 1951 message); |
| 1946 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); | 1952 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 1947 } else { | 1953 } else { |
| 1948 factory_->HandleBackingStoreFailure(backing_store_->origin()); | 1954 factory_->HandleBackingStoreFailure(backing_store_->origin()); |
| 1949 } | 1955 } |
| 1950 } | 1956 } |
| 1951 | 1957 |
| 1952 } // namespace content | 1958 } // namespace content |
| OLD | NEW |