1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_FETCH_STORES_DISPATCHER_H_
6 #define CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_FETCH_STORES_DISPATCHER_H_
10 #include "base/id_map.h"
11 #include "base/macros.h"
12 #include "base/strings/string16.h"
13 #include "content/public/renderer/render_process_observer.h"
14 #include "third_party/WebKit/public/platform/WebServiceWorkerCacheError.h"
15 #include "third_party/WebKit/public/platform/WebServiceWorkerCacheStorage.h"
19 class ServiceWorkerScriptContext;
21 // There is one ServiceWorkerCacheStorageDispatcher per
22 // ServiceWorkerScriptContext. It starts CacheStorage operations with messages
23 // to the browser process and runs callbacks at operation completion.
25 class ServiceWorkerCacheStorageDispatcher
26 : public blink::WebServiceWorkerCacheStorage {
28 explicit ServiceWorkerCacheStorageDispatcher(
29 ServiceWorkerScriptContext* script_context);
30 virtual ~ServiceWorkerCacheStorageDispatcher();
32 bool OnMessageReceived(const IPC::Message& message);
34 // Message handlers for messages from the browser process.
35 void OnCacheStorageGetSuccess(int request_id, int cache_id);
36 void OnCacheStorageHasSuccess(int request_id);
37 void OnCacheStorageCreateSuccess(int request_id, int cache_id);
38 void OnCacheStorageDeleteSuccess(int request_id);
39 void OnCacheStorageKeysSuccess(int request_id,
40 const std::vector<base::string16>& keys);
42 void OnCacheStorageGetError(int request_id,
43 blink::WebServiceWorkerCacheError reason);
44 void OnCacheStorageHasError(int request_id,
45 blink::WebServiceWorkerCacheError reason);
46 void OnCacheStorageCreateError(int request_id,
47 blink::WebServiceWorkerCacheError reason);
48 void OnCacheStorageDeleteError(int request_id,
49 blink::WebServiceWorkerCacheError reason);
50 void OnCacheStorageKeysError(int request_id,
51 blink::WebServiceWorkerCacheError reason);
53 // From WebServiceWorkerCacheStorage:
54 virtual void dispatchGet(CacheStorageWithCacheCallbacks* callbacks,
55 const blink::WebString& cacheName);
56 virtual void dispatchHas(CacheStorageCallbacks* callbacks,
57 const blink::WebString& cacheName);
58 virtual void dispatchCreate(CacheStorageWithCacheCallbacks* callbacks,
59 const blink::WebString& cacheName);
60 virtual void dispatchDelete(CacheStorageCallbacks* callbacks,
61 const blink::WebString& cacheName);
62 virtual void dispatchKeys(CacheStorageKeysCallbacks* callbacks);
65 typedef IDMap<CacheStorageCallbacks, IDMapOwnPointer> CallbacksMap;
66 typedef IDMap<CacheStorageWithCacheCallbacks, IDMapOwnPointer>
67 WithCacheCallbacksMap;
68 typedef IDMap<CacheStorageKeysCallbacks, IDMapOwnPointer>
71 // Not owned. The script context containing this object.
72 ServiceWorkerScriptContext* script_context_;
74 WithCacheCallbacksMap get_callbacks_;
75 CallbacksMap has_callbacks_;
76 WithCacheCallbacksMap create_callbacks_;
77 CallbacksMap delete_callbacks_;
78 KeysCallbacksMap keys_callbacks_;
80 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorageDispatcher);
83 } // namespace content
85 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_DISPATCHER_H_