OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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/net_benchmarking_extension.h" | 5 #include "chrome/renderer/net_benchmarking_extension.h" |
6 | 6 |
7 #include "chrome/common/benchmarking_messages.h" | 7 #include "chrome/common/net_benchmarking.mojom.h" |
8 #include "content/public/renderer/render_thread.h" | 8 #include "content/public/renderer/render_thread.h" |
9 #include "services/service_manager/public/cpp/interface_provider.h" | |
9 #include "third_party/WebKit/public/web/WebCache.h" | 10 #include "third_party/WebKit/public/web/WebCache.h" |
10 #include "v8/include/v8.h" | 11 #include "v8/include/v8.h" |
11 | 12 |
12 using blink::WebCache; | 13 using blink::WebCache; |
13 | 14 |
14 const char kNetBenchmarkingExtensionName[] = "v8/NetBenchmarking"; | 15 const char kNetBenchmarkingExtensionName[] = "v8/NetBenchmarking"; |
15 | 16 |
16 namespace extensions_v8 { | 17 namespace extensions_v8 { |
17 | 18 |
18 class NetBenchmarkingWrapper : public v8::Extension { | 19 class NetBenchmarkingWrapper : public v8::Extension { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 v8::String::NewFromUtf8(isolate, "ClearPredictorCache"))) { | 56 v8::String::NewFromUtf8(isolate, "ClearPredictorCache"))) { |
56 return v8::FunctionTemplate::New(isolate, ClearPredictorCache); | 57 return v8::FunctionTemplate::New(isolate, ClearPredictorCache); |
57 } else if (name->Equals( | 58 } else if (name->Equals( |
58 v8::String::NewFromUtf8(isolate, "CloseConnections"))) { | 59 v8::String::NewFromUtf8(isolate, "CloseConnections"))) { |
59 return v8::FunctionTemplate::New(isolate, CloseConnections); | 60 return v8::FunctionTemplate::New(isolate, CloseConnections); |
60 } | 61 } |
61 | 62 |
62 return v8::Local<v8::FunctionTemplate>(); | 63 return v8::Local<v8::FunctionTemplate>(); |
63 } | 64 } |
64 | 65 |
66 static chrome::mojom::NetBenchmarking& GetNetBenchmarking() { | |
67 CR_DEFINE_STATIC_LOCAL(chrome::mojom::NetBenchmarkingPtr, net_benchmarking, | |
68 (ConnectToBrowser())); | |
69 return *net_benchmarking; | |
70 } | |
71 | |
72 static chrome::mojom::NetBenchmarkingPtr ConnectToBrowser() { | |
73 chrome::mojom::NetBenchmarkingPtr net_benchmarking; | |
74 content::RenderThread::Get()->GetRemoteInterfaces()->GetInterface( | |
75 &net_benchmarking); | |
76 return net_benchmarking; | |
77 } | |
78 | |
65 static void ClearCache(const v8::FunctionCallbackInfo<v8::Value>& args) { | 79 static void ClearCache(const v8::FunctionCallbackInfo<v8::Value>& args) { |
66 int rv; | 80 int rv; |
67 content::RenderThread::Get()->Send(new ChromeViewHostMsg_ClearCache(&rv)); | 81 GetNetBenchmarking().ClearCache(&rv); |
68 WebCache::clear(); | 82 WebCache::clear(); |
69 } | 83 } |
70 | 84 |
71 static void ClearHostResolverCache( | 85 static void ClearHostResolverCache( |
72 const v8::FunctionCallbackInfo<v8::Value>& args) { | 86 const v8::FunctionCallbackInfo<v8::Value>& args) { |
73 content::RenderThread::Get()->Send( | 87 chrome::mojom::NetBenchmarking::ClearHostResolverCacheCallback callback; |
74 new ChromeViewHostMsg_ClearHostResolverCache()); | 88 GetNetBenchmarking().ClearHostResolverCache(callback); |
Sam McNally
2016/12/12 22:57:04
Change the rest of these calls to use the sync ver
dvallet
2016/12/13 00:22:18
Done. Gotcha, I thought it was only for methods th
| |
75 } | 89 } |
76 | 90 |
77 static void ClearPredictorCache( | 91 static void ClearPredictorCache( |
78 const v8::FunctionCallbackInfo<v8::Value>& args) { | 92 const v8::FunctionCallbackInfo<v8::Value>& args) { |
79 content::RenderThread::Get()->Send( | 93 chrome::mojom::NetBenchmarking::ClearPredictorCacheCallback callback; |
80 new ChromeViewHostMsg_ClearPredictorCache()); | 94 GetNetBenchmarking().ClearPredictorCache(callback); |
81 } | 95 } |
82 | 96 |
83 static void CloseConnections( | 97 static void CloseConnections( |
84 const v8::FunctionCallbackInfo<v8::Value>& args) { | 98 const v8::FunctionCallbackInfo<v8::Value>& args) { |
85 content::RenderThread::Get()->Send( | 99 chrome::mojom::NetBenchmarking::CloseCurrentConnectionsCallback callback; |
86 new ChromeViewHostMsg_CloseCurrentConnections()); | 100 GetNetBenchmarking().CloseCurrentConnections(callback); |
87 } | 101 } |
88 }; | 102 }; |
89 | 103 |
90 v8::Extension* NetBenchmarkingExtension::Get() { | 104 v8::Extension* NetBenchmarkingExtension::Get() { |
91 return new NetBenchmarkingWrapper(); | 105 return new NetBenchmarkingWrapper(); |
92 } | 106 } |
93 | 107 |
94 } // namespace extensions_v8 | 108 } // namespace extensions_v8 |
OLD | NEW |