Commit 5ea50535 authored by Anna Offenwanger's avatar Anna Offenwanger Committed by Commit Bot

Add code to record URL Omnibox entry in VR

For VR UKM Metrics recording.

Bug: 808584
Cq-Include-Trybots: luci.chromium.try:linux_optional_gpu_tests_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_vr;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I98418d91b0df01c265683362349cff6365d375c8
Reviewed-on: https://chromium-review.googlesource.com/959440
Commit-Queue: Anna Offenwanger <offenwanger@chromium.org>
Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Reviewed-by: default avatarChristopher Grant <cjgrant@chromium.org>
Reviewed-by: default avatarTibor Goldschwendt <tiborg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543789}
parent 7667979b
...@@ -209,10 +209,11 @@ void VrGLThread::OnContentPaused(bool enabled) { ...@@ -209,10 +209,11 @@ void VrGLThread::OnContentPaused(bool enabled) {
base::BindOnce(&VrShell::OnContentPaused, weak_vr_shell_, enabled)); base::BindOnce(&VrShell::OnContentPaused, weak_vr_shell_, enabled));
} }
void VrGLThread::Navigate(GURL gurl) { void VrGLThread::Navigate(GURL gurl, NavigationMethod method) {
DCHECK(OnGlThread()); DCHECK(OnGlThread());
main_thread_task_runner_->PostTask( main_thread_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&VrShell::Navigate, weak_vr_shell_, gurl)); FROM_HERE,
base::BindOnce(&VrShell::Navigate, weak_vr_shell_, gurl, method));
} }
void VrGLThread::NavigateBack() { void VrGLThread::NavigateBack() {
......
...@@ -79,7 +79,7 @@ class VrGLThread : public base::android::JavaHandlerThread, ...@@ -79,7 +79,7 @@ class VrGLThread : public base::android::JavaHandlerThread,
// UiBrowserInterface implementation (UI calling to VrShell). // UiBrowserInterface implementation (UI calling to VrShell).
void ExitPresent() override; void ExitPresent() override;
void ExitFullscreen() override; void ExitFullscreen() override;
void Navigate(GURL gurl) override; void Navigate(GURL gurl, NavigationMethod method) override;
void NavigateBack() override; void NavigateBack() override;
void ExitCct() override; void ExitCct() override;
void CloseHostedDialog() override; void CloseHostedDialog() override;
......
...@@ -331,8 +331,18 @@ void VrShell::OnContentPaused(bool paused) { ...@@ -331,8 +331,18 @@ void VrShell::OnContentPaused(bool paused) {
device->Focus(); device->Focus();
} }
void VrShell::Navigate(GURL url) { void VrShell::Navigate(GURL url, NavigationMethod method) {
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
// Record metrics.
if (method == NavigationMethod::kOmniboxSuggestionSelected ||
method == NavigationMethod::kOmniboxUrlEntry) {
SessionMetricsHelper* metrics_helper =
SessionMetricsHelper::FromWebContents(web_contents_);
if (metrics_helper)
metrics_helper->RecordUrlRequested(url, method);
}
Java_VrShellImpl_loadUrl( Java_VrShellImpl_loadUrl(
env, j_vr_shell_, env, j_vr_shell_,
base::android::ConvertUTF8ToJavaString(env, url.spec())); base::android::ConvertUTF8ToJavaString(env, url.spec()));
...@@ -1016,7 +1026,7 @@ void VrShell::OnVoiceResults(const base::string16& result) { ...@@ -1016,7 +1026,7 @@ void VrShell::OnVoiceResults(const base::string16& result) {
SessionMetricsHelper* metrics_helper = SessionMetricsHelper* metrics_helper =
SessionMetricsHelper::FromWebContents(web_contents_); SessionMetricsHelper::FromWebContents(web_contents_);
if (metrics_helper && input_was_url) if (metrics_helper && input_was_url)
metrics_helper->RecordUrlRequestedByVoice(url); metrics_helper->RecordUrlRequested(url, NavigationMethod::kVoiceSearch);
Java_VrShellImpl_loadUrl( Java_VrShellImpl_loadUrl(
env, j_vr_shell_, env, j_vr_shell_,
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "chrome/browser/vr/exit_vr_prompt_choice.h" #include "chrome/browser/vr/exit_vr_prompt_choice.h"
#include "chrome/browser/vr/speech_recognizer.h" #include "chrome/browser/vr/speech_recognizer.h"
#include "chrome/browser/vr/ui.h" #include "chrome/browser/vr/ui.h"
#include "chrome/browser/vr/ui_browser_interface.h"
#include "chrome/browser/vr/ui_unsupported_mode.h" #include "chrome/browser/vr/ui_unsupported_mode.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "device/vr/android/gvr/cardboard_gamepad_data_provider.h" #include "device/vr/android/gvr/cardboard_gamepad_data_provider.h"
...@@ -122,7 +123,7 @@ class VrShell : device::GvrGamepadDataProvider, ...@@ -122,7 +123,7 @@ class VrShell : device::GvrGamepadDataProvider,
jboolean incognito, jboolean incognito,
jint id); jint id);
void OnContentPaused(bool paused); void OnContentPaused(bool paused);
void Navigate(GURL url); void Navigate(GURL url, NavigationMethod method);
void NavigateBack(); void NavigateBack();
void ExitCct(); void ExitCct();
void CloseHostedDialog(); void CloseHostedDialog();
......
...@@ -300,8 +300,10 @@ void SessionMetricsHelper::RecordVoiceSearchStarted() { ...@@ -300,8 +300,10 @@ void SessionMetricsHelper::RecordVoiceSearchStarted() {
num_voice_search_started_++; num_voice_search_started_++;
} }
void SessionMetricsHelper::RecordUrlRequestedByVoice(GURL url) { void SessionMetricsHelper::RecordUrlRequested(GURL url,
url_requested_by_voice_ = url; NavigationMethod method) {
last_requested_url_ = url;
last_url_request_method_ = method;
} }
void SessionMetricsHelper::SetVrMode(Mode new_mode) { void SessionMetricsHelper::SetVrMode(Mode new_mode) {
...@@ -558,13 +560,21 @@ void SessionMetricsHelper::DidFinishNavigation( ...@@ -558,13 +560,21 @@ void SessionMetricsHelper::DidFinishNavigation(
ukm::GetSourceIdForWebContentsDocument(web_contents()))); ukm::GetSourceIdForWebContentsDocument(web_contents())));
// Check that the completed navigation is indeed the one that was requested // Check that the completed navigation is indeed the one that was requested
// by voice, in case that one was incomplete and another was begun. Check // by either voice or omnibox entry, in case the requested navigation was
// against the first entry for the navigation, as redirects might have // incomplete when another was begun. Check against the first entry for the
// changed what the URL looks like. // navigation, as redirects might have changed what the URL looks like.
if (url_requested_by_voice_ == handle->GetRedirectChain().front()) { if (last_requested_url_ == handle->GetRedirectChain().front()) {
page_session_tracker_->ukm_entry()->SetWasVoiceSearchNavigation(1); switch (last_url_request_method_) {
case kOmniboxUrlEntry:
case kOmniboxSuggestionSelected:
page_session_tracker_->ukm_entry()->SetWasOmniboxNavigation(1);
break;
case kVoiceSearch:
page_session_tracker_->ukm_entry()->SetWasVoiceSearchNavigation(1);
break;
}
} }
url_requested_by_voice_ = GURL(); last_requested_url_ = GURL();
if (mode_ == Mode::kWebXrVrPresentation) { if (mode_ == Mode::kWebXrVrPresentation) {
presentation_session_tracker_ = std::make_unique< presentation_session_tracker_ = std::make_unique<
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/vr/mode.h" #include "chrome/browser/vr/mode.h"
#include "chrome/browser/vr/ui_browser_interface.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "services/metrics/public/cpp/ukm_builders.h" #include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_source_id.h" #include "services/metrics/public/cpp/ukm_source_id.h"
...@@ -118,7 +119,7 @@ class SessionMetricsHelper : public content::WebContentsObserver { ...@@ -118,7 +119,7 @@ class SessionMetricsHelper : public content::WebContentsObserver {
void SetWebVREnabled(bool is_webvr_presenting); void SetWebVREnabled(bool is_webvr_presenting);
void SetVRActive(bool is_vr_enabled); void SetVRActive(bool is_vr_enabled);
void RecordVoiceSearchStarted(); void RecordVoiceSearchStarted();
void RecordUrlRequestedByVoice(GURL url); void RecordUrlRequested(GURL url, NavigationMethod method);
private: private:
SessionMetricsHelper(content::WebContents* contents, SessionMetricsHelper(content::WebContents* contents,
...@@ -165,7 +166,8 @@ class SessionMetricsHelper : public content::WebContentsObserver { ...@@ -165,7 +166,8 @@ class SessionMetricsHelper : public content::WebContentsObserver {
bool is_vr_enabled_ = false; bool is_vr_enabled_ = false;
bool started_with_autopresentation_ = false; bool started_with_autopresentation_ = false;
GURL url_requested_by_voice_; GURL last_requested_url_;
NavigationMethod last_url_request_method_;
int num_videos_playing_ = 0; int num_videos_playing_ = 0;
int num_session_navigation_ = 0; int num_session_navigation_ = 0;
......
...@@ -18,7 +18,7 @@ class MockUiBrowserInterface : public UiBrowserInterface { ...@@ -18,7 +18,7 @@ class MockUiBrowserInterface : public UiBrowserInterface {
MOCK_METHOD0(ExitPresent, void()); MOCK_METHOD0(ExitPresent, void());
MOCK_METHOD0(ExitFullscreen, void()); MOCK_METHOD0(ExitFullscreen, void());
MOCK_METHOD1(Navigate, void(GURL gurl)); MOCK_METHOD2(Navigate, void(GURL gurl, NavigationMethod method));
MOCK_METHOD0(NavigateBack, void()); MOCK_METHOD0(NavigateBack, void());
MOCK_METHOD0(ExitCct, void()); MOCK_METHOD0(ExitCct, void());
MOCK_METHOD0(CloseHostedDialog, void()); MOCK_METHOD0(CloseHostedDialog, void());
......
...@@ -459,7 +459,7 @@ void VrTestContext::SetVoiceSearchActive(bool active) { ...@@ -459,7 +459,7 @@ void VrTestContext::SetVoiceSearchActive(bool active) {
void VrTestContext::ExitPresent() {} void VrTestContext::ExitPresent() {}
void VrTestContext::ExitFullscreen() {} void VrTestContext::ExitFullscreen() {}
void VrTestContext::Navigate(GURL gurl) { void VrTestContext::Navigate(GURL gurl, NavigationMethod method) {
ToolbarState state(gurl, security_state::SecurityLevel::HTTP_SHOW_WARNING, ToolbarState state(gurl, security_state::SecurityLevel::HTTP_SHOW_WARNING,
&toolbar::kHttpIcon, base::string16(), true, false); &toolbar::kHttpIcon, base::string16(), true, false);
ui_->SetToolbarState(state); ui_->SetToolbarState(state);
......
...@@ -53,7 +53,7 @@ class VrTestContext : public vr::UiBrowserInterface { ...@@ -53,7 +53,7 @@ class VrTestContext : public vr::UiBrowserInterface {
void SetVoiceSearchActive(bool active) override; void SetVoiceSearchActive(bool active) override;
void StartAutocomplete(const AutocompleteRequest& request) override; void StartAutocomplete(const AutocompleteRequest& request) override;
void StopAutocomplete() override; void StopAutocomplete() override;
void Navigate(GURL gurl) override; void Navigate(GURL gurl, NavigationMethod method) override;
void set_window_size(const gfx::Size& size) { window_size_ = size; } void set_window_size(const gfx::Size& size) { window_size_ = size; }
......
...@@ -13,6 +13,13 @@ ...@@ -13,6 +13,13 @@
namespace vr { namespace vr {
// A actions which can trigger the navigate function.
enum NavigationMethod {
kOmniboxUrlEntry,
kOmniboxSuggestionSelected,
kVoiceSearch,
};
// An interface for the VR UI to communicate with VrShell. Many of the functions // An interface for the VR UI to communicate with VrShell. Many of the functions
// in this interface are proxies to methods on VrShell. // in this interface are proxies to methods on VrShell.
class UiBrowserInterface { class UiBrowserInterface {
...@@ -21,7 +28,7 @@ class UiBrowserInterface { ...@@ -21,7 +28,7 @@ class UiBrowserInterface {
virtual void ExitPresent() = 0; virtual void ExitPresent() = 0;
virtual void ExitFullscreen() = 0; virtual void ExitFullscreen() = 0;
virtual void Navigate(GURL gurl) = 0; virtual void Navigate(GURL gurl, NavigationMethod method) = 0;
virtual void NavigateBack() = 0; virtual void NavigateBack() = 0;
virtual void ExitCct() = 0; virtual void ExitCct() = 0;
virtual void CloseHostedDialog() = 0; virtual void CloseHostedDialog() = 0;
......
...@@ -188,7 +188,8 @@ void OnSuggestionModelAdded(UiScene* scene, ...@@ -188,7 +188,8 @@ void OnSuggestionModelAdded(UiScene* scene,
kNone, kPhaseForeground, kNone, kPhaseForeground,
base::BindRepeating( base::BindRepeating(
[](UiBrowserInterface* b, Ui* ui, Model* m, SuggestionBinding* e) { [](UiBrowserInterface* b, Ui* ui, Model* m, SuggestionBinding* e) {
b->Navigate(e->model()->destination); b->Navigate(e->model()->destination,
NavigationMethod::kOmniboxSuggestionSelected);
ui->OnUiRequestedNavigation(); ui->OnUiRequestedNavigation();
}, },
base::Unretained(browser), base::Unretained(ui), base::Unretained(browser), base::Unretained(ui),
...@@ -1998,7 +1999,8 @@ void UiSceneCreator::CreateOmnibox() { ...@@ -1998,7 +1999,8 @@ void UiSceneCreator::CreateOmnibox() {
[](Model* model, UiBrowserInterface* browser, Ui* ui, [](Model* model, UiBrowserInterface* browser, Ui* ui,
const EditedText& text) { const EditedText& text) {
if (!model->omnibox_suggestions.empty()) { if (!model->omnibox_suggestions.empty()) {
browser->Navigate(model->omnibox_suggestions.front().destination); browser->Navigate(model->omnibox_suggestions.front().destination,
NavigationMethod::kOmniboxUrlEntry);
ui->OnUiRequestedNavigation(); ui->OnUiRequestedNavigation();
} }
}, },
......
...@@ -997,7 +997,9 @@ TEST_F(UiTest, OmniboxSuggestionNavigates) { ...@@ -997,7 +997,9 @@ TEST_F(UiTest, OmniboxSuggestionNavigates) {
ASSERT_NE(suggestions, nullptr); ASSERT_NE(suggestions, nullptr);
UiElement* suggestion = suggestions->children().front().get(); UiElement* suggestion = suggestions->children().front().get();
ASSERT_NE(suggestion, nullptr); ASSERT_NE(suggestion, nullptr);
EXPECT_CALL(*browser_, Navigate(gurl)).Times(1); EXPECT_CALL(*browser_,
Navigate(gurl, NavigationMethod::kOmniboxSuggestionSelected))
.Times(1);
suggestion->OnHoverEnter({0, 0}); suggestion->OnHoverEnter({0, 0});
suggestion->OnButtonDown({0, 0}); suggestion->OnButtonDown({0, 0});
suggestion->OnButtonUp({0, 0}); suggestion->OnButtonUp({0, 0});
......
...@@ -3169,6 +3169,12 @@ be describing additional metrics about the same event. ...@@ -3169,6 +3169,12 @@ be describing additional metrics about the same event.
Deprecated. Deprecated.
</summary> </summary>
</metric> </metric>
<metric name="WasOmniboxNavigation">
<summary>
A boolean that is set to 1 if this page was entered into the omnibox,
either manually or using autocomplete.
</summary>
</metric>
<metric name="WasVoiceSearchNavigation"> <metric name="WasVoiceSearchNavigation">
<summary> <summary>
A boolean that is set to 1 if this page was specifically requested and A boolean that is set to 1 if this page was specifically requested and
......
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