| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.android_webview.crash; | |
| 6 | |
| 7 import org.chromium.base.CommandLine; | |
| 8 import org.chromium.base.annotations.SuppressFBWarnings; | |
| 9 | |
| 10 /** | |
| 11 * Class for fetching command line switches for WebView in a thread-safe way. | |
| 12 */ | |
| 13 class SynchronizedWebViewCommandLine { | |
| 14 private static final Object sLock = new Object(); | |
| 15 private static InitState sInitialized = InitState.NOT_STARTED; | |
| 16 // TODO(gsennton): this value is used in WebViewChromiumFactoryProvider as w
ell - set it | |
| 17 // somewhere where it can be read from both classes. | |
| 18 private static final String WEBVIEW_COMMAND_LINE_FILE = "/data/local/tmp/web
view-command-line"; | |
| 19 | |
| 20 private enum InitState { NOT_STARTED, STARTED, DONE } | |
| 21 | |
| 22 /** | |
| 23 * Initialize the global CommandLine using the WebView command line file. | |
| 24 * This method includes IO operations - it shouldn't be performed on the mai
n thread. | |
| 25 */ | |
| 26 public static void initOnSeparateThread() { | |
| 27 synchronized (sLock) { | |
| 28 if (sInitialized != InitState.NOT_STARTED) return; | |
| 29 sInitialized = InitState.STARTED; | |
| 30 } | |
| 31 new Thread(new Runnable() { | |
| 32 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") | |
| 33 @Override | |
| 34 public void run() { | |
| 35 CommandLine.initFromFile(WEBVIEW_COMMAND_LINE_FILE); | |
| 36 synchronized (sLock) { | |
| 37 sInitialized = InitState.DONE; | |
| 38 sLock.notifyAll(); | |
| 39 } | |
| 40 } | |
| 41 }, "WebView-command-line-init-thread").start(); | |
| 42 } | |
| 43 | |
| 44 /** | |
| 45 * Returns true if this command line contains the given switch. | |
| 46 */ | |
| 47 public static boolean hasSwitch(String switchString) { | |
| 48 synchronized (sLock) { | |
| 49 while (sInitialized != InitState.DONE) { | |
| 50 try { | |
| 51 sLock.wait(); | |
| 52 } catch (InterruptedException e) { | |
| 53 throw new RuntimeException(e); | |
| 54 } | |
| 55 } | |
| 56 return CommandLine.getInstance().hasSwitch(switchString); | |
| 57 } | |
| 58 } | |
| 59 } | |
| OLD | NEW |