diff options
| author | Mathew Inwood <mathewi@google.com> | 2011-09-05 18:58:48 +0100 |
|---|---|---|
| committer | Mathew Inwood <mathewi@google.com> | 2011-09-06 12:22:26 +0100 |
| commit | b4e831bf1ff62945199b89a77ad039be7bd16545 (patch) | |
| tree | a3a7dcf7f0de94487e03ec9b9904ab9cbdaa67ba /src/com/android/browser/IntentHandler.java | |
| parent | 012dcd474cd3980aa206e4b7a31fa67114f56d54 (diff) | |
| download | packages_apps_Browser-b4e831bf1ff62945199b89a77ad039be7bd16545.tar.gz packages_apps_Browser-b4e831bf1ff62945199b89a77ad039be7bd16545.tar.bz2 packages_apps_Browser-b4e831bf1ff62945199b89a77ad039be7bd16545.zip | |
Support for measuring page load times.
An app can attached a pending intent to an intent sent to the browser
which will be send when the load completes. The browser will fill in
the timestamp of when the page load completed, and details of preloading
success or otherwise if this was used.
Bug: 5259031
Change-Id: I2d025caabd6055ac25f06e69897a03d5c57c4f41
Diffstat (limited to 'src/com/android/browser/IntentHandler.java')
| -rw-r--r-- | src/com/android/browser/IntentHandler.java | 66 |
1 files changed, 63 insertions, 3 deletions
diff --git a/src/com/android/browser/IntentHandler.java b/src/com/android/browser/IntentHandler.java index cc6b57c91..178ba62c3 100644 --- a/src/com/android/browser/IntentHandler.java +++ b/src/com/android/browser/IntentHandler.java @@ -18,6 +18,8 @@ package com.android.browser; import android.app.Activity; +import android.app.PendingIntent; +import android.app.PendingIntent.CanceledException; import android.app.SearchManager; import android.content.ContentResolver; import android.content.Context; @@ -30,6 +32,7 @@ import android.provider.Browser; import android.provider.MediaStore; import android.speech.RecognizerResultsIntent; import android.text.TextUtils; +import android.util.Log; import android.util.Patterns; import com.android.browser.search.SearchEngine; @@ -50,6 +53,22 @@ public class IntentHandler { // "source" parameter for Google search from unknown source final static String GOOGLE_SEARCH_SOURCE_UNKNOWN = "unknown"; + // Pending intent extra attached to browser intents that is broadcast when the page load + // completes. + // TODO move to android.provider.Browser & make public? + private static final String EXTRA_LOAD_COMPLETE_PENDINGINTENT = "load_complete_intent"; + // extra attached to intent received via EXTRA_LOAD_COMPLETE_PENDINGINTENT indicating the + // time at which the load completed. + public static final String EXTRA_LOAD_COMPLETION_TIME = "completets"; + // extra attached to intent received via EXTRA_LOAD_COMPLETE_PENDINGINTENT indicating if + // preloading was attempted. + public static final String EXTRA_PREFETCH_ATTEMPTED = "prefattempt"; + // extra attached to intent received via EXTRA_LOAD_COMPLETE_PENDINGINTENT indicating if + // preloading succeeded. + public static final String EXTRA_PREFETCH_SUCCESS = "prefsuccess"; + + + /* package */ static final UrlData EMPTY_URL_DATA = new UrlData(null); private Activity mActivity; @@ -224,11 +243,39 @@ public class IntentHandler { } } + /** + * Send a pending intent received in a page view intent. This should be called when the page + * has finished loading. + * + * @param prefetchAttempted Indicates if prefetching was attempted, {@code null} if prefetching + * was not requested or is disabled. + * @param prefetchSucceeded Indicates if prefetching succeeded, {@code null} if prefetching + * was not requested or is disabled. + */ + public static void sendPageLoadCompletePendingIntent(Context context, PendingIntent pi, + Boolean prefetchAttempted, Boolean prefetchSucceeded) { + if (pi == null) return; + Intent fillIn = new Intent(); + fillIn.putExtra(EXTRA_LOAD_COMPLETION_TIME, System.currentTimeMillis()); + if (prefetchAttempted != null) { + fillIn.putExtra(EXTRA_PREFETCH_ATTEMPTED, prefetchAttempted.booleanValue()); + } + if (prefetchSucceeded != null) { + fillIn.putExtra(EXTRA_PREFETCH_SUCCESS, prefetchSucceeded.booleanValue()); + } + try { + pi.send(context, Activity.RESULT_OK, fillIn); + } catch (CanceledException e) { + // ignore + } + } + protected static UrlData getUrlDataFromIntent(Intent intent) { String url = ""; Map<String, String> headers = null; PreloadedTabControl preloaded = null; String preloadedSearchBoxQuery = null; + PendingIntent loadCompletePendingIntent = null; if (intent != null && (intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) { final String action = intent.getAction(); @@ -253,6 +300,10 @@ public class IntentHandler { PreloadRequestReceiver.EXTRA_SEARCHBOX_SETQUERY); preloaded = Preloader.getInstance().getPreloadedTab(id); } + if (intent.hasExtra(EXTRA_LOAD_COMPLETE_PENDINGINTENT)) { + loadCompletePendingIntent = + intent.getParcelableExtra(EXTRA_LOAD_COMPLETE_PENDINGINTENT); + } } else if (Intent.ACTION_SEARCH.equals(action) || MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action) || Intent.ACTION_WEB_SEARCH.equals(action)) { @@ -277,7 +328,8 @@ public class IntentHandler { } } } - return new UrlData(url, headers, intent, preloaded, preloadedSearchBoxQuery); + return new UrlData(url, headers, intent, preloaded, preloadedSearchBoxQuery, + loadCompletePendingIntent); } /** @@ -362,6 +414,7 @@ public class IntentHandler { final Intent mVoiceIntent; final PreloadedTabControl mPreloadedTab; final String mSearchBoxQueryToSubmit; + final PendingIntent mOnLoadCompletePendingIntent; UrlData(String url) { this.mUrl = url; @@ -369,14 +422,16 @@ public class IntentHandler { this.mVoiceIntent = null; this.mPreloadedTab = null; this.mSearchBoxQueryToSubmit = null; + this.mOnLoadCompletePendingIntent = null; } UrlData(String url, Map<String, String> headers, Intent intent) { - this(url, headers, intent, null, null); + this(url, headers, intent, null, null, null); } UrlData(String url, Map<String, String> headers, Intent intent, - PreloadedTabControl preloaded, String searchBoxQueryToSubmit) { + PreloadedTabControl preloaded, String searchBoxQueryToSubmit, + PendingIntent onLoadCompletePendingIntent) { this.mUrl = url; this.mHeaders = headers; if (RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS @@ -387,6 +442,7 @@ public class IntentHandler { } this.mPreloadedTab = preloaded; this.mSearchBoxQueryToSubmit = searchBoxQueryToSubmit; + this.mOnLoadCompletePendingIntent = onLoadCompletePendingIntent; } boolean isEmpty() { @@ -404,6 +460,10 @@ public class IntentHandler { String getSearchBoxQueryToSubmit() { return mSearchBoxQueryToSubmit; } + + PendingIntent getOnLoadCompletePendingIntent() { + return mOnLoadCompletePendingIntent; + } } } |
