Commit 21f50494 authored by yusufo's avatar yusufo Committed by Commit Bot

Disable search functionality in ChromeActivity before search promo check

- Disable contextual search before we go through the search engine promo
check
- On a WebSearch from selection, first show the search engine promo and
only after that send the search intent.

BUG=728891

Review-Url: https://codereview.chromium.org/2926413002
Cr-Commit-Position: refs/heads/master@{#478677}
parent 528c7c50
......@@ -88,6 +88,7 @@ import org.chromium.chrome.browser.history.HistoryManagerUtils;
import org.chromium.chrome.browser.infobar.InfoBarContainer;
import org.chromium.chrome.browser.init.AsyncInitializationActivity;
import org.chromium.chrome.browser.init.ProcessInitializationHandler;
import org.chromium.chrome.browser.locale.LocaleManager;
import org.chromium.chrome.browser.media.PictureInPictureController;
import org.chromium.chrome.browser.metrics.LaunchMetrics;
import org.chromium.chrome.browser.metrics.StartupMetrics;
......@@ -740,7 +741,7 @@ public abstract class ChromeActivity extends AsyncInitializationActivity
* @return Whether contextual search is allowed for this activity or not.
*/
protected boolean isContextualSearchAllowed() {
return true;
return !LocaleManager.getInstance().needToCheckForSearchEnginePromo();
}
@Override
......@@ -1377,9 +1378,18 @@ public abstract class ChromeActivity extends AsyncInitializationActivity
return new IntentHandlerDelegate() {
@Override
public void processWebSearchIntent(String query) {
Intent searchIntent = new Intent(Intent.ACTION_WEB_SEARCH);
final Intent searchIntent = new Intent(Intent.ACTION_WEB_SEARCH);
searchIntent.putExtra(SearchManager.QUERY, query);
startActivity(searchIntent);
Callback<Boolean> callback = new Callback<Boolean>() {
@Override
public void onResult(Boolean result) {
if (result != null && result) startActivity(searchIntent);
}
};
if (!LocaleManager.getInstance().showSearchEnginePromoIfNeeded(
ChromeActivity.this, callback)) {
callback.onResult(true);
}
}
@Override
......
......@@ -8,6 +8,7 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.StrictMode;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
......@@ -113,8 +114,14 @@ public class LocaleManager {
* Default constructor.
*/
public LocaleManager() {
int state = ContextUtils.getAppSharedPreferences().getInt(
KEY_SEARCH_ENGINE_PROMO_SHOW_STATE, SEARCH_ENGINE_PROMO_SHOULD_CHECK);
int state = SEARCH_ENGINE_PROMO_SHOULD_CHECK;
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
ContextUtils.getAppSharedPreferences().getInt(
KEY_SEARCH_ENGINE_PROMO_SHOW_STATE, SEARCH_ENGINE_PROMO_SHOULD_CHECK);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
mSearchEnginePromoCompleted = state == SEARCH_ENGINE_PROMO_CHECKED_AND_SHOWN;
}
......@@ -449,8 +456,14 @@ public class LocaleManager {
* @return Whether we still have to check for whether search engine dialog is necessary.
*/
public boolean needToCheckForSearchEnginePromo() {
int state = ContextUtils.getAppSharedPreferences().getInt(
KEY_SEARCH_ENGINE_PROMO_SHOW_STATE, SEARCH_ENGINE_PROMO_SHOULD_CHECK);
int state = SEARCH_ENGINE_PROMO_SHOULD_CHECK;
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
ContextUtils.getAppSharedPreferences().getInt(
KEY_SEARCH_ENGINE_PROMO_SHOW_STATE, SEARCH_ENGINE_PROMO_SHOULD_CHECK);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
return state == SEARCH_ENGINE_PROMO_SHOULD_CHECK;
}
......
......@@ -58,6 +58,7 @@ import org.chromium.chrome.browser.contextualsearch.ContextualSearchInternalStat
import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler;
import org.chromium.chrome.browser.firstrun.FirstRunStatus;
import org.chromium.chrome.browser.gsa.GSAContextDisplaySelection;
import org.chromium.chrome.browser.locale.LocaleManager;
import org.chromium.chrome.browser.omnibox.UrlBar;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver;
......@@ -145,6 +146,13 @@ public class ContextualSearchManagerTest {
FirstRunStatus.setFirstRunFlowComplete(true);
}
});
LocaleManager.setInstanceForTest(new LocaleManager() {
@Override
public boolean needToCheckForSearchEnginePromo() {
return false;
}
});
mActivityTestRule.startMainActivityWithURL(mTestServer.getURL(TEST_PAGE));
// There's a problem with immediate startup that causes flakes due to the page not being
// ready, so specify a startup-delay of 1000 for legacy behavior. See crbug.com/635661.
......
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