Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / content / browser / service_worker / service_worker_cache_listener.h
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.
4
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_LISTENER_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_LISTENER_H_
7
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"
12
13 namespace content {
14
15 class ServiceWorkerVersion;
16
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 {
21  public:
22   ServiceWorkerCacheListener(ServiceWorkerVersion* version,
23                              base::WeakPtr<ServiceWorkerContextCore> context);
24   virtual ~ServiceWorkerCacheListener();
25
26   // From EmbeddedWorkerInstance::Listener:
27   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
28
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);
37
38  private:
39   void Send(const IPC::Message& message);
40
41   void OnCacheStorageGetCallback(
42       int request_id,
43       int cache_id,
44       ServiceWorkerCacheStorage::CacheStorageError error);
45   void OnCacheStorageHasCallback(
46       int request_id,
47       bool has_cache,
48       ServiceWorkerCacheStorage::CacheStorageError error);
49   void OnCacheStorageCreateCallback(
50       int request_id,
51       int cache_id,
52       ServiceWorkerCacheStorage::CacheStorageError error);
53   void OnCacheStorageDeleteCallback(
54       int request_id,
55       bool deleted,
56       ServiceWorkerCacheStorage::CacheStorageError error);
57   void OnCacheStorageKeysCallback(
58       int request_id,
59       const std::vector<std::string>& strings,
60       ServiceWorkerCacheStorage::CacheStorageError error);
61
62   // The ServiceWorkerVersion to use for messaging back to the renderer thread.
63   ServiceWorkerVersion* version_;
64
65   // The ServiceWorkerContextCore should always outlive this.
66   base::WeakPtr<ServiceWorkerContextCore> context_;
67
68   base::WeakPtrFactory<ServiceWorkerCacheListener> weak_factory_;
69
70   DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheListener);
71 };
72
73 }  // namespace content
74
75 #endif  // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_LISTENER_H_