Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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. | |
| 4 | |
| 5 #include "content/renderer/stats_collection_extension.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/bind_helpers.h" | |
| 9 #include "base/json/json_writer.h" | |
| 10 #include "base/metrics/histogram.h" | |
| 11 #include "base/metrics/statistics_recorder.h" | |
| 12 #include "base/string_util.h" | |
| 13 #include "content/common/child_process_messages.h" | |
| 14 #include "content/common/tab_load_stats.h" | |
| 15 #include "content/renderer/render_view_impl.h" | |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
| 18 | |
| 19 using webkit_glue::CppArgumentList; | |
| 20 using webkit_glue::CppVariant; | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 bool CurrentRenderViewRoutingID(int* routing_id) { | |
| 25 WebKit::WebFrame* web_frame = WebKit::WebFrame::frameForCurrentContext(); | |
| 26 if (!web_frame) | |
| 27 return false; | |
| 28 | |
| 29 WebKit::WebView* web_view = web_frame->view(); | |
| 30 if (!web_view) | |
| 31 return false; | |
| 32 | |
| 33 content::RenderViewImpl* render_view_impl = | |
|
jam
2013/04/04 17:28:39
nit: put the anonymous namespace in content so tha
jeremy
2013/04/07 14:51:54
Done.
| |
| 34 content::RenderViewImpl::FromWebView(web_view); | |
| 35 if (!render_view_impl) | |
| 36 return false; | |
| 37 | |
| 38 *routing_id = render_view_impl->GetRoutingID(); | |
| 39 return true; | |
| 40 } | |
| 41 | |
| 42 } // namespace | |
| 43 | |
| 44 namespace content { | |
| 45 | |
| 46 StatsCollectionExtension::StatsCollectionExtension() | |
| 47 : sender_(NULL) { | |
| 48 BindCallback("getHistogram", | |
| 49 base::Bind(&StatsCollectionExtension::GetHistogram, | |
| 50 base::Unretained(this))); | |
| 51 BindCallback("getBrowserHistogram", | |
| 52 base::Bind(&StatsCollectionExtension::GetBrowserHistogram, | |
| 53 base::Unretained(this))); | |
| 54 BindCallback("tabLoadTiming", | |
| 55 base::Bind( | |
| 56 &StatsCollectionExtension::GetTabLoadTiming, | |
| 57 base::Unretained(this))); | |
| 58 } | |
| 59 | |
| 60 void StatsCollectionExtension::GetHistogram(const CppArgumentList& args, | |
| 61 CppVariant* result) { | |
| 62 if (args.size() != 1) { | |
| 63 result->SetNull(); | |
| 64 return; | |
| 65 } | |
| 66 base::HistogramBase* histogram = | |
| 67 base::StatisticsRecorder::FindHistogram(args[0].ToString()); | |
| 68 std::string output; | |
| 69 if (!histogram) { | |
| 70 output = "{}"; | |
| 71 } else { | |
| 72 histogram->WriteJSON(&output); | |
| 73 } | |
| 74 result->Set(output); | |
| 75 } | |
| 76 | |
| 77 void StatsCollectionExtension::GetBrowserHistogram(const CppArgumentList& args, | |
| 78 CppVariant* result) { | |
| 79 if (args.size() != 1) { | |
| 80 result->SetNull(); | |
| 81 return; | |
| 82 } | |
| 83 | |
| 84 if (!sender_) { | |
| 85 NOTREACHED(); | |
| 86 result->SetNull(); | |
| 87 return; | |
| 88 } | |
| 89 | |
| 90 std::string histogram_json; | |
| 91 sender_->Send(new ChildProcessHostMsg_GetBrowserHistogram( | |
| 92 args[0].ToString(), &histogram_json)); | |
| 93 result->Set(histogram_json); | |
| 94 } | |
| 95 | |
| 96 void StatsCollectionExtension::GetTabLoadTiming( | |
| 97 const CppArgumentList& args, | |
| 98 CppVariant* result) { | |
| 99 if (!sender_) { | |
| 100 NOTREACHED(); | |
| 101 result->SetNull(); | |
| 102 return; | |
| 103 } | |
| 104 | |
| 105 int routing_id = -1; | |
| 106 if (!CurrentRenderViewRoutingID(&routing_id)) { | |
| 107 NOTREACHED(); | |
| 108 result->SetNull(); | |
| 109 return; | |
| 110 } | |
| 111 | |
| 112 content::TabLoadTime tab_load_time; | |
|
jam
2013/04/04 17:28:39
nit: "content::" needed
jeremy
2013/04/07 14:51:54
Done.
jeremy
2013/04/07 14:51:54
Done.
| |
| 113 base::TimeTicks timer_start; | |
| 114 sender_->Send( | |
| 115 new ChildProcessHostMsg_GetTabLoadTimingInformation( | |
| 116 routing_id, &tab_load_time, &timer_start)); | |
| 117 | |
| 118 std::string tab_timing_json; | |
| 119 ConvertTabLoadTimeToJSON(tab_load_time, timer_start, &tab_timing_json); | |
| 120 result->Set(tab_timing_json); | |
| 121 } | |
| 122 | |
| 123 } // namespace content | |
| OLD | NEW |