From b808eb6f0f47a7c4ad15dd8ec115404ce14b47b6 Mon Sep 17 00:00:00 2001 From: "tonyg@chromium.org" Date: Tue, 18 May 2010 17:09:33 +0000 Subject: Wire sending/receiving cacheable metadata from the renderer to the disk cache. BUG=32407 TEST=None Review URL: http://codereview.chromium.org/1698001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47522 0039d316-1c4b-4281-b951-d872f2087c98 --- .../renderer_host/async_resource_handler.cc | 9 ++++++ .../renderer_host/resource_message_filter.cc | 32 +++++++++++++++++++++- .../renderer_host/resource_message_filter.h | 7 +++-- 3 files changed, 45 insertions(+), 3 deletions(-) (limited to 'chrome/browser/renderer_host') diff --git a/chrome/browser/renderer_host/async_resource_handler.cc b/chrome/browser/renderer_host/async_resource_handler.cc index a4a3494..30df3a2 100644 --- a/chrome/browser/renderer_host/async_resource_handler.cc +++ b/chrome/browser/renderer_host/async_resource_handler.cc @@ -124,6 +124,15 @@ bool AsyncResourceHandler::OnResponseStarted(int request_id, receiver_->Send(new ViewMsg_Resource_ReceivedResponse( routing_id_, request_id, response->response_head)); + + if (request->response_info().metadata) { + std::vector copy(request->response_info().metadata->data(), + request->response_info().metadata->data() + + request->response_info().metadata->size()); + receiver_->Send(new ViewMsg_Resource_ReceivedCachedMetadata( + routing_id_, request_id, copy)); + } + return true; } diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index d27ec21..7de83a7 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -548,6 +548,8 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_CloseCurrentConnections, OnCloseCurrentConnections) IPC_MESSAGE_HANDLER(ViewHostMsg_SetCacheMode, OnSetCacheMode) + IPC_MESSAGE_HANDLER(ViewHostMsg_DidGenerateCacheableMetadata, + OnCacheableMetadataAvailable) IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetFileSize, OnGetFileSize) IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetFileModificationTime, OnGetFileModificationTime) @@ -1300,7 +1302,7 @@ void ResourceMessageFilter::OnOpenChannelToTab( } } -bool ResourceMessageFilter::CheckBenchmarkingEnabled() { +bool ResourceMessageFilter::CheckBenchmarkingEnabled() const { static bool checked = false; static bool result = false; if (!checked) { @@ -1332,6 +1334,34 @@ void ResourceMessageFilter::OnSetCacheMode(bool enabled) { http_transaction_factory()->GetCache()->set_mode(mode); } +bool ResourceMessageFilter::CheckPreparsedJsCachingEnabled() const { + static bool checked = false; + static bool result = false; + if (!checked) { + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + result = command_line.HasSwitch(switches::kEnablePreparsedJsCaching); + checked = true; + } + return result; +} + +void ResourceMessageFilter::OnCacheableMetadataAvailable( + const GURL& url, + double expected_response_time, + const std::vector& data) { + if (!CheckPreparsedJsCachingEnabled()) + return; + + net::HttpCache* cache = request_context_->GetURLRequestContext()-> + http_transaction_factory()->GetCache(); + DCHECK(cache); + + scoped_refptr buf = new net::IOBuffer(data.size()); + memcpy(buf->data(), &data.front(), data.size()); + cache->WriteMetadata( + url, base::Time::FromDoubleT(expected_response_time), buf, data.size()); +} + void ResourceMessageFilter::OnGetFileSize(const FilePath& path, IPC::Message* reply_msg) { // Get file size only when the child process has been granted permission to diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h index e3e9ef6..76e1ea1 100644 --- a/chrome/browser/renderer_host/resource_message_filter.h +++ b/chrome/browser/renderer_host/resource_message_filter.h @@ -315,7 +315,9 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, void OnCloseCurrentConnections(); void OnSetCacheMode(bool enabled); - + void OnCacheableMetadataAvailable(const GURL& url, + double expected_response_time, + const std::vector& data); void OnGetFileSize(const FilePath& path, IPC::Message* reply_msg); void OnGetFileModificationTime(const FilePath& path, IPC::Message* reply_msg); void OnGetFileInfoOnFileThread(const FilePath& path, @@ -352,7 +354,8 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, void DoOnAllocateTempFileForPrinting(IPC::Message* reply_msg); #endif - bool CheckBenchmarkingEnabled(); + bool CheckBenchmarkingEnabled() const; + bool CheckPreparsedJsCachingEnabled() const; // We have our own clipboard because we want to access the clipboard on the // IO thread instead of forwarding (possibly synchronous) messages to the UI -- cgit v1.1