Java Code Examples for org.chromium.base.ThreadUtils#assertOnUiThread()

The following examples show how to use org.chromium.base.ThreadUtils#assertOnUiThread() . 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: CustomTabsConnection.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * High confidence mayLaunchUrl() call, that is:
 * - Tries to prerender if possible.
 * - An empty URL cancels the current prerender if any.
 * - If prerendering is not possible, makes sure that there is a spare renderer.
 */
private void highConfidenceMayLaunchUrl(CustomTabsSessionToken session,
        int uid, String url, Bundle extras, List<Bundle> otherLikelyBundles) {
    ThreadUtils.assertOnUiThread();
    if (TextUtils.isEmpty(url)) {
        cancelPrerender(session);
        return;
    }
    url = DataReductionProxySettings.getInstance().maybeRewriteWebliteUrl(url);
    boolean noPrerendering =
            extras != null ? extras.getBoolean(NO_PRERENDERING_KEY, false) : false;
    WarmupManager.getInstance().maybePreconnectUrlAndSubResources(
            Profile.getLastUsedProfile(), url);
    boolean didStartPrerender = false;
    if (!noPrerendering && mayPrerender(session)) {
        didStartPrerender = prerenderUrl(session, url, extras, uid);
    }
    preconnectUrls(otherLikelyBundles);
    if (!didStartPrerender) createSpareWebContents();
}
 
Example 2
Source File: ChromeActivitySessionTracker.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Each top-level activity (those extending {@link ChromeActivity}) should call this during
 * its onStart phase. When called for the first time, this marks the beginning of a foreground
 * session and calls onForegroundSessionStart(). Subsequent calls are noops until
 * onForegroundSessionEnd() is called, to handle changing top-level Chrome activities in one
 * foreground session.
 */
public void onStartWithNative() {
    ThreadUtils.assertOnUiThread();

    if (mIsStarted) return;
    mIsStarted = true;

    assert mIsInitialized;

    onForegroundSessionStart();
    cacheNativeFlags();
}
 
Example 3
Source File: TemplateUrlService.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public static TemplateUrlService getInstance() {
    ThreadUtils.assertOnUiThread();
    if (sService == null) {
        sService = new TemplateUrlService();
    }
    return sService;
}
 
Example 4
Source File: ActivityAssigner.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the singleton instance, creating it if necessary.
 * @param namespace The namespace of the Activities being assigned.
 */
public static ActivityAssigner instance(@ActivityAssignerNamespace int namespace) {
    ThreadUtils.assertOnUiThread();
    synchronized (LOCK) {
        if (sInstances == null) {
            sInstances = new ArrayList<ActivityAssigner>(NAMESPACE_COUNT);
            for (int i = 0; i < NAMESPACE_COUNT; ++i) {
                sInstances.add(new ActivityAssigner(i));
            }
        }
    }
    return sInstances.get(namespace);
}
 
Example 5
Source File: DocumentModeAssassin.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the stage of the migration.
 * @param expectedStage Stage of the pipeline that is currently expected.
 * @param newStage      Stage of the pipeline that is being activated.
 * @return Whether or not the stage was updated.
 */
private final boolean setStage(int expectedStage, int newStage) {
    ThreadUtils.assertOnUiThread();

    if (mStage != expectedStage) {
        Log.e(TAG, "Wrong stage encountered: expected " + expectedStage + " but in " + mStage);
        return false;
    }
    mStage = newStage;

    for (DocumentModeAssassinObserver callback : mObservers) callback.onStageChange(newStage);
    startStage(newStage);
    return true;
}
 
Example 6
Source File: IncognitoTabModel.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures that the real TabModel has been created.
 */
protected void ensureTabModelImpl() {
    ThreadUtils.assertOnUiThread();
    if (!(mDelegateModel instanceof EmptyTabModel)) return;

    IncognitoNotificationManager.showIncognitoNotification();
    mDelegateModel = mDelegate.createTabModel();
    for (TabModelObserver observer : mObservers) {
        mDelegateModel.addObserver(observer);
    }
}
 
Example 7
Source File: BatteryMonitorFactory.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public BatteryMonitor createImpl() {
    ThreadUtils.assertOnUiThread();

    if (mSubscribedMonitors.isEmpty() && !mManager.start()) {
        Log.e(TAG, "BatteryStatusManager failed to start.");
    }
    // TODO(ppi): record the "BatteryStatus.StartAndroid" histogram here once we have a Java API
    //            for UMA - http://crbug.com/442300.

    BatteryMonitorImpl monitor = new BatteryMonitorImpl(this);
    mSubscribedMonitors.add(monitor);
    return monitor;
}
 
Example 8
Source File: OfflinePageBridge.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * @return True if saving offline pages in the background is enabled.
 */
@VisibleForTesting
public static boolean isBackgroundLoadingEnabled() {
    ThreadUtils.assertOnUiThread();
    if (sBackgroundLoadingEnabled == null) {
        sBackgroundLoadingEnabled = nativeIsBackgroundLoadingEnabled();
    }
    return sBackgroundLoadingEnabled;
}
 
Example 9
Source File: OfflinePageBridge.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * @return True if offline pages feature is enabled.
 */
public static boolean isOfflinePagesEnabled() {
    ThreadUtils.assertOnUiThread();
    if (sOfflinePagesEnabled == null) {
        sOfflinePagesEnabled = nativeIsOfflinePagesEnabled();
    }
    return sOfflinePagesEnabled;
}
 
Example 10
Source File: FeedbackCollector.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void maybePostResult() {
    ThreadUtils.assertOnUiThread();
    if (mCallback == null) return;
    if (mResultPosted) return;
    if (shouldWaitForScreenshot() || shouldWaitForConnectivityTask()) return;

    mResultPosted = true;
    ThreadUtils.postOnUiThread(new Runnable() {
        @Override
        public void run() {
            mCallback.onResult(FeedbackCollector.this);
        }
    });
}
 
Example 11
Source File: DownloadManagerService.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * For tests only: sets the DownloadManagerService.
 * @param service An instance of DownloadManagerService.
 * @return Null or a currently set instance of DownloadManagerService.
 */
@VisibleForTesting
public static DownloadManagerService setDownloadManagerService(DownloadManagerService service) {
    ThreadUtils.assertOnUiThread();
    DownloadManagerService prev = sDownloadManagerService;
    sDownloadManagerService = service;
    return prev;
}
 
Example 12
Source File: PersonalDataManager.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public CreditCard getCreditCard(String guid) {
    ThreadUtils.assertOnUiThread();
    return nativeGetCreditCardByGUID(mPersonalDataManagerAndroid, guid);
}
 
Example 13
Source File: ContentSettingsResources.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes and returns the map. Only initializes it the first time it's needed.
 */
private static Map<Integer, ResourceItem> getResourceInfo() {
    ThreadUtils.assertOnUiThread();
    if (sResourceInfo == null) {
        Map<Integer, ResourceItem> localMap = new HashMap<Integer, ResourceItem>();
        localMap.put(ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOPLAY,
                new ResourceItem(R.drawable.settings_autoplay, R.string.autoplay_title,
                             R.string.autoplay_title, ContentSetting.ALLOW,
                             ContentSetting.BLOCK,
                             R.string.website_settings_category_autoplay_allowed, 0));
        localMap.put(ContentSettingsType.CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC,
                new ResourceItem(R.drawable.permission_background_sync,
                             R.string.background_sync_permission_title,
                             R.string.background_sync_permission_title, ContentSetting.ALLOW,
                             ContentSetting.BLOCK,
                             R.string.website_settings_category_allowed_recommended, 0));
        localMap.put(ContentSettingsType.CONTENT_SETTINGS_TYPE_COOKIES,
                new ResourceItem(R.drawable.permission_cookie, R.string.cookies_title,
                             R.string.cookies_title, ContentSetting.ALLOW, ContentSetting.BLOCK,
                             R.string.website_settings_category_cookie_allowed, 0));
        localMap.put(ContentSettingsType.CONTENT_SETTINGS_TYPE_GEOLOCATION,
                new ResourceItem(R.drawable.permission_location,
                             R.string.website_settings_device_location,
                             R.string.geolocation_permission_title, ContentSetting.ASK,
                             ContentSetting.BLOCK,
                             R.string.website_settings_category_location_ask, 0));
        localMap.put(ContentSettingsType.CONTENT_SETTINGS_TYPE_JAVASCRIPT,
                new ResourceItem(R.drawable.permission_javascript,
                             R.string.javascript_permission_title,
                             R.string.javascript_permission_title, ContentSetting.ALLOW,
                             ContentSetting.BLOCK,
                             R.string.website_settings_category_javascript_allowed, 0));
        localMap.put(ContentSettingsType.CONTENT_SETTINGS_TYPE_KEYGEN,
                new ResourceItem(R.drawable.permission_keygen,
                             R.string.keygen_permission_title,
                             R.string.keygen_permission_title, ContentSetting.ALLOW,
                             ContentSetting.BLOCK,
                             0, R.string.website_settings_category_blocked_recommended));
        localMap.put(
                ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
                new ResourceItem(R.drawable.permission_camera,
                        R.string.website_settings_use_camera, R.string.camera_permission_title,
                        ContentSetting.ASK, ContentSetting.BLOCK,
                        R.string.website_settings_category_camera_ask, 0));
        localMap.put(
                ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
                new ResourceItem(R.drawable.permission_mic, R.string.website_settings_use_mic,
                        R.string.mic_permission_title, ContentSetting.ASK, ContentSetting.BLOCK,
                        R.string.website_settings_category_mic_ask, 0));
        localMap.put(ContentSettingsType.CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
                new ResourceItem(R.drawable.permission_midi, 0,
                             R.string.midi_sysex_permission_title, null, null, 0, 0));
        localMap.put(ContentSettingsType.CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
                new ResourceItem(R.drawable.permission_push_notification,
                             R.string.push_notifications_permission_title,
                             R.string.push_notifications_permission_title, ContentSetting.ASK,
                             ContentSetting.BLOCK,
                             R.string.website_settings_category_notifications_ask, 0));
        localMap.put(ContentSettingsType.CONTENT_SETTINGS_TYPE_POPUPS,
                new ResourceItem(R.drawable.permission_popups, R.string.popup_permission_title,
                             R.string.popup_permission_title, ContentSetting.ALLOW,
                             ContentSetting.BLOCK, 0,
                             R.string.website_settings_category_popups_blocked));
        localMap.put(ContentSettingsType.CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER,
                new ResourceItem(R.drawable.permission_protected_media,
                             org.chromium.chrome.R.string.protected_content,
                             org.chromium.chrome.R.string.protected_content,
                             ContentSetting.ASK, ContentSetting.BLOCK, 0, 0));
        localMap.put(ContentSettingsType.CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA,
                new ResourceItem(R.drawable.settings_usb, 0, 0, ContentSetting.ASK,
                             ContentSetting.BLOCK, 0, 0));
        sResourceInfo = localMap;
    }
    return sResourceInfo;
}
 
Example 14
Source File: ProfileSyncService.java    From delion with Apache License 2.0 4 votes vote down vote up
public void removeSyncStateChangedListener(SyncStateChangedListener listener) {
    ThreadUtils.assertOnUiThread();
    mListeners.remove(listener);
}
 
Example 15
Source File: BrowserStartupController.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * @return Whether the browser process completed successfully.
 */
public boolean isStartupSuccessfullyCompleted() {
    ThreadUtils.assertOnUiThread();
    return mStartupDone && mStartupSuccess;
}
 
Example 16
Source File: ContentSettings.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Return true if JavaScript is enabled. Must be called on the UI thread.
 *
 * @return True if JavaScript is enabled.
 */
public boolean getJavaScriptEnabled() {
    ThreadUtils.assertOnUiThread();
    return mNativeContentSettings != 0 ?
            nativeGetJavaScriptEnabled(mNativeContentSettings) : false;
}
 
Example 17
Source File: PersonalDataManager.java    From 365browser with Apache License 2.0 4 votes vote down vote up
public void updateServerCardBillingAddress(CreditCard card) {
    ThreadUtils.assertOnUiThread();
    nativeUpdateServerCardBillingAddress(mPersonalDataManagerAndroid, card);
}
 
Example 18
Source File: PersonalDataManager.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
public void deleteProfile(String guid) {
    ThreadUtils.assertOnUiThread();
    nativeRemoveByGUID(mPersonalDataManagerAndroid, guid);
}
 
Example 19
Source File: UserRecoverableErrorHandler.java    From 365browser with Apache License 2.0 2 votes vote down vote up
/**
 * Handles the specified error code from Google Play Services.
 * This method must only be called on the UI thread.
 * This method asserts that it is being called on the UI thread, then calls
 * {@link #handle(Context, int)}.
 * @param context the context in which the error was encountered
 * @param errorCode the error code from Google Play Services
 */
public final void handleError(final Context context, final int errorCode) {
    ThreadUtils.assertOnUiThread();
    handle(context, errorCode);
}
 
Example 20
Source File: FeedbackCollector.java    From AndroidChromium with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a {@link FeedbackCollector} and starts asynchronous operations to gather extra data.
 * @param profile the current Profile.
 * @param url The URL of the current tab to include in the feedback the user sends, if any.
 *            This parameter may be null.
 * @param callback The callback which is invoked when feedback gathering is finished.
 * @return the created {@link FeedbackCollector}.
 */
public static FeedbackCollector create(
        Activity activity, Profile profile, @Nullable String url, FeedbackResult callback) {
    ThreadUtils.assertOnUiThread();
    return new FeedbackCollector(activity, profile, url, callback);
}