| 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.
|
| *
|
|
|