Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/locale/DefaultSearchEnginePromoDialog.java

Issue 2928653003: Ensure only one live search engine promo. (Closed)
Patch Set: Fix findbugs Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/widget/AlwaysDismissedDialog.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.locale; 5 package org.chromium.chrome.browser.locale;
6 6
7 import android.annotation.SuppressLint;
7 import android.app.Activity; 8 import android.app.Activity;
8 import android.content.DialogInterface; 9 import android.content.DialogInterface;
9 import android.os.Bundle; 10 import android.os.Bundle;
10 import android.support.annotation.Nullable; 11 import android.support.annotation.Nullable;
11 import android.widget.Button; 12 import android.widget.Button;
12 13
13 import org.chromium.base.Callback; 14 import org.chromium.base.Callback;
14 import org.chromium.base.VisibleForTesting; 15 import org.chromium.base.VisibleForTesting;
15 import org.chromium.base.metrics.RecordUserAction; 16 import org.chromium.base.metrics.RecordUserAction;
16 import org.chromium.chrome.R; 17 import org.chromium.chrome.R;
17 import org.chromium.chrome.browser.locale.LocaleManager.SearchEnginePromoType; 18 import org.chromium.chrome.browser.locale.LocaleManager.SearchEnginePromoType;
18 import org.chromium.chrome.browser.widget.PromoDialog; 19 import org.chromium.chrome.browser.widget.PromoDialog;
19 import org.chromium.chrome.browser.widget.RadioButtonLayout; 20 import org.chromium.chrome.browser.widget.RadioButtonLayout;
20 21
21 /** A dialog that forces the user to choose a default search engine. */ 22 /** A dialog that forces the user to choose a default search engine. */
22 public class DefaultSearchEnginePromoDialog extends PromoDialog { 23 public class DefaultSearchEnginePromoDialog extends PromoDialog {
23 /** Notified about events happening to the dialog. */ 24 /** Notified about events happening to the dialog. */
24 public static interface DefaultSearchEnginePromoDialogObserver { 25 public static interface DefaultSearchEnginePromoDialogObserver {
25 void onDialogShown(DefaultSearchEnginePromoDialog shownDialog); 26 void onDialogShown(DefaultSearchEnginePromoDialog shownDialog);
26 } 27 }
27 private static DefaultSearchEnginePromoDialogObserver sObserver; 28 private static DefaultSearchEnginePromoDialogObserver sObserver;
28 29
30 @SuppressLint("StaticFieldLeak")
31 private static DefaultSearchEnginePromoDialog sCurrentDialog;
32
29 /** Used to determine the promo dialog contents. */ 33 /** Used to determine the promo dialog contents. */
30 @SearchEnginePromoType 34 @SearchEnginePromoType
31 private final int mDialogType; 35 private final int mDialogType;
32 36
33 /** Called when the dialog is dismissed after the user has chosen a search e ngine. */ 37 /** Called when the dialog is dismissed after the user has chosen a search e ngine. */
34 private final Callback<Boolean> mOnDismissed; 38 private final Callback<Boolean> mOnDismissed;
35 39
36 /** Encapsulates most of the logic for filling the dialog and handling click s. */ 40 /** Encapsulates most of the logic for filling the dialog and handling click s. */
37 private DefaultSearchEngineDialogHelper mHelper; 41 private DefaultSearchEngineDialogHelper mHelper;
38 42
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 dismiss(); 87 dismiss();
84 } 88 }
85 }; 89 };
86 mHelper = new DefaultSearchEngineDialogHelper( 90 mHelper = new DefaultSearchEngineDialogHelper(
87 mDialogType, radioButtons, okButton, dismissRunnable); 91 mDialogType, radioButtons, okButton, dismissRunnable);
88 } 92 }
89 93
90 @Override 94 @Override
91 public void show() { 95 public void show() {
92 super.show(); 96 super.show();
97 if (sCurrentDialog != null) sCurrentDialog.dismiss();
98 setCurrentDialog(this);
99
93 if (mDialogType == LocaleManager.SEARCH_ENGINE_PROMO_SHOW_NEW) { 100 if (mDialogType == LocaleManager.SEARCH_ENGINE_PROMO_SHOW_NEW) {
94 RecordUserAction.record("SearchEnginePromo.NewDevice.Shown.Dialog"); 101 RecordUserAction.record("SearchEnginePromo.NewDevice.Shown.Dialog");
95 } else if (mDialogType == LocaleManager.SEARCH_ENGINE_PROMO_SHOW_EXISTIN G) { 102 } else if (mDialogType == LocaleManager.SEARCH_ENGINE_PROMO_SHOW_EXISTIN G) {
96 RecordUserAction.record("SearchEnginePromo.ExistingDevice.Shown.Dial og"); 103 RecordUserAction.record("SearchEnginePromo.ExistingDevice.Shown.Dial og");
97 } 104 }
98 if (sObserver != null) sObserver.onDialogShown(this); 105 if (sObserver != null) sObserver.onDialogShown(this);
99 } 106 }
100 107
101 @Override 108 @Override
102 public void onDismiss(DialogInterface dialog) { 109 public void onDismiss(DialogInterface dialog) {
103 if (mHelper.getCurrentlySelectedKeyword() == null) { 110 if (mHelper.getCurrentlySelectedKeyword() == null) {
104 // If no selection, finish the Activity so that the user has to resp ond to the dialog 111 // If no selection, finish the Activity so that the user has to resp ond to the dialog
105 // next time. 112 // next time.
106 if (getOwnerActivity() != null) getOwnerActivity().finish(); 113 if (getOwnerActivity() != null) getOwnerActivity().finish();
107 } 114 }
108 115
109 if (mOnDismissed != null) { 116 if (mOnDismissed != null) {
110 mOnDismissed.onResult(mHelper.getCurrentlySelectedKeyword() != null) ; 117 mOnDismissed.onResult(mHelper.getCurrentlySelectedKeyword() != null) ;
111 } 118 }
119
120 if (sCurrentDialog == this) setCurrentDialog(null);
112 } 121 }
113 122
114 /** See {@link #sObserver}. */ 123 /** See {@link #sObserver}. */
115 @VisibleForTesting 124 @VisibleForTesting
116 @Nullable 125 @Nullable
117 public static void setObserverForTests(DefaultSearchEnginePromoDialogObserve r observer) { 126 public static void setObserverForTests(DefaultSearchEnginePromoDialogObserve r observer) {
118 sObserver = observer; 127 sObserver = observer;
119 } 128 }
129
130 /** @return The current visible Default Search Engine dialog. */
131 static DefaultSearchEnginePromoDialog getCurrentDialog() {
132 return sCurrentDialog;
133 }
134
135 private static void setCurrentDialog(DefaultSearchEnginePromoDialog dialog) {
136 sCurrentDialog = dialog;
137 }
120 } 138 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/widget/AlwaysDismissedDialog.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698