bug 1172377 change RunInStableState API to receive ownership of nsIRunnable r=roc

This commit is contained in:
Karl Tomlinson 2015-06-08 11:06:38 +12:00
parent dfec676114
commit 9314668ae3
6 changed files with 29 additions and 21 deletions

View File

@ -5162,9 +5162,7 @@ nsContentUtils::RunInStableState(already_AddRefed<nsIRunnable> aRunnable,
MOZ_ASSERT(aHandling == DispatchFailureHandling::IgnoreFailure); MOZ_ASSERT(aHandling == DispatchFailureHandling::IgnoreFailure);
return; return;
} }
DebugOnly<nsresult> rv = appShell->RunInStableState(runnable); appShell->RunInStableState(runnable.forget());
MOZ_ASSERT(NS_SUCCEEDED(rv) ||
aHandling == DispatchFailureHandling::IgnoreFailure);
} }
void void

View File

@ -171,9 +171,9 @@ ScreenProxy::InvalidateCacheOnNextTick()
nsCOMPtr<nsIAppShell> appShell = do_GetService(kAppShellCID); nsCOMPtr<nsIAppShell> appShell = do_GetService(kAppShellCID);
if (appShell) { if (appShell) {
appShell->RunInStableState( nsCOMPtr<nsIRunnable> r =
NS_NewRunnableMethod(this, &ScreenProxy::InvalidateCache) NS_NewRunnableMethod(this, &ScreenProxy::InvalidateCache);
); appShell->RunInStableState(r.forget());
} else { } else {
// It's pretty bad news if we can't get the appshell. In that case, // It's pretty bad news if we can't get the appshell. In that case,
// let's just invalidate the cache right away. // let's just invalidate the cache right away.

View File

@ -387,7 +387,8 @@ nsBaseAppShell::RunSyncSectionsInternal(bool aStable,
} }
void void
nsBaseAppShell::ScheduleSyncSection(nsIRunnable* aRunnable, bool aStable) nsBaseAppShell::ScheduleSyncSection(already_AddRefed<nsIRunnable> aRunnable,
bool aStable)
{ {
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread."); NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
@ -444,16 +445,16 @@ nsBaseAppShell::Observe(nsISupports *subject, const char *topic,
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP void
nsBaseAppShell::RunInStableState(nsIRunnable* aRunnable) nsBaseAppShell::RunInStableState(already_AddRefed<nsIRunnable> aRunnable)
{ {
ScheduleSyncSection(aRunnable, true); ScheduleSyncSection(mozilla::Move(aRunnable), true);
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsBaseAppShell::RunBeforeNextEvent(nsIRunnable* aRunnable) nsBaseAppShell::RunBeforeNextEvent(nsIRunnable* aRunnable)
{ {
ScheduleSyncSection(aRunnable, false); nsCOMPtr<nsIRunnable> runnable = aRunnable;
ScheduleSyncSection(runnable.forget(), false);
return NS_OK; return NS_OK;
} }

View File

@ -25,6 +25,8 @@ class nsBaseAppShell : public nsIAppShell, public nsIThreadObserver,
public: public:
NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIAPPSHELL NS_DECL_NSIAPPSHELL
void RunInStableState(already_AddRefed<nsIRunnable> runnable) override;
NS_DECL_NSITHREADOBSERVER NS_DECL_NSITHREADOBSERVER
NS_DECL_NSIOBSERVER NS_DECL_NSIOBSERVER
@ -94,7 +96,7 @@ private:
} }
} }
void ScheduleSyncSection(nsIRunnable* runnable, bool stable); void ScheduleSyncSection(already_AddRefed<nsIRunnable> runnable, bool stable);
struct SyncSection { struct SyncSection {
SyncSection() SyncSection()

View File

@ -7,12 +7,15 @@
#include "nsISupports.idl" #include "nsISupports.idl"
interface nsIRunnable; interface nsIRunnable;
%{ C++
template <class T> struct already_AddRefed;
%}
/** /**
* Interface for the native event system layer. This interface is designed * Interface for the native event system layer. This interface is designed
* to be used on the main application thread only. * to be used on the main application thread only.
*/ */
[uuid(2d10ca53-f143-439a-bb2e-c1fbc71f6a05)] [uuid(3d09973e-3975-4fd4-b103-276300cc8437)]
interface nsIAppShell : nsISupports interface nsIAppShell : nsISupports
{ {
/** /**
@ -71,16 +74,20 @@ interface nsIAppShell : nsISupports
*/ */
readonly attribute unsigned long eventloopNestingLevel; readonly attribute unsigned long eventloopNestingLevel;
%{ C++
/** /**
* Allows running of a "synchronous section", in the form of an nsIRunnable * Add a "synchronous section", in the form of an nsIRunnable run once the
* once the event loop has reached a "stable state". We've reached a stable * event loop has reached a "stable state". |runnable| must not cause any
* state when the currently executing task/event has finished, see: * queued events to be processed (i.e. must not spin the event loop). We've
* reached a stable state when the currently executing task/event has
* finished, see:
* http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#synchronous-section * http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#synchronous-section
* In practice this runs aRunnable once the currently executing event * In practice this runs aRunnable once the currently executing event
* finishes. If called multiple times per task/event, all the runnables will * finishes. If called multiple times per task/event, all the runnables will
* be executed, in the order in which runInStableState() was called. * be executed, in the order in which runInStableState() was called.
*/ */
void runInStableState(in nsIRunnable runnable); virtual void RunInStableState(already_AddRefed<nsIRunnable> runnable) = 0;
%}
/** /**
* Run the given runnable before the next iteration of the event loop (this * Run the given runnable before the next iteration of the event loop (this

View File

@ -200,9 +200,9 @@ nsScreenManagerProxy::InvalidateCacheOnNextTick()
nsCOMPtr<nsIAppShell> appShell = do_GetService(kAppShellCID); nsCOMPtr<nsIAppShell> appShell = do_GetService(kAppShellCID);
if (appShell) { if (appShell) {
appShell->RunInStableState( nsCOMPtr<nsIRunnable> r =
NS_NewRunnableMethod(this, &nsScreenManagerProxy::InvalidateCache) NS_NewRunnableMethod(this, &nsScreenManagerProxy::InvalidateCache);
); appShell->RunInStableState(r.forget());
} else { } else {
// It's pretty bad news if we can't get the appshell. In that case, // It's pretty bad news if we can't get the appshell. In that case,
// let's just invalidate the cache right away. // let's just invalidate the cache right away.