Exposes the UKM source ID in WebContentsImpl to WebContents.
Exposes the UKM source ID from WebContentsImpl to WebContents,
so it can be used in NavigationPredictor to send metrics to the
UKM.
Bug: 972128
Change-Id: I7181890ed7977904b8d4dca9db78b7bbbad85b83
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1686633
Reviewed-by: Steven Holte <[email protected]>
Reviewed-by: Kinuko Yasuda <[email protected]>
Reviewed-by: Tarun Bansal <[email protected]>
Reviewed-by: Ryan Sturm <[email protected]>
Commit-Queue: Sofiya Semenova <[email protected]>
Cr-Commit-Position: refs/heads/master@{#676267}
diff --git a/chrome/browser/navigation_predictor/navigation_predictor.cc b/chrome/browser/navigation_predictor/navigation_predictor.cc
index e432978..8e58fdc 100644
--- a/chrome/browser/navigation_predictor/navigation_predictor.cc
+++ b/chrome/browser/navigation_predictor/navigation_predictor.cc
@@ -201,6 +201,7 @@
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
current_visibility_ = web_contents->GetVisibility();
+ ukm_source_id_ = web_contents->GetLastCommittedSourceId();
Observe(web_contents);
}
diff --git a/chrome/browser/navigation_predictor/navigation_predictor.h b/chrome/browser/navigation_predictor/navigation_predictor.h
index 2485012..fa75cb69 100644
--- a/chrome/browser/navigation_predictor/navigation_predictor.h
+++ b/chrome/browser/navigation_predictor/navigation_predictor.h
@@ -17,6 +17,7 @@
#include "content/public/browser/visibility.h"
#include "content/public/browser/web_contents_observer.h"
#include "mojo/public/cpp/bindings/interface_request.h"
+#include "services/metrics/public/cpp/ukm_source_id.h"
#include "third_party/blink/public/mojom/loader/navigation_predictor.mojom.h"
#include "ui/gfx/geometry/size.h"
#include "url/origin.h"
@@ -286,6 +287,11 @@
// PrerenderHandle returned after completing a prefetch in PrerenderManager.
std::unique_ptr<prerender::PrerenderHandle> prerender_handle_;
+ // UKM ID for navigation
+ // TODO(sofiyase): implement that function that uses this id to send aggregate
+ // link information to the UKM.
+ ukm::SourceId ukm_source_id_;
+
SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(NavigationPredictor);
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 3cc697a..4f1cac5 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -6725,6 +6725,10 @@
return GetAudioStreamFactory()->group_id();
}
+ukm::SourceId WebContentsImpl::GetLastCommittedSourceId() {
+ return last_committed_source_id_;
+}
+
BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
return browser_plugin_embedder_.get();
}
diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h
index 2fde40c..46a71cb 100644
--- a/content/browser/web_contents/web_contents_impl.h
+++ b/content/browser/web_contents/web_contents_impl.h
@@ -468,6 +468,7 @@
void SetShowingContextMenu(bool showing) override;
base::UnguessableToken GetAudioGroupId() override;
bool CompletedFirstVisuallyNonEmptyPaint() override;
+ ukm::SourceId GetLastCommittedSourceId() override;
#if defined(OS_ANDROID)
base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents() override;
diff --git a/content/public/browser/BUILD.gn b/content/public/browser/BUILD.gn
index 37d805b..acc91aa7d 100644
--- a/content/public/browser/BUILD.gn
+++ b/content/public/browser/BUILD.gn
@@ -415,6 +415,7 @@
"//net",
"//ppapi/c",
"//services/device/public/cpp/geolocation",
+ "//services/metrics/public/cpp:metrics_cpp",
"//services/service_manager/embedder:embedder_result_codes",
"//ui/accessibility",
"//ui/base",
diff --git a/content/public/browser/DEPS b/content/public/browser/DEPS
index 08ef71e..39f1a4a 100644
--- a/content/public/browser/DEPS
+++ b/content/public/browser/DEPS
@@ -7,6 +7,7 @@
"+device/fido",
"+services/device/public",
"+services/media_session/public",
+ "+services/metrics/public/cpp",
"+services/network/public/cpp",
"+services/service_manager/sandbox",
"+services/video_capture/public/mojom",
diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h
index 06536cf6..b0f5041 100644
--- a/content/public/browser/web_contents.h
+++ b/content/public/browser/web_contents.h
@@ -29,6 +29,7 @@
#include "content/public/browser/visibility.h"
#include "content/public/browser/web_ui.h"
#include "content/public/common/stop_find_action.h"
+#include "services/metrics/public/cpp/ukm_source_id.h"
#include "third_party/blink/public/common/frame/sandbox_flags.h"
#include "third_party/blink/public/mojom/frame/find_in_page.mojom-forward.h"
#include "third_party/blink/public/mojom/loader/pause_subresource_loading_handle.mojom-forward.h"
@@ -943,6 +944,9 @@
// created from a renderer that originated from this WebContents.
virtual base::UnguessableToken GetAudioGroupId() = 0;
+ // The source ID of the last committed navigation.
+ virtual ukm::SourceId GetLastCommittedSourceId() = 0;
+
private:
// This interface should only be implemented inside content.
friend class WebContentsImpl;