Commit 144317b4 authored by gavinp@chromium.org's avatar gavinp@chromium.org

Content blink::WebServiceWorkerCacheStorage implementation.

This new object is implemented in content in both the renderer and browser
side. The CacheStorage API methods now pass in to the browser process in
the UI thread, where all API calls are failed as not implemented.

R=jkarlin@chromium.org,falken@chromium.org,jochen@chromium.org,jschuh@chromium.org
BUG=392621

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

Cr-Commit-Position: refs/heads/master@{#288413}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288413 0039d316-1c4b-4281-b951-d872f2087c98
parent 2f6bc704
......@@ -44,6 +44,7 @@ include_rules = [
"+third_party/WebKit/public/platform/WebScreenOrientationLockType.h",
"+third_party/WebKit/public/platform/WebScreenOrientationType.h",
"+third_party/WebKit/public/platform/WebScreenInfo.h",
"+third_party/WebKit/public/platform/WebServiceWorkerCacheError.h",
"+third_party/WebKit/public/platform/WebServiceWorkerError.h",
"+third_party/WebKit/public/platform/WebServiceWorkerEventResult.h",
"+third_party/WebKit/public/platform/WebServiceWorkerState.h",
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/service_worker/service_worker_cache_listener.h"
#include "content/browser/service_worker/service_worker_version.h"
#include "content/common/service_worker/service_worker_messages.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerCacheError.h"
namespace content {
ServiceWorkerStoresListener::ServiceWorkerStoresListener(
ServiceWorkerVersion* version) : version_(version) {}
ServiceWorkerStoresListener::~ServiceWorkerStoresListener() {}
bool ServiceWorkerStoresListener::OnMessageReceived(
const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ServiceWorkerStoresListener, message)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheStorageGet,
OnCacheStorageGet)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheStorageHas,
OnCacheStorageGet)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheStorageCreate,
OnCacheStorageCreate)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheStorageDelete,
OnCacheStorageDelete)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheStorageKeys,
OnCacheStorageKeys)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void ServiceWorkerStoresListener::OnCacheStorageGet(
int request_id,
const base::string16& fetch_store_name) {
// TODO(gavinp,jkarlin): Implement this method.
Send(ServiceWorkerMsg_CacheStorageGetError(
request_id,
blink::WebServiceWorkerCacheErrorNotImplemented));
}
void ServiceWorkerStoresListener::OnCacheStorageHas(
int request_id,
const base::string16& fetch_store_name) {
// TODO(gavinp,jkarlin): Implement this method.
Send(ServiceWorkerMsg_CacheStorageHasError(
request_id,
blink::WebServiceWorkerCacheErrorNotImplemented));
}
void ServiceWorkerStoresListener::OnCacheStorageCreate(
int request_id,
const base::string16& fetch_store_name) {
// TODO(gavinp,jkarlin): Implement this method.
Send(ServiceWorkerMsg_CacheStorageCreateError(
request_id,
blink::WebServiceWorkerCacheErrorNotImplemented));
}
void ServiceWorkerStoresListener::OnCacheStorageDelete(
int request_id,
const base::string16& fetch_store_name) {
// TODO(gavinp,jkarlin): Implement this method.
Send(ServiceWorkerMsg_CacheStorageDeleteError(
request_id, blink::WebServiceWorkerCacheErrorNotImplemented));
}
void ServiceWorkerStoresListener::OnCacheStorageKeys(
int request_id) {
// TODO(gavinp,jkarlin): Implement this method.
Send(ServiceWorkerMsg_CacheStorageKeysError(
request_id, blink::WebServiceWorkerCacheErrorNotImplemented));
}
void ServiceWorkerStoresListener::Send(const IPC::Message& message) {
version_->embedded_worker()->SendMessage(message);
}
} // namespace content
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORES_LISTENER_H_
#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORES_LISTENER_H_
#include "base/strings/string16.h"
#include "content/browser/service_worker/embedded_worker_instance.h"
namespace content {
class ServiceWorkerVersion;
// This class listens for requests on the Store APIs, and sends response
// messages to the renderer process. There is one instance per
// ServiceWorkerVersion instance.
class ServiceWorkerStoresListener : public EmbeddedWorkerInstance::Listener {
public:
explicit ServiceWorkerStoresListener(ServiceWorkerVersion* version);
virtual ~ServiceWorkerStoresListener();
// From EmbeddedWorkerInstance::Listener:
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
// Message receiver functions for 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,
const base::string16& cache_name);
void OnCacheStorageDelete(int request_id,
const base::string16& cache_name);
void OnCacheStorageKeys(int request_id);
private:
void Send(const IPC::Message& message);
// The ServiceWorkerVersion to use for messaging back to the renderer thread.
ServiceWorkerVersion* version_;
};
} // namespace content
#endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORES_LISTENER_H_
......@@ -110,6 +110,8 @@ ServiceWorkerVersion::ServiceWorkerVersion(
context_->AddLiveVersion(this);
embedded_worker_ = context_->embedded_worker_registry()->CreateWorker();
embedded_worker_->AddListener(this);
stores_listener_.reset(new ServiceWorkerStoresListener(this));
embedded_worker_->AddListener(stores_listener_.get());
}
ServiceWorkerVersion::~ServiceWorkerVersion() {
......
......@@ -18,6 +18,7 @@
#include "base/observer_list.h"
#include "base/timer/timer.h"
#include "content/browser/service_worker/embedded_worker_instance.h"
#include "content/browser/service_worker/service_worker_cache_listener.h"
#include "content/browser/service_worker/service_worker_script_cache_map.h"
#include "content/common/content_export.h"
#include "content/common/service_worker/service_worker_status_code.h"
......@@ -284,6 +285,7 @@ class CONTENT_EXPORT ServiceWorkerVersion
GURL scope_;
Status status_;
scoped_ptr<EmbeddedWorkerInstance> embedded_worker_;
scoped_ptr<ServiceWorkerStoresListener> stores_listener_;
std::vector<StatusCallback> start_callbacks_;
std::vector<StatusCallback> stop_callbacks_;
std::vector<base::Closure> status_change_callbacks_;
......
......@@ -29,6 +29,7 @@ include_rules = [
"+third_party/WebKit/public/platform/WebScreenInfo.h",
"+third_party/WebKit/public/platform/WebServiceWorkerError.h",
"+third_party/WebKit/public/platform/WebServiceWorkerEventResult.h",
"+third_party/WebKit/public/platform/WebServiceWorkerCacheError.h",
"+third_party/WebKit/public/platform/WebServiceWorkerState.h",
"+third_party/WebKit/public/platform/WebStorageArea.h",
"+third_party/WebKit/public/platform/WebString.h",
......
......@@ -4,11 +4,15 @@
// Message definition file, included multiple times, hence no include guard.
#include <string>
#include <vector>
#include "base/strings/string16.h"
#include "content/common/service_worker/service_worker_status_code.h"
#include "content/common/service_worker/service_worker_types.h"
#include "ipc/ipc_message_macros.h"
#include "ipc/ipc_param_traits.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerCacheError.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerError.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h"
#include "url/gurl.h"
......@@ -53,6 +57,10 @@ IPC_STRUCT_TRAITS_BEGIN(content::ServiceWorkerObjectInfo)
IPC_STRUCT_TRAITS_MEMBER(state)
IPC_STRUCT_TRAITS_END()
IPC_ENUM_TRAITS_MAX_VALUE(
blink::WebServiceWorkerCacheError,
blink::WebServiceWorkerCacheErrorLast);
//---------------------------------------------------------------------------
// Messages sent from the child process to the browser.
......@@ -127,6 +135,26 @@ IPC_MESSAGE_ROUTED3(ServiceWorkerHostMsg_PostMessageToDocument,
base::string16 /* message */,
std::vector<int> /* sent_message_port_ids */)
// CacheStorage operations in the browser.
IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_CacheStorageGet,
int /* request_id */,
base::string16 /* fetch_store_name */)
IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_CacheStorageHas,
int /* request_id */,
base::string16 /* fetch_store_name */)
IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_CacheStorageCreate,
int /* request_id */,
base::string16 /* fetch_store_name */)
IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_CacheStorageDelete,
int /* request_id */,
base::string16 /* fetch_store_name */)
IPC_MESSAGE_ROUTED1(ServiceWorkerHostMsg_CacheStorageKeys,
int /* request_id */)
//---------------------------------------------------------------------------
// Messages sent from the browser to the child process.
//
......@@ -219,3 +247,35 @@ IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_MessageToWorker,
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_DidGetClientDocuments,
int /* request_id */,
std::vector<int> /* client_ids */)
// Sent via EmbeddedWorker at successful completion of CacheStorage operations.
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheStorageGetSuccess,
int /* request_id */,
int /* fetch_store_id */)
IPC_MESSAGE_CONTROL1(ServiceWorkerMsg_CacheStorageHasSuccess,
int /* request_id */)
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheStorageCreateSuccess,
int /* request_id */,
int /* fetch_store_id */)
IPC_MESSAGE_CONTROL1(ServiceWorkerMsg_CacheStorageDeleteSuccess,
int /* request_id */)
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheStorageKeysSuccess,
int /* request_id */,
std::vector<base::string16> /* keys */)
// Sent via EmbeddedWorker at erroneous completion of CacheStorage operations.
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheStorageGetError,
int /* request_id */,
blink::WebServiceWorkerCacheError /* reason */)
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheStorageHasError,
int /* request_id */,
blink::WebServiceWorkerCacheError /* reason */)
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheStorageCreateError,
int /* request_id */,
blink::WebServiceWorkerCacheError /* reason */)
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheStorageDeleteError,
int /* request_id */,
blink::WebServiceWorkerCacheError /* reason */)
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheStorageKeysError,
int /* request_id */,
blink::WebServiceWorkerCacheError /* reason */)
......@@ -1122,6 +1122,8 @@
'browser/service_worker/embedded_worker_instance.h',
'browser/service_worker/embedded_worker_registry.cc',
'browser/service_worker/embedded_worker_registry.h',
'browser/service_worker/service_worker_cache_listener.cc',
'browser/service_worker/service_worker_cache_listener.h',
'browser/service_worker/service_worker_context_core.cc',
'browser/service_worker/service_worker_context_core.h',
'browser/service_worker/service_worker_context_observer.h',
......
......@@ -435,6 +435,8 @@
'renderer/service_worker/embedded_worker_devtools_agent.h',
'renderer/service_worker/embedded_worker_dispatcher.cc',
'renderer/service_worker/embedded_worker_dispatcher.h',
'renderer/service_worker/service_worker_cache_storage_dispatcher.cc',
'renderer/service_worker/service_worker_cache_storage_dispatcher.h',
'renderer/service_worker/service_worker_script_context.cc',
'renderer/service_worker/service_worker_script_context.h',
'renderer/shared_memory_seqlock_reader.cc',
......
......@@ -123,6 +123,11 @@ blink::WebURL EmbeddedWorkerContextClient::scope() const {
return service_worker_scope_;
}
blink::WebServiceWorkerCacheStorage*
EmbeddedWorkerContextClient::cacheStorage() {
return script_context_->cache_storage();
}
void EmbeddedWorkerContextClient::didPauseAfterDownload() {
Send(new EmbeddedWorkerHostMsg_DidPauseAfterDownload(embedded_worker_id_));
}
......
......@@ -63,6 +63,7 @@ class EmbeddedWorkerContextClient
// WebServiceWorkerContextClient overrides, some of them are just dispatched
// on to script_context_.
virtual blink::WebURL scope() const;
virtual blink::WebServiceWorkerCacheStorage* cacheStorage();
virtual void didPauseAfterDownload();
virtual void getClients(blink::WebServiceWorkerClientsCallbacks*);
virtual void workerContextFailedToStart();
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/service_worker/service_worker_cache_storage_dispatcher.h"
#include "base/logging.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"
namespace content {
namespace {
template<typename T>
void ClearCallbacksMapWithErrors(T* callbacks_map) {
typename T::iterator iter(callbacks_map);
while (!iter.IsAtEnd()) {
blink::WebServiceWorkerCacheError reason =
blink::WebServiceWorkerCacheErrorNotFound;
iter.GetCurrentValue()->onError(&reason);
callbacks_map->Remove(iter.GetCurrentKey());
iter.Advance();
}
}
} // namespace
ServiceWorkerCacheStorageDispatcher::ServiceWorkerCacheStorageDispatcher(
ServiceWorkerScriptContext* script_context)
: script_context_(script_context) {}
ServiceWorkerCacheStorageDispatcher::~ServiceWorkerCacheStorageDispatcher() {
ClearCallbacksMapWithErrors(&get_callbacks_);
ClearCallbacksMapWithErrors(&has_callbacks_);
ClearCallbacksMapWithErrors(&create_callbacks_);
ClearCallbacksMapWithErrors(&delete_callbacks_);
ClearCallbacksMapWithErrors(&keys_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_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void ServiceWorkerCacheStorageDispatcher::OnCacheStorageGetSuccess(
int request_id,
int cache_id) {
CacheStorageWithCacheCallbacks* callbacks =
get_callbacks_.Lookup(request_id);
DCHECK(callbacks);
callbacks->onSuccess(NULL);
get_callbacks_.Remove(request_id);
}
void ServiceWorkerCacheStorageDispatcher::OnCacheStorageHasSuccess(
int request_id) {
CacheStorageCallbacks* callbacks = has_callbacks_.Lookup(request_id);
DCHECK(callbacks);
callbacks->onSuccess();
has_callbacks_.Remove(request_id);
}
void ServiceWorkerCacheStorageDispatcher::OnCacheStorageCreateSuccess(
int request_id,
int cache_id) {
CacheStorageWithCacheCallbacks* callbacks =
create_callbacks_.Lookup(request_id);
DCHECK(callbacks);
callbacks->onSuccess(NULL);
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);
}
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];
callbacks->onSuccess(&webKeys);
keys_callbacks_.Remove(request_id);
}
void ServiceWorkerCacheStorageDispatcher::OnCacheStorageGetError(
int request_id,
blink::WebServiceWorkerCacheError reason) {
CacheStorageWithCacheCallbacks* callbacks =
get_callbacks_.Lookup(request_id);
DCHECK(callbacks);
callbacks->onError(&reason);
get_callbacks_.Remove(request_id);
}
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);
}
void ServiceWorkerCacheStorageDispatcher::OnCacheStorageCreateError(
int request_id,
blink::WebServiceWorkerCacheError reason) {
CacheStorageWithCacheCallbacks* callbacks =
create_callbacks_.Lookup(request_id);
DCHECK(callbacks);
callbacks->onError(&reason);
create_callbacks_.Remove(request_id);
}
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);
}
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::dispatchGet(
CacheStorageWithCacheCallbacks* callbacks,
const blink::WebString& cacheName) {
int request_id = get_callbacks_.Add(callbacks);
script_context_->Send(new ServiceWorkerHostMsg_CacheStorageGet(
script_context_->GetRoutingID(), request_id, cacheName));
}
void ServiceWorkerCacheStorageDispatcher::dispatchHas(
CacheStorageCallbacks* callbacks,
const blink::WebString& cacheName) {
int request_id = delete_callbacks_.Add(callbacks);
script_context_->Send(new ServiceWorkerHostMsg_CacheStorageDelete(
script_context_->GetRoutingID(), request_id, cacheName));
}
void ServiceWorkerCacheStorageDispatcher::dispatchCreate(
CacheStorageWithCacheCallbacks* callbacks,
const blink::WebString& cacheName) {
int request_id = create_callbacks_.Add(callbacks);
script_context_->Send(new ServiceWorkerHostMsg_CacheStorageCreate(
script_context_->GetRoutingID(), request_id, cacheName));
}
void ServiceWorkerCacheStorageDispatcher::dispatchDelete(
CacheStorageCallbacks* callbacks,
const blink::WebString& cacheName) {
int request_id = delete_callbacks_.Add(callbacks);
script_context_->Send(new ServiceWorkerHostMsg_CacheStorageDelete(
script_context_->GetRoutingID(), request_id, cacheName));
}
void ServiceWorkerCacheStorageDispatcher::dispatchKeys(
CacheStorageKeysCallbacks* callbacks) {
int request_id = keys_callbacks_.Add(callbacks);
script_context_->Send(new ServiceWorkerHostMsg_CacheStorageKeys(
script_context_->GetRoutingID(), request_id));
}
} // namespace content
// Copyright 2014 The Chromium Authors. All rights reserved.
// 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_
#include <vector>
#include "base/id_map.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "content/public/renderer/render_process_observer.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerCacheError.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerCacheStorage.h"
namespace content {
class ServiceWorkerScriptContext;
// There is one ServiceWorkerCacheStorageDispatcher per
// ServiceWorkerScriptContext. It starts CacheStorage operations with messages
// to the browser process and runs callbacks at operation completion.
class ServiceWorkerCacheStorageDispatcher
: public blink::WebServiceWorkerCacheStorage {
public:
explicit ServiceWorkerCacheStorageDispatcher(
ServiceWorkerScriptContext* script_context);
virtual ~ServiceWorkerCacheStorageDispatcher();
bool OnMessageReceived(const IPC::Message& message);
// Message handlers for 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);
void OnCacheStorageGetError(int request_id,
blink::WebServiceWorkerCacheError reason);
void OnCacheStorageHasError(int request_id,
blink::WebServiceWorkerCacheError reason);
void OnCacheStorageCreateError(int request_id,
blink::WebServiceWorkerCacheError reason);
void OnCacheStorageDeleteError(int request_id,
blink::WebServiceWorkerCacheError reason);
void OnCacheStorageKeysError(int request_id,
blink::WebServiceWorkerCacheError reason);
// From WebServiceWorkerCacheStorage:
virtual void dispatchGet(CacheStorageWithCacheCallbacks* callbacks,
const blink::WebString& cacheName);
virtual void dispatchHas(CacheStorageCallbacks* callbacks,
const blink::WebString& cacheName);
virtual void dispatchCreate(CacheStorageWithCacheCallbacks* callbacks,
const blink::WebString& cacheName);
virtual void dispatchDelete(CacheStorageCallbacks* callbacks,
const blink::WebString& cacheName);
virtual void dispatchKeys(CacheStorageKeysCallbacks* callbacks);
private:
typedef IDMap<CacheStorageCallbacks, IDMapOwnPointer> CallbacksMap;
typedef IDMap<CacheStorageWithCacheCallbacks, IDMapOwnPointer>
WithCacheCallbacksMap;
typedef IDMap<CacheStorageKeysCallbacks, IDMapOwnPointer>
KeysCallbacksMap;
// Not owned. The script context containing this object.
ServiceWorkerScriptContext* script_context_;
WithCacheCallbacksMap get_callbacks_;
CallbacksMap has_callbacks_;
WithCacheCallbacksMap create_callbacks_;
CallbacksMap delete_callbacks_;
KeysCallbacksMap keys_callbacks_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorageDispatcher);
};
} // namespace content
#endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_DISPATCHER_H_
......@@ -39,7 +39,8 @@ void SendPostMessageToDocumentOnMainThread(
ServiceWorkerScriptContext::ServiceWorkerScriptContext(
EmbeddedWorkerContextClient* embedded_context,
blink::WebServiceWorkerContextProxy* proxy)
: embedded_context_(embedded_context),
: cache_storage_dispatcher_(new ServiceWorkerCacheStorageDispatcher(this)),
embedded_context_(embedded_context),
proxy_(proxy) {
}
......@@ -59,6 +60,12 @@ void ServiceWorkerScriptContext::OnMessageReceived(
OnDidGetClientDocuments)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
// TODO(gavinp): Would it be preferable to put an AddListener() method to
// EmbeddedWorkerContextClient?
if (!handled)
handled = cache_storage_dispatcher_->OnMessageReceived(message);
DCHECK(handled);
}
......@@ -116,6 +123,10 @@ void ServiceWorkerScriptContext::Send(IPC::Message* message) {
embedded_context_->Send(message);
}
int ServiceWorkerScriptContext::GetRoutingID() const {
return embedded_context_->embedded_worker_id();
}
void ServiceWorkerScriptContext::OnActivateEvent(int request_id) {
proxy_->dispatchActivateEvent(request_id);
}
......@@ -187,8 +198,4 @@ void ServiceWorkerScriptContext::OnDidGetClientDocuments(
pending_clients_callbacks_.Remove(request_id);
}
int ServiceWorkerScriptContext::GetRoutingID() const {
return embedded_context_->embedded_worker_id();
}
} // namespace content
......@@ -10,9 +10,11 @@
#include "base/basictypes.h"
#include "base/id_map.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
#include "content/child/webmessageportchannel_impl.h"
#include "content/common/service_worker/service_worker_types.h"
#include "content/renderer/service_worker/service_worker_cache_storage_dispatcher.h"
#include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerClientsInfo.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h"
......@@ -57,12 +59,21 @@ class ServiceWorkerScriptContext {
const base::string16& message,
scoped_ptr<blink::WebMessagePortChannelArray> channels);
// Send a message to the browser. Takes ownership of |message|.
void Send(IPC::Message* message);
// Get routing_id for sending message to the ServiceWorkerVersion
// in the browser process.
int GetRoutingID() const;
blink::WebServiceWorkerCacheStorage* cache_storage() {
return cache_storage_dispatcher_.get();
}
private:
typedef IDMap<blink::WebServiceWorkerClientsCallbacks, IDMapOwnPointer>
ClientsCallbacksMap;
// Send a message to the browser.
void Send(IPC::Message* message);
void OnActivateEvent(int request_id);
void OnInstallEvent(int request_id, int active_version_id);
......@@ -75,9 +86,7 @@ class ServiceWorkerScriptContext {
void OnDidGetClientDocuments(
int request_id, const std::vector<int>& client_ids);
// Get routing_id for sending message to the ServiceWorkerVersion
// in the browser process.
int GetRoutingID() const;
scoped_ptr<ServiceWorkerCacheStorageDispatcher> cache_storage_dispatcher_;
// Not owned; embedded_context_ owns this.
EmbeddedWorkerContextClient* embedded_context_;
......
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