| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_DISPATCHER_HOST_H_ |
| 6 #define CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_DISPATCHER_HOST_H_ |
| 7 | 7 |
| 8 #include <list> |
| 9 |
| 8 #include "content/browser/cache_storage/cache_storage.h" | 10 #include "content/browser/cache_storage/cache_storage.h" |
| 9 #include "content/public/browser/browser_message_filter.h" | 11 #include "content/public/browser/browser_message_filter.h" |
| 10 | 12 |
| 11 namespace content { | 13 namespace content { |
| 12 | 14 |
| 13 class CacheStorageContextImpl; | 15 class CacheStorageContextImpl; |
| 14 class CacheStorageListener; | |
| 15 | 16 |
| 16 // Handles Cache Storage related messages sent to the browser process from | 17 // Handles Cache Storage related messages sent to the browser process from |
| 17 // child processes. One host instance exists per child process. All | 18 // child processes. One host instance exists per child process. All |
| 18 // messages are processed on the IO thread. Currently, all messages are | 19 // messages are processed on the IO thread. |
| 19 // passed directly to the owned CacheStorageListener instance, which | |
| 20 // in turn dispatches calls to the CacheStorageManager owned | |
| 21 // by the CacheStorageContextImpl for the entire browsing context. | |
| 22 // TODO(jsbell): Merge this with CacheStorageListener crbug.com/439389 | |
| 23 class CONTENT_EXPORT CacheStorageDispatcherHost : public BrowserMessageFilter { | 20 class CONTENT_EXPORT CacheStorageDispatcherHost : public BrowserMessageFilter { |
| 24 public: | 21 public: |
| 25 CacheStorageDispatcherHost(); | 22 CacheStorageDispatcherHost(); |
| 26 | 23 |
| 27 // Runs on UI thread. | 24 // Runs on UI thread. |
| 28 void Init(CacheStorageContextImpl* context); | 25 void Init(CacheStorageContextImpl* context); |
| 29 | 26 |
| 30 // BrowserMessageFilter implementation | 27 // BrowserMessageFilter implementation |
| 31 void OnDestruct() const override; | 28 void OnDestruct() const override; |
| 32 bool OnMessageReceived(const IPC::Message& message) override; | 29 bool OnMessageReceived(const IPC::Message& message) override; |
| 33 | 30 |
| 34 private: | 31 private: |
| 35 // Friends to allow OnDestruct() delegation | 32 // Friends to allow OnDestruct() delegation |
| 36 friend class BrowserThread; | 33 friend class BrowserThread; |
| 37 friend class base::DeleteHelper<CacheStorageDispatcherHost>; | 34 friend class base::DeleteHelper<CacheStorageDispatcherHost>; |
| 38 | 35 |
| 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; |
| 40 |
| 39 ~CacheStorageDispatcherHost() override; | 41 ~CacheStorageDispatcherHost() override; |
| 40 | 42 |
| 41 // Called by Init() on IO thread. | 43 // Called by Init() on IO thread. |
| 42 void CreateCacheListener(CacheStorageContextImpl* context); | 44 void CreateCacheListener(CacheStorageContextImpl* context); |
| 43 | 45 |
| 44 // The message receiver functions for the CacheStorage API: | 46 // The message receiver functions for the CacheStorage API: |
| 45 void OnCacheStorageHas(int thread_id, | 47 void OnCacheStorageHas(int thread_id, |
| 46 int request_id, | 48 int request_id, |
| 47 const GURL& origin, | 49 const GURL& origin, |
| 48 const base::string16& cache_name); | 50 const base::string16& cache_name); |
| 49 void OnCacheStorageOpen(int thread_id, | 51 void OnCacheStorageOpen(int thread_id, |
| 50 int request_id, | 52 int request_id, |
| 51 const GURL& origin, | 53 const GURL& origin, |
| 52 const base::string16& cache_name); | 54 const base::string16& cache_name); |
| 53 void OnCacheStorageDelete(int thread_id, | 55 void OnCacheStorageDelete(int thread_id, |
| 54 int request_id, | 56 int request_id, |
| 55 const GURL& origin, | 57 const GURL& origin, |
| 56 const base::string16& cache_name); | 58 const base::string16& cache_name); |
| 57 void OnCacheStorageKeys(int thread_id, int request_id, const GURL& origin); | 59 void OnCacheStorageKeys(int thread_id, int request_id, const GURL& origin); |
| 58 void OnCacheStorageMatch(int thread_id, | 60 void OnCacheStorageMatch(int thread_id, |
| 59 int request_id, | 61 int request_id, |
| 60 const GURL& origin, | 62 const GURL& origin, |
| 61 const ServiceWorkerFetchRequest& request, | 63 const ServiceWorkerFetchRequest& request, |
| 62 const CacheStorageCacheQueryParams& match_params); | 64 const CacheStorageCacheQueryParams& match_params); |
| 63 | 65 |
| 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); |
| 83 |
| 64 // CacheStorageManager callbacks | 84 // CacheStorageManager callbacks |
| 65 void OnCacheStorageHasCallback(int thread_id, | 85 void OnCacheStorageHasCallback(int thread_id, |
| 66 int request_id, | 86 int request_id, |
| 67 bool has_cache, | 87 bool has_cache, |
| 68 CacheStorage::CacheStorageError error); | 88 CacheStorage::CacheStorageError error); |
| 69 void OnCacheStorageOpenCallback(int thread_id, | 89 void OnCacheStorageOpenCallback(int thread_id, |
| 70 int request_id, | 90 int request_id, |
| 71 const scoped_refptr<CacheStorageCache>& cache, | 91 const scoped_refptr<CacheStorageCache>& cache, |
| 72 CacheStorage::CacheStorageError error); | 92 CacheStorage::CacheStorageError error); |
| 73 void OnCacheStorageDeleteCallback(int thread_id, | 93 void OnCacheStorageDeleteCallback(int thread_id, |
| 74 int request_id, | 94 int request_id, |
| 75 bool deleted, | 95 bool deleted, |
| 76 CacheStorage::CacheStorageError error); | 96 CacheStorage::CacheStorageError error); |
| 77 void OnCacheStorageKeysCallback(int thread_id, | 97 void OnCacheStorageKeysCallback(int thread_id, |
| 78 int request_id, | 98 int request_id, |
| 79 const std::vector<std::string>& strings, | 99 const std::vector<std::string>& strings, |
| 80 CacheStorage::CacheStorageError error); | 100 CacheStorage::CacheStorageError error); |
| 81 void OnCacheStorageMatchCallback( | 101 void OnCacheStorageMatchCallback( |
| 82 int thread_id, | 102 int thread_id, |
| 83 int request_id, | 103 int request_id, |
| 84 CacheStorageCache::ErrorType error, | 104 CacheStorageCache::ErrorType error, |
| 85 scoped_ptr<ServiceWorkerResponse> response, | 105 scoped_ptr<ServiceWorkerResponse> response, |
| 86 scoped_ptr<storage::BlobDataHandle> blob_data_handle); | 106 scoped_ptr<storage::BlobDataHandle> blob_data_handle); |
| 87 | 107 |
| 88 scoped_ptr<CacheStorageListener> cache_listener_; | 108 // Cache callbacks. |
| 109 void OnCacheMatchCallback( |
| 110 int thread_id, |
| 111 int request_id, |
| 112 const scoped_refptr<CacheStorageCache>& cache, |
| 113 CacheStorageCache::ErrorType error, |
| 114 scoped_ptr<ServiceWorkerResponse> response, |
| 115 scoped_ptr<storage::BlobDataHandle> blob_data_handle); |
| 116 void OnCacheMatchAll(int thread_id, |
| 117 int request_id, |
| 118 int cache_id, |
| 119 const ServiceWorkerFetchRequest& request, |
| 120 const CacheStorageCacheQueryParams& match_params); |
| 121 void OnCacheKeysCallback(int thread_id, |
| 122 int request_id, |
| 123 const scoped_refptr<CacheStorageCache>& cache, |
| 124 CacheStorageCache::ErrorType error, |
| 125 scoped_ptr<CacheStorageCache::Requests> requests); |
| 126 void OnCacheDeleteCallback(int thread_id, |
| 127 int request_id, |
| 128 const scoped_refptr<CacheStorageCache>& cache, |
| 129 CacheStorageCache::ErrorType error); |
| 130 void OnCachePutCallback(int thread_id, |
| 131 int request_id, |
| 132 const scoped_refptr<CacheStorageCache>& cache, |
| 133 CacheStorageCache::ErrorType error, |
| 134 scoped_ptr<ServiceWorkerResponse> response, |
| 135 scoped_ptr<storage::BlobDataHandle> blob_data_handle); |
| 136 |
| 137 // Hangs onto a scoped_refptr for the cache if it isn't already doing so. |
| 138 // Returns a unique cache_id. Call DropCacheReference when the client is done |
| 139 // with this cache. |
| 140 CacheID StoreCacheReference(const scoped_refptr<CacheStorageCache>& cache); |
| 141 void DropCacheReference(CacheID cache_id); |
| 142 |
| 143 // Stores blob handles while waiting for acknowledgement of receipt from the |
| 144 // renderer. |
| 145 void StoreBlobDataHandle( |
| 146 scoped_ptr<storage::BlobDataHandle> blob_data_handle); |
| 147 void DropBlobDataHandle(std::string uuid); |
| 148 |
| 149 IDToCacheMap id_to_cache_map_; |
| 150 CacheID next_cache_id_ = 0; |
| 151 |
| 152 UUIDToBlobDataHandleList blob_handle_store_; |
| 153 |
| 89 scoped_refptr<CacheStorageContextImpl> context_; | 154 scoped_refptr<CacheStorageContextImpl> context_; |
| 90 | 155 |
| 91 DISALLOW_COPY_AND_ASSIGN(CacheStorageDispatcherHost); | 156 DISALLOW_COPY_AND_ASSIGN(CacheStorageDispatcherHost); |
| 92 }; | 157 }; |
| 93 | 158 |
| 94 } // namespace content | 159 } // namespace content |
| 95 | 160 |
| 96 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_DISPATCHER_HOST_H_ | 161 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_DISPATCHER_HOST_H_ |
| OLD | NEW |