org.chromium.content.browser.BrowserStartupController Java Examples

The following examples show how to use org.chromium.content.browser.BrowserStartupController. 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: ChromeBrowserInitializer.java    From delion with Apache License 2.0 6 votes vote down vote up
private void startChromeBrowserProcessesSync() throws ProcessInitException {
    try {
        TraceEvent.begin("ChromeBrowserInitializer.startChromeBrowserProcessesSync");
        ThreadUtils.assertOnUiThread();
        mApplication.initCommandLine();
        LibraryLoader libraryLoader = LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER);
        StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
        libraryLoader.ensureInitialized(mApplication);
        StrictMode.setThreadPolicy(oldPolicy);
        libraryLoader.asyncPrefetchLibrariesToMemory();
        // The policies are used by browser startup, so we need to register the policy providers
        // before starting the browser process.
        mApplication.registerPolicyProviders(CombinedPolicyProvider.get());
        BrowserStartupController.get(mApplication, LibraryProcessType.PROCESS_BROWSER)
                .startBrowserProcessesSync(false);
        GoogleServicesManager.get(mApplication);
    } finally {
        TraceEvent.end("ChromeBrowserInitializer.startChromeBrowserProcessesSync");
    }
}
 
Example #2
Source File: ChromiumSyncAdapter.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void startBrowserProcessesSync(
        final BrowserStartupController.StartupCallback callback) {
    if (BrowserStartupController.get(mApplication).startBrowserProcessesSync(
            BrowserStartupController.MAX_RENDERERS_LIMIT)) {
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                callback.onSuccess(false);
            }
        });
    } else {
        Log.e(TAG, "Unable to start browser process.");
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                callback.onFailure();
            }
        });
    }
}
 
Example #3
Source File: ChromiumSyncAdapter.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void startBrowserProcess(
        final BrowserStartupController.StartupCallback callback,
        final SyncResult syncResult, Semaphore semaphore) {
    try {
        ThreadUtils.runOnUiThreadBlocking(new Runnable() {
            @Override
            public void run() {
                initCommandLine();
                if (mAsyncStartup) {
                    BrowserStartupController.get(mApplication)
                            .startBrowserProcessesAsync(callback);
                } else {
                    startBrowserProcessesSync(callback);
                }
            }
        });
    } catch (RuntimeException e) {
        // It is still unknown why we ever experience this. See http://crbug.com/180044.
        Log.w(TAG, "Got exception when trying to request a sync. Informing Android system.", e);
        // Using numIoExceptions so Android will treat this as a soft error.
        syncResult.stats.numIoExceptions++;
        semaphore.release();
    }
}
 
Example #4
Source File: ChromiumSyncAdapter.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
                          ContentProviderClient provider, SyncResult syncResult) {
    if (!DelayedSyncController.getInstance().shouldPerformSync(getContext(), extras, account)) {
        return;
    }

    // Browser startup is asynchronous, so we will need to wait for startup to finish.
    Semaphore semaphore = new Semaphore(0);

    // Configure the callback with all the data it needs.
    BrowserStartupController.StartupCallback callback =
            getStartupCallback(mApplication, account, extras, syncResult, semaphore);
    startBrowserProcess(callback, syncResult, semaphore);

    try {
        // Wait for startup to complete.
        semaphore.acquire();
    } catch (InterruptedException e) {
        Log.w(TAG, "Got InterruptedException when trying to request a sync.", e);
        // Using numIoExceptions so Android will treat this as a soft error.
        syncResult.stats.numIoExceptions++;
    }
}
 
Example #5
Source File: AccountsChangedReceiver.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void onReceive(final Context context, Intent intent) {
    if (AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION.equals(intent.getAction())) {
        final Account signedInUser =
                ChromeSigninController.get(context).getSignedInUser();
        if (signedInUser != null) {
            BrowserStartupController.StartupCallback callback =
                    new BrowserStartupController.StartupCallback() {
                @Override
                public void onSuccess(boolean alreadyStarted) {
                    OAuth2TokenService.getForProfile(Profile.getLastUsedProfile())
                            .validateAccounts(context);
                }

                @Override
                public void onFailure() {
                    Log.w(TAG, "Failed to start browser process.");
                }
            };
            startBrowserProcessOnUiThread(context, callback);
        }
    }
}
 
Example #6
Source File: ChromiumSyncAdapter.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void startBrowserProcessesSync(
        final BrowserStartupController.StartupCallback callback) {
    if (BrowserStartupController.get(mApplication).startBrowserProcessesSync(
            BrowserStartupController.MAX_RENDERERS_LIMIT)) {
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                callback.onSuccess(false);
            }
        });
    } else {
        Log.e(TAG, "Unable to start browser process.");
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                callback.onFailure();
            }
        });
    }
}
 
Example #7
Source File: ChromiumSyncAdapter.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void startBrowserProcess(
        final BrowserStartupController.StartupCallback callback,
        final SyncResult syncResult, Semaphore semaphore) {
    try {
        ThreadUtils.runOnUiThreadBlocking(new Runnable() {
            @Override
            public void run() {
                initCommandLine();
                if (mAsyncStartup) {
                    BrowserStartupController.get(mApplication)
                            .startBrowserProcessesAsync(callback);
                } else {
                    startBrowserProcessesSync(callback);
                }
            }
        });
    } catch (RuntimeException e) {
        // It is still unknown why we ever experience this. See http://crbug.com/180044.
        Log.w(TAG, "Got exception when trying to request a sync. Informing Android system.", e);
        // Using numIoExceptions so Android will treat this as a soft error.
        syncResult.stats.numIoExceptions++;
        semaphore.release();
    }
}
 
Example #8
Source File: ChromiumSyncAdapter.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
                          ContentProviderClient provider, SyncResult syncResult) {
    if (!DelayedSyncController.getInstance().shouldPerformSync(getContext(), extras, account)) {
        return;
    }

    // Browser startup is asynchronous, so we will need to wait for startup to finish.
    Semaphore semaphore = new Semaphore(0);

    // Configure the callback with all the data it needs.
    BrowserStartupController.StartupCallback callback =
            getStartupCallback(mApplication, account, extras, syncResult, semaphore);
    startBrowserProcess(callback, syncResult, semaphore);

    try {
        // Wait for startup to complete.
        semaphore.acquire();
    } catch (InterruptedException e) {
        Log.w(TAG, "Got InterruptedException when trying to request a sync.", e);
        // Using numIoExceptions so Android will treat this as a soft error.
        syncResult.stats.numIoExceptions++;
    }
}
 
Example #9
Source File: AccountsChangedReceiver.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void onReceive(final Context context, Intent intent) {
    if (AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION.equals(intent.getAction())) {
        final Account signedInUser =
                ChromeSigninController.get(context).getSignedInUser();
        if (signedInUser != null) {
            BrowserStartupController.StartupCallback callback =
                    new BrowserStartupController.StartupCallback() {
                @Override
                public void onSuccess(boolean alreadyStarted) {
                    OAuth2TokenService.getForProfile(Profile.getLastUsedProfile())
                            .validateAccounts(context);
                }

                @Override
                public void onFailure() {
                    Log.w(TAG, "Failed to start browser process.");
                }
            };
            startBrowserProcessOnUiThread(context, callback);
        }
    }
}
 
Example #10
Source File: ChromeBrowserProvider.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreate() {
    // Work around for broken Android versions that break the Android contract and initialize
    // ContentProviders on non-UI threads.  crbug.com/705442
    ThreadUtils.runOnUiThreadBlocking(new Runnable() {
        @Override
        public void run() {
            ContentApplication.initCommandLine(getContext());

            BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER)
                    .addStartupCompletedObserver(
                            new BrowserStartupController.StartupCallback() {
                                @Override
                                public void onSuccess(boolean alreadyStarted) {
                                    ensureNativeSideInitialized();
                                }

                                @Override
                                public void onFailure() {
                                }
                            });
        }
    });

    return true;
}
 
Example #11
Source File: GcmUma.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private static void onNativeLaunched(final Context context, final Runnable task) {
    ThreadUtils.postOnUiThread(new Runnable() {
        @Override
        public void run() {
            BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER)
                    .addStartupCompletedObserver(
                            new StartupCallback() {
                                @Override
                                public void onSuccess(boolean alreadyStarted) {
                                    task.run();
                                }

                                @Override
                                public void onFailure() {
                                    // Startup failed.
                                }
                            });
        }
    });
}
 
Example #12
Source File: AccountsChangedReceiver.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private static void notifyAccountsChangedOnBrowserStartup(final Context context) {
    StartupCallback notifyAccountsChangedCallback = new StartupCallback() {
        @Override
        public void onSuccess(boolean alreadyStarted) {
            for (AccountsChangedObserver observer : sObservers) {
                observer.onAccountsChanged();
            }
        }

        @Override
        public void onFailure() {
            // Startup failed, so ignore call.
        }
    };
    // If the browser process has already been loaded, a task will be posted immediately to
    // call the |notifyAccountsChangedCallback| passed in as a parameter.
    BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER)
            .addStartupCompletedObserver(notifyAccountsChangedCallback);
}
 
Example #13
Source File: UrlManager.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Register a StartupCallback to initialize the native portion of the JNI bridge.
 */
private void registerNativeInitStartupCallback() {
    ThreadUtils.postOnUiThread(new Runnable() {
        @Override
        public void run() {
            BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER)
                    .addStartupCompletedObserver(new StartupCallback() {
                        @Override
                        public void onSuccess(boolean alreadyStarted) {
                            mNativePhysicalWebDataSourceAndroid = nativeInit();
                            for (UrlInfo urlInfo : getUrls()) {
                                safeNotifyNativeListenersOnFound(urlInfo.getUrl());
                            }
                        }

                        @Override
                        public void onFailure() {
                            // Startup failed.
                        }
                    });
        }
    });
}
 
Example #14
Source File: DownloadNotificationService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
void cancelOffTheRecordDownloads() {
    boolean cancelActualDownload =
            BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER)
                    .isStartupSuccessfullyCompleted()
            && Profile.getLastUsedProfile().hasOffTheRecordProfile();

    List<DownloadSharedPreferenceEntry> entries = mDownloadSharedPreferenceHelper.getEntries();
    List<DownloadSharedPreferenceEntry> copies =
            new ArrayList<DownloadSharedPreferenceEntry>(entries);
    for (DownloadSharedPreferenceEntry entry : copies) {
        if (!entry.isOffTheRecord) continue;
        ContentId id = entry.id;
        notifyDownloadCanceled(id);
        if (cancelActualDownload) {
            DownloadServiceDelegate delegate = getServiceDelegate(id);
            delegate.cancelDownload(id, true);
            delegate.destroyServiceDelegate();
        }
        for (Observer observer : mObservers) observer.onDownloadCanceled(id);
    }
}
 
Example #15
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 #16
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 #17
Source File: ChromeBrowserInitializer.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void startChromeBrowserProcessesSync() throws ProcessInitException {
    try {
        TraceEvent.begin("ChromeBrowserInitializer.startChromeBrowserProcessesSync");
        ThreadUtils.assertOnUiThread();
        mApplication.initCommandLine();
        LibraryLoader libraryLoader = LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER);
        StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
        libraryLoader.ensureInitialized();
        StrictMode.setThreadPolicy(oldPolicy);
        libraryLoader.asyncPrefetchLibrariesToMemory();
        BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER)
                .startBrowserProcessesSync(false);
        GoogleServicesManager.get(mApplication);
    } finally {
        TraceEvent.end("ChromeBrowserInitializer.startChromeBrowserProcessesSync");
    }
}
 
Example #18
Source File: ChromeBrowserProvider.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreate() {
    ContentApplication.initCommandLine(getContext());

    BrowserStartupController.get(getContext(), LibraryProcessType.PROCESS_BROWSER)
            .addStartupCompletedObserver(
                    new BrowserStartupController.StartupCallback() {
                        @Override
                        public void onSuccess(boolean alreadyStarted) {
                            ensureNativeSideInitialized();
                        }

                        @Override
                        public void onFailure() {
                        }
                    });

    return true;
}
 
Example #19
Source File: GcmUma.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private static void onNativeLaunched(final Context context, final Runnable task) {
    ThreadUtils.postOnUiThread(new Runnable() {
        @Override
        public void run() {
            BrowserStartupController.get(context, LibraryProcessType.PROCESS_BROWSER)
                    .addStartupCompletedObserver(
                            new StartupCallback() {
                                @Override
                                public void onSuccess(boolean alreadyStarted) {
                                    task.run();
                                }

                                @Override
                                public void onFailure() {
                                    // Startup failed.
                                }
                            });
        }
    });
}
 
Example #20
Source File: AccountsChangedReceiver.java    From delion with Apache License 2.0 6 votes vote down vote up
private static void notifyAccountsChangedOnBrowserStartup(
        final Context context, final Intent intent) {
    StartupCallback notifyAccountsChangedCallback = new StartupCallback() {
        @Override
        public void onSuccess(boolean alreadyStarted) {
            for (AccountsChangedObserver observer : sObservers) {
                observer.onAccountsChanged(context, intent);
            }
        }

        @Override
        public void onFailure() {
            // Startup failed, so ignore call.
        }
    };
    // If the browser process has already been loaded, a task will be posted immediately to
    // call the |notifyAccountsChangedCallback| passed in as a parameter.
    BrowserStartupController.get(context, LibraryProcessType.PROCESS_BROWSER)
            .addStartupCompletedObserver(notifyAccountsChangedCallback);
}
 
Example #21
Source File: AccountsChangedReceiver.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private static void notifyAccountsChangedOnBrowserStartup(
        final Context context, final Intent intent) {
    StartupCallback notifyAccountsChangedCallback = new StartupCallback() {
        @Override
        public void onSuccess(boolean alreadyStarted) {
            for (AccountsChangedObserver observer : sObservers) {
                observer.onAccountsChanged(context, intent);
            }
        }

        @Override
        public void onFailure() {
            // Startup failed, so ignore call.
        }
    };
    // If the browser process has already been loaded, a task will be posted immediately to
    // call the |notifyAccountsChangedCallback| passed in as a parameter.
    BrowserStartupController.get(context, LibraryProcessType.PROCESS_BROWSER)
            .addStartupCompletedObserver(notifyAccountsChangedCallback);
}
 
Example #22
Source File: GcmUma.java    From delion with Apache License 2.0 6 votes vote down vote up
private static void onNativeLaunched(final Context context, final Runnable task) {
    ThreadUtils.postOnUiThread(new Runnable() {
        @Override
        public void run() {
            BrowserStartupController.get(context, LibraryProcessType.PROCESS_BROWSER)
                    .addStartupCompletedObserver(
                            new StartupCallback() {
                                @Override
                                public void onSuccess(boolean alreadyStarted) {
                                    task.run();
                                }

                                @Override
                                public void onFailure() {
                                    // Startup failed.
                                }
                            });
        }
    });
}
 
Example #23
Source File: UrlManager.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Register a StartupCallback to initialize the native portion of the JNI bridge.
 */
private void registerNativeInitStartupCallback() {
    ThreadUtils.postOnUiThread(new Runnable() {
        @Override
        public void run() {
            BrowserStartupController.get(mContext, LibraryProcessType.PROCESS_BROWSER)
                    .addStartupCompletedObserver(new StartupCallback() {
                        @Override
                        public void onSuccess(boolean alreadyStarted) {
                            mNativePhysicalWebDataSourceAndroid = nativeInit();
                        }

                        @Override
                        public void onFailure() {
                            // Startup failed.
                        }
                    });
        }
    });
}
 
Example #24
Source File: ChromeBrowserInitializer.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void startChromeBrowserProcessesSync() throws ProcessInitException {
    try {
        TraceEvent.begin("ChromeBrowserInitializer.startChromeBrowserProcessesSync");
        ThreadUtils.assertOnUiThread();
        mApplication.initCommandLine();
        LibraryLoader libraryLoader = LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER);
        StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
        libraryLoader.ensureInitialized();
        StrictMode.setThreadPolicy(oldPolicy);
        libraryLoader.asyncPrefetchLibrariesToMemory();
        BrowserStartupController.get(mApplication, LibraryProcessType.PROCESS_BROWSER)
                .startBrowserProcessesSync(false);
        GoogleServicesManager.get(mApplication);
    } finally {
        TraceEvent.end("ChromeBrowserInitializer.startChromeBrowserProcessesSync");
    }
}
 
Example #25
Source File: ChromeBrowserProvider.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
    public boolean onCreate() {
//        ContentApplication.initCommandLine(getContext());

        BrowserStartupController.get(getContext(), LibraryProcessType.PROCESS_BROWSER)
                .addStartupCompletedObserver(
                        new BrowserStartupController.StartupCallback() {
                            @Override
                            public void onSuccess(boolean alreadyStarted) {
                                ensureNativeSideInitialized();
                            }

                            @Override
                            public void onFailure() {
                            }
                        });

        return true;
    }
 
Example #26
Source File: DownloadNotificationService.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Checks to see if the summary notification is alone and, if so, hides it.  If the summary
 * notification thinks it's in the foreground, this will start the service with the goal of
 * shutting it down.  That is because if the service is in the foreground it's not possible to
 * stop it through the notification manager.
 * @param removedNotificationId The id of the notification that was just removed or {@code -1}
 *                              if this does not apply.
 */
@TargetApi(Build.VERSION_CODES.M)
public static void hideDanglingSummaryNotification(Context context, int removedNotificationId) {
    if (!useForegroundService()) return;

    NotificationManager manager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    if (hasDownloadNotifications(manager, removedNotificationId)) return;

    StatusBarNotification summary = getSummaryNotification(manager);
    if (summary == null) return;

    boolean isForeground =
            (summary.getNotification().flags & Notification.FLAG_FOREGROUND_SERVICE) != 0;

    if (BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER)
                    .isStartupSuccessfullyCompleted()) {
        RecordHistogram.recordBooleanHistogram(
                "MobileDownload.Notification.FixingSummaryLeak", isForeground);
    }

    if (isForeground) {
        // If it is a foreground notification, we are in a bad state.  We don't have any
        // other download notifications, but we can't close the summary.  Try to start
        // up the service and quit through that path?
        startDownloadNotificationService(context, new Intent(ACTION_DOWNLOAD_FAIL_SAFE));
    } else {
        manager.cancel(NotificationConstants.NOTIFICATION_ID_DOWNLOAD_SUMMARY);
    }
}
 
Example #27
Source File: AwBrowserProcess.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Starts the chromium browser process running within this process. Creates threads
 * and performs other per-app resource allocations; must not be called from zygote.
 * Note: it is up to the caller to ensure this is only called once.
 * @param context The Android application context
 */
public static void start(final Context context) {
    // We must post to the UI thread to cover the case that the user
    // has invoked Chromium startup by using the (thread-safe)
    // CookieManager rather than creating a WebView.
    ThreadUtils.runOnUiThreadBlocking(new Runnable() {
        @Override
        public void run() {
            if( !BrowserStartupController.get(context).startBrowserProcessesSync(
                        BrowserStartupController.MAX_RENDERERS_SINGLE_PROCESS)) {
                throw new RuntimeException("Cannot initialize WebView");
            }
        }
    });
}
 
Example #28
Source File: ChromiumSyncAdapter.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private BrowserStartupController.StartupCallback getStartupCallback(
        final Context context, final Account acct, Bundle extras,
        final SyncResult syncResult, final Semaphore semaphore) {
    final boolean syncAllTypes = extras.getString(INVALIDATION_OBJECT_ID_KEY) == null;
    final int objectSource = syncAllTypes ? 0 : extras.getInt(INVALIDATION_OBJECT_SOURCE_KEY);
    final String objectId = syncAllTypes ? "" : extras.getString(INVALIDATION_OBJECT_ID_KEY);
    final long version = syncAllTypes ? 0 : extras.getLong(INVALIDATION_VERSION_KEY);
    final String payload = syncAllTypes ? "" : extras.getString(INVALIDATION_PAYLOAD_KEY);

    return new BrowserStartupController.StartupCallback() {
        @Override
        public void onSuccess(boolean alreadyStarted) {
            // Startup succeeded, so we can tickle the sync engine.
            if (syncAllTypes) {
                Log.v(TAG, "Received sync tickle for all types.");
                requestSyncForAllTypes();
            } else {
                // Invalidations persisted before objectSource was added should be assumed to be
                // for Sync objects. TODO(stepco): Remove this check once all persisted
                // invalidations can be expected to have the objectSource.
                int resolvedSource = objectSource;
                if (resolvedSource == 0) {
                  resolvedSource = Types.ObjectSource.Type.CHROME_SYNC.getNumber();
                }
                Log.v(TAG, "Received sync tickle for " + resolvedSource + " " + objectId + ".");
                requestSync(resolvedSource, objectId, version, payload);
            }
            semaphore.release();
        }

        @Override
        public void onFailure() {
            // The startup failed, so we reset the delayed sync state.
            DelayedSyncController.getInstance().setDelayedSync(context, acct.name);
            // Using numIoExceptions so Android will treat this as a soft error.
            syncResult.stats.numIoExceptions++;
            semaphore.release();
        }
    };
}
 
Example #29
Source File: ChromeBrowserInitializer.java    From delion with Apache License 2.0 5 votes vote down vote up
private void startChromeBrowserProcessesAsync(
        boolean startGpuProcess,
        BrowserStartupController.StartupCallback callback) throws ProcessInitException {
    try {
        TraceEvent.begin("ChromeBrowserInitializer.startChromeBrowserProcessesAsync");
        mApplication.registerPolicyProviders(CombinedPolicyProvider.get());
        BrowserStartupController.get(mApplication, LibraryProcessType.PROCESS_BROWSER)
                .startBrowserProcessesAsync(startGpuProcess, callback);
    } finally {
        TraceEvent.end("ChromeBrowserInitializer.startChromeBrowserProcessesAsync");
    }
}
 
Example #30
Source File: AccountsChangedReceiver.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static void startBrowserProcessOnUiThread(final Context context,
        final BrowserStartupController.StartupCallback callback) {
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            BrowserStartupController.get(context).startBrowserProcessesAsync(callback);
        }
    });
}