Commit 203f6295 authored by gavinp's avatar gavinp Committed by Commit bot

content::WebServiceWorkerCache implementation.

The WebCache object itself is created by the
ServiceWorkerCacheStorageDispatcher, which also handles much of its
messaging for lifetime reasons, since a cache operation can outlive
its WebServiceWorkerCache object.

R=falken@chromium.org,jkarlin@chromium.org
BUG=None

Review URL: https://codereview.chromium.org/474593002

Cr-Commit-Position: refs/heads/master@{#296726}
parent 2eee6cb9
......@@ -72,6 +72,16 @@ bool ServiceWorkerCacheListener::OnMessageReceived(
OnCacheStorageDelete)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheStorageKeys,
OnCacheStorageKeys)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheMatch,
OnCacheMatch)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheMatchAll,
OnCacheMatchAll)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheKeys,
OnCacheKeys)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheBatch,
OnCacheBatch)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheClosed,
OnCacheClosed)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
......@@ -140,6 +150,49 @@ void ServiceWorkerCacheListener::OnCacheStorageKeys(int request_id) {
request_id));
}
void ServiceWorkerCacheListener::OnCacheMatch(
int request_id,
int cache_id,
const ServiceWorkerFetchRequest& request,
const ServiceWorkerCacheQueryParams& match_params) {
// TODO(gavinp,jkarlin): Implement this method.
Send(ServiceWorkerMsg_CacheMatchError(
request_id, blink::WebServiceWorkerCacheErrorNotImplemented));
}
void ServiceWorkerCacheListener::OnCacheMatchAll(
int request_id,
int cache_id,
const ServiceWorkerFetchRequest& request,
const ServiceWorkerCacheQueryParams& match_params) {
// TODO(gavinp,jkarlin): Implement this method.
Send(ServiceWorkerMsg_CacheMatchAllError(
request_id, blink::WebServiceWorkerCacheErrorNotImplemented));
}
void ServiceWorkerCacheListener::OnCacheKeys(
int request_id,
int cache_id,
const ServiceWorkerFetchRequest& request,
const ServiceWorkerCacheQueryParams& match_params) {
// TODO(gavinp,jkarlin): Implement this method.
Send(ServiceWorkerMsg_CacheKeysError(
request_id, blink::WebServiceWorkerCacheErrorNotImplemented));
}
void ServiceWorkerCacheListener::OnCacheBatch(
int request_id,
int cache_id,
const std::vector<ServiceWorkerBatchOperation>& operations) {
// TODO(gavinp,jkarlin): Implement this method.
Send(ServiceWorkerMsg_CacheBatchError(
request_id, blink::WebServiceWorkerCacheErrorNotImplemented));
}
void ServiceWorkerCacheListener::OnCacheClosed(int cache_id) {
// TODO(gavinp,jkarlin): Implement this method.
}
void ServiceWorkerCacheListener::Send(const IPC::Message& message) {
version_->embedded_worker()->SendMessage(message);
}
......
......@@ -12,6 +12,9 @@
namespace content {
struct ServiceWorkerBatchOperation;
struct ServiceWorkerCacheQueryParams;
struct ServiceWorkerFetchRequest;
class ServiceWorkerVersion;
// This class listens for requests on the Cache APIs, and sends response
......@@ -26,7 +29,8 @@ class ServiceWorkerCacheListener : public EmbeddedWorkerInstance::Listener {
// From EmbeddedWorkerInstance::Listener:
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
// Message receiver functions for CacheStorage API.
private:
// The message receiver functions for the CacheStorage API:
void OnCacheStorageGet(int request_id, const base::string16& cache_name);
void OnCacheStorageHas(int request_id, const base::string16& cache_name);
void OnCacheStorageCreate(int request_id,
......@@ -35,8 +39,23 @@ class ServiceWorkerCacheListener : public EmbeddedWorkerInstance::Listener {
const base::string16& cache_name);
void OnCacheStorageKeys(int request_id);
// TODO(gavinp,jkarlin): Plumb a message up from the renderer saying that the
// renderer is done with a cache id.
// The message receiver functions for the Cache API:
void OnCacheMatch(int request_id,
int cache_id,
const ServiceWorkerFetchRequest& request,
const ServiceWorkerCacheQueryParams& match_params);
void OnCacheMatchAll(int request_id,
int cache_id,
const ServiceWorkerFetchRequest& request,
const ServiceWorkerCacheQueryParams& match_params);
void OnCacheKeys(int request_id,
int cache_id,
const ServiceWorkerFetchRequest& request,
const ServiceWorkerCacheQueryParams& match_params);
void OnCacheBatch(int request_id,
int cache_id,
const std::vector<ServiceWorkerBatchOperation>& operations);
void OnCacheClosed(int cache_id);
private:
typedef int32_t CacheID; // TODO(jkarlin): Bump to 64 bit.
......
......@@ -52,6 +52,23 @@ IPC_STRUCT_TRAITS_BEGIN(content::ServiceWorkerResponse)
IPC_STRUCT_TRAITS_MEMBER(blob_uuid)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(content::ServiceWorkerCacheQueryParams)
IPC_STRUCT_TRAITS_MEMBER(ignore_search)
IPC_STRUCT_TRAITS_MEMBER(ignore_method)
IPC_STRUCT_TRAITS_MEMBER(ignore_vary)
IPC_STRUCT_TRAITS_MEMBER(prefix_match)
IPC_STRUCT_TRAITS_END()
IPC_ENUM_TRAITS_MAX_VALUE(content::ServiceWorkerCacheOperationType,
content::SERVICE_WORKER_CACHE_OPERATION_TYPE_LAST)
IPC_STRUCT_TRAITS_BEGIN(content::ServiceWorkerBatchOperation)
IPC_STRUCT_TRAITS_MEMBER(operation_type)
IPC_STRUCT_TRAITS_MEMBER(request)
IPC_STRUCT_TRAITS_MEMBER(response)
IPC_STRUCT_TRAITS_MEMBER(match_params)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(content::ServiceWorkerObjectInfo)
IPC_STRUCT_TRAITS_MEMBER(handle_id)
IPC_STRUCT_TRAITS_MEMBER(scope)
......@@ -182,6 +199,33 @@ IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_CacheStorageDelete,
IPC_MESSAGE_ROUTED1(ServiceWorkerHostMsg_CacheStorageKeys,
int /* request_id */)
// Cache operations in the browser.
IPC_MESSAGE_ROUTED4(ServiceWorkerHostMsg_CacheMatch,
int /* request_id */,
int /* cache_id */,
content::ServiceWorkerFetchRequest,
content::ServiceWorkerCacheQueryParams)
IPC_MESSAGE_ROUTED4(ServiceWorkerHostMsg_CacheMatchAll,
int /* request_id */,
int /* cache_id */,
content::ServiceWorkerFetchRequest,
content::ServiceWorkerCacheQueryParams)
IPC_MESSAGE_ROUTED4(ServiceWorkerHostMsg_CacheKeys,
int /* request_id */,
int /* cache_id */,
content::ServiceWorkerFetchRequest,
content::ServiceWorkerCacheQueryParams);
IPC_MESSAGE_ROUTED3(ServiceWorkerHostMsg_CacheBatch,
int /* request_id */,
int /* cache_id */,
std::vector<content::ServiceWorkerBatchOperation>);
IPC_MESSAGE_ROUTED1(ServiceWorkerHostMsg_CacheClosed,
int /* cache_id */);
//---------------------------------------------------------------------------
// Messages sent from the browser to the child process.
//
......@@ -335,3 +379,31 @@ IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheStorageDeleteError,
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheStorageKeysError,
int /* request_id */,
blink::WebServiceWorkerCacheError /* reason */)
// Sent via EmbeddedWorker at successful completion of Cache operations.
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheMatchSuccess,
int /* request_id */,
content::ServiceWorkerResponse)
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheMatchAllSuccess,
int /* request_id */,
std::vector<content::ServiceWorkerResponse>)
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheKeysSuccess,
int /* request_id */,
std::vector<content::ServiceWorkerFetchRequest>)
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheBatchSuccess,
int /* request_id */,
std::vector<content::ServiceWorkerResponse>)
// Sent via EmbeddedWorker at erroneous completion of CacheStorage operations.
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheMatchError,
int /* request_id */,
blink::WebServiceWorkerCacheError)
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheMatchAllError,
int /* request_id */,
blink::WebServiceWorkerCacheError)
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheKeysError,
int /* request_id */,
blink::WebServiceWorkerCacheError)
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheBatchError,
int /* request_id */,
blink::WebServiceWorkerCacheError)
......@@ -6,9 +6,8 @@
namespace content {
ServiceWorkerFetchRequest::ServiceWorkerFetchRequest()
: blob_size(0), is_reload(false) {
}
ServiceWorkerFetchRequest::ServiceWorkerFetchRequest() : blob_size(0),
is_reload(false) {}
ServiceWorkerFetchRequest::ServiceWorkerFetchRequest(
const GURL& url,
......@@ -21,8 +20,7 @@ ServiceWorkerFetchRequest::ServiceWorkerFetchRequest(
headers(headers),
blob_size(0),
referrer(referrer),
is_reload(is_reload) {
}
is_reload(is_reload) {}
ServiceWorkerFetchRequest::~ServiceWorkerFetchRequest() {}
......@@ -38,11 +36,18 @@ ServiceWorkerResponse::ServiceWorkerResponse(
status_code(status_code),
status_text(status_text),
headers(headers),
blob_uuid(blob_uuid) {
}
blob_uuid(blob_uuid) {}
ServiceWorkerResponse::~ServiceWorkerResponse() {}
ServiceWorkerCacheQueryParams::ServiceWorkerCacheQueryParams()
: ignore_search(false),
ignore_method(false),
ignore_vary(false),
prefix_match(false) {}
ServiceWorkerBatchOperation::ServiceWorkerBatchOperation() {}
ServiceWorkerObjectInfo::ServiceWorkerObjectInfo()
: handle_id(kInvalidServiceWorkerHandleId),
state(blink::WebServiceWorkerStateUnknown) {}
......
......@@ -88,6 +88,35 @@ struct CONTENT_EXPORT ServiceWorkerResponse {
std::string blob_uuid;
};
// Controls how requests are matched in the Cache API.
struct CONTENT_EXPORT ServiceWorkerCacheQueryParams {
ServiceWorkerCacheQueryParams();
bool ignore_search;
bool ignore_method;
bool ignore_vary;
bool prefix_match;
};
// The type of a single batch operation in the Cache API.
enum ServiceWorkerCacheOperationType {
SERVICE_WORKER_CACHE_OPERATION_TYPE_UNDEFINED,
SERVICE_WORKER_CACHE_OPERATION_TYPE_PUT,
SERVICE_WORKER_CACHE_OPERATION_TYPE_DELETE,
SERVICE_WORKER_CACHE_OPERATION_TYPE_LAST =
SERVICE_WORKER_CACHE_OPERATION_TYPE_DELETE
};
// A single batch operation for the Cache API.
struct CONTENT_EXPORT ServiceWorkerBatchOperation {
ServiceWorkerBatchOperation();
ServiceWorkerCacheOperationType operation_type;
ServiceWorkerFetchRequest request;
ServiceWorkerResponse response;
ServiceWorkerCacheQueryParams match_params;
};
// Represents initialization info for a WebServiceWorker object.
struct CONTENT_EXPORT ServiceWorkerObjectInfo {
ServiceWorkerObjectInfo();
......
......@@ -2,25 +2,30 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_FETCH_STORES_DISPATCHER_H_
#define CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_FETCH_STORES_DISPATCHER_H_
#ifndef CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_DISPATCHER_H_
#define CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_DISPATCHER_H_
#include <vector>
#include "base/id_map.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "content/public/renderer/render_process_observer.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerCache.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerCacheError.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerCacheStorage.h"
namespace content {
struct ServiceWorkerFetchRequest;
class ServiceWorkerScriptContext;
struct ServiceWorkerResponse;
// There is one ServiceWorkerCacheStorageDispatcher per
// ServiceWorkerScriptContext. It starts CacheStorage operations with messages
// to the browser process and runs callbacks at operation completion.
// ServiceWorkerScriptContext. It handles CacheStorage operations with messages
// to/from the browser, creating Cache objects (for which it also handles
// messages) as it goes.
class ServiceWorkerCacheStorageDispatcher
: public blink::WebServiceWorkerCacheStorage {
......@@ -29,26 +34,48 @@ class ServiceWorkerCacheStorageDispatcher
ServiceWorkerScriptContext* script_context);
virtual ~ServiceWorkerCacheStorageDispatcher();
// ServiceWorkerScriptContext calls our OnMessageReceived directly.
bool OnMessageReceived(const IPC::Message& message);
// Message handlers for messages from the browser process.
// Message handlers for CacheStorage messages from the browser process.
void OnCacheStorageGetSuccess(int request_id, int cache_id);
void OnCacheStorageHasSuccess(int request_id);
void OnCacheStorageCreateSuccess(int request_id, int cache_id);
void OnCacheStorageDeleteSuccess(int request_id);
void OnCacheStorageKeysSuccess(int request_id,
const std::vector<base::string16>& keys);
const std::vector<base::string16>& keys);
void OnCacheStorageGetError(int request_id,
blink::WebServiceWorkerCacheError reason);
blink::WebServiceWorkerCacheError reason);
void OnCacheStorageHasError(int request_id,
blink::WebServiceWorkerCacheError reason);
blink::WebServiceWorkerCacheError reason);
void OnCacheStorageCreateError(int request_id,
blink::WebServiceWorkerCacheError reason);
blink::WebServiceWorkerCacheError reason);
void OnCacheStorageDeleteError(int request_id,
blink::WebServiceWorkerCacheError reason);
blink::WebServiceWorkerCacheError reason);
void OnCacheStorageKeysError(int request_id,
blink::WebServiceWorkerCacheError reason);
blink::WebServiceWorkerCacheError reason);
// Message handlers for Cache messages from the browser process.
void OnCacheMatchSuccess(int request_id,
const ServiceWorkerResponse& response);
void OnCacheMatchAllSuccess(
int request_id,
const std::vector<ServiceWorkerResponse>& response);
void OnCacheKeysSuccess(
int request_id,
const std::vector<ServiceWorkerFetchRequest>& response);
void OnCacheBatchSuccess(int request_id,
const std::vector<ServiceWorkerResponse>& response);
void OnCacheMatchError(int request_id,
blink::WebServiceWorkerCacheError reason);
void OnCacheMatchAllError(int request_id,
blink::WebServiceWorkerCacheError reason);
void OnCacheKeysError(int request_id,
blink::WebServiceWorkerCacheError reason);
void OnCacheBatchError(int request_id,
blink::WebServiceWorkerCacheError reason);
// From WebServiceWorkerCacheStorage:
virtual void dispatchGet(CacheStorageWithCacheCallbacks* callbacks,
......@@ -61,13 +88,47 @@ class ServiceWorkerCacheStorageDispatcher
const blink::WebString& cacheName);
virtual void dispatchKeys(CacheStorageKeysCallbacks* callbacks);
// These methods are used by WebCache to forward events to the browser
// process.
void dispatchMatchForCache(
int cache_id,
blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks,
const blink::WebServiceWorkerRequest& request,
const blink::WebServiceWorkerCache::QueryParams& query_params);
void dispatchMatchAllForCache(
int cache_id,
blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks,
const blink::WebServiceWorkerRequest& request,
const blink::WebServiceWorkerCache::QueryParams& query_params);
void dispatchKeysForCache(
int cache_id,
blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks,
const blink::WebServiceWorkerRequest* request,
const blink::WebServiceWorkerCache::QueryParams& query_params);
void dispatchBatchForCache(
int cache_id,
blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks,
const blink::WebVector<blink::WebServiceWorkerCache::BatchOperation>&
batch_operations);
void OnWebCacheDestruction(int cache_id);
private:
class WebCache;
typedef IDMap<CacheStorageCallbacks, IDMapOwnPointer> CallbacksMap;
typedef IDMap<CacheStorageWithCacheCallbacks, IDMapOwnPointer>
WithCacheCallbacksMap;
typedef IDMap<CacheStorageKeysCallbacks, IDMapOwnPointer>
KeysCallbacksMap;
typedef IDMap<blink::WebServiceWorkerCache::CacheMatchCallbacks,
IDMapOwnPointer> MatchCallbacksMap;
typedef IDMap<blink::WebServiceWorkerCache::CacheWithResponsesCallbacks,
IDMapOwnPointer> WithResponsesCallbacksMap;
typedef IDMap<blink::WebServiceWorkerCache::CacheWithRequestsCallbacks,
IDMapOwnPointer> WithRequestsCallbacksMap;
// Not owned. The script context containing this object.
ServiceWorkerScriptContext* script_context_;
......@@ -77,6 +138,18 @@ class ServiceWorkerCacheStorageDispatcher
CallbacksMap delete_callbacks_;
KeysCallbacksMap keys_callbacks_;
// The individual caches created under this CacheStorage object.
IDMap<WebCache, IDMapExternalPointer> web_caches_;
// These ID maps are held in the CacheStorage object rather than the Cache
// object to ensure that the IDs are unique.
MatchCallbacksMap cache_match_callbacks_;
WithResponsesCallbacksMap cache_match_all_callbacks_;
WithRequestsCallbacksMap cache_keys_callbacks_;
WithResponsesCallbacksMap cache_batch_callbacks_;
base::WeakPtrFactory<ServiceWorkerCacheStorageDispatcher> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorageDispatcher);
};
......
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