Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 //
7 // Eric Vaughan
8 // Netscape Communications
9 //
10 // See documentation in associated header file
11 //
13 #include "nsRepeatService.h"
14 #include "nsIServiceManager.h"
16 nsRepeatService* nsRepeatService::gInstance = nullptr;
18 nsRepeatService::nsRepeatService()
19 : mCallback(nullptr), mCallbackData(nullptr)
20 {
21 }
23 nsRepeatService::~nsRepeatService()
24 {
25 NS_ASSERTION(!mCallback && !mCallbackData, "Callback was not removed before shutdown");
26 }
28 nsRepeatService*
29 nsRepeatService::GetInstance()
30 {
31 if (!gInstance) {
32 gInstance = new nsRepeatService();
33 NS_IF_ADDREF(gInstance);
34 }
35 return gInstance;
36 }
38 /*static*/ void
39 nsRepeatService::Shutdown()
40 {
41 NS_IF_RELEASE(gInstance);
42 }
44 void nsRepeatService::Start(Callback aCallback, void* aCallbackData,
45 uint32_t aInitialDelay)
46 {
47 NS_PRECONDITION(aCallback != nullptr, "null ptr");
49 mCallback = aCallback;
50 mCallbackData = aCallbackData;
51 nsresult rv;
52 mRepeatTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
54 if (NS_SUCCEEDED(rv)) {
55 mRepeatTimer->InitWithCallback(this, aInitialDelay, nsITimer::TYPE_ONE_SHOT);
56 }
57 }
59 void nsRepeatService::Stop(Callback aCallback, void* aCallbackData)
60 {
61 if (mCallback != aCallback || mCallbackData != aCallbackData)
62 return;
64 //printf("Stopping repeat timer\n");
65 if (mRepeatTimer) {
66 mRepeatTimer->Cancel();
67 mRepeatTimer = nullptr;
68 }
69 mCallback = nullptr;
70 mCallbackData = nullptr;
71 }
73 NS_IMETHODIMP nsRepeatService::Notify(nsITimer *timer)
74 {
75 // do callback
76 if (mCallback)
77 mCallback(mCallbackData);
79 // start timer again.
80 if (mRepeatTimer) {
81 mRepeatTimer->InitWithCallback(this, REPEAT_DELAY, nsITimer::TYPE_ONE_SHOT);
82 }
83 return NS_OK;
84 }
86 NS_IMPL_ISUPPORTS(nsRepeatService, nsITimerCallback)