summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortonyg@chromium.org <tonyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-18 17:09:33 +0000
committertonyg@chromium.org <tonyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-18 17:09:33 +0000
commitb808eb6f0f47a7c4ad15dd8ec115404ce14b47b6 (patch)
tree8315454562119f7591028e5f13bb528abb1dc9ef
parentcadf9b3f3fc8844f95b467afd40a2abf3cd615f9 (diff)
downloadchromium_src-b808eb6f0f47a7c4ad15dd8ec115404ce14b47b6.zip
chromium_src-b808eb6f0f47a7c4ad15dd8ec115404ce14b47b6.tar.gz
chromium_src-b808eb6f0f47a7c4ad15dd8ec115404ce14b47b6.tar.bz2
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
-rw-r--r--chrome/browser/renderer_host/async_resource_handler.cc9
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc32
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.h7
-rw-r--r--chrome/common/chrome_switches.cc3
-rw-r--r--chrome/common/chrome_switches.h1
-rw-r--r--chrome/common/render_messages_internal.h12
-rw-r--r--chrome/common/resource_dispatcher.cc21
-rw-r--r--chrome/common/resource_dispatcher.h1
-rw-r--r--chrome/renderer/renderer_webkitclient_impl.cc27
-rw-r--r--chrome/renderer/renderer_webkitclient_impl.h4
10 files changed, 114 insertions, 3 deletions
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<char> 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<char>& data) {
+ if (!CheckPreparsedJsCachingEnabled())
+ return;
+
+ net::HttpCache* cache = request_context_->GetURLRequestContext()->
+ http_transaction_factory()->GetCache();
+ DCHECK(cache);
+
+ scoped_refptr<net::IOBuffer> 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<char>& 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
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 0713882..ae6691c 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -324,6 +324,9 @@ const char kEnableNativeWebWorkers[] = "enable-native-web-workers";
// Enable speculative TCP/IP preconnection.
const char kEnablePreconnect[] = "enable-preconnect";
+// Enable caching of pre-parsed JS script data. See http://crbug.com/32407.
+const char kEnablePreparsedJsCaching[] = "enable-preparsed-js-caching";
+
// Enable Privacy Blacklists.
const char kEnablePrivacyBlacklists[] = "enable-privacy-blacklists";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 1167178..8c67aa2 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -105,6 +105,7 @@ extern const char kEnableLogging[];
extern const char kEnableMonitorProfile[];
extern const char kEnableNaCl[];
extern const char kEnableNativeWebWorkers[];
+extern const char kEnablePreparsedJsCaching[];
extern const char kEnablePreconnect[];
extern const char kEnablePrivacyBlacklists[];
extern const char kEnableRendererAccessibility[];
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index db1907d..c7fa4de 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -273,6 +273,11 @@ IPC_BEGIN_MESSAGES(View)
int /* request_id */,
ResourceResponseHead)
+ // Sent when cached metadata from a resource request is ready.
+ IPC_MESSAGE_ROUTED2(ViewMsg_Resource_ReceivedCachedMetadata,
+ int /* request_id */,
+ std::vector<char> /* data */)
+
// Sent as download progress is being made, size of the resource may be
// unknown, in that case |size| is -1.
IPC_MESSAGE_ROUTED3(ViewMsg_Resource_DownloadProgress,
@@ -2097,6 +2102,13 @@ IPC_BEGIN_MESSAGES(ViewHost)
IPC_MESSAGE_CONTROL1(ViewHostMsg_SetCacheMode,
bool /* enabled */)
+ // Message sent from the renderer to the browser to request that the browser
+ // cache |data| associated with |url|.
+ IPC_MESSAGE_CONTROL3(ViewHostMsg_DidGenerateCacheableMetadata,
+ GURL /* url */,
+ double /* expected_response_time */,
+ std::vector<char> /* data */)
+
// Get the storage area id for a particular origin within a namespace.
IPC_SYNC_MESSAGE_CONTROL2_1(ViewHostMsg_DOMStorageStorageAreaId,
int64 /* namespace_id */,
diff --git a/chrome/common/resource_dispatcher.cc b/chrome/common/resource_dispatcher.cc
index b0d2918..b8f306c 100644
--- a/chrome/common/resource_dispatcher.cc
+++ b/chrome/common/resource_dispatcher.cc
@@ -367,6 +367,24 @@ void ResourceDispatcher::OnReceivedResponse(
peer->OnReceivedResponse(response_head, false);
}
+void ResourceDispatcher::OnReceivedCachedMetadata(
+ int request_id, const std::vector<char>& data) {
+ PendingRequestList::iterator it = pending_requests_.find(request_id);
+ if (it == pending_requests_.end()) {
+ // this might happen for kill()ed requests on the webkit end, so perhaps
+ // it shouldn't be a warning...
+ DLOG(WARNING) << "Got metadata for a nonexistant or finished request";
+ return;
+ }
+
+ if (data.size()) {
+ PendingRequestInfo& request_info = it->second;
+ RESOURCE_LOG("Dispatching " << data.size() << " metadata bytes for " <<
+ request_info.peer->GetURLForDebugging().possibly_invalid_spec());
+ request_info.peer->OnReceivedCachedMetadata(&data.front(), data.size());
+ }
+}
+
void ResourceDispatcher::OnReceivedData(const IPC::Message& message,
int request_id,
base::SharedMemoryHandle shm_handle,
@@ -528,6 +546,8 @@ void ResourceDispatcher::DispatchMessage(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message)
IPC_MESSAGE_HANDLER(ViewMsg_Resource_UploadProgress, OnUploadProgress)
IPC_MESSAGE_HANDLER(ViewMsg_Resource_ReceivedResponse, OnReceivedResponse)
+ IPC_MESSAGE_HANDLER(
+ ViewMsg_Resource_ReceivedCachedMetadata, OnReceivedCachedMetadata)
IPC_MESSAGE_HANDLER(ViewMsg_Resource_ReceivedRedirect, OnReceivedRedirect)
IPC_MESSAGE_HANDLER(ViewMsg_Resource_DataReceived, OnReceivedData)
IPC_MESSAGE_HANDLER(ViewMsg_Resource_RequestComplete, OnRequestComplete)
@@ -579,6 +599,7 @@ bool ResourceDispatcher::IsResourceDispatcherMessage(
switch (message.type()) {
case ViewMsg_Resource_UploadProgress::ID:
case ViewMsg_Resource_ReceivedResponse::ID:
+ case ViewMsg_Resource_ReceivedCachedMetadata::ID:
case ViewMsg_Resource_ReceivedRedirect::ID:
case ViewMsg_Resource_DataReceived::ID:
case ViewMsg_Resource_RequestComplete::ID:
diff --git a/chrome/common/resource_dispatcher.h b/chrome/common/resource_dispatcher.h
index ab5ab81..cf050a2 100644
--- a/chrome/common/resource_dispatcher.h
+++ b/chrome/common/resource_dispatcher.h
@@ -91,6 +91,7 @@ class ResourceDispatcher {
int64 position,
int64 size);
void OnReceivedResponse(int request_id, const ResourceResponseHead&);
+ void OnReceivedCachedMetadata(int request_id, const std::vector<char>& data);
void OnReceivedRedirect(
const IPC::Message& message,
int request_id,
diff --git a/chrome/renderer/renderer_webkitclient_impl.cc b/chrome/renderer/renderer_webkitclient_impl.cc
index bc3c0c9..7135038 100644
--- a/chrome/renderer/renderer_webkitclient_impl.cc
+++ b/chrome/renderer/renderer_webkitclient_impl.cc
@@ -135,6 +135,33 @@ void RendererWebKitClientImpl::prefetchHostName(const WebString& hostname) {
}
}
+bool RendererWebKitClientImpl::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 RendererWebKitClientImpl::cacheMetadata(
+ const WebKit::WebURL& url,
+ double response_time,
+ const char* data,
+ size_t size) {
+ if (!CheckPreparsedJsCachingEnabled())
+ return;
+
+ // Let the browser know we generated cacheable metadata for this resource. The
+ // browser may cache it and return it on subsequent responses to speed
+ // the processing of this resource.
+ std::vector<char> copy(data, data + size);
+ RenderThread::current()->Send(new ViewHostMsg_DidGenerateCacheableMetadata(
+ url, response_time, copy));
+}
+
WebString RendererWebKitClientImpl::defaultLocale() {
// TODO(darin): Eliminate this webkit_glue call.
return WideToUTF16(webkit_glue::GetWebKitLocale());
diff --git a/chrome/renderer/renderer_webkitclient_impl.h b/chrome/renderer/renderer_webkitclient_impl.h
index 82c40295..17e706f 100644
--- a/chrome/renderer/renderer_webkitclient_impl.h
+++ b/chrome/renderer/renderer_webkitclient_impl.h
@@ -43,6 +43,8 @@ class RendererWebKitClientImpl : public webkit_glue::WebKitClientImpl {
virtual bool isLinkVisited(unsigned long long linkHash);
virtual WebKit::WebMessagePortChannel* createMessagePortChannel();
virtual void prefetchHostName(const WebKit::WebString&);
+ virtual void cacheMetadata(
+ const WebKit::WebURL&, double, const char*, size_t);
virtual WebKit::WebString defaultLocale();
virtual void suddenTerminationChanged(bool enabled);
virtual WebKit::WebStorageNamespace* createLocalStorageNamespace(
@@ -88,6 +90,8 @@ class RendererWebKitClientImpl : public webkit_glue::WebKitClientImpl {
int mode);
};
+ bool CheckPreparsedJsCachingEnabled() const;
+
#if defined(OS_WIN)
class SandboxSupport : public WebKit::WebSandboxSupport {
public: