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 <memory> | 10 #include <memory> |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 NOTREACHED(); | 76 NOTREACHED(); |
77 return KEY_PATH_TYPE_NONE; | 77 return KEY_PATH_TYPE_NONE; |
78 } | 78 } |
79 | 79 |
80 } // namespace | 80 } // namespace |
81 | 81 |
82 // This represents what script calls an 'IDBOpenDBRequest' - either a database | 82 // This represents what script calls an 'IDBOpenDBRequest' - either a database |
83 // open or delete call. These may be blocked on other connections. After every | 83 // open or delete call. These may be blocked on other connections. After every |
84 // callback, the request must call IndexedDBDatabase::RequestComplete() or be | 84 // callback, the request must call IndexedDBDatabase::RequestComplete() or be |
85 // expecting a further callback. | 85 // expecting a further callback. |
86 class IndexedDBDatabase::OpenOrDeleteRequest { | 86 class IndexedDBDatabase::ConnectionRequest { |
87 public: | 87 public: |
88 explicit OpenOrDeleteRequest(scoped_refptr<IndexedDBDatabase> db) : db_(db) {} | 88 explicit ConnectionRequest(scoped_refptr<IndexedDBDatabase> db) : db_(db) {} |
89 | 89 |
90 virtual ~OpenOrDeleteRequest() {} | 90 virtual ~ConnectionRequest() {} |
91 | 91 |
92 // Called when the request makes it to the front of the queue. | 92 // Called when the request makes it to the front of the queue. |
93 virtual void Perform() = 0; | 93 virtual void Perform() = 0; |
94 | 94 |
95 // Called if a front-end signals that it is ignoring a "versionchange" | 95 // Called if a front-end signals that it is ignoring a "versionchange" |
96 // event. This should result in firing a "blocked" event at the request. | 96 // event. This should result in firing a "blocked" event at the request. |
97 virtual void OnVersionChangeIgnored() const = 0; | 97 virtual void OnVersionChangeIgnored() const = 0; |
98 | 98 |
99 // Called when a connection is closed; if it corresponds to this connection, | 99 // Called when a connection is closed; if it corresponds to this connection, |
100 // need to do cleanup. Otherwise, it may unblock further steps. | 100 // need to do cleanup. Otherwise, it may unblock further steps. |
101 virtual void OnConnectionClosed(IndexedDBConnection* connection) = 0; | 101 virtual void OnConnectionClosed(IndexedDBConnection* connection) = 0; |
102 | 102 |
103 // Called when the upgrade transaction has started executing. | 103 // Called when the upgrade transaction has started executing. |
104 virtual void UpgradeTransactionStarted(int64_t old_version) = 0; | 104 virtual void UpgradeTransactionStarted(int64_t old_version) = 0; |
105 | 105 |
106 // Called when the upgrade transaction has finished. | 106 // Called when the upgrade transaction has finished. |
107 virtual void UpgradeTransactionFinished(bool committed) = 0; | 107 virtual void UpgradeTransactionFinished(bool committed) = 0; |
108 | 108 |
109 protected: | 109 protected: |
110 scoped_refptr<IndexedDBDatabase> db_; | 110 scoped_refptr<IndexedDBDatabase> db_; |
111 | 111 |
112 private: | 112 private: |
113 DISALLOW_COPY_AND_ASSIGN(OpenOrDeleteRequest); | 113 DISALLOW_COPY_AND_ASSIGN(ConnectionRequest); |
114 }; | 114 }; |
115 | 115 |
116 class IndexedDBDatabase::OpenRequest | 116 class IndexedDBDatabase::OpenRequest |
117 : public IndexedDBDatabase::OpenOrDeleteRequest { | 117 : public IndexedDBDatabase::ConnectionRequest { |
118 public: | 118 public: |
119 OpenRequest(scoped_refptr<IndexedDBDatabase> db, | 119 OpenRequest(scoped_refptr<IndexedDBDatabase> db, |
120 std::unique_ptr<IndexedDBPendingConnection> pending_connection) | 120 std::unique_ptr<IndexedDBPendingConnection> pending_connection) |
121 : OpenOrDeleteRequest(db), pending_(std::move(pending_connection)) {} | 121 : ConnectionRequest(db), pending_(std::move(pending_connection)) {} |
122 | 122 |
123 void Perform() override { | 123 void Perform() override { |
124 if (db_->metadata_.id == kInvalidId) { | 124 if (db_->metadata_.id == kInvalidId) { |
125 // The database was deleted then immediately re-opened; OpenInternal() | 125 // The database was deleted then immediately re-opened; OpenInternal() |
126 // recreates it in the backing store. | 126 // recreates it in the backing store. |
127 if (!db_->OpenInternal().ok()) { | 127 if (!db_->OpenInternal().ok()) { |
128 // TODO(jsbell): Consider including sanitized leveldb status message. | 128 // TODO(jsbell): Consider including sanitized leveldb status message. |
129 base::string16 message; | 129 base::string16 message; |
130 if (pending_->version == IndexedDBDatabaseMetadata::NO_VERSION) { | 130 if (pending_->version == IndexedDBDatabaseMetadata::NO_VERSION) { |
131 message = ASCIIToUTF16( | 131 message = ASCIIToUTF16( |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 std::unique_ptr<IndexedDBPendingConnection> pending_; | 279 std::unique_ptr<IndexedDBPendingConnection> pending_; |
280 | 280 |
281 // If an upgrade is needed, holds the pending connection until ownership is | 281 // If an upgrade is needed, holds the pending connection until ownership is |
282 // transferred to the IndexedDBDispatcherHost via OnUpgradeNeeded. | 282 // transferred to the IndexedDBDispatcherHost via OnUpgradeNeeded. |
283 std::unique_ptr<IndexedDBConnection> connection_; | 283 std::unique_ptr<IndexedDBConnection> connection_; |
284 | 284 |
285 DISALLOW_COPY_AND_ASSIGN(OpenRequest); | 285 DISALLOW_COPY_AND_ASSIGN(OpenRequest); |
286 }; | 286 }; |
287 | 287 |
288 class IndexedDBDatabase::DeleteRequest | 288 class IndexedDBDatabase::DeleteRequest |
289 : public IndexedDBDatabase::OpenOrDeleteRequest { | 289 : public IndexedDBDatabase::ConnectionRequest { |
290 public: | 290 public: |
291 DeleteRequest(scoped_refptr<IndexedDBDatabase> db, | 291 DeleteRequest(scoped_refptr<IndexedDBDatabase> db, |
292 scoped_refptr<IndexedDBCallbacks> callbacks) | 292 scoped_refptr<IndexedDBCallbacks> callbacks) |
293 : OpenOrDeleteRequest(db), callbacks_(callbacks) {} | 293 : ConnectionRequest(db), callbacks_(callbacks) {} |
294 | 294 |
295 void Perform() override { | 295 void Perform() override { |
296 if (db_->connections_.empty()) { | 296 if (db_->connections_.empty()) { |
297 // No connections, so delete immediately. | 297 // No connections, so delete immediately. |
298 DoDelete(); | 298 DoDelete(); |
299 return; | 299 return; |
300 } | 300 } |
301 | 301 |
302 // Front end ensures the event is not fired at connections that have | 302 // Front end ensures the event is not fired at connections that have |
303 // close_pending set. | 303 // close_pending set. |
(...skipping 1542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1846 if (status.IsCorruption()) { | 1846 if (status.IsCorruption()) { |
1847 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1847 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
1848 "Error committing transaction"); | 1848 "Error committing transaction"); |
1849 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); | 1849 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
1850 } else { | 1850 } else { |
1851 factory_->HandleBackingStoreFailure(backing_store_->origin()); | 1851 factory_->HandleBackingStoreFailure(backing_store_->origin()); |
1852 } | 1852 } |
1853 } | 1853 } |
1854 | 1854 |
1855 void IndexedDBDatabase::AppendRequest( | 1855 void IndexedDBDatabase::AppendRequest( |
1856 std::unique_ptr<OpenOrDeleteRequest> request) { | 1856 std::unique_ptr<ConnectionRequest> request) { |
1857 pending_requests_.push(std::move(request)); | 1857 pending_requests_.push(std::move(request)); |
1858 | 1858 |
1859 if (!active_request_) | 1859 if (!active_request_) |
1860 ProcessRequestQueue(); | 1860 ProcessRequestQueue(); |
1861 } | 1861 } |
1862 | 1862 |
1863 void IndexedDBDatabase::RequestComplete(OpenOrDeleteRequest* request) { | 1863 void IndexedDBDatabase::RequestComplete(ConnectionRequest* request) { |
1864 DCHECK_EQ(request, active_request_.get()); | 1864 DCHECK_EQ(request, active_request_.get()); |
1865 active_request_.reset(); | 1865 active_request_.reset(); |
1866 | 1866 |
1867 if (!pending_requests_.empty()) | 1867 if (!pending_requests_.empty()) |
1868 ProcessRequestQueue(); | 1868 ProcessRequestQueue(); |
1869 } | 1869 } |
1870 | 1870 |
1871 void IndexedDBDatabase::ProcessRequestQueue() { | 1871 void IndexedDBDatabase::ProcessRequestQueue() { |
1872 // Don't run re-entrantly to avoid exploding call stacks for requests that | 1872 // Don't run re-entrantly to avoid exploding call stacks for requests that |
1873 // complete synchronously. The loop below will process requests until one is | 1873 // complete synchronously. The loop below will process requests until one is |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2004 | 2004 |
2005 void IndexedDBDatabase::VersionChangeAbortOperation( | 2005 void IndexedDBDatabase::VersionChangeAbortOperation( |
2006 int64_t previous_version, | 2006 int64_t previous_version, |
2007 IndexedDBTransaction* transaction) { | 2007 IndexedDBTransaction* transaction) { |
2008 DCHECK(!transaction); | 2008 DCHECK(!transaction); |
2009 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); | 2009 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); |
2010 metadata_.version = previous_version; | 2010 metadata_.version = previous_version; |
2011 } | 2011 } |
2012 | 2012 |
2013 } // namespace content | 2013 } // namespace content |
OLD | NEW |