| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.ntp; |
| 6 |
| 7 import org.chromium.base.metrics.RecordHistogram; |
| 8 import org.chromium.chrome.browser.ntp.LogoBridge.Logo; |
| 9 import org.chromium.chrome.browser.ntp.LogoBridge.LogoObserver; |
| 10 import org.chromium.chrome.browser.tab.Tab; |
| 11 import org.chromium.content_public.browser.LoadUrlParams; |
| 12 import org.chromium.ui.base.PageTransition; |
| 13 |
| 14 import jp.tomorrowkey.android.gifplayer.BaseGifImage; |
| 15 |
| 16 /** |
| 17 * An implementation of {@link LogoView.Delegate}. |
| 18 */ |
| 19 public class LogoDelegateImpl implements LogoView.Delegate { |
| 20 // UMA enum constants. CTA means the "click-to-action" icon. |
| 21 private static final String LOGO_SHOWN_UMA_NAME = "NewTabPage.LogoShown"; |
| 22 private static final int STATIC_LOGO_SHOWN = 0; |
| 23 private static final int CTA_IMAGE_SHOWN = 1; |
| 24 |
| 25 private static final String LOGO_CLICK_UMA_NAME = "NewTabPage.LogoClick"; |
| 26 private static final int STATIC_LOGO_CLICKED = 0; |
| 27 private static final int CTA_IMAGE_CLICKED = 1; |
| 28 private static final int ANIMATED_LOGO_CLICKED = 2; |
| 29 |
| 30 private final Tab mTab; |
| 31 private LogoView mLogoView; |
| 32 |
| 33 private LogoBridge mLogoBridge; |
| 34 private String mOnLogoClickUrl; |
| 35 private String mAnimatedLogoUrl; |
| 36 |
| 37 private boolean mIsDestroyed; |
| 38 |
| 39 /** |
| 40 * Construct a new {@link LogoDelegateImpl}. |
| 41 * @param tab The tab showing the logo view. |
| 42 * @param logoView The view that shows the search provider logo. |
| 43 */ |
| 44 public LogoDelegateImpl(Tab tab, LogoView logoView) { |
| 45 mTab = tab; |
| 46 mLogoView = logoView; |
| 47 mLogoBridge = new LogoBridge(tab.getProfile()); |
| 48 } |
| 49 |
| 50 @Override |
| 51 public void destroy() { |
| 52 mIsDestroyed = true; |
| 53 } |
| 54 |
| 55 @Override |
| 56 public void onLogoClicked(boolean isAnimatedLogoShowing) { |
| 57 if (mIsDestroyed) return; |
| 58 |
| 59 if (!isAnimatedLogoShowing && mAnimatedLogoUrl != null) { |
| 60 RecordHistogram.recordSparseSlowlyHistogram(LOGO_CLICK_UMA_NAME, CTA
_IMAGE_CLICKED); |
| 61 mLogoView.showLoadingView(); |
| 62 mLogoBridge.getAnimatedLogo(new LogoBridge.AnimatedLogoCallback() { |
| 63 @Override |
| 64 public void onAnimatedLogoAvailable(BaseGifImage animatedLogoIma
ge) { |
| 65 if (mIsDestroyed) return; |
| 66 mLogoView.playAnimatedLogo(animatedLogoImage); |
| 67 } |
| 68 }, mAnimatedLogoUrl); |
| 69 } else if (mOnLogoClickUrl != null) { |
| 70 RecordHistogram.recordSparseSlowlyHistogram(LOGO_CLICK_UMA_NAME, |
| 71 isAnimatedLogoShowing ? ANIMATED_LOGO_CLICKED : STATIC_LOGO_
CLICKED); |
| 72 mTab.loadUrl(new LoadUrlParams(mOnLogoClickUrl, PageTransition.LINK)
); |
| 73 } |
| 74 } |
| 75 |
| 76 @Override |
| 77 public void getSearchProviderLogo(final LogoObserver logoObserver) { |
| 78 if (mIsDestroyed) return; |
| 79 |
| 80 LogoObserver wrapperCallback = new LogoObserver() { |
| 81 @Override |
| 82 public void onLogoAvailable(Logo logo, boolean fromCache) { |
| 83 if (mIsDestroyed) return; |
| 84 mOnLogoClickUrl = logo != null ? logo.onClickUrl : null; |
| 85 mAnimatedLogoUrl = logo != null ? logo.animatedLogoUrl : null; |
| 86 if (logo != null) { |
| 87 RecordHistogram.recordSparseSlowlyHistogram(LOGO_SHOWN_UMA_N
AME, |
| 88 logo.animatedLogoUrl == null ? STATIC_LOGO_SHOWN : C
TA_IMAGE_SHOWN); |
| 89 } |
| 90 logoObserver.onLogoAvailable(logo, fromCache); |
| 91 } |
| 92 }; |
| 93 |
| 94 mLogoBridge.getCurrentLogo(wrapperCallback); |
| 95 } |
| 96 } |
| OLD | NEW |