0

[unseasoned-pdf] Enable user action recording

Recording user actions in a renderer process can't be done using
base::RecordAction and friends because there is no running metrics
service. Instead, there's a call in the content layer, which passes the
actions across an IPC bridge, so the actions can be recorded in the
browser process.

Since the call is in the content layer, inject a dependency using the
Client interface.

Fixed: 1231356
Change-Id: I6e6cc5d2f652c9f8b930ce5d9355284028b8be1b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3043668
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#905385}
This commit is contained in:
Daniel Hosseinian
2021-07-26 20:10:12 +00:00
committed by Chromium LUCI CQ
parent cd53a9acc7
commit 18596eb2ce
5 changed files with 13 additions and 4 deletions

@ -2836,7 +2836,7 @@ IN_PROC_BROWSER_TEST_P(PDFExtensionTest,
ASSERT_TRUE(LoadPdf(test_pdf_url));
}
IN_PROC_BROWSER_TEST_F(PDFExtensionTestWithoutUnseasonedOverride, Metrics) {
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Metrics) {
base::HistogramTester histograms;
base::UserActionTester actions;

@ -5,6 +5,7 @@
#include "components/pdf/renderer/pdf_view_web_plugin_client.h"
#include "base/check.h"
#include "content/public/renderer/render_thread.h"
#include "printing/buildflags/buildflags.h"
#include "third_party/blink/public/web/web_element.h"
@ -29,4 +30,8 @@ void PdfViewWebPluginClient::Print(const blink::WebElement& element) {
#endif // BUILDFLAG(ENABLE_PRINTING)
}
void PdfViewWebPluginClient::RecordComputedAction(const std::string& action) {
content::RenderThread::Get()->RecordComputedAction(action);
}
} // namespace pdf

@ -22,6 +22,7 @@ class PdfViewWebPluginClient : public chrome_pdf::PdfViewWebPlugin::Client {
// chrome_pdf::PdfViewWebPlugin::Client:
void Print(const blink::WebElement& element) override;
void RecordComputedAction(const std::string& action) override;
private:
content::RenderFrame* const render_frame_;

@ -14,8 +14,6 @@
#include "base/check_op.h"
#include "base/i18n/string_search.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/thread_annotations.h"
@ -781,7 +779,7 @@ void PdfViewWebPlugin::NotifyUnsupportedFeature() {
}
void PdfViewWebPlugin::UserMetricsRecordAction(const std::string& action) {
base::RecordAction(base::UserMetricsAction(action.c_str()));
client_->RecordComputedAction(action);
}
void PdfViewWebPlugin::OnViewportChanged(const gfx::Rect& view_rect,

@ -119,6 +119,11 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
// Prints the given `element`.
virtual void Print(const blink::WebElement& element) {}
// Sends over a string to be recorded by user metrics as a computed action.
// When you use this, you need to also update the rules for extracting known
// actions in tools/metrics/actions/extract_actions.py.
virtual void RecordComputedAction(const std::string& action) {}
};
PdfViewWebPlugin(