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 "content/renderer/memory_benchmarking_extension.h" | 5 #include "content/renderer/memory_benchmarking_extension.h" |
6 | 6 |
7 #include "content/common/memory_benchmark_messages.h" | 7 #include "content/common/memory_benchmark_messages.h" |
| 8 #include "content/renderer/chrome_object_extensions_utils.h" |
8 #include "content/renderer/render_thread_impl.h" | 9 #include "content/renderer/render_thread_impl.h" |
9 #include "gin/arguments.h" | 10 #include "gin/arguments.h" |
10 #include "gin/handle.h" | 11 #include "gin/handle.h" |
11 #include "gin/object_template_builder.h" | 12 #include "gin/object_template_builder.h" |
12 #include "third_party/WebKit/public/web/WebFrame.h" | 13 #include "third_party/WebKit/public/web/WebFrame.h" |
13 #include "third_party/WebKit/public/web/WebKit.h" | 14 #include "third_party/WebKit/public/web/WebKit.h" |
14 | 15 |
15 #if defined(USE_TCMALLOC) && (defined(OS_LINUX) || defined(OS_ANDROID)) | 16 #if defined(USE_TCMALLOC) && (defined(OS_LINUX) || defined(OS_ANDROID)) |
16 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" | 17 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" |
17 #endif | 18 #endif |
(...skipping 10 matching lines...) Expand all Loading... |
28 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); | 29 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); |
29 if (context.IsEmpty()) | 30 if (context.IsEmpty()) |
30 return; | 31 return; |
31 | 32 |
32 v8::Context::Scope context_scope(context); | 33 v8::Context::Scope context_scope(context); |
33 gin::Handle<MemoryBenchmarkingExtension> controller = | 34 gin::Handle<MemoryBenchmarkingExtension> controller = |
34 gin::CreateHandle(isolate, new MemoryBenchmarkingExtension()); | 35 gin::CreateHandle(isolate, new MemoryBenchmarkingExtension()); |
35 if (controller.IsEmpty()) | 36 if (controller.IsEmpty()) |
36 return; | 37 return; |
37 | 38 |
38 v8::Handle<v8::Object> global = context->Global(); | 39 v8::Handle<v8::Object> chrome = GetOrCreateChromeObject(isolate, |
39 v8::Handle<v8::Object> chrome = | 40 context->Global()); |
40 global->Get(gin::StringToV8(isolate, "chrome"))->ToObject(); | |
41 if (chrome.IsEmpty()) { | |
42 chrome = v8::Object::New(isolate); | |
43 global->Set(gin::StringToV8(isolate, "chrome"), chrome); | |
44 } | |
45 chrome->Set(gin::StringToV8(isolate, "memoryBenchmarking"), | 41 chrome->Set(gin::StringToV8(isolate, "memoryBenchmarking"), |
46 controller.ToV8()); | 42 controller.ToV8()); |
47 } | 43 } |
48 | 44 |
49 MemoryBenchmarkingExtension::MemoryBenchmarkingExtension() {} | 45 MemoryBenchmarkingExtension::MemoryBenchmarkingExtension() {} |
50 | 46 |
51 MemoryBenchmarkingExtension::~MemoryBenchmarkingExtension() {} | 47 MemoryBenchmarkingExtension::~MemoryBenchmarkingExtension() {} |
52 | 48 |
53 gin::ObjectTemplateBuilder | 49 gin::ObjectTemplateBuilder |
54 MemoryBenchmarkingExtension::GetObjectTemplateBuilder(v8::Isolate* isolate) { | 50 MemoryBenchmarkingExtension::GetObjectTemplateBuilder(v8::Isolate* isolate) { |
(...skipping 27 matching lines...) Expand all Loading... |
82 if (process_type == "browser") { | 78 if (process_type == "browser") { |
83 content::RenderThreadImpl::current()->Send( | 79 content::RenderThreadImpl::current()->Send( |
84 new MemoryBenchmarkHostMsg_HeapProfilerDump(reason)); | 80 new MemoryBenchmarkHostMsg_HeapProfilerDump(reason)); |
85 } else { | 81 } else { |
86 ::HeapProfilerDump(reason.c_str()); | 82 ::HeapProfilerDump(reason.c_str()); |
87 } | 83 } |
88 #endif | 84 #endif |
89 } | 85 } |
90 | 86 |
91 } // namespace content | 87 } // namespace content |
OLD | NEW |