Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Unified Diff: content/renderer/service_worker/service_worker_cache_storage_dispatcher.cc

Issue 379303002: Content blink::WebServiceWorkerCacheStorage implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: meets presubmit! Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..bc56bfb43bef0e01dbb39cc09eea7f0e1861fd59
--- /dev/null
+++ b/content/renderer/service_worker/service_worker_cache_storage_dispatcher.cc
@@ -0,0 +1,190 @@
+// 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 {
+
+ServiceWorkerCacheStorageDispatcher::ServiceWorkerCacheStorageDispatcher(
+ ServiceWorkerScriptContext* script_context)
+ : script_context_(script_context) {}
+
+ServiceWorkerCacheStorageDispatcher::~ServiceWorkerCacheStorageDispatcher() { }
+
+bool ServiceWorkerCacheStorageDispatcher::OnMessageReceived(
+ const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(ServiceWorkerCacheStorageDispatcher, message)
+ IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageCreateSuccess,
+ OnCacheStorageCreateSuccess)
+ IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageRenameSuccess,
+ OnCacheStorageRenameSuccess)
+ IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageGetSuccess,
+ OnCacheStorageGetSuccess)
+ IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageDeleteSuccess,
+ OnCacheStorageDeleteSuccess)
+ IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageKeysSuccess,
+ OnCacheStorageKeysSuccess)
+ IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageCreateError,
+ OnCacheStorageCreateError)
+ IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageRenameError,
+ OnCacheStorageRenameError)
+ IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageGetError,
+ OnCacheStorageGetError)
+ 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::OnCacheStorageCreateSuccess(
+ int request_id,
+ int cache_id) {
+ CacheStorageWithCacheCallbacks* callbacks =
+ create_callbacks_.Lookup(request_id);
+ DCHECK(callbacks);
+ callbacks->onSuccess(&cache_id);
+ create_callbacks_.Remove(request_id);
+}
+
+void ServiceWorkerCacheStorageDispatcher::OnCacheStorageRenameSuccess(
+ int request_id) {
+ CacheStorageCallbacks* callbacks = rename_callbacks_.Lookup(request_id);
+ DCHECK(callbacks);
+ callbacks->onSuccess();
+ rename_callbacks_.Remove(request_id);
+}
+
+void ServiceWorkerCacheStorageDispatcher::OnCacheStorageGetSuccess(
+ int request_id,
+ int cache_id) {
+ CacheStorageWithCacheCallbacks* callbacks = get_callbacks_.Lookup(request_id);
+ DCHECK(callbacks);
+ callbacks->onSuccess(&cache_id);
+ get_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::OnCacheStorageCreateError(
+ int request_id,
+ blink::WebServiceWorkerCacheStorageError reason) {
+ CacheStorageWithCacheCallbacks* callbacks =
+ create_callbacks_.Lookup(request_id);
+ DCHECK(callbacks);
+ callbacks->onError(&reason);
+ create_callbacks_.Remove(request_id);
+}
+
+void ServiceWorkerCacheStorageDispatcher::OnCacheStorageRenameError(
+ int request_id,
+ blink::WebServiceWorkerCacheStorageError reason) {
+ CacheStorageCallbacks* callbacks = rename_callbacks_.Lookup(request_id);
+ DCHECK(callbacks);
+ callbacks->onError(&reason);
+ rename_callbacks_.Remove(request_id);
+}
+
+void ServiceWorkerCacheStorageDispatcher::OnCacheStorageGetError(
+ int request_id,
+ blink::WebServiceWorkerCacheStorageError reason) {
+ CacheStorageWithCacheCallbacks* callbacks = get_callbacks_.Lookup(request_id);
+ DCHECK(callbacks);
+ callbacks->onError(&reason);
+ get_callbacks_.Remove(request_id);
+}
+
+void ServiceWorkerCacheStorageDispatcher::OnCacheStorageDeleteError(
+ int request_id,
+ blink::WebServiceWorkerCacheStorageError 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::WebServiceWorkerCacheStorageError reason) {
+ CacheStorageKeysCallbacks* callbacks = keys_callbacks_.Lookup(request_id);
+ DCHECK(callbacks);
+ callbacks->onError(&reason);
+ keys_callbacks_.Remove(request_id);
+}
+
+void ServiceWorkerCacheStorageDispatcher::dispatchCreate(
+ CacheStorageWithCacheCallbacks* callbacks,
+ const blink::WebString& key) {
+ int request_id = create_callbacks_.Add(callbacks);
+ base::string16 myKey = key;
+ script_context_->Send(
+ new ServiceWorkerHostMsg_CacheStorageCreate(
+ script_context_->GetRoutingID(), request_id, myKey));
+}
+
+void ServiceWorkerCacheStorageDispatcher::dispatchRename(
+ CacheStorageCallbacks* callbacks,
+ const blink::WebString& oldKey,
+ const blink::WebString& newKey) {
+ int request_id = rename_callbacks_.Add(callbacks);
+ script_context_->Send(
+ new ServiceWorkerHostMsg_CacheStorageRename(
+ script_context_->GetRoutingID(), request_id, oldKey, newKey));
+}
+
+void ServiceWorkerCacheStorageDispatcher::dispatchGet(
+ CacheStorageWithCacheCallbacks* callbacks,
+ const blink::WebString& key) {
+ int request_id = get_callbacks_.Add(callbacks);
+ script_context_->Send(
+ new ServiceWorkerHostMsg_CacheStorageGet(script_context_->GetRoutingID(),
+ request_id, key));
+}
+
+void ServiceWorkerCacheStorageDispatcher::dispatchDelete(
+ CacheStorageCallbacks* callbacks,
+ const blink::WebString& key) {
+ int request_id = delete_callbacks_.Add(callbacks);
+ script_context_->Send(
+ new ServiceWorkerHostMsg_CacheStorageDelete(
+ script_context_->GetRoutingID(), request_id, key));
+}
+
+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

Powered by Google App Engine
This is Rietveld 408576698