Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | "use strict"; |
michael@0 | 5 | |
michael@0 | 6 | var MemoryObserver = { |
michael@0 | 7 | observe: function mo_observe(aSubject, aTopic, aData) { |
michael@0 | 8 | if (aTopic == "memory-pressure") { |
michael@0 | 9 | if (aData != "heap-minimize") { |
michael@0 | 10 | this.handleLowMemory(); |
michael@0 | 11 | } |
michael@0 | 12 | // The JS engine would normally GC on this notification, but since we |
michael@0 | 13 | // disabled that in favor of this method (bug 669346), we should gc here. |
michael@0 | 14 | // See bug 784040 for when this code was ported from XUL to native Fennec. |
michael@0 | 15 | this.gc(); |
michael@0 | 16 | } else if (aTopic == "Memory:Dump") { |
michael@0 | 17 | this.dumpMemoryStats(aData); |
michael@0 | 18 | } |
michael@0 | 19 | }, |
michael@0 | 20 | |
michael@0 | 21 | handleLowMemory: function() { |
michael@0 | 22 | // do things to reduce memory usage here |
michael@0 | 23 | let tabs = BrowserApp.tabs; |
michael@0 | 24 | let selected = BrowserApp.selectedTab; |
michael@0 | 25 | for (let i = 0; i < tabs.length; i++) { |
michael@0 | 26 | if (tabs[i] != selected) { |
michael@0 | 27 | this.zombify(tabs[i]); |
michael@0 | 28 | Telemetry.addData("FENNEC_TAB_ZOMBIFIED", (Date.now() - tabs[i].lastTouchedAt) / 1000); |
michael@0 | 29 | } |
michael@0 | 30 | } |
michael@0 | 31 | Telemetry.addData("FENNEC_LOWMEM_TAB_COUNT", tabs.length); |
michael@0 | 32 | }, |
michael@0 | 33 | |
michael@0 | 34 | zombify: function(tab) { |
michael@0 | 35 | let browser = tab.browser; |
michael@0 | 36 | let data = browser.__SS_data; |
michael@0 | 37 | let extra = browser.__SS_extdata; |
michael@0 | 38 | |
michael@0 | 39 | // We need this data to correctly create and position the new browser |
michael@0 | 40 | // If this browser is already a zombie, fallback to the session data |
michael@0 | 41 | let currentURL = browser.__SS_restore ? data.entries[0].url : browser.currentURI.spec; |
michael@0 | 42 | let sibling = browser.nextSibling; |
michael@0 | 43 | let isPrivate = PrivateBrowsingUtils.isWindowPrivate(browser.contentWindow); |
michael@0 | 44 | |
michael@0 | 45 | tab.destroy(); |
michael@0 | 46 | tab.create(currentURL, { sibling: sibling, zombifying: true, delayLoad: true, isPrivate: isPrivate }); |
michael@0 | 47 | |
michael@0 | 48 | // Reattach session store data and flag this browser so it is restored on select |
michael@0 | 49 | browser = tab.browser; |
michael@0 | 50 | browser.__SS_data = data; |
michael@0 | 51 | browser.__SS_extdata = extra; |
michael@0 | 52 | browser.__SS_restore = true; |
michael@0 | 53 | browser.setAttribute("pending", "true"); |
michael@0 | 54 | }, |
michael@0 | 55 | |
michael@0 | 56 | gc: function() { |
michael@0 | 57 | window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect(); |
michael@0 | 58 | Cu.forceGC(); |
michael@0 | 59 | }, |
michael@0 | 60 | |
michael@0 | 61 | dumpMemoryStats: function(aLabel) { |
michael@0 | 62 | let memDumper = Cc["@mozilla.org/memory-info-dumper;1"].getService(Ci.nsIMemoryInfoDumper); |
michael@0 | 63 | memDumper.dumpMemoryInfoToTempDir(aLabel, /* minimize = */ false); |
michael@0 | 64 | }, |
michael@0 | 65 | }; |