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
Esse commit está contido em:
mbelshe@google.com
2009-06-05 07:33:21 +00:00
commit b63520da3c
12 arquivos alterados com 179 adições e 0 exclusões
@@ -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);
}
@@ -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
+3
Ver Arquivo
@@ -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
+2
Ver Arquivo
@@ -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
+10
Ver Arquivo
@@ -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)
+12
Ver Arquivo
@@ -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)) {
+6
Ver Arquivo
@@ -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);
+7
Ver Arquivo
@@ -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
@@ -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
@@ -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_
+6
Ver Arquivo
@@ -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 ---------------------------------
+2
Ver Arquivo
@@ -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',