Bug 787273 - Part 3: Don't rely on Identity in SyncStorageRequest; r=rnewman

The Identity singleton is going away. This refactors SyncStorageRequest
to not use it. Behavior now works like Resource. Instances are obtained
from the Service singleton and have authentication functionality
attached.
This commit is contained in:
Gregory Szorc 2012-09-14 16:02:32 -07:00
parent 6aed806b4c
commit 86496151d6
3 changed files with 20 additions and 10 deletions

View File

@ -7,7 +7,6 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://services-common/log4moz.js");
Cu.import("resource://services-common/rest.js");
Cu.import("resource://services-sync/util.js");
Cu.import("resource://services-sync/identity.js");
Cu.import("resource://services-sync/constants.js");
const EXPORTED_SYMBOLS = ["SyncStorageRequest"];
@ -19,6 +18,8 @@ const STORAGE_REQUEST_TIMEOUT = 5 * 60; // 5 minutes
*/
function SyncStorageRequest(uri) {
RESTRequest.call(this, uri);
this.authenticator = null;
}
SyncStorageRequest.prototype = {
@ -53,9 +54,8 @@ SyncStorageRequest.prototype = {
this.setHeader("user-agent", ua);
}
let authenticator = Identity.getRESTRequestAuthenticator();
if (authenticator) {
authenticator(this);
if (this.authenticator) {
this.authenticator(this);
} else {
this._log.debug("No authenticator found.");
}

View File

@ -481,6 +481,16 @@ WeaveSvc.prototype = {
return res;
},
/**
* Obtain a SyncStorageRequest instance with authentication credentials.
*/
getStorageRequest: function getStorageRequest(url) {
let request = new SyncStorageRequest(url);
request.authenticator = this._identity.getRESTRequestAuthenticator();
return request;
},
/**
* Perform the info fetch as part of a login or key fetch.
*/
@ -1430,7 +1440,7 @@ WeaveSvc.prototype = {
let info_type = "info/" + type;
this._log.trace("Retrieving '" + info_type + "'...");
let url = this.userBaseURL + info_type;
return new SyncStorageRequest(url).get(function onComplete(error) {
return this.getStorageRequest(url).get(function onComplete(error) {
// Note: 'this' is the request.
if (error) {
this._log.debug("Failed to retrieve '" + info_type + "': " +

View File

@ -1,11 +1,11 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
Cu.import("resource://services-sync/rest.js");
Cu.import("resource://services-sync/util.js");
Cu.import("resource://services-sync/identity.js");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-common/log4moz.js");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/rest.js");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/util.js");
const STORAGE_REQUEST_RESOURCE_URL = TEST_SERVER_URL + "resource";
@ -59,7 +59,7 @@ add_test(function test_auth() {
setBasicCredentials("johndoe", "ilovejane", "XXXXXXXXX");
let request = new SyncStorageRequest(STORAGE_REQUEST_RESOURCE_URL);
let request = Service.getStorageRequest(STORAGE_REQUEST_RESOURCE_URL);
request.get(function (error) {
do_check_eq(error, null);
do_check_eq(this.response.status, 200);