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

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

Issue 2748013004: CustomTabs: Base version for prerender switch (Closed)
Patch Set: Tiny rework of startSpeculation Created 3 years, 8 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 | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java » ('j') | 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.content.ComponentName; 7 import android.content.ComponentName;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.content.ServiceConnection; 10 import android.content.ServiceConnection;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 public final PostMessageHandler postMessageHandler; 124 public final PostMessageHandler postMessageHandler;
125 public boolean mIgnoreFragments; 125 public boolean mIgnoreFragments;
126 public boolean lowConfidencePrediction; 126 public boolean lowConfidencePrediction;
127 public boolean highConfidencePrediction; 127 public boolean highConfidencePrediction;
128 private boolean mShouldHideDomain; 128 private boolean mShouldHideDomain;
129 private boolean mShouldPrerenderOnCellular; 129 private boolean mShouldPrerenderOnCellular;
130 private boolean mShouldSendNavigationInfo; 130 private boolean mShouldSendNavigationInfo;
131 private KeepAliveServiceConnection mKeepAliveConnection; 131 private KeepAliveServiceConnection mKeepAliveConnection;
132 private String mPredictedUrl; 132 private String mPredictedUrl;
133 private long mLastMayLaunchUrlTimestamp; 133 private long mLastMayLaunchUrlTimestamp;
134 private int mSpeculationMode;
134 135
135 public SessionParams(Context context, int uid, DisconnectCallback callba ck, 136 public SessionParams(Context context, int uid, DisconnectCallback callba ck,
136 PostMessageHandler postMessageHandler) { 137 PostMessageHandler postMessageHandler) {
137 this.uid = uid; 138 this.uid = uid;
138 packageName = getPackageName(context, uid); 139 packageName = getPackageName(context, uid);
139 disconnectCallback = callback; 140 disconnectCallback = callback;
140 this.postMessageHandler = postMessageHandler; 141 this.postMessageHandler = postMessageHandler;
142 this.mSpeculationMode = CustomTabsConnection.SpeculationParams.PRERE NDER;
141 } 143 }
142 144
143 private static String getPackageName(Context context, int uid) { 145 private static String getPackageName(Context context, int uid) {
144 PackageManager packageManager = context.getPackageManager(); 146 PackageManager packageManager = context.getPackageManager();
145 String[] packageList = packageManager.getPackagesForUid(uid); 147 String[] packageList = packageManager.getPackagesForUid(uid);
146 if (packageList.length != 1 || TextUtils.isEmpty(packageList[0])) re turn null; 148 if (packageList.length != 1 || TextUtils.isEmpty(packageList[0])) re turn null;
147 return packageList[0]; 149 return packageList[0];
148 } 150 }
149 151
150 public KeepAliveServiceConnection getKeepAliveConnection() { 152 public KeepAliveServiceConnection getKeepAliveConnection() {
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 445
444 /** 446 /**
445 * Sets whether prerender should be turned on for mobile networks for given session. 447 * Sets whether prerender should be turned on for mobile networks for given session.
446 */ 448 */
447 public synchronized void setPrerenderCellularForSession( 449 public synchronized void setPrerenderCellularForSession(
448 CustomTabsSessionToken session, boolean prerender) { 450 CustomTabsSessionToken session, boolean prerender) {
449 SessionParams params = mSessionParams.get(session); 451 SessionParams params = mSessionParams.get(session);
450 if (params != null) params.mShouldPrerenderOnCellular = prerender; 452 if (params != null) params.mShouldPrerenderOnCellular = prerender;
451 } 453 }
452 454
455 /**
456 * Sets the speculation mode to be used by default for given session.
457 */
458 public synchronized void setSpeculationModeForSession(
459 CustomTabsSessionToken session, int speculationMode) {
460 SessionParams params = mSessionParams.get(session);
461 if (params != null) params.mSpeculationMode = speculationMode;
462 }
463
464 /**
465 * Get the speculation mode to be used by default for the given session.
466 * If no value has been set will default to PRERENDER mode.
467 */
468 public synchronized int getSpeculationModeForSession(CustomTabsSessionToken session) {
469 SessionParams params = mSessionParams.get(session);
470 return params == null ? CustomTabsConnection.SpeculationParams.PRERENDER
471 : params.mSpeculationMode;
472 }
473
453 /** Tries to bind to a client to keep it alive, and returns true for success . */ 474 /** Tries to bind to a client to keep it alive, and returns true for success . */
454 public synchronized boolean keepAliveForSession(CustomTabsSessionToken sessi on, Intent intent) { 475 public synchronized boolean keepAliveForSession(CustomTabsSessionToken sessi on, Intent intent) {
455 // When an application is bound to a service, its priority is raised to 476 // When an application is bound to a service, its priority is raised to
456 // be at least equal to the application's one. This binds to a dummy 477 // be at least equal to the application's one. This binds to a dummy
457 // service (no calls to this service are made). 478 // service (no calls to this service are made).
458 if (intent == null || intent.getComponent() == null) return false; 479 if (intent == null || intent.getComponent() == null) return false;
459 SessionParams params = mSessionParams.get(session); 480 SessionParams params = mSessionParams.get(session);
460 if (params == null) return false; 481 if (params == null) return false;
461 482
462 KeepAliveServiceConnection connection = params.getKeepAliveConnection(); 483 KeepAliveServiceConnection connection = params.getKeepAliveConnection();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 SessionParams params = mSessionParams.get(session); 542 SessionParams params = mSessionParams.get(session);
522 if (params == null) return; 543 if (params == null) return;
523 mSessionParams.remove(session); 544 mSessionParams.remove(session);
524 if (params.postMessageHandler != null) { 545 if (params.postMessageHandler != null) {
525 params.postMessageHandler.unbindFromContext(mContext); 546 params.postMessageHandler.unbindFromContext(mContext);
526 } 547 }
527 if (params.disconnectCallback != null) params.disconnectCallback.run(ses sion); 548 if (params.disconnectCallback != null) params.disconnectCallback.run(ses sion);
528 mUidHasCalledWarmup.delete(params.uid); 549 mUidHasCalledWarmup.delete(params.uid);
529 } 550 }
530 } 551 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698