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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/profiles/MostVisitedSites.java

Issue 1373983003: Add UMA stats for which icon types are shown and clicked on the NTP. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed test Created 5 years, 2 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.profiles; 5 package org.chromium.chrome.browser.profiles;
6 6
7 import android.graphics.Bitmap; 7 import android.graphics.Bitmap;
8 8
9 import org.chromium.base.annotations.CalledByNative; 9 import org.chromium.base.annotations.CalledByNative;
10 10
11 /** 11 /**
12 * Methods to bridge into native history to provide most recent urls, titles and thumbnails. 12 * Methods to bridge into native history to provide most recent urls, titles and thumbnails.
13 */ 13 */
14 public class MostVisitedSites { 14 public class MostVisitedSites {
15 15
16 private long mNativeMostVisitedSites; 16 private long mNativeMostVisitedSites;
17 17
18 /** 18 /**
19 * Interface for receiving the list of most visited urls. 19 * Interface for receiving the list of most visited urls.
20 */ 20 */
21 public interface MostVisitedURLsObserver { 21 public interface MostVisitedURLsObserver {
22 /** 22 /**
23 * This is called when the list of most visited URLs is initially availa ble or updated. 23 * This is called when the list of most visited URLs is initially availa ble or updated.
24 * Parameters guaranteed to be non-null. 24 * Parameters guaranteed to be non-null.
25 * 25 *
26 * @param titles Array of most visited url page titles. 26 * @param titles Array of most visited url page titles.
27 * @param urls Array of most visited URLs, including popular URLs if 27 * @param urls Array of most visited URLs, including popular URLs if
28 * available and necessary (i.e. there aren't enough most 28 * available and necessary (i.e. there aren't enough most
29 * visited URLs). 29 * visited URLs).
30 */ 30 */
31 @CalledByNative("MostVisitedURLsObserver") 31 @CalledByNative("MostVisitedURLsObserver")
32 public void onMostVisitedURLsAvailable(String[] titles, String[] urls); 32 public void onMostVisitedURLsAvailable(String[] titles, String[] urls);
33 33
34 /** 34 /**
35 * This is called when the list of popular URLs is initially available o r updated. 35 * This is called when the list of popular URLs is initially available o r updated.
36 * Parameters guaranteed to be non-null. 36 * Parameters guaranteed to be non-null.
37 * 37 *
38 * @param urls Array of popular URLs. 38 * @param urls Array of popular URLs.
39 * @param faviconUrls Array of URLs for the corresponding favicons (if k nown). 39 * @param faviconUrls Array of URLs for the corresponding favicons (if k nown).
40 */ 40 */
41 @CalledByNative("MostVisitedURLsObserver") 41 @CalledByNative("MostVisitedURLsObserver")
42 public void onPopularURLsAvailable(String[] urls, String[] faviconUrls); 42 public void onPopularURLsAvailable(String[] urls, String[] faviconUrls);
43 } 43 }
44 44
45 /** 45 /**
46 * Interface for receiving a thumbnail for a most visited site. 46 * Interface for receiving a thumbnail for a most visited site.
47 */ 47 */
48 public interface ThumbnailCallback { 48 public interface ThumbnailCallback {
49 /** 49 /**
50 * Callback method for fetching thumbnail of a most visited URL. 50 * Callback method for fetching thumbnail of a most visited URL.
51 * Parameter may be null. 51 * Parameter may be null.
52 * 52 *
53 * @param thumbnail The bitmap thumbnail for the requested URL. 53 * @param thumbnail The bitmap thumbnail for the requested URL.
54 * @param isLocalThumbnail Whether the thumbnail was locally captured, a s opposed to
55 * server-provided.
54 */ 56 */
55 @CalledByNative("ThumbnailCallback") 57 @CalledByNative("ThumbnailCallback")
56 public void onMostVisitedURLsThumbnailAvailable(Bitmap thumbnail); 58 public void onMostVisitedURLsThumbnailAvailable(Bitmap thumbnail, boolea n isLocalThumbnail);
57 } 59 }
58 60
59 /** 61 /**
60 * MostVisitedSites constructor requires a valid user profile object. 62 * MostVisitedSites constructor requires a valid user profile object.
61 * 63 *
62 * @param profile The profile for which to fetch most visited sites. 64 * @param profile The profile for which to fetch most visited sites.
63 */ 65 */
64 public MostVisitedSites(Profile profile) { 66 public MostVisitedSites(Profile profile) {
65 mNativeMostVisitedSites = nativeInit(profile); 67 mNativeMostVisitedSites = nativeInit(profile);
66 } 68 }
67 69
68 /** 70 /**
69 * Cleans up the C++ side of this class. This instance must not be used afte r calling destroy(). 71 * Cleans up the C++ side of this class. This instance must not be used afte r calling destroy().
70 */ 72 */
71 public void destroy() { 73 public void destroy() {
72 assert mNativeMostVisitedSites != 0; 74 assert mNativeMostVisitedSites != 0;
73 nativeDestroy(mNativeMostVisitedSites); 75 nativeDestroy(mNativeMostVisitedSites);
74 mNativeMostVisitedSites = 0; 76 mNativeMostVisitedSites = 0;
75 } 77 }
76 78
77 /** 79 /**
78 * Sets the MostVisitedURLsObserver to receive the list of most visited site s now or soon, and 80 * Sets the MostVisitedURLsObserver to receive the list of most visited site s now or soon, and
79 * after any changes to the list. Note: the observer may be notified synchro nously or 81 * after any changes to the list. Note: the observer may be notified synchro nously or
80 * asynchronously. 82 * asynchronously.
81 * @param observer The MostVisitedURLsObserver to be called once when the mo st visited sites 83 * @param observer The MostVisitedURLsObserver to be called once when the mo st visited sites
82 * are initially available and again whenever the list of most vi sited sites changes. 84 * are initially available and again whenever the list of mo st visited sites
85 * changes.
83 * @param numSites The maximum number of most visited sites to return. 86 * @param numSites The maximum number of most visited sites to return.
84 */ 87 */
85 public void setMostVisitedURLsObserver(final MostVisitedURLsObserver observe r, int numSites) { 88 public void setMostVisitedURLsObserver(final MostVisitedURLsObserver observe r, int numSites) {
86 MostVisitedURLsObserver wrappedObserver = new MostVisitedURLsObserver() { 89 MostVisitedURLsObserver wrappedObserver = new MostVisitedURLsObserver() {
87 @Override 90 @Override
88 public void onMostVisitedURLsAvailable(String[] titles, String[] url s) { 91 public void onMostVisitedURLsAvailable(String[] titles, String[] url s) {
89 // Don't notify observer if we've already been destroyed. 92 // Don't notify observer if we've already been destroyed.
90 if (mNativeMostVisitedSites != 0) { 93 if (mNativeMostVisitedSites != 0) {
91 observer.onMostVisitedURLsAvailable(titles, urls); 94 observer.onMostVisitedURLsAvailable(titles, urls);
92 } 95 }
(...skipping 11 matching lines...) Expand all
104 107
105 /** 108 /**
106 * Fetches thumbnail bitmap for a url returned by getMostVisitedURLs. 109 * Fetches thumbnail bitmap for a url returned by getMostVisitedURLs.
107 * 110 *
108 * @param url String representation of url. 111 * @param url String representation of url.
109 * @param callback Instance of a callback object. 112 * @param callback Instance of a callback object.
110 */ 113 */
111 public void getURLThumbnail(String url, final ThumbnailCallback callback) { 114 public void getURLThumbnail(String url, final ThumbnailCallback callback) {
112 ThumbnailCallback wrappedCallback = new ThumbnailCallback() { 115 ThumbnailCallback wrappedCallback = new ThumbnailCallback() {
113 @Override 116 @Override
114 public void onMostVisitedURLsThumbnailAvailable(Bitmap thumbnail) { 117 public void onMostVisitedURLsThumbnailAvailable(Bitmap thumbnail,
118 boolean isLocalThumbnail) {
115 // Don't notify callback if we've already been destroyed. 119 // Don't notify callback if we've already been destroyed.
116 if (mNativeMostVisitedSites != 0) { 120 if (mNativeMostVisitedSites != 0) {
117 callback.onMostVisitedURLsThumbnailAvailable(thumbnail); 121 callback.onMostVisitedURLsThumbnailAvailable(thumbnail, isLo calThumbnail);
118 } 122 }
119 } 123 }
120 }; 124 };
121 nativeGetURLThumbnail(mNativeMostVisitedSites, url, wrappedCallback); 125 nativeGetURLThumbnail(mNativeMostVisitedSites, url, wrappedCallback);
122 } 126 }
123 127
124 /** 128 /**
125 * Blacklist a URL from the most visited URLs list. 129 * Blacklists a URL from the most visited URLs list.
126 * @param url The URL to be blacklisted. 130 * @param url The URL to be blacklisted.
127 */ 131 */
128 public void blacklistUrl(String url) { 132 public void blacklistUrl(String url) {
129 nativeBlacklistUrl(mNativeMostVisitedSites, url); 133 nativeBlacklistUrl(mNativeMostVisitedSites, url);
130 } 134 }
131 135
132 /** 136 /**
133 * Called when the loading of the Most Visited page is complete. 137 * Records metrics about which types of tiles are displayed.
138 * @param tileTypes An array of values from MostVisitedTileType indicating t he type of each
139 * tile that's currently showing.
140 * @paral isIconMode Whether the icon-based version of the NTP is showing (a s opposed to the
141 * thumbnail-based version).
134 */ 142 */
135 public void onLoadingComplete() { 143 public void recordTileTypeMetrics(int[] tileTypes, boolean isIconMode) {
136 nativeOnLoadingComplete(mNativeMostVisitedSites); 144 nativeRecordTileTypeMetrics(mNativeMostVisitedSites, tileTypes, isIconMo de);
137 } 145 }
138 146
139 /** 147 /**
140 * Record the opening of a Most Visited Item. 148 * Records the opening of a Most Visited Item.
141 * @param index The index of the item that was opened. 149 * @param index The index of the item that was opened.
150 * @param tileType The visual type of the item. Valid values are listed in M ostVisitedTileType.
142 */ 151 */
143 public void recordOpenedMostVisitedItem(int index) { 152 public void recordOpenedMostVisitedItem(int index, int tileType) {
144 nativeRecordOpenedMostVisitedItem(mNativeMostVisitedSites, index); 153 nativeRecordOpenedMostVisitedItem(mNativeMostVisitedSites, index, tileTy pe);
145 } 154 }
146 155
147 private native long nativeInit(Profile profile); 156 private native long nativeInit(Profile profile);
148 private native void nativeDestroy(long nativeMostVisitedSites); 157 private native void nativeDestroy(long nativeMostVisitedSites);
149 private native void nativeOnLoadingComplete(long nativeMostVisitedSites);
150 private native void nativeSetMostVisitedURLsObserver(long nativeMostVisitedS ites, 158 private native void nativeSetMostVisitedURLsObserver(long nativeMostVisitedS ites,
151 MostVisitedURLsObserver observer, int numSites); 159 MostVisitedURLsObserver observer, int numSites);
152 private native void nativeGetURLThumbnail(long nativeMostVisitedSites, Strin g url, 160 private native void nativeGetURLThumbnail(long nativeMostVisitedSites, Strin g url,
153 ThumbnailCallback callback); 161 ThumbnailCallback callback);
154 private native void nativeBlacklistUrl(long nativeMostVisitedSites, String u rl); 162 private native void nativeBlacklistUrl(long nativeMostVisitedSites, String u rl);
155 private native void nativeRecordOpenedMostVisitedItem(long nativeMostVisited Sites, int index); 163 private native void nativeRecordTileTypeMetrics(long nativeMostVisitedSites, int[] tileTypes,
164 boolean isIconMode);
165 private native void nativeRecordOpenedMostVisitedItem(long nativeMostVisited Sites, int index,
166 int tileType);
156 167
157 } 168 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698