Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: content/renderer/stats_collection_controller.cc

Issue 113893005: [gin] Introduce Wrappable::GetObjectTemplate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/stats_collection_controller.h ('k') | gin/function_template.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/stats_collection_controller.h" 5 #include "content/renderer/stats_collection_controller.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/metrics/statistics_recorder.h" 9 #include "base/metrics/statistics_recorder.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "content/common/child_process_messages.h" 11 #include "content/common/child_process_messages.h"
12 #include "content/renderer/render_view_impl.h" 12 #include "content/renderer/render_view_impl.h"
13 #include "gin/handle.h" 13 #include "gin/handle.h"
14 #include "gin/object_template_builder.h" 14 #include "gin/object_template_builder.h"
15 #include "gin/per_isolate_data.h"
16 #include "third_party/WebKit/public/web/WebFrame.h" 15 #include "third_party/WebKit/public/web/WebFrame.h"
17 #include "third_party/WebKit/public/web/WebKit.h" 16 #include "third_party/WebKit/public/web/WebKit.h"
18 #include "third_party/WebKit/public/web/WebView.h" 17 #include "third_party/WebKit/public/web/WebView.h"
19 18
20 namespace content { 19 namespace content {
21 20
22 namespace { 21 namespace {
23 22
24 bool CurrentRenderViewImpl(RenderViewImpl** out) { 23 bool CurrentRenderViewImpl(RenderViewImpl** out) {
25 blink::WebFrame* web_frame = blink::WebFrame::frameForCurrentContext(); 24 blink::WebFrame* web_frame = blink::WebFrame::frameForCurrentContext();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } 68 }
70 69
71 } // namespace 70 } // namespace
72 71
73 // static 72 // static
74 gin::WrapperInfo StatsCollectionController::kWrapperInfo = { 73 gin::WrapperInfo StatsCollectionController::kWrapperInfo = {
75 gin::kEmbedderNativeGin 74 gin::kEmbedderNativeGin
76 }; 75 };
77 76
78 // static 77 // static
78 v8::Local<v8::ObjectTemplate> StatsCollectionController::GetObjectTemplate(
79 v8::Isolate* isolate) {
80 return gin::ObjectTemplateBuilder(isolate)
81 .SetMethod("getHistogram", &StatsCollectionController::GetHistogram)
82 .SetMethod("getBrowserHistogram",
83 &StatsCollectionController::GetBrowserHistogram)
84 .SetMethod("tabLoadTiming", &StatsCollectionController::GetTabLoadTiming)
85 .Build();
86 }
87
88 // static
79 void StatsCollectionController::Install(blink::WebFrame* frame) { 89 void StatsCollectionController::Install(blink::WebFrame* frame) {
80 v8::Isolate* isolate = blink::mainThreadIsolate(); 90 v8::Isolate* isolate = blink::mainThreadIsolate();
81 v8::HandleScope handle_scope(isolate); 91 v8::HandleScope handle_scope(isolate);
82 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); 92 v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
83 if (context.IsEmpty()) 93 if (context.IsEmpty())
84 return; 94 return;
85 95
86 v8::Context::Scope context_scope(context); 96 v8::Context::Scope context_scope(context);
87 97
88 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
89 if (data->GetObjectTemplate(&StatsCollectionController::kWrapperInfo)
90 .IsEmpty()) {
91 v8::Handle<v8::ObjectTemplate> templ =
92 gin::ObjectTemplateBuilder(isolate)
93 .SetMethod("getHistogram", &StatsCollectionController::GetHistogram)
94 .SetMethod("getBrowserHistogram",
95 &StatsCollectionController::GetBrowserHistogram)
96 .SetMethod("tabLoadTiming",
97 &StatsCollectionController::GetTabLoadTiming)
98 .Build();
99 templ->SetInternalFieldCount(gin::kNumberOfInternalFields);
100 data->SetObjectTemplate(&StatsCollectionController::kWrapperInfo, templ);
101 }
102
103 gin::Handle<StatsCollectionController> controller = 98 gin::Handle<StatsCollectionController> controller =
104 gin::CreateHandle(isolate, new StatsCollectionController()); 99 gin::CreateHandle(isolate, new StatsCollectionController());
105 v8::Handle<v8::Object> global = context->Global(); 100 v8::Handle<v8::Object> global = context->Global();
106 global->Set(gin::StringToV8(isolate, "statsCollectionController"), 101 global->Set(gin::StringToV8(isolate, "statsCollectionController"),
107 controller.ToV8()); 102 controller.ToV8());
108 } 103 }
109 104
110 StatsCollectionController::StatsCollectionController() {} 105 StatsCollectionController::StatsCollectionController() {}
111 106
112 StatsCollectionController::~StatsCollectionController() {} 107 StatsCollectionController::~StatsCollectionController() {}
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 148 }
154 149
155 std::string tab_timing_json; 150 std::string tab_timing_json;
156 ConvertLoadTimeToJSON( 151 ConvertLoadTimeToJSON(
157 observer->load_start_time(), observer->load_stop_time(), 152 observer->load_start_time(), observer->load_stop_time(),
158 &tab_timing_json); 153 &tab_timing_json);
159 return tab_timing_json; 154 return tab_timing_json;
160 } 155 }
161 156
162 } // namespace content 157 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/stats_collection_controller.h ('k') | gin/function_template.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698