Chromium Code Reviews| Index: Source/modules/cachestorage/InspectorCacheStorageAgent.cpp |
| diff --git a/Source/modules/cachestorage/InspectorCacheStorageAgent.cpp b/Source/modules/cachestorage/InspectorCacheStorageAgent.cpp |
| index 61899800186c60f29cfcda7a8121e926331dd769..e071c56080ed0ef29038f89536dd85f8bc63fd8e 100644 |
| --- a/Source/modules/cachestorage/InspectorCacheStorageAgent.cpp |
| +++ b/Source/modules/cachestorage/InspectorCacheStorageAgent.cpp |
| @@ -7,10 +7,10 @@ |
| #include "core/InspectorBackendDispatcher.h" |
| #include "core/InspectorTypeBuilder.h" |
| -#include "modules/serviceworkers/ServiceWorkerGlobalScope.h" |
| #include "platform/JSONValues.h" |
| #include "platform/heap/Handle.h" |
| #include "platform/weborigin/DatabaseIdentifier.h" |
| +#include "platform/weborigin/SecurityOrigin.h" |
| #include "public/platform/Platform.h" |
| #include "public/platform/WebServiceWorkerCache.h" |
| #include "public/platform/WebServiceWorkerCacheError.h" |
| @@ -31,26 +31,46 @@ |
| #include <algorithm> |
| using blink::TypeBuilder::Array; |
| -using blink::TypeBuilder::ServiceWorkerCache::DataEntry; |
| +using blink::TypeBuilder::CacheStorage::Cache; |
| +using blink::TypeBuilder::CacheStorage::DataEntry; |
| -typedef blink::InspectorBackendDispatcher::ServiceWorkerCacheCommandHandler::DeleteCacheCallback DeleteCacheCallback; |
| -typedef blink::InspectorBackendDispatcher::ServiceWorkerCacheCommandHandler::RequestCacheNamesCallback RequestCacheNamesCallback; |
| -typedef blink::InspectorBackendDispatcher::ServiceWorkerCacheCommandHandler::RequestEntriesCallback RequestEntriesCallback; |
| +typedef blink::InspectorBackendDispatcher::CacheStorageCommandHandler::DeleteCacheCallback DeleteCacheCallback; |
| +typedef blink::InspectorBackendDispatcher::CacheStorageCommandHandler::RequestCacheNamesCallback RequestCacheNamesCallback; |
| +typedef blink::InspectorBackendDispatcher::CacheStorageCommandHandler::RequestEntriesCallback RequestEntriesCallback; |
| typedef blink::InspectorBackendDispatcher::CallbackBase RequestCallback; |
| namespace blink { |
| namespace { |
| -PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorage(ErrorString* errorString, ServiceWorkerGlobalScope* globalScope) |
| +String composeCacheId(const String& securityOrigin, const String& cacheName) |
|
pfeldman
2015/04/20 18:14:31
super nit: we typically use build* and parse*, but
dmurph
2015/04/20 20:58:17
Done.
|
| { |
| - String identifier = createDatabaseIdentifierFromSecurityOrigin(globalScope->securityOrigin()); |
| - OwnPtr<WebServiceWorkerCacheStorage> caches = adoptPtr(Platform::current()->cacheStorage(identifier)); |
| - if (!caches) { |
| - *errorString = "Cache Storage not available in global scope."; |
| - return nullptr; |
| + String id(securityOrigin); |
| + id.append("|"); |
| + id.append(cacheName); |
| + return id; |
| +} |
| + |
| +bool decomposeCacheId(ErrorString* errorString, const String& id, String* securityOrigin, String* cacheName) |
| +{ |
| + size_t pipe = id.find('|'); |
| + if (pipe == WTF::kNotFound) { |
| + *errorString = "Cannot find the | character to decompose the cache id"; |
|
pfeldman
2015/04/20 18:14:31
nit: you can just say that this was a poor id, no
dmurph
2015/04/20 20:58:17
Done.
|
| + return false; |
| } |
| - return caches.release(); |
| + *securityOrigin = id.substring(0, pipe); |
| + *cacheName = id.substring(pipe + 1); |
| + return true; |
| +} |
| + |
| +PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorage(ErrorString* errorString, const String& securityOrigin) |
| +{ |
| + RefPtr<SecurityOrigin> secOrigin = SecurityOrigin::createFromString(securityOrigin); |
| + String identifier = createDatabaseIdentifierFromSecurityOrigin(secOrigin.get()); |
| + WebServiceWorkerCacheStorage* cache = Platform::current()->cacheStorage(identifier); |
|
pfeldman
2015/04/20 18:14:31
Adopt right away, you'll still be able to check fo
dmurph
2015/04/20 20:58:17
Done.
|
| + if (!cache) |
| + *errorString = "Could not find cache storage."; |
| + return adoptPtr(cache); |
| } |
| CString serviceWorkerCacheErrorString(WebServiceWorkerCacheError* error) |
| @@ -76,8 +96,9 @@ class RequestCacheNames |
| WTF_MAKE_NONCOPYABLE(RequestCacheNames); |
| public: |
| - RequestCacheNames(PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> callback) |
| - : m_callback(callback) |
| + RequestCacheNames(const String& securityOrigin, PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> callback) |
| + : m_securityOrigin(securityOrigin) |
| + , m_callback(callback) |
| { |
| } |
| @@ -85,9 +106,14 @@ public: |
| void onSuccess(WebVector<WebString>* caches) |
| { |
| - RefPtr<TypeBuilder::Array<String>> array = TypeBuilder::Array<String>::create(); |
| + RefPtr<Array<Cache>> array = Array<Cache>::create(); |
| for (size_t i = 0; i < caches->size(); i++) { |
| - array->addItem(String((*caches)[i])); |
| + String name = String((*caches)[i]); |
| + RefPtr<Cache> entry = Cache::create() |
| + .setSecurityOrigin(m_securityOrigin) |
| + .setCacheName(name) |
| + .setCacheId(composeCacheId(m_securityOrigin, name)); |
| + array->addItem(entry); |
| } |
| m_callback->sendSuccess(array); |
| } |
| @@ -98,6 +124,7 @@ public: |
| } |
| private: |
| + String m_securityOrigin; |
| RefPtrWillBePersistent<RequestCacheNamesCallback> m_callback; |
| }; |
| @@ -152,7 +179,7 @@ public: |
| m_responses.remove(m_params.pageSize, m_responses.size() - m_params.pageSize); |
| hasMore = true; |
| } |
| - RefPtr<TypeBuilder::Array<DataEntry>> array = TypeBuilder::Array<DataEntry>::create(); |
| + RefPtr<Array<DataEntry>> array = Array<DataEntry>::create(); |
| for (const auto& requestResponse : m_responses) { |
| RefPtr<DataEntry> entry = DataEntry::create() |
| .setRequest(JSONString::create(requestResponse.request)->toJSONString()) |
| @@ -215,6 +242,11 @@ public: |
| void onSuccess(WebVector<WebServiceWorkerRequest>* requests) |
| { |
| + if (requests->isEmpty()) { |
| + RefPtr<Array<DataEntry>> array = Array<DataEntry>::create(); |
| + m_callback->sendSuccess(array, false); |
| + return; |
| + } |
| RefPtr<ResponsesAccumulator> accumulator = adoptRef(new ResponsesAccumulator(requests->size(), m_params, m_callback)); |
| for (size_t i = 0; i < requests->size(); i++) { |
| @@ -289,9 +321,8 @@ private: |
| } // namespace |
| -InspectorCacheStorageAgent::InspectorCacheStorageAgent(ServiceWorkerGlobalScope* scope) |
| - : InspectorBaseAgent<blink::InspectorCacheStorageAgent, InspectorFrontend::ServiceWorkerCache>("ServiceWorkerCache") |
| - , m_globalScope(scope) |
| +InspectorCacheStorageAgent::InspectorCacheStorageAgent() |
| + : InspectorBaseAgent<InspectorCacheStorageAgent, InspectorFrontend::CacheStorage>("CacheStorage") |
| { |
| } |
| @@ -302,20 +333,24 @@ DEFINE_TRACE(InspectorCacheStorageAgent) |
| InspectorBaseAgent::trace(visitor); |
| } |
| -void InspectorCacheStorageAgent::requestCacheNames(ErrorString* errorString, PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> callback) |
| +void InspectorCacheStorageAgent::requestCacheNames(ErrorString* errorString, const String& securityOrigin, PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> callback) |
| { |
| - OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, m_globalScope); |
| + OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, securityOrigin); |
| if (!cache) { |
| callback->sendFailure(*errorString); |
| return; |
| } |
| - cache->dispatchKeys(new RequestCacheNames(callback)); |
| + cache->dispatchKeys(new RequestCacheNames(securityOrigin, callback)); |
| } |
| - |
| -void InspectorCacheStorageAgent::requestEntries(ErrorString* errorString, const String& cacheName, int skipCount, int pageSize, PassRefPtrWillBeRawPtr<RequestEntriesCallback> callback) |
| +void InspectorCacheStorageAgent::requestEntries(ErrorString* errorString, const String& cacheId, int skipCount, int pageSize, PassRefPtrWillBeRawPtr<RequestEntriesCallback> callback) |
| { |
| - OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, m_globalScope); |
| + String securityOrigin, cacheName; |
|
pfeldman
2015/04/20 18:14:31
Declaration per line, please!
dmurph
2015/04/20 20:58:17
Done.
|
| + if (!decomposeCacheId(errorString, cacheId, &securityOrigin, &cacheName)) { |
| + callback->sendFailure(*errorString); |
| + return; |
| + } |
| + OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, securityOrigin); |
|
pfeldman
2015/04/20 18:14:31
Extract assertCacheStorageForId(errorString, cache
dmurph
2015/04/20 20:58:17
Done.
|
| if (!cache) { |
| callback->sendFailure(*errorString); |
| return; |
| @@ -327,9 +362,14 @@ void InspectorCacheStorageAgent::requestEntries(ErrorString* errorString, const |
| cache->dispatchOpen(new GetCacheForRequestData(params, callback), WebString(cacheName)); |
| } |
| -void InspectorCacheStorageAgent::deleteCache(ErrorString* errorString, const String& cacheName, PassRefPtrWillBeRawPtr<DeleteCacheCallback> callback) |
| +void InspectorCacheStorageAgent::deleteCache(ErrorString* errorString, const String& cacheId, PassRefPtrWillBeRawPtr<DeleteCacheCallback> callback) |
| { |
| - OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, m_globalScope); |
| + String securityOrigin, cacheName; |
| + if (!decomposeCacheId(errorString, cacheId, &securityOrigin, &cacheName)) { |
| + callback->sendFailure(*errorString); |
| + return; |
| + } |
| + OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, securityOrigin); |
| if (!cache) { |
| callback->sendFailure(*errorString); |
| return; |