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: 4; 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 #include "nsXPCOM.h"
7 #include "nsMemory.h"
8 #include "nsIMemory.h"
9 #include "nsXPCOMPrivate.h"
10 #include "nsDebug.h"
11 #include "nsISupportsUtils.h"
12 #include "nsCOMPtr.h"
14 ////////////////////////////////////////////////////////////////////////////////
15 // nsMemory static helper routines
17 NS_COM_GLUE nsresult
18 nsMemory::HeapMinimize(bool aImmediate)
19 {
20 nsCOMPtr<nsIMemory> mem;
21 nsresult rv = NS_GetMemoryManager(getter_AddRefs(mem));
22 if (NS_WARN_IF(NS_FAILED(rv)))
23 return rv;
25 return mem->HeapMinimize(aImmediate);
26 }
28 NS_COM_GLUE void*
29 nsMemory::Clone(const void* ptr, size_t size)
30 {
31 void* newPtr = NS_Alloc(size);
32 if (newPtr)
33 memcpy(newPtr, ptr, size);
34 return newPtr;
35 }
37 NS_COM_GLUE nsIMemory*
38 nsMemory::GetGlobalMemoryService()
39 {
40 nsIMemory* mem;
41 nsresult rv = NS_GetMemoryManager(&mem);
42 if (NS_FAILED(rv)) return nullptr;
44 return mem;
45 }
47 //----------------------------------------------------------------------