Commit 960dc104 authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

Small cleanup: error generation in inspector cache storage agent.

.data() may not be \0 terminated; switching this to const char*
directly, no need to copy into std::string.

to call Latin1().c_str() on these cache name params.

String: :Format expects LATIN1 parameters, so I figure it's better
Change-Id: I516f335ae41d760db91a7bd45ac7fba3432ec502
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2049998Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740496}
parent 3857f11d
...@@ -150,32 +150,32 @@ ProtocolResponse AssertCacheStorageAndNameForId( ...@@ -150,32 +150,32 @@ ProtocolResponse AssertCacheStorageAndNameForId(
return AssertCacheStorage(security_origin, frames, caches, result); return AssertCacheStorage(security_origin, frames, caches, result);
} }
std::string CacheStorageErrorString(mojom::blink::CacheStorageError error) { const char* CacheStorageErrorString(mojom::blink::CacheStorageError error) {
switch (error) { switch (error) {
case mojom::blink::CacheStorageError::kErrorNotImplemented: case mojom::blink::CacheStorageError::kErrorNotImplemented:
return std::string("not implemented."); return "not implemented.";
case mojom::blink::CacheStorageError::kErrorNotFound: case mojom::blink::CacheStorageError::kErrorNotFound:
return std::string("not found."); return "not found.";
case mojom::blink::CacheStorageError::kErrorExists: case mojom::blink::CacheStorageError::kErrorExists:
return std::string("cache already exists."); return "cache already exists.";
case mojom::blink::CacheStorageError::kErrorQuotaExceeded: case mojom::blink::CacheStorageError::kErrorQuotaExceeded:
return std::string("quota exceeded."); return "quota exceeded.";
case mojom::blink::CacheStorageError::kErrorCacheNameNotFound: case mojom::blink::CacheStorageError::kErrorCacheNameNotFound:
return std::string("cache not found."); return "cache not found.";
case mojom::blink::CacheStorageError::kErrorQueryTooLarge: case mojom::blink::CacheStorageError::kErrorQueryTooLarge:
return std::string("operation too large."); return "operation too large.";
case mojom::blink::CacheStorageError::kErrorStorage: case mojom::blink::CacheStorageError::kErrorStorage:
return std::string("storage failure."); return "storage failure.";
case mojom::blink::CacheStorageError::kErrorDuplicateOperation: case mojom::blink::CacheStorageError::kErrorDuplicateOperation:
return std::string("duplicate operation."); return "duplicate operation.";
case mojom::blink::CacheStorageError::kErrorCrossOriginResourcePolicy: case mojom::blink::CacheStorageError::kErrorCrossOriginResourcePolicy:
return std::string("failed Cross-Origin-Resource-Policy check."); return "failed Cross-Origin-Resource-Policy check.";
case mojom::blink::CacheStorageError::kSuccess: case mojom::blink::CacheStorageError::kSuccess:
// This function should only be called upon error. // This function should only be called upon error.
break; break;
} }
NOTREACHED(); NOTREACHED();
return std::string(); return "";
} }
CachedResponseType ResponseTypeToString( CachedResponseType ResponseTypeToString(
...@@ -351,10 +351,9 @@ class ResponsesAccumulator : public RefCounted<ResponsesAccumulator> { ...@@ -351,10 +351,9 @@ class ResponsesAccumulator : public RefCounted<ResponsesAccumulator> {
} }
void SendFailure(const mojom::blink::CacheStorageError& error) { void SendFailure(const mojom::blink::CacheStorageError& error) {
callback_->sendFailure(ProtocolResponse::Error( callback_->sendFailure(ProtocolResponse::Error(String::Format(
String::Format("Error requesting responses for cache %s : %s", "Error requesting responses for cache %s : %s",
params_.cache_name.Utf8().c_str(), params_.cache_name.Latin1().c_str(), CacheStorageErrorString(error))));
CacheStorageErrorString(error).data())));
} }
std::unique_ptr<Array<Header>> SerializeHeaders( std::unique_ptr<Array<Header>> SerializeHeaders(
...@@ -407,8 +406,8 @@ class GetCacheKeysForRequestData { ...@@ -407,8 +406,8 @@ class GetCacheKeysForRequestData {
self->callback_->sendFailure( self->callback_->sendFailure(
ProtocolResponse::Error(String::Format( ProtocolResponse::Error(String::Format(
"Error requesting requests for cache %s: %s", "Error requesting requests for cache %s: %s",
params.cache_name.Utf8().c_str(), params.cache_name.Latin1().c_str(),
CacheStorageErrorString(result->get_status()).data()))); CacheStorageErrorString(result->get_status()))));
} else { } else {
if (result->get_keys().IsEmpty()) { if (result->get_keys().IsEmpty()) {
auto array = std::make_unique<protocol::Array<DataEntry>>(); auto array = std::make_unique<protocol::Array<DataEntry>>();
...@@ -585,8 +584,8 @@ void InspectorCacheStorageAgent::requestEntries( ...@@ -585,8 +584,8 @@ void InspectorCacheStorageAgent::requestEntries(
if (result->is_status()) { if (result->is_status()) {
callback->sendFailure(ProtocolResponse::Error(String::Format( callback->sendFailure(ProtocolResponse::Error(String::Format(
"Error requesting cache %s: %s", "Error requesting cache %s: %s",
params.cache_name.Utf8().c_str(), params.cache_name.Latin1().c_str(),
CacheStorageErrorString(result->get_status()).data()))); CacheStorageErrorString(result->get_status()))));
} else { } else {
auto request = std::make_unique<GetCacheKeysForRequestData>( auto request = std::make_unique<GetCacheKeysForRequestData>(
params, std::move(result->get_cache()), std::move(callback)); params, std::move(result->get_cache()), std::move(callback));
...@@ -623,7 +622,7 @@ void InspectorCacheStorageAgent::deleteCache( ...@@ -623,7 +622,7 @@ void InspectorCacheStorageAgent::deleteCache(
} else { } else {
callback->sendFailure(ProtocolResponse::Error( callback->sendFailure(ProtocolResponse::Error(
String::Format("Error requesting cache names: %s", String::Format("Error requesting cache names: %s",
CacheStorageErrorString(error).data()))); CacheStorageErrorString(error))));
} }
}, },
std::move(callback))); std::move(callback)));
...@@ -654,8 +653,8 @@ void InspectorCacheStorageAgent::deleteEntry( ...@@ -654,8 +653,8 @@ void InspectorCacheStorageAgent::deleteEntry(
mojom::blink::OpenResultPtr result) { mojom::blink::OpenResultPtr result) {
if (result->is_status()) { if (result->is_status()) {
callback->sendFailure(ProtocolResponse::Error(String::Format( callback->sendFailure(ProtocolResponse::Error(String::Format(
"Error requesting cache %s: %s", cache_name.Utf8().c_str(), "Error requesting cache %s: %s", cache_name.Latin1().c_str(),
CacheStorageErrorString(result->get_status()).data()))); CacheStorageErrorString(result->get_status()))));
} else { } else {
Vector<mojom::blink::BatchOperationPtr> batch_operations; Vector<mojom::blink::BatchOperationPtr> batch_operations;
batch_operations.push_back(mojom::blink::BatchOperation::New()); batch_operations.push_back(mojom::blink::BatchOperation::New());
...@@ -681,8 +680,7 @@ void InspectorCacheStorageAgent::deleteEntry( ...@@ -681,8 +680,7 @@ void InspectorCacheStorageAgent::deleteEntry(
callback->sendFailure( callback->sendFailure(
ProtocolResponse::Error(String::Format( ProtocolResponse::Error(String::Format(
"Error deleting cache entry: %s", "Error deleting cache entry: %s",
CacheStorageErrorString(error->value) CacheStorageErrorString(error->value))));
.data())));
} else { } else {
callback->sendSuccess(); callback->sendSuccess();
} }
...@@ -733,7 +731,7 @@ void InspectorCacheStorageAgent::requestCachedResponse( ...@@ -733,7 +731,7 @@ void InspectorCacheStorageAgent::requestCachedResponse(
if (result->is_status()) { if (result->is_status()) {
callback->sendFailure(ProtocolResponse::Error(String::Format( callback->sendFailure(ProtocolResponse::Error(String::Format(
"Unable to read cached response: %s", "Unable to read cached response: %s",
CacheStorageErrorString(result->get_status()).data()))); CacheStorageErrorString(result->get_status()))));
} else { } else {
std::unique_ptr<protocol::DictionaryValue> headers = std::unique_ptr<protocol::DictionaryValue> headers =
protocol::DictionaryValue::create(); protocol::DictionaryValue::create();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment