Skip to content

Commit

Permalink
Bug 787273 - Part 3: Don't rely on Identity in SyncStorageRequest; r=…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
indygreg committed Sep 14, 2012
1 parent ec4fb8a commit d613262
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
8 changes: 4 additions & 4 deletions services/sync/modules/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -19,6 +18,8 @@ const STORAGE_REQUEST_TIMEOUT = 5 * 60; // 5 minutes
*/
function SyncStorageRequest(uri) {
RESTRequest.call(this, uri);

this.authenticator = null;
}
SyncStorageRequest.prototype = {

Expand Down Expand Up @@ -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.");
}
Expand Down
12 changes: 11 additions & 1 deletion services/sync/modules/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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 + "': " +
Expand Down
8 changes: 4 additions & 4 deletions services/sync/tests/unit/test_syncstoragerequest.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

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");
Cu.import("resource://services-sync/identity.js");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-common/log4moz.js");

const STORAGE_REQUEST_RESOURCE_URL = TEST_SERVER_URL + "resource";

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d613262

Please sign in to comment.