OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/renderer/page_load_metrics/page_timing_metrics_sender.h" | 5 #include "chrome/renderer/page_load_metrics/page_timing_metrics_sender.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/feature_list.h" |
10 #include "base/time/time.h" | 11 #include "base/time/time.h" |
11 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 13 #include "chrome/common/chrome_features.h" |
12 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h" | 14 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h" |
| 15 #include "chrome/renderer/page_load_metrics/page_timing_sender.h" |
13 #include "ipc/ipc_sender.h" | 16 #include "ipc/ipc_sender.h" |
14 | 17 |
15 namespace page_load_metrics { | 18 namespace page_load_metrics { |
16 | 19 |
17 namespace { | 20 namespace { |
18 const int kInitialTimerDelayMillis = 50; | 21 const int kInitialTimerDelayMillis = 50; |
19 const int kTimerDelayMillis = 1000; | 22 const int kTimerDelayMillis = 1000; |
20 } // namespace | 23 } // namespace |
21 | 24 |
22 PageTimingMetricsSender::PageTimingMetricsSender( | 25 PageTimingMetricsSender::PageTimingMetricsSender( |
23 IPC::Sender* ipc_sender, | 26 IPC::Sender* ipc_sender, |
24 int routing_id, | 27 int routing_id, |
| 28 PageTimingSender* page_timing_sender, |
25 std::unique_ptr<base::Timer> timer, | 29 std::unique_ptr<base::Timer> timer, |
26 const PageLoadTiming& initial_timing) | 30 const PageLoadTiming& initial_timing) |
27 : ipc_sender_(ipc_sender), | 31 : ipc_sender_(ipc_sender), |
28 routing_id_(routing_id), | 32 routing_id_(routing_id), |
| 33 page_timing_sender_(page_timing_sender), |
29 timer_(std::move(timer)), | 34 timer_(std::move(timer)), |
30 last_timing_(initial_timing), | 35 last_timing_(initial_timing), |
31 metadata_(PageLoadMetadata()) { | 36 metadata_(PageLoadMetadata()) { |
32 if (!initial_timing.IsEmpty()) { | 37 if (!initial_timing.IsEmpty()) { |
33 // Send an initial IPC relatively early to help track aborts. | 38 // Send an initial IPC relatively early to help track aborts. |
34 EnsureSendTimer(kInitialTimerDelayMillis); | 39 EnsureSendTimer(kInitialTimerDelayMillis); |
35 } | 40 } |
36 } | 41 } |
37 | 42 |
38 // On destruction, we want to send any data we have if we have a timer | 43 // On destruction, we want to send any data we have if we have a timer |
(...skipping 30 matching lines...) Expand all Loading... |
69 } | 74 } |
70 | 75 |
71 void PageTimingMetricsSender::EnsureSendTimer(int delay) { | 76 void PageTimingMetricsSender::EnsureSendTimer(int delay) { |
72 if (!timer_->IsRunning()) | 77 if (!timer_->IsRunning()) |
73 timer_->Start( | 78 timer_->Start( |
74 FROM_HERE, base::TimeDelta::FromMilliseconds(delay), | 79 FROM_HERE, base::TimeDelta::FromMilliseconds(delay), |
75 base::Bind(&PageTimingMetricsSender::SendNow, base::Unretained(this))); | 80 base::Bind(&PageTimingMetricsSender::SendNow, base::Unretained(this))); |
76 } | 81 } |
77 | 82 |
78 void PageTimingMetricsSender::SendNow() { | 83 void PageTimingMetricsSender::SendNow() { |
| 84 if (base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication)) { |
| 85 page_timing_sender_->SendTiming(last_timing_, metadata_); |
| 86 return; |
| 87 } |
79 ipc_sender_->Send(new PageLoadMetricsMsg_TimingUpdated( | 88 ipc_sender_->Send(new PageLoadMetricsMsg_TimingUpdated( |
80 routing_id_, last_timing_, metadata_)); | 89 routing_id_, last_timing_, metadata_)); |
81 } | 90 } |
82 | 91 |
83 } // namespace page_load_metrics | 92 } // namespace page_load_metrics |
OLD | NEW |