Commit ce1adfa1 authored by Theresa's avatar Theresa Committed by Commit Bot

[EoC] Don't record toolbar button shown while in tab switcher

Rather, wait to record until the user exits the tab switcher to try to
record. The user must exist the tab switcher on the tab for which
results were returned.

Also logs a histogram indicating whether results were returned while the
user was in the tab switcher so that we can ballpark estimate
adjustments needed to M69 metrics.

BUG=890366

Change-Id: Ic5726907911df15d4bc6a5cbd97633fcf7415595
Reviewed-on: https://chromium-review.googlesource.com/1252627Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Commit-Queue: Theresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595852}
parent 0aa11802
......@@ -15,8 +15,13 @@ import android.view.View;
import org.chromium.base.ContextUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.compositor.layouts.EmptyOverviewModeObserver;
import org.chromium.chrome.browser.compositor.layouts.LayoutManager;
import org.chromium.chrome.browser.compositor.layouts.LayoutManagerChrome;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior;
import org.chromium.chrome.browser.contextual_suggestions.ContextualSuggestionsBridge.ContextualSuggestionsResult;
import org.chromium.chrome.browser.dependency_injection.ActivityScope;
import org.chromium.chrome.browser.feature_engagement.TrackerFactory;
......@@ -68,6 +73,7 @@ class ContextualSuggestionsMediator
private final EnabledStateMonitor mEnabledStateMonitor;
private final Handler mHandler = new Handler();
private final Provider<ContextualSuggestionsSource> mSuggestionSourceProvider;
private @Nullable final OverviewModeBehavior mOverviewModeBehavior;
private ContextualSuggestionsCoordinator mCoordinator;
private View mIphParentView;
......@@ -95,15 +101,18 @@ class ContextualSuggestionsMediator
* events.
* @param model The {@link ContextualSuggestionsModel} for the component.
* @param toolbarManager The {@link ToolbarManager} for the containing activity.
* @param layoutManager The {@link LayoutManager} used to retrieve the
* {@link OverviewModeBehavior} if it exists.
* @param enabledStateMonitor The state monitor that will alert the mediator if the enabled
* state for contextual suggestions changes.
* @param suggestionSourceProvider The provider of {@link ContextualSuggestionsSource} instances.
* @param suggestionSourceProvider The provider of {@link ContextualSuggestionsSource}
* instances.
*/
@Inject
ContextualSuggestionsMediator(@Named(LAST_USED_PROFILE) Profile profile,
TabModelSelector tabModelSelector, ChromeFullscreenManager fullscreenManager,
ContextualSuggestionsModel model, ToolbarManager toolbarManager,
EnabledStateMonitor enabledStateMonitor,
LayoutManager layoutManager, EnabledStateMonitor enabledStateMonitor,
Provider<ContextualSuggestionsSource> suggestionSourceProvider) {
mProfile = profile.getOriginalProfile();
mTabModelSelector = tabModelSelector;
......@@ -135,6 +144,18 @@ class ContextualSuggestionsMediator
@Override
public void onBottomControlsHeightChanged(int bottomControlsHeight) {}
});
if (layoutManager instanceof LayoutManagerChrome) {
mOverviewModeBehavior = (LayoutManagerChrome) layoutManager;
mOverviewModeBehavior.addOverviewModeObserver(new EmptyOverviewModeObserver() {
@Override
public void onOverviewModeFinishedHiding() {
reportToolbarButtonShown();
}
});
} else {
mOverviewModeBehavior = null;
}
}
/**
......@@ -243,6 +264,8 @@ class ContextualSuggestionsMediator
view -> onToolbarButtonClicked(),
R.drawable.contextual_suggestions,
R.string.contextual_suggestions_button_description);
RecordHistogram.recordBooleanHistogram(
"ContextualSuggestions.ResultsReturnedInOverviewMode", isOverviewModeVisible());
reportToolbarButtonShown();
});
}
......@@ -281,7 +304,7 @@ class ContextualSuggestionsMediator
}
private void reportToolbarButtonShown() {
if (mHasRecordedButtonShownForTab || areBrowserControlsHidden()
if (mHasRecordedButtonShownForTab || areBrowserControlsHidden() || isOverviewModeVisible()
|| mSuggestionsSource == null || !mModel.hasSuggestions()) {
return;
}
......@@ -483,6 +506,10 @@ class ContextualSuggestionsMediator
mSuggestionsSource.reportEvent(mTabModelSelector.getCurrentTab().getWebContents(), event);
}
private boolean isOverviewModeVisible() {
return mOverviewModeBehavior != null && mOverviewModeBehavior.overviewVisible();
}
@VisibleForTesting
void showContentInSheetForTesting(boolean disablePeekDelay) {
if (disablePeekDelay) mHasPeekDelayPassed = true;
......
......@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.dependency_injection;
import android.content.res.Resources;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.compositor.layouts.LayoutManager;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.toolbar.ToolbarManager;
......@@ -42,7 +43,6 @@ public class ChromeActivityCommonsModule {
return mActivity.getTabModelSelector();
}
@Provides
public ChromeFullscreenManager provideChromeFullscreenManager() {
return mActivity.getFullscreenManager();
......@@ -53,6 +53,11 @@ public class ChromeActivityCommonsModule {
return mActivity.getToolbarManager();
}
@Provides
public LayoutManager provideLayoutManager() {
return mActivity.getCompositorViewHolder().getLayoutManager();
}
@Provides
public ChromeActivity provideChromeActivity() {
// Ideally this should provide only the Context instead of specific activity, but currently
......
......@@ -15168,6 +15168,16 @@ uploading your change for review.
</summary>
</histogram>
<histogram name="ContextualSuggestions.ResultsReturnedInOverviewMode"
enum="BooleanEnabled" expires_after="2019-01-30">
<owner>twellington@chromium.org</owner>
<owner>huayinz@chromium.org</owner>
<summary>
Android: Whether the contextual suggestions results are returned to the
UI-layer while the user is in overview mode.
</summary>
</histogram>
<histogram base="true" name="Cookie.AgeFor" units="days">
<owner>mkwst@chromium.org</owner>
<owner>tnagel@chromium.org</owner>
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