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 OnCacheMatchAll(int thread_id
,
119 const ServiceWorkerFetchRequest
& request
,
120 const CacheStorageCacheQueryParams
& match_params
);
121 void OnCacheKeysCallback(int thread_id
,
123 const scoped_refptr
<CacheStorageCache
>& cache
,
124 CacheStorageError error
,
125 scoped_ptr
<CacheStorageCache::Requests
> requests
);
126 void OnCacheBatchCallback(int thread_id
,
128 const scoped_refptr
<CacheStorageCache
>& cache
,
129 CacheStorageError error
);
131 // Hangs onto a scoped_refptr for the cache if it isn't already doing so.
132 // Returns a unique cache_id. Call DropCacheReference when the client is done
134 CacheID
StoreCacheReference(const scoped_refptr
<CacheStorageCache
>& cache
);
135 void DropCacheReference(CacheID cache_id
);
137 // Stores blob handles while waiting for acknowledgement of receipt from the
139 void StoreBlobDataHandle(
140 scoped_ptr
<storage::BlobDataHandle
> blob_data_handle
);
141 void DropBlobDataHandle(std::string uuid
);
143 IDToCacheMap id_to_cache_map_
;
144 CacheID next_cache_id_
= 0;
146 UUIDToBlobDataHandleList blob_handle_store_
;
148 scoped_refptr
<CacheStorageContextImpl
> context_
;
150 DISALLOW_COPY_AND_ASSIGN(CacheStorageDispatcherHost
);
153 } // namespace content
155 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_DISPATCHER_HOST_H_