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_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_LISTENER_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_LISTENER_H_
8 #include "base/memory/weak_ptr.h"
9 #include "base/strings/string16.h"
10 #include "content/browser/service_worker/embedded_worker_instance.h"
11 #include "content/browser/service_worker/service_worker_cache_storage.h"
15 class ServiceWorkerVersion;
17 // This class listens for requests on the Cache APIs, and sends response
18 // messages to the renderer process. There is one instance per
19 // ServiceWorkerVersion instance.
20 class ServiceWorkerCacheListener : public EmbeddedWorkerInstance::Listener {
22 ServiceWorkerCacheListener(ServiceWorkerVersion* version,
23 base::WeakPtr<ServiceWorkerContextCore> context);
24 virtual ~ServiceWorkerCacheListener();
26 // From EmbeddedWorkerInstance::Listener:
27 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
29 // Message receiver functions for CacheStorage API.
30 void OnCacheStorageGet(int request_id, const base::string16& cache_name);
31 void OnCacheStorageHas(int request_id, const base::string16& cache_name);
32 void OnCacheStorageCreate(int request_id,
33 const base::string16& cache_name);
34 void OnCacheStorageDelete(int request_id,
35 const base::string16& cache_name);
36 void OnCacheStorageKeys(int request_id);
39 void Send(const IPC::Message& message);
41 void OnCacheStorageGetCallback(
44 ServiceWorkerCacheStorage::CacheStorageError error);
45 void OnCacheStorageHasCallback(
48 ServiceWorkerCacheStorage::CacheStorageError error);
49 void OnCacheStorageCreateCallback(
52 ServiceWorkerCacheStorage::CacheStorageError error);
53 void OnCacheStorageDeleteCallback(
56 ServiceWorkerCacheStorage::CacheStorageError error);
57 void OnCacheStorageKeysCallback(
59 const std::vector<std::string>& strings,
60 ServiceWorkerCacheStorage::CacheStorageError error);
62 // The ServiceWorkerVersion to use for messaging back to the renderer thread.
63 ServiceWorkerVersion* version_;
65 // The ServiceWorkerContextCore should always outlive this.
66 base::WeakPtr<ServiceWorkerContextCore> context_;
68 base::WeakPtrFactory<ServiceWorkerCacheListener> weak_factory_;
70 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheListener);
73 } // namespace content
75 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_LISTENER_H_