diff options
-rw-r--r-- | chrome/browser/net/predictor_api.cc | 7 | ||||
-rw-r--r-- | chrome/browser/net/predictor_api.h | 3 | ||||
-rw-r--r-- | chrome/browser/net/predictor_unittest.cc | 24 | ||||
-rw-r--r-- | chrome/renderer/render_thread.cc | 10 | ||||
-rw-r--r-- | chrome/renderer/render_thread.h | 6 | ||||
-rw-r--r-- | chrome/renderer/renderer_glue.cc | 8 | ||||
-rw-r--r-- | content/browser/renderer_host/render_message_filter.cc | 33 | ||||
-rw-r--r-- | content/browser/renderer_host/render_message_filter.h | 2 | ||||
-rw-r--r-- | content/common/view_messages.h | 12 | ||||
-rw-r--r-- | webkit/extensions/v8/benchmarking_extension.cc | 24 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.h | 7 | ||||
-rw-r--r-- | webkit/support/webkit_support_glue.cc | 6 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.cc | 8 |
13 files changed, 150 insertions, 0 deletions
diff --git a/chrome/browser/net/predictor_api.cc b/chrome/browser/net/predictor_api.cc index d9a7906..232cb9f 100644 --- a/chrome/browser/net/predictor_api.cc +++ b/chrome/browser/net/predictor_api.cc @@ -381,6 +381,13 @@ void PredictorGetHtmlInfo(std::string* output) { output->append("</body></html>"); } +void ClearPredictorCache() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + if (!predictor_enabled || NULL == g_predictor) + return; + g_predictor->DiscardAllResults(); +} + //------------------------------------------------------------------------------ // This section intializes global DNS prefetch services. //------------------------------------------------------------------------------ diff --git a/chrome/browser/net/predictor_api.h b/chrome/browser/net/predictor_api.h index 8532b34..37d39e6 100644 --- a/chrome/browser/net/predictor_api.h +++ b/chrome/browser/net/predictor_api.h @@ -61,6 +61,9 @@ void PreconnectUrlAndSubresources(const GURL& url); // When displaying info in about:dns, the following API is called. void PredictorGetHtmlInfo(std::string* output); +// Destroy the predictor's internal state: referrers and work queue. +void ClearPredictorCache(); + //------------------------------------------------------------------------------ // When we navigate to a frame that may contain embedded resources, we may know // in advance some other URLs that will need to be connected to (via TCP and diff --git a/chrome/browser/net/predictor_unittest.cc b/chrome/browser/net/predictor_unittest.cc index 6eba190..951d1a7 100644 --- a/chrome/browser/net/predictor_unittest.cc +++ b/chrome/browser/net/predictor_unittest.cc @@ -585,4 +585,28 @@ TEST_F(PredictorTest, CanonicalizeUrl) { long_https.GetWithEmptyPath()); } +TEST_F(PredictorTest, DiscardPredictorResults) { + scoped_refptr<Predictor> predictor( + new Predictor(host_resolver_.get(), + default_max_queueing_delay_, + PredictorInit::kMaxSpeculativeParallelResolves, + false)); + ListValue referral_list; + predictor->SerializeReferrers(&referral_list); + EXPECT_EQ(1U, referral_list.GetSize()); + + GURL host_1("http://test_1"); + GURL host_2("http://test_2"); + predictor->LearnFromNavigation(host_1, host_2); + + predictor->SerializeReferrers(&referral_list); + EXPECT_EQ(2U, referral_list.GetSize()); + + predictor->DiscardAllResults(); + predictor->SerializeReferrers(&referral_list); + EXPECT_EQ(1U, referral_list.GetSize()); + + predictor->Shutdown(); +} + } // namespace chrome_browser_net diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index a500845..24e61ed 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -828,6 +828,16 @@ void RenderThread::ClearCache(bool preserve_ssl_host_info) { Send(new ViewHostMsg_ClearCache(preserve_ssl_host_info, &rv)); } +void RenderThread::ClearHostResolverCache() { + int rv; + Send(new ViewHostMsg_ClearHostResolverCache(&rv)); +} + +void RenderThread::ClearPredictorCache() { + int rv; + Send(new ViewHostMsg_ClearPredictorCache(&rv)); +} + void RenderThread::EnableSpdy(bool enable) { Send(new ViewHostMsg_EnableSpdy(enable)); } diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h index db542bd..4b0ae29 100644 --- a/chrome/renderer/render_thread.h +++ b/chrome/renderer/render_thread.h @@ -225,6 +225,12 @@ class RenderThread : public RenderThreadBase, // entries related to cached SSL information. void ClearCache(bool preserve_ssl_host_info); + // Sends a message to the browser to clear thed host cache. + void ClearHostResolverCache(); + + // Sends a message to the browser to clear the predictor cache. + void ClearPredictorCache(); + // Sends a message to the browser to enable/disable spdy. void EnableSpdy(bool enable); diff --git a/chrome/renderer/renderer_glue.cc b/chrome/renderer/renderer_glue.cc index 5798e80..3e40ea3 100644 --- a/chrome/renderer/renderer_glue.cc +++ b/chrome/renderer/renderer_glue.cc @@ -255,6 +255,14 @@ void ClearCache(bool preserve_ssl_host_info) { RenderThread::current()->ClearCache(preserve_ssl_host_info); } +void ClearHostResolverCache() { + RenderThread::current()->ClearHostResolverCache(); +} + +void ClearPredictorCache() { + RenderThread::current()->ClearPredictorCache(); +} + std::string GetProductVersion() { chrome::VersionInfo version_info; std::string product("Chrome/"); diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc index c29ed65..14805f4 100644 --- a/content/browser/renderer_host/render_message_filter.cc +++ b/content/browser/renderer_host/render_message_filter.cc @@ -17,6 +17,7 @@ #include "chrome/browser/download/download_types.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/net/chrome_url_request_context.h" +#include "chrome/browser/net/predictor_api.h" #include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/notifications/notifications_prefs_cache.h" #include "chrome/browser/platform_util.h" @@ -39,6 +40,7 @@ #include "content/common/view_messages.h" #include "ipc/ipc_channel_handle.h" #include "net/base/cookie_monster.h" +#include "net/base/host_resolver_impl.h" #include "net/base/io_buffer.h" #include "net/base/keygen_handler.h" #include "net/base/mime_util.h" @@ -348,6 +350,10 @@ bool RenderMessageFilter::OnMessageReceived(const IPC::Message& message, OnCloseCurrentConnections) IPC_MESSAGE_HANDLER(ViewHostMsg_SetCacheMode, OnSetCacheMode) IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ClearCache, OnClearCache) + IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ClearHostResolverCache, + OnClearHostResolverCache) + IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ClearPredictorCache, + OnClearPredictorCache) IPC_MESSAGE_HANDLER(ViewHostMsg_DidGenerateCacheableMetadata, OnCacheableMetadataAvailable) IPC_MESSAGE_HANDLER(ViewHostMsg_EnableSpdy, OnEnableSpdy) @@ -855,6 +861,33 @@ void RenderMessageFilter::OnClearCache(bool preserve_ssl_host_info, Send(reply_msg); } +void RenderMessageFilter::OnClearHostResolverCache(IPC::Message* reply_msg) { + // This function is disabled unless the user has enabled + // benchmarking extensions. + int rv = -1; + DCHECK(CheckBenchmarkingEnabled()); + net::HostResolverImpl* host_resolver_impl = + request_context_->GetURLRequestContext()-> + host_resolver()->GetAsHostResolverImpl(); + if (host_resolver_impl) { + net::HostCache* cache = host_resolver_impl->cache(); + DCHECK(cache); + cache->clear(); + rv = 0; + } + ViewHostMsg_ClearHostResolverCache::WriteReplyParams(reply_msg, rv); + Send(reply_msg); +} + +void RenderMessageFilter::OnClearPredictorCache(IPC::Message* reply_msg) { + // This function is disabled unless the user has enabled + // benchmarking extensions. + CHECK(CheckBenchmarkingEnabled()); + chrome_browser_net::ClearPredictorCache(); + ViewHostMsg_ClearPredictorCache::WriteReplyParams(reply_msg, 0); + Send(reply_msg); +} + bool RenderMessageFilter::CheckPreparsedJsCachingEnabled() const { static bool checked = false; static bool result = false; diff --git a/content/browser/renderer_host/render_message_filter.h b/content/browser/renderer_host/render_message_filter.h index 25014f8..7325a60 100644 --- a/content/browser/renderer_host/render_message_filter.h +++ b/content/browser/renderer_host/render_message_filter.h @@ -194,6 +194,8 @@ class RenderMessageFilter : public BrowserMessageFilter { void OnCloseCurrentConnections(); void OnSetCacheMode(bool enabled); void OnClearCache(bool preserve_ssl_host_info, IPC::Message* reply_msg); + void OnClearHostResolverCache(IPC::Message* reply_msg); + void OnClearPredictorCache(IPC::Message* reply_msg); void OnCacheableMetadataAvailable(const GURL& url, double expected_response_time, const std::vector<char>& data); diff --git a/content/common/view_messages.h b/content/common/view_messages.h index fa0ef4a..2ff791d 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -1852,6 +1852,18 @@ IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_ClearCache, int /* result */) // Message sent from the renderer to the browser to request that the browser +// clear the host cache. Used for debugging/testing. +// |result| is the returned status from the operation. +IPC_SYNC_MESSAGE_CONTROL0_1(ViewHostMsg_ClearHostResolverCache, + int /* result */) + +// Message sent from the renderer to the browser to request that the browser +// clear the predictor cache. Used for debugging/testing. +// |result| is the returned status from the operation. +IPC_SYNC_MESSAGE_CONTROL0_1(ViewHostMsg_ClearPredictorCache, + int /* result */) + +// Message sent from the renderer to the browser to request that the browser // enable or disable spdy. Used for debugging/testing/benchmarking. IPC_MESSAGE_CONTROL1(ViewHostMsg_EnableSpdy, bool /* enable */) diff --git a/webkit/extensions/v8/benchmarking_extension.cc b/webkit/extensions/v8/benchmarking_extension.cc index 600eafa..e622ba7 100644 --- a/webkit/extensions/v8/benchmarking_extension.cc +++ b/webkit/extensions/v8/benchmarking_extension.cc @@ -31,6 +31,14 @@ class BenchmarkingWrapper : public v8::Extension { " native function ClearCache();" " ClearCache(preserve_ssl_entries);" "};" + "chrome.benchmarking.clearHostResolverCache = function() {" + " native function ClearHostResolverCache();" + " ClearHostResolverCache();" + "};" + "chrome.benchmarking.clearPredictorCache = function() {" + " native function ClearPredictorCache();" + " ClearPredictorCache();" + "};" "chrome.benchmarking.closeConnections = function() {" " native function CloseConnections();" " CloseConnections();" @@ -75,6 +83,10 @@ class BenchmarkingWrapper : public v8::Extension { return v8::FunctionTemplate::New(CloseConnections); } else if (name->Equals(v8::String::New("ClearCache"))) { return v8::FunctionTemplate::New(ClearCache); + } else if (name->Equals(v8::String::New("ClearHostResolverCache"))) { + return v8::FunctionTemplate::New(ClearHostResolverCache); + } else if (name->Equals(v8::String::New("ClearPredictorCache"))) { + return v8::FunctionTemplate::New(ClearPredictorCache); } else if (name->Equals(v8::String::New("EnableSpdy"))) { return v8::FunctionTemplate::New(EnableSpdy); } else if (name->Equals(v8::String::New("GetCounter"))) { @@ -102,6 +114,18 @@ class BenchmarkingWrapper : public v8::Extension { return v8::Undefined(); } + static v8::Handle<v8::Value> ClearHostResolverCache( + const v8::Arguments& args) { + webkit_glue::ClearHostResolverCache(); + return v8::Undefined(); + } + + static v8::Handle<v8::Value> ClearPredictorCache( + const v8::Arguments& args) { + webkit_glue::ClearPredictorCache(); + return v8::Undefined(); + } + static v8::Handle<v8::Value> EnableSpdy(const v8::Arguments& args) { if (!args.Length() || !args[0]->IsBoolean()) return v8::Undefined(); diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h index a860888..5df4a52 100644 --- a/webkit/glue/webkit_glue.h +++ b/webkit/glue/webkit_glue.h @@ -267,6 +267,13 @@ void SetCacheMode(bool enabled); // SSL information should be purged. void ClearCache(bool preserve_ssl_host_info); +// Clear the host resolver cache. Used for debugging. +void ClearHostResolverCache(); + +// Clear the predictor cache (for DNS prefetch and preconnect). Used for +// debugging. +void ClearPredictorCache(); + // 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 562b989..522cfa9 100644 --- a/webkit/support/webkit_support_glue.cc +++ b/webkit/support/webkit_support_glue.cc @@ -75,6 +75,12 @@ void SetCacheMode(bool enabled) { void ClearCache(bool preserve_ssl_info) { } +void ClearHostResolverCache() { +} + +void ClearPredictorCache() { +} + 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 40eb490..5d9f533 100644 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -683,6 +683,14 @@ void ClearCache(bool preserve_ssl_entries) { // Used in benchmarking, Ignored for test_shell. } +void ClearHostResolverCache() { + // Used in benchmarking, Ignored for test_shell. +} + +void ClearPredictorCache() { + // Used in benchmarking, Ignored for test_shell. +} + void EnableSpdy(bool enable) { // Used in benchmarking, Ignored for test_shell. } |