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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/search_engines/TemplateUrlService.java

Issue 2930063002: Ensure TemplateUrlService is loaded in SearchActivity. (Closed)
Patch Set: Rebase Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/search_engines/TemplateUrlService.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/search_engines/TemplateUrlService.java b/chrome/android/java/src/org/chromium/chrome/browser/search_engines/TemplateUrlService.java
index a7bde8869364f2b0f902bc71ac6924dc041e98df..0678a0f89bd3a2aa1d8c12f395de2e7c7c7d867c 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/search_engines/TemplateUrlService.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/search_engines/TemplateUrlService.java
@@ -166,6 +166,31 @@ public class TemplateUrlService {
nativeLoad(mNativeTemplateUrlServiceAndroid);
}
+ /**
+ * Ensure the TemplateUrlService is loaded before running the specified action. If the service
+ * is already loaded, then run the action immediately.
+ * <p>
+ * Because this can introduce an arbitrary delay in the action being executed, ensure the state
+ * is still valid in the action before interacting with anything that might no longer be
+ * available (i.e. an Activity that has since been destroyed).
+ *
+ * @param action The action to be run.
+ */
+ public void runWhenLoaded(final Runnable action) {
+ if (isLoaded()) {
+ action.run();
+ } else {
+ registerLoadListener(new LoadListener() {
+ @Override
+ public void onTemplateUrlServiceLoaded() {
+ unregisterLoadListener(this);
+ action.run();
+ }
+ });
+ load();
+ }
+ }
+
/**
* Returns a list of the prepopulated search engines.
*

Powered by Google App Engine
This is Rietveld 408576698