Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "AlarmHalService.h"
7 namespace mozilla {
8 namespace dom {
9 namespace alarm {
11 using namespace hal;
13 NS_IMPL_ISUPPORTS(AlarmHalService, nsIAlarmHalService)
15 void
16 AlarmHalService::Init()
17 {
18 mAlarmEnabled = RegisterTheOneAlarmObserver(this);
19 if (!mAlarmEnabled) {
20 return;
21 }
22 RegisterSystemTimezoneChangeObserver(this);
23 }
25 /* virtual */ AlarmHalService::~AlarmHalService()
26 {
27 if (mAlarmEnabled) {
28 UnregisterTheOneAlarmObserver();
29 UnregisterSystemTimezoneChangeObserver(this);
30 }
31 }
33 /* static */ StaticRefPtr<AlarmHalService> AlarmHalService::sSingleton;
35 /* static */ already_AddRefed<AlarmHalService>
36 AlarmHalService::GetInstance()
37 {
38 if (!sSingleton) {
39 sSingleton = new AlarmHalService();
40 sSingleton->Init();
41 ClearOnShutdown(&sSingleton);
42 }
44 nsRefPtr<AlarmHalService> service = sSingleton.get();
45 return service.forget();
46 }
48 NS_IMETHODIMP
49 AlarmHalService::SetAlarm(int32_t aSeconds, int32_t aNanoseconds, bool* aStatus)
50 {
51 if (!mAlarmEnabled) {
52 return NS_ERROR_FAILURE;
53 }
55 bool status = hal::SetAlarm(aSeconds, aNanoseconds);
56 if (status) {
57 *aStatus = status;
58 return NS_OK;
59 } else {
60 return NS_ERROR_FAILURE;
61 }
62 }
64 NS_IMETHODIMP
65 AlarmHalService::SetAlarmFiredCb(nsIAlarmFiredCb* aAlarmFiredCb)
66 {
67 mAlarmFiredCb = aAlarmFiredCb;
68 return NS_OK;
69 }
71 NS_IMETHODIMP
72 AlarmHalService::SetTimezoneChangedCb(nsITimezoneChangedCb* aTimeZoneChangedCb)
73 {
74 mTimezoneChangedCb = aTimeZoneChangedCb;
75 return NS_OK;
76 }
78 void
79 AlarmHalService::Notify(const void_t& aVoid)
80 {
81 if (!mAlarmFiredCb) {
82 return;
83 }
84 mAlarmFiredCb->OnAlarmFired();
85 }
87 void
88 AlarmHalService::Notify(
89 const SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo)
90 {
91 if (!mTimezoneChangedCb) {
92 return;
93 }
94 mTimezoneChangedCb->OnTimezoneChanged(
95 aSystemTimezoneChangeInfo.newTimezoneOffsetMinutes());
96 }
98 } // alarm
99 } // dom
100 } // mozilla