org.chromium.chrome.browser.init.ChromeBrowserInitializer Java Examples

The following examples show how to use org.chromium.chrome.browser.init.ChromeBrowserInitializer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChromeGcmListenerService.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void pushMessageReceived(final String from, final Bundle data) {
    final String bundleSubtype = "subtype";
    if (!data.containsKey(bundleSubtype)) {
        Log.w(TAG, "Received push message with no subtype");
        return;
    }
    final String appId = data.getString(bundleSubtype);
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        @SuppressFBWarnings("DM_EXIT")
        public void run() {
            try {
                ChromeBrowserInitializer.getInstance(getApplicationContext())
                    .handleSynchronousStartup();
                GCMDriver.onMessageReceived(appId, from, data);
            } catch (ProcessInitException e) {
                Log.e(TAG, "ProcessInitException while starting the browser process");
                // Since the library failed to initialize nothing in the application
                // can work, so kill the whole application not just the activity.
                System.exit(-1);
            }
        }
    });
}
 
Example #2
Source File: ChromeBrowserProvider.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether Chrome is sufficiently initialized to handle a call to the
 * ChromeBrowserProvider.
 */
private boolean canHandleContentProviderApiCall() {
    if (isInUiThread()) return false;
    ensureUriMatcherInitialized();
    if (mNativeChromeBrowserProvider != 0) return true;
    synchronized (mLoadNativeLock) {
        ThreadUtils.runOnUiThreadBlocking(new Runnable() {
            @Override
            @SuppressFBWarnings("DM_EXIT")
            public void run() {
                if (mNativeChromeBrowserProvider != 0) return;
                try {
                    ChromeBrowserInitializer.getInstance(getContext())
                            .handleSynchronousStartup();
                } catch (ProcessInitException e) {
                    // Chrome browser runs in the background, so exit silently; but do exit,
                    // since otherwise the next attempt to use Chrome will find a broken JNI.
                    System.exit(-1);
                }
                ensureNativeSideInitialized();
            }
        });
    }
    return true;
}
 
Example #3
Source File: ChromeGcmListenerService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * To be called when a GCM message is ready to be dispatched. Will initialise the native code
 * of the browser process, and forward the message to the GCM Driver. Must be called on the UI
 * thread.
 */
@SuppressFBWarnings("DM_EXIT")
static void dispatchMessageToDriver(Context applicationContext, GCMMessage message) {
    ThreadUtils.assertOnUiThread();

    try {
        ChromeBrowserInitializer.getInstance(applicationContext).handleSynchronousStartup();
        GCMDriver.dispatchMessage(message);

    } catch (ProcessInitException e) {
        Log.e(TAG, "ProcessInitException while starting the browser process");

        // Since the library failed to initialize nothing in the application can work, so kill
        // the whole application as opposed to just this service.
        System.exit(-1);
    }
}
 
Example #4
Source File: CustomTabsConnection.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/** Warmup activities that should only happen once. */
@SuppressFBWarnings("DM_EXIT")
private static void initializeBrowser(final Application app) {
    ThreadUtils.assertOnUiThread();
    try {
        ChromeBrowserInitializer.getInstance(app).handleSynchronousStartupWithGpuWarmUp();
    } catch (ProcessInitException e) {
        Log.e(TAG, "ProcessInitException while starting the browser process.");
        // Cannot do anything without the native library, and cannot show a
        // dialog to the user.
        System.exit(-1);
    }
    final Context context = app.getApplicationContext();
    ChildProcessLauncher.warmUp(context);
    ChromeBrowserInitializer.initNetworkChangeNotifier(context);
    WarmupManager.getInstance().initializeViewHierarchy(
            context, R.layout.custom_tabs_control_container, R.layout.custom_tabs_toolbar);
}
 
Example #5
Source File: ChromeBackgroundService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
@SuppressFBWarnings("DM_EXIT")
protected void launchBrowser(Context context, String tag) {
    Log.i(TAG, "Launching browser");
    try {
        ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "ProcessInitException while starting the browser process");
        switch (tag) {
            case PrecacheController.PERIODIC_TASK_TAG:
            case PrecacheController.CONTINUATION_TASK_TAG:
                // Record the failure persistently, and upload to UMA when the library
                // successfully loads next time.
                PrecacheUMA.record(PrecacheUMA.Event.PRECACHE_TASK_LOAD_LIBRARY_FAIL);
                break;
            default:
                break;
        }
        // Since the library failed to initialize nothing in the application
        // can work, so kill the whole application not just the activity.
        System.exit(-1);
    }
}
 
Example #6
Source File: PrefetchBackgroundTask.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
@SuppressFBWarnings("DM_EXIT")
void launchBrowserIfNecessary(Context context) {
    if (BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER)
                    .isStartupSuccessfullyCompleted()) {
        return;
    }

    // TODO(https://crbug.com/717251): Remove when BackgroundTaskScheduler supports loading the
    // native library.
    try {
        ChromeBrowserInitializer.getInstance(context).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "ProcessInitException while starting the browser process.");
        // Since the library failed to initialize nothing in the application can work, so kill
        // the whole application not just the activity.
        System.exit(-1);
    }
}
 
Example #7
Source File: OfflineBackgroundTask.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private static void launchBrowserIfNecessary(Context context) {
    if (BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER)
                    .isStartupSuccessfullyCompleted()) {
        return;
    }

    // TODO(fgorski): This method is taken from ChromeBackgroundService as a local fix and will
    // be removed with BackgroundTaskScheduler supporting GcmNetworkManager scheduling.
    try {
        ChromeBrowserInitializer.getInstance(context).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "ProcessInitException while starting the browser process.");
        // Since the library failed to initialize nothing in the application can work, so kill
        // the whole application not just the activity.
        System.exit(-1);
    }
}
 
Example #8
Source File: ChromeBrowserProvider.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether Chrome is sufficiently initialized to handle a call to the
 * ChromeBrowserProvider.
 */
private boolean canHandleContentProviderApiCall() {
    if (isInUiThread()) return false;
    ensureUriMatcherInitialized();
    if (mNativeChromeBrowserProvider != 0) return true;
    synchronized (mLoadNativeLock) {
        ThreadUtils.runOnUiThreadBlocking(new Runnable() {
            @Override
            @SuppressFBWarnings("DM_EXIT")
            public void run() {
                if (mNativeChromeBrowserProvider != 0) return;
                try {
                    ChromeBrowserInitializer.getInstance(getContext())
                            .handleSynchronousStartup();
                } catch (ProcessInitException e) {
                    // Chrome browser runs in the background, so exit silently; but do exit,
                    // since otherwise the next attempt to use Chrome will find a broken JNI.
                    System.exit(-1);
                }
                ensureNativeSideInitialized();
            }
        });
    }
    return true;
}
 
Example #9
Source File: NotificationService.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Chrome and starts the browser process if it's not running as of yet, and
 * dispatch |intent| to the NotificationPlatformBridge once this is done.
 *
 * @param intent The intent containing the notification's information.
 */
@SuppressFBWarnings("DM_EXIT")
private void dispatchIntentOnUIThread(Intent intent) {
    try {
        ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup();

        // Now that the browser process is initialized, we pass forward the call to the
        // NotificationPlatformBridge which will take care of delivering the appropriate events.
        if (!NotificationPlatformBridge.dispatchNotificationEvent(intent)) {
            Log.w(TAG, "Unable to dispatch the notification event to Chrome.");
        }

        // TODO(peter): Verify that the lifetime of the NotificationService is sufficient
        // when a notification event could be dispatched successfully.

    } catch (ProcessInitException e) {
        Log.e(TAG, "Unable to start the browser process.", e);
        System.exit(-1);
    }
}
 
Example #10
Source File: CustomTabsConnection.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/** Warmup activities that should only happen once. */
@SuppressFBWarnings("DM_EXIT")
private static void initializeBrowser(final Application app) {
    ThreadUtils.assertOnUiThread();
    try {
        ChromeBrowserInitializer.getInstance(app).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "ProcessInitException while starting the browser process.");
        // Cannot do anything without the native library, and cannot show a
        // dialog to the user.
        System.exit(-1);
    }
    final Context context = app.getApplicationContext();
    final ChromeApplication chrome = (ChromeApplication) context;
    ChildProcessCreationParams.set(chrome.getChildProcessCreationParams());
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            ChildProcessLauncher.warmUp(context);
            return null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    ChromeBrowserInitializer.initNetworkChangeNotifier(context);
    WarmupManager.getInstance().initializeViewHierarchy(
            context, R.layout.custom_tabs_control_container, R.layout.custom_tabs_toolbar);
}
 
Example #11
Source File: ChromeBackgroundService.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
@SuppressFBWarnings("DM_EXIT")
protected void launchBrowser(Context context, String tag) {
    Log.i(TAG, "Launching browser");
    try {
        ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "ProcessInitException while starting the browser process");
        switch (tag) {
            case PrecacheController.PERIODIC_TASK_TAG:
            case PrecacheController.CONTINUATION_TASK_TAG:
                // Record the failure persistently, and upload to UMA when the library
                // successfully loads next time.
                PrecacheUMA.record(PrecacheUMA.Event.PRECACHE_TASK_LOAD_LIBRARY_FAIL);
                break;
            default:
                break;
        }
        // Since the library failed to initialize nothing in the application
        // can work, so kill the whole application not just the activity.
        System.exit(-1);
    }
}
 
Example #12
Source File: ChromeBackgroundService.java    From delion with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
@SuppressFBWarnings("DM_EXIT")
protected void launchBrowser(Context context, String tag) {
    Log.i(TAG, "Launching browser");
    try {
        ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "ProcessInitException while starting the browser process");
        switch (tag) {
            case PrecacheController.PERIODIC_TASK_TAG:
            case PrecacheController.CONTINUATION_TASK_TAG:
                // Record the failure persistently, and upload to UMA when the library
                // successfully loads next time.
                PrecacheUMA.record(PrecacheUMA.Event.PRECACHE_TASK_LOAD_LIBRARY_FAIL);
                break;
            default:
                break;
        }
        // Since the library failed to initialize nothing in the application
        // can work, so kill the whole application not just the activity.
        System.exit(-1);
    }
}
 
Example #13
Source File: CustomTabsConnection.java    From delion with Apache License 2.0 6 votes vote down vote up
/** Warmup activities that should only happen once. */
@SuppressFBWarnings("DM_EXIT")
private static void initializeBrowser(final Application app) {
    ThreadUtils.assertOnUiThread();
    try {
        ChromeBrowserInitializer.getInstance(app).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "ProcessInitException while starting the browser process.");
        // Cannot do anything without the native library, and cannot show a
        // dialog to the user.
        System.exit(-1);
    }
    final Context context = app.getApplicationContext();
    final ChromeApplication chrome = (ChromeApplication) context;
    ChildProcessCreationParams.set(chrome.getChildProcessCreationParams());
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            ChildProcessLauncher.warmUp(context);
            return null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    ChromeBrowserInitializer.initNetworkChangeNotifier(context);
    WarmupManager.getInstance().initializeViewHierarchy(
            context, R.layout.custom_tabs_control_container);
}
 
Example #14
Source File: ChromeBrowserProvider.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether Chrome is sufficiently initialized to handle a call to the
 * ChromeBrowserProvider.
 */
private boolean canHandleContentProviderApiCall() {
    if (isInUiThread()) return false;
    ensureUriMatcherInitialized();
    if (mNativeChromeBrowserProvider != 0) return true;
    synchronized (mLoadNativeLock) {
        ThreadUtils.runOnUiThreadBlocking(new Runnable() {
            @Override
            @SuppressFBWarnings("DM_EXIT")
            public void run() {
                if (mNativeChromeBrowserProvider != 0) return;
                try {
                    ChromeBrowserInitializer.getInstance(getContext())
                            .handleSynchronousStartup();
                } catch (ProcessInitException e) {
                    // Chrome browser runs in the background, so exit silently; but do exit,
                    // since otherwise the next attempt to use Chrome will find a broken JNI.
                    System.exit(-1);
                }
                ensureNativeSideInitialized();
            }
        });
    }
    return true;
}
 
Example #15
Source File: ChromeGcmListenerService.java    From delion with Apache License 2.0 6 votes vote down vote up
private void pushMessageReceived(final String from, final Bundle data) {
    final String bundleSubtype = "subtype";
    if (!data.containsKey(bundleSubtype)) {
        Log.w(TAG, "Received push message with no subtype");
        return;
    }
    final String appId = data.getString(bundleSubtype);
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        @SuppressFBWarnings("DM_EXIT")
        public void run() {
            try {
                ChromeBrowserInitializer.getInstance(getApplicationContext())
                    .handleSynchronousStartup();
                GCMDriver.onMessageReceived(appId, from, data);
            } catch (ProcessInitException e) {
                Log.e(TAG, "ProcessInitException while starting the browser process");
                // Since the library failed to initialize nothing in the application
                // can work, so kill the whole application not just the activity.
                System.exit(-1);
            }
        }
    });
}
 
Example #16
Source File: NotificationService.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Chrome and starts the browser process if it's not running as of yet, and
 * dispatch |intent| to the NotificationPlatformBridge once this is done.
 *
 * @param intent The intent containing the notification's information.
 */
@SuppressFBWarnings("DM_EXIT")
static void dispatchIntentOnUIThread(Context context, Intent intent) {
    try {
        ChromeBrowserInitializer.getInstance(context).handleSynchronousStartup();

        // Warm up the WebappRegistry, as we need to check if this notification should launch a
        // standalone web app. This no-ops if the registry is already initialized and warmed,
        // but triggers a strict mode violation otherwise (i.e. the browser isn't running).
        // Temporarily disable strict mode to work around the violation.
        StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
        try {
            WebappRegistry.getInstance();
            WebappRegistry.warmUpSharedPrefs();
        } finally {
            StrictMode.setThreadPolicy(oldPolicy);
        }

        // Now that the browser process is initialized, we pass forward the call to the
        // NotificationPlatformBridge which will take care of delivering the appropriate events.
        if (!NotificationPlatformBridge.dispatchNotificationEvent(intent)) {
            Log.w(TAG, "Unable to dispatch the notification event to Chrome.");
        }

        // TODO(peter): Verify that the lifetime of the NotificationService is sufficient
        // when a notification event could be dispatched successfully.

    } catch (ProcessInitException e) {
        Log.e(TAG, "Unable to start the browser process.", e);
        System.exit(-1);
    }
}
 
Example #17
Source File: BookmarkWidgetService.java    From delion with Apache License 2.0 5 votes vote down vote up
@UiThread
@SuppressFBWarnings("DM_EXIT")
@Override
public void onCreate() {
    // Required to be applied here redundantly to prevent crashes in the cases where the
    // package data is deleted or the Chrome application forced to stop.
    try {
        ChromeBrowserInitializer.getInstance(mContext).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "Failed to start browser process.", e);
        // Since the library failed to initialize nothing in the application
        // can work, so kill the whole application not just the activity
        System.exit(-1);
    }
    if (isWidgetNewlyCreated()) {
        RecordUserAction.record("BookmarkNavigatorWidgetAdded");
    }

    // Partner bookmarks need to be loaded explicitly.
    PartnerBookmarksShim.kickOffReading(mContext);

    mBookmarkModel = new BookmarkModel();
    mBookmarkModel.addObserver(new BookmarkModelObserver() {
        @Override
        public void bookmarkModelLoaded() {
            // Do nothing. No need to refresh.
        }

        @Override
        public void bookmarkModelChanged() {
            refreshWidget();
        }
    });
}
 
Example #18
Source File: SynchronousInitializationActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Ensure that native library is loaded.
    try {
        ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "Failed to start browser process.", e);
        ChromeApplication.reportStartupErrorAndExit(e);
    }
}
 
Example #19
Source File: AccountsChangedReceiver.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@SuppressFBWarnings("DM_EXIT")
private static void startBrowserIfNeededAndValidateAccounts(final Context context) {
    BrowserParts parts = new EmptyBrowserParts() {
        @Override
        public void finishNativeInitialization() {
            ThreadUtils.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    SigninHelper.get(context).validateAccountSettings(true);
                }
            });
        }

        @Override
        public void onStartupFailure() {
            // Startup failed. So notify SigninHelper of changed accounts via
            // shared prefs.
            SigninHelper.markAccountsChangedPref(context);
        }
    };
    try {
        ChromeBrowserInitializer.getInstance(context).handlePreNativeStartup(parts);
        ChromeBrowserInitializer.getInstance(context).handlePostNativeStartup(true, parts);
    } catch (ProcessInitException e) {
        Log.e(TAG, "Unable to load native library.", e);
        ChromeApplication.reportStartupErrorAndExit(e);
    }
}
 
Example #20
Source File: SynchronousInitializationActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Ensure that native library is loaded.
    try {
        ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "Failed to start browser process.", e);
        ChromeApplication.reportStartupErrorAndExit(e);
    }
}
 
Example #21
Source File: AccountsChangedReceiver.java    From delion with Apache License 2.0 5 votes vote down vote up
@SuppressFBWarnings("DM_EXIT")
private static void startBrowserIfNeededAndValidateAccounts(final Context context) {
    BrowserParts parts = new EmptyBrowserParts() {
        @Override
        public void finishNativeInitialization() {
            ThreadUtils.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    SigninHelper.get(context).validateAccountSettings(true);
                }
            });
        }

        @Override
        public void onStartupFailure() {
            // Startup failed. So notify SigninHelper of changed accounts via
            // shared prefs.
            SigninHelper.markAccountsChangedPref(context);
        }
    };
    try {
        ChromeBrowserInitializer.getInstance(context).handlePreNativeStartup(parts);
        ChromeBrowserInitializer.getInstance(context).handlePostNativeStartup(true, parts);
    } catch (ProcessInitException e) {
        Log.e(TAG, "Unable to load native library.", e);
        ChromeApplication.reportStartupErrorAndExit(e);
    }
}
 
Example #22
Source File: BookmarkWidgetService.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@UiThread
@SuppressFBWarnings("DM_EXIT")
@Override
public void onCreate() {
    // Required to be applied here redundantly to prevent crashes in the cases where the
    // package data is deleted or the Chrome application forced to stop.
    try {
        ChromeBrowserInitializer.getInstance(mContext).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "Failed to start browser process.", e);
        // Since the library failed to initialize nothing in the application
        // can work, so kill the whole application not just the activity
        System.exit(-1);
    }
    if (isWidgetNewlyCreated()) {
        RecordUserAction.record("BookmarkNavigatorWidgetAdded");
    }

    // Partner bookmarks need to be loaded explicitly.
    PartnerBookmarksShim.kickOffReading(mContext);

    mBookmarkModel = new BookmarkModel();
    mBookmarkModel.addObserver(new BookmarkModelObserver() {
        @Override
        public void bookmarkModelLoaded() {
            // Do nothing. No need to refresh.
        }

        @Override
        public void bookmarkModelChanged() {
            refreshWidget();
        }
    });
}
 
Example #23
Source File: NativeBackgroundTask.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Ensure that native is started before running the task. If native fails to start, the task is
 * going to be rescheduled, by issuing a {@see TaskFinishedCallback} with parameter set to
 * <c>true</c>.
 *
 * @param context the current context
 * @param startWithNativeRunnable A runnable that will execute #onStartTaskWithNative, after the
 *    native is loaded.
 * @param rescheduleRunnable A runnable that will be called to reschedule the task in case
 *    native initialization fails.
 */
protected final void runWithNative(final Context context,
        final Runnable startWithNativeRunnable, final Runnable rescheduleRunnable) {
    if (isNativeLoaded()) {
        ThreadUtils.postOnUiThread(startWithNativeRunnable);
        return;
    }

    final BrowserParts parts = new EmptyBrowserParts() {
        @Override
        public void finishNativeInitialization() {
            ThreadUtils.postOnUiThread(startWithNativeRunnable);
        }
        @Override
        public void onStartupFailure() {
            ThreadUtils.postOnUiThread(rescheduleRunnable);
        }
    };

    ThreadUtils.postOnUiThread(new Runnable() {
        @Override
        public void run() {
            // If task was stopped before we got here, don't start native initialization.
            if (mTaskStopped) return;
            try {
                ChromeBrowserInitializer.getInstance(context).handlePreNativeStartup(parts);

                ChromeBrowserInitializer.getInstance(context).handlePostNativeStartup(
                        true /* isAsync */, parts);
            } catch (ProcessInitException e) {
                Log.e(TAG, "ProcessInitException while starting the browser process.");
                rescheduleRunnable.run();
                return;
            }
        }
    });
}
 
Example #24
Source File: NotificationService.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Chrome and starts the browser process if it's not running as of yet, and
 * dispatch |intent| to the NotificationPlatformBridge once this is done.
 *
 * @param intent The intent containing the notification's information.
 */
@SuppressFBWarnings("DM_EXIT")
private void dispatchIntentOnUIThread(Intent intent) {
    try {
        ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup();

        // Warm up the WebappRegistry, as we need to check if this notification should launch a
        // standalone web app. This no-ops if the registry is already initialized and warmed,
        // but triggers a strict mode violation otherwise (i.e. the browser isn't running).
        // Temporarily disable strict mode to work around the violation.
        StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
        try {
            WebappRegistry.getInstance();
            WebappRegistry.warmUpSharedPrefs();
        } finally {
            StrictMode.setThreadPolicy(oldPolicy);
        }

        // Now that the browser process is initialized, we pass forward the call to the
        // NotificationPlatformBridge which will take care of delivering the appropriate events.
        if (!NotificationPlatformBridge.dispatchNotificationEvent(intent)) {
            Log.w(TAG, "Unable to dispatch the notification event to Chrome.");
        }

        // TODO(peter): Verify that the lifetime of the NotificationService is sufficient
        // when a notification event could be dispatched successfully.

    } catch (ProcessInitException e) {
        Log.e(TAG, "Unable to start the browser process.", e);
        System.exit(-1);
    }
}
 
Example #25
Source File: SupervisedUserContentProvider.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private long getSupervisedUserContentProvider() throws ProcessInitException {
    mChromeAlreadyStarted = LibraryLoader.isInitialized();
    if (mNativeSupervisedUserContentProvider != 0) {
        return mNativeSupervisedUserContentProvider;
    }

    ChromeBrowserInitializer.getInstance(getContext()).handleSynchronousStartup();

    mNativeSupervisedUserContentProvider = nativeCreateSupervisedUserContentProvider();
    return mNativeSupervisedUserContentProvider;
}
 
Example #26
Source File: FirstRunActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void initializeBrowserProcess() {
    // The Chrome browser process must be started here because this Activity
    // may be started explicitly for tests cases, from Android notifications or
    // when the application is restoring a FRE fragment after Chrome being killed.
    // This should happen before super.onCreate() because it might recreate a fragment,
    // and a fragment might depend on the native library.
    try {
        ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup();
        mNativeSideIsInitialized = true;
    } catch (ProcessInitException e) {
        Log.e(TAG, "Unable to load native library.", e);
        abortFirstRunExperience();
        return;
    }
}
 
Example #27
Source File: ChromeBackupAgent.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
protected boolean initializeBrowser(Context context) {
    try {
        ChromeBrowserInitializer.getInstance(context).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.w(TAG, "Browser launch failed on restore: " + e);
        return false;
    }
    return true;
}
 
Example #28
Source File: AccountsChangedReceiver.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@SuppressFBWarnings("DM_EXIT")
private static void startBrowserIfNeededAndValidateAccounts(final Context context) {
    BrowserParts parts = new EmptyBrowserParts() {
        @Override
        public void finishNativeInitialization() {
            ThreadUtils.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    SigninHelper.get(context).validateAccountSettings(true);
                }
            });
        }

        @Override
        public void onStartupFailure() {
            // Startup failed. So notify SigninHelper of changed accounts via
            // shared prefs.
            SigninHelper.markAccountsChangedPref(context);
        }
    };
    try {
        ChromeBrowserInitializer.getInstance(context).handlePreNativeStartup(parts);
        ChromeBrowserInitializer.getInstance(context).handlePostNativeStartup(true, parts);
    } catch (ProcessInitException e) {
        Log.e(TAG, "Unable to load native library.", e);
        ChromeApplication.reportStartupErrorAndExit(e);
    }
}
 
Example #29
Source File: FirstRunActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
private void initializeBrowserProcess() {
    // The Chrome browser process must be started here because this Activity
    // may be started explicitly for tests cases, from Android notifications or
    // when the application is restoring a FRE fragment after Chrome being killed.
    // This should happen before super.onCreate() because it might recreate a fragment,
    // and a fragment might depend on the native library.
    try {
        ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup();
        mNativeSideIsInitialized = true;
    } catch (ProcessInitException e) {
        Log.e(TAG, "Unable to load native library.", e);
        abortFirstRunExperience();
        return;
    }
}
 
Example #30
Source File: SupervisedUserContentProvider.java    From delion with Apache License 2.0 5 votes vote down vote up
private long getSupervisedUserContentProvider() throws ProcessInitException {
    if (mNativeSupervisedUserContentProvider != 0) {
        return mNativeSupervisedUserContentProvider;
    }

    ChromeBrowserInitializer.getInstance(getContext()).handleSynchronousStartup();

    mNativeSupervisedUserContentProvider = nativeCreateSupervisedUserContentProvider();
    return mNativeSupervisedUserContentProvider;
}