当前位置: 首页>>代码示例>>Java>>正文


Java ThreadUtils类代码示例

本文整理汇总了Java中org.chromium.base.ThreadUtils的典型用法代码示例。如果您正苦于以下问题:Java ThreadUtils类的具体用法?Java ThreadUtils怎么用?Java ThreadUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ThreadUtils类属于org.chromium.base包,在下文中一共展示了ThreadUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: requestTokenWithoutActivity

import org.chromium.base.ThreadUtils; //导入依赖的package包/类
/**
 * Requests an authentication token. If the account is not properly setup, it will result in
 * a failure.
 *
 * @param ctx The application context
 * @param requestData The object holding the data related to the current request
 * @param features An array of the account features to require, may be null or empty
 */
private void requestTokenWithoutActivity(
        Context ctx, RequestData requestData, String[] features) {
    if (lacksPermission(ctx, Manifest.permission.GET_ACCOUNTS, true /* onlyPreM */)) {
        // Protecting the AccountManager#getAccountsByTypeAndFeatures call.
        // API  < 23 Requires the GET_ACCOUNTS permission or throws an exception.
        // API >= 23 Requires the GET_ACCOUNTS permission (CONTACTS permission group) or
        //           returns only the accounts whose authenticator has a signature that
        //           matches our app. Working with this restriction and not requesting
        //           the permission is a valid use case in the context of WebView, so we
        //           don't require it on M+
        Log.e(TAG, "ERR_MISCONFIGURED_AUTH_ENVIRONMENT: GET_ACCOUNTS permission not "
                        + "granted. Aborting authentication.");
        nativeSetResult(requestData.nativeResultObject,
                NetError.ERR_MISCONFIGURED_AUTH_ENVIRONMENT, null);
        return;
    }
    requestData.accountManager.getAccountsByTypeAndFeatures(mAccountType, features,
            new GetAccountsCallback(requestData), new Handler(ThreadUtils.getUiThreadLooper()));
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:28,代码来源:HttpNegotiateAuthenticator.java

示例2: isUserManaged

import org.chromium.base.ThreadUtils; //导入依赖的package包/类
/**
 * Performs an asynchronous check to see if the user is a managed user.
 * @param callback A callback to be called with true if the user is a managed user and false
 *         otherwise.
 */
public static void isUserManaged(String email, final Callback<Boolean> callback) {
    if (nativeShouldLoadPolicyForUser(email)) {
        nativeIsUserManaged(email, callback);
    } else {
        // Although we know the result immediately, the caller may not be able to handle the
        // callback being executed during this method call. So we post the callback on the
        // looper.
        ThreadUtils.postOnUiThread(new Runnable() {
            @Override
            public void run() {
                callback.onResult(false);
            }
        });
    }
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:21,代码来源:SigninManager.java

示例3: setTitleToPageTitle

import org.chromium.base.ThreadUtils; //导入依赖的package包/类
@Override
public void setTitleToPageTitle() {
    Tab currentTab = getToolbarDataProvider().getTab();
    if (currentTab == null || TextUtils.isEmpty(currentTab.getTitle())) {
        mTitleBar.setText("");
        return;
    }
    String title = currentTab.getTitle();

    // It takes some time to parse the title of the webcontent, and before that Tab#getTitle
    // always return the url. We postpone the title animation until the title is authentic.
    if ((mState == STATE_DOMAIN_AND_TITLE || mState == STATE_TITLE_ONLY)
            && !title.equals(currentTab.getUrl())
            && !title.equals(UrlConstants.ABOUT_BLANK)) {
        // Delay the title animation until security icon animation finishes.
        ThreadUtils.postOnUiThreadDelayed(mTitleAnimationStarter, TITLE_ANIM_DELAY_MS);
    }

    mTitleBar.setText(title);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:21,代码来源:CustomTabToolbar.java

示例4: captureNavigationInfo

import org.chromium.base.ThreadUtils; //导入依赖的package包/类
private void captureNavigationInfo(final Tab tab) {
    if (mCustomTabsConnection == null) return;
    if (!mCustomTabsConnection.shouldSendNavigationInfoForSession(mSession)) return;

    final ContentBitmapCallback callback = new ContentBitmapCallback() {
        @Override
        public void onFinishGetBitmap(Bitmap bitmap, int response) {
            if (TextUtils.isEmpty(tab.getTitle()) && bitmap == null) return;
            mCustomTabsConnection.sendNavigationInfo(
                    mSession, tab.getUrl(), tab.getTitle(), bitmap);
        }
    };
    // Delay screenshot capture since the page might be doing post load tasks. And this also
    // gives time to get rid of any redirects and avoid capturing screenshots for those.
    ThreadUtils.postOnUiThreadDelayed(new Runnable() {
        @Override
        public void run() {
            if (!tab.isHidden() && mCurrentState != STATE_RESET) return;
            if (tab.getWebContents() == null) return;
            tab.getWebContents().getContentBitmapAsync(
                    Bitmap.Config.ARGB_8888, mScaleForNavigationInfo, new Rect(), callback);
            mScreenshotTakenForCurrentNavigation = true;
        }
    }, 1000);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:26,代码来源:CustomTabObserver.java

示例5: canHandleContentProviderApiCall

import org.chromium.base.ThreadUtils; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:29,代码来源:ChromeBrowserProvider.java

示例6: unregisterActivity

import org.chromium.base.ThreadUtils; //导入依赖的package包/类
private static void unregisterActivity(final Activity activity) {
    ThreadUtils.assertOnUiThread();

    sPendingShareActivities.remove(activity);
    if (!sPendingShareActivities.isEmpty()) return;
    ApplicationStatus.unregisterActivityStateListener(sStateListener);

    waitForPendingStateChangeTask();
    sStateChangeTask = new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            if (!sPendingShareActivities.isEmpty()) return null;

            activity.getPackageManager().setComponentEnabledSetting(
                    new ComponentName(activity, PrintShareActivity.class),
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            if (sStateChangeTask == this) sStateChangeTask = null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:27,代码来源:PrintShareActivity.java

示例7: safeNotifyNativeListenersOnDistanceChanged

import org.chromium.base.ThreadUtils; //导入依赖的package包/类
/**
 * Notify native listeners with an updated estimate of the distance to the broadcasting device.
 * No notification will be sent if the feature is in the Onboarding state.
 * @param url The Physical Web URL.
 * @param distanceEstimate The updated distance estimate.
 */
private void safeNotifyNativeListenersOnDistanceChanged(
        final String url, final double distanceEstimate) {
    if (!isNativeInitialized() || PhysicalWeb.isOnboarding()) {
        return;
    }

    ThreadUtils.postOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (isNativeInitialized()) {
                nativeOnDistanceChanged(mNativePhysicalWebDataSourceAndroid, url,
                        distanceEstimate);
            }
        }
    });
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:23,代码来源:UrlManager.java

示例8: create

import org.chromium.base.ThreadUtils; //导入依赖的package包/类
/**
 * Prepares screenshot (possibly asynchronously) and invokes the callback when the screenshot
 * is available, or collection has failed. The asynchronous path is only taken when the activity
 * that is passed in is a {@link ChromeActivity}.
 * The callback is always invoked asynchronously.
 */
public static void create(Activity activity, final ScreenshotTaskCallback callback) {
    if (activity instanceof ChromeActivity) {
        Rect rect = new Rect();
        activity.getWindow().getDecorView().getRootView().getWindowVisibleDisplayFrame(rect);
        createCompositorScreenshot(((ChromeActivity) activity).getWindowAndroid(), rect,
                callback);
        return;
    }

    final Bitmap bitmap = prepareScreenshot(activity, null);
    ThreadUtils.postOnUiThread(new Runnable() {
        @Override
        public void run() {
            callback.onGotBitmap(bitmap);
        }
    });
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:24,代码来源:ScreenshotTask.java

示例9: reportFeedbackWithWebContents

import org.chromium.base.ThreadUtils; //导入依赖的package包/类
/**
 * A static method for native code to open the external feedback form UI.
 * @param webContents The WebContents containing the distilled content.
 * @param url The URL to report feedback for.
 * @param good True if the feedback is good and false if not.
 */
@CalledByNative
public static void reportFeedbackWithWebContents(
        WebContents webContents, String url, final boolean good) {
    ThreadUtils.assertOnUiThread();
    // TODO(mdjones): It would be better to get the WebContents from the manager so that the
    // native code does not need to depend on RenderFrame.
    Activity activity = getActivityFromWebContents(webContents);
    if (activity == null) return;

    if (sFeedbackReporter == null) {
        ChromeApplication application = (ChromeApplication) activity.getApplication();
        sFeedbackReporter = application.createFeedbackReporter();
    }
    FeedbackCollector.create(activity, Profile.getLastUsedProfile(), url,
            new FeedbackCollector.FeedbackResult() {
                @Override
                public void onResult(FeedbackCollector collector) {
                    String quality =
                            good ? DISTILLATION_QUALITY_GOOD : DISTILLATION_QUALITY_BAD;
                    collector.add(DISTILLATION_QUALITY_KEY, quality);
                    sFeedbackReporter.reportFeedback(collector);
                }
            });
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:31,代码来源:DomDistillerUIUtils.java

示例10: preInflationStartup

import org.chromium.base.ThreadUtils; //导入依赖的package包/类
private void preInflationStartup() {
    ThreadUtils.assertOnUiThread();
    if (mPreInflationStartupComplete) return;
    PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);

    // Ensure critical files are available, so they aren't blocked on the file-system
    // behind long-running accesses in next phase.
    // Don't do any large file access here!
    ContentApplication.initCommandLine(mApplication);
    waitForDebuggerIfNeeded();
    ChromeStrictMode.configureStrictMode();
    ChromeWebApkHost.init();

    warmUpSharedPrefs();

    DeviceUtils.addDeviceSpecificUserAgentSwitch(mApplication);
    ApplicationStatus.registerStateListenerForAllActivities(
            createActivityStateListener());

    mPreInflationStartupComplete = true;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:22,代码来源:ChromeBrowserInitializer.java

示例11: postMessage

import org.chromium.base.ThreadUtils; //导入依赖的package包/类
/**
 * Relay a postMessage request through the current channel assigned to this session.
 * @param message The message to be sent.
 * @return The result of the postMessage request. Returning true means the request was accepted,
 *         not necessarily that the postMessage was successful.
 */
public int postMessage(final String message) {
    if (mChannel == null || !mChannel[0].isReady() || mChannel[0].isClosed()) {
        return CustomTabsService.RESULT_FAILURE_MESSAGING_ERROR;
    }
    ThreadUtils.postOnUiThread(new Runnable() {
        @Override
        public void run() {
            // It is still possible that the page has navigated while this task is in the queue.
            // If that happens fail gracefully.
            if (mChannel == null || mChannel[0].isClosed()) return;
            mChannel[0].postMessage(message, null);
        }
    });
    return CustomTabsService.RESULT_SUCCESS;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:22,代码来源:PostMessageHandler.java

示例12: loadBookmarks

import org.chromium.base.ThreadUtils; //导入依赖的package包/类
@BinderThread
private BookmarkFolder loadBookmarks(final BookmarkId folderId) {
    final LinkedBlockingQueue<BookmarkFolder> resultQueue = new LinkedBlockingQueue<>(1);
    //A reference of BookmarkLoader is needed in binder thread to
    //prevent it from being garbage collected.
    final BookmarkLoader bookmarkLoader = new BookmarkLoader();
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            bookmarkLoader.initialize(mContext, folderId, new BookmarkLoaderCallback() {
                @Override
                public void onBookmarksLoaded(BookmarkFolder folder) {
                    resultQueue.add(folder);
                }
            });
        }
    });
    try {
        return resultQueue.take();
    } catch (InterruptedException e) {
        return null;
    }
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:24,代码来源:BookmarkWidgetService.java

示例13: getCount

import org.chromium.base.ThreadUtils; //导入依赖的package包/类
@BinderThread
@Override
public int getCount() {
    //On some Sony devices, getCount() could be called before onDatasetChanged()
    //returns. If it happens, refresh widget until the bookmarks are all loaded.
    if (mCurrentFolder == null || !mPreferences.getString(PREF_CURRENT_FOLDER, "")
            .equals(mCurrentFolder.folder.id.toString())) {
        ThreadUtils.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                refreshWidget();
            }
        });
    }
    if (mCurrentFolder == null) {
        return 0;
    }
    return mCurrentFolder.children.size() + (mCurrentFolder.parent != null ? 1 : 0);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:20,代码来源:BookmarkWidgetService.java

示例14: initializeBrowser

import org.chromium.base.ThreadUtils; //导入依赖的package包/类
/** 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);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:27,代码来源:CustomTabsConnection.java

示例15: destroyIncognitoIfNecessary

import org.chromium.base.ThreadUtils; //导入依赖的package包/类
/**
 * Destroys the Incognito profile when all Incognito tabs have been closed.  Also resets the
 * delegate TabModel to be a stub EmptyTabModel.
 */
protected void destroyIncognitoIfNecessary() {
    ThreadUtils.assertOnUiThread();
    if (!isEmpty() || mDelegateModel instanceof EmptyTabModel || mIsAddingTab) {
        return;
    }

    Profile profile = getProfile();
    mDelegateModel.destroy();

    // Only delete the incognito profile if there are no incognito tabs open in any tab
    // model selector as the profile is shared between them.
    if (profile != null && !mDelegate.doIncognitoTabsExist()) {
        IncognitoNotificationManager.dismissIncognitoNotification();

        profile.destroyWhenAppropriate();
    }

    mDelegateModel = EmptyTabModel.getInstance();
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:24,代码来源:IncognitoTabModel.java


注:本文中的org.chromium.base.ThreadUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。