gecko-dev/widget/nsIdleService.h
Mason Chang 8180f9229c Bug 1085696. Part 1 Move widget/xpwidget to /widget. r=roc
--HG--
rename : widget/xpwidgets/ContentHelper.cpp => widget/ContentHelper.cpp
rename : widget/xpwidgets/ContentHelper.h => widget/ContentHelper.h
rename : widget/xpwidgets/GfxDriverInfo.cpp => widget/GfxDriverInfo.cpp
rename : widget/xpwidgets/GfxDriverInfo.h => widget/GfxDriverInfo.h
rename : widget/xpwidgets/GfxInfoBase.cpp => widget/GfxInfoBase.cpp
rename : widget/xpwidgets/GfxInfoBase.h => widget/GfxInfoBase.h
rename : widget/xpwidgets/GfxInfoCollector.cpp => widget/GfxInfoCollector.cpp
rename : widget/xpwidgets/GfxInfoCollector.h => widget/GfxInfoCollector.h
rename : widget/xpwidgets/GfxInfoWebGL.cpp => widget/GfxInfoWebGL.cpp
rename : widget/xpwidgets/GfxInfoWebGL.h => widget/GfxInfoWebGL.h
rename : widget/xpwidgets/GfxInfoX11.cpp => widget/GfxInfoX11.cpp
rename : widget/xpwidgets/GfxInfoX11.h => widget/GfxInfoX11.h
rename : widget/xpwidgets/InputData.cpp => widget/InputData.cpp
rename : widget/xpwidgets/PuppetWidget.cpp => widget/PuppetWidget.cpp
rename : widget/xpwidgets/PuppetWidget.h => widget/PuppetWidget.h
rename : widget/xpwidgets/ScreenProxy.cpp => widget/ScreenProxy.cpp
rename : widget/xpwidgets/ScreenProxy.h => widget/ScreenProxy.h
rename : widget/shared/SharedWidgetUtils.cpp => widget/SharedWidgetUtils.cpp
rename : widget/xpwidgets/WidgetUtils.cpp => widget/WidgetUtils.cpp
rename : widget/xpwidgets/nsAppShellSingleton.h => widget/nsAppShellSingleton.h
rename : widget/xpwidgets/nsBaseAppShell.cpp => widget/nsBaseAppShell.cpp
rename : widget/xpwidgets/nsBaseAppShell.h => widget/nsBaseAppShell.h
rename : widget/xpwidgets/nsBaseClipboard.cpp => widget/nsBaseClipboard.cpp
rename : widget/xpwidgets/nsBaseClipboard.h => widget/nsBaseClipboard.h
rename : widget/xpwidgets/nsBaseDragService.cpp => widget/nsBaseDragService.cpp
rename : widget/xpwidgets/nsBaseDragService.h => widget/nsBaseDragService.h
rename : widget/xpwidgets/nsBaseFilePicker.cpp => widget/nsBaseFilePicker.cpp
rename : widget/xpwidgets/nsBaseFilePicker.h => widget/nsBaseFilePicker.h
rename : widget/xpwidgets/nsBaseScreen.cpp => widget/nsBaseScreen.cpp
rename : widget/xpwidgets/nsBaseScreen.h => widget/nsBaseScreen.h
rename : widget/xpwidgets/nsBaseWidget.cpp => widget/nsBaseWidget.cpp
rename : widget/xpwidgets/nsBaseWidget.h => widget/nsBaseWidget.h
rename : widget/xpwidgets/nsClipboardHelper.cpp => widget/nsClipboardHelper.cpp
rename : widget/xpwidgets/nsClipboardHelper.h => widget/nsClipboardHelper.h
rename : widget/xpwidgets/nsClipboardProxy.cpp => widget/nsClipboardProxy.cpp
rename : widget/xpwidgets/nsClipboardProxy.h => widget/nsClipboardProxy.h
rename : widget/xpwidgets/nsColorPickerProxy.cpp => widget/nsColorPickerProxy.cpp
rename : widget/xpwidgets/nsColorPickerProxy.h => widget/nsColorPickerProxy.h
rename : widget/xpwidgets/nsContentProcessWidgetFactory.cpp => widget/nsContentProcessWidgetFactory.cpp
rename : widget/xpwidgets/nsFilePickerProxy.cpp => widget/nsFilePickerProxy.cpp
rename : widget/xpwidgets/nsFilePickerProxy.h => widget/nsFilePickerProxy.h
rename : widget/xpwidgets/nsHTMLFormatConverter.cpp => widget/nsHTMLFormatConverter.cpp
rename : widget/xpwidgets/nsHTMLFormatConverter.h => widget/nsHTMLFormatConverter.h
rename : widget/xpwidgets/nsIWidgetListener.cpp => widget/nsIWidgetListener.cpp
rename : widget/xpwidgets/nsIdleService.cpp => widget/nsIdleService.cpp
rename : widget/xpwidgets/nsIdleService.h => widget/nsIdleService.h
rename : widget/xpwidgets/nsNativeTheme.cpp => widget/nsNativeTheme.cpp
rename : widget/xpwidgets/nsNativeTheme.h => widget/nsNativeTheme.h
rename : widget/xpwidgets/nsPrimitiveHelpers.cpp => widget/nsPrimitiveHelpers.cpp
rename : widget/xpwidgets/nsPrimitiveHelpers.h => widget/nsPrimitiveHelpers.h
rename : widget/xpwidgets/nsPrintOptionsImpl.cpp => widget/nsPrintOptionsImpl.cpp
rename : widget/xpwidgets/nsPrintOptionsImpl.h => widget/nsPrintOptionsImpl.h
rename : widget/xpwidgets/nsPrintSession.cpp => widget/nsPrintSession.cpp
rename : widget/xpwidgets/nsPrintSession.h => widget/nsPrintSession.h
rename : widget/xpwidgets/nsPrintSettingsImpl.cpp => widget/nsPrintSettingsImpl.cpp
rename : widget/xpwidgets/nsPrintSettingsImpl.h => widget/nsPrintSettingsImpl.h
rename : widget/xpwidgets/nsScreenManagerProxy.cpp => widget/nsScreenManagerProxy.cpp
rename : widget/xpwidgets/nsScreenManagerProxy.h => widget/nsScreenManagerProxy.h
rename : widget/xpwidgets/nsTransferable.cpp => widget/nsTransferable.cpp
rename : widget/xpwidgets/nsTransferable.h => widget/nsTransferable.h
rename : widget/xpwidgets/nsXPLookAndFeel.cpp => widget/nsXPLookAndFeel.cpp
rename : widget/xpwidgets/nsXPLookAndFeel.h => widget/nsXPLookAndFeel.h
2014-10-23 10:16:45 -07:00

226 lines
6.4 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:expandtab:shiftwidth=2:tabstop=2:
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsIdleService_h__
#define nsIdleService_h__
#include "nsIIdleServiceInternal.h"
#include "nsCOMPtr.h"
#include "nsITimer.h"
#include "nsTArray.h"
#include "nsIObserver.h"
#include "nsIIdleService.h"
#include "nsCategoryCache.h"
#include "nsWeakReference.h"
#include "mozilla/TimeStamp.h"
/**
* Class we can use to store an observer with its associated idle time
* requirement and whether or not the observer thinks it's "idle".
*/
class IdleListener {
public:
nsCOMPtr<nsIObserver> observer;
uint32_t reqIdleTime;
bool isIdle;
IdleListener(nsIObserver* obs, uint32_t reqIT, bool aIsIdle = false) :
observer(obs), reqIdleTime(reqIT), isIdle(aIsIdle) {}
~IdleListener() {}
};
// This one will be declared later.
class nsIdleService;
/**
* Class to handle the daily idle timer.
*/
class nsIdleServiceDaily : public nsIObserver,
public nsSupportsWeakReference
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
explicit nsIdleServiceDaily(nsIIdleService* aIdleService);
/**
* Initializes the daily idle observer.
* Keep this separated from the constructor, since it could cause pointer
* corruption due to AddRef/Release of "this".
*/
void Init();
private:
virtual ~nsIdleServiceDaily();
/**
* StageIdleDaily is the interim call made when an idle-daily event is due.
* However we don't want to fire idle-daily until the user is idle for this
* session, so this sets up a short wait for an idle event which triggers
* the actual idle-daily event.
*
* @param aHasBeenLongWait Pass true indicating nsIdleServiceDaily is having
* trouble getting the idle-daily event fired. If true StageIdleDaily will
* use a shorter idle wait time before firing idle-daily.
*/
void StageIdleDaily(bool aHasBeenLongWait);
/**
* @note This is a normal pointer, part to avoid creating a cycle with the
* idle service, part to avoid potential pointer corruption due to this class
* being instantiated in the constructor of the service itself.
*/
nsIIdleService* mIdleService;
/**
* Place to hold the timer used by this class to determine when a day has
* passed, after that it will wait for idle time to be detected.
*/
nsCOMPtr<nsITimer> mTimer;
/**
* Function that is called back once a day.
*/
static void DailyCallback(nsITimer* aTimer, void* aClosure);
/**
* Cache of observers for the "idle-daily" category.
*/
nsCategoryCache<nsIObserver> mCategoryObservers;
/**
* Boolean set to true when daily idle notifications should be disabled.
*/
bool mShutdownInProgress;
/**
* Next time we expect an idle-daily timer to fire, in case timers aren't
* very reliable on the platform. Value is in PR_Now microsecond units.
*/
PRTime mExpectedTriggerTime;
/**
* Tracks which idle daily observer callback we ask for. There are two: a
* regular long idle wait and a shorter wait if we've been waiting to fire
* idle daily for an extended period. Set by StageIdleDaily.
*/
int32_t mIdleDailyTriggerWait;
};
class nsIdleService : public nsIIdleServiceInternal
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIIDLESERVICE
NS_DECL_NSIIDLESERVICEINTERNAL
protected:
static already_AddRefed<nsIdleService> GetInstance();
nsIdleService();
virtual ~nsIdleService();
/**
* If there is a platform specific function to poll the system idel time
* then that must be returned in this function, and the function MUST return
* true, otherwise then the function should be left unimplemented or made
* to return false (this can also be used for systems where it depends on
* the configuration of the system if the idle time can be determined)
*
* @param aIdleTime
* The idle time in ms.
*
* @return true if the idle time could be polled, false otherwise.
*
* @note The time returned by this function can be different than the one
* returned by GetIdleTime, as that is corrected by any calls to
* ResetIdleTimeOut(), unless you overwrite that function too...
*/
virtual bool PollIdleTime(uint32_t* aIdleTime);
/**
* Function that determines if we are in poll mode or not.
*
* @return true if polling is supported, false otherwise.
*/
virtual bool UsePollMode();
private:
/**
* Ensure that the timer is expiring at least at the given time
*
* The function might not restart the timer if there is one running currently
*
* @param aNextTimeout
* The last absolute time the timer should expire
*/
void SetTimerExpiryIfBefore(mozilla::TimeStamp aNextTimeout);
/**
* Stores the next timeout time, 0 means timer not running
*/
mozilla::TimeStamp mCurrentlySetToTimeoutAt;
/**
* mTimer holds the internal timer used by this class to detect when to poll
* for idle time, when to check if idle timers should expire etc.
*/
nsCOMPtr<nsITimer> mTimer;
/**
* Array of listeners that wants to be notified about idle time.
*/
nsTArray<IdleListener> mArrayListeners;
/**
* Object keeping track of the daily idle thingy.
*/
nsRefPtr<nsIdleServiceDaily> mDailyIdle;
/**
* Number of observers currently in idle mode.
*/
uint32_t mIdleObserverCount;
/**
* Delta time from last non idle time to when the next observer should switch
* to idle mode
*
* Time in seconds
*
* If this value is 0 it means there are no active observers
*/
uint32_t mDeltaToNextIdleSwitchInS;
/**
* Absolute value for when the last user interaction took place.
*/
mozilla::TimeStamp mLastUserInteraction;
/**
* Function that ensures the timer is running with at least the minimum time
* needed. It will kill the timer if there are no active observers.
*/
void ReconfigureTimer(void);
/**
* Callback function that is called when the internal timer expires.
*
* This in turn calls the IdleTimerCallback that does the real processing
*/
static void StaticIdleTimerCallback(nsITimer* aTimer, void* aClosure);
/**
* Function that handles when a timer has expired
*/
void IdleTimerCallback(void);
};
#endif // nsIdleService_h__