Commit d55503d4 authored by Brandon Wylie's avatar Brandon Wylie Committed by Commit Bot

Observe TemplateUrlService directly from LocationBarLayout

Currently ToolbarManager pokes at LocationBar from the observer there.
Instead, LocationBar now observers the service directly and the
interface method can be removed.

Bug: 1132073
Change-Id: Ie56487252c4142f78f618fe6cb7c93ab173d6a7a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441682Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Brandon Wylie <wylieb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812905}
parent 0729852d
......@@ -829,10 +829,6 @@ public class CustomTabToolbar extends ToolbarLayout implements View.OnLongClickL
@Override
public void setUnfocusedWidth(int unfocusedWidth) {}
@Override
public void updateSearchEngineStatusIcon(boolean shouldShowSearchEngineLogo,
boolean isSearchEngineGoogle, String searchEngineUrl) {}
// Implements FakeBoxDelegate.
@Override
public boolean isUrlBarFocused() {
......
......@@ -205,17 +205,6 @@ public interface LocationBar extends UrlBarDelegate, FakeboxDelegate {
*/
void setUnfocusedWidth(int unfocusedWidth);
/**
* Called when the default search engine changes.
* @param shouldShowSearchEngineLogo True if the search engine should be shown. Prefer to call
* {@link SearchEngineLogoUtils#shouldShowSearchEngineLogo}.
* @param isSearchEngineGoogle True if the current search engine is Google.
* @param searchEngineUrl The url for the current search engine's logo, usually just a base url
* that we use to fetch the favicon.
*/
void updateSearchEngineStatusIcon(boolean shouldShowSearchEngineLogo,
boolean isSearchEngineGoogle, String searchEngineUrl);
/**
* Sets the (observable) supplier of the active profile. This supplier will notify observers of
* changes to the active profile, e.g. when selecting an incognito tab model.
......
......@@ -74,6 +74,9 @@ import org.chromium.chrome.browser.util.ChromeAccessibilityUtil;
import org.chromium.chrome.browser.util.KeyNavigationUtil;
import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.components.browser_ui.widget.CompositeTouchDelegate;
import org.chromium.components.search_engines.TemplateUrl;
import org.chromium.components.search_engines.TemplateUrlService;
import org.chromium.components.search_engines.TemplateUrlService.TemplateUrlServiceObserver;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.common.ResourceRequestBody;
import org.chromium.ui.KeyboardVisibilityDelegate;
......@@ -142,6 +145,7 @@ public class LocationBarLayout extends FrameLayout
private ObservableSupplier<Profile> mProfileSupplier;
private Callback<Profile> mProfileSupplierObserver;
private CallbackController mCallbackController = new CallbackController();
private TemplateUrlServiceObserver mTemplateUrlObserver;
/**
* Class to handle input from a hardware keyboard when the focus is on the URL bar. In
......@@ -259,6 +263,11 @@ public class LocationBarLayout extends FrameLayout
mProfileSupplier = null;
mProfileSupplierObserver = null;
}
if (mTemplateUrlObserver != null) {
TemplateUrlServiceFactory.get().removeObserver(mTemplateUrlObserver);
mTemplateUrlObserver = null;
}
}
@Override
......@@ -355,6 +364,7 @@ public class LocationBarLayout extends FrameLayout
*/
@Override
public void onNativeLibraryReady() {
TemplateUrlServiceFactory.get().runWhenLoaded(this::registerTemplateUrlObserver);
mNativeInitialized = true;
mAutocompleteCoordinator.onNativeInitialized();
......@@ -382,6 +392,37 @@ public class LocationBarLayout extends FrameLayout
setProfile(mProfileSupplier.get());
}
private void registerTemplateUrlObserver() {
final TemplateUrlService templateUrlService = TemplateUrlServiceFactory.get();
assert mTemplateUrlObserver == null;
mTemplateUrlObserver = new TemplateUrlServiceObserver() {
private TemplateUrl mSearchEngine =
templateUrlService.getDefaultSearchEngineTemplateUrl();
@Override
public void onTemplateURLServiceChanged() {
TemplateUrl searchEngine = templateUrlService.getDefaultSearchEngineTemplateUrl();
if ((mSearchEngine == null && searchEngine == null)
|| (mSearchEngine != null && mSearchEngine.equals(searchEngine))) {
return;
}
mSearchEngine = searchEngine;
updateSearchEngineStatusIcon(SearchEngineLogoUtils.shouldShowSearchEngineLogo(
mToolbarDataProvider.isIncognito()),
TemplateUrlServiceFactory.get().isDefaultSearchEngineGoogle(),
SearchEngineLogoUtils.getSearchLogoUrl());
}
};
templateUrlService.addObserver(mTemplateUrlObserver);
// Force an update once to populate initial data.
updateSearchEngineStatusIcon(SearchEngineLogoUtils.shouldShowSearchEngineLogo(
mToolbarDataProvider.isIncognito()),
TemplateUrlServiceFactory.get().isDefaultSearchEngineGoogle(),
SearchEngineLogoUtils.getSearchLogoUrl());
}
/**
* Evaluate state and update child components' animations.
*
......@@ -1075,8 +1116,7 @@ public class LocationBarLayout extends FrameLayout
mStatusCoordinator.setUnfocusedLocationBarWidth(unfocusedWidth);
}
@Override
public void updateSearchEngineStatusIcon(boolean shouldShowSearchEngineLogo,
protected void updateSearchEngineStatusIcon(boolean shouldShowSearchEngineLogo,
boolean isSearchEngineGoogle, String searchEngineUrl) {
mStatusCoordinator.updateSearchEngineStatusIcon(
shouldShowSearchEngineLogo, isSearchEngineGoogle, searchEngineUrl);
......
......@@ -58,7 +58,7 @@ public class LocationBarPhone extends LocationBarLayout {
}
@Override
public void updateSearchEngineStatusIcon(boolean shouldShowSearchEngineLogo,
protected void updateSearchEngineStatusIcon(boolean shouldShowSearchEngineLogo,
boolean isSearchEngineGoogle, String searchEngineUrl) {
super.updateSearchEngineStatusIcon(
shouldShowSearchEngineLogo, isSearchEngineGoogle, searchEngineUrl);
......
......@@ -55,7 +55,6 @@ import org.chromium.chrome.browser.ntp.FakeboxDelegate;
import org.chromium.chrome.browser.ntp.IncognitoNewTabPage;
import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.omnibox.LocationBar;
import org.chromium.chrome.browser.omnibox.SearchEngineLogoUtils;
import org.chromium.chrome.browser.omnibox.UrlFocusChangeListener;
import org.chromium.chrome.browser.previews.Previews;
import org.chromium.chrome.browser.previews.PreviewsAndroidBridge;
......@@ -972,21 +971,10 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
}
mSearchEngine = searchEngine;
mLocationBar.updateSearchEngineStatusIcon(
SearchEngineLogoUtils.shouldShowSearchEngineLogo(
mLocationBarModel.isIncognito()),
TemplateUrlServiceFactory.get().isDefaultSearchEngineGoogle(),
SearchEngineLogoUtils.getSearchLogoUrl());
mToolbar.onDefaultSearchEngineChanged();
}
};
templateUrlService.addObserver(mTemplateUrlObserver);
// Force an update once to populate initial data.
mLocationBar.updateSearchEngineStatusIcon(
SearchEngineLogoUtils.shouldShowSearchEngineLogo(mLocationBarModel.isIncognito()),
TemplateUrlServiceFactory.get().isDefaultSearchEngineGoogle(),
SearchEngineLogoUtils.getSearchLogoUrl());
}
private void handleTabRestoreCompleted() {
......
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