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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/suggestions/MostVisitedSitesBridge.java

Issue 2897293002: Adding CrHome-specific implementation for home page tile. (Closed)
Patch Set: Created 3 years, 7 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 static org.chromium.base.ContextUtils.getApplicationContext;
dgn 2017/05/25 10:33:33 just use a regular import here, and call ContextUt
fhorschig 2017/05/30 10:25:21 Done.
8
7 import org.chromium.base.annotations.JNIAdditionalImport; 9 import org.chromium.base.annotations.JNIAdditionalImport;
10 import org.chromium.chrome.browser.ChromeFeatureList;
11 import org.chromium.chrome.browser.UrlConstants;
12 import org.chromium.chrome.browser.partnercustomizations.HomepageManager;
8 import org.chromium.chrome.browser.profiles.Profile; 13 import org.chromium.chrome.browser.profiles.Profile;
9 14
10 /** 15 /**
11 * Methods to bridge into native history to provide most recent urls, titles and thumbnails. 16 * Methods to bridge into native history to provide most recent urls, titles and thumbnails.
12 */ 17 */
13 @JNIAdditionalImport(MostVisitedSites.class) // Needed for the Observer usage in the native calls. 18 @JNIAdditionalImport(MostVisitedSites.class) // Needed for the Observer usage in the native calls.
14 public class MostVisitedSitesBridge implements MostVisitedSites { 19 public class MostVisitedSitesBridge
20 implements MostVisitedSites, HomepageManager.HomepageStateListener {
15 private long mNativeMostVisitedSitesBridge; 21 private long mNativeMostVisitedSitesBridge;
16 22
17 /** 23 /**
18 * MostVisitedSites constructor requires a valid user profile object. 24 * MostVisitedSites constructor requires a valid user profile object.
19 * 25 *
20 * @param profile The profile for which to fetch most visited sites. 26 * @param profile The profile for which to fetch most visited sites.
21 */ 27 */
22 public MostVisitedSitesBridge(Profile profile) { 28 public MostVisitedSitesBridge(Profile profile) {
23 mNativeMostVisitedSitesBridge = nativeInit(profile); 29 mNativeMostVisitedSitesBridge = nativeInit(profile);
30 // The first tile replaces the home page button (only) in Chrome Home.
31 if (ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_HOME)) {
32 initializeClient();
33 HomepageManager.getInstance(getApplicationContext()).addListener(thi s);
dgn 2017/05/25 10:33:33 when should the listener be removed? destroy() ?
fhorschig 2017/05/30 10:25:21 Yes. Done.
34 }
24 } 35 }
25 36
26 /** 37 /**
27 * Cleans up the C++ side of this class. This instance must not be used afte r calling destroy(). 38 * Cleans up the C++ side of this class. This instance must not be used afte r calling destroy().
28 */ 39 */
29 @Override 40 @Override
30 public void destroy() { 41 public void destroy() {
31 assert mNativeMostVisitedSitesBridge != 0; 42 assert mNativeMostVisitedSitesBridge != 0;
32 nativeDestroy(mNativeMostVisitedSitesBridge); 43 nativeDestroy(mNativeMostVisitedSitesBridge);
33 mNativeMostVisitedSitesBridge = 0; 44 mNativeMostVisitedSitesBridge = 0;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 public void recordPageImpression(int[] tileTypes, int[] sources, String[] ti leUrls) { 80 public void recordPageImpression(int[] tileTypes, int[] sources, String[] ti leUrls) {
70 nativeRecordPageImpression(mNativeMostVisitedSitesBridge, tileTypes, sou rces, tileUrls); 81 nativeRecordPageImpression(mNativeMostVisitedSitesBridge, tileTypes, sou rces, tileUrls);
71 } 82 }
72 83
73 @Override 84 @Override
74 public void recordOpenedMostVisitedItem( 85 public void recordOpenedMostVisitedItem(
75 int index, @TileVisualType int type, @TileSource int source) { 86 int index, @TileVisualType int type, @TileSource int source) {
76 nativeRecordOpenedMostVisitedItem(mNativeMostVisitedSitesBridge, index, type, source); 87 nativeRecordOpenedMostVisitedItem(mNativeMostVisitedSitesBridge, index, type, source);
77 } 88 }
78 89
90 @Override
91 public void onHomepageStateUpdated() {
92 if (mNativeMostVisitedSitesBridge == 0) {
dgn 2017/05/25 10:33:33 can it happen in the normal functioning of the cla
fhorschig 2017/05/30 10:25:21 Changed to assert. This can not happen anymore (be
93 return; // Calling the blacklist only works if the native side of th e bridge is alive.
94 }
95 // Ensure the home page is set as first tile if (re-)enabled - even if b lacklisted before.
dgn 2017/05/25 10:33:33 how does that set the tile as first? to me it only
fhorschig 2017/05/30 10:25:21 Absolutely. Gone.
96 if (HomepageManager.isHomepageEnabled(getApplicationContext())) {
97 removeBlacklistedUrl(HomepageManager.getHomepageUri(getApplicationCo ntext()));
98 }
99 }
100
101 private void initializeClient() {
102 nativeSetClient(mNativeMostVisitedSitesBridge, new Client() {
103 @Override
104 public boolean isHomePageEnabled() {
105 return HomepageManager.isHomepageEnabled(getApplicationContext() );
106 }
107
108 @Override
109 public boolean isNewTabPageUsedAsHomePage() {
110 return HomepageManager.getHomepageUri(getApplicationContext())
dgn 2017/05/25 10:33:33 compare strings with TextUtils.equals(s1, s2), the
fhorschig 2017/05/30 10:25:21 Thanks, done and used. (This code used to work bec
111 .equals(UrlConstants.NTP_URL);
112 }
113
114 @Override
115 public String getHomePageUrl() {
dgn 2017/05/25 10:33:33 this can return null, mark @Nullable? also, does t
fhorschig 2017/05/30 10:25:21 @Nullable added. The backend handles null values n
116 return HomepageManager.getHomepageUri(getApplicationContext());
117 }
118 });
119 }
120
79 private native long nativeInit(Profile profile); 121 private native long nativeInit(Profile profile);
80 private native void nativeDestroy(long nativeMostVisitedSitesBridge); 122 private native void nativeDestroy(long nativeMostVisitedSitesBridge);
81 private native void nativeSetObserver( 123 private native void nativeSetObserver(
82 long nativeMostVisitedSitesBridge, MostVisitedSites.Observer observe r, int numSites); 124 long nativeMostVisitedSitesBridge, MostVisitedSites.Observer observe r, int numSites);
125 private native void nativeSetClient(
126 long nativeMostVisitedSitesBridge, MostVisitedSites.Client client);
83 private native void nativeAddOrRemoveBlacklistedUrl( 127 private native void nativeAddOrRemoveBlacklistedUrl(
84 long nativeMostVisitedSitesBridge, String url, boolean addUrl); 128 long nativeMostVisitedSitesBridge, String url, boolean addUrl);
85 private native void nativeRecordPageImpression( 129 private native void nativeRecordPageImpression(
86 long nativeMostVisitedSitesBridge, int[] tileTypes, int[] sources, S tring[] tileUrls); 130 long nativeMostVisitedSitesBridge, int[] tileTypes, int[] sources, S tring[] tileUrls);
87 private native void nativeRecordOpenedMostVisitedItem( 131 private native void nativeRecordOpenedMostVisitedItem(
88 long nativeMostVisitedSitesBridge, int index, int tileType, int sour ce); 132 long nativeMostVisitedSitesBridge, int index, int tileType, int sour ce);
89 } 133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698