diff options
author | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-25 21:07:12 +0000 |
---|---|---|
committer | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-25 21:07:12 +0000 |
commit | 8e7f82c04b00baa250ab70c3871c11640794269b (patch) | |
tree | e76a4311612cedcc50f388c2c14831c13d447fb8 | |
parent | 895044f91ab417ddaf19f5e176d744cc76f866bb (diff) | |
download | chromium_src-8e7f82c04b00baa250ab70c3871c11640794269b.zip chromium_src-8e7f82c04b00baa250ab70c3871c11640794269b.tar.gz chromium_src-8e7f82c04b00baa250ab70c3871c11640794269b.tar.bz2 |
Move the chromium.Interval to chrome.Interval as part of the benchmarking
extension. This means that users will need to use --enable-benchmarking
to access it. It really shouldn't be part of the exposed API.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3126029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57386 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/common/extensions/docs/examples/api/messaging/timer/popup.html | 148 | ||||
-rw-r--r-- | chrome/renderer/render_thread.cc | 3 | ||||
-rw-r--r-- | webkit/extensions/v8/benchmarking_extension.cc | 29 | ||||
-rw-r--r-- | webkit/extensions/v8/interval_extension.cc | 58 | ||||
-rw-r--r-- | webkit/extensions/v8/interval_extension.h | 22 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 2 | ||||
-rw-r--r-- | webkit/support/test_webkit_client.cc | 3 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webkit_init.cc | 3 |
8 files changed, 106 insertions, 162 deletions
diff --git a/chrome/common/extensions/docs/examples/api/messaging/timer/popup.html b/chrome/common/extensions/docs/examples/api/messaging/timer/popup.html index 5f7e2b4..e20e799 100644 --- a/chrome/common/extensions/docs/examples/api/messaging/timer/popup.html +++ b/chrome/common/extensions/docs/examples/api/messaging/timer/popup.html @@ -1,71 +1,77 @@ -<head>
-<style>
-tr {
- white-space: nowrap;
-}
-.results {
- text-align: right;
- min-width: 6em;
- color: black;
-}
-</style>
-<script>
-function setChildTextNode(elementId, text) {
- document.getElementById(elementId).innerText = text;
-}
-
-// Tests the roundtrip time of sendRequest().
-function testRequest() {
- setChildTextNode("resultsRequest", "running...");
-
- chrome.tabs.getSelected(null, function(tab) {
- var timer = new chromium.Interval();
- timer.start();
-
- chrome.tabs.sendRequest(tab.id, {counter: 1}, function handler(response) {
- if (response.counter < 1000) {
- chrome.tabs.sendRequest(tab.id, {counter: response.counter}, handler);
- } else {
- timer.stop();
- var usec = Math.round(timer.microseconds() / response.counter);
- setChildTextNode("resultsRequest", usec + "usec");
- }
- });
- });
-}
-
-// Tests the roundtrip time of Port.postMessage() after opening a channel.
-function testConnect() {
- setChildTextNode("resultsConnect", "running...");
-
- chrome.tabs.getSelected(null, function(tab) {
- var timer = new chromium.Interval();
- timer.start();
-
- var port = chrome.tabs.connect(tab.id);
- port.postMessage({counter: 1});
- port.onMessage.addListener(function getResp(response) {
- if (response.counter < 1000) {
- port.postMessage({counter: response.counter});
- } else {
- timer.stop();
- var usec = Math.round(timer.microseconds() / response.counter);
- setChildTextNode("resultsConnect", usec + "usec");
- }
- });
- });
-}
-</script>
-</head>
-<body>
-<table>
- <tr>
- <td><button onclick="testRequest()">Measure sendRequest</button></td>
- <td id="resultsRequest" class="results">(results)</td>
- </tr>
- <tr>
- <td><button onclick="testConnect()">Measure postMessage</button></td>
- <td id="resultsConnect" class="results">(results)</td>
- </tr>
-</table>
-</body>
+<head> +<style> +tr { + white-space: nowrap; +} +.results { + text-align: right; + min-width: 6em; + color: black; +} +</style> +<script> +if (!chrome.benchmarking) { + alert("Warning: Looks like you forgot to run chrome with " + + " --enable-benchmarking set."); + return; +} + +function setChildTextNode(elementId, text) { + document.getElementById(elementId).innerText = text; +} + +// Tests the roundtrip time of sendRequest(). +function testRequest() { + setChildTextNode("resultsRequest", "running..."); + + chrome.tabs.getSelected(null, function(tab) { + var timer = new chrome.Interval(); + timer.start(); + + chrome.tabs.sendRequest(tab.id, {counter: 1}, function handler(response) { + if (response.counter < 1000) { + chrome.tabs.sendRequest(tab.id, {counter: response.counter}, handler); + } else { + timer.stop(); + var usec = Math.round(timer.microseconds() / response.counter); + setChildTextNode("resultsRequest", usec + "usec"); + } + }); + }); +} + +// Tests the roundtrip time of Port.postMessage() after opening a channel. +function testConnect() { + setChildTextNode("resultsConnect", "running..."); + + chrome.tabs.getSelected(null, function(tab) { + var timer = new chrome.Interval(); + timer.start(); + + var port = chrome.tabs.connect(tab.id); + port.postMessage({counter: 1}); + port.onMessage.addListener(function getResp(response) { + if (response.counter < 1000) { + port.postMessage({counter: response.counter}); + } else { + timer.stop(); + var usec = Math.round(timer.microseconds() / response.counter); + setChildTextNode("resultsConnect", usec + "usec"); + } + }); + }); +} +</script> +</head> +<body> +<table> + <tr> + <td><button onclick="testRequest()">Measure sendRequest</button></td> + <td id="resultsRequest" class="results">(results)</td> + </tr> + <tr> + <td><button onclick="testConnect()">Measure postMessage</button></td> + <td id="resultsConnect" class="results">(results)</td> + </tr> +</table> +</body> diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index ff2e1c1..c105ae3 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -87,7 +87,6 @@ #include "third_party/WebKit/WebKit/chromium/public/WebView.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" #include "v8/include/v8.h" @@ -854,8 +853,6 @@ void RenderThread::EnsureWebKitInitialized() { WebScriptController::registerExtension(extensions_v8::GearsExtension::Get()); #endif WebScriptController::registerExtension( - extensions_v8::IntervalExtension::Get()); - WebScriptController::registerExtension( extensions_v8::LoadTimesExtension::Get()); WebScriptController::registerExtension( extensions_v8::ExternalExtension::Get()); diff --git a/webkit/extensions/v8/benchmarking_extension.cc b/webkit/extensions/v8/benchmarking_extension.cc index 31bb080..1a30968 100644 --- a/webkit/extensions/v8/benchmarking_extension.cc +++ b/webkit/extensions/v8/benchmarking_extension.cc @@ -4,6 +4,7 @@ #include "base/command_line.h" #include "base/stats_table.h" +#include "base/time.h" #include "net/http/http_network_layer.h" #include "third_party/WebKit/WebKit/chromium/public/WebCache.h" #include "webkit/extensions/v8/benchmarking_extension.h" @@ -45,6 +46,26 @@ class BenchmarkingWrapper : public v8::Extension { " native function IsSingleProcess();" " return IsSingleProcess();" "};" + "chrome.Interval = function() {" + " var start_ = 0;" + " var stop_ = 0;" + " native function HiResTime();" + " this.start = function() {" + " stop_ = 0;" + " start_ = HiResTime();" + " };" + " this.stop = function() {" + " stop_ = HiResTime();" + " if (start_ == 0)" + " stop_ = 0;" + " };" + " this.microseconds = function() {" + " var stop = stop_;" + " if (stop == 0 && start_ != 0)" + " stop = HiResTime();" + " return Math.ceil(stop - start_);" + " };" + "}" ) {} virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( @@ -59,7 +80,10 @@ class BenchmarkingWrapper : public v8::Extension { return v8::FunctionTemplate::New(GetCounter); } else if (name->Equals(v8::String::New("IsSingleProcess"))) { return v8::FunctionTemplate::New(IsSingleProcess); + } else if (name->Equals(v8::String::New("HiResTime"))) { + return v8::FunctionTemplate::New(HiResTime); } + return v8::Handle<v8::FunctionTemplate>(); } @@ -99,6 +123,11 @@ class BenchmarkingWrapper : public v8::Extension { static v8::Handle<v8::Value> IsSingleProcess(const v8::Arguments& args) { return v8::Boolean::New(webkit_glue::IsSingleProcess()); } + + static v8::Handle<v8::Value> HiResTime(const v8::Arguments& args) { + return v8::Number::New( + static_cast<double>(base::TimeTicks::HighResNow().ToInternalValue())); + } }; v8::Extension* BenchmarkingExtension::Get() { diff --git a/webkit/extensions/v8/interval_extension.cc b/webkit/extensions/v8/interval_extension.cc deleted file mode 100644 index 95b69a5..0000000 --- a/webkit/extensions/v8/interval_extension.cc +++ /dev/null @@ -1,58 +0,0 @@ -// 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 "webkit/extensions/v8/interval_extension.h" -#include "base/time.h" - -namespace extensions_v8 { - -const char* kIntervalExtensionName = "v8/Interval"; - -class IntervalExtensionWrapper : public v8::Extension { - public: - IntervalExtensionWrapper() - : v8::Extension( - kIntervalExtensionName, - "var chromium;" - "if (!chromium)" - " chromium = {};" - "chromium.Interval = function() {" - " var start_ = 0;" - " var stop_ = 0;" - " native function HiResTime();" - " this.start = function() {" - " stop_ = 0;" - " start_ = HiResTime();" - " };" - " this.stop = function() {" - " stop_ = HiResTime();" - " if (start_ == 0)" - " stop_ = 0;" - " };" - " this.microseconds = function() {" - " var stop = stop_;" - " if (stop == 0 && start_ != 0)" - " stop = HiResTime();" - " return Math.ceil((stop - start_) * 1000000);" - " };" - "}") {} - - virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( - v8::Handle<v8::String> name) { - if (name->Equals(v8::String::New("HiResTime"))) { - return v8::FunctionTemplate::New(HiResTime); - } - return v8::Handle<v8::FunctionTemplate>(); - } - - static v8::Handle<v8::Value> HiResTime(const v8::Arguments& args) { - return v8::Number::New(base::Time::Now().ToDoubleT()); - } -}; - -v8::Extension* IntervalExtension::Get() { - return new IntervalExtensionWrapper(); -} - -} // namespace extensions_v8 diff --git a/webkit/extensions/v8/interval_extension.h b/webkit/extensions/v8/interval_extension.h deleted file mode 100644 index 83e37bc..0000000 --- a/webkit/extensions/v8/interval_extension.h +++ /dev/null @@ -1,22 +0,0 @@ -// 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. - -// The IntervalExtension is a v8 extension to implement a simple interval -// class for measuring microsecond intervals. - -#ifndef WEBKIT_EXTENSIONS_V8_INTERVAL_EXTENSION_H_ -#define WEBKIT_EXTENSIONS_V8_INTERVAL_EXTENSION_H_ - -#include "v8/include/v8.h" - -namespace extensions_v8 { - -class IntervalExtension { - public: - static v8::Extension* Get(); -}; - -} // namespace extensions_v8 - -#endif // WEBKIT_EXTENSIONS_V8_INTERVAL_EXTENSION_H_ diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index 40cc67d..450a870 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -353,8 +353,6 @@ '../extensions/v8/gears_extension.h', '../extensions/v8/heap_profiler_extension.cc', '../extensions/v8/heap_profiler_extension.h', - '../extensions/v8/interval_extension.cc', - '../extensions/v8/interval_extension.h', '../extensions/v8/playback_extension.cc', '../extensions/v8/playback_extension.h', '../extensions/v8/profiler_extension.cc', diff --git a/webkit/support/test_webkit_client.cc b/webkit/support/test_webkit_client.cc index c33545d..3497377 100644 --- a/webkit/support/test_webkit_client.cc +++ b/webkit/support/test_webkit_client.cc @@ -30,7 +30,6 @@ #include "webkit/database/vfs_backend.h" #include "webkit/extensions/v8/gc_extension.h" #include "webkit/extensions/v8/gears_extension.h" -#include "webkit/extensions/v8/interval_extension.h" #include "webkit/glue/simple_webmimeregistry_impl.h" #include "webkit/glue/webclipboard_impl.h" #include "webkit/glue/webkit_glue.h" @@ -67,8 +66,6 @@ TestWebKitClient::TestWebKitClient(bool unit_test_mode) WebScriptController::enableV8SingleThreadMode(); WebScriptController::registerExtension( extensions_v8::GearsExtension::Get()); - WebScriptController::registerExtension( - extensions_v8::IntervalExtension::Get()); WebKit::WebRuntimeFeatures::enableSockets(true); WebKit::WebRuntimeFeatures::enableApplicationCache(true); WebKit::WebRuntimeFeatures::enableDatabase(true); diff --git a/webkit/tools/test_shell/test_shell_webkit_init.cc b/webkit/tools/test_shell/test_shell_webkit_init.cc index c0ac404..706eaa6 100644 --- a/webkit/tools/test_shell/test_shell_webkit_init.cc +++ b/webkit/tools/test_shell/test_shell_webkit_init.cc @@ -13,7 +13,6 @@ #include "third_party/WebKit/WebKit/chromium/public/WebScriptController.h" #include "third_party/WebKit/WebKit/chromium/public/WebSecurityPolicy.h" #include "webkit/extensions/v8/gears_extension.h" -#include "webkit/extensions/v8/interval_extension.h" #include "webkit/tools/test_shell/test_shell.h" #if defined(OS_WIN) @@ -32,8 +31,6 @@ TestShellWebKitInit::TestShellWebKitInit(bool layout_test_mode) { WebKit::WebScriptController::enableV8SingleThreadMode(); WebKit::WebScriptController::registerExtension( extensions_v8::GearsExtension::Get()); - WebKit::WebScriptController::registerExtension( - extensions_v8::IntervalExtension::Get()); WebKit::WebRuntimeFeatures::enableSockets(true); WebKit::WebRuntimeFeatures::enableApplicationCache(true); WebKit::WebRuntimeFeatures::enableDatabase(true); |