From 8093a58b34fb9d08c0bc84ef6e425da5eadfca97 Mon Sep 17 00:00:00 2001 From: "danhn@chromium.org" Date: Fri, 15 Feb 2013 17:57:21 +0000 Subject: Fixed browser crash when Telemetry uses Debug build. Factored out chrome.benchmarking methods which don't depend on stats table. BUG=168640 TEST=tools/telemetry/run_tests --browser=debug PageRunnerTests Review URL: https://chromiumcodereview.appspot.com/11801024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182754 0039d316-1c4b-4281-b951-d872f2087c98 --- .../browser/chrome_benchmarking_message_filter.cc | 169 -------------------- .../browser/chrome_benchmarking_message_filter.h | 55 ------- chrome/browser/chrome_content_browser_client.cc | 11 +- .../chrome_net_benchmarking_message_filter.cc | 170 +++++++++++++++++++++ .../chrome_net_benchmarking_message_filter.h | 56 +++++++ chrome/chrome_browser.gypi | 4 +- chrome/chrome_renderer.gypi | 2 + chrome/common/chrome_switches.cc | 3 + chrome/common/chrome_switches.h | 1 + chrome/renderer/benchmarking_extension.cc | 76 +-------- chrome/renderer/chrome_content_renderer_client.cc | 3 + chrome/renderer/net_benchmarking_extension.cc | 110 +++++++++++++ chrome/renderer/net_benchmarking_extension.h | 19 +++ .../telemetry/telemetry/desktop_browser_backend.py | 21 ++- 14 files changed, 391 insertions(+), 309 deletions(-) delete mode 100644 chrome/browser/chrome_benchmarking_message_filter.cc delete mode 100644 chrome/browser/chrome_benchmarking_message_filter.h create mode 100644 chrome/browser/chrome_net_benchmarking_message_filter.cc create mode 100644 chrome/browser/chrome_net_benchmarking_message_filter.h create mode 100644 chrome/renderer/net_benchmarking_extension.cc create mode 100644 chrome/renderer/net_benchmarking_extension.h diff --git a/chrome/browser/chrome_benchmarking_message_filter.cc b/chrome/browser/chrome_benchmarking_message_filter.cc deleted file mode 100644 index 5be4df1..0000000 --- a/chrome/browser/chrome_benchmarking_message_filter.cc +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright (c) 2012 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 "chrome/browser/chrome_benchmarking_message_filter.h" - -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/command_line.h" -#include "base/memory/scoped_ptr.h" -#include "chrome/browser/net/chrome_url_request_context.h" -#include "chrome/browser/net/predictor.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/common/benchmarking_messages.h" -#include "chrome/common/chrome_switches.h" -#include "net/base/host_cache.h" -#include "net/base/host_resolver.h" -#include "net/base/net_errors.h" -#include "net/disk_cache/disk_cache.h" -#include "net/http/http_cache.h" -#include "net/http/http_network_layer.h" -#include "net/http/http_stream_factory.h" - -namespace { - -void ClearCacheCallback(ChromeBenchmarkingMessageFilter* filter, - IPC::Message* reply_msg, - int result) { - ChromeViewHostMsg_ClearCache::WriteReplyParams(reply_msg, result); - filter->Send(reply_msg); -} - -} // namespace - -ChromeBenchmarkingMessageFilter::ChromeBenchmarkingMessageFilter( - int render_process_id, - Profile* profile, - net::URLRequestContextGetter* request_context) - : render_process_id_(render_process_id), - profile_(profile), - request_context_(request_context) { -} - -ChromeBenchmarkingMessageFilter::~ChromeBenchmarkingMessageFilter() { -} - -bool ChromeBenchmarkingMessageFilter::OnMessageReceived( - const IPC::Message& message, bool* message_was_ok) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP_EX(ChromeBenchmarkingMessageFilter, message, - *message_was_ok) - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CloseCurrentConnections, - OnCloseCurrentConnections) - IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_ClearCache, OnClearCache) - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ClearHostResolverCache, - OnClearHostResolverCache) - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_EnableSpdy, OnEnableSpdy) - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ClearPredictorCache, - OnClearPredictorCache) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP_EX() - return handled; -} - -void ChromeBenchmarkingMessageFilter::OnClearCache(IPC::Message* reply_msg) { - // This function is disabled unless the user has enabled - // benchmarking extensions. - if (!CheckBenchmarkingEnabled()) { - NOTREACHED() << "Received unexpected benchmarking IPC"; - return; - } - int rv = -1; - - disk_cache::Backend* backend = request_context_->GetURLRequestContext()-> - http_transaction_factory()->GetCache()->GetCurrentBackend(); - if (backend) { - net::CompletionCallback callback = - base::Bind(&ClearCacheCallback, make_scoped_refptr(this), reply_msg); - rv = backend->DoomAllEntries(callback); - if (rv == net::ERR_IO_PENDING) { - // The callback will send the reply. - return; - } - } - ChromeViewHostMsg_ClearCache::WriteReplyParams(reply_msg, rv); - Send(reply_msg); -} - -void ChromeBenchmarkingMessageFilter::OnClearHostResolverCache(int* result) { - // This function is disabled unless the user has enabled - // benchmarking extensions. - if (!CheckBenchmarkingEnabled()) { - NOTREACHED() << "Received unexpected benchmarking IPC"; - return; - } - *result = -1; - net::HostCache* cache = - request_context_->GetURLRequestContext()->host_resolver()->GetHostCache(); - if (cache) { - cache->clear(); - *result = 0; - } -} - -// TODO(lzheng): This only enables spdy over ssl. Enable spdy for http -// when needed. -void ChromeBenchmarkingMessageFilter::OnEnableSpdy(bool enable) { - // This function is disabled unless the user has enabled - // benchmarking extensions. - if (!CheckBenchmarkingEnabled()) { - NOTREACHED() << "Received unexpected benchmarking IPC"; - return; - } - if (enable) { - net::HttpStreamFactory::EnableNpnSpdy(); - net::HttpNetworkLayer::ForceAlternateProtocol(); - } else { - net::HttpStreamFactory::EnableNpnHttpOnly(); - } -} - -void ChromeBenchmarkingMessageFilter::OnCloseCurrentConnections() { - // This function is disabled unless the user has enabled - // benchmarking extensions. - if (!CheckBenchmarkingEnabled()) { - NOTREACHED() << "Received unexpected benchmarking IPC"; - return; - } - request_context_->GetURLRequestContext()-> - http_transaction_factory()->GetCache()->CloseAllConnections(); -} - -void ChromeBenchmarkingMessageFilter::OnSetCacheMode(bool enabled) { - // This function is disabled unless the user has enabled - // benchmarking extensions. - if (!CheckBenchmarkingEnabled()) { - NOTREACHED() << "Received unexpected benchmarking IPC"; - return; - } - net::HttpCache::Mode mode = enabled ? - net::HttpCache::NORMAL : net::HttpCache::DISABLE; - net::HttpCache* http_cache = request_context_->GetURLRequestContext()-> - http_transaction_factory()->GetCache(); - http_cache->set_mode(mode); -} - -void ChromeBenchmarkingMessageFilter::OnClearPredictorCache(int* result) { - // This function is disabled unless the user has enabled - // benchmarking extensions. - if (!CheckBenchmarkingEnabled()) { - NOTREACHED() << "Received unexpected benchmarking IPC"; - return; - } - chrome_browser_net::Predictor* predictor = profile_->GetNetworkPredictor(); - if (predictor) - predictor->DiscardAllResults(); - *result = 0; -} - -bool ChromeBenchmarkingMessageFilter::CheckBenchmarkingEnabled() const { - 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; -} diff --git a/chrome/browser/chrome_benchmarking_message_filter.h b/chrome/browser/chrome_benchmarking_message_filter.h deleted file mode 100644 index ca1ae0f..0000000 --- a/chrome/browser/chrome_benchmarking_message_filter.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef CHROME_BROWSER_CHROME_BENCHMARKING_MESSAGE_FILTER_H_ -#define CHROME_BROWSER_CHROME_BENCHMARKING_MESSAGE_FILTER_H_ - -#include "content/public/browser/browser_message_filter.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" - -namespace net { -class URLRequestContextGetter; -} - -class Profile; - -// This class filters out incoming Chrome-specific benchmarking IPC messages -// for the renderer process on the IPC thread. -class ChromeBenchmarkingMessageFilter : public content::BrowserMessageFilter { - public: - ChromeBenchmarkingMessageFilter( - int render_process_id, - Profile* profile, - net::URLRequestContextGetter* request_context); - - // content::BrowserMessageFilter methods: - virtual bool OnMessageReceived(const IPC::Message& message, - bool* message_was_ok) OVERRIDE; - - private: - virtual ~ChromeBenchmarkingMessageFilter(); - - // Message handlers. - void OnCloseCurrentConnections(); - void OnClearCache(IPC::Message* reply_msg); - void OnClearHostResolverCache(int* result); - void OnEnableSpdy(bool enable); - void OnSetCacheMode(bool enabled); - void OnClearPredictorCache(int* result); - - // Returns true if benchmarking is enabled for chrome. - bool CheckBenchmarkingEnabled() const; - - int render_process_id_; - - // The Profile associated with our renderer process. This should only be - // accessed on the UI thread! - Profile* profile_; - scoped_refptr request_context_; - - DISALLOW_COPY_AND_ASSIGN(ChromeBenchmarkingMessageFilter); -}; - -#endif // CHROME_BROWSER_CHROME_BENCHMARKING_MESSAGE_FILTER_H_ - diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 9c126c7..e1908ec 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -20,7 +20,7 @@ #include "chrome/browser/browsing_data/browsing_data_helper.h" #include "chrome/browser/browsing_data/browsing_data_remover.h" #include "chrome/browser/character_encoding.h" -#include "chrome/browser/chrome_benchmarking_message_filter.h" +#include "chrome/browser/chrome_net_benchmarking_message_filter.h" #include "chrome/browser/chrome_quota_permission_context.h" #include "chrome/browser/content_settings/content_settings_utils.h" #include "chrome/browser/content_settings/cookie_settings.h" @@ -648,8 +648,11 @@ void ChromeContentBrowserClient::RenderProcessHostCreated( content::RenderProcessHost* host) { int id = host->GetID(); Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); + net::URLRequestContextGetter* context = + profile->GetRequestContextForRenderProcess(id); + host->GetChannel()->AddFilter(new ChromeRenderMessageFilter( - id, profile, profile->GetRequestContextForRenderProcess(id))); + id, profile, context)); #if defined(ENABLE_PLUGINS) host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile)); #endif @@ -662,8 +665,8 @@ void ChromeContentBrowserClient::RenderProcessHostCreated( #if defined(OS_MACOSX) host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac()); #endif - host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter( - id, profile, profile->GetRequestContextForRenderProcess(id))); + host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter( + id, profile, context)); host->GetChannel()->AddFilter( new prerender::PrerenderMessageFilter(id, profile)); diff --git a/chrome/browser/chrome_net_benchmarking_message_filter.cc b/chrome/browser/chrome_net_benchmarking_message_filter.cc new file mode 100644 index 0000000..abe3652 --- /dev/null +++ b/chrome/browser/chrome_net_benchmarking_message_filter.cc @@ -0,0 +1,170 @@ +// Copyright (c) 2012 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 "chrome/browser/chrome_net_benchmarking_message_filter.h" + +#include "base/bind.h" +#include "base/bind_helpers.h" +#include "base/command_line.h" +#include "base/memory/scoped_ptr.h" +#include "chrome/browser/net/chrome_url_request_context.h" +#include "chrome/browser/net/predictor.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/common/benchmarking_messages.h" +#include "chrome/common/chrome_switches.h" +#include "net/base/host_cache.h" +#include "net/base/host_resolver.h" +#include "net/base/net_errors.h" +#include "net/disk_cache/disk_cache.h" +#include "net/http/http_cache.h" +#include "net/http/http_network_layer.h" +#include "net/http/http_stream_factory.h" + +namespace { + +void ClearCacheCallback(ChromeNetBenchmarkingMessageFilter* filter, + IPC::Message* reply_msg, + int result) { + ChromeViewHostMsg_ClearCache::WriteReplyParams(reply_msg, result); + filter->Send(reply_msg); +} + +} // namespace + +ChromeNetBenchmarkingMessageFilter::ChromeNetBenchmarkingMessageFilter( + int render_process_id, + Profile* profile, + net::URLRequestContextGetter* request_context) + : render_process_id_(render_process_id), + profile_(profile), + request_context_(request_context) { +} + +ChromeNetBenchmarkingMessageFilter::~ChromeNetBenchmarkingMessageFilter() { +} + +bool ChromeNetBenchmarkingMessageFilter::OnMessageReceived( + const IPC::Message& message, bool* message_was_ok) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP_EX(ChromeNetBenchmarkingMessageFilter, message, + *message_was_ok) + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CloseCurrentConnections, + OnCloseCurrentConnections) + IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_ClearCache, OnClearCache) + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ClearHostResolverCache, + OnClearHostResolverCache) + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_EnableSpdy, OnEnableSpdy) + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ClearPredictorCache, + OnClearPredictorCache) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP_EX() + return handled; +} + +void ChromeNetBenchmarkingMessageFilter::OnClearCache(IPC::Message* reply_msg) { + // This function is disabled unless the user has enabled + // benchmarking extensions. + if (!CheckBenchmarkingEnabled()) { + NOTREACHED() << "Received unexpected benchmarking IPC"; + return; + } + int rv = -1; + + disk_cache::Backend* backend = request_context_->GetURLRequestContext()-> + http_transaction_factory()->GetCache()->GetCurrentBackend(); + if (backend) { + net::CompletionCallback callback = + base::Bind(&ClearCacheCallback, make_scoped_refptr(this), reply_msg); + rv = backend->DoomAllEntries(callback); + if (rv == net::ERR_IO_PENDING) { + // The callback will send the reply. + return; + } + } + ChromeViewHostMsg_ClearCache::WriteReplyParams(reply_msg, rv); + Send(reply_msg); +} + +void ChromeNetBenchmarkingMessageFilter::OnClearHostResolverCache(int* result) { + // This function is disabled unless the user has enabled + // benchmarking extensions. + if (!CheckBenchmarkingEnabled()) { + NOTREACHED() << "Received unexpected benchmarking IPC"; + return; + } + *result = -1; + net::HostCache* cache = + request_context_->GetURLRequestContext()->host_resolver()->GetHostCache(); + if (cache) { + cache->clear(); + *result = 0; + } +} + +// TODO(lzheng): This only enables spdy over ssl. Enable spdy for http +// when needed. +void ChromeNetBenchmarkingMessageFilter::OnEnableSpdy(bool enable) { + // This function is disabled unless the user has enabled + // benchmarking extensions. + if (!CheckBenchmarkingEnabled()) { + NOTREACHED() << "Received unexpected benchmarking IPC"; + return; + } + if (enable) { + net::HttpStreamFactory::EnableNpnSpdy(); + net::HttpNetworkLayer::ForceAlternateProtocol(); + } else { + net::HttpStreamFactory::EnableNpnHttpOnly(); + } +} + +void ChromeNetBenchmarkingMessageFilter::OnCloseCurrentConnections() { + // This function is disabled unless the user has enabled + // benchmarking extensions. + if (!CheckBenchmarkingEnabled()) { + NOTREACHED() << "Received unexpected benchmarking IPC"; + return; + } + request_context_->GetURLRequestContext()-> + http_transaction_factory()->GetCache()->CloseAllConnections(); +} + +void ChromeNetBenchmarkingMessageFilter::OnSetCacheMode(bool enabled) { + // This function is disabled unless the user has enabled + // benchmarking extensions. + if (!CheckBenchmarkingEnabled()) { + NOTREACHED() << "Received unexpected benchmarking IPC"; + return; + } + net::HttpCache::Mode mode = enabled ? + net::HttpCache::NORMAL : net::HttpCache::DISABLE; + net::HttpCache* http_cache = request_context_->GetURLRequestContext()-> + http_transaction_factory()->GetCache(); + http_cache->set_mode(mode); +} + +void ChromeNetBenchmarkingMessageFilter::OnClearPredictorCache(int* result) { + // This function is disabled unless the user has enabled + // benchmarking extensions. + if (!CheckBenchmarkingEnabled()) { + NOTREACHED() << "Received unexpected benchmarking IPC"; + return; + } + chrome_browser_net::Predictor* predictor = profile_->GetNetworkPredictor(); + if (predictor) + predictor->DiscardAllResults(); + *result = 0; +} + +bool ChromeNetBenchmarkingMessageFilter::CheckBenchmarkingEnabled() const { + static bool checked = false; + static bool result = false; + if (!checked) { + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + result = command_line.HasSwitch(switches::kEnableNetBenchmarking); + checked = true; + } + return result; +} + diff --git a/chrome/browser/chrome_net_benchmarking_message_filter.h b/chrome/browser/chrome_net_benchmarking_message_filter.h new file mode 100644 index 0000000..6fa1d99 --- /dev/null +++ b/chrome/browser/chrome_net_benchmarking_message_filter.h @@ -0,0 +1,56 @@ +// Copyright (c) 2011 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. + +#ifndef CHROME_BROWSER_CHROME_NET_BENCHMARKING_MESSAGE_FILTER_H_ +#define CHROME_BROWSER_CHROME_NET_BENCHMARKING_MESSAGE_FILTER_H_ + +#include "content/public/browser/browser_message_filter.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" + +namespace net { +class URLRequestContextGetter; +} + +class Profile; + +// This class filters out incoming Chrome-specific benchmarking IPC messages +// for the renderer process on the IPC thread. +class ChromeNetBenchmarkingMessageFilter + : public content::BrowserMessageFilter { + public: + ChromeNetBenchmarkingMessageFilter( + int render_process_id, + Profile* profile, + net::URLRequestContextGetter* request_context); + + // content::BrowserMessageFilter methods: + virtual bool OnMessageReceived(const IPC::Message& message, + bool* message_was_ok) OVERRIDE; + + private: + virtual ~ChromeNetBenchmarkingMessageFilter(); + + // Message handlers. + void OnCloseCurrentConnections(); + void OnClearCache(IPC::Message* reply_msg); + void OnClearHostResolverCache(int* result); + void OnEnableSpdy(bool enable); + void OnSetCacheMode(bool enabled); + void OnClearPredictorCache(int* result); + + // Returns true if benchmarking is enabled for chrome. + bool CheckBenchmarkingEnabled() const; + + int render_process_id_; + + // The Profile associated with our renderer process. This should only be + // accessed on the UI thread! + Profile* profile_; + scoped_refptr request_context_; + + DISALLOW_COPY_AND_ASSIGN(ChromeNetBenchmarkingMessageFilter); +}; + +#endif // CHROME_BROWSER_CHROME_NET_BENCHMARKING_MESSAGE_FILTER_H_ + diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 7f8130d..adde372 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -425,8 +425,8 @@ 'browser/certificate_viewer.h', 'browser/character_encoding.cc', 'browser/character_encoding.h', - 'browser/chrome_benchmarking_message_filter.cc', - 'browser/chrome_benchmarking_message_filter.h', + 'browser/chrome_net_benchmarking_message_filter.cc', + 'browser/chrome_net_benchmarking_message_filter.h', 'browser/chrome_browser_application_mac.h', 'browser/chrome_browser_application_mac.mm', 'browser/chrome_browser_field_trials.cc', diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi index d7aabab..3db7244 100644 --- a/chrome/chrome_renderer.gypi +++ b/chrome/chrome_renderer.gypi @@ -140,6 +140,8 @@ 'renderer/net/predictor_queue.h', 'renderer/net/renderer_net_predictor.cc', 'renderer/net/renderer_net_predictor.h', + 'renderer/net_benchmarking_extension.cc', + 'renderer/net_benchmarking_extension.h', 'renderer/one_click_signin_agent.cc', 'renderer/one_click_signin_agent.h', 'renderer/playback_extension.cc', diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index f3620aa..dacabd4 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -562,6 +562,9 @@ const char kEnableNaClExceptionHandling[] = "enable-nacl-exception-handling"; // Enables the native messaging extensions API. const char kEnableNativeMessaging[] = "enable-native-messaging"; +// Enables the network-related benchmarking extensions. +const char kEnableNetBenchmarking[] = "enable-net-benchmarking"; + // Enables the new Autofill UI, which is part of the browser process rather than // part of the renderer process. http://crbug.com/51644 const char kEnableNewAutofillUi[] = "enable-new-autofill-ui"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 0d2d837..1cc0c8c 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -159,6 +159,7 @@ extern const char kEnableNaCl[]; extern const char kEnableNaClDebug[]; extern const char kEnableNaClExceptionHandling[]; extern const char kEnableNativeMessaging[]; +extern const char kEnableNetBenchmarking[]; extern const char kEnableNewAutofillHeuristics[]; extern const char kEnableNewAutofillUi[]; extern const char kEnableNpn[]; diff --git a/chrome/renderer/benchmarking_extension.cc b/chrome/renderer/benchmarking_extension.cc index 1125550..7572a40 100644 --- a/chrome/renderer/benchmarking_extension.cc +++ b/chrome/renderer/benchmarking_extension.cc @@ -7,14 +7,10 @@ #include "base/command_line.h" #include "base/metrics/stats_table.h" #include "base/time.h" -#include "chrome/common/benchmarking_messages.h" #include "content/public/common/content_switches.h" #include "content/public/renderer/render_thread.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" #include "v8/include/v8.h" -using WebKit::WebCache; - const char kBenchmarkingExtensionName[] = "v8/Benchmarking"; namespace extensions_v8 { @@ -29,30 +25,10 @@ class BenchmarkingWrapper : public v8::Extension { "if (typeof(chrome.benchmarking) == 'undefined') {" " chrome.benchmarking = {};" "};" - "chrome.benchmarking.clearCache = function() {" - " native function ClearCache();" - " ClearCache();" - "};" - "chrome.benchmarking.clearHostResolverCache = function() {" - " native function ClearHostResolverCache();" - " ClearHostResolverCache();" - "};" - "chrome.benchmarking.clearPredictorCache = function() {" - " native function ClearPredictorCache();" - " ClearPredictorCache();" - "};" - "chrome.benchmarking.closeConnections = function() {" - " native function CloseConnections();" - " CloseConnections();" - "};" "chrome.benchmarking.counter = function(name) {" " native function GetCounter();" " return GetCounter(name);" "};" - "chrome.benchmarking.enableSpdy = function(name) {" - " native function EnableSpdy();" - " EnableSpdy(name);" - "};" "chrome.benchmarking.isSingleProcess = function() {" " native function IsSingleProcess();" " return IsSingleProcess();" @@ -80,18 +56,8 @@ class BenchmarkingWrapper : public v8::Extension { ) {} virtual v8::Handle GetNativeFunction( - v8::Handle name) OVERRIDE { - 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); - } 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"))) { + v8::Handle name) { + if (name->Equals(v8::String::New("GetCounter"))) { return v8::FunctionTemplate::New(GetCounter); } else if (name->Equals(v8::String::New("IsSingleProcess"))) { return v8::FunctionTemplate::New(IsSingleProcess); @@ -102,44 +68,6 @@ class BenchmarkingWrapper : public v8::Extension { return v8::Handle(); } - static v8::Handle CloseConnections(const v8::Arguments& args) { - content::RenderThread::Get()->Send( - new ChromeViewHostMsg_CloseCurrentConnections()); - return v8::Undefined(); - } - - static v8::Handle ClearCache(const v8::Arguments& args) { - int rv; - content::RenderThread::Get()->Send(new ChromeViewHostMsg_ClearCache(&rv)); - WebCache::clear(); - return v8::Undefined(); - } - - static v8::Handle ClearHostResolverCache( - const v8::Arguments& args) { - int rv; - content::RenderThread::Get()->Send( - new ChromeViewHostMsg_ClearHostResolverCache(&rv)); - return v8::Undefined(); - } - - static v8::Handle ClearPredictorCache( - const v8::Arguments& args) { - int rv; - content::RenderThread::Get()->Send( - new ChromeViewHostMsg_ClearPredictorCache(&rv)); - return v8::Undefined(); - } - - static v8::Handle EnableSpdy(const v8::Arguments& args) { - if (!args.Length() || !args[0]->IsBoolean()) - return v8::Undefined(); - - content::RenderThread::Get()->Send(new ChromeViewHostMsg_EnableSpdy( - args[0]->BooleanValue())); - return v8::Undefined(); - } - static v8::Handle GetCounter(const v8::Arguments& args) { if (!args.Length() || !args[0]->IsString() || !base::StatsTable::current()) return v8::Undefined(); diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc index 9932f4b..bb74b7b 100644 --- a/chrome/renderer/chrome_content_renderer_client.cc +++ b/chrome/renderer/chrome_content_renderer_client.cc @@ -47,6 +47,7 @@ #include "chrome/renderer/external_extension.h" #include "chrome/renderer/loadtimes_extension_bindings.h" #include "chrome/renderer/net/renderer_net_predictor.h" +#include "chrome/renderer/net_benchmarking_extension.h" #include "chrome/renderer/one_click_signin_agent.h" #include "chrome/renderer/page_click_tracker.h" #include "chrome/renderer/page_load_histograms.h" @@ -225,6 +226,8 @@ void ChromeContentRendererClient::RenderThreadStarted() { CommandLine* command_line = CommandLine::ForCurrentProcess(); if (command_line->HasSwitch(switches::kEnableBenchmarking)) thread->RegisterExtension(extensions_v8::BenchmarkingExtension::Get()); + if (command_line->HasSwitch(switches::kEnableNetBenchmarking)) + thread->RegisterExtension(extensions_v8::NetBenchmarkingExtension::Get()); if (command_line->HasSwitch(switches::kPlaybackMode) || command_line->HasSwitch(switches::kRecordMode) || diff --git a/chrome/renderer/net_benchmarking_extension.cc b/chrome/renderer/net_benchmarking_extension.cc new file mode 100644 index 0000000..9fb0581 --- /dev/null +++ b/chrome/renderer/net_benchmarking_extension.cc @@ -0,0 +1,110 @@ +// Copyright (c) 2013 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 "chrome/renderer/net_benchmarking_extension.h" + +#include "chrome/common/benchmarking_messages.h" +#include "content/public/renderer/render_thread.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" +#include "v8/include/v8.h" + +using WebKit::WebCache; + +const char kNetBenchmarkingExtensionName[] = "v8/NetBenchmarking"; + +namespace extensions_v8 { + +class NetBenchmarkingWrapper : public v8::Extension { + public: + NetBenchmarkingWrapper() : + v8::Extension(kNetBenchmarkingExtensionName, + "if (typeof(chrome) == 'undefined') {" + " chrome = {};" + "};" + "if (typeof(chrome.benchmarking) == 'undefined') {" + " chrome.benchmarking = {};" + "};" + "chrome.benchmarking.clearCache = function() {" + " native function ClearCache();" + " ClearCache();" + "};" + "chrome.benchmarking.clearHostResolverCache = function() {" + " native function ClearHostResolverCache();" + " ClearHostResolverCache();" + "};" + "chrome.benchmarking.clearPredictorCache = function() {" + " native function ClearPredictorCache();" + " ClearPredictorCache();" + "};" + "chrome.benchmarking.closeConnections = function() {" + " native function CloseConnections();" + " CloseConnections();" + "};" + "chrome.benchmarking.enableSpdy = function(name) {" + " native function EnableSpdy();" + " EnableSpdy(name);" + "};" + ) {} + + virtual v8::Handle GetNativeFunction( + v8::Handle name) { + 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("CloseConnections"))) { + return v8::FunctionTemplate::New(CloseConnections); + } + + return v8::Handle(); + } + + static v8::Handle ClearCache(const v8::Arguments& args) { + int rv; + content::RenderThread::Get()->Send(new ChromeViewHostMsg_ClearCache(&rv)); + WebCache::clear(); + return v8::Undefined(); + } + + static v8::Handle ClearHostResolverCache( + const v8::Arguments& args) { + int rv; + content::RenderThread::Get()->Send( + new ChromeViewHostMsg_ClearHostResolverCache(&rv)); + return v8::Undefined(); + } + + static v8::Handle ClearPredictorCache( + const v8::Arguments& args) { + int rv; + content::RenderThread::Get()->Send( + new ChromeViewHostMsg_ClearPredictorCache(&rv)); + return v8::Undefined(); + } + + static v8::Handle CloseConnections(const v8::Arguments& args) { + content::RenderThread::Get()->Send( + new ChromeViewHostMsg_CloseCurrentConnections()); + return v8::Undefined(); + } + + static v8::Handle EnableSpdy(const v8::Arguments& args) { + if (!args.Length() || !args[0]->IsBoolean()) + return v8::Undefined(); + + content::RenderThread::Get()->Send(new ChromeViewHostMsg_EnableSpdy( + args[0]->BooleanValue())); + return v8::Undefined(); + } +}; + +v8::Extension* NetBenchmarkingExtension::Get() { + return new NetBenchmarkingWrapper(); +} + +} // namespace extensions_v8 diff --git a/chrome/renderer/net_benchmarking_extension.h b/chrome/renderer/net_benchmarking_extension.h new file mode 100644 index 0000000..f3083d3 --- /dev/null +++ b/chrome/renderer/net_benchmarking_extension.h @@ -0,0 +1,19 @@ +// Copyright (c) 2013 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. + +#ifndef CHROME_RENDERER_NET_BENCHMARKING_EXTENSION_H_ +#define CHROME_RENDERER_NET_BENCHMARKING_EXTENSION_H_ + +#include "chrome/renderer/benchmarking_extension.h" + +namespace extensions_v8 { + +class NetBenchmarkingExtension { + public: + static v8::Extension* Get(); +}; + +} // namespace extensions_v8 + +#endif // CHROME_RENDERER_NET_BENCHMARKING_EXTENSION_H_ diff --git a/tools/telemetry/telemetry/desktop_browser_backend.py b/tools/telemetry/telemetry/desktop_browser_backend.py index cb4d7c92..31ccc3f 100644 --- a/tools/telemetry/telemetry/desktop_browser_backend.py +++ b/tools/telemetry/telemetry/desktop_browser_backend.py @@ -2,6 +2,7 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import os as os +import re import subprocess as subprocess import shutil import tempfile @@ -52,11 +53,15 @@ class DesktopBrowserBackend(browser_backend.BrowserBackend): def GetBrowserStartupArgs(self): args = super(DesktopBrowserBackend, self).GetBrowserStartupArgs() args.append('--remote-debugging-port=%i' % self._port) - args.append('--window-size=1280,1024') - args.append('--enable-benchmarking') - if not self.options.dont_override_profile: - self._tmpdir = tempfile.mkdtemp() - args.append('--user-data-dir=%s' % self._tmpdir) + if not self.is_content_shell: + args.append('--window-size=1280,1024') + if self._GetChromeBranchNumber() >= 1404: + args.append('--enable-net-benchmarking') + else: + args.append('--enable-benchmarking') + if not self.options.dont_override_profile: + self._tmpdir = tempfile.mkdtemp() + args.append('--user-data-dir=%s' % self._tmpdir) return args def IsBrowserRunning(self): @@ -113,6 +118,12 @@ class DesktopBrowserBackend(browser_backend.BrowserBackend): def CreateForwarder(self, *port_pairs): return DoNothingForwarder(*port_pairs) + def _GetChromeBranchNumber(self): + version = subprocess.check_output([self._executable, '--version']) + match = re.match('[^\d]+\s+\d+\.\d+\.(\d+)\.\d+.*', version) + assert match + return int(match.group(1)) + class DoNothingForwarder(object): def __init__(self, *port_pairs): self._host_port = port_pairs[0].local_port -- cgit v1.1