Add UKM to record actions associated with the Pepper Broker

Records when the Pepper broker process channel is opened by a plugin.

Bug: 756138
Change-Id: Ibc480af41cb0f0b004d167dcefae325e7920b7ad
Reviewed-on: https://chromium-review.googlesource.com/778743
Commit-Queue: Raymes Khoury <[email protected]>
Reviewed-by: Brett Wilson <[email protected]>
Reviewed-by: Alexei Svitkine <[email protected]>
Cr-Commit-Position: refs/heads/master@{#519228}
diff --git a/content/browser/plugin_service_impl.cc b/content/browser/plugin_service_impl.cc
index 545d953..0378ab3 100644
--- a/content/browser/plugin_service_impl.cc
+++ b/content/browser/plugin_service_impl.cc
@@ -32,11 +32,14 @@
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/content_browser_client.h"
 #include "content/public/browser/plugin_service_filter.h"
+#include "content/public/browser/render_frame_host.h"
 #include "content/public/browser/resource_context.h"
+#include "content/public/browser/web_contents.h"
 #include "content/public/common/content_constants.h"
 #include "content/public/common/content_switches.h"
 #include "content/public/common/process_type.h"
 #include "content/public/common/webplugininfo.h"
+#include "services/metrics/public/cpp/ukm_builders.h"
 
 namespace content {
 namespace {
@@ -57,6 +60,17 @@
   DCHECK(sequence_checker->CalledOnValidSequence());
 }
 
+void RecordBrokerUsage(int render_process_id, int render_frame_id) {
+  ukm::UkmRecorder* recorder = ukm::UkmRecorder::Get();
+  ukm::SourceId source_id = ukm::UkmRecorder::GetNewSourceID();
+  WebContents* web_contents = WebContents::FromRenderFrameHost(
+      RenderFrameHost::FromID(render_process_id, render_frame_id));
+  if (web_contents) {
+    recorder->UpdateSourceURL(source_id, web_contents->GetLastCommittedURL());
+    ukm::builders::Pepper_Broker(source_id).Record(recorder);
+  }
+}
+
 }  // namespace
 
 // static
@@ -213,8 +227,13 @@
 
 void PluginServiceImpl::OpenChannelToPpapiBroker(
     int render_process_id,
+    int render_frame_id,
     const base::FilePath& path,
     PpapiPluginProcessHost::BrokerClient* client) {
+  BrowserThread::PostTask(
+      BrowserThread::UI, FROM_HERE,
+      base::Bind(&RecordBrokerUsage, render_process_id, render_frame_id));
+
   PpapiPluginProcessHost* plugin_host = FindOrStartPpapiBrokerProcess(
       render_process_id, path);
   if (plugin_host) {