Bug 925517 - Remove filter on recorded search engine identifiers for Fennec. r=mcomella

This commit is contained in:
Richard Newman 2013-10-18 13:13:37 -07:00
Родитель af2e02d2a2
Коммит 25f479a6ac
5 изменённых файлов: 119 добавлений и 148 удалений

Просмотреть файл

@ -19,6 +19,7 @@ import org.mozilla.gecko.health.BrowserHealthReporter;
import org.mozilla.gecko.home.BrowserSearch;
import org.mozilla.gecko.home.HomePager;
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.home.SearchEngine;
import org.mozilla.gecko.menu.GeckoMenu;
import org.mozilla.gecko.prompts.Prompt;
import org.mozilla.gecko.util.Clipboard;
@ -1485,15 +1486,18 @@ abstract public class BrowserApp extends GeckoApp
/**
* Record in Health Report that a search has occurred.
*
* @param identifier
* a search identifier, such as "partnername". Can be null.
* @param engine
* a search engine instance. Can be null.
* @param where
* where the search was initialized; one of the values in
* {@link BrowserHealthRecorder#SEARCH_LOCATIONS}.
*/
private static void recordSearch(String identifier, String where) {
Log.i(LOGTAG, "Recording search: " + identifier + ", " + where);
private static void recordSearch(SearchEngine engine, String where) {
Log.i(LOGTAG, "Recording search: " +
((engine == null) ? "null" : engine.name) +
", " + where);
try {
String identifier = (engine == null) ? "other" : engine.getEngineIdentifier();
JSONObject message = new JSONObject();
message.put("type", BrowserHealthRecorder.EVENT_SEARCH);
message.put("location", where);
@ -2308,9 +2312,9 @@ abstract public class BrowserApp extends GeckoApp
// BrowserSearch.OnSearchListener
@Override
public void onSearch(String engineId, String text) {
recordSearch(engineId, "barsuggest");
openUrl(text, engineId);
public void onSearch(SearchEngine engine, String text) {
recordSearch(engine, "barsuggest");
openUrl(text, engine.name);
}
// BrowserSearch.OnEditSuggestionListener

Просмотреть файл

@ -741,7 +741,7 @@ public class BrowserHealthRecorder implements GeckoEventListener {
*/
public static final String MEASUREMENT_NAME_SEARCH_COUNTS = "org.mozilla.searches.counts";
public static final int MEASUREMENT_VERSION_SEARCH_COUNTS = 4;
public static final int MEASUREMENT_VERSION_SEARCH_COUNTS = 5;
public static final String[] SEARCH_LOCATIONS = {
"barkeyword",
@ -749,84 +749,6 @@ public class BrowserHealthRecorder implements GeckoEventListener {
"bartext",
};
// See services/healthreport/providers.jsm. Sorry for the duplication.
// THIS LIST MUST BE SORTED per java.lang.Comparable<String>.
private static final String[] SEARCH_PROVIDERS = {
"amazon-co-uk",
"amazon-de",
"amazon-en-GB",
"amazon-france",
"amazon-it",
"amazon-jp",
"amazondotcn",
"amazondotcom",
"amazondotcom-de",
"aol-en-GB",
"aol-web-search",
"bing",
"eBay",
"eBay-de",
"eBay-en-GB",
"eBay-es",
"eBay-fi",
"eBay-france",
"eBay-hu",
"eBay-in",
"eBay-it",
"google",
"google-jp",
"google-ku",
"google-maps-zh-TW",
"mailru",
"mercadolibre-ar",
"mercadolibre-cl",
"mercadolibre-mx",
"seznam-cz",
"twitter",
"twitter-de",
"twitter-ja",
"wikipedia", // Manually added.
"yahoo",
"yahoo-NO",
"yahoo-answer-zh-TW",
"yahoo-ar",
"yahoo-bid-zh-TW",
"yahoo-br",
"yahoo-ch",
"yahoo-cl",
"yahoo-de",
"yahoo-en-GB",
"yahoo-es",
"yahoo-fi",
"yahoo-france",
"yahoo-fy-NL",
"yahoo-id",
"yahoo-in",
"yahoo-it",
"yahoo-jp",
"yahoo-jp-auctions",
"yahoo-mx",
"yahoo-sv-SE",
"yahoo-zh-TW",
"yandex",
"yandex-ru",
"yandex-slovari",
"yandex-tr",
"yandex.by",
"yandex.ru-be",
};
private void initializeSearchProvider() {
this.storage.ensureMeasurementInitialized(
MEASUREMENT_NAME_SEARCH_COUNTS,
@ -854,30 +776,13 @@ public class BrowserHealthRecorder implements GeckoEventListener {
this.dispatcher.registerEventListener(EVENT_SEARCH, this);
}
/**
* Return the field key for the search provider. This turns null and
* non-partner providers into "other".
*
* @param engine an engine identifier, such as "yandex"
* @return the key to use, such as "other" or "yandex".
*/
protected String getEngineKey(final String engine) {
if (engine == null) {
return "other";
}
// This is inefficient. Optimize if necessary.
boolean found = (0 <= java.util.Arrays.binarySearch(SEARCH_PROVIDERS, engine));
return found ? engine : "other";
}
/**
* Record a search.
*
* @param engine the string identifier for the engine, or null if it's not a partner.
* @param engineID the string identifier for the engine. Can be <code>null</code>.
* @param location one of a fixed set of locations: see {@link #SEARCH_LOCATIONS}.
*/
public void recordSearch(final String engine, final String location) {
public void recordSearch(final String engineID, final String location) {
if (this.state != State.INITIALIZED) {
Log.d(LOG_TAG, "Not initialized: not recording search. (" + this.state + ")");
return;
@ -889,7 +794,7 @@ public class BrowserHealthRecorder implements GeckoEventListener {
final int day = storage.getDay();
final int env = this.env;
final String key = getEngineKey(engine);
final String key = (engineID == null) ? "other" : engineID;
final BrowserHealthRecorder self = this;
ThreadUtils.postToBackgroundThread(new Runnable() {

Просмотреть файл

@ -13,8 +13,8 @@ import org.mozilla.gecko.R;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.db.BrowserDB.URLColumns;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.home.SearchEngine;
import org.mozilla.gecko.home.SearchLoader.SearchCursorLoader;
import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.util.StringUtils;
@ -132,7 +132,7 @@ public class BrowserSearch extends HomeFragment
private View mSuggestionsOptInPrompt;
public interface OnSearchListener {
public void onSearch(String engineId, String text);
public void onSearch(SearchEngine engine, String text);
}
public interface OnEditSuggestionListener {
@ -393,7 +393,7 @@ public class BrowserSearch extends HomeFragment
}
private void setSuggestions(ArrayList<String> suggestions) {
mSearchEngines.get(0).suggestions = suggestions;
mSearchEngines.get(0).setSuggestions(suggestions);
mAdapter.notifyDataSetChanged();
}
@ -417,14 +417,11 @@ public class BrowserSearch extends HomeFragment
ArrayList<SearchEngine> searchEngines = new ArrayList<SearchEngine>();
for (int i = 0; i < engines.length(); i++) {
final JSONObject engineJSON = engines.getJSONObject(i);
final String name = engineJSON.getString("name");
final String identifier = engineJSON.getString("identifier");
final String iconURI = engineJSON.getString("iconURI");
final Bitmap icon = BitmapUtils.getBitmapFromDataURI(iconURI);
final SearchEngine engine = new SearchEngine(engineJSON);
if (name.equals(suggestEngine) && suggestTemplate != null) {
// Suggest engine should be at the front of the list
searchEngines.add(0, new SearchEngine(name, identifier, icon));
if (engine.name.equals(suggestEngine) && suggestTemplate != null) {
// Suggest engine should be at the front of the list.
searchEngines.add(0, engine);
// The only time Tabs.getInstance().getSelectedTab() should
// be null is when we're restoring after a crash. We should
@ -441,7 +438,7 @@ public class BrowserSearch extends HomeFragment
SUGGESTION_TIMEOUT, SUGGESTION_MAX);
}
} else {
searchEngines.add(new SearchEngine(name, identifier, icon));
searchEngines.add(engine);
}
}
@ -713,7 +710,7 @@ public class BrowserSearch extends HomeFragment
// row contains multiple items, clicking the row will do nothing.
final int index = getEngineIndex(position);
if (index != -1) {
return mSearchEngines.get(index).suggestions.isEmpty();
return !mSearchEngines.get(index).hasSuggestions();
}
return true;
@ -744,7 +741,7 @@ public class BrowserSearch extends HomeFragment
row.setSearchTerm(mSearchTerm);
final SearchEngine engine = mSearchEngines.get(getEngineIndex(position));
final boolean animate = (mAnimateSuggestions && engine.suggestions.size() > 0);
final boolean animate = (mAnimateSuggestions && engine.hasSuggestions());
row.updateFromSearchEngine(engine, animate);
if (animate) {
// Only animate suggestions the first time they are shown

Просмотреть файл

@ -5,25 +5,89 @@
package org.mozilla.gecko.home;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.json.JSONException;
import org.json.JSONObject;
import android.graphics.Bitmap;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
class SearchEngine {
public String name;
public String identifier;
public Bitmap icon;
public ArrayList<String> suggestions;
public class SearchEngine {
public static final String LOG_TAG = "GeckoSearchEngine";
public SearchEngine(String name, String identifier) {
this(name, identifier, null);
public final String name; // Never null.
public final String identifier; // Can be null.
private final Bitmap icon;
private volatile List<String> suggestions = new ArrayList<String>(); // Never null.
public SearchEngine(JSONObject engineJSON) throws JSONException {
if (engineJSON == null) {
throw new IllegalArgumentException("Can't instantiate SearchEngine from null JSON.");
}
this.name = getString(engineJSON, "name");
if (this.name == null) {
throw new IllegalArgumentException("Cannot have an unnamed search engine.");
}
this.identifier = getString(engineJSON, "identifier");
final String iconURI = getString(engineJSON, "iconURI");
if (iconURI == null) {
Log.w(LOG_TAG, "iconURI is null for search engine " + this.name);
this.icon = null;
return;
}
this.icon = BitmapUtils.getBitmapFromDataURI(iconURI);
}
public SearchEngine(String name, String identifier, Bitmap icon) {
this.name = name;
this.identifier = identifier;
this.icon = icon;
this.suggestions = new ArrayList<String>();
private static String getString(JSONObject data, String key) throws JSONException {
if (data.isNull(key)) {
return null;
}
return data.getString(key);
}
/**
* @return a non-null string suitable for use by FHR.
*/
public String getEngineIdentifier() {
if (this.identifier != null) {
return this.identifier;
}
if (this.name != null) {
return "other-" + this.name;
}
return "other";
}
public boolean hasSuggestions() {
return !this.suggestions.isEmpty();
}
public int getSuggestionsCount() {
return this.suggestions.size();
}
public Iterable<String> getSuggestions() {
return this.suggestions;
}
public void setSuggestions(List<String> suggestions) {
if (suggestions == null) {
this.suggestions = new ArrayList<String>();
return;
}
this.suggestions = suggestions;
}
public Bitmap getIcon() {
return this.icon;
}
}

Просмотреть файл

@ -82,7 +82,7 @@ class SearchEngineRow extends AnimatedHeightLayout {
mUrlOpenListener.onUrlOpen(suggestion, EnumSet.noneOf(OnUrlOpenListener.Flags.class));
}
} else if (mSearchListener != null) {
mSearchListener.onSearch(mSearchEngine.name, suggestion);
mSearchListener.onSearch(mSearchEngine, suggestion);
}
}
};
@ -135,7 +135,7 @@ class SearchEngineRow extends AnimatedHeightLayout {
public void performUserEnteredSearch() {
String searchTerm = getSuggestionTextFromView(mUserEnteredView);
if (mSearchListener != null) {
mSearchListener.onSearch(mSearchEngine.name, searchTerm);
mSearchListener.onSearch(mSearchEngine, searchTerm);
}
}
@ -162,25 +162,25 @@ class SearchEngineRow extends AnimatedHeightLayout {
}
public void updateFromSearchEngine(SearchEngine searchEngine, boolean animate) {
// Update search engine reference
// Update search engine reference.
mSearchEngine = searchEngine;
// Set the search engine icon (e.g., Google) for the row
mIconView.updateAndScaleImage(mSearchEngine.icon, mSearchEngine.name);
// Set the search engine icon (e.g., Google) for the row.
mIconView.updateAndScaleImage(mSearchEngine.getIcon(), mSearchEngine.getEngineIdentifier());
// Set the initial content description
// Set the initial content description.
setDescriptionOnSuggestion(mUserEnteredTextView, mUserEnteredTextView.getText().toString());
// Add additional suggestions given by this engine
// Add additional suggestions given by this engine.
final int recycledSuggestionCount = mSuggestionView.getChildCount();
final int suggestionCount = mSearchEngine.suggestions.size();
for (int i = 0; i < suggestionCount; i++) {
int suggestionCounter = 0;
for (String suggestion : mSearchEngine.getSuggestions()) {
final View suggestionItem;
// Reuse suggestion views from recycled view, if possible
if (i + 1 < recycledSuggestionCount) {
suggestionItem = mSuggestionView.getChildAt(i + 1);
// Reuse suggestion views from recycled view, if possible.
if (suggestionCounter + 1 < recycledSuggestionCount) {
suggestionItem = mSuggestionView.getChildAt(suggestionCounter + 1);
suggestionItem.setVisibility(View.VISIBLE);
} else {
suggestionItem = mInflater.inflate(R.layout.suggestion_item, null);
@ -195,23 +195,24 @@ class SearchEngineRow extends AnimatedHeightLayout {
mSuggestionView.addView(suggestionItem);
}
final String suggestion = mSearchEngine.suggestions.get(i);
setSuggestionOnView(suggestionItem, suggestion);
if (animate) {
AlphaAnimation anim = new AlphaAnimation(0, 1);
anim.setDuration(ANIMATION_DURATION);
anim.setStartOffset(i * ANIMATION_DURATION);
anim.setStartOffset(suggestionCounter * ANIMATION_DURATION);
suggestionItem.startAnimation(anim);
}
++suggestionCounter;
}
// Hide extra suggestions that have been recycled
for (int i = suggestionCount + 1; i < recycledSuggestionCount; i++) {
// Hide extra suggestions that have been recycled.
for (int i = suggestionCounter + 1; i < recycledSuggestionCount; ++i) {
mSuggestionView.getChildAt(i).setVisibility(View.GONE);
}
// Make sure mSelectedView is still valid
// Make sure mSelectedView is still valid.
if (mSelectedView >= mSuggestionView.getChildCount()) {
mSelectedView = mSuggestionView.getChildCount() - 1;
}