OLD | NEW |
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.suggestions; | 5 package org.chromium.chrome.browser.suggestions; |
6 | 6 |
7 import android.support.annotation.Nullable; | 7 import android.support.annotation.Nullable; |
8 | 8 |
| 9 import org.chromium.base.DiscardableReferencePool; |
9 import org.chromium.chrome.browser.NativePageHost; | 10 import org.chromium.chrome.browser.NativePageHost; |
10 import org.chromium.chrome.browser.favicon.FaviconHelper; | 11 import org.chromium.chrome.browser.favicon.FaviconHelper; |
11 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; | 12 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; |
12 import org.chromium.chrome.browser.favicon.FaviconHelper.IconAvailabilityCallbac
k; | 13 import org.chromium.chrome.browser.favicon.FaviconHelper.IconAvailabilityCallbac
k; |
13 import org.chromium.chrome.browser.favicon.LargeIconBridge; | 14 import org.chromium.chrome.browser.favicon.LargeIconBridge; |
14 import org.chromium.chrome.browser.favicon.LargeIconBridge.LargeIconCallback; | 15 import org.chromium.chrome.browser.favicon.LargeIconBridge.LargeIconCallback; |
15 import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource; | 16 import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource; |
16 import org.chromium.chrome.browser.profiles.Profile; | 17 import org.chromium.chrome.browser.profiles.Profile; |
17 | 18 |
18 import java.util.ArrayList; | 19 import java.util.ArrayList; |
19 import java.util.List; | 20 import java.util.List; |
20 | 21 |
21 /** | 22 /** |
22 * {@link SuggestionsUiDelegate} implementation. | 23 * {@link SuggestionsUiDelegate} implementation. |
23 */ | 24 */ |
24 public class SuggestionsUiDelegateImpl implements SuggestionsUiDelegate { | 25 public class SuggestionsUiDelegateImpl implements SuggestionsUiDelegate { |
25 private final List<DestructionObserver> mDestructionObservers = new ArrayLis
t<>(); | 26 private final List<DestructionObserver> mDestructionObservers = new ArrayLis
t<>(); |
26 private final SuggestionsSource mSuggestionsSource; | 27 private final SuggestionsSource mSuggestionsSource; |
27 private final SuggestionsRanker mSuggestionsRanker; | 28 private final SuggestionsRanker mSuggestionsRanker; |
28 private final SuggestionsEventReporter mSuggestionsEventReporter; | 29 private final SuggestionsEventReporter mSuggestionsEventReporter; |
29 private final SuggestionsNavigationDelegate mSuggestionsNavigationDelegate; | 30 private final SuggestionsNavigationDelegate mSuggestionsNavigationDelegate; |
30 | 31 |
31 private final Profile mProfile; | 32 private final Profile mProfile; |
32 | 33 |
33 private final NativePageHost mHost; | 34 private final NativePageHost mHost; |
34 | 35 |
| 36 private final DiscardableReferencePool mReferencePool; |
| 37 |
35 private FaviconHelper mFaviconHelper; | 38 private FaviconHelper mFaviconHelper; |
36 private LargeIconBridge mLargeIconBridge; | 39 private LargeIconBridge mLargeIconBridge; |
37 | 40 |
38 private boolean mIsDestroyed; | 41 private boolean mIsDestroyed; |
39 | 42 |
40 public SuggestionsUiDelegateImpl(SuggestionsSource suggestionsSource, | 43 public SuggestionsUiDelegateImpl(SuggestionsSource suggestionsSource, |
41 SuggestionsEventReporter eventReporter, | 44 SuggestionsEventReporter eventReporter, |
42 SuggestionsNavigationDelegate navigationDelegate, Profile profile, | 45 SuggestionsNavigationDelegate navigationDelegate, Profile profile, N
ativePageHost host, |
43 NativePageHost host) { | 46 DiscardableReferencePool referencePool) { |
44 mSuggestionsSource = suggestionsSource; | 47 mSuggestionsSource = suggestionsSource; |
45 mSuggestionsRanker = new SuggestionsRanker(); | 48 mSuggestionsRanker = new SuggestionsRanker(); |
46 mSuggestionsEventReporter = eventReporter; | 49 mSuggestionsEventReporter = eventReporter; |
47 mSuggestionsNavigationDelegate = navigationDelegate; | 50 mSuggestionsNavigationDelegate = navigationDelegate; |
48 | 51 |
49 mProfile = profile; | 52 mProfile = profile; |
50 mHost = host; | 53 mHost = host; |
| 54 mReferencePool = referencePool; |
51 } | 55 } |
52 | 56 |
53 @Override | 57 @Override |
54 public void getLocalFaviconImageForURL( | 58 public void getLocalFaviconImageForURL( |
55 String url, int size, FaviconImageCallback faviconCallback) { | 59 String url, int size, FaviconImageCallback faviconCallback) { |
56 if (mIsDestroyed) return; | 60 if (mIsDestroyed) return; |
57 getFaviconHelper().getLocalFaviconImageForURL(mProfile, url, size, favic
onCallback); | 61 getFaviconHelper().getLocalFaviconImageForURL(mProfile, url, size, favic
onCallback); |
58 } | 62 } |
59 | 63 |
60 @Override | 64 @Override |
(...skipping 29 matching lines...) Expand all Loading... |
90 return mSuggestionsEventReporter; | 94 return mSuggestionsEventReporter; |
91 } | 95 } |
92 | 96 |
93 @Nullable | 97 @Nullable |
94 @Override | 98 @Override |
95 public SuggestionsNavigationDelegate getNavigationDelegate() { | 99 public SuggestionsNavigationDelegate getNavigationDelegate() { |
96 return mSuggestionsNavigationDelegate; | 100 return mSuggestionsNavigationDelegate; |
97 } | 101 } |
98 | 102 |
99 @Override | 103 @Override |
| 104 public DiscardableReferencePool getReferencePool() { |
| 105 return mReferencePool; |
| 106 } |
| 107 |
| 108 @Override |
100 public void addDestructionObserver(DestructionObserver destructionObserver)
{ | 109 public void addDestructionObserver(DestructionObserver destructionObserver)
{ |
101 mDestructionObservers.add(destructionObserver); | 110 mDestructionObservers.add(destructionObserver); |
102 } | 111 } |
103 | 112 |
104 @Override | 113 @Override |
105 public boolean isVisible() { | 114 public boolean isVisible() { |
106 return mHost.isVisible(); | 115 return mHost.isVisible(); |
107 } | 116 } |
108 | 117 |
109 /** Invalidates the delegate and calls the registered destruction observers.
*/ | 118 /** Invalidates the delegate and calls the registered destruction observers.
*/ |
(...skipping 26 matching lines...) Expand all Loading... |
136 /** | 145 /** |
137 * Utility method to lazily create the {@link LargeIconBridge}, and avoid un
necessary native | 146 * Utility method to lazily create the {@link LargeIconBridge}, and avoid un
necessary native |
138 * calls in tests. | 147 * calls in tests. |
139 */ | 148 */ |
140 private LargeIconBridge getLargeIconBridge() { | 149 private LargeIconBridge getLargeIconBridge() { |
141 assert !mIsDestroyed; | 150 assert !mIsDestroyed; |
142 if (mLargeIconBridge == null) mLargeIconBridge = new LargeIconBridge(mPr
ofile); | 151 if (mLargeIconBridge == null) mLargeIconBridge = new LargeIconBridge(mPr
ofile); |
143 return mLargeIconBridge; | 152 return mLargeIconBridge; |
144 } | 153 } |
145 } | 154 } |
OLD | NEW |