Commit 310fa8d9 authored by Hongbo Song's avatar Hongbo Song Committed by Commit Bot

Use the Document::UkmRecorder instead of DelegatingUkmRecorder for input delay UKM.

On render side, the DelegatingUkmRecorder doesn't work. To record UKM,
we need the Document::UkmRecorder. This CL is for changing the ukm recorder for input delay UKM.

Change-Id: Iaaaa47c478d9bcf5e5f43a0cbcc81483cb4ee27a
Bug: 1042004
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2035307Reviewed-by: default avatarNate Chapin <japhet@chromium.org>
Commit-Queue: Hongbo Song <hbsong@google.com>
Cr-Commit-Position: refs/heads/master@{#739013}
parent b5583266
......@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "third_party/blink/renderer/core/loader/interactive_detector.h"
#include "base/time/default_tick_clock.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
......@@ -57,7 +56,8 @@ InteractiveDetector::InteractiveDetector(
document.GetTaskRunner(TaskType::kInternalDefault),
this,
&InteractiveDetector::TimeToInteractiveTimerFired),
initially_hidden_(document.hidden()) {}
initially_hidden_(document.hidden()),
ukm_recorder_(document.UkmRecorder()) {}
void InteractiveDetector::SetNavigationStartTime(
base::TimeTicks navigation_start_time) {
......@@ -235,7 +235,7 @@ void InteractiveDetector::HandleForInputDelay(
DCHECK_NE(source_id, ukm::kInvalidSourceId);
ukm::builders::InputEvent(source_id)
.SetInteractiveTiming_InputDelay(delay.InMilliseconds())
.Record(ukm::UkmRecorder::Get());
.Record(GetUkmRecorder());
UMA_HISTOGRAM_CUSTOM_TIMES(kHistogramInputDelay, delay,
base::TimeDelta::FromMilliseconds(1),
......@@ -553,4 +553,12 @@ void InteractiveDetector::SetTaskRunnerForTesting(
time_to_interactive_timer_.MoveToNewTaskRunner(task_runner_for_testing);
}
ukm::UkmRecorder* InteractiveDetector::GetUkmRecorder() const {
return ukm_recorder_;
}
void InteractiveDetector::SetUkmRecorderForTesting(
ukm::UkmRecorder* test_ukm_recorder) {
ukm_recorder_ = test_ukm_recorder;
}
} // namespace blink
......@@ -24,6 +24,10 @@ namespace base {
class TickClock;
} // namespace base
namespace ukm {
class UkmRecorder;
} // namespace ukm
namespace blink {
class Document;
......@@ -126,6 +130,10 @@ class CORE_EXPORT InteractiveDetector
// The caller owns the |clock| which must outlive the InteractiveDetector.
void SetTickClockForTesting(const base::TickClock* clock);
ukm::UkmRecorder* GetUkmRecorder() const;
void SetUkmRecorderForTesting(ukm::UkmRecorder* test_ukm_recorder);
private:
friend class InteractiveDetectorTest;
......@@ -211,6 +219,8 @@ class CORE_EXPORT InteractiveDetector
// pending_pointerdown_delay_.
base::TimeTicks pending_pointerdown_timestamp_;
ukm::UkmRecorder* ukm_recorder_;
DISALLOW_COPY_AND_ASSIGN(InteractiveDetector);
};
......
......@@ -51,7 +51,6 @@ class InteractiveDetectorTest : public testing::Test {
IntSize(), nullptr, nullptr, base::NullCallback(), tick_clock);
Document* document = &dummy_page_holder_->GetDocument();
detector_ = MakeGarbageCollected<InteractiveDetector>(
*document, new NetworkActivityCheckerForTest(document));
detector_->SetTaskRunnerForTesting(test_task_runner);
......@@ -604,7 +603,6 @@ TEST_F(InteractiveDetectorTest, LongTaskAfterTTIDoesNothing) {
}
TEST_F(InteractiveDetectorTest, RecordInputDelayUKM) {
ukm::TestAutoSetUkmRecorder test_ukm_recorder;
base::TimeDelta delay = base::TimeDelta::FromMilliseconds(10);
Event event;
event.SetTrusted(true);
......@@ -612,6 +610,8 @@ TEST_F(InteractiveDetectorTest, RecordInputDelayUKM) {
base::TimeTicks processing_start = Now() + delay;
base::TimeTicks event_platform_timestamp = Now();
ukm::TestAutoSetUkmRecorder test_ukm_recorder;
GetDetector()->SetUkmRecorderForTesting(&test_ukm_recorder);
GetDetector()->HandleForInputDelay(event, event_platform_timestamp,
processing_start);
auto entries = test_ukm_recorder.GetEntriesByName(InputEvent::kEntryName);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment