Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(517)

Unified Diff: third_party/WebKit/Source/modules/indexeddb/InspectorIndexedDBAgent.cpp

Issue 1411633005: Indexed DB: Prevent inspector from re-creating deleted databases (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added tests Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/inspector/indexeddb/upgrade-events-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/indexeddb/InspectorIndexedDBAgent.cpp
diff --git a/third_party/WebKit/Source/modules/indexeddb/InspectorIndexedDBAgent.cpp b/third_party/WebKit/Source/modules/indexeddb/InspectorIndexedDBAgent.cpp
index f0cb0d80163f2be68b7f658109acfc6a2cedb745..8590db3c58da1bd988732ecfe98352b912671a7d 100644
--- a/third_party/WebKit/Source/modules/indexeddb/InspectorIndexedDBAgent.cpp
+++ b/third_party/WebKit/Source/modules/indexeddb/InspectorIndexedDBAgent.cpp
@@ -194,16 +194,55 @@ private:
RefPtr<ExecutableWithDatabase> m_executableWithDatabase;
};
+class UpgradeDatabaseCallback final : public EventListener {
+public:
+ static PassRefPtrWillBeRawPtr<UpgradeDatabaseCallback> create(ExecutableWithDatabase* executableWithDatabase)
+ {
+ return adoptRefWillBeNoop(new UpgradeDatabaseCallback(executableWithDatabase));
+ }
+
+ ~UpgradeDatabaseCallback() override { }
+
+ bool operator==(const EventListener& other) override
+ {
+ return this == &other;
+ }
+
+ void handleEvent(ExecutionContext* context, Event* event) override
+ {
+ if (event->type() != EventTypeNames::upgradeneeded) {
+ m_executableWithDatabase->requestCallback()->sendFailure("Unexpected event type.");
+ return;
+ }
+
+ // If an "upgradeneeded" event comes through then the database that
+ // had previously been enumerated was deleted. We don't want to
+ // implicitly re-create it here, so abort the transaction.
+ IDBOpenDBRequest* idbOpenDBRequest = static_cast<IDBOpenDBRequest*>(event->target());
+ NonThrowableExceptionState exceptionState;
+ idbOpenDBRequest->transaction()->abort(exceptionState);
+ m_executableWithDatabase->requestCallback()->sendFailure("Aborted upgrade.");
+ }
+
+private:
+ UpgradeDatabaseCallback(ExecutableWithDatabase* executableWithDatabase)
+ : EventListener(EventListener::CPPEventListenerType)
+ , m_executableWithDatabase(executableWithDatabase) { }
+ RefPtr<ExecutableWithDatabase> m_executableWithDatabase;
+};
+
void ExecutableWithDatabase::start(IDBFactory* idbFactory, SecurityOrigin*, const String& databaseName)
{
- RefPtrWillBeRawPtr<OpenDatabaseCallback> callback = OpenDatabaseCallback::create(this);
+ RefPtrWillBeRawPtr<OpenDatabaseCallback> openCallback = OpenDatabaseCallback::create(this);
+ RefPtrWillBeRawPtr<UpgradeDatabaseCallback> upgradeCallback = UpgradeDatabaseCallback::create(this);
TrackExceptionState exceptionState;
IDBOpenDBRequest* idbOpenDBRequest = idbFactory->open(scriptState(), databaseName, exceptionState);
if (exceptionState.hadException()) {
requestCallback()->sendFailure("Could not open database.");
return;
}
- idbOpenDBRequest->addEventListener(EventTypeNames::success, callback, false);
+ idbOpenDBRequest->addEventListener(EventTypeNames::upgradeneeded, upgradeCallback, false);
+ idbOpenDBRequest->addEventListener(EventTypeNames::success, openCallback, false);
}
static IDBTransaction* transactionForDatabase(ScriptState* scriptState, IDBDatabase* idbDatabase, const String& objectStoreName, const String& mode = IndexedDBNames::readonly)
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/inspector/indexeddb/upgrade-events-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698