Bug 1421968 - Fix more instances of .getService to use Services.jsm where possible. r?Mossop draft
authorMark Banner <standard8@mozilla.com>
Thu, 30 Nov 2017 12:04:16 +0000
changeset 707646 fdf2c537900e3b123feb788111fa92bac9c21d0d
parent 707503 b4cef8d1dff06a1ec2b9bb17211c0c3c7f5b76fa
child 707647 9e690062e7b70114f2596733679103f094c68888
push id92187
push userbmo:standard8@mozilla.com
push dateTue, 05 Dec 2017 16:50:05 +0000
reviewersMossop
bugs1421968
milestone59.0a1
Bug 1421968 - Fix more instances of .getService to use Services.jsm where possible. r?Mossop MozReview-Commit-ID: 2EbsWq7VPrI
caps/tests/mochitest/test_disallowInheritPrincipal.html
ipc/testshell/tests/test_ipcshell.js
ipc/testshell/tests/test_ipcshell_child.js
storage/test/unit/head_storage.js
storage/test/unit/test_bug-365166.js
storage/test/unit/test_cache_size.js
storage/test/unit/test_chunk_growth.js
storage/test/unit/test_connection_asyncClose.js
storage/test/unit/test_levenshtein.js
storage/test/unit/test_locale_collation.js
storage/test/unit/test_page_size_is_32k.js
storage/test/unit/test_sqlite_secure_delete.js
storage/test/unit/test_statement_executeAsync.js
storage/test/unit/test_storage_connection.js
storage/test/unit/test_storage_service.js
storage/test/unit/test_storage_service_unshared.js
storage/test/unit/test_telemetry_vfs.js
storage/test/unit/vacuumParticipant.js
tools/quitter/QuitterObserver.js
--- a/caps/tests/mochitest/test_disallowInheritPrincipal.html
+++ b/caps/tests/mochitest/test_disallowInheritPrincipal.html
@@ -27,19 +27,17 @@ var secMan = SpecialPowers.Cc["@mozilla.
                        .getService(nsIScriptSecurityManager);
 var sysPrincipal = secMan.getSystemPrincipal();
 isnot(sysPrincipal, undefined, "Should have a principal");
 isnot(sysPrincipal, null, "Should have a non-null principal");
 is(secMan.isSystemPrincipal(sysPrincipal), true,
    "Should have system principal here");
 
 
-var ioService = SpecialPowers.Cc["@mozilla.org/network/io-service;1"].
-                getService(SpecialPowers.Ci.nsIIOService);
-var inheritingURI = ioService.newURI("javascript:1+1");
+var inheritingURI = SpecialPowers.Services.io.newURI("javascript:1+1");
 
 // First try a normal call to checkLoadURIWithPrincipal
 try {
   secMan.checkLoadURIWithPrincipal(sysPrincipal, inheritingURI,
                                    nsIScriptSecurityManager.STANDARD);
   ok(true, "checkLoadURI allowed the load");
 } catch (e) {
   ok(false, "checkLoadURI failed unexpectedly: " + e);
--- a/ipc/testshell/tests/test_ipcshell.js
+++ b/ipc/testshell/tests/test_ipcshell.js
@@ -1,11 +1,12 @@
 var Cc = Components.classes;
 var Ci = Components.interfaces;
 
+// eslint-disable-next-line mozilla/use-services
 const runtime = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
 
 function callback(result) {
   do_check_eq(result, Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT);
   do_test_finished();
 }
 
 function run_test() {
--- a/ipc/testshell/tests/test_ipcshell_child.js
+++ b/ipc/testshell/tests/test_ipcshell_child.js
@@ -1,8 +1,9 @@
 var Cc = Components.classes;
 var Ci = Components.interfaces;
 
+// eslint-disable-next-line mozilla/use-services
 const runtime = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
 
 function run_test() {
   do_check_eq(runtime.processType, Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
 }
--- a/storage/test/unit/head_storage.js
+++ b/storage/test/unit/head_storage.js
@@ -3,27 +3,25 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 const Ci = Components.interfaces;
 const Cc = Components.classes;
 const Cr = Components.results;
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/AppConstants.jsm");
 
 
 do_get_profile();
-var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
-             getService(Ci.nsIProperties);
-
 var gDBConn = null;
 
 function getTestDB() {
-  var db = dirSvc.get("ProfD", Ci.nsIFile);
+  var db = Services.dirsvc.get("ProfD", Ci.nsIFile);
   db.append("test_storage.sqlite");
   return db;
 }
 
 /**
  * Obtains a corrupt database to test against.
  */
 function getCorruptDB() {
@@ -77,57 +75,53 @@ function asyncCleanup() {
   // we need to null out the database variable to get a new connection the next
   // time getOpenedDatabase is called
   gDBConn = null;
 
   // removing test db
   deleteTestDB();
 }
 
-function getService() {
-  return Cc["@mozilla.org/storage/service;1"].getService(Ci.mozIStorageService);
-}
-
 /**
  * Get a connection to the test database.  Creates and caches the connection
  * if necessary, otherwise reuses the existing cached connection. This
  * connection shares its cache.
  *
  * @returns the mozIStorageConnection for the file.
  */
 function getOpenedDatabase() {
   if (!gDBConn) {
-    gDBConn = getService().openDatabase(getTestDB());
+    gDBConn = Services.storage.openDatabase(getTestDB());
   }
   return gDBConn;
 }
 
 /**
  * Get a connection to the test database.  Creates and caches the connection
  * if necessary, otherwise reuses the existing cached connection. This
  * connection doesn't share its cache.
  *
  * @returns the mozIStorageConnection for the file.
  */
 function getOpenedUnsharedDatabase() {
   if (!gDBConn) {
-    gDBConn = getService().openUnsharedDatabase(getTestDB());
+    gDBConn = Services.storage.openUnsharedDatabase(getTestDB());
   }
   return gDBConn;
 }
 
 /**
  * Obtains a specific database to use.
  *
  * @param aFile
  *        The nsIFile representing the db file to open.
  * @returns the mozIStorageConnection for the file.
  */
 function getDatabase(aFile) {
-  return getService().openDatabase(aFile);
+  return Services.storage.openDatabase(aFile);
 }
 
 function createStatement(aSQL) {
   return getOpenedDatabase().createStatement(aSQL);
 }
 
 /**
  * Creates an asynchronous SQL statement.
@@ -273,17 +267,17 @@ function openAsyncDatabase(file, options
     let properties;
     if (options) {
       properties = Cc["@mozilla.org/hash-property-bag;1"].
           createInstance(Ci.nsIWritablePropertyBag);
       for (let k in options) {
         properties.setProperty(k, options[k]);
       }
     }
-    getService().openAsyncDatabase(file, properties, function(status, db) {
+    Services.storage.openAsyncDatabase(file, properties, function(status, db) {
       if (Components.isSuccessCode(status)) {
         resolve(db.QueryInterface(Ci.mozIStorageAsyncConnection));
       } else {
         reject(status);
       }
     });
   });
 }
--- a/storage/test/unit/test_bug-365166.js
+++ b/storage/test/unit/test_bug-365166.js
@@ -5,19 +5,17 @@ function run_test() {
   test("user");
   test("schema");
 
   function test(param) {
     var colName = param + "_version";
     var sql = "PRAGMA " + colName;
 
     var file = getTestDB();
-    var storageService = Components.classes["@mozilla.org/storage/service;1"].
-                         getService(Components.interfaces.mozIStorageService);
-    var conn = storageService.openDatabase(file);
+    var conn = Services.storage.openDatabase(file);
     var statement = conn.createStatement(sql);
     try {
       // This shouldn't crash:
       do_check_eq(statement.getColumnName(0), colName);
     } finally {
       statement.reset();
       statement.finalize();
     }
--- a/storage/test/unit/test_cache_size.js
+++ b/storage/test/unit/test_cache_size.js
@@ -39,17 +39,17 @@ function check_size(dbOpener, file, page
   // Check cache size is as expected.
   stmt = db.createStatement("PRAGMA cache_size");
   do_check_true(stmt.executeStep());
   do_check_eq(stmt.row.cache_size, expectedCacheSize);
   stmt.finalize();
 }
 
 function new_file(name) {
-  let file = dirSvc.get("ProfD", Ci.nsIFile);
+  let file = Services.dirsvc.get("ProfD", Ci.nsIFile);
   file.append(name + ".sqlite");
   do_check_false(file.exists());
   return file;
 }
 
 function run_test() {
   const kExpectedCacheSize = -2048; // 2MiB
 
@@ -58,12 +58,12 @@ function run_test() {
     4096,
     32768,
   ];
 
   for (let i = 0; i < pageSizes.length; i++) {
     let pageSize = pageSizes[i];
     check_size(getDatabase,
                new_file("shared" + pageSize), pageSize, kExpectedCacheSize);
-    check_size(getService().openUnsharedDatabase,
+    check_size(Services.storage.openUnsharedDatabase,
                new_file("unshared" + pageSize), pageSize, kExpectedCacheSize);
   }
 }
--- a/storage/test/unit/test_chunk_growth.js
+++ b/storage/test/unit/test_chunk_growth.js
@@ -2,17 +2,17 @@
 
 function run_sql(d, sql) {
   var stmt = d.createStatement(sql);
   stmt.execute();
   stmt.finalize();
 }
 
 function new_file(name) {
-  var file = dirSvc.get("ProfD", Ci.nsIFile);
+  var file = Services.dirsvc.get("ProfD", Ci.nsIFile);
   file.append(name);
   return file;
 }
 
 function get_size(name) {
   return new_file(name).fileSize;
 }
 
@@ -44,9 +44,8 @@ function run_test() {
   }
   /* In addition to growing in chunk-size increments, the db
    * should shrink in chunk-size increments too.
    */
   run_sql(d, "DELETE FROM bloat");
   run_sql(d, "VACUUM");
   do_check_true(get_size(filename) >= CHUNK_SIZE);
 }
-
--- a/storage/test/unit/test_connection_asyncClose.js
+++ b/storage/test/unit/test_connection_asyncClose.js
@@ -27,17 +27,17 @@
 /**
  * Sanity check that our close indeed happens after asynchronously executed
  * statements scheduled during the same turn of the event loop.  Note that we
  * just care that the statement says it completed without error, we're not
  * worried that the close will happen and then the statement will magically
  * complete.
  */
 add_task(async function test_asyncClose_does_not_complete_before_statements() {
-  let db = getService().openDatabase(getTestDB());
+  let db = Services.storage.openDatabase(getTestDB());
   let stmt = db.createStatement("SELECT * FROM sqlite_master");
   // Issue the executeAsync but don't yield for it...
   let asyncStatementPromise = executeAsync(stmt);
   stmt.finalize();
 
   // Issue the close.  (And now the order of yielding doesn't matter.)
   // Branch coverage: (asyncThread && mDBConn)
   await asyncClose(db);
@@ -76,17 +76,17 @@ if (!AppConstants.DEBUG) {
 /**
  * Create a sync db connection and never take it asynchronous and then call
  * asyncClose on it.  This will bring the async thread to life to perform the
  * shutdown to avoid blocking the main thread, although we won't be able to
  * tell the difference between this happening and the method secretly shunting
  * to close().
  */
 add_task(async function test_asyncClose_on_sync_db() {
-  let db = getService().openDatabase(getTestDB());
+  let db = Services.storage.openDatabase(getTestDB());
 
   // Branch coverage: (!asyncThread && mDBConn)
   await asyncClose(db);
   ok(true, "closed sync connection asynchronously");
 });
 
 /**
  * Fail to asynchronously open a DB in order to get an async thread existing
--- a/storage/test/unit/test_levenshtein.js
+++ b/storage/test/unit/test_levenshtein.js
@@ -1,17 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // This file tests the Levenshtein Distance function we've registered.
 
 function createUtf16Database() {
   print("Creating the in-memory UTF-16-encoded database.");
-  let conn = getService().openSpecialDatabase("memory");
+  let conn = Services.storage.openSpecialDatabase("memory");
   conn.executeSimpleSQL("PRAGMA encoding = 'UTF-16'");
 
   print("Make sure the encoding was set correctly and is now UTF-16.");
   let stmt = conn.createStatement("PRAGMA encoding");
   do_check_true(stmt.executeStep());
   let enc = stmt.getString(0);
   stmt.finalize();
 
@@ -59,12 +59,8 @@ function testLevenshtein(db) {
   var dashes1000 = Array(1001).join("-");
   check_levenshtein(db, dots1000, dashes1000, 1000);
 }
 
 function run_test() {
   testLevenshtein(getOpenedDatabase());
   testLevenshtein(createUtf16Database());
 }
-
-
-
-
--- a/storage/test/unit/test_locale_collation.js
+++ b/storage/test/unit/test_locale_collation.js
@@ -39,17 +39,17 @@ function cleanupLocaleTests() {
 /**
  * Creates a test database similar to the default one created in
  * head_storage.js, except that this one uses UTF-16 encoding.
  *
  * @return A connection to the database.
  */
 function createUtf16Database() {
   print("Creating the in-memory UTF-16-encoded database.");
-  let conn = getService().openSpecialDatabase("memory");
+  let conn = Services.storage.openSpecialDatabase("memory");
   conn.executeSimpleSQL("PRAGMA encoding = 'UTF-16'");
 
   print("Make sure the encoding was set correctly and is now UTF-16.");
   let stmt = conn.createStatement("PRAGMA encoding");
   do_check_true(stmt.executeStep());
   let enc = stmt.getString(0);
   stmt.finalize();
 
--- a/storage/test/unit/test_page_size_is_32k.js
+++ b/storage/test/unit/test_page_size_is_32k.js
@@ -14,19 +14,18 @@ function check_size(db) {
   stmt.finalize();
   stmt = db.createStatement("PRAGMA cache_size");
   stmt.executeStep();
   do_check_eq(stmt.getInt32(0), kExpectedCacheSize);
   stmt.finalize();
 }
 
 function new_file(name) {
-  var file = dirSvc.get("ProfD", Ci.nsIFile);
+  var file = Services.dirsvc.get("ProfD", Ci.nsIFile);
   file.append(name + ".sqlite");
   do_check_false(file.exists());
   return file;
 }
 
 function run_test() {
   check_size(getDatabase(new_file("shared32k")));
-  check_size(getService().openUnsharedDatabase(new_file("unshared32k")));
+  check_size(Services.storage.openUnsharedDatabase(new_file("unshared32k")));
 }
-
--- a/storage/test/unit/test_sqlite_secure_delete.js
+++ b/storage/test/unit/test_sqlite_secure_delete.js
@@ -30,17 +30,17 @@ function getFileContents(aFile) {
 }
 
 // Tests
 
 add_test(function test_delete_removes_data() {
   const TEST_STRING = "SomeRandomStringToFind";
 
   let file = getTestDB();
-  let db = getService().openDatabase(file);
+  let db = Services.storage.openDatabase(file);
 
   // Create the table and insert the data.
   db.createTable("test", "data TEXT");
   let stmt = db.createStatement("INSERT INTO test VALUES(:data)");
   stmt.params.data = TEST_STRING;
   try {
     stmt.execute();
   } finally {
--- a/storage/test/unit/test_statement_executeAsync.js
+++ b/storage/test/unit/test_statement_executeAsync.js
@@ -130,18 +130,17 @@ function execAsync(aStmt, aOptions, aRes
     pending = aStmt.executeAsync(listener);
   } else {
     aStmt.executeAsync(listener);
   }
 
   if ("cancel" in aOptions && aOptions.cancel)
     pending.cancel();
 
-  let tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
-  tm.spinEventLoopUntil(() => completed || _quit);
+  Services.tm.spinEventLoopUntil(() => completed || _quit);
 
   return pending;
 }
 
 /**
  * Make sure that illegal SQL generates the expected runtime error and does not
  * result in any crashes.  Async-only since the synchronous case generates the
  * error synchronously (and is tested elsewhere).
--- a/storage/test/unit/test_storage_connection.js
+++ b/storage/test/unit/test_storage_connection.js
@@ -156,17 +156,17 @@ add_task(async function test_set_schemaV
   msc.schemaVersion = version;
   do_check_eq(version, msc.schemaVersion);
 });
 
 add_task(async function test_createTable() {
   var temp = getTestDB().parent;
   temp.append("test_db_table");
   try {
-    var con = getService().openDatabase(temp);
+    var con = Services.storage.openDatabase(temp);
     con.createTable("a", "");
   } catch (e) {
     if (temp.exists()) {
       try {
         temp.remove(false);
       } catch (e2) {
         // Do nothing.
       }
@@ -200,18 +200,17 @@ add_task(async function test_close_does_
     ran: false,
     run() {
       this.ran = true;
     },
   };
 
   // Post the event before we call close, so it would run if the event loop was
   // spun during close.
-  Cc["@mozilla.org/thread-manager;1"].
-    getService(Ci.nsIThreadManager).dispatchToMainThread(event);
+  Services.tm.dispatchToMainThread(event);
 
   // Sanity check, then close the database.  Afterwards, we should not have ran!
   do_check_false(event.ran);
   getOpenedDatabase().close();
   do_check_false(event.ran);
 
   // Reset gDBConn so that later tests will get a new connection object.
   gDBConn = null;
@@ -273,17 +272,17 @@ if (!AppConstants.DEBUG) {
     let db = getOpenedDatabase();
     Assert.throws(() => db.close(), /NS_ERROR_UNEXPECTED/);
     // Reset gDBConn so that later tests will get a new connection object.
     gDBConn = null;
   });
 }
 
 add_task(async function test_clone_optional_param() {
-  let db1 = getService().openUnsharedDatabase(getTestDB());
+  let db1 = Services.storage.openUnsharedDatabase(getTestDB());
   let db2 = db1.clone();
   do_check_true(db2.connectionReady);
 
   // A write statement should not fail here.
   let stmt = db2.createStatement("INSERT INTO test (name) VALUES (:name)");
   stmt.params.name = "dwitte";
   stmt.execute();
   stmt.finalize();
@@ -421,17 +420,17 @@ add_task(async function test_async_open_
   });
   do_check_true(found);
   stmt.finalize();
   await asyncClose(adb);
 });
 
 add_task(async function test_clone_trivial_async() {
   do_print("Open connection");
-  let db = getService().openDatabase(getTestDB());
+  let db = Services.storage.openDatabase(getTestDB());
   do_check_true(db instanceof Ci.mozIStorageAsyncConnection);
   do_print("AsyncClone connection");
   let clone = await asyncClone(db, true);
   do_check_true(clone instanceof Ci.mozIStorageAsyncConnection);
   do_check_false(clone instanceof Ci.mozIStorageConnection);
   do_print("Close connection");
   await asyncClose(db);
   do_print("Close clone");
@@ -480,17 +479,17 @@ add_task(async function test_clone_no_op
   await asyncClose(adb2);
   do_print("First db closed");
 
   await asyncClose(adb1);
   do_print("Second db closed");
 });
 
 add_task(async function test_clone_readonly() {
-  let db1 = getService().openUnsharedDatabase(getTestDB());
+  let db1 = Services.storage.openUnsharedDatabase(getTestDB());
   let db2 = db1.clone(true);
   do_check_true(db2.connectionReady);
 
   // A write statement should fail here.
   let stmt = db2.createStatement("INSERT INTO test (name) VALUES (:name)");
   stmt.params.name = "reed";
   expectError(Cr.NS_ERROR_FILE_READ_ONLY, () => stmt.execute());
   stmt.finalize();
@@ -500,17 +499,17 @@ add_task(async function test_clone_reado
   do_check_true(stmt.executeStep());
   stmt.finalize();
 
   db1.close();
   db2.close();
 });
 
 add_task(async function test_clone_shared_readonly() {
-  let db1 = getService().openDatabase(getTestDB());
+  let db1 = Services.storage.openDatabase(getTestDB());
   let db2 = db1.clone(true);
   do_check_true(db2.connectionReady);
 
   let stmt = db2.createStatement("INSERT INTO test (name) VALUES (:name)");
   stmt.params.name = "parker";
   // TODO currently SQLite does not actually work correctly here.  The behavior
   //      we want is commented out, and the current behavior is being tested
   //      for.  Our IDL comments will have to be updated when this starts to
@@ -529,24 +528,24 @@ add_task(async function test_clone_share
 });
 
 add_task(async function test_close_clone_fails() {
   let calls = [
     "openDatabase",
     "openUnsharedDatabase",
   ];
   calls.forEach(function(methodName) {
-    let db = getService()[methodName](getTestDB());
+    let db = Services.storage[methodName](getTestDB());
     db.close();
     expectError(Cr.NS_ERROR_NOT_INITIALIZED, () => db.clone());
   });
 });
 
 add_task(async function test_memory_clone_fails() {
-  let db = getService().openSpecialDatabase("memory");
+  let db = Services.storage.openSpecialDatabase("memory");
   db.close();
   expectError(Cr.NS_ERROR_NOT_INITIALIZED, () => db.clone());
 });
 
 add_task(async function test_clone_copies_functions() {
   const FUNC_NAME = "test_func";
   let calls = [
     "openDatabase",
@@ -554,17 +553,17 @@ add_task(async function test_clone_copie
   ];
   let functionMethods = [
     "createFunction",
     "createAggregateFunction",
   ];
   calls.forEach(function(methodName) {
     [true, false].forEach(function(readOnly) {
       functionMethods.forEach(function(functionMethod) {
-        let db1 = getService()[methodName](getTestDB());
+        let db1 = Services.storage[methodName](getTestDB());
         // Create a function for db1.
         db1[functionMethod](FUNC_NAME, 1, {
           onFunctionCall: () => 0,
           onStep: () => 0,
           onFinal: () => 0,
         });
 
         // Clone it, and make sure the function exists still.
@@ -600,17 +599,17 @@ add_task(async function test_clone_copie
   ];
   let functionMethods = [
     "createFunction",
     "createAggregateFunction",
   ];
   calls.forEach(function(methodName) {
     [true, false].forEach(function(readOnly) {
       functionMethods.forEach(function(functionMethod) {
-        let db1 = getService()[methodName](getTestDB());
+        let db1 = Services.storage[methodName](getTestDB());
         // Create a function for db1.
         let func = new test_func();
         db1[functionMethod](FUNC_NAME, 1, func);
         do_check_false(func.called);
 
         // Clone it, and make sure the function gets called.
         let db2 = db1.clone(readOnly);
         let stmt = db2.createStatement("SELECT " + FUNC_NAME + "(id) FROM test");
@@ -631,17 +630,17 @@ add_task(async function test_clone_copie
     { name: "foreign_keys", value: 1, copied: true },
     { name: "journal_size_limit", value: 524288, copied: true },
     { name: "synchronous", value: 2, copied: true },
     { name: "wal_autocheckpoint", value: 16, copied: true },
     { name: "busy_timeout", value: 50, copied: true },
     { name: "ignore_check_constraints", value: 1, copied: false },
   ];
 
-  let db1 = getService().openUnsharedDatabase(getTestDB());
+  let db1 = Services.storage.openUnsharedDatabase(getTestDB());
 
   // Sanity check initial values are different from enforced ones.
   PRAGMAS.forEach(function(pragma) {
     let stmt = db1.createStatement("PRAGMA " + pragma.name);
     do_check_true(stmt.executeStep());
     do_check_neq(pragma.value, stmt.getInt32(0));
     stmt.finalize();
   });
@@ -673,17 +672,17 @@ add_task(async function test_readonly_cl
     { name: "foreign_keys", value: 1, copied: false },
     { name: "journal_size_limit", value: 524288, copied: false },
     { name: "synchronous", value: 2, copied: false },
     { name: "wal_autocheckpoint", value: 16, copied: false },
     { name: "busy_timeout", value: 50, copied: false },
     { name: "ignore_check_constraints", value: 1, copied: false },
   ];
 
-  let db1 = getService().openUnsharedDatabase(getTestDB());
+  let db1 = Services.storage.openUnsharedDatabase(getTestDB());
 
   // Sanity check initial values are different from enforced ones.
   PRAGMAS.forEach(function(pragma) {
     let stmt = db1.createStatement("PRAGMA " + pragma.name);
     do_check_true(stmt.executeStep());
     do_check_neq(pragma.value, stmt.getInt32(0));
     stmt.finalize();
   });
@@ -704,23 +703,23 @@ add_task(async function test_readonly_cl
     stmt.finalize();
   });
 
   db1.close();
   db2.close();
 });
 
 add_task(async function test_clone_attach_database() {
-  let db1 = getService().openUnsharedDatabase(getTestDB());
+  let db1 = Services.storage.openUnsharedDatabase(getTestDB());
 
   let c = 0;
   function attachDB(conn, name) {
-    let file = dirSvc.get("ProfD", Ci.nsIFile);
+    let file = Services.dirsvc.get("ProfD", Ci.nsIFile);
     file.append("test_storage_" + (++c) + ".sqlite");
-    let db = getService().openUnsharedDatabase(file);
+    let db = Services.storage.openUnsharedDatabase(file);
     conn.executeSimpleSQL(`ATTACH DATABASE '${db.databaseFile.path}' AS ${name}`);
     db.close();
   }
   attachDB(db1, "attached_1");
   attachDB(db1, "attached_2");
 
   // These should not throw.
   let stmt = db1.createStatement("SELECT * FROM attached_1.sqlite_master");
@@ -750,17 +749,17 @@ add_task(async function test_clone_attac
 
   db1.close();
   db2.close();
   db3.close();
 });
 
 add_task(async function test_async_clone_with_temp_trigger_and_table() {
   do_print("Open connection");
-  let db = getService().openDatabase(getTestDB());
+  let db = Services.storage.openDatabase(getTestDB());
   do_check_true(db instanceof Ci.mozIStorageAsyncConnection);
 
   do_print("Set up tables on original connection");
   let createQueries = [
     `CREATE TEMP TABLE test_temp(name TEXT)`,
     `CREATE INDEX test_temp_idx ON test_temp(name)`,
     `CREATE TEMP TRIGGER test_temp_afterdelete_trigger
      AFTER DELETE ON test_temp FOR EACH ROW
@@ -812,17 +811,17 @@ add_task(async function test_async_clone
   do_print("Clean up");
   for (let conn of [db, readWriteClone, readOnlyClone]) {
     await asyncClose(conn);
   }
 });
 
 add_task(async function test_sync_clone_in_transaction() {
   do_print("Open connection");
-  let db = getService().openDatabase(getTestDB());
+  let db = Services.storage.openDatabase(getTestDB());
   do_check_true(db instanceof Ci.mozIStorageAsyncConnection);
 
   do_print("Begin transaction on main connection");
   db.beginTransaction();
 
   do_print("Create temp table and trigger in transaction");
   let createQueries = [
     `CREATE TEMP TABLE test_temp(name TEXT)`,
@@ -854,17 +853,17 @@ add_task(async function test_sync_clone_
   do_print("Clean up");
 
   db.close();
   clone.close();
 });
 
 add_task(async function test_sync_clone_with_function() {
   do_print("Open connection");
-  let db = getService().openDatabase(getTestDB());
+  let db = Services.storage.openDatabase(getTestDB());
   do_check_true(db instanceof Ci.mozIStorageAsyncConnection);
 
   do_print("Create SQL function");
   function storeLastInsertedNameFunc() {
     this.name = null;
   }
   storeLastInsertedNameFunc.prototype = {
     onFunctionCall(args) {
--- a/storage/test/unit/test_storage_service.js
+++ b/storage/test/unit/test_storage_service.js
@@ -4,60 +4,60 @@
 
 // This file tests the functions of mozIStorageService except for
 // openUnsharedDatabase, which is tested by test_storage_service_unshared.js.
 
 const BACKUP_FILE_NAME = "test_storage.sqlite.backup";
 
 function test_openSpecialDatabase_invalid_arg() {
   try {
-    getService().openSpecialDatabase("abcd");
+    Services.storage.openSpecialDatabase("abcd");
     do_throw("We should not get here!");
   } catch (e) {
     print(e);
     print("e.result is " + e.result);
     do_check_eq(Cr.NS_ERROR_INVALID_ARG, e.result);
   }
 }
 
 function test_openDatabase_null_file() {
   try {
-    getService().openDatabase(null);
+    Services.storage.openDatabase(null);
     do_throw("We should not get here!");
   } catch (e) {
     print(e);
     print("e.result is " + e.result);
     do_check_eq(Cr.NS_ERROR_INVALID_ARG, e.result);
   }
 }
 
 function test_openUnsharedDatabase_null_file() {
   try {
-    getService().openUnsharedDatabase(null);
+    Services.storage.openUnsharedDatabase(null);
     do_throw("We should not get here!");
   } catch (e) {
     print(e);
     print("e.result is " + e.result);
     do_check_eq(Cr.NS_ERROR_INVALID_ARG, e.result);
   }
 }
 
 function test_openDatabase_file_DNE() {
   // the file should be created after calling
   var db = getTestDB();
   do_check_false(db.exists());
-  getService().openDatabase(db);
+  Services.storage.openDatabase(db);
   do_check_true(db.exists());
 }
 
 function test_openDatabase_file_exists() {
   // it should already exist from our last test
   var db = getTestDB();
   do_check_true(db.exists());
-  getService().openDatabase(db);
+  Services.storage.openDatabase(db);
   do_check_true(db.exists());
 }
 
 function test_corrupt_db_throws_with_openDatabase() {
   try {
     getDatabase(getCorruptDB());
     do_throw("should not be here");
   } catch (e) {
@@ -72,39 +72,39 @@ function test_fake_db_throws_with_openDa
   } catch (e) {
     do_check_eq(Cr.NS_ERROR_FILE_CORRUPTED, e.result);
   }
 }
 
 function test_backup_not_new_filename() {
   const fname = getTestDB().leafName;
 
-  var backup = getService().backupDatabaseFile(getTestDB(), fname);
+  var backup = Services.storage.backupDatabaseFile(getTestDB(), fname);
   do_check_neq(fname, backup.leafName);
 
   backup.remove(false);
 }
 
 function test_backup_new_filename() {
-  var backup = getService().backupDatabaseFile(getTestDB(), BACKUP_FILE_NAME);
+  var backup = Services.storage.backupDatabaseFile(getTestDB(), BACKUP_FILE_NAME);
   do_check_eq(BACKUP_FILE_NAME, backup.leafName);
 
   backup.remove(false);
 }
 
 function test_backup_new_folder() {
   var parentDir = getTestDB().parent;
   parentDir.append("test_storage_temp");
   if (parentDir.exists())
     parentDir.remove(true);
   parentDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
   do_check_true(parentDir.exists());
 
-  var backup = getService().backupDatabaseFile(getTestDB(), BACKUP_FILE_NAME,
-                                               parentDir);
+  var backup = Services.storage.backupDatabaseFile(getTestDB(), BACKUP_FILE_NAME,
+                                                   parentDir);
   do_check_eq(BACKUP_FILE_NAME, backup.leafName);
   do_check_true(parentDir.equals(backup.parent));
 
   parentDir.remove(true);
 }
 
 var tests = [
   test_openSpecialDatabase_invalid_arg,
@@ -121,9 +121,8 @@ var tests = [
 
 function run_test() {
   for (var i = 0; i < tests.length; i++) {
     tests[i]();
   }
 
   cleanup();
 }
-
--- a/storage/test/unit/test_storage_service_unshared.js
+++ b/storage/test/unit/test_storage_service_unshared.js
@@ -3,30 +3,29 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // This file tests the openUnsharedDatabase function of mozIStorageService.
 
 function test_openUnsharedDatabase_file_DNE() {
   // the file should be created after calling
   var db = getTestDB();
   do_check_false(db.exists());
-  getService().openUnsharedDatabase(db);
+  Services.storage.openUnsharedDatabase(db);
   do_check_true(db.exists());
 }
 
 function test_openUnsharedDatabase_file_exists() {
   // it should already exist from our last test
   var db = getTestDB();
   do_check_true(db.exists());
-  getService().openUnsharedDatabase(db);
+  Services.storage.openUnsharedDatabase(db);
   do_check_true(db.exists());
 }
 
 var tests = [test_openUnsharedDatabase_file_DNE,
              test_openUnsharedDatabase_file_exists];
 
 function run_test() {
   for (var i = 0; i < tests.length; i++)
     tests[i]();
 
   cleanup();
 }
-
--- a/storage/test/unit/test_telemetry_vfs.js
+++ b/storage/test/unit/test_telemetry_vfs.js
@@ -6,23 +6,21 @@
 
 function run_sql(d, sql) {
   var stmt = d.createStatement(sql);
   stmt.execute();
   stmt.finalize();
 }
 
 function new_file(name) {
-  var file = dirSvc.get("ProfD", Ci.nsIFile);
+  var file = Services.dirsvc.get("ProfD", Ci.nsIFile);
   file.append(name);
   return file;
 }
 function run_test() {
-  const Telemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry);
-  let read_hgram = Telemetry.getHistogramById("MOZ_SQLITE_OTHER_READ_B");
+  let read_hgram = Services.telemetry.getHistogramById("MOZ_SQLITE_OTHER_READ_B");
   let old_sum = read_hgram.snapshot().sum;
   const file = new_file("telemetry.sqlite");
   var d = getDatabase(file);
   run_sql(d, "CREATE TABLE bloat(data varchar)");
   run_sql(d, "DROP TABLE bloat");
   do_check_true(read_hgram.snapshot().sum > old_sum);
 }
-
--- a/storage/test/unit/vacuumParticipant.js
+++ b/storage/test/unit/vacuumParticipant.js
@@ -20,18 +20,17 @@ function new_db_file(name) {
   return file;
 }
 
 /**
  * Opens and returns a connection to the provided database file.
  * @param nsIFile interface to the database file.
  */
 function getDatabase(aFile) {
-  return Cc["@mozilla.org/storage/service;1"].getService(Ci.mozIStorageService)
-                                             .openDatabase(aFile);
+  return Services.storage.openDatabase(aFile);
 }
 
 function vacuumParticipant() {
   this._dbConn = getDatabase(new_db_file("testVacuum"));
   Services.obs.addObserver(this, "test-options");
 }
 
 vacuumParticipant.prototype =
@@ -87,19 +86,17 @@ vacuumParticipant.prototype =
       this._stmt.params.test = 1;
       this._stmt.executeStep();
     } else if (aData == "memory") {
       try {
         this._dbConn.asyncClose();
       } catch (e) {
         // Do nothing.
       }
-      this._dbConn = Cc["@mozilla.org/storage/service;1"].
-                     getService(Ci.mozIStorageService).
-                     openSpecialDatabase("memory");
+      this._dbConn = Services.storage.openSpecialDatabase("memory");
     } else if (aData == "dispose") {
       Services.obs.removeObserver(this, "test-options");
       try {
         this._dbConn.asyncClose();
       } catch (e) {
         // Do nothing.
       }
     }
--- a/tools/quitter/QuitterObserver.js
+++ b/tools/quitter/QuitterObserver.js
@@ -52,16 +52,15 @@ QuitterObserver.prototype = {
 
   /**
    * messageManager callback function
    * This will get requests from our API in the window and process them in chrome for it
    **/
   receiveMessage(aMessage) {
     switch (aMessage.name) {
       case "Quitter.Quit":
-        let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
-        appStartup.quit(Ci.nsIAppStartup.eForceQuit);
+        Services.startup.quit(Ci.nsIAppStartup.eForceQuit);
         break;
     }
   }
 };
 
 const NSGetFactory = XPCOMUtils.generateNSGetFactory([QuitterObserver]);