Chromium Code Reviews| Index: content/renderer/service_worker/service_worker_cache_storage_dispatcher.cc |
| diff --git a/content/renderer/service_worker/service_worker_cache_storage_dispatcher.cc b/content/renderer/service_worker/service_worker_cache_storage_dispatcher.cc |
| index 750713ca032aae249b9070cdf690728a5fff1f00..0335a762d7dc448bdc6a63fb984efbd811029434 100644 |
| --- a/content/renderer/service_worker/service_worker_cache_storage_dispatcher.cc |
| +++ b/content/renderer/service_worker/service_worker_cache_storage_dispatcher.cc |
| @@ -4,15 +4,142 @@ |
| #include "content/renderer/service_worker/service_worker_cache_storage_dispatcher.h" |
| +#include <map> |
| +#include <string> |
| +#include <utility> |
| + |
| #include "base/logging.h" |
| +#include "base/strings/utf_string_conversions.h" |
| #include "content/common/service_worker/service_worker_messages.h" |
| #include "content/public/renderer/render_thread.h" |
| #include "content/renderer/service_worker/service_worker_script_context.h" |
| +#include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" |
| +#include "third_party/WebKit/public/platform/WebServiceWorkerCache.h" |
| +#include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" |
| +#include "third_party/WebKit/public/platform/WebServiceWorkerResponse.h" |
| namespace content { |
| +using blink::WebServiceWorkerCacheError; |
| +using blink::WebServiceWorkerRequest; |
| + |
| namespace { |
| +class StringMapHTTPHeaderVisitor : public blink::WebHTTPHeaderVisitor { |
|
dominicc (has gone to gerrit)
2014/08/15 06:48:35
I wonder if this is the best name? A BirthdayCake
gavinp
2014/09/03 18:35:24
Done.
|
| + public: |
| + StringMapHTTPHeaderVisitor(std::map<std::string, std::string>* string_map) |
| + : string_map_(string_map) {} |
| + virtual ~StringMapHTTPHeaderVisitor() {} |
| + |
| + virtual void visitHeader(const blink::WebString& name, |
| + const blink::WebString& value) { |
| + string_map_->insert( |
| + std::map<std::string, std::string>::value_type( |
| + base::UTF16ToASCII(name), base::UTF16ToASCII(value))); |
| + } |
| + |
| + private: |
| + std::map<std::string, std::string>* string_map_; |
| +}; |
| + |
| +scoped_ptr<StringMapHTTPHeaderVisitor> MakeStringMapHTTPHeaderVisitor( |
| + std::map<std::string, std::string>* string_map) { |
| + return scoped_ptr<StringMapHTTPHeaderVisitor>( |
| + new StringMapHTTPHeaderVisitor(string_map)).Pass(); |
| +} |
| + |
| +ServiceWorkerFetchRequest FetchRequestFromWebRequest( |
| + const blink::WebServiceWorkerRequest& web_request) { |
| + |
| + std::map<std::string, std::string> headers; |
| + web_request.visitHTTPHeaderFields( |
| + MakeStringMapHTTPHeaderVisitor(&headers).get()); |
| + |
| + return ServiceWorkerFetchRequest(web_request.url(), |
| + base::UTF16ToASCII(web_request.method()), |
| + headers, web_request.referrerUrl(), |
| + web_request.isReload()); |
| +} |
| + |
| +void PopulateWebRequestFromFetchRequest( |
| + const ServiceWorkerFetchRequest& request, |
| + blink::WebServiceWorkerRequest* web_request) { |
| + web_request->setURL(request.url); |
| + web_request->setMethod(base::ASCIIToUTF16(request.method)); |
| + for (std::map<std::string, std::string>::const_iterator |
| + i = request.headers.begin(), end = request.headers.end(); |
| + i != end; ++i) { |
| + web_request->setHeader(base::ASCIIToUTF16(i->first), |
| + base::ASCIIToUTF16(i->second)); |
| + } |
| + web_request->setReferrer(base::ASCIIToUTF16(request.referrer.spec()), |
| + blink::WebReferrerPolicy::WebReferrerPolicyNever); |
| + web_request->setIsReload(request.is_reload); |
| +} |
| + |
| +ServiceWorkerResponse ResponseFromWebResponse( |
| + const blink::WebServiceWorkerResponse& web_response) { |
| + std::map<std::string, std::string> headers; |
| + web_response.visitHTTPHeaderFields( |
| + MakeStringMapHTTPHeaderVisitor(&headers).get()); |
| + |
| + return ServiceWorkerResponse( |
| + web_response.url(), web_response.status(), |
| + base::UTF16ToASCII(web_response.statusText()), headers, |
| + base::UTF16ToASCII(web_response.blobUUID())); |
| +} |
| + |
| +void PopulateWebResponseFromResponse( |
| + const ServiceWorkerResponse& response, |
| + blink::WebServiceWorkerResponse* web_response) { |
| + web_response->setURL(response.url); |
| + web_response->setStatus(response.status_code); |
| + web_response->setStatusText(base::ASCIIToUTF16(response.status_text)); |
| + for (std::map<std::string, std::string>::const_iterator |
| + i = response.headers.begin(), end = response.headers.end(); |
| + i != end; ++i) { |
| + web_response->setHeader(base::ASCIIToUTF16(i->first), |
| + base::ASCIIToUTF16(i->second)); |
| + } |
| + // TODO(gavinp): set blob here. |
| +} |
| + |
| +ServiceWorkerCacheQueryParams QueryParamsFromWebQueryParams( |
| + const blink::WebServiceWorkerCache::QueryParams& web_query_params) { |
| + ServiceWorkerCacheQueryParams query_params; |
| + query_params.ignore_search = web_query_params.ignoreSearch; |
| + query_params.ignore_method = web_query_params.ignoreMethod; |
| + query_params.ignore_vary = web_query_params.ignoreVary; |
| + query_params.prefix_match = web_query_params.prefixMatch; |
| + |
| + return query_params; |
| +} |
| + |
| +ServiceWorkerCacheOperationType CacheOperationTypeFromWebCacheOperationType( |
| + const blink::WebServiceWorkerCache:: |
| + WebServiceWorkerCacheOperationType& operation_type) { |
| + switch (operation_type) { |
| + case blink::WebServiceWorkerCache::WebServiceWorkerCacheOperationTypePut: |
| + return SERVICE_WORKER_CACHE_OPERATION_TYPE_PUT; |
| + case blink::WebServiceWorkerCache::WebServiceWorkerCacheOperationTypeDelete: |
| + return SERVICE_WORKER_CACHE_OPERATION_TYPE_DELETE; |
| + default: |
| + return SERVICE_WORKER_CACHE_OPERATION_TYPE_UNDEFINED; |
| + } |
| +} |
| + |
|
dominicc (has gone to gerrit)
2014/08/15 06:48:35
I'm sad at this point that browser can not dabble
gavinp
2014/09/03 18:35:25
You can, provided that the enumeration is defined
|
| +ServiceWorkerBatchOperation BatchOperationFromWebBatchOperation( |
| + const blink::WebServiceWorkerCache::BatchOperation& web_operation) { |
| + ServiceWorkerBatchOperation operation; |
| + operation.operation_type = |
| + CacheOperationTypeFromWebCacheOperationType(web_operation.operationType); |
| + operation.request = FetchRequestFromWebRequest(web_operation.request); |
| + operation.response = ResponseFromWebResponse(web_operation.response); |
| + operation.match_params = |
| + QueryParamsFromWebQueryParams(web_operation.matchParams); |
| + return operation; |
| +} |
| + |
| template<typename T> |
| void ClearCallbacksMapWithErrors(T* callbacks_map) { |
| typename T::iterator iter(callbacks_map); |
| @@ -27,6 +154,48 @@ void ClearCallbacksMapWithErrors(T* callbacks_map) { |
| } // namespace |
| +// The WebCache object is the chrome side implementation of the blink |
|
dominicc (has gone to gerrit)
2014/08/15 06:48:35
chrome -> Chrome or Chromium
blink -> Blink
gavinp
2014/09/03 18:35:25
Done.
|
| +// WebServiceWorkerCache API. Most of its methods delegate directly to the |
| +// ServiceWorkerStorage object, which is able to assign unique IDs as well |
| +// as have a lifetime longer than the requests. |
| +class ServiceWorkerCacheStorageDispatcher::WebCache |
| + : public blink::WebServiceWorkerCache { |
| + public: |
| + WebCache(ServiceWorkerCacheStorageDispatcher* dispatcher, int cache_id) |
| + : dispatcher_(dispatcher), cache_id_(cache_id) {} |
| + |
| + // From blink::WebServiceWorkerCache: |
| + virtual void dispatchMatch(CacheMatchCallbacks* callbacks, |
| + const blink::WebServiceWorkerRequest& request, |
| + const QueryParams& query_params) { |
| + dispatcher_->dispatchMatchForCache(cache_id_, callbacks, request, |
| + query_params); |
| + } |
| + virtual void dispatchMatchAll(CacheWithResponsesCallbacks* callbacks, |
| + const blink::WebServiceWorkerRequest& request, |
| + const QueryParams& query_params) { |
| + dispatcher_->dispatchMatchAllForCache(cache_id_, callbacks, request, |
| + query_params); |
| + } |
| + virtual void dispatchKeys(CacheWithRequestsCallbacks* callbacks, |
| + const blink::WebServiceWorkerRequest* request, |
| + const QueryParams& query_params) { |
| + dispatcher_->dispatchKeysForCache(cache_id_, callbacks, request, |
| + query_params); |
| + } |
| + virtual void dispatchBatch( |
| + CacheWithResponsesCallbacks* callbacks, |
| + const blink::WebVector<BatchOperation>& batch_operations) { |
| + dispatcher_->dispatchBatchForCache(cache_id_, callbacks, batch_operations); |
| + } |
| + |
| + private: |
| + // Not owned. Pointer to a dispatcher to use for sending events. |
|
dominicc (has gone to gerrit)
2014/08/15 06:48:35
What's the disengagement protocol? Because I thoug
gavinp
2014/09/03 18:35:25
It is. Its destructor is called by Blink when the
|
| + ServiceWorkerCacheStorageDispatcher* dispatcher_; |
| + |
| + const int cache_id_; |
| +}; |
| + |
| ServiceWorkerCacheStorageDispatcher::ServiceWorkerCacheStorageDispatcher( |
| ServiceWorkerScriptContext* script_context) |
| : script_context_(script_context) {} |
| @@ -37,32 +206,53 @@ ServiceWorkerCacheStorageDispatcher::~ServiceWorkerCacheStorageDispatcher() { |
| ClearCallbacksMapWithErrors(&create_callbacks_); |
| ClearCallbacksMapWithErrors(&delete_callbacks_); |
| ClearCallbacksMapWithErrors(&keys_callbacks_); |
| + |
| + ClearCallbacksMapWithErrors(&cache_match_callbacks_); |
| + ClearCallbacksMapWithErrors(&cache_match_all_callbacks_); |
| + ClearCallbacksMapWithErrors(&cache_keys_callbacks_); |
| + ClearCallbacksMapWithErrors(&cache_batch_callbacks_); |
| } |
| bool ServiceWorkerCacheStorageDispatcher::OnMessageReceived( |
| const IPC::Message& message) { |
| bool handled = true; |
| IPC_BEGIN_MESSAGE_MAP(ServiceWorkerCacheStorageDispatcher, message) |
| - IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageGetSuccess, |
| - OnCacheStorageGetSuccess) |
| - IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageHasSuccess, |
| - OnCacheStorageHasSuccess) |
| - IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageCreateSuccess, |
| - OnCacheStorageCreateSuccess) |
| - IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageDeleteSuccess, |
| - OnCacheStorageDeleteSuccess) |
| - IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageKeysSuccess, |
| - OnCacheStorageKeysSuccess) |
| - IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageGetError, |
| - OnCacheStorageGetError) |
| - IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageHasError, |
| - OnCacheStorageHasError) |
| - IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageCreateError, |
| - OnCacheStorageCreateError) |
| - IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageDeleteError, |
| - OnCacheStorageDeleteError) |
| - IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageKeysError, |
| - OnCacheStorageKeysError) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageGetSuccess, |
| + OnCacheStorageGetSuccess) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageHasSuccess, |
| + OnCacheStorageHasSuccess) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageCreateSuccess, |
| + OnCacheStorageCreateSuccess) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageDeleteSuccess, |
| + OnCacheStorageDeleteSuccess) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageKeysSuccess, |
| + OnCacheStorageKeysSuccess) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageGetError, |
| + OnCacheStorageGetError) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageHasError, |
| + OnCacheStorageHasError) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageCreateError, |
| + OnCacheStorageCreateError) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageDeleteError, |
| + OnCacheStorageDeleteError) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageKeysError, |
| + OnCacheStorageKeysError) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheMatchSuccess, |
| + OnCacheMatchSuccess) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheMatchAllSuccess, |
| + OnCacheMatchAllSuccess) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheKeysSuccess, |
| + OnCacheKeysSuccess) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheBatchSuccess, |
| + OnCacheBatchSuccess) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheMatchError, |
| + OnCacheMatchError) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheMatchAllError, |
| + OnCacheMatchAllError) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheKeysError, |
| + OnCacheKeysError) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheBatchError, |
| + OnCacheBatchError) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| @@ -74,16 +264,20 @@ void ServiceWorkerCacheStorageDispatcher::OnCacheStorageGetSuccess( |
| int cache_id) { |
| CacheStorageWithCacheCallbacks* callbacks = |
| get_callbacks_.Lookup(request_id); |
| - DCHECK(callbacks); |
| - callbacks->onSuccess(NULL); |
| + |
| + WebCache* web_cache = web_caches_.Lookup(cache_id); |
| + if (!web_cache) { |
| + WebCache* web_cache = new WebCache(this, cache_id); |
| + web_caches_.AddWithID(web_cache, cache_id); |
| + } |
| + callbacks->onSuccess(web_cache); |
| get_callbacks_.Remove(request_id); |
| } |
| void ServiceWorkerCacheStorageDispatcher::OnCacheStorageHasSuccess( |
| int request_id) { |
| CacheStorageCallbacks* callbacks = has_callbacks_.Lookup(request_id); |
| - DCHECK(callbacks); |
| - callbacks->onSuccess(); |
| + callbacks->onSuccess(); |
| has_callbacks_.Remove(request_id); |
| } |
| @@ -92,15 +286,19 @@ void ServiceWorkerCacheStorageDispatcher::OnCacheStorageCreateSuccess( |
| int cache_id) { |
| CacheStorageWithCacheCallbacks* callbacks = |
| create_callbacks_.Lookup(request_id); |
| - DCHECK(callbacks); |
| - callbacks->onSuccess(NULL); |
| + |
| + WebCache* web_cache = web_caches_.Lookup(cache_id); |
| + if (!web_cache) { |
| + WebCache* web_cache = new WebCache(this, cache_id); |
| + web_caches_.AddWithID(web_cache, cache_id); |
| + } |
| + callbacks->onSuccess(web_cache); |
| create_callbacks_.Remove(request_id); |
| } |
| void ServiceWorkerCacheStorageDispatcher::OnCacheStorageDeleteSuccess( |
| int request_id) { |
| CacheStorageCallbacks* callbacks = delete_callbacks_.Lookup(request_id); |
| - DCHECK(callbacks); |
| callbacks->onSuccess(); |
| delete_callbacks_.Remove(request_id); |
| } |
| @@ -109,7 +307,6 @@ void ServiceWorkerCacheStorageDispatcher::OnCacheStorageKeysSuccess( |
| int request_id, |
| const std::vector<base::string16>& keys) { |
| CacheStorageKeysCallbacks* callbacks = keys_callbacks_.Lookup(request_id); |
| - DCHECK(callbacks); |
| blink::WebVector<blink::WebString> webKeys(keys.size()); |
| for (size_t i = 0; i < keys.size(); ++i) |
| webKeys[i] = keys[i]; |
| @@ -123,7 +320,6 @@ void ServiceWorkerCacheStorageDispatcher::OnCacheStorageGetError( |
| blink::WebServiceWorkerCacheError reason) { |
| CacheStorageWithCacheCallbacks* callbacks = |
| get_callbacks_.Lookup(request_id); |
| - DCHECK(callbacks); |
| callbacks->onError(&reason); |
| get_callbacks_.Remove(request_id); |
| } |
| @@ -132,7 +328,6 @@ void ServiceWorkerCacheStorageDispatcher::OnCacheStorageHasError( |
| int request_id, |
| blink::WebServiceWorkerCacheError reason) { |
| CacheStorageCallbacks* callbacks = has_callbacks_.Lookup(request_id); |
| - DCHECK(callbacks); |
| callbacks->onError(&reason); |
| has_callbacks_.Remove(request_id); |
| } |
| @@ -142,7 +337,6 @@ void ServiceWorkerCacheStorageDispatcher::OnCacheStorageCreateError( |
| blink::WebServiceWorkerCacheError reason) { |
| CacheStorageWithCacheCallbacks* callbacks = |
| create_callbacks_.Lookup(request_id); |
| - DCHECK(callbacks); |
| callbacks->onError(&reason); |
| create_callbacks_.Remove(request_id); |
| } |
| @@ -151,7 +345,6 @@ void ServiceWorkerCacheStorageDispatcher::OnCacheStorageDeleteError( |
| int request_id, |
| blink::WebServiceWorkerCacheError reason) { |
| CacheStorageCallbacks* callbacks = delete_callbacks_.Lookup(request_id); |
| - DCHECK(callbacks); |
| callbacks->onError(&reason); |
| delete_callbacks_.Remove(request_id); |
| } |
| @@ -160,11 +353,102 @@ void ServiceWorkerCacheStorageDispatcher::OnCacheStorageKeysError( |
| int request_id, |
| blink::WebServiceWorkerCacheError reason) { |
| CacheStorageKeysCallbacks* callbacks = keys_callbacks_.Lookup(request_id); |
| - DCHECK(callbacks); |
| callbacks->onError(&reason); |
| keys_callbacks_.Remove(request_id); |
| } |
| +void ServiceWorkerCacheStorageDispatcher::OnCacheMatchSuccess( |
| + int request_id, |
| + const ServiceWorkerResponse& response) { |
| + blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks = |
| + cache_match_callbacks_.Lookup(request_id); |
| + |
| + blink::WebServiceWorkerResponse web_response; |
| + PopulateWebResponseFromResponse(response, &web_response); |
| + callbacks->onSuccess(&web_response); |
| + cache_match_callbacks_.Remove(request_id); |
| +} |
| + |
| +void ServiceWorkerCacheStorageDispatcher::OnCacheMatchAllSuccess( |
| + int request_id, |
| + const std::vector<ServiceWorkerResponse>& responses) { |
| + blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks = |
| + cache_match_all_callbacks_.Lookup(request_id); |
| + |
| + blink::WebVector<blink::WebServiceWorkerResponse> |
| + web_responses(responses.size()); |
| + for (size_t i = 0; i < responses.size(); ++i) |
|
dominicc (has gone to gerrit)
2014/08/15 06:48:35
Seems you could have a helper for this; it happens
gavinp
2014/09/03 18:35:25
I think it's just twice for responses and once for
|
| + PopulateWebResponseFromResponse(responses[i], &(web_responses[i])); |
| + callbacks->onSuccess(&web_responses); |
| + cache_match_all_callbacks_.Remove(request_id); |
| +} |
| + |
| +void ServiceWorkerCacheStorageDispatcher::OnCacheKeysSuccess( |
| + |
| + int request_id, |
| + const std::vector<ServiceWorkerFetchRequest>& requests) { |
| + blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks = |
| + cache_keys_callbacks_.Lookup(request_id); |
| + |
| + blink::WebVector<blink::WebServiceWorkerRequest> |
| + web_requests(requests.size()); |
| + for (size_t i = 0; i < requests.size(); ++i) |
| + PopulateWebRequestFromFetchRequest(requests[i], &(web_requests[i])); |
| + callbacks->onSuccess(&web_requests); |
| + |
|
dominicc (has gone to gerrit)
2014/08/15 06:48:35
There's some inconsistency here wrt vertical white
gavinp
2014/09/03 18:35:25
Done.
|
| + cache_keys_callbacks_.Remove(request_id); |
| +} |
| + |
| +void ServiceWorkerCacheStorageDispatcher::OnCacheBatchSuccess( |
| + int request_id, |
| + const std::vector<ServiceWorkerResponse>& responses) { |
| + blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks = |
| + cache_batch_callbacks_.Lookup(request_id); |
| + |
| + blink::WebVector<blink::WebServiceWorkerResponse> |
| + web_responses(responses.size()); |
| + for (size_t i = 0; i < responses.size(); ++i) |
| + PopulateWebResponseFromResponse(responses[i], &(web_responses[i])); |
| + callbacks->onSuccess(&web_responses); |
| + cache_batch_callbacks_.Remove(request_id); |
| +} |
| + |
| +void ServiceWorkerCacheStorageDispatcher::OnCacheMatchError( |
| + int request_id, |
| + blink::WebServiceWorkerCacheError reason) { |
| + blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks = |
| + cache_match_callbacks_.Lookup(request_id); |
| + callbacks->onError(&reason); |
| + cache_match_callbacks_.Remove(request_id); |
| +} |
| + |
| +void ServiceWorkerCacheStorageDispatcher::OnCacheMatchAllError( |
| + int request_id, |
| + blink::WebServiceWorkerCacheError reason) { |
| + blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks = |
| + cache_match_all_callbacks_.Lookup(request_id); |
| + callbacks->onError(&reason); |
| + cache_match_all_callbacks_.Remove(request_id); |
| +} |
| + |
| +void ServiceWorkerCacheStorageDispatcher::OnCacheKeysError( |
| + int request_id, |
| + blink::WebServiceWorkerCacheError reason) { |
| + blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks = |
| + cache_keys_callbacks_.Lookup(request_id); |
| + callbacks->onError(&reason); |
| + cache_keys_callbacks_.Remove(request_id); |
| +} |
| + |
| +void ServiceWorkerCacheStorageDispatcher::OnCacheBatchError( |
| + int request_id, |
| + blink::WebServiceWorkerCacheError reason) { |
| + blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks = |
| + cache_batch_callbacks_.Lookup(request_id); |
| + callbacks->onError(&reason); |
| + cache_batch_callbacks_.Remove(request_id); |
| +} |
| + |
| void ServiceWorkerCacheStorageDispatcher::dispatchGet( |
| CacheStorageWithCacheCallbacks* callbacks, |
| const blink::WebString& cacheName) { |
| @@ -176,7 +460,7 @@ void ServiceWorkerCacheStorageDispatcher::dispatchGet( |
| void ServiceWorkerCacheStorageDispatcher::dispatchHas( |
| CacheStorageCallbacks* callbacks, |
| const blink::WebString& cacheName) { |
| - int request_id = delete_callbacks_.Add(callbacks); |
| + int request_id = has_callbacks_.Add(callbacks); |
|
dominicc (has gone to gerrit)
2014/08/15 06:48:35
Would be nice if this kind of error was unpossible
gavinp
2014/09/03 18:35:25
Static type incompatibility seems the way to go, s
|
| script_context_->Send(new ServiceWorkerHostMsg_CacheStorageDelete( |
| script_context_->GetRoutingID(), request_id, cacheName)); |
| } |
| @@ -204,4 +488,62 @@ void ServiceWorkerCacheStorageDispatcher::dispatchKeys( |
| script_context_->GetRoutingID(), request_id)); |
| } |
| +void ServiceWorkerCacheStorageDispatcher::dispatchMatchForCache( |
| + int cache_id, |
| + blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks, |
| + const blink::WebServiceWorkerRequest& request, |
| + const blink::WebServiceWorkerCache::QueryParams& query_params) { |
| + int request_id = cache_match_callbacks_.Add(callbacks); |
| + |
| + script_context_->Send(new ServiceWorkerHostMsg_CacheMatch( |
| + script_context_->GetRoutingID(), request_id, cache_id, |
| + FetchRequestFromWebRequest(request), |
| + QueryParamsFromWebQueryParams(query_params))); |
| +} |
| + |
| +void ServiceWorkerCacheStorageDispatcher::dispatchMatchAllForCache( |
| + int cache_id, |
| + blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks, |
| + const blink::WebServiceWorkerRequest& request, |
| + const blink::WebServiceWorkerCache::QueryParams& query_params) { |
| + int request_id = cache_match_all_callbacks_.Add(callbacks); |
| + |
| + script_context_->Send(new ServiceWorkerHostMsg_CacheMatchAll( |
| + script_context_->GetRoutingID(), request_id, cache_id, |
| + FetchRequestFromWebRequest(request), |
| + QueryParamsFromWebQueryParams(query_params))); |
| +} |
| + |
| +void ServiceWorkerCacheStorageDispatcher::dispatchKeysForCache( |
| + int cache_id, |
| + blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks, |
| + const blink::WebServiceWorkerRequest* request, |
| + const blink::WebServiceWorkerCache::QueryParams& query_params) { |
| + int request_id = cache_keys_callbacks_.Add(callbacks); |
| + |
| + script_context_->Send(new ServiceWorkerHostMsg_CacheKeys( |
| + script_context_->GetRoutingID(), request_id, cache_id, |
| + request ? FetchRequestFromWebRequest(*request) |
| + : ServiceWorkerFetchRequest(), |
| + QueryParamsFromWebQueryParams(query_params))); |
| +} |
| + |
| +void ServiceWorkerCacheStorageDispatcher::dispatchBatchForCache( |
| + int cache_id, |
| + blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks, |
| + const blink::WebVector< |
| + blink::WebServiceWorkerCache::BatchOperation>& web_operations) { |
| + int request_id = cache_batch_callbacks_.Add(callbacks); |
| + |
| + std::vector<ServiceWorkerBatchOperation> operations; |
| + operations.reserve(web_operations.size()); |
| + for (size_t i = 0; i < web_operations.size(); ++i) { |
| + operations.push_back( |
| + BatchOperationFromWebBatchOperation(web_operations[i])); |
| + } |
| + |
| + script_context_->Send(new ServiceWorkerHostMsg_CacheBatch( |
| + script_context_->GetRoutingID(), request_id, cache_id, operations)); |
| +} |
| + |
| } // namespace content |