Skip to content

Commit

Permalink
[Android] Cache document-mode command-line check
Browse files Browse the repository at this point in the history
FeatureUtilities.isDocumentMode can be called relatively frequently.
Avoid the cost of the associated JNI command-line call and string
conversion by caching the result of the "--disable-document-mode"
query.

BUG=457748

Review URL: https://codereview.chromium.org/1255733002

Cr-Commit-Position: refs/heads/master@{#340185}
  • Loading branch information
jdduke authored and Commit bot committed Jul 23, 2015
1 parent 6172036 commit 8e78caf
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
public class FeatureUtilities {
private static Boolean sHasGoogleAccountAuthenticator;
private static Boolean sHasRecognitionIntentHandler;
private static Boolean sDocumentModeDisabled;

/**
* Determines whether or not the {@link RecognizerIntent#ACTION_WEB_SEARCH} {@link Intent}
Expand Down Expand Up @@ -95,11 +96,13 @@ private static boolean hasSyncPermissions(Context context) {
* @return Whether Chrome should be running on document mode.
*/
public static boolean isDocumentMode(Context context) {
if (sDocumentModeDisabled == null && CommandLine.getInstance() != null) {
sDocumentModeDisabled = CommandLine.getInstance().hasSwitch(
ChromeSwitches.DISABLE_DOCUMENT_MODE);
}
return isDocumentModeEligible(context)
&& !DocumentModeManager.getInstance(context).isOptedOutOfDocumentMode()
&& ((CommandLine.getInstance() == null)
|| !CommandLine.getInstance().hasSwitch(
ChromeSwitches.DISABLE_DOCUMENT_MODE));
&& (sDocumentModeDisabled == null || !sDocumentModeDisabled.booleanValue());
}

/**
Expand Down

0 comments on commit 8e78caf

Please sign in to comment.