summaryrefslogtreecommitdiffstats
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
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
-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
-rw-r--r--webkit/extensions/v8/benchmarking_extension.cc63
-rw-r--r--webkit/extensions/v8/benchmarking_extension.h23
-rw-r--r--webkit/glue/webkit_glue.h6
-rw-r--r--webkit/webkit.gyp2
12 files changed, 179 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
diff --git a/webkit/extensions/v8/benchmarking_extension.cc b/webkit/extensions/v8/benchmarking_extension.cc
new file mode 100644
index 0000000..e2e926d
--- /dev/null
+++ b/webkit/extensions/v8/benchmarking_extension.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "Cache.h"
+#include "webkit/extensions/v8/benchmarking_extension.h"
+#include "webkit/glue/webkit_glue.h"
+
+namespace extensions_v8 {
+
+const char* kBenchmarkingExtensionName = "v8/Benchmarking";
+
+class BenchmarkingWrapper : public v8::Extension {
+ public:
+ BenchmarkingWrapper() :
+ v8::Extension(kBenchmarkingExtensionName,
+ "if (typeof(chromium) == 'undefined') {"
+ " chromium = {};"
+ "};"
+ "if (typeof(chromium.benchmarking) == 'undefined') {"
+ " chromium.benchmarking = {};"
+ "};"
+ "chromium.benchmarking.clearCache = function() {"
+ " native function ClearCache();"
+ " ClearCache();"
+ "};"
+ "chromium.benchmarking.closeConnections = function() {"
+ " native function CloseConnections();"
+ " CloseConnections();"
+ "};") {}
+
+ virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
+ v8::Handle<v8::String> name) {
+ if (name->Equals(v8::String::New("CloseConnections"))) {
+ return v8::FunctionTemplate::New(CloseConnections);
+ } else if (name->Equals(v8::String::New("ClearCache"))) {
+ return v8::FunctionTemplate::New(ClearCache);
+ }
+ return v8::Handle<v8::FunctionTemplate>();
+ }
+
+ static v8::Handle<v8::Value> CloseConnections(const v8::Arguments& args) {
+ webkit_glue::CloseIdleConnections();
+ return v8::Undefined();
+ }
+
+ static v8::Handle<v8::Value> ClearCache(const v8::Arguments& args) {
+ // TODO(mbelshe): should be enable/disable?
+ webkit_glue::SetCacheMode(false);
+
+ // Disabling and re-enabling the cache forces it to flush.
+ WebCore::cache()->setDisabled(true);
+ WebCore::cache()->setDisabled(false);
+ return v8::Undefined();
+ }
+};
+
+v8::Extension* BenchmarkingExtension::Get() {
+ return new BenchmarkingWrapper();
+}
+
+} // namespace extensions_v8
diff --git a/webkit/extensions/v8/benchmarking_extension.h b/webkit/extensions/v8/benchmarking_extension.h
new file mode 100644
index 0000000..0ce9850
--- /dev/null
+++ b/webkit/extensions/v8/benchmarking_extension.h
@@ -0,0 +1,23 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Profiler is an extension to allow javascript access to the API for
+// an external profiler program (such as Quantify). The "External" part of the
+// name is to distinguish it from the built-in V8 Profiler.
+
+#ifndef WEBKIT_EXTENSIONS_V8_BENCHMARKING_EXTENSION_H_
+#define WEBKIT_EXTENSIONS_V8_BENCHMARKING_EXTENSION_H_
+
+#include "v8/include/v8.h"
+
+namespace extensions_v8 {
+
+class BenchmarkingExtension {
+ public:
+ static v8::Extension* Get();
+};
+
+} // namespace extensions_v8
+
+#endif // WEBKIT_EXTENSIONS_V8_BENCHMARKING_EXTENSION_H_
diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h
index 2fa9e4b..2276038 100644
--- a/webkit/glue/webkit_glue.h
+++ b/webkit/glue/webkit_glue.h
@@ -199,6 +199,12 @@ bool FindProxyForUrl(const GURL& url, std::string* proxy_list);
// the form language-country (e.g., en-US or pt-BR).
std::wstring GetWebKitLocale();
+// Close idle connections. Used for debugging.
+void CloseIdleConnections();
+
+// Enable or disable the disk cache. Used for debugging.
+void SetCacheMode(bool enabled);
+
// ---- END FUNCTIONS IMPLEMENTED BY EMBEDDER ---------------------------------
diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp
index 6a977bb..88c8373 100644
--- a/webkit/webkit.gyp
+++ b/webkit/webkit.gyp
@@ -1125,6 +1125,8 @@
'extensions/v8/playback_extension.h',
'extensions/v8/profiler_extension.cc',
'extensions/v8/profiler_extension.h',
+ 'extensions/v8/benchmarking_extension.cc',
+ 'extensions/v8/benchmarking_extension.h',
'port/bindings/v8/DOMObjectsInclude.h',
'port/bindings/v8/JSXPathNSResolver.cpp',
'port/bindings/v8/JSXPathNSResolver.h',