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 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef nsServiceManagerUtils_h__
7 #define nsServiceManagerUtils_h__
9 #include "nsIServiceManager.h"
10 #include "nsCOMPtr.h"
12 inline
13 const nsGetServiceByCID
14 do_GetService(const nsCID& aCID)
15 {
16 return nsGetServiceByCID(aCID);
17 }
19 inline
20 const nsGetServiceByCIDWithError
21 do_GetService(const nsCID& aCID, nsresult* error)
22 {
23 return nsGetServiceByCIDWithError(aCID, error);
24 }
26 inline
27 const nsGetServiceByContractID
28 do_GetService(const char* aContractID)
29 {
30 return nsGetServiceByContractID(aContractID);
31 }
33 inline
34 const nsGetServiceByContractIDWithError
35 do_GetService( const char* aContractID, nsresult* error)
36 {
37 return nsGetServiceByContractIDWithError(aContractID, error);
38 }
40 class nsGetServiceFromCategory : public nsCOMPtr_helper
41 {
42 public:
43 nsGetServiceFromCategory(const char* aCategory, const char* aEntry,
44 nsresult* aErrorPtr)
45 : mCategory(aCategory),
46 mEntry(aEntry),
47 mErrorPtr(aErrorPtr)
48 {
49 // nothing else to do
50 }
52 virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
53 protected:
54 const char* mCategory;
55 const char* mEntry;
56 nsresult* mErrorPtr;
57 };
59 inline
60 const nsGetServiceFromCategory
61 do_GetServiceFromCategory( const char* category, const char* entry,
62 nsresult* error = 0)
63 {
64 return nsGetServiceFromCategory(category, entry, error);
65 }
67 NS_COM_GLUE nsresult
68 CallGetService(const nsCID &aClass, const nsIID &aIID, void **aResult);
70 NS_COM_GLUE nsresult
71 CallGetService(const char *aContractID, const nsIID &aIID, void **aResult);
73 // type-safe shortcuts for calling |GetService|
74 template <class DestinationType>
75 inline
76 nsresult
77 CallGetService( const nsCID &aClass,
78 DestinationType** aDestination)
79 {
80 NS_PRECONDITION(aDestination, "null parameter");
82 return CallGetService(aClass,
83 NS_GET_TEMPLATE_IID(DestinationType),
84 reinterpret_cast<void**>(aDestination));
85 }
87 template <class DestinationType>
88 inline
89 nsresult
90 CallGetService( const char *aContractID,
91 DestinationType** aDestination)
92 {
93 NS_PRECONDITION(aContractID, "null parameter");
94 NS_PRECONDITION(aDestination, "null parameter");
96 return CallGetService(aContractID,
97 NS_GET_TEMPLATE_IID(DestinationType),
98 reinterpret_cast<void**>(aDestination));
99 }
101 #endif