Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "base/basictypes.h"
8 : #include "jsapi.h"
9 : #include "mozilla/ClearOnShutdown.h"
10 : #include "mozilla/Hal.h"
11 : #include "TimeService.h"
12 :
13 : namespace mozilla {
14 : namespace dom {
15 : namespace time {
16 :
17 0 : NS_IMPL_ISUPPORTS(TimeService, nsITimeService)
18 :
19 3 : /* static */ StaticRefPtr<TimeService> TimeService::sSingleton;
20 :
21 : /* static */ already_AddRefed<TimeService>
22 0 : TimeService::GetInstance()
23 : {
24 0 : if (!sSingleton) {
25 0 : sSingleton = new TimeService();
26 0 : ClearOnShutdown(&sSingleton);
27 : }
28 0 : RefPtr<TimeService> service = sSingleton.get();
29 0 : return service.forget();
30 : }
31 :
32 : NS_IMETHODIMP
33 0 : TimeService::Set(int64_t aTimeInMS) {
34 0 : hal::AdjustSystemClock(aTimeInMS - (JS_Now() / PR_USEC_PER_MSEC));
35 0 : return NS_OK;
36 : }
37 :
38 : } // namespace time
39 : } // namespace dom
40 9 : } // namespace mozilla
|