Commit e44b691b authored by Michael Crouse's avatar Michael Crouse Committed by Commit Bot

Populates navigation time into UKM source proto.

Bug: 928299
Change-Id: I28cf9ad47f7ca05fe9132b3bb64ee2a346a8fc8c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1555418Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Auto-Submit: Michael Crouse <mcrouse@chromium.org>
Commit-Queue: Michael Crouse <mcrouse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658733}
parent 91fcf385
......@@ -332,6 +332,8 @@ void SourceUrlRecorderWebContentsObserver::MaybeRecordUrl(
navigation_data.previous_source_id =
last_committed_full_navigation_source_id_;
navigation_data.navigation_time = navigation_handle->NavigationStart();
// If the last_committed_full_navigation_or_same_document_source_id_ isn't
// equal to the last_committed_full_navigation_source_id_, it indicates the
// previous source was a same document navigation.
......
......@@ -122,6 +122,7 @@ TEST_F(SourceUrlRecorderWebContentsObserverTest, SameDocumentNavigation) {
EXPECT_FALSE(full_nav_source1.is_same_document_navigation());
EXPECT_FALSE(full_nav_source1.has_previous_source_id());
EXPECT_FALSE(full_nav_source1.has_previous_same_document_source_id());
EXPECT_TRUE(full_nav_source1.has_navigation_time_msec());
// The second navigation was a same-document navigation to
// same_document_url1. It should have a previous_source_id that points to
......@@ -131,6 +132,7 @@ TEST_F(SourceUrlRecorderWebContentsObserverTest, SameDocumentNavigation) {
EXPECT_TRUE(same_doc_source1.is_same_document_navigation());
EXPECT_EQ(full_nav_source1.id(), same_doc_source1.previous_source_id());
EXPECT_FALSE(same_doc_source1.has_previous_same_document_source_id());
EXPECT_TRUE(same_doc_source1.has_navigation_time_msec());
// The third navigation was a non-same-document navigation to url2. It should
// have a previous_source_id pointing to the source for url1, and a
......@@ -142,6 +144,7 @@ TEST_F(SourceUrlRecorderWebContentsObserverTest, SameDocumentNavigation) {
EXPECT_EQ(full_nav_source1.id(), full_nav_source2.previous_source_id());
EXPECT_EQ(same_doc_source1.id(),
full_nav_source2.previous_same_document_source_id());
EXPECT_TRUE(full_nav_source2.has_navigation_time_msec());
// The fourth navigation was a same-document navigation to
// same_document_url2. It should have a previous_source_id pointing to the
......@@ -151,8 +154,17 @@ TEST_F(SourceUrlRecorderWebContentsObserverTest, SameDocumentNavigation) {
EXPECT_TRUE(same_doc_source2.is_same_document_navigation());
EXPECT_EQ(full_nav_source2.id(), same_doc_source2.previous_source_id());
EXPECT_FALSE(same_doc_source2.has_previous_same_document_source_id());
EXPECT_TRUE(same_doc_source2.has_navigation_time_msec());
EXPECT_EQ(url2, GetAssociatedURLForWebContentsDocument());
// The recorded time of each navigation should increase monotonically.
EXPECT_LE(full_nav_source1.navigation_time_msec(),
same_doc_source1.navigation_time_msec());
EXPECT_LE(same_doc_source1.navigation_time_msec(),
full_nav_source2.navigation_time_msec());
EXPECT_LE(full_nav_source2.navigation_time_msec(),
same_doc_source2.navigation_time_msec());
}
TEST_F(SourceUrlRecorderWebContentsObserverTest,
......
......@@ -64,6 +64,7 @@ UkmSource::NavigationData UkmSource::NavigationData::CopyWithSanitizedUrls(
sanitized_navigation_data.tab_id = tab_id;
sanitized_navigation_data.is_same_document_navigation =
is_same_document_navigation;
sanitized_navigation_data.navigation_time = navigation_time;
return sanitized_navigation_data;
}
......@@ -129,6 +130,11 @@ void UkmSource::PopulateProto(Source* proto_source) const {
if (navigation_data_.is_same_document_navigation)
proto_source->set_is_same_document_navigation(true);
if (navigation_data_.navigation_time) {
proto_source->set_navigation_time_msec(
navigation_data_.navigation_time->since_origin().InMilliseconds());
}
}
} // namespace ukm
......@@ -79,6 +79,10 @@ class METRICS_EXPORT UkmSource {
// document navigations are fragment navigations, pushState/replaceState,
// and same page history navigation.
bool is_same_document_navigation = false;
// The navigation start time relative to session start. The navigation
// time within session should be monotonically increasing.
base::Optional<base::TimeTicks> navigation_time;
};
UkmSource(SourceId id, const GURL& url);
......
......@@ -84,8 +84,12 @@ message Source {
// Flag indicating if the metric was collected while inside a "custom tab".
optional bool is_custom_tab = 7;
// Timestamp of navigation to this Source, as seen by the client. Time of
// events related to this Source will generally be relative to this timestamp.
// Relative time of navigation for this Source, as seen by the client, and is
// set for sources of type ukm::SourceIdType::NAVIGATION_ID. Time of events
// related to this Source will generally be relative to this timestamp. The
// recorded navigation time is in TimeTicks, which is the relative time since
// the origin. The origin is platform-specific but is guaranteed to be
// monotonically increase within each session.
optional int64 navigation_time_msec = 3;
// Unique identifier (for a given client_id/session_id) for the tab this
......
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