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

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

Issue 2468273002: [DevTools] migrate Database, IndexedDB and CacheStorage to new style (Closed)
Patch Set: addressed comments & rebased Created 4 years, 1 month 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
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 819155622e869f3e962f706d9c1ac332fe786bc2..45cac8342432eac1f3cbb4e879f4a188dd4e38df 100644
--- a/third_party/WebKit/Source/modules/indexeddb/InspectorIndexedDBAgent.cpp
+++ b/third_party/WebKit/Source/modules/indexeddb/InspectorIndexedDBAgent.cpp
@@ -87,7 +87,8 @@ static const char indexedDBAgentEnabled[] = "indexedDBAgentEnabled";
namespace {
-static const char indexedDBObjectGroup[] = "indexeddb";
+static const char kIndexedDBObjectGroup[] = "indexeddb";
+static const char kNoDocumentError[] = "No document for given frame found";
class GetDatabaseNamesCallback final : public EventListener {
WTF_MAKE_NONCOPYABLE(GetDatabaseNamesCallback);
@@ -108,14 +109,15 @@ class GetDatabaseNamesCallback final : public EventListener {
void handleEvent(ExecutionContext*, Event* event) override {
if (event->type() != EventTypeNames::success) {
- m_requestCallback->sendFailure("Unexpected event type.");
+ m_requestCallback->sendFailure(Response::Error("Unexpected event type."));
return;
}
IDBRequest* idbRequest = static_cast<IDBRequest*>(event->target());
IDBAny* requestResult = idbRequest->resultAsAny();
if (requestResult->getType() != IDBAny::DOMStringListType) {
- m_requestCallback->sendFailure("Unexpected result type.");
+ m_requestCallback->sendFailure(
+ Response::Error("Unexpected result type."));
return;
}
@@ -163,7 +165,8 @@ class ExecutableWithDatabase
IDBOpenDBRequest* idbOpenDBRequest =
idbFactory->open(getScriptState(), databaseName, exceptionState);
if (exceptionState.hadException()) {
- getRequestCallback()->sendFailure("Could not open database.");
+ getRequestCallback()->sendFailure(
+ Response::Error("Could not open database."));
return;
}
idbOpenDBRequest->addEventListener(EventTypeNames::upgradeneeded,
@@ -199,7 +202,7 @@ class OpenDatabaseCallback final : public EventListener {
void handleEvent(ExecutionContext* context, Event* event) override {
if (event->type() != EventTypeNames::success) {
m_executableWithDatabase->getRequestCallback()->sendFailure(
- "Unexpected event type.");
+ Response::Error("Unexpected event type."));
return;
}
@@ -208,7 +211,7 @@ class OpenDatabaseCallback final : public EventListener {
IDBAny* requestResult = idbOpenDBRequest->resultAsAny();
if (requestResult->getType() != IDBAny::IDBDatabaseType) {
m_executableWithDatabase->getRequestCallback()->sendFailure(
- "Unexpected result type.");
+ Response::Error("Unexpected result type."));
return;
}
@@ -245,7 +248,7 @@ class UpgradeDatabaseCallback final : public EventListener {
void handleEvent(ExecutionContext* context, Event* event) override {
if (event->type() != EventTypeNames::upgradeneeded) {
m_executableWithDatabase->getRequestCallback()->sendFailure(
- "Unexpected event type.");
+ Response::Error("Unexpected event type."));
return;
}
@@ -257,7 +260,7 @@ class UpgradeDatabaseCallback final : public EventListener {
NonThrowableExceptionState exceptionState;
idbOpenDBRequest->transaction()->abort(exceptionState);
m_executableWithDatabase->getRequestCallback()->sendFailure(
- "Aborted upgrade.");
+ Response::Error("Aborted upgrade."));
}
private:
@@ -483,7 +486,7 @@ class OpenCursorCallback final : public EventListener {
void handleEvent(ExecutionContext*, Event* event) override {
if (event->type() != EventTypeNames::success) {
- m_requestCallback->sendFailure("Unexpected event type.");
+ m_requestCallback->sendFailure(Response::Error("Unexpected event type."));
return;
}
@@ -494,7 +497,8 @@ class OpenCursorCallback final : public EventListener {
return;
}
if (requestResult->getType() != IDBAny::IDBCursorWithValueType) {
- m_requestCallback->sendFailure("Unexpected result type.");
+ m_requestCallback->sendFailure(
+ Response::Error("Unexpected result type."));
return;
}
@@ -503,8 +507,10 @@ class OpenCursorCallback final : public EventListener {
if (m_skipCount) {
TrackExceptionState exceptionState;
idbCursor->advance(m_skipCount, exceptionState);
- if (exceptionState.hadException())
- m_requestCallback->sendFailure("Could not advance cursor.");
+ if (exceptionState.hadException()) {
+ m_requestCallback->sendFailure(
+ Response::Error("Could not advance cursor."));
+ }
m_skipCount = 0;
return;
}
@@ -519,7 +525,8 @@ class OpenCursorCallback final : public EventListener {
TrackExceptionState exceptionState;
idbCursor->continueFunction(nullptr, nullptr, exceptionState);
if (exceptionState.hadException()) {
- m_requestCallback->sendFailure("Could not continue cursor.");
+ m_requestCallback->sendFailure(
+ Response::Error("Could not continue cursor."));
return;
}
@@ -530,7 +537,7 @@ class OpenCursorCallback final : public EventListener {
ScriptState::Scope scope(scriptState);
v8::Local<v8::Context> context = scriptState->context();
v8_inspector::StringView objectGroup =
- toV8InspectorStringView(indexedDBObjectGroup);
+ toV8InspectorStringView(kIndexedDBObjectGroup);
std::unique_ptr<DataEntry> dataEntry =
DataEntry::create()
.setKey(m_v8Session->wrapObject(
@@ -595,13 +602,15 @@ class DataLoader final : public ExecutableWithDatabase<RequestDataCallback> {
IDBTransaction* idbTransaction = transactionForDatabase(
getScriptState(), idbDatabase, m_objectStoreName);
if (!idbTransaction) {
- m_requestCallback->sendFailure("Could not get transaction");
+ m_requestCallback->sendFailure(
+ Response::Error("Could not get transaction"));
return;
}
IDBObjectStore* idbObjectStore =
objectStoreForTransaction(idbTransaction, m_objectStoreName);
if (!idbObjectStore) {
- m_requestCallback->sendFailure("Could not get object store");
+ m_requestCallback->sendFailure(
+ Response::Error("Could not get object store"));
return;
}
@@ -609,7 +618,7 @@ class DataLoader final : public ExecutableWithDatabase<RequestDataCallback> {
if (!m_indexName.isEmpty()) {
IDBIndex* idbIndex = indexForObjectStore(idbObjectStore, m_indexName);
if (!idbIndex) {
- m_requestCallback->sendFailure("Could not get index");
+ m_requestCallback->sendFailure(Response::Error("Could not get index"));
return;
}
@@ -668,49 +677,39 @@ InspectorIndexedDBAgent::~InspectorIndexedDBAgent() {}
void InspectorIndexedDBAgent::restore() {
if (m_state->booleanProperty(IndexedDBAgentState::indexedDBAgentEnabled,
false)) {
- ErrorString error;
- enable(&error);
+ enable();
}
}
void InspectorIndexedDBAgent::didCommitLoadForLocalFrame(LocalFrame* frame) {
- if (frame == m_inspectedFrames->root())
+ if (frame == m_inspectedFrames->root()) {
m_v8Session->releaseObjectGroup(
- toV8InspectorStringView(indexedDBObjectGroup));
+ toV8InspectorStringView(kIndexedDBObjectGroup));
+ }
}
-void InspectorIndexedDBAgent::enable(ErrorString*) {
+Response InspectorIndexedDBAgent::enable() {
m_state->setBoolean(IndexedDBAgentState::indexedDBAgentEnabled, true);
+ return Response::OK();
}
-void InspectorIndexedDBAgent::disable(ErrorString*) {
+Response InspectorIndexedDBAgent::disable() {
m_state->setBoolean(IndexedDBAgentState::indexedDBAgentEnabled, false);
m_v8Session->releaseObjectGroup(
- toV8InspectorStringView(indexedDBObjectGroup));
+ toV8InspectorStringView(kIndexedDBObjectGroup));
+ return Response::OK();
}
-static Document* assertDocument(ErrorString* errorString, LocalFrame* frame) {
- Document* document = frame ? frame->document() : nullptr;
-
- if (!document)
- *errorString = "No document for given frame found";
-
- return document;
-}
-
-static IDBFactory* assertIDBFactory(ErrorString* errorString,
- Document* document) {
+static Response assertIDBFactory(Document* document, IDBFactory*& result) {
LocalDOMWindow* domWindow = document->domWindow();
- if (!domWindow) {
- *errorString = "No IndexedDB factory for given frame found";
- return nullptr;
- }
+ if (!domWindow)
+ return Response::Error("No IndexedDB factory for given frame found");
IDBFactory* idbFactory = GlobalIndexedDB::indexedDB(*domWindow);
if (!idbFactory)
- *errorString = "No IndexedDB factory for given frame found";
-
- return idbFactory;
+ return Response::Error("No IndexedDB factory for given frame found");
+ result = idbFactory;
+ return Response::OK();
}
void InspectorIndexedDBAgent::requestDatabaseNames(
@@ -719,26 +718,30 @@ void InspectorIndexedDBAgent::requestDatabaseNames(
LocalFrame* frame =
m_inspectedFrames->frameWithSecurityOrigin(securityOrigin);
ErrorString errorString;
- Document* document = assertDocument(&errorString, frame);
+ Document* document = frame ? frame->document() : nullptr;
if (!document) {
- requestCallback->sendFailure(errorString);
+ requestCallback->sendFailure(Response::Error(kNoDocumentError));
return;
}
- IDBFactory* idbFactory = assertIDBFactory(&errorString, document);
- if (!idbFactory) {
- requestCallback->sendFailure(errorString);
+ IDBFactory* idbFactory = nullptr;
+ Response response = assertIDBFactory(document, idbFactory);
+ if (!response.isSuccess()) {
+ requestCallback->sendFailure(response);
return;
}
ScriptState* scriptState = ScriptState::forMainWorld(frame);
- if (!scriptState)
+ if (!scriptState) {
+ requestCallback->sendFailure(Response::InternalError());
return;
+ }
ScriptState::Scope scope(scriptState);
TrackExceptionState exceptionState;
IDBRequest* idbRequest =
idbFactory->getDatabaseNames(scriptState, exceptionState);
if (exceptionState.hadException()) {
- requestCallback->sendFailure("Could not obtain database names.");
+ requestCallback->sendFailure(
+ Response::Error("Could not obtain database names."));
return;
}
idbRequest->addEventListener(
@@ -756,20 +759,24 @@ void InspectorIndexedDBAgent::requestDatabase(
LocalFrame* frame =
m_inspectedFrames->frameWithSecurityOrigin(securityOrigin);
ErrorString errorString;
- Document* document = assertDocument(&errorString, frame);
+ Document* document = frame ? frame->document() : nullptr;
if (!document) {
- requestCallback->sendFailure(errorString);
+ requestCallback->sendFailure(Response::Error(kNoDocumentError));
return;
}
- IDBFactory* idbFactory = assertIDBFactory(&errorString, document);
- if (!idbFactory) {
- requestCallback->sendFailure(errorString);
+ IDBFactory* idbFactory = nullptr;
+ Response response = assertIDBFactory(document, idbFactory);
+ if (!response.isSuccess()) {
+ requestCallback->sendFailure(response);
return;
}
ScriptState* scriptState = ScriptState::forMainWorld(frame);
- if (!scriptState)
+ if (!scriptState) {
+ requestCallback->sendFailure(Response::InternalError());
return;
+ }
+
ScriptState::Scope scope(scriptState);
RefPtr<DatabaseLoader> databaseLoader =
DatabaseLoader::create(scriptState, std::move(requestCallback));
@@ -784,19 +791,20 @@ void InspectorIndexedDBAgent::requestData(
const String& indexName,
int skipCount,
int pageSize,
- const Maybe<protocol::IndexedDB::KeyRange>& keyRange,
+ Maybe<protocol::IndexedDB::KeyRange> keyRange,
std::unique_ptr<RequestDataCallback> requestCallback) {
LocalFrame* frame =
m_inspectedFrames->frameWithSecurityOrigin(securityOrigin);
ErrorString errorString;
- Document* document = assertDocument(&errorString, frame);
+ Document* document = frame ? frame->document() : nullptr;
if (!document) {
- requestCallback->sendFailure(errorString);
+ requestCallback->sendFailure(Response::Error(kNoDocumentError));
return;
}
- IDBFactory* idbFactory = assertIDBFactory(&errorString, document);
- if (!idbFactory) {
- requestCallback->sendFailure(errorString);
+ IDBFactory* idbFactory = nullptr;
+ Response response = assertIDBFactory(document, idbFactory);
+ if (!response.isSuccess()) {
+ requestCallback->sendFailure(response);
return;
}
@@ -804,13 +812,16 @@ void InspectorIndexedDBAgent::requestData(
? idbKeyRangeFromKeyRange(keyRange.fromJust())
: nullptr;
if (keyRange.isJust() && !idbKeyRange) {
- requestCallback->sendFailure("Can not parse key range.");
+ requestCallback->sendFailure(Response::Error("Can not parse key range."));
return;
}
ScriptState* scriptState = ScriptState::forMainWorld(frame);
- if (!scriptState)
+ if (!scriptState) {
+ requestCallback->sendFailure(Response::InternalError());
return;
+ }
+
ScriptState::Scope scope(scriptState);
RefPtr<DataLoader> dataLoader = DataLoader::create(
m_v8Session, scriptState, std::move(requestCallback), objectStoreName,
@@ -835,7 +846,7 @@ class ClearObjectStoreListener final : public EventListener {
void handleEvent(ExecutionContext*, Event* event) override {
if (event->type() != EventTypeNames::complete) {
- m_requestCallback->sendFailure("Unexpected event type.");
+ m_requestCallback->sendFailure(Response::Error("Unexpected event type."));
return;
}
@@ -876,13 +887,15 @@ class ClearObjectStore final
transactionForDatabase(getScriptState(), idbDatabase, m_objectStoreName,
IndexedDBNames::readwrite);
if (!idbTransaction) {
- m_requestCallback->sendFailure("Could not get transaction");
+ m_requestCallback->sendFailure(
+ Response::Error("Could not get transaction"));
return;
}
IDBObjectStore* idbObjectStore =
objectStoreForTransaction(idbTransaction, m_objectStoreName);
if (!idbObjectStore) {
- m_requestCallback->sendFailure("Could not get object store");
+ m_requestCallback->sendFailure(
+ Response::Error("Could not get object store"));
return;
}
@@ -891,9 +904,9 @@ class ClearObjectStore final
ASSERT(!exceptionState.hadException());
if (exceptionState.hadException()) {
ExceptionCode ec = exceptionState.code();
- m_requestCallback->sendFailure(
+ m_requestCallback->sendFailure(Response::Error(
String::format("Could not clear object store '%s': %d",
- m_objectStoreName.utf8().data(), ec));
+ m_objectStoreName.utf8().data(), ec)));
return;
}
idbTransaction->addEventListener(
@@ -918,20 +931,24 @@ void InspectorIndexedDBAgent::clearObjectStore(
LocalFrame* frame =
m_inspectedFrames->frameWithSecurityOrigin(securityOrigin);
ErrorString errorString;
- Document* document = assertDocument(&errorString, frame);
+ Document* document = frame ? frame->document() : nullptr;
if (!document) {
- requestCallback->sendFailure(errorString);
+ requestCallback->sendFailure(Response::Error(kNoDocumentError));
return;
}
- IDBFactory* idbFactory = assertIDBFactory(&errorString, document);
- if (!idbFactory) {
- requestCallback->sendFailure(errorString);
+ IDBFactory* idbFactory = nullptr;
+ Response response = assertIDBFactory(document, idbFactory);
+ if (!response.isSuccess()) {
+ requestCallback->sendFailure(response);
return;
}
ScriptState* scriptState = ScriptState::forMainWorld(frame);
- if (!scriptState)
+ if (!scriptState) {
+ requestCallback->sendFailure(Response::InternalError());
return;
+ }
+
ScriptState::Scope scope(scriptState);
RefPtr<ClearObjectStore> clearObjectStore = ClearObjectStore::create(
scriptState, objectStoreName, std::move(requestCallback));

Powered by Google App Engine
This is Rietveld 408576698