Index: content/browser/indexed_db/indexed_db_database.h |
diff --git a/content/browser/indexed_db/indexed_db_database.h b/content/browser/indexed_db/indexed_db_database.h |
index c02b066448805f36078a14b4311a6518599f3eaa..8977d8609b59a1ec656ea917d66959248916232b 100644 |
--- a/content/browser/indexed_db/indexed_db_database.h |
+++ b/content/browser/indexed_db/indexed_db_database.h |
@@ -10,6 +10,7 @@ |
#include <list> |
#include <map> |
+#include <memory> |
#include <queue> |
#include <string> |
#include <utility> |
@@ -85,10 +86,11 @@ class CONTENT_EXPORT IndexedDBDatabase |
const IndexedDBKeyPath& key_path, |
bool auto_increment); |
void DeleteObjectStore(int64_t transaction_id, int64_t object_store_id); |
- void CreateTransaction(int64_t transaction_id, |
- IndexedDBConnection* connection, |
- const std::vector<int64_t>& object_store_ids, |
- blink::WebIDBTransactionMode mode); |
+ IndexedDBTransaction* CreateTransaction( |
+ int64_t transaction_id, |
+ IndexedDBConnection* connection, |
+ const std::vector<int64_t>& object_store_ids, |
+ blink::WebIDBTransactionMode mode); |
void Close(IndexedDBConnection* connection, bool forced); |
void ForceClose(); |
@@ -179,15 +181,14 @@ class CONTENT_EXPORT IndexedDBDatabase |
scoped_refptr<IndexedDBCallbacks> callbacks); |
// Number of connections that have progressed passed initial open call. |
- size_t ConnectionCount() const; |
- // Number of open calls that are blocked on other connections. |
- size_t PendingOpenCount() const; |
- // Number of pending upgrades (0 or 1). Also included in ConnectionCount(). |
- size_t PendingUpgradeCount() const; |
- // Number of running upgrades (0 or 1). Also included in ConnectionCount(). |
- size_t RunningUpgradeCount() const; |
- // Number of pending deletes, blocked on other connections. |
- size_t PendingDeleteCount() const; |
+ size_t ConnectionCount() const { return connections_.size(); } |
+ |
+ // Number of active open/delete calls (running or blocked on other |
+ // connections). |
+ size_t ActiveOpenDeleteCount() const { return active_request_ ? 1 : 0; } |
+ |
+ // Number of open/delete calls that are waiting their turn. |
+ size_t PendingOpenDeleteCount() const { return pending_requests_.size(); } |
// Asynchronous tasks scheduled within transactions: |
void CreateObjectStoreAbortOperation(int64_t object_store_id, |
@@ -199,7 +200,6 @@ class CONTENT_EXPORT IndexedDBDatabase |
IndexedDBTransaction* transaction); |
void VersionChangeOperation(int64_t version, |
scoped_refptr<IndexedDBCallbacks> callbacks, |
- std::unique_ptr<IndexedDBConnection> connection, |
IndexedDBTransaction* transaction); |
void VersionChangeAbortOperation(int64_t previous_version, |
IndexedDBTransaction* transaction); |
@@ -260,29 +260,23 @@ class CONTENT_EXPORT IndexedDBDatabase |
friend class base::RefCounted<IndexedDBDatabase>; |
friend class IndexedDBClassFactory; |
- class PendingDeleteCall; |
- class PendingSuccessCall; |
- class PendingUpgradeCall; |
- |
- bool IsUpgradeRunning() const; |
- bool IsUpgradePendingOrRunning() const; |
+ class OpenOrDeleteRequest; |
+ class OpenRequest; |
+ class DeleteRequest; |
- bool IsOpenConnectionBlocked() const; |
leveldb::Status OpenInternal(); |
- void RunVersionChangeTransaction( |
- scoped_refptr<IndexedDBCallbacks> callbacks, |
- std::unique_ptr<IndexedDBConnection> connection, |
- int64_t transaction_id, |
- int64_t requested_version); |
- void RunVersionChangeTransactionFinal( |
- scoped_refptr<IndexedDBCallbacks> callbacks, |
- std::unique_ptr<IndexedDBConnection> connection, |
- int64_t transaction_id, |
- int64_t requested_version); |
- void ProcessPendingCalls(); |
- bool IsDeleteDatabaseBlocked() const; |
- void DeleteDatabaseFinal(scoped_refptr<IndexedDBCallbacks> callbacks); |
+ // Called internally when an open or delete request comes in. Processes |
+ // the queue immediately if there are no other requests. |
+ void AppendRequest(std::unique_ptr<OpenOrDeleteRequest> request); |
+ |
+ // Called by requests when complete. The request will be freed, so the |
+ // request must do no other work after calling this. If there are pending |
+ // requests, the queue will be synchronously processed. |
+ void RequestComplete(OpenOrDeleteRequest* request); |
+ |
+ // Pop the first request from the queue and start it. |
+ void ProcessRequestQueue(); |
std::unique_ptr<IndexedDBConnection> CreateConnection( |
scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
@@ -308,39 +302,23 @@ class CONTENT_EXPORT IndexedDBDatabase |
std::map<int64_t, IndexedDBTransaction*> transactions_; |
- // An open request ends up here if: |
- // * There is a running or pending upgrade. |
- // * There are pending deletes. |
- // Requests here have *not* broadcast OnVersionChange if necessary. |
- // When no longer blocked, the OpenConnection() calls are remade. |
- std::queue<IndexedDBPendingConnection> pending_open_calls_; |
- |
- // This owns the connection for the first upgrade request (open with higher |
- // version) that could not be immediately processed. The request has already |
- // broadcast OnVersionChange if necessary. |
- std::unique_ptr<PendingUpgradeCall> |
- pending_run_version_change_transaction_call_; |
- |
- // This references a connection for an upgrade request while the upgrade |
- // transaction is running, so that the success/error result can be sent. It |
- // is not set until the upgrade transaction actually starts executing |
- // operations, so do not rely on it to determine if an upgrade is in |
- // progress. |
- std::unique_ptr<PendingSuccessCall> pending_second_half_open_; |
- |
- // A delete request ends up here if: |
- // * There is a running upgrade. |
- // Requests here have *not* broadcast OnVersionChange if necessary. |
- // When no longer blocked, DeleteDatabase() calls are remade. |
- std::list<std::unique_ptr<PendingDeleteCall>> pending_delete_calls_; |
- |
- // A delete request ends up here if: |
- // * There are open connections. |
- // Requests here have already broadcast OnVersionChange if necessary. |
- // When no longer blocked, DeleteDatabaseFinal() calls are made. |
- std::list<std::unique_ptr<PendingDeleteCall>> blocked_delete_calls_; |
- |
list_set<IndexedDBConnection*> connections_; |
+ |
+ // This holds the first open or delete request that could not be immediately |
+ // processed. The request has already broadcast OnVersionChange if |
+ // necessary. |
+ std::unique_ptr<OpenOrDeleteRequest> active_request_; |
+ |
+ // This holds open or delete requests that are waiting for the active |
+ // request to be completed. The requests have not yet broadcast |
+ // OnVersionChange (if necessary). |
+ std::queue<std::unique_ptr<OpenOrDeleteRequest>> pending_requests_; |
+ |
+ // The |processing_pending_requests_| flag is set while ProcessRequestQueue() |
+ // is executing. It prevents rentrant calls if the active request completes |
+ // synchronously. |
+ bool processing_pending_requests_ = false; |
+ |
bool experimental_web_platform_features_enabled_; |
DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabase); |