Java Code Examples for org.chromium.base.ThreadUtils#postOnUiThreadDelayed()
The following examples show how to use
org.chromium.base.ThreadUtils#postOnUiThreadDelayed() .
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: ToolbarManager.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * Handle all necessary tasks that can be delayed until initialization completes. * @param activityCreationTimeMs The time of creation for the activity this toolbar belongs to. * @param activityName Simple class name for the activity this toolbar belongs to. */ public void onDeferredStartup(final long activityCreationTimeMs, final String activityName) { // Record startup performance statistics long elapsedTime = SystemClock.elapsedRealtime() - activityCreationTimeMs; if (elapsedTime < RECORD_UMA_PERFORMANCE_METRICS_DELAY_MS) { ThreadUtils.postOnUiThreadDelayed(new Runnable() { @Override public void run() { onDeferredStartup(activityCreationTimeMs, activityName); } }, RECORD_UMA_PERFORMANCE_METRICS_DELAY_MS - elapsedTime); } RecordHistogram.recordTimesHistogram("MobileStartup.ToolbarFirstDrawTime." + activityName, mToolbar.getFirstDrawTime() - activityCreationTimeMs, TimeUnit.MILLISECONDS); long firstFocusTime = mToolbar.getLocationBar().getFirstUrlBarFocusTime(); if (firstFocusTime != 0) { RecordHistogram.recordCustomTimesHistogram( "MobileStartup.ToolbarFirstFocusTime." + activityName, firstFocusTime - activityCreationTimeMs, MIN_FOCUS_TIME_FOR_UMA_HISTOGRAM_MS, MAX_FOCUS_TIME_FOR_UMA_HISTOGRAM_MS, TimeUnit.MILLISECONDS, 50); } }
Example 2
Source File: DisplayAndroidManager.java From 365browser with Apache License 2.0 | 6 votes |
@Override public void startAccurateListening() { ++mAccurateCount; if (mAccurateCount > 1) return; // Start polling if we went from 0 to 1. The polling will // automatically stop when mAccurateCount reaches 0. final DisplayListenerAPI16 self = this; ThreadUtils.postOnUiThreadDelayed(new Runnable() { @Override public void run() { self.onConfigurationChanged(null); if (self.mAccurateCount < 1) return; ThreadUtils.postOnUiThreadDelayed(this, DisplayListenerAPI16.POLLING_DELAY); } }, POLLING_DELAY); }
Example 3
Source File: ToolbarManager.java From 365browser with Apache License 2.0 | 6 votes |
/** * Handle all necessary tasks that can be delayed until initialization completes. * @param activityCreationTimeMs The time of creation for the activity this toolbar belongs to. * @param activityName Simple class name for the activity this toolbar belongs to. */ public void onDeferredStartup(final long activityCreationTimeMs, final String activityName) { // Record startup performance statistics long elapsedTime = SystemClock.elapsedRealtime() - activityCreationTimeMs; if (elapsedTime < RECORD_UMA_PERFORMANCE_METRICS_DELAY_MS) { ThreadUtils.postOnUiThreadDelayed(new Runnable() { @Override public void run() { onDeferredStartup(activityCreationTimeMs, activityName); } }, RECORD_UMA_PERFORMANCE_METRICS_DELAY_MS - elapsedTime); } RecordHistogram.recordTimesHistogram("MobileStartup.ToolbarFirstDrawTime." + activityName, mToolbar.getFirstDrawTime() - activityCreationTimeMs, TimeUnit.MILLISECONDS); long firstFocusTime = mToolbar.getLocationBar().getFirstUrlBarFocusTime(); if (firstFocusTime != 0) { RecordHistogram.recordCustomTimesHistogram( "MobileStartup.ToolbarFirstFocusTime." + activityName, firstFocusTime - activityCreationTimeMs, MIN_FOCUS_TIME_FOR_UMA_HISTOGRAM_MS, MAX_FOCUS_TIME_FOR_UMA_HISTOGRAM_MS, TimeUnit.MILLISECONDS, 50); } }
Example 4
Source File: CustomTabToolbar.java From 365browser with Apache License 2.0 | 6 votes |
@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(ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL)) { // Delay the title animation until security icon animation finishes. ThreadUtils.postOnUiThreadDelayed(mTitleAnimationStarter, TITLE_ANIM_DELAY_MS); } mTitleBar.setText(title); }
Example 5
Source File: CustomTabActivity.java From 365browser with Apache License 2.0 | 6 votes |
/** * Finishes the activity and removes the reference from the Android recents. * * @param reparenting true iff the activity finishes due to tab reparenting. */ public final void finishAndClose(boolean reparenting) { if (mIsClosing) return; mIsClosing = true; if (!reparenting) { // Closing the activity destroys the renderer as well. Re-create a spare renderer some // time after, so that we have one ready for the next tab open. This does not increase // memory consumption, as the current renderer goes away. We create a renderer as a lot // of users open several Custom Tabs in a row. The delay is there to avoid jank in the // transition animation when closing the tab. ThreadUtils.postOnUiThreadDelayed(new Runnable() { @Override public void run() { WarmupManager.getInstance().createSpareWebContents(); } }, 500); } handleFinishAndClose(); }
Example 6
Source File: CustomTabObserver.java From 365browser with Apache License 2.0 | 6 votes |
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( mContentBitmapWidth, mContentBitmapHeight, callback); mScreenshotTakenForCurrentNavigation = true; } }, 1000); }
Example 7
Source File: CustomTabToolbar.java From AndroidChromium with Apache License 2.0 | 6 votes |
@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); }
Example 8
Source File: CustomTabActivity.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * Finishes the activity and removes the reference from the Android recents. * * @param reparenting true iff the activity finishes due to tab reparenting. */ public final void finishAndClose(boolean reparenting) { mIsClosing = true; if (!reparenting) { // Closing the activity destroys the renderer as well. Re-create a spare renderer some // time after, so that we have one ready for the next tab open. This does not increase // memory consumption, as the current renderer goes away. We create a renderer as a lot // of users open several Custom Tabs in a row. The delay is there to avoid jank in the // transition animation when closing the tab. ThreadUtils.postOnUiThreadDelayed(new Runnable() { @Override public void run() { WarmupManager.getInstance().createSpareWebContents(); } }, 500); } handleFinishAndClose(); }
Example 9
Source File: CustomTabObserver.java From AndroidChromium with Apache License 2.0 | 6 votes |
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); }
Example 10
Source File: ChromeFullscreenManager.java From AndroidChromium with Apache License 2.0 | 6 votes |
@Override public void onActivityStateChange(Activity activity, int newState) { if (newState == ActivityState.STOPPED) { // Exit fullscreen in onStop to ensure the system UI flags are set correctly when // showing again (on JB MR2+ builds, the omnibox would be covered by the // notification bar when this was done in onStart()). setPersistentFullscreenMode(false); } else if (newState == ActivityState.STARTED) { ThreadUtils.postOnUiThreadDelayed(new Runnable() { @Override public void run() { mBrowserVisibilityDelegate.showControlsTransient(); } }, ACTIVITY_RETURN_SHOW_REQUEST_DELAY_MS); } else if (newState == ActivityState.DESTROYED) { ApplicationStatus.unregisterActivityStateListener(this); ((BaseChromiumApplication) mWindow.getContext().getApplicationContext()) .unregisterWindowFocusChangedListener(this); mTabModelObserver.destroy(); } }
Example 11
Source File: ChildProcessLauncher.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
/** * Remove the initial binding of the child process. Child processes are bound with initial * binding to protect them from getting killed before they are put to use. This method * allows to remove the binding once it is no longer needed. The binding is removed after a * fixed delay period so that the renderer will not be killed immediately after the call. */ void removeInitialBinding(final int pid) { final ChildProcessConnection connection = sServiceMap.get(pid); if (connection == null) { LogPidWarning(pid, "Tried to remove a binding for a non-existent connection"); return; } if (!connection.isInitialBindingBound()) return; ThreadUtils.postOnUiThreadDelayed(new Runnable() { @Override public void run() { synchronized (mCountLock) { if (connection.isInitialBindingBound()) { decrementOomCount(pid); connection.removeInitialBinding(); } } } }, REMOVE_INITIAL_BINDING_DELAY_MILLIS); }
Example 12
Source File: ChildProcessLauncher.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
/** * Remove the initial binding of the child process. Child processes are bound with initial * binding to protect them from getting killed before they are put to use. This method * allows to remove the binding once it is no longer needed. The binding is removed after a * fixed delay period so that the renderer will not be killed immediately after the call. */ void removeInitialBinding(final int pid) { final ChildProcessConnection connection = sServiceMap.get(pid); if (connection == null) { LogPidWarning(pid, "Tried to remove a binding for a non-existent connection"); return; } if (!connection.isInitialBindingBound()) return; ThreadUtils.postOnUiThreadDelayed(new Runnable() { @Override public void run() { synchronized (mCountLock) { if (connection.isInitialBindingBound()) { decrementOomCount(pid); connection.removeInitialBinding(); } } } }, REMOVE_INITIAL_BINDING_DELAY_MILLIS); }
Example 13
Source File: PartnerBrowserCustomizations.java From delion with Apache License 2.0 | 5 votes |
/** * Sets a callback that will be executed when the initialization is done. * * @param callback This is called when the initialization is done. * @param timeoutMs If initializing takes more than this time since this function is called, * force run |callback| early. The unit is ms. */ public static void setOnInitializeAsyncFinished(final Runnable callback, long timeoutMs) { sInitializeAsyncCallbacks.add(callback); ThreadUtils.postOnUiThreadDelayed( new Runnable() { @Override public void run() { if (sInitializeAsyncCallbacks.remove(callback)) callback.run(); } }, sIsInitialized ? 0 : timeoutMs); }
Example 14
Source File: PartnerBrowserCustomizations.java From 365browser with Apache License 2.0 | 5 votes |
/** * Sets a callback that will be executed when the initialization is done. * * @param callback This is called when the initialization is done. * @param timeoutMs If initializing takes more than this time since this function is called, * force run |callback| early. The unit is ms. */ public static void setOnInitializeAsyncFinished(final Runnable callback, long timeoutMs) { sInitializeAsyncCallbacks.add(callback); ThreadUtils.postOnUiThreadDelayed( new Runnable() { @Override public void run() { if (sInitializeAsyncCallbacks.remove(callback)) callback.run(); } }, sIsInitialized ? 0 : timeoutMs); }
Example 15
Source File: FeedbackCollector.java From 365browser with Apache License 2.0 | 5 votes |
private void postTimeoutTask() { ThreadUtils.postOnUiThreadDelayed(new Runnable() { @Override public void run() { maybePostResult(); } }, TIMEOUT_MS); }
Example 16
Source File: ChildProcessLauncher.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * Unbind a high priority process which was previous bound with bindAsHighPriority. * @param pid The process handle of the service. */ void unbindAsHighPriority(final int pid) { final ChildProcessConnection connection = sServiceMap.get(pid); if (connection == null) { LogPidWarning(pid, "Tried to unbind non-existent connection"); return; } if (!connection.isStrongBindingBound()) return; // This runnable performs the actual unbinding. It will be executed synchronously when // on low-end devices and posted with a delay otherwise. Runnable doUnbind = new Runnable() { @Override public void run() { synchronized (mCountLock) { if (connection.isStrongBindingBound()) { decrementOomCount(pid); connection.detachAsActive(); } } } }; if (SysUtils.isLowEndDevice()) { doUnbind.run(); } else { ThreadUtils.postOnUiThreadDelayed(doUnbind, DETACH_AS_ACTIVE_HIGH_END_DELAY_MILLIS); } }
Example 17
Source File: FeedbackCollector.java From AndroidChromium with Apache License 2.0 | 5 votes |
private void postTimeoutTask() { ThreadUtils.postOnUiThreadDelayed(new Runnable() { @Override public void run() { maybePostResult(); } }, TIMEOUT_MS); }
Example 18
Source File: PartnerBrowserCustomizations.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Sets a callback that will be executed when the initialization is done. * * @param callback This is called when the initialization is done. * @param timeoutMs If initializing takes more than this time since this function is called, * force run |callback| early. The unit is ms. */ public static void setOnInitializeAsyncFinished(final Runnable callback, long timeoutMs) { sInitializeAsyncCallbacks.add(callback); ThreadUtils.postOnUiThreadDelayed( new Runnable() { @Override public void run() { if (sInitializeAsyncCallbacks.remove(callback)) callback.run(); } }, sIsInitialized ? 0 : timeoutMs); }
Example 19
Source File: ChildProcessLauncher.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * Unbind a high priority process which was previous bound with bindAsHighPriority. * @param pid The process handle of the service. */ void unbindAsHighPriority(final int pid) { final ChildProcessConnection connection = sServiceMap.get(pid); if (connection == null) { LogPidWarning(pid, "Tried to unbind non-existent connection"); return; } if (!connection.isStrongBindingBound()) return; // This runnable performs the actual unbinding. It will be executed synchronously when // on low-end devices and posted with a delay otherwise. Runnable doUnbind = new Runnable() { @Override public void run() { synchronized (mCountLock) { if (connection.isStrongBindingBound()) { decrementOomCount(pid); connection.detachAsActive(); } } } }; if (SysUtils.isLowEndDevice()) { doUnbind.run(); } else { ThreadUtils.postOnUiThreadDelayed(doUnbind, DETACH_AS_ACTIVE_HIGH_END_DELAY_MILLIS); } }
Example 20
Source File: InstalledAppProviderImpl.java From 365browser with Apache License 2.0 | 2 votes |
/** * Runs a Runnable task after a given delay. * * Protected and non-static for testing. * * @param r The Runnable that will be executed. * @param delayMillis The delay (in ms) until the Runnable will be executed. * @return True if the Runnable was successfully placed into the message queue. */ protected void delayThenRun(Runnable r, long delayMillis) { ThreadUtils.postOnUiThreadDelayed(r, delayMillis); }