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_
10 #include "content/browser/cache_storage/cache_storage.h"
11 #include "content/public/browser/browser_message_filter.h"
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
{
22 CacheStorageDispatcherHost();
25 void Init(CacheStorageContextImpl
* context
);
27 // BrowserMessageFilter implementation
28 void OnDestruct() const override
;
29 bool OnMessageReceived(const IPC::Message
& message
) override
;
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
,
50 const base::string16
& cache_name
);
51 void OnCacheStorageOpen(int thread_id
,
54 const base::string16
& cache_name
);
55 void OnCacheStorageDelete(int thread_id
,
58 const base::string16
& cache_name
);
59 void OnCacheStorageKeys(int thread_id
, int request_id
, const GURL
& origin
);
60 void OnCacheStorageMatch(int thread_id
,
63 const ServiceWorkerFetchRequest
& request
,
64 const CacheStorageCacheQueryParams
& match_params
);
66 // The message receiver functions for the Cache API:
67 void OnCacheMatch(int thread_id
,
70 const ServiceWorkerFetchRequest
& request
,
71 const CacheStorageCacheQueryParams
& match_params
);
72 void OnCacheKeys(int thread_id
,
75 const ServiceWorkerFetchRequest
& request
,
76 const CacheStorageCacheQueryParams
& match_params
);
77 void OnCacheBatch(int thread_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
,
88 CacheStorageError error
);
89 void OnCacheStorageOpenCallback(int thread_id
,
91 const scoped_refptr
<CacheStorageCache
>& cache
,
92 CacheStorageError error
);
93 void OnCacheStorageDeleteCallback(int thread_id
,
96 CacheStorageError error
);
97 void OnCacheStorageKeysCallback(int thread_id
,
99 const std::vector
<std::string
>& strings
,
100 CacheStorageError error
);
101 void OnCacheStorageMatchCallback(
104 CacheStorageError error
,
105 scoped_ptr
<ServiceWorkerResponse
> response
,
106 scoped_ptr
<storage::BlobDataHandle
> blob_data_handle
);
109 void OnCacheMatchCallback(
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(
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(
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
,
133 const ServiceWorkerFetchRequest
& request
,
134 const CacheStorageCacheQueryParams
& match_params
);
135 void OnCacheKeysCallback(int thread_id
,
137 const scoped_refptr
<CacheStorageCache
>& cache
,
138 CacheStorageError error
,
139 scoped_ptr
<CacheStorageCache::Requests
> requests
);
140 void OnCacheBatchCallback(int thread_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
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
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_