dom/apps/src/AppDownloadManager.jsm

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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.

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
michael@0 5 "use strict";
michael@0 6
michael@0 7 const Cc = Components.classes;
michael@0 8 const Ci = Components.interfaces;
michael@0 9 const Cu = Components.utils;
michael@0 10
michael@0 11 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 12
michael@0 13 XPCOMUtils.defineLazyModuleGetter(this, "FreeSpaceWatcher",
michael@0 14 "resource://gre/modules/FreeSpaceWatcher.jsm");
michael@0 15
michael@0 16 this.EXPORTED_SYMBOLS = ["AppDownloadManager"];
michael@0 17
michael@0 18 function debug(aMsg) {
michael@0 19 //dump("-*-*- AppDownloadManager.jsm : " + aMsg + "\n");
michael@0 20 }
michael@0 21
michael@0 22 this.AppDownloadManager = {
michael@0 23 // Minimum disk free space we want to keep, in bytes.
michael@0 24 // Keep synchronized with Webapps.jsm
michael@0 25 MIN_REMAINING_FREESPACE: 5 * 1024 * 1024,
michael@0 26
michael@0 27 downloads: {},
michael@0 28 count: 0,
michael@0 29 cancelFunc: null,
michael@0 30 timer: null,
michael@0 31
michael@0 32 /**
michael@0 33 * Registers the function called when we need to cancel a download.
michael@0 34 * The function will be called with a single parameter being the
michael@0 35 * manifest URL.
michael@0 36 */
michael@0 37 registerCancelFunction: function app_dlMgr_registerCancel(aFunction) {
michael@0 38 this.cancelFunc = aFunction;
michael@0 39 },
michael@0 40
michael@0 41 /**
michael@0 42 * Adds a download to the list of current downloads.
michael@0 43 * @param aManifestURL The manifest URL for the application being downloaded.
michael@0 44 * @param aDownload An opaque object representing the download.
michael@0 45 */
michael@0 46 add: function app_dlMgr_add(aManifestURL, aDownload) {
michael@0 47 debug("Adding " + aManifestURL);
michael@0 48 if (!(aManifestURL in this.downloads)) {
michael@0 49 this.count++;
michael@0 50 if (this.count == 1) {
michael@0 51 this.timer = FreeSpaceWatcher.create(this.MIN_REMAINING_FREESPACE,
michael@0 52 this._spaceWatcher.bind(this));
michael@0 53 }
michael@0 54 }
michael@0 55 this.downloads[aManifestURL] = aDownload;
michael@0 56 },
michael@0 57
michael@0 58 /**
michael@0 59 * Retrieves a download from the list of current downloads.
michael@0 60 * @param aManifestURL The manifest URL for the application being retrieved.
michael@0 61 * @return The opaque object representing the download.
michael@0 62 */
michael@0 63 get: function app_dlMgr_get(aManifestURL) {
michael@0 64 debug("Getting " + aManifestURL);
michael@0 65 if (!this.downloads[aManifestURL]) {
michael@0 66 return null;
michael@0 67 }
michael@0 68 return this.downloads[aManifestURL];
michael@0 69 },
michael@0 70
michael@0 71 /**
michael@0 72 * Removes a download of the list of current downloads.
michael@0 73 * @param aManifestURL The manifest URL for the application being removed.
michael@0 74 */
michael@0 75 remove: function app_dlMgr_remove(aManifestURL) {
michael@0 76 debug("Removing " + aManifestURL);
michael@0 77 if (aManifestURL in this.downloads) {
michael@0 78 this.count--;
michael@0 79 delete this.downloads[aManifestURL];
michael@0 80 if (this.count == 0) {
michael@0 81 FreeSpaceWatcher.stop(this.timer);
michael@0 82 }
michael@0 83 }
michael@0 84 },
michael@0 85
michael@0 86 /**
michael@0 87 * Callback for the free space watcher. This will call cancel on downloads
michael@0 88 * if needed.
michael@0 89 */
michael@0 90 _spaceWatcher: function app_dlMgr_watcher(aStatus) {
michael@0 91 debug("Disk space is now " + aStatus);
michael@0 92 if (aStatus == "free") {
michael@0 93 // Nothing to do.
michael@0 94 return;
michael@0 95 }
michael@0 96
michael@0 97 // We cancel all downloads, because we don't know which ones we could
michael@0 98 // keep running. We can improve that later if we have better heuristics,
michael@0 99 // or when we'll support pause & resume we should just pause downloads.
michael@0 100 for (let url in this.downloads) {
michael@0 101 this.cancelFunc(url, "INSUFFICIENT_STORAGE");
michael@0 102 }
michael@0 103 }
michael@0 104 }

mercurial