diff options
-rwxr-xr-x[-rw-r--r--] | chrome/browser/renderer_host/resource_message_filter.cc | 49 | ||||
-rwxr-xr-x[-rw-r--r--] | chrome/browser/renderer_host/resource_message_filter.h | 1 | ||||
-rwxr-xr-x[-rw-r--r--] | chrome/common/render_messages_internal.h | 7 | ||||
-rwxr-xr-x[-rw-r--r--] | chrome/renderer/render_thread.cc | 5 | ||||
-rwxr-xr-x[-rw-r--r--] | chrome/renderer/render_thread.h | 3 | ||||
-rwxr-xr-x[-rw-r--r--] | chrome/renderer/renderer_glue.cc | 4 | ||||
-rwxr-xr-x[-rw-r--r--] | webkit/extensions/v8/benchmarking_extension.cc | 4 | ||||
-rwxr-xr-x[-rw-r--r--] | webkit/glue/webkit_glue.h | 3 | ||||
-rwxr-xr-x[-rw-r--r--] | webkit/support/webkit_support_glue.cc | 3 | ||||
-rwxr-xr-x[-rw-r--r--] | webkit/tools/test_shell/test_shell.cc | 4 |
10 files changed, 77 insertions, 6 deletions
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index 848076d..2170c78 100644..100755 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -67,6 +67,7 @@ #include "net/base/load_flags.h" #include "net/base/mime_util.h" #include "net/base/net_errors.h" +#include "net/disk_cache/disk_cache.h" #include "net/http/http_cache.h" #include "net/http/http_transaction_factory.h" #include "net/url_request/url_request_context.h" @@ -271,6 +272,25 @@ class GetRawCookiesCompletion : public net::CompletionCallback { scoped_refptr<URLRequestContext> context_; }; +class ClearCacheCompletion : public net::CompletionCallback { + public: + ClearCacheCompletion(IPC::Message* reply_msg, + ResourceMessageFilter* filter) + : reply_msg_(reply_msg), + filter_(filter) { + } + + virtual void RunWithParams(const Tuple1<int>& params) { + ViewHostMsg_ClearCache::WriteReplyParams(reply_msg_, params.a); + filter_->Send(reply_msg_); + delete this; + } + + private: + IPC::Message* reply_msg_; + scoped_refptr<ResourceMessageFilter> filter_; +}; + void WriteFileSize(IPC::Message* reply_msg, const file_util::FileInfo& file_info) { ViewHostMsg_GetFileSize::WriteReplyParams(reply_msg, file_info.size); @@ -552,6 +572,7 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_CloseCurrentConnections, OnCloseCurrentConnections) IPC_MESSAGE_HANDLER(ViewHostMsg_SetCacheMode, OnSetCacheMode) + IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ClearCache, OnClearCache) IPC_MESSAGE_HANDLER(ViewHostMsg_DidGenerateCacheableMetadata, OnCacheableMetadataAvailable) IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetFileSize, OnGetFileSize) @@ -1345,8 +1366,32 @@ void ResourceMessageFilter::OnSetCacheMode(bool enabled) { net::HttpCache::Mode mode = enabled ? net::HttpCache::NORMAL : net::HttpCache::DISABLE; - request_context_->GetURLRequestContext()-> - http_transaction_factory()->GetCache()->set_mode(mode); + net::HttpCache* http_cache = request_context_->GetURLRequestContext()-> + http_transaction_factory()->GetCache(); + http_cache->set_mode(mode); +} + +void ResourceMessageFilter::OnClearCache(IPC::Message* reply_msg) { + // This function is disabled unless the user has enabled + // benchmarking extensions. + int rv = -1; + if (CheckBenchmarkingEnabled()) { + disk_cache::Backend* backend = request_context_->GetURLRequestContext()-> + http_transaction_factory()->GetCache()->GetCurrentBackend(); + if (backend) { + ClearCacheCompletion* callback = + new ClearCacheCompletion(reply_msg, this); + rv = backend->DoomAllEntries(callback); + if (rv == net::ERR_IO_PENDING) { + // The callback will send the reply. + return; + } + // Completed synchronously, no need for the callback. + delete callback; + } + } + ViewHostMsg_ClearCache::WriteReplyParams(reply_msg, rv); + Send(reply_msg); } bool ResourceMessageFilter::CheckPreparsedJsCachingEnabled() const { diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h index 76e1ea1..33a6d44 100644..100755 --- a/chrome/browser/renderer_host/resource_message_filter.h +++ b/chrome/browser/renderer_host/resource_message_filter.h @@ -315,6 +315,7 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, void OnCloseCurrentConnections(); void OnSetCacheMode(bool enabled); + void OnClearCache(IPC::Message* reply_msg); void OnCacheableMetadataAvailable(const GURL& url, double expected_response_time, const std::vector<char>& data); diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 35456e5..70d24c6 100644..100755 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -2120,11 +2120,16 @@ IPC_BEGIN_MESSAGES(ViewHost) IPC_MESSAGE_CONTROL0(ViewHostMsg_CloseCurrentConnections) // Message sent from the renderer to the browser to request that the browser - // close all idle sockets. Used for debugging/testing. + // enable or disable the cache. Used for debugging/testing. IPC_MESSAGE_CONTROL1(ViewHostMsg_SetCacheMode, bool /* enabled */) // Message sent from the renderer to the browser to request that the browser + // clear the cache. Used for debugging/testing. + IPC_SYNC_MESSAGE_CONTROL0_1(ViewHostMsg_ClearCache, + int /* result */) + + // 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 */, diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index 767fc37..d69de4d 100644..100755 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -693,6 +693,11 @@ void RenderThread::SetCacheMode(bool enabled) { Send(new ViewHostMsg_SetCacheMode(enabled)); } +void RenderThread::ClearCache() { + int rv; + Send(new ViewHostMsg_ClearCache(&rv)); +} + void RenderThread::UpdateActiveExtensions() { // In single-process mode, the browser process reports the active extensions. if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h index a02a0b9..d59f4ff 100644..100755 --- a/chrome/renderer/render_thread.h +++ b/chrome/renderer/render_thread.h @@ -174,6 +174,9 @@ class RenderThread : public RenderThreadBase, // Sends a message to the browser to enable or disable the disk cache. void SetCacheMode(bool enabled); + // Sends a message to the browser to clear the disk cache. + void ClearCache(); + // Update the list of active extensions that will be reported when we crash. void UpdateActiveExtensions(); diff --git a/chrome/renderer/renderer_glue.cc b/chrome/renderer/renderer_glue.cc index c2b4d0d..87c9049 100644..100755 --- a/chrome/renderer/renderer_glue.cc +++ b/chrome/renderer/renderer_glue.cc @@ -268,6 +268,10 @@ void SetCacheMode(bool enabled) { RenderThread::current()->SetCacheMode(enabled); } +void ClearCache() { + RenderThread::current()->ClearCache(); +} + std::string GetProductVersion() { scoped_ptr<FileVersionInfo> version_info( chrome_app::GetChromeVersionInfo()); diff --git a/webkit/extensions/v8/benchmarking_extension.cc b/webkit/extensions/v8/benchmarking_extension.cc index bac4677..362a928 100644..100755 --- a/webkit/extensions/v8/benchmarking_extension.cc +++ b/webkit/extensions/v8/benchmarking_extension.cc @@ -55,9 +55,7 @@ class BenchmarkingWrapper : public v8::Extension { } static v8::Handle<v8::Value> ClearCache(const v8::Arguments& args) { - // TODO(mbelshe): should be enable/disable? - webkit_glue::SetCacheMode(false); - + webkit_glue::ClearCache(); WebCache::clear(); return v8::Undefined(); } diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h index f8095d9..8f6b42c 100644..100755 --- a/webkit/glue/webkit_glue.h +++ b/webkit/glue/webkit_glue.h @@ -242,6 +242,9 @@ void CloseCurrentConnections(); // Enable or disable the disk cache. Used for debugging. void SetCacheMode(bool enabled); +// Clear the disk cache. Used for debugging. +void ClearCache(); + // Returns the product version. E.g., Chrome/4.1.333.0 std::string GetProductVersion(); diff --git a/webkit/support/webkit_support_glue.cc b/webkit/support/webkit_support_glue.cc index 5f11be0..28bf904 100644..100755 --- a/webkit/support/webkit_support_glue.cc +++ b/webkit/support/webkit_support_glue.cc @@ -51,6 +51,9 @@ void CloseCurrentConnections() { void SetCacheMode(bool enabled) { } +void ClearCache() { +} + std::string GetProductVersion() { return std::string("DumpRenderTree/0.0.0.0"); } diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index f921a96..14e092a 100644..100755 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -807,6 +807,10 @@ void SetCacheMode(bool enabled) { // Used in benchmarking, Ignored for test_shell. } +void ClearCache() { + // Used in benchmarking, Ignored for test_shell. +} + std::string GetProductVersion() { return std::string("Chrome/0.0.0.0"); } |