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

Unified Diff: components/page_load_metrics/browser/page_load_metrics_web_contents_observer.cc

Issue 1282303002: PageLoadMetrics renderer and browser implementation (deprecated) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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: components/page_load_metrics/browser/page_load_metrics_web_contents_observer.cc
diff --git a/components/page_load_metrics/browser/page_load_metrics_web_contents_observer.cc b/components/page_load_metrics/browser/page_load_metrics_web_contents_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..abf7b3b1670b3785fc50ddf2531f792a607e9a9a
--- /dev/null
+++ b/components/page_load_metrics/browser/page_load_metrics_web_contents_observer.cc
@@ -0,0 +1,109 @@
+// Copyright 2015 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 "components/page_load_metrics/browser/page_load_metrics_web_contents_observer.h"
+
+#include "base/metrics/histogram.h"
+#include "components/page_load_metrics/common/page_load_metrics_messages.h"
+#include "components/page_load_metrics/common/page_load_timing.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/browser/web_contents_user_data.h"
+#include "ipc/ipc_message.h"
+#include "ipc/ipc_message_macros.h"
+
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(
+ page_load_metrics::PageLoadMetricsWebContentsObserver);
+
+namespace page_load_metrics {
+
+PageLoadMetricsWebContentsObserver::PageLoadMetricsWebContentsObserver(
+ content::WebContents* web_contents)
+ : content::WebContentsObserver(web_contents) {
+}
+
+PageLoadMetricsWebContentsObserver::~PageLoadMetricsWebContentsObserver() {}
nasko 2015/08/26 17:27:24 nit: Be consistent with the constructor. Either {}
+
+bool PageLoadMetricsWebContentsObserver::OnMessageReceived(
+ const IPC::Message& message, content::RenderFrameHost* render_frame_host) {
nasko 2015/08/26 17:27:24 Each parameter must be on a new line.
+ // TODO verify that this is getting called on the thread that other
+ // WebContentsObserver callbacks get invoked on (browser UI thread?).
nasko 2015/08/26 17:27:24 WebContentsObserver methods are only called on the
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(PageLoadMetricsWebContentsObserver, message)
+ IPC_MESSAGE_HANDLER(PageLoadMetricsMsg_OnTimingUpdated,
+ OnTimingUpdated)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+#if 0
+
+// TODO figure out which of these hooks may actually be useful to implement.
+
+void PageLoadMetricsWebContentsObserver::DidCommitNavigation(
+ content::NavigationHandle* navigation_handle) {
+ if (!navigation_handle->IsInMainFrame())
+ return;
+
+ if (!navigation_handle->HasCommittedDocument())
+ return;
+
+ const GURL& url = navigation_handle->GetURL();
+ if (!url.SchemeIsHTTPOrHTTPS())
+ return;
+
+ page_timing_metrics_receiver_.reset(new PageTimingMetricsReceiver());
+}
+
+void PageLoadMetricsWebContentsObserver::DidNavigateMainFrame(
+ const LoadCommittedDetails& details,
+ const FrameNavigateParams& params) {
+ DCHECK(details.is_main_frame);
+
+ // TODO how are the 2 checks below different?
+ if (details.type != NAVIGATION_TYPE_NEW_PAGE)
+ return;
+ if (details.is_in_page)
+ return;
+
+}
+#endif
+
+#define PAGE_LOAD_HISTOGRAM(name, sample) \
+ UMA_HISTOGRAM_CUSTOM_TIMES(name, \
+ sample, \
+ base::TimeDelta::FromMilliseconds(10), \
+ base::TimeDelta::FromMinutes(10), \
+ 100);
+
+void PageLoadMetricsWebContentsObserver::OnTimingUpdated(
+ const PageLoadTiming& timing) {
+ // TODO ignore non-HTTP/HTTPS URLs (e.g. chrome://newtab).
+
+ // TODO store the updated timing info, and log it when the next
+ // navigation occurrs.
+}
+
+// TODO call this when a page is being navigated away from
+void PageLoadMetricsWebContentsObserver::RecordTimingHistograms(
+ const PageLoadTiming& timing) {
+ if (timing.navigation_start.is_null())
+ return;
+
+ if (!timing.dom_content_loaded_event_start.is_null())
+ PAGE_LOAD_HISTOGRAM("PageLoad.Timing.DOMContentLoadedEventFired",
+ timing.dom_content_loaded_event_start - timing.navigation_start);
+
+ if (!timing.load_event_start.is_null())
+ PAGE_LOAD_HISTOGRAM("PageLoad.Timing.LoadEventFired",
+ timing.load_event_start - timing.navigation_start);
+
+ if (!timing.load_event_start.is_null())
+ PAGE_LOAD_HISTOGRAM("PageLoad.Timing.FirstLayout",
+ timing.first_layout - timing.navigation_start);
+}
+
+} // namespace page_load_metrics

Powered by Google App Engine
This is Rietveld 408576698