Index: third_party/WebKit/Source/modules/cachestorage/InspectorCacheStorageAgent.cpp |
diff --git a/third_party/WebKit/Source/modules/cachestorage/InspectorCacheStorageAgent.cpp b/third_party/WebKit/Source/modules/cachestorage/InspectorCacheStorageAgent.cpp |
index d15891be8697a294eaced9e226665c8ca44d0c35..4da2ddf59fc5e0b41803cca73c065654e27b0fe7 100644 |
--- a/third_party/WebKit/Source/modules/cachestorage/InspectorCacheStorageAgent.cpp |
+++ b/third_party/WebKit/Source/modules/cachestorage/InspectorCacheStorageAgent.cpp |
@@ -52,48 +52,44 @@ String buildCacheId(const String& securityOrigin, const String& cacheName) { |
return id; |
} |
-bool parseCacheId(ErrorString* errorString, |
- const String& id, |
- String* securityOrigin, |
- String* cacheName) { |
+Response parseCacheId(const String& id, |
+ String* securityOrigin, |
+ String* cacheName) { |
size_t pipe = id.find('|'); |
- if (pipe == WTF::kNotFound) { |
- *errorString = "Invalid cache id."; |
- return false; |
- } |
+ if (pipe == WTF::kNotFound) |
+ return Response::Error("Invalid cache id."); |
*securityOrigin = id.substring(0, pipe); |
*cacheName = id.substring(pipe + 1); |
- return true; |
+ return Response::OK(); |
} |
-std::unique_ptr<WebServiceWorkerCacheStorage> assertCacheStorage( |
- ErrorString* errorString, |
- const String& securityOrigin) { |
+Response assertCacheStorage( |
+ const String& securityOrigin, |
+ std::unique_ptr<WebServiceWorkerCacheStorage>& result) { |
RefPtr<SecurityOrigin> secOrigin = |
SecurityOrigin::createFromString(securityOrigin); |
// Cache Storage API is restricted to trustworthy origins. |
- if (!secOrigin->isPotentiallyTrustworthy()) { |
- *errorString = secOrigin->isPotentiallyTrustworthyErrorMessage(); |
- return nullptr; |
- } |
+ if (!secOrigin->isPotentiallyTrustworthy()) |
+ return Response::Error(secOrigin->isPotentiallyTrustworthyErrorMessage()); |
std::unique_ptr<WebServiceWorkerCacheStorage> cache = wrapUnique( |
Platform::current()->cacheStorage(WebSecurityOrigin(secOrigin))); |
if (!cache) |
- *errorString = "Could not find cache storage."; |
- return cache; |
+ return Response::Error("Could not find cache storage."); |
+ result = std::move(cache); |
+ return Response::OK(); |
} |
-std::unique_ptr<WebServiceWorkerCacheStorage> assertCacheStorageAndNameForId( |
- ErrorString* errorString, |
+Response assertCacheStorageAndNameForId( |
const String& cacheId, |
- String* cacheName) { |
+ String* cacheName, |
+ std::unique_ptr<WebServiceWorkerCacheStorage>& result) { |
String securityOrigin; |
- if (!parseCacheId(errorString, cacheId, &securityOrigin, cacheName)) { |
- return nullptr; |
- } |
- return assertCacheStorage(errorString, securityOrigin); |
+ Response response = parseCacheId(cacheId, &securityOrigin, cacheName); |
+ if (!response.isSuccess()) |
+ return response; |
+ return assertCacheStorage(securityOrigin, result); |
} |
CString serviceWorkerCacheErrorString(WebServiceWorkerCacheError error) { |
@@ -145,9 +141,9 @@ class RequestCacheNames |
} |
void onError(WebServiceWorkerCacheError error) override { |
- m_callback->sendFailure( |
+ m_callback->sendFailure(Response::Error( |
String::format("Error requesting cache names: %s", |
- serviceWorkerCacheErrorString(error).data())); |
+ serviceWorkerCacheErrorString(error).data()))); |
} |
private: |
@@ -216,7 +212,7 @@ class ResponsesAccumulator : public RefCounted<ResponsesAccumulator> { |
m_callback->sendSuccess(std::move(array), hasMore); |
} |
- void sendFailure(const String& error) { m_callback->sendFailure(error); } |
+ void sendFailure(const Response& error) { m_callback->sendFailure(error); } |
private: |
DataRequestParams m_params; |
@@ -241,10 +237,10 @@ class GetCacheResponsesForRequestData |
} |
void onError(WebServiceWorkerCacheError error) override { |
- m_accumulator->sendFailure( |
+ m_accumulator->sendFailure(Response::Error( |
String::format("Error requesting responses for cache %s: %s", |
m_params.cacheName.utf8().data(), |
- serviceWorkerCacheErrorString(error).data())); |
+ serviceWorkerCacheErrorString(error).data()))); |
} |
private: |
@@ -287,10 +283,10 @@ class GetCacheKeysForRequestData |
} |
void onError(WebServiceWorkerCacheError error) override { |
- m_callback->sendFailure( |
+ m_callback->sendFailure(Response::Error( |
String::format("Error requesting requests for cache %s: %s", |
m_params.cacheName.utf8().data(), |
- serviceWorkerCacheErrorString(error).data())); |
+ serviceWorkerCacheErrorString(error).data()))); |
} |
private: |
@@ -317,9 +313,9 @@ class GetCacheForRequestData |
} |
void onError(WebServiceWorkerCacheError error) override { |
- m_callback->sendFailure(String::format( |
+ m_callback->sendFailure(Response::Error(String::format( |
"Error requesting cache %s: %s", m_params.cacheName.utf8().data(), |
- serviceWorkerCacheErrorString(error).data())); |
+ serviceWorkerCacheErrorString(error).data()))); |
} |
private: |
@@ -338,9 +334,9 @@ class DeleteCache : public WebServiceWorkerCacheStorage::CacheStorageCallbacks { |
void onSuccess() override { m_callback->sendSuccess(); } |
void onError(WebServiceWorkerCacheError error) override { |
- m_callback->sendFailure( |
+ m_callback->sendFailure(Response::Error( |
String::format("Error requesting cache names: %s", |
- serviceWorkerCacheErrorString(error).data())); |
+ serviceWorkerCacheErrorString(error).data()))); |
} |
private: |
@@ -358,9 +354,9 @@ class DeleteCacheEntry : public WebServiceWorkerCache::CacheBatchCallbacks { |
void onSuccess() override { m_callback->sendSuccess(); } |
void onError(WebServiceWorkerCacheError error) override { |
- m_callback->sendFailure( |
+ m_callback->sendFailure(Response::Error( |
String::format("Error requesting cache names: %s", |
- serviceWorkerCacheErrorString(error).data())); |
+ serviceWorkerCacheErrorString(error).data()))); |
} |
private: |
@@ -392,9 +388,9 @@ class GetCacheForDeleteEntry |
} |
void onError(WebServiceWorkerCacheError error) override { |
- m_callback->sendFailure(String::format( |
+ m_callback->sendFailure(Response::Error(String::format( |
"Error requesting cache %s: %s", m_cacheName.utf8().data(), |
- serviceWorkerCacheErrorString(error).data())); |
+ serviceWorkerCacheErrorString(error).data()))); |
} |
private: |
@@ -427,11 +423,10 @@ void InspectorCacheStorageAgent::requestCacheNames( |
return; |
} |
- ErrorString errorString; |
- std::unique_ptr<WebServiceWorkerCacheStorage> cache = |
- assertCacheStorage(&errorString, securityOrigin); |
- if (!cache) { |
- callback->sendFailure(errorString); |
+ std::unique_ptr<WebServiceWorkerCacheStorage> cache; |
+ Response response = assertCacheStorage(securityOrigin, cache); |
+ if (!response.isSuccess()) { |
+ callback->sendFailure(response); |
return; |
} |
cache->dispatchKeys( |
@@ -443,12 +438,12 @@ void InspectorCacheStorageAgent::requestEntries( |
int skipCount, |
int pageSize, |
std::unique_ptr<RequestEntriesCallback> callback) { |
- ErrorString errorString; |
String cacheName; |
- std::unique_ptr<WebServiceWorkerCacheStorage> cache = |
- assertCacheStorageAndNameForId(&errorString, cacheId, &cacheName); |
- if (!cache) { |
- callback->sendFailure(errorString); |
+ std::unique_ptr<WebServiceWorkerCacheStorage> cache; |
+ Response response = |
+ assertCacheStorageAndNameForId(cacheId, &cacheName, cache); |
+ if (!response.isSuccess()) { |
+ callback->sendFailure(response); |
return; |
} |
DataRequestParams params; |
@@ -463,11 +458,11 @@ void InspectorCacheStorageAgent::deleteCache( |
const String& cacheId, |
std::unique_ptr<DeleteCacheCallback> callback) { |
String cacheName; |
- ErrorString errorString; |
- std::unique_ptr<WebServiceWorkerCacheStorage> cache = |
- assertCacheStorageAndNameForId(&errorString, cacheId, &cacheName); |
- if (!cache) { |
- callback->sendFailure(errorString); |
+ std::unique_ptr<WebServiceWorkerCacheStorage> cache; |
+ Response response = |
+ assertCacheStorageAndNameForId(cacheId, &cacheName, cache); |
+ if (!response.isSuccess()) { |
+ callback->sendFailure(response); |
return; |
} |
cache->dispatchDelete(new DeleteCache(std::move(callback)), |
@@ -479,11 +474,11 @@ void InspectorCacheStorageAgent::deleteEntry( |
const String& request, |
std::unique_ptr<DeleteEntryCallback> callback) { |
String cacheName; |
- ErrorString errorString; |
- std::unique_ptr<WebServiceWorkerCacheStorage> cache = |
- assertCacheStorageAndNameForId(&errorString, cacheId, &cacheName); |
- if (!cache) { |
- callback->sendFailure(errorString); |
+ std::unique_ptr<WebServiceWorkerCacheStorage> cache; |
+ Response response = |
+ assertCacheStorageAndNameForId(cacheId, &cacheName, cache); |
+ if (!response.isSuccess()) { |
+ callback->sendFailure(response); |
return; |
} |
cache->dispatchOpen( |