dom/time/TimeService.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/time/TimeService.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,38 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#include "base/basictypes.h"
     1.9 +#include "jsapi.h"
    1.10 +#include "mozilla/ClearOnShutdown.h"
    1.11 +#include "mozilla/Hal.h"
    1.12 +#include "TimeService.h"
    1.13 +
    1.14 +namespace mozilla {
    1.15 +namespace dom {
    1.16 +namespace time {
    1.17 +
    1.18 +NS_IMPL_ISUPPORTS(TimeService, nsITimeService)
    1.19 +
    1.20 +/* static */ StaticRefPtr<TimeService> TimeService::sSingleton;
    1.21 +
    1.22 +/* static */ already_AddRefed<TimeService>
    1.23 +TimeService::GetInstance()
    1.24 +{
    1.25 +  if (!sSingleton) {
    1.26 +    sSingleton = new TimeService();
    1.27 +    ClearOnShutdown(&sSingleton);
    1.28 +  }
    1.29 +  nsRefPtr<TimeService> service = sSingleton.get();
    1.30 +  return service.forget();
    1.31 +}
    1.32 +
    1.33 +NS_IMETHODIMP
    1.34 +TimeService::Set(int64_t aTimeInMS) {
    1.35 +  hal::AdjustSystemClock(aTimeInMS - (JS_Now() / PR_USEC_PER_MSEC));
    1.36 +  return NS_OK;
    1.37 +}
    1.38 +
    1.39 +} // namespace time
    1.40 +} // namespace dom
    1.41 +} // namespace mozilla

mercurial