Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; |
michael@0 | 6 | |
michael@0 | 7 | Cu.import("resource://gre/modules/Log.jsm"); |
michael@0 | 8 | Cu.import("resource://services-common/rest.js"); |
michael@0 | 9 | Cu.import("resource://services-sync/util.js"); |
michael@0 | 10 | Cu.import("resource://services-sync/constants.js"); |
michael@0 | 11 | |
michael@0 | 12 | this.EXPORTED_SYMBOLS = ["SyncStorageRequest"]; |
michael@0 | 13 | |
michael@0 | 14 | const STORAGE_REQUEST_TIMEOUT = 5 * 60; // 5 minutes |
michael@0 | 15 | |
michael@0 | 16 | /** |
michael@0 | 17 | * RESTRequest variant for use against a Sync storage server. |
michael@0 | 18 | */ |
michael@0 | 19 | this.SyncStorageRequest = function SyncStorageRequest(uri) { |
michael@0 | 20 | RESTRequest.call(this, uri); |
michael@0 | 21 | |
michael@0 | 22 | this.authenticator = null; |
michael@0 | 23 | } |
michael@0 | 24 | SyncStorageRequest.prototype = { |
michael@0 | 25 | |
michael@0 | 26 | __proto__: RESTRequest.prototype, |
michael@0 | 27 | |
michael@0 | 28 | _logName: "Sync.StorageRequest", |
michael@0 | 29 | |
michael@0 | 30 | /** |
michael@0 | 31 | * The string to use as the base User-Agent in Sync requests. |
michael@0 | 32 | * These strings will look something like |
michael@0 | 33 | * |
michael@0 | 34 | * Firefox/4.0 FxSync/1.8.0.20100101.mobile |
michael@0 | 35 | * |
michael@0 | 36 | * or |
michael@0 | 37 | * |
michael@0 | 38 | * Firefox Aurora/5.0a1 FxSync/1.9.0.20110409.desktop |
michael@0 | 39 | */ |
michael@0 | 40 | userAgent: |
michael@0 | 41 | Services.appinfo.name + "/" + Services.appinfo.version + // Product. |
michael@0 | 42 | " FxSync/" + WEAVE_VERSION + "." + // Sync. |
michael@0 | 43 | Services.appinfo.appBuildID + ".", // Build. |
michael@0 | 44 | |
michael@0 | 45 | /** |
michael@0 | 46 | * Wait 5 minutes before killing a request. |
michael@0 | 47 | */ |
michael@0 | 48 | timeout: STORAGE_REQUEST_TIMEOUT, |
michael@0 | 49 | |
michael@0 | 50 | dispatch: function dispatch(method, data, onComplete, onProgress) { |
michael@0 | 51 | // Compose a UA string fragment from the various available identifiers. |
michael@0 | 52 | if (Svc.Prefs.get("sendVersionInfo", true)) { |
michael@0 | 53 | let ua = this.userAgent + Svc.Prefs.get("client.type", "desktop"); |
michael@0 | 54 | this.setHeader("user-agent", ua); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | if (this.authenticator) { |
michael@0 | 58 | this.authenticator(this); |
michael@0 | 59 | } else { |
michael@0 | 60 | this._log.debug("No authenticator found."); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | return RESTRequest.prototype.dispatch.apply(this, arguments); |
michael@0 | 64 | }, |
michael@0 | 65 | |
michael@0 | 66 | onStartRequest: function onStartRequest(channel) { |
michael@0 | 67 | RESTRequest.prototype.onStartRequest.call(this, channel); |
michael@0 | 68 | if (this.status == this.ABORTED) { |
michael@0 | 69 | return; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | let headers = this.response.headers; |
michael@0 | 73 | // Save the latest server timestamp when possible. |
michael@0 | 74 | if (headers["x-weave-timestamp"]) { |
michael@0 | 75 | SyncStorageRequest.serverTime = parseFloat(headers["x-weave-timestamp"]); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | // This is a server-side safety valve to allow slowing down |
michael@0 | 79 | // clients without hurting performance. |
michael@0 | 80 | if (headers["x-weave-backoff"]) { |
michael@0 | 81 | Svc.Obs.notify("weave:service:backoff:interval", |
michael@0 | 82 | parseInt(headers["x-weave-backoff"], 10)); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | if (this.response.success && headers["x-weave-quota-remaining"]) { |
michael@0 | 86 | Svc.Obs.notify("weave:service:quota:remaining", |
michael@0 | 87 | parseInt(headers["x-weave-quota-remaining"], 10)); |
michael@0 | 88 | } |
michael@0 | 89 | } |
michael@0 | 90 | }; |