Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / chrome / renderer / net_benchmarking_extension.cc
blobf3621f44e04ea2c2c0e9d00325077942ce702caf
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/renderer/net_benchmarking_extension.h"
7 #include "chrome/common/benchmarking_messages.h"
8 #include "content/public/renderer/render_thread.h"
9 #include "third_party/WebKit/public/web/WebCache.h"
10 #include "v8/include/v8.h"
12 using blink::WebCache;
14 const char kNetBenchmarkingExtensionName[] = "v8/NetBenchmarking";
16 namespace extensions_v8 {
18 class NetBenchmarkingWrapper : public v8::Extension {
19 public:
20 NetBenchmarkingWrapper() :
21 v8::Extension(kNetBenchmarkingExtensionName,
22 "if (typeof(chrome) == 'undefined') {"
23 " chrome = {};"
24 "};"
25 "if (typeof(chrome.benchmarking) == 'undefined') {"
26 " chrome.benchmarking = {};"
27 "};"
28 "chrome.benchmarking.clearCache = function() {"
29 " native function ClearCache();"
30 " ClearCache();"
31 "};"
32 "chrome.benchmarking.clearHostResolverCache = function() {"
33 " native function ClearHostResolverCache();"
34 " ClearHostResolverCache();"
35 "};"
36 "chrome.benchmarking.clearPredictorCache = function() {"
37 " native function ClearPredictorCache();"
38 " ClearPredictorCache();"
39 "};"
40 "chrome.benchmarking.closeConnections = function() {"
41 " native function CloseConnections();"
42 " CloseConnections();"
43 "};"
44 ) {}
46 v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate(
47 v8::Isolate* isolate,
48 v8::Handle<v8::String> name) override {
49 if (name->Equals(v8::String::NewFromUtf8(isolate, "ClearCache"))) {
50 return v8::FunctionTemplate::New(isolate, ClearCache);
51 } else if (name->Equals(v8::String::NewFromUtf8(
52 isolate, "ClearHostResolverCache"))) {
53 return v8::FunctionTemplate::New(isolate, ClearHostResolverCache);
54 } else if (name->Equals(
55 v8::String::NewFromUtf8(isolate, "ClearPredictorCache"))) {
56 return v8::FunctionTemplate::New(isolate, ClearPredictorCache);
57 } else if (name->Equals(
58 v8::String::NewFromUtf8(isolate, "CloseConnections"))) {
59 return v8::FunctionTemplate::New(isolate, CloseConnections);
62 return v8::Handle<v8::FunctionTemplate>();
65 static void ClearCache(const v8::FunctionCallbackInfo<v8::Value>& args) {
66 int rv;
67 content::RenderThread::Get()->Send(new ChromeViewHostMsg_ClearCache(&rv));
68 WebCache::clear();
71 static void ClearHostResolverCache(
72 const v8::FunctionCallbackInfo<v8::Value>& args) {
73 content::RenderThread::Get()->Send(
74 new ChromeViewHostMsg_ClearHostResolverCache());
77 static void ClearPredictorCache(
78 const v8::FunctionCallbackInfo<v8::Value>& args) {
79 content::RenderThread::Get()->Send(
80 new ChromeViewHostMsg_ClearPredictorCache());
83 static void CloseConnections(
84 const v8::FunctionCallbackInfo<v8::Value>& args) {
85 content::RenderThread::Get()->Send(
86 new ChromeViewHostMsg_CloseCurrentConnections());
90 v8::Extension* NetBenchmarkingExtension::Get() {
91 return new NetBenchmarkingWrapper();
94 } // namespace extensions_v8