[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / cache_storage / cache_storage_dispatcher_host.h
blob966d46125775c48ccb1d7b0084d2edf7a3059bd1
1 // Copyright 2015 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_CACHE_STORAGE_CACHE_STORAGE_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_DISPATCHER_HOST_H_
8 #include <list>
10 #include "content/browser/cache_storage/cache_storage.h"
11 #include "content/public/browser/browser_message_filter.h"
13 namespace content {
15 class CacheStorageContextImpl;
17 // Handles Cache Storage related messages sent to the browser process from
18 // child processes. One host instance exists per child process. All
19 // messages are processed on the IO thread.
20 class CONTENT_EXPORT CacheStorageDispatcherHost : public BrowserMessageFilter {
21 public:
22 CacheStorageDispatcherHost();
24 // Runs on UI thread.
25 void Init(CacheStorageContextImpl* context);
27 // BrowserMessageFilter implementation
28 void OnDestruct() const override;
29 bool OnMessageReceived(const IPC::Message& message) override;
31 private:
32 // Friends to allow OnDestruct() delegation
33 friend class BrowserThread;
34 friend class base::DeleteHelper<CacheStorageDispatcherHost>;
36 typedef int32_t CacheID; // TODO(jkarlin): Bump to 64 bit.
37 typedef std::map<CacheID, scoped_refptr<CacheStorageCache>> IDToCacheMap;
38 typedef std::map<std::string, std::list<storage::BlobDataHandle>>
39 UUIDToBlobDataHandleList;
41 ~CacheStorageDispatcherHost() override;
43 // Called by Init() on IO thread.
44 void CreateCacheListener(CacheStorageContextImpl* context);
46 // The message receiver functions for the CacheStorage API:
47 void OnCacheStorageHas(int thread_id,
48 int request_id,
49 const GURL& origin,
50 const base::string16& cache_name);
51 void OnCacheStorageOpen(int thread_id,
52 int request_id,
53 const GURL& origin,
54 const base::string16& cache_name);
55 void OnCacheStorageDelete(int thread_id,
56 int request_id,
57 const GURL& origin,
58 const base::string16& cache_name);
59 void OnCacheStorageKeys(int thread_id, int request_id, const GURL& origin);
60 void OnCacheStorageMatch(int thread_id,
61 int request_id,
62 const GURL& origin,
63 const ServiceWorkerFetchRequest& request,
64 const CacheStorageCacheQueryParams& match_params);
66 // The message receiver functions for the Cache API:
67 void OnCacheMatch(int thread_id,
68 int request_id,
69 int cache_id,
70 const ServiceWorkerFetchRequest& request,
71 const CacheStorageCacheQueryParams& match_params);
72 void OnCacheKeys(int thread_id,
73 int request_id,
74 int cache_id,
75 const ServiceWorkerFetchRequest& request,
76 const CacheStorageCacheQueryParams& match_params);
77 void OnCacheBatch(int thread_id,
78 int request_id,
79 int cache_id,
80 const std::vector<CacheStorageBatchOperation>& operations);
81 void OnCacheClosed(int cache_id);
82 void OnBlobDataHandled(const std::string& uuid);
84 // CacheStorageManager callbacks
85 void OnCacheStorageHasCallback(int thread_id,
86 int request_id,
87 bool has_cache,
88 CacheStorageError error);
89 void OnCacheStorageOpenCallback(int thread_id,
90 int request_id,
91 const scoped_refptr<CacheStorageCache>& cache,
92 CacheStorageError error);
93 void OnCacheStorageDeleteCallback(int thread_id,
94 int request_id,
95 bool deleted,
96 CacheStorageError error);
97 void OnCacheStorageKeysCallback(int thread_id,
98 int request_id,
99 const std::vector<std::string>& strings,
100 CacheStorageError error);
101 void OnCacheStorageMatchCallback(
102 int thread_id,
103 int request_id,
104 CacheStorageError error,
105 scoped_ptr<ServiceWorkerResponse> response,
106 scoped_ptr<storage::BlobDataHandle> blob_data_handle);
108 // Cache callbacks.
109 void OnCacheMatchCallback(
110 int thread_id,
111 int request_id,
112 const scoped_refptr<CacheStorageCache>& cache,
113 CacheStorageError error,
114 scoped_ptr<ServiceWorkerResponse> response,
115 scoped_ptr<storage::BlobDataHandle> blob_data_handle);
116 void OnCacheMatchAllCallbackAdapter(
117 int thread_id,
118 int request_id,
119 const scoped_refptr<CacheStorageCache>& cache,
120 CacheStorageError error,
121 scoped_ptr<ServiceWorkerResponse> response,
122 scoped_ptr<storage::BlobDataHandle> blob_data_handle);
123 void OnCacheMatchAllCallback(
124 int thread_id,
125 int request_id,
126 const scoped_refptr<CacheStorageCache>& cache,
127 CacheStorageError error,
128 scoped_ptr<std::vector<ServiceWorkerResponse>> responses,
129 scoped_ptr<CacheStorageCache::BlobDataHandles> blob_data_handles);
130 void OnCacheMatchAll(int thread_id,
131 int request_id,
132 int cache_id,
133 const ServiceWorkerFetchRequest& request,
134 const CacheStorageCacheQueryParams& match_params);
135 void OnCacheKeysCallback(int thread_id,
136 int request_id,
137 const scoped_refptr<CacheStorageCache>& cache,
138 CacheStorageError error,
139 scoped_ptr<CacheStorageCache::Requests> requests);
140 void OnCacheBatchCallback(int thread_id,
141 int request_id,
142 const scoped_refptr<CacheStorageCache>& cache,
143 CacheStorageError error);
145 // Hangs onto a scoped_refptr for the cache if it isn't already doing so.
146 // Returns a unique cache_id. Call DropCacheReference when the client is done
147 // with this cache.
148 CacheID StoreCacheReference(const scoped_refptr<CacheStorageCache>& cache);
149 void DropCacheReference(CacheID cache_id);
151 // Stores blob handles while waiting for acknowledgement of receipt from the
152 // renderer.
153 void StoreBlobDataHandle(const storage::BlobDataHandle& blob_data_handle);
154 void DropBlobDataHandle(const std::string& uuid);
156 IDToCacheMap id_to_cache_map_;
157 CacheID next_cache_id_ = 0;
159 UUIDToBlobDataHandleList blob_handle_store_;
161 scoped_refptr<CacheStorageContextImpl> context_;
163 DISALLOW_COPY_AND_ASSIGN(CacheStorageDispatcherHost);
166 } // namespace content
168 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_DISPATCHER_HOST_H_