OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/renderer/benchmarking_extension.h" | 5 #include "chrome/renderer/benchmarking_extension.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "content/public/common/content_switches.h" | 9 #include "content/public/common/content_switches.h" |
10 #include "content/public/renderer/render_thread.h" | 10 #include "content/public/renderer/render_thread.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 " };" | 43 " };" |
44 " this.microseconds = function() {" | 44 " this.microseconds = function() {" |
45 " var stop = stop_;" | 45 " var stop = stop_;" |
46 " if (stop == 0 && start_ != 0)" | 46 " if (stop == 0 && start_ != 0)" |
47 " stop = HiResTime();" | 47 " stop = HiResTime();" |
48 " return Math.ceil(stop - start_);" | 48 " return Math.ceil(stop - start_);" |
49 " };" | 49 " };" |
50 "}" | 50 "}" |
51 ) {} | 51 ) {} |
52 | 52 |
53 v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate( | 53 v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( |
54 v8::Isolate* isolate, | 54 v8::Isolate* isolate, |
55 v8::Handle<v8::String> name) override { | 55 v8::Local<v8::String> name) override { |
56 if (name->Equals(v8::String::NewFromUtf8(isolate, "IsSingleProcess"))) { | 56 if (name->Equals(v8::String::NewFromUtf8(isolate, "IsSingleProcess"))) { |
57 return v8::FunctionTemplate::New(isolate, IsSingleProcess); | 57 return v8::FunctionTemplate::New(isolate, IsSingleProcess); |
58 } else if (name->Equals(v8::String::NewFromUtf8(isolate, "HiResTime"))) { | 58 } else if (name->Equals(v8::String::NewFromUtf8(isolate, "HiResTime"))) { |
59 return v8::FunctionTemplate::New(isolate, HiResTime); | 59 return v8::FunctionTemplate::New(isolate, HiResTime); |
60 } | 60 } |
61 | 61 |
62 return v8::Handle<v8::FunctionTemplate>(); | 62 return v8::Local<v8::FunctionTemplate>(); |
63 } | 63 } |
64 | 64 |
65 static void IsSingleProcess(const v8::FunctionCallbackInfo<v8::Value>& args) { | 65 static void IsSingleProcess(const v8::FunctionCallbackInfo<v8::Value>& args) { |
66 args.GetReturnValue().Set(base::CommandLine::ForCurrentProcess()->HasSwitch( | 66 args.GetReturnValue().Set(base::CommandLine::ForCurrentProcess()->HasSwitch( |
67 switches::kSingleProcess)); | 67 switches::kSingleProcess)); |
68 } | 68 } |
69 | 69 |
70 static void HiResTime(const v8::FunctionCallbackInfo<v8::Value>& args) { | 70 static void HiResTime(const v8::FunctionCallbackInfo<v8::Value>& args) { |
71 args.GetReturnValue().Set( | 71 args.GetReturnValue().Set( |
72 static_cast<double>(base::TimeTicks::Now().ToInternalValue())); | 72 static_cast<double>(base::TimeTicks::Now().ToInternalValue())); |
73 } | 73 } |
74 }; | 74 }; |
75 | 75 |
76 v8::Extension* BenchmarkingExtension::Get() { | 76 v8::Extension* BenchmarkingExtension::Get() { |
77 return new BenchmarkingWrapper(); | 77 return new BenchmarkingWrapper(); |
78 } | 78 } |
79 | 79 |
80 } // namespace extensions_v8 | 80 } // namespace extensions_v8 |
OLD | NEW |