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

Unified Diff: content/renderer/stats_collection_extension.cc

Issue 12389073: Collect tab timing information for use in telementry-based startup tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: formatting/compile fix Created 7 years, 9 months 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/stats_collection_extension.cc
diff --git a/content/renderer/stats_collection_extension.cc b/content/renderer/stats_collection_extension.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8b3c1e2904ab8743f6472c0220ebfdcb6873c5a6
--- /dev/null
+++ b/content/renderer/stats_collection_extension.cc
@@ -0,0 +1,123 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/stats_collection_extension.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/json/json_writer.h"
+#include "base/metrics/histogram.h"
+#include "base/metrics/statistics_recorder.h"
+#include "base/string_util.h"
+#include "content/common/child_process_messages.h"
+#include "content/common/tab_load_stats.h"
+#include "content/renderer/render_view_impl.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
+
+using webkit_glue::CppArgumentList;
+using webkit_glue::CppVariant;
+
+namespace {
+
+bool CurrentRenderViewRoutingID(int* routing_id) {
+ WebKit::WebFrame* web_frame = WebKit::WebFrame::frameForCurrentContext();
+ if (!web_frame)
+ return false;
+
+ WebKit::WebView* web_view = web_frame->view();
+ if (!web_view)
+ return false;
+
+ 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.
+ content::RenderViewImpl::FromWebView(web_view);
+ if (!render_view_impl)
+ return false;
+
+ *routing_id = render_view_impl->GetRoutingID();
+ return true;
+}
+
+} // namespace
+
+namespace content {
+
+StatsCollectionExtension::StatsCollectionExtension()
+ : sender_(NULL) {
+ BindCallback("getHistogram",
+ base::Bind(&StatsCollectionExtension::GetHistogram,
+ base::Unretained(this)));
+ BindCallback("getBrowserHistogram",
+ base::Bind(&StatsCollectionExtension::GetBrowserHistogram,
+ base::Unretained(this)));
+ BindCallback("tabLoadTiming",
+ base::Bind(
+ &StatsCollectionExtension::GetTabLoadTiming,
+ base::Unretained(this)));
+}
+
+void StatsCollectionExtension::GetHistogram(const CppArgumentList& args,
+ CppVariant* result) {
+ if (args.size() != 1) {
+ result->SetNull();
+ return;
+ }
+ base::HistogramBase* histogram =
+ base::StatisticsRecorder::FindHistogram(args[0].ToString());
+ std::string output;
+ if (!histogram) {
+ output = "{}";
+ } else {
+ histogram->WriteJSON(&output);
+ }
+ result->Set(output);
+}
+
+void StatsCollectionExtension::GetBrowserHistogram(const CppArgumentList& args,
+ CppVariant* result) {
+ if (args.size() != 1) {
+ result->SetNull();
+ return;
+ }
+
+ if (!sender_) {
+ NOTREACHED();
+ result->SetNull();
+ return;
+ }
+
+ std::string histogram_json;
+ sender_->Send(new ChildProcessHostMsg_GetBrowserHistogram(
+ args[0].ToString(), &histogram_json));
+ result->Set(histogram_json);
+}
+
+void StatsCollectionExtension::GetTabLoadTiming(
+ const CppArgumentList& args,
+ CppVariant* result) {
+ if (!sender_) {
+ NOTREACHED();
+ result->SetNull();
+ return;
+ }
+
+ int routing_id = -1;
+ if (!CurrentRenderViewRoutingID(&routing_id)) {
+ NOTREACHED();
+ result->SetNull();
+ return;
+ }
+
+ 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.
+ base::TimeTicks timer_start;
+ sender_->Send(
+ new ChildProcessHostMsg_GetTabLoadTimingInformation(
+ routing_id, &tab_load_time, &timer_start));
+
+ std::string tab_timing_json;
+ ConvertTabLoadTimeToJSON(tab_load_time, timer_start, &tab_timing_json);
+ result->Set(tab_timing_json);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698