Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
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/. */
7 #ifndef xpcom_build_IOInterposerPrivate_h
8 #define xpcom_build_IOInterposerPrivate_h
10 /* This header file contains declarations for helper classes that are
11 to be used exclusively by IOInterposer and its observers. This header
12 file is not to be used by anything else and MUST NOT be exported! */
14 #include <prcvar.h>
15 #include <prlock.h>
17 namespace mozilla {
18 namespace IOInterposer {
20 /**
21 * The following classes are simple wrappers for PRLock and PRCondVar.
22 * IOInterposer and friends use these instead of Mozilla::Mutex et al because
23 * of the fact that IOInterposer is permitted to run until the process
24 * terminates; we can't use anything that plugs into leak checkers or deadlock
25 * detectors because IOInterposer will outlive those and generate false
26 * positives.
27 */
29 class Monitor
30 {
31 public:
32 Monitor()
33 : mLock(PR_NewLock())
34 , mCondVar(PR_NewCondVar(mLock))
35 {
36 }
38 ~Monitor()
39 {
40 PR_DestroyCondVar(mCondVar);
41 mCondVar = nullptr;
42 PR_DestroyLock(mLock);
43 mLock = nullptr;
44 }
46 void Lock()
47 {
48 PR_Lock(mLock);
49 }
51 void Unlock()
52 {
53 PR_Unlock(mLock);
54 }
56 bool Wait(PRIntervalTime aTimeout = PR_INTERVAL_NO_TIMEOUT)
57 {
58 return PR_WaitCondVar(mCondVar, aTimeout) == PR_SUCCESS;
59 }
61 bool Notify()
62 {
63 return PR_NotifyCondVar(mCondVar) == PR_SUCCESS;
64 }
66 private:
67 PRLock* mLock;
68 PRCondVar* mCondVar;
69 };
71 class MonitorAutoLock
72 {
73 public:
74 MonitorAutoLock(Monitor &aMonitor)
75 : mMonitor(aMonitor)
76 {
77 mMonitor.Lock();
78 }
80 ~MonitorAutoLock()
81 {
82 mMonitor.Unlock();
83 }
85 bool Wait(PRIntervalTime aTimeout = PR_INTERVAL_NO_TIMEOUT)
86 {
87 return mMonitor.Wait(aTimeout);
88 }
90 bool Notify()
91 {
92 return mMonitor.Notify();
93 }
95 private:
96 Monitor& mMonitor;
97 };
99 class MonitorAutoUnlock
100 {
101 public:
102 MonitorAutoUnlock(Monitor &aMonitor)
103 : mMonitor(aMonitor)
104 {
105 mMonitor.Unlock();
106 }
108 ~MonitorAutoUnlock()
109 {
110 mMonitor.Lock();
111 }
113 private:
114 Monitor& mMonitor;
115 };
117 class Mutex
118 {
119 public:
120 Mutex()
121 : mPRLock(PR_NewLock())
122 {
123 }
125 ~Mutex()
126 {
127 PR_DestroyLock(mPRLock);
128 mPRLock = nullptr;
129 }
131 void Lock()
132 {
133 PR_Lock(mPRLock);
134 }
136 void Unlock()
137 {
138 PR_Unlock(mPRLock);
139 }
141 private:
142 PRLock* mPRLock;
143 };
145 class AutoLock
146 {
147 public:
148 AutoLock(Mutex& aLock)
149 : mLock(aLock)
150 {
151 mLock.Lock();
152 }
154 ~AutoLock()
155 {
156 mLock.Unlock();
157 }
159 private:
160 Mutex& mLock;
161 };
163 } // namespace IOInterposer
164 } // namespace mozilla
166 #endif // xpcom_build_IOInterposerPrivate_h