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

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

Issue 118423004: Add support for wrapping classes indirectly inherited from gin::Wrappable<T> (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update StatsCollectionController 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/wrappable.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"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 68 }
69 69
70 } // namespace 70 } // namespace
71 71
72 // static 72 // static
73 gin::WrapperInfo StatsCollectionController::kWrapperInfo = { 73 gin::WrapperInfo StatsCollectionController::kWrapperInfo = {
74 gin::kEmbedderNativeGin 74 gin::kEmbedderNativeGin
75 }; 75 };
76 76
77 // 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
89 void StatsCollectionController::Install(blink::WebFrame* frame) { 78 void StatsCollectionController::Install(blink::WebFrame* frame) {
90 v8::Isolate* isolate = blink::mainThreadIsolate(); 79 v8::Isolate* isolate = blink::mainThreadIsolate();
91 v8::HandleScope handle_scope(isolate); 80 v8::HandleScope handle_scope(isolate);
92 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); 81 v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
93 if (context.IsEmpty()) 82 if (context.IsEmpty())
94 return; 83 return;
95 84
96 v8::Context::Scope context_scope(context); 85 v8::Context::Scope context_scope(context);
97 86
98 gin::Handle<StatsCollectionController> controller = 87 gin::Handle<StatsCollectionController> controller =
99 gin::CreateHandle(isolate, new StatsCollectionController()); 88 gin::CreateHandle(isolate, new StatsCollectionController());
100 v8::Handle<v8::Object> global = context->Global(); 89 v8::Handle<v8::Object> global = context->Global();
101 global->Set(gin::StringToV8(isolate, "statsCollectionController"), 90 global->Set(gin::StringToV8(isolate, "statsCollectionController"),
102 controller.ToV8()); 91 controller.ToV8());
103 } 92 }
104 93
105 StatsCollectionController::StatsCollectionController() {} 94 StatsCollectionController::StatsCollectionController() {}
106 95
107 StatsCollectionController::~StatsCollectionController() {} 96 StatsCollectionController::~StatsCollectionController() {}
108 97
98 gin::ObjectTemplateBuilder StatsCollectionController::GetObjectTemplateBuilder(
99 v8::Isolate* isolate) {
100 return gin::Wrappable<StatsCollectionController>::GetObjectTemplateBuilder(
101 isolate)
102 .SetMethod("getHistogram", &StatsCollectionController::GetHistogram)
103 .SetMethod("getBrowserHistogram",
104 &StatsCollectionController::GetBrowserHistogram)
105 .SetMethod("tabLoadTiming", &StatsCollectionController::GetTabLoadTiming);
106 }
107
109 std::string StatsCollectionController::GetHistogram( 108 std::string StatsCollectionController::GetHistogram(
110 const std::string& histogram_name) { 109 const std::string& histogram_name) {
111 base::HistogramBase* histogram = 110 base::HistogramBase* histogram =
112 base::StatisticsRecorder::FindHistogram(histogram_name); 111 base::StatisticsRecorder::FindHistogram(histogram_name);
113 std::string output; 112 std::string output;
114 if (!histogram) { 113 if (!histogram) {
115 output = "{}"; 114 output = "{}";
116 } else { 115 } else {
117 histogram->WriteJSON(&output); 116 histogram->WriteJSON(&output);
118 } 117 }
(...skipping 29 matching lines...) Expand all
148 } 147 }
149 148
150 std::string tab_timing_json; 149 std::string tab_timing_json;
151 ConvertLoadTimeToJSON( 150 ConvertLoadTimeToJSON(
152 observer->load_start_time(), observer->load_stop_time(), 151 observer->load_start_time(), observer->load_stop_time(),
153 &tab_timing_json); 152 &tab_timing_json);
154 return tab_timing_json; 153 return tab_timing_json;
155 } 154 }
156 155
157 } // namespace content 156 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/stats_collection_controller.h ('k') | gin/wrappable.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698