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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java

Issue 1348473002: Fix size estimation for prerender in custom tabs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added comments to size estimate Created 5 years, 3 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
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.customtabs; 5 package org.chromium.chrome.browser.customtabs;
6 6
7 import android.app.ActivityManager; 7 import android.app.ActivityManager;
8 import android.app.Application; 8 import android.app.Application;
9 import android.content.ComponentName; 9 import android.content.ComponentName;
10 import android.content.Context; 10 import android.content.Context;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 private static AtomicReference<CustomTabsConnection> sInstance = 83 private static AtomicReference<CustomTabsConnection> sInstance =
84 new AtomicReference<CustomTabsConnection>(); 84 new AtomicReference<CustomTabsConnection>();
85 85
86 private static final class PrerenderedUrlParams { 86 private static final class PrerenderedUrlParams {
87 public final IBinder mSession; 87 public final IBinder mSession;
88 public final WebContents mWebContents; 88 public final WebContents mWebContents;
89 public final String mUrl; 89 public final String mUrl;
90 public final String mReferrer; 90 public final String mReferrer;
91 public final Bundle mExtras; 91 public final Bundle mExtras;
92 public final Point mSize;
92 93
93 PrerenderedUrlParams(IBinder session, WebContents webContents, String ur l, String referrer, 94 PrerenderedUrlParams(IBinder session, WebContents webContents, String ur l, String referrer,
94 Bundle extras) { 95 Point size, Bundle extras) {
95 mSession = session; 96 mSession = session;
96 mWebContents = webContents; 97 mWebContents = webContents;
97 mUrl = url; 98 mUrl = url;
98 mReferrer = referrer; 99 mReferrer = referrer;
100 mSize = size;
99 mExtras = extras; 101 mExtras = extras;
100 } 102 }
101 } 103 }
102 104
103 private static final class PredictionStats { 105 private static final class PredictionStats {
104 private static final long MIN_DELAY = 100; 106 private static final long MIN_DELAY = 100;
105 private static final long MAX_DELAY = 10000; 107 private static final long MAX_DELAY = 10000;
106 private long mLastRequestTimestamp = -1; 108 private long mLastRequestTimestamp = -1;
107 private long mDelayMs = MIN_DELAY; 109 private long mDelayMs = MIN_DELAY;
108 110
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 * hand, not cancelling the previous prerender leads to wasted resources, as 429 * hand, not cancelling the previous prerender leads to wasted resources, as
428 * a WebContents is lingering. This can be solved by requiring applications 430 * a WebContents is lingering. This can be solved by requiring applications
429 * to call mayLaunchUrl(null) to cancel a current prerender before 2, that 431 * to call mayLaunchUrl(null) to cancel a current prerender before 2, that
430 * is for a mispredict. 432 * is for a mispredict.
431 * 433 *
432 * @param session The Binder object identifying a session. 434 * @param session The Binder object identifying a session.
433 * @param url The URL the WebContents is for. 435 * @param url The URL the WebContents is for.
434 * @param referrer The referrer to use for |url|. 436 * @param referrer The referrer to use for |url|.
435 * @return The prerendered WebContents, or null. 437 * @return The prerendered WebContents, or null.
436 */ 438 */
437 WebContents takePrerenderedUrl(IBinder session, String url, String referrer) { 439 WebContents takePrerenderedUrl(IBinder session, String url, String referrer, Point size) {
438 ThreadUtils.assertOnUiThread(); 440 ThreadUtils.assertOnUiThread();
439 if (mPrerender == null || session == null || !session.equals(mPrerender. mSession)) { 441 if (mPrerender == null || session == null || !session.equals(mPrerender. mSession)) {
440 return null; 442 return null;
441 } 443 }
442 WebContents webContents = mPrerender.mWebContents; 444 WebContents webContents = mPrerender.mWebContents;
443 String prerenderedUrl = mPrerender.mUrl; 445 String prerenderedUrl = mPrerender.mUrl;
444 String prerenderReferrer = mPrerender.mReferrer; 446 String prerenderReferrer = mPrerender.mReferrer;
447 size.x = mPrerender.mSize.x;
448 size.y = mPrerender.mSize.y;
445 if (referrer == null) referrer = ""; 449 if (referrer == null) referrer = "";
446 mPrerender = null; 450 mPrerender = null;
447 if (TextUtils.equals(prerenderedUrl, url) 451 if (TextUtils.equals(prerenderedUrl, url)
448 && TextUtils.equals(prerenderReferrer, referrer)) { 452 && TextUtils.equals(prerenderReferrer, referrer)) {
449 return webContents; 453 return webContents;
450 } 454 }
451 mExternalPrerenderHandler.cancelCurrentPrerender(); 455 mExternalPrerenderHandler.cancelCurrentPrerender();
452 webContents.destroy(); 456 webContents.destroy();
453 return null; 457 return null;
454 } 458 }
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 mPrerender.mWebContents.destroy(); 670 mPrerender.mWebContents.destroy();
667 mPrerender = null; 671 mPrerender = null;
668 } 672 }
669 if (TextUtils.isEmpty(url)) return; 673 if (TextUtils.isEmpty(url)) return;
670 Intent extrasIntent = new Intent(); 674 Intent extrasIntent = new Intent();
671 if (extras != null) extrasIntent.putExtras(extras); 675 if (extras != null) extrasIntent.putExtras(extras);
672 if (IntentHandler.getExtraHeadersFromIntent(extrasIntent) != null) retur n; 676 if (IntentHandler.getExtraHeadersFromIntent(extrasIntent) != null) retur n;
673 if (mExternalPrerenderHandler == null) { 677 if (mExternalPrerenderHandler == null) {
674 mExternalPrerenderHandler = new ExternalPrerenderHandler(); 678 mExternalPrerenderHandler = new ExternalPrerenderHandler();
675 } 679 }
676 Point contentSize = estimateContentSize();
677 Context context = mApplication.getApplicationContext(); 680 Context context = mApplication.getApplicationContext();
678 String referrer = IntentHandler.getReferrerUrlIncludingExtraHeaders(extr asIntent, context); 681 String referrer = IntentHandler.getReferrerUrlIncludingExtraHeaders(extr asIntent, context);
679 if (referrer == null && getReferrerForSession(session) != null) { 682 if (referrer == null && getReferrerForSession(session) != null) {
680 referrer = getReferrerForSession(session).getUrl(); 683 referrer = getReferrerForSession(session).getUrl();
681 } 684 }
682 if (referrer == null) referrer = ""; 685 if (referrer == null) referrer = "";
686 Point contentSize = estimateContentSize(true);
683 WebContents webContents = mExternalPrerenderHandler.addPrerender( 687 WebContents webContents = mExternalPrerenderHandler.addPrerender(
684 Profile.getLastUsedProfile(), url, referrer, contentSize.x, cont entSize.y); 688 Profile.getLastUsedProfile(), url, referrer, contentSize.x, cont entSize.y);
685 if (webContents != null) { 689 if (webContents != null) {
686 mPrerender = new PrerenderedUrlParams(session, webContents, url, ref errer, extras); 690 mPrerender = new PrerenderedUrlParams(
691 session, webContents, url, referrer, estimateContentSize(fal se), extras);
Ted C 2015/09/16 18:12:47 why is this false? Isn't this for prerendered con
687 } 692 }
688 } 693 }
689 694
690 /** 695 /**
691 * Provides an estimate of the contents size. 696 * Provides an estimate of the contents size.
692 * 697 *
693 * The estimate is likely to be incorrect. This is not a problem, as the aim 698 * The estimate is likely to be incorrect. This is not a problem, as the aim
694 * is to avoid getting a different layout and resources than needed at 699 * is to avoid getting a different layout and resources than needed at
695 * render time. 700 * render time.
701 * @param forPrerenderedContents Whether the size returned should be for pre rendered web
702 * contents or for ContentViewCore. The former takes the web
703 * content size that doesn't include control c onatiner height
704 * in dp, the latter includes the control cont ainer height and
705 * is in pixels.
696 */ 706 */
697 private Point estimateContentSize() { 707 private Point estimateContentSize(boolean forPrerenderedContents) {
698 // The size is estimated as: 708 // The size is estimated as:
699 // X = screenSizeX 709 // X = screenSizeX
700 // Y = screenSizeY - top bar - bottom bar - custom tabs bar 710 // Y = screenSizeY - top bar - bottom bar - custom tabs bar
701 Point screenSize = new Point(); 711 Point screenSize = new Point();
702 WindowManager wm = (WindowManager) mApplication.getSystemService(Context .WINDOW_SERVICE); 712 WindowManager wm = (WindowManager) mApplication.getSystemService(Context .WINDOW_SERVICE);
703 wm.getDefaultDisplay().getSize(screenSize); 713 wm.getDefaultDisplay().getSize(screenSize);
704 Resources resources = mApplication.getResources(); 714 Resources resources = mApplication.getResources();
705 int statusBarId = resources.getIdentifier("status_bar_height", "dimen", "android"); 715 int statusBarId = resources.getIdentifier("status_bar_height", "dimen", "android");
706 int navigationBarId = resources.getIdentifier("navigation_bar_height", " dimen", "android");
707 try { 716 try {
708 screenSize.y -= 717 if (forPrerenderedContents) {
709 resources.getDimensionPixelSize(R.dimen.custom_tabs_control_ container_height); 718 screenSize.y -= resources.getDimensionPixelSize(
719 R.dimen.custom_tabs_control_container_height);
720 }
710 screenSize.y -= resources.getDimensionPixelSize(statusBarId); 721 screenSize.y -= resources.getDimensionPixelSize(statusBarId);
711 screenSize.y -= resources.getDimensionPixelSize(navigationBarId);
712 } catch (Resources.NotFoundException e) { 722 } catch (Resources.NotFoundException e) {
713 // Nothing, this is just a best effort estimate. 723 // Nothing, this is just a best effort estimate.
714 } 724 }
725 if (forPrerenderedContents) {
726 float density = resources.getDisplayMetrics().density;
727 screenSize.x /= density;
728 screenSize.y /= density;
729 }
715 return screenSize; 730 return screenSize;
716 } 731 }
717 732
718 @VisibleForTesting 733 @VisibleForTesting
719 void resetThrottling(int uid) { 734 void resetThrottling(int uid) {
720 synchronized (mLock) { 735 synchronized (mLock) {
721 mUidToPredictionsStats.put(uid, new PredictionStats()); 736 mUidToPredictionsStats.put(uid, new PredictionStats());
722 } 737 }
723 } 738 }
724 } 739 }
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698