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

Side by Side Diff: chromecast/shell/android/apk/src/org/chromium/chromecast/shell/CastBrowserHelper.java

Issue 490603002: Chromecast: initial checkin of Android-based cast shell. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: naming change Created 6 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
OLDNEW
(Empty)
1 // Copyright 2014 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.chromecast.shell;
6
7 import android.app.Activity;
8 import android.content.Context;
9 import android.content.Intent;
10 import android.os.Build;
11 import android.os.Debug;
12 import android.util.Log;
13
14 import org.chromium.base.BaseSwitches;
15 import org.chromium.base.CommandLine;
16 import org.chromium.base.library_loader.LibraryLoader;
17 import org.chromium.base.library_loader.ProcessInitException;
18 import org.chromium.content.browser.BrowserStartupController;
19 import org.chromium.content.browser.DeviceUtils;
20
21 /**
22 * Static, one-time initialization for the browser process.
23 */
24 public class CastBrowserHelper {
25 private static final String TAG = "CastBrowserHelper";
26
27 public static final String COMMAND_LINE_FILE = "/data/local/tmp/castshell-co mmand-line";
28 public static final String COMMAND_LINE_ARGS_KEY = "commandLineArgs";
29
30 private static boolean sIsBrowserInitialized = false;
31
32 /**
33 * Starts the browser process synchronously, returning success or failure. I f the browser has
34 * already started, immediately returns true without performing any more ini tialization.
35 * This may only be called on the UI thread.
36 *
37 * @return whether or not the process started successfully
38 */
39 public static boolean initializeBrowser(Context context) {
40 if (sIsBrowserInitialized) return true;
41
42 Log.d(TAG, "Performing one-time browser initialization");
43
44 // Initializing the command line must occur before loading the library.
45 if (!CommandLine.isInitialized()) {
46 if (allowCommandLineImport()) {
47 Log.d(TAG, "Initializing command line from " + COMMAND_LINE_FILE );
48 CommandLine.initFromFile(COMMAND_LINE_FILE);
49 } else {
50 CommandLine.init(null);
51 }
52
53 if (context instanceof Activity) {
54 Intent launchingIntent = ((Activity) context).getIntent();
55 String[] commandLineParams = getCommandLineParamsFromIntent(laun chingIntent);
56 if (commandLineParams != null) {
57 CommandLine.getInstance().appendSwitchesAndArguments(command LineParams);
58 }
59 }
60 }
61
62 CommandLine.getInstance().appendSwitchWithValue("force-device-scale-fact or", "1");
Yaron 2014/09/06 01:10:14 use constant from ContentSwitches
gunsch 2014/09/08 19:42:23 Done.
63
64 waitForDebuggerIfNeeded();
65
66 DeviceUtils.addDeviceSpecificUserAgentSwitch(context);
67
68 try {
69 LibraryLoader.ensureInitialized();
70
71 Log.d(TAG, "Loading BrowserStartupController...");
72 BrowserStartupController.get(context).startBrowserProcessesSync(fals e);
73
74 sIsBrowserInitialized = true;
75 return true;
76 } catch (ProcessInitException e) {
77 Log.e(TAG, "Unable to launch browser process.", e);
78 return false;
79 }
80 }
81
82 private static boolean allowCommandLineImport() {
83 return !Build.TYPE.equals("user");
84 }
85
86 private static String[] getCommandLineParamsFromIntent(Intent intent) {
87 return intent != null ? intent.getStringArrayExtra(COMMAND_LINE_ARGS_KEY ) : null;
88 }
89
90 private static void waitForDebuggerIfNeeded() {
91 if (!CommandLine.getInstance().hasSwitch(BaseSwitches.WAIT_FOR_JAVA_DEBU GGER)) {
92 return;
93 }
94 Log.e(TAG, "Waiting for Java debugger to connect...");
95 Debug.waitForDebugger();
96 Log.e(TAG, "Java debugger connected. Resuming execution.");
97 }
98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698