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

Side by Side Diff: components/page_load_metrics/renderer/page_timing_metrics_sender.cc

Issue 1312213010: PageLoadMetrics renderer and browser implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Relax DCHECK constraints slightly for tests Created 5 years, 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 "base/callback.h"
6 #include "base/time/time.h"
7 #include "base/timer/timer.h"
8 #include "components/page_load_metrics/common/page_load_metrics_messages.h"
9 #include "components/page_load_metrics/renderer/page_timing_metrics_sender.h"
10 #include "ipc/ipc_sender.h"
11
12 namespace page_load_metrics {
13
14 namespace {
15 const int kTimerDelayMillis = 1000;
16 } // namespace
17
18 PageTimingMetricsSender::PageTimingMetricsSender(IPC::Sender* ipc_sender,
19 int routing_id,
20 scoped_ptr<base::Timer> timer)
21 : ipc_sender_(ipc_sender), routing_id_(routing_id), timer_(timer.Pass()) {}
22
23 // On destruction, we want to send any data we have if we have a timer
24 // currently running (and thus are talking to a browser process)
25 PageTimingMetricsSender::~PageTimingMetricsSender() {
26 if (timer_->IsRunning()) {
27 timer_->Stop();
28 SendNow();
29 }
30 }
31
32 void PageTimingMetricsSender::Send(const PageLoadTiming& timing) {
33 if (timing == last_timing_)
34 return;
35
36 // We want to make sure that each PageTimingMetricsSender is associated
37 // with a distinct page navigation. Because we reset the object on commit,
38 // we can trash last_timing_ on a provisional load before SendNow() fires.
39 if (!last_timing_.navigation_start.is_null() &&
40 last_timing_.navigation_start != timing.navigation_start) {
41 return;
42 }
43
44 last_timing_ = timing;
45
46 if (!timer_->IsRunning())
47 timer_->Start(
48 FROM_HERE, base::TimeDelta::FromMilliseconds(kTimerDelayMillis),
49 base::Bind(&PageTimingMetricsSender::SendNow, base::Unretained(this)));
50 }
51
52 void PageTimingMetricsSender::SendNow() {
53 ipc_sender_->Send(
54 new PageLoadMetricsMsg_TimingUpdated(routing_id_, last_timing_));
55 }
56
57 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698