Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(836)

Unified Diff: content/browser/cache_storage/cache_storage_dispatcher_host.cc

Issue 1107293002: CacheStorage: Merge CacheStorageListener into CacheStorageDispatcherHost (2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@merge_cache_listener_and_dispatcher
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/cache_storage/cache_storage_dispatcher_host.cc
diff --git a/content/browser/cache_storage/cache_storage_dispatcher_host.cc b/content/browser/cache_storage/cache_storage_dispatcher_host.cc
index 84d695b5eec74b27cf58a8a0cdbbe76deff42faf..bb9ae48b0714e80c6b6188218d028a97a6ac5aec 100644
--- a/content/browser/cache_storage/cache_storage_dispatcher_host.cc
+++ b/content/browser/cache_storage/cache_storage_dispatcher_host.cc
@@ -4,11 +4,13 @@
#include "content/browser/cache_storage/cache_storage_dispatcher_host.h"
+#include "base/bind.h"
#include "base/logging.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/trace_event/trace_event.h"
+#include "content/browser/cache_storage/cache_storage_cache.h"
#include "content/browser/cache_storage/cache_storage_context_impl.h"
-#include "content/browser/cache_storage/cache_storage_listener.h"
#include "content/browser/cache_storage/cache_storage_manager.h"
#include "content/common/cache_storage/cache_storage_messages.h"
#include "content/public/browser/content_browser_client.h"
@@ -102,13 +104,15 @@ bool CacheStorageDispatcherHost::OnMessageReceived(
IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheStorageKeys, OnCacheStorageKeys)
IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheStorageMatch,
OnCacheStorageMatch)
+ IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheMatch, OnCacheMatch)
+ IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheMatchAll, OnCacheMatchAll)
+ IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheKeys, OnCacheKeys)
+ IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheBatch, OnCacheBatch)
+ IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheClosed, OnCacheClosed)
+ IPC_MESSAGE_HANDLER(CacheStorageHostMsg_BlobDataHandled, OnBlobDataHandled)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
- if (handled)
- return handled;
- DCHECK(cache_listener_);
- handled = cache_listener_->OnMessageReceived(message);
if (!handled)
BadMessageReceived();
return handled;
@@ -117,7 +121,6 @@ bool CacheStorageDispatcherHost::OnMessageReceived(
void CacheStorageDispatcherHost::CreateCacheListener(
CacheStorageContextImpl* context) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- cache_listener_.reset(new CacheStorageListener(this, context));
context_ = context;
}
@@ -197,6 +200,121 @@ void CacheStorageDispatcherHost::OnCacheStorageMatch(
thread_id, request_id));
}
+void CacheStorageDispatcherHost::OnCacheMatch(
+ int thread_id,
+ int request_id,
+ int cache_id,
+ const ServiceWorkerFetchRequest& request,
+ const CacheStorageCacheQueryParams& match_params) {
+ IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id);
+ if (it == id_to_cache_map_.end()) {
+ Send(new CacheStorageMsg_CacheMatchError(
+ thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound));
+ return;
+ }
+
+ scoped_refptr<CacheStorageCache> cache = it->second;
+ scoped_ptr<ServiceWorkerFetchRequest> scoped_request(
+ new ServiceWorkerFetchRequest(request.url, request.method,
+ request.headers, request.referrer,
+ request.is_reload));
+ cache->Match(scoped_request.Pass(),
+ base::Bind(&CacheStorageDispatcherHost::OnCacheMatchCallback,
+ this, thread_id, request_id, cache));
+}
+
+void CacheStorageDispatcherHost::OnCacheMatchAll(
+ int thread_id,
+ int request_id,
+ int cache_id,
+ const ServiceWorkerFetchRequest& request,
+ const CacheStorageCacheQueryParams& match_params) {
+ // TODO(gavinp,jkarlin): Implement this method.
+ Send(new CacheStorageMsg_CacheMatchAllError(
+ thread_id, request_id, blink::WebServiceWorkerCacheErrorNotImplemented));
+}
+
+void CacheStorageDispatcherHost::OnCacheKeys(
+ int thread_id,
+ int request_id,
+ int cache_id,
+ const ServiceWorkerFetchRequest& request,
+ const CacheStorageCacheQueryParams& match_params) {
+ IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id);
+ if (it == id_to_cache_map_.end()) {
+ Send(new CacheStorageMsg_CacheKeysError(
+ thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound));
+ return;
+ }
+
+ scoped_refptr<CacheStorageCache> cache = it->second;
+
+ cache->Keys(base::Bind(&CacheStorageDispatcherHost::OnCacheKeysCallback, this,
+ thread_id, request_id, cache));
+}
+
+void CacheStorageDispatcherHost::OnCacheBatch(
+ int thread_id,
+ int request_id,
+ int cache_id,
+ const std::vector<CacheStorageBatchOperation>& operations) {
+ if (operations.size() != 1u) {
+ Send(new CacheStorageMsg_CacheBatchError(
+ thread_id, request_id,
+ blink::WebServiceWorkerCacheErrorNotImplemented));
+ return;
+ }
+
+ IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id);
+ if (it == id_to_cache_map_.end()) {
+ Send(new CacheStorageMsg_CacheBatchError(
+ thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound));
+ return;
+ }
+
+ const CacheStorageBatchOperation& operation = operations[0];
+
+ scoped_refptr<CacheStorageCache> cache = it->second;
+ scoped_ptr<ServiceWorkerFetchRequest> scoped_request(
+ new ServiceWorkerFetchRequest(
+ operation.request.url, operation.request.method,
+ operation.request.headers, operation.request.referrer,
+ operation.request.is_reload));
+
+ if (operation.operation_type == CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE) {
+ cache->Delete(scoped_request.Pass(),
+ base::Bind(&CacheStorageDispatcherHost::OnCacheDeleteCallback,
+ this, thread_id, request_id, cache));
+ return;
+ }
+
+ if (operation.operation_type == CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT) {
+ // We don't support streaming for cache.
+ DCHECK(operation.response.stream_url.is_empty());
+ scoped_ptr<ServiceWorkerResponse> scoped_response(new ServiceWorkerResponse(
+ operation.response.url, operation.response.status_code,
+ operation.response.status_text, operation.response.response_type,
+ operation.response.headers, operation.response.blob_uuid,
+ operation.response.blob_size, operation.response.stream_url));
+ cache->Put(scoped_request.Pass(), scoped_response.Pass(),
+ base::Bind(&CacheStorageDispatcherHost::OnCachePutCallback, this,
+ thread_id, request_id, cache));
+
+ return;
+ }
+
+ Send(new CacheStorageMsg_CacheBatchError(
+ thread_id, request_id, blink::WebServiceWorkerCacheErrorNotImplemented));
+}
+
+void CacheStorageDispatcherHost::OnCacheClosed(int cache_id) {
+ DropCacheReference(cache_id);
+}
+
+void CacheStorageDispatcherHost::OnBlobDataHandled(const std::string& uuid) {
+ DropBlobDataHandle(uuid);
+}
+
void CacheStorageDispatcherHost::OnCacheStorageHasCallback(
int thread_id,
int request_id,
@@ -225,8 +343,7 @@ void CacheStorageDispatcherHost::OnCacheStorageOpenCallback(
thread_id, request_id, ToWebServiceWorkerCacheError(error)));
return;
}
- CacheStorageListener::CacheID cache_id =
- cache_listener_->StoreCacheReference(cache);
+ CacheID cache_id = StoreCacheReference(cache);
Send(new CacheStorageMsg_CacheStorageOpenSuccess(thread_id, request_id,
cache_id));
}
@@ -276,10 +393,120 @@ void CacheStorageDispatcherHost::OnCacheStorageMatchCallback(
}
if (blob_data_handle)
- cache_listener_->StoreBlobDataHandle(blob_data_handle.Pass());
+ StoreBlobDataHandle(blob_data_handle.Pass());
Send(new CacheStorageMsg_CacheStorageMatchSuccess(thread_id, request_id,
*response));
}
+void CacheStorageDispatcherHost::OnCacheMatchCallback(
+ int thread_id,
+ int request_id,
+ const scoped_refptr<CacheStorageCache>& cache,
+ CacheStorageCache::ErrorType error,
+ scoped_ptr<ServiceWorkerResponse> response,
+ scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
+ if (error != CacheStorageCache::ERROR_TYPE_OK) {
+ Send(new CacheStorageMsg_CacheMatchError(
+ thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error)));
+ return;
+ }
+
+ if (blob_data_handle)
+ StoreBlobDataHandle(blob_data_handle.Pass());
+
+ Send(new CacheStorageMsg_CacheMatchSuccess(thread_id, request_id, *response));
+}
+
+void CacheStorageDispatcherHost::OnCacheKeysCallback(
+ int thread_id,
+ int request_id,
+ const scoped_refptr<CacheStorageCache>& cache,
+ CacheStorageCache::ErrorType error,
+ scoped_ptr<CacheStorageCache::Requests> requests) {
+ if (error != CacheStorageCache::ERROR_TYPE_OK) {
+ Send(new CacheStorageMsg_CacheKeysError(
+ thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error)));
+ return;
+ }
+
+ CacheStorageCache::Requests out;
+
+ for (CacheStorageCache::Requests::const_iterator it = requests->begin();
+ it != requests->end(); ++it) {
+ ServiceWorkerFetchRequest request(it->url, it->method, it->headers,
+ it->referrer, it->is_reload);
+ out.push_back(request);
+ }
+
+ Send(new CacheStorageMsg_CacheKeysSuccess(thread_id, request_id, out));
+}
+
+void CacheStorageDispatcherHost::OnCacheDeleteCallback(
+ int thread_id,
+ int request_id,
+ const scoped_refptr<CacheStorageCache>& cache,
+ CacheStorageCache::ErrorType error) {
+ if (error != CacheStorageCache::ERROR_TYPE_OK) {
+ Send(new CacheStorageMsg_CacheBatchError(
+ thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error)));
+ return;
+ }
+
+ Send(new CacheStorageMsg_CacheBatchSuccess(
+ thread_id, request_id, std::vector<ServiceWorkerResponse>()));
+}
+
+void CacheStorageDispatcherHost::OnCachePutCallback(
+ int thread_id,
+ int request_id,
+ const scoped_refptr<CacheStorageCache>& cache,
+ CacheStorageCache::ErrorType error,
+ scoped_ptr<ServiceWorkerResponse> response,
+ scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
+ if (error != CacheStorageCache::ERROR_TYPE_OK) {
+ Send(new CacheStorageMsg_CacheBatchError(
+ thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error)));
+ return;
+ }
+
+ if (blob_data_handle)
+ StoreBlobDataHandle(blob_data_handle.Pass());
+
+ std::vector<ServiceWorkerResponse> responses;
+ responses.push_back(*response);
+ Send(new CacheStorageMsg_CacheBatchSuccess(thread_id, request_id, responses));
+}
+
+CacheStorageDispatcherHost::CacheID
+CacheStorageDispatcherHost::StoreCacheReference(
+ const scoped_refptr<CacheStorageCache>& cache) {
+ int cache_id = next_cache_id_++;
+ id_to_cache_map_[cache_id] = cache;
+ return cache_id;
+}
+
+void CacheStorageDispatcherHost::DropCacheReference(CacheID cache_id) {
+ id_to_cache_map_.erase(cache_id);
+}
+
+void CacheStorageDispatcherHost::StoreBlobDataHandle(
+ scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
+ DCHECK(blob_data_handle);
+ std::pair<UUIDToBlobDataHandleList::iterator, bool> rv =
+ blob_handle_store_.insert(std::make_pair(
+ blob_data_handle->uuid(), std::list<storage::BlobDataHandle>()));
+ rv.first->second.push_front(storage::BlobDataHandle(*blob_data_handle));
+}
+
+void CacheStorageDispatcherHost::DropBlobDataHandle(std::string uuid) {
+ UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid);
+ if (it == blob_handle_store_.end())
+ return;
+ DCHECK(!it->second.empty());
+ it->second.pop_front();
+ if (it->second.empty())
+ blob_handle_store_.erase(it);
+}
+
} // namespace content
« no previous file with comments | « content/browser/cache_storage/cache_storage_dispatcher_host.h ('k') | content/browser/cache_storage/cache_storage_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698