OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 public synchronized int getSpeculationModeForSession(CustomTabsSessionToken session) { | |
Benoit L
2017/03/27 13:18:14
tiny nit: I'm usually all for not adding javadoc t
ahemery1
2017/03/27 14:47:33
Done.
| |
465 SessionParams params = mSessionParams.get(session); | |
466 return params == null ? CustomTabsConnection.SpeculationParams.PRERENDER | |
467 : params.mSpeculationMode; | |
468 } | |
469 | |
453 /** Tries to bind to a client to keep it alive, and returns true for success . */ | 470 /** 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) { | 471 public synchronized boolean keepAliveForSession(CustomTabsSessionToken sessi on, Intent intent) { |
455 // When an application is bound to a service, its priority is raised to | 472 // 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 | 473 // be at least equal to the application's one. This binds to a dummy |
457 // service (no calls to this service are made). | 474 // service (no calls to this service are made). |
458 if (intent == null || intent.getComponent() == null) return false; | 475 if (intent == null || intent.getComponent() == null) return false; |
459 SessionParams params = mSessionParams.get(session); | 476 SessionParams params = mSessionParams.get(session); |
460 if (params == null) return false; | 477 if (params == null) return false; |
461 | 478 |
462 KeepAliveServiceConnection connection = params.getKeepAliveConnection(); | 479 KeepAliveServiceConnection connection = params.getKeepAliveConnection(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
521 SessionParams params = mSessionParams.get(session); | 538 SessionParams params = mSessionParams.get(session); |
522 if (params == null) return; | 539 if (params == null) return; |
523 mSessionParams.remove(session); | 540 mSessionParams.remove(session); |
524 if (params.postMessageHandler != null) { | 541 if (params.postMessageHandler != null) { |
525 params.postMessageHandler.unbindFromContext(mContext); | 542 params.postMessageHandler.unbindFromContext(mContext); |
526 } | 543 } |
527 if (params.disconnectCallback != null) params.disconnectCallback.run(ses sion); | 544 if (params.disconnectCallback != null) params.disconnectCallback.run(ses sion); |
528 mUidHasCalledWarmup.delete(params.uid); | 545 mUidHasCalledWarmup.delete(params.uid); |
529 } | 546 } |
530 } | 547 } |
OLD | NEW |