summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authormbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-05 07:33:21 +0000
committermbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-05 07:33:21 +0000
commitb07f2909abb3f48f25a0e96f2a41b55199023375 (patch)
tree6fcd75248dfe672a8f9e87c4b1504ab235d7013e /chrome
parentafb14af4fd9db9c357b391c1cbb6b95e25bb82a3 (diff)
downloadchromium_src-b07f2909abb3f48f25a0e96f2a41b55199023375.zip
chromium_src-b07f2909abb3f48f25a0e96f2a41b55199023375.tar.gz
chromium_src-b07f2909abb3f48f25a0e96f2a41b55199023375.tar.bz2
Add an extension to expose some primitives to JS for doing
benchmarking from within Chrome. Because the JS resides in the renderer and the HTTP logic resides in the browser, this required creation of two new, control messages which can be sent from the renderer to the browser. These are controlled under a new commandline option "--enable-benchmarking" BUG=6754 TEST=none Review URL: http://codereview.chromium.org/119191 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17722 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc40
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.h5
-rw-r--r--chrome/common/chrome_switches.cc3
-rw-r--r--chrome/common/chrome_switches.h2
-rw-r--r--chrome/common/render_messages_internal.h10
-rw-r--r--chrome/renderer/render_thread.cc12
-rw-r--r--chrome/renderer/render_thread.h6
-rw-r--r--chrome/renderer/renderer_glue.cc7
8 files changed, 85 insertions, 0 deletions
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index 6a28e81..a37f683 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/renderer_host/resource_message_filter.h"
#include "base/clipboard.h"
+#include "base/command_line.h"
#include "base/gfx/native_widget_types.h"
#include "base/histogram.h"
#include "base/process_util.h"
@@ -23,6 +24,7 @@
#include "chrome/common/app_cache/app_cache_dispatcher_host.h"
#include "chrome/common/chrome_plugin_lib.h"
#include "chrome/common/chrome_plugin_util.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/common/histogram_synchronizer.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
@@ -32,6 +34,8 @@
#include "net/base/cookie_monster.h"
#include "net/base/mime_util.h"
#include "net/base/load_flags.h"
+#include "net/http/http_cache.h"
+#include "net/http/http_transaction_factory.h"
#include "net/url_request/url_request_context.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/glue/webplugin.h"
@@ -303,6 +307,11 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& message) {
#endif
IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToExtension,
OnOpenChannelToExtension)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_CloseIdleConnections,
+ OnCloseIdleConnections)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_SetCacheMode,
+ OnSetCacheMode)
+
IPC_MESSAGE_UNHANDLED(
handled = false)
IPC_END_MESSAGE_MAP_EX()
@@ -852,3 +861,34 @@ void ResourceMessageFilter::OnOpenChannelToExtension(
*port_id = ExtensionMessageService::GetInstance(request_context_.get())->
OpenChannelToExtension(routing_id, extension_id, this);
}
+
+bool ResourceMessageFilter::CheckBenchmarkingEnabled() {
+ static bool checked = false;
+ static bool result = false;
+ if (!checked) {
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ result = command_line.HasSwitch(switches::kEnableBenchmarking);
+ checked = true;
+ }
+ return result;
+}
+
+void ResourceMessageFilter::OnCloseIdleConnections() {
+ // This function is disabled unless the user has enabled
+ // benchmarking extensions.
+ if (!CheckBenchmarkingEnabled())
+ return;
+ request_context_->
+ http_transaction_factory()->GetCache()->CloseIdleConnections();
+}
+
+void ResourceMessageFilter::OnSetCacheMode(bool enabled) {
+ // This function is disabled unless the user has enabled
+ // benchmarking extensions.
+ if (!CheckBenchmarkingEnabled())
+ return;
+
+ net::HttpCache::Mode mode = enabled ?
+ net::HttpCache::NORMAL : net::HttpCache::DISABLE;
+ request_context_->http_transaction_factory()->GetCache()->set_mode(mode);
+}
diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h
index 9e23079..784cc44 100644
--- a/chrome/browser/renderer_host/resource_message_filter.h
+++ b/chrome/browser/renderer_host/resource_message_filter.h
@@ -211,6 +211,9 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
void OnOpenChannelToExtension(int routing_id,
const std::string& extension_id, int* port_id);
+ void OnCloseIdleConnections();
+ void OnSetCacheMode(bool enabled);
+
#if defined(OS_LINUX)
void SendDelayedReply(IPC::Message* reply_msg);
void DoOnGetScreenInfo(gfx::NativeViewId view, IPC::Message* reply_msg);
@@ -223,6 +226,8 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
void DoOnClipboardReadHTML(IPC::Message* reply_msg);
#endif
+ bool CheckBenchmarkingEnabled();
+
// 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
// thread. This instance of the clipboard should be accessed only on the IO
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index a319b70..78ad058 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -481,4 +481,7 @@ const wchar_t kNewNewTabPage[] = L"new-new-tab-page";
// to avoid having the default browser info-bar displayed.
const wchar_t kNoDefaultBrowserCheck[] = L"no-default-browser-check";
+// Enables the benchmarking extensions.
+const wchar_t kEnableBenchmarking[] = L"enable-benchmarking";
+
} // namespace switches
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 955eafa..2432050 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -179,6 +179,8 @@ extern const wchar_t kForceFieldTestNameAndValue[];
extern const wchar_t kNewNewTabPage[];
+extern const wchar_t kEnableBenchmarking[];
+
extern const wchar_t kNoDefaultBrowserCheck[];
} // namespace switches
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 2b47570..b5a28d2 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -1401,6 +1401,15 @@ IPC_BEGIN_MESSAGES(ViewHost)
IPC_MESSAGE_ROUTED1(ViewHostMsg_AccessibilityFocusChange,
int /* accessibility object id */)
+ // Message sent from the renderer to the browser to request that the browser
+ // close all idle sockets. Used for debugging/testing.
+ IPC_MESSAGE_CONTROL0(ViewHostMsg_CloseIdleConnections)
+
+ // Message sent from the renderer to the browser to request that the browser
+ // close all idle sockets. Used for debugging/testing.
+ IPC_MESSAGE_CONTROL1(ViewHostMsg_SetCacheMode,
+ bool /* enabled */)
+
//---------------------------------------------------------------------------
// Utility process host messages:
// These are messages from the utility process to the browser. They're here
@@ -1418,4 +1427,5 @@ IPC_BEGIN_MESSAGES(ViewHost)
// |error_message| is a user-displayable explanation of what went wrong.
IPC_MESSAGE_CONTROL1(UtilityHostMsg_UnpackExtension_Failed,
std::string /* error_message, if any */)
+
IPC_END_MESSAGES(ViewHost)
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc
index 0072972..3a0e739 100644
--- a/chrome/renderer/render_thread.cc
+++ b/chrome/renderer/render_thread.cc
@@ -41,6 +41,7 @@
#include "webkit/api/public/WebCache.h"
#include "webkit/api/public/WebKit.h"
#include "webkit/api/public/WebString.h"
+#include "webkit/extensions/v8/benchmarking_extension.h"
#include "webkit/extensions/v8/gears_extension.h"
#include "webkit/extensions/v8/interval_extension.h"
#include "webkit/extensions/v8/playback_extension.h"
@@ -296,6 +297,14 @@ void RenderThread::InformHostOfCacheStatsLater() {
kCacheStatsDelayMS);
}
+void RenderThread::CloseIdleConnections() {
+ Send(new ViewHostMsg_CloseIdleConnections());
+}
+
+void RenderThread::SetCacheMode(bool enabled) {
+ Send(new ViewHostMsg_SetCacheMode(enabled));
+}
+
static void* CreateHistogram(
const char *name, int min, int max, size_t buckets) {
Histogram* histogram = new Histogram(name, min, max, buckets);
@@ -350,6 +359,9 @@ void RenderThread::EnsureWebKitInitialized() {
WebKit::registerExtension(RendererExtensionBindings::Get());
}
+ if (command_line.HasSwitch(switches::kEnableBenchmarking))
+ WebKit::registerExtension(extensions_v8::BenchmarkingExtension::Get());
+
if (command_line.HasSwitch(switches::kPlaybackMode) ||
command_line.HasSwitch(switches::kRecordMode) ||
command_line.HasSwitch(switches::kNoJsRandomness)) {
diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h
index 0e7a3c8..7935a32 100644
--- a/chrome/renderer/render_thread.h
+++ b/chrome/renderer/render_thread.h
@@ -103,6 +103,12 @@ class RenderThread : public RenderThreadBase,
// bookkeeping operation off the critical latency path.
void InformHostOfCacheStatsLater();
+ // Sends a message to the browser to close all idle connections.
+ void CloseIdleConnections();
+
+ // Sends a message to the browser to enable or disable the disk cache.
+ void SetCacheMode(bool enabled);
+
private:
virtual void OnControlMessageReceived(const IPC::Message& msg);
diff --git a/chrome/renderer/renderer_glue.cc b/chrome/renderer/renderer_glue.cc
index e5fddd3..be7893d 100644
--- a/chrome/renderer/renderer_glue.cc
+++ b/chrome/renderer/renderer_glue.cc
@@ -240,5 +240,12 @@ void NotifyCacheStats() {
RenderThread::current()->InformHostOfCacheStatsLater();
}
+void CloseIdleConnections() {
+ RenderThread::current()->CloseIdleConnections();
+}
+
+void SetCacheMode(bool enabled) {
+ RenderThread::current()->SetCacheMode(enabled);
+}
} // namespace webkit_glue