Bug 1240161 - Remove "only-if-cached" from RequestCache; r=bkelly
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 14 Jan 2016 17:15:16 -0500
changeset 317228 8f569dd0a9eb2548dc8a1ec6c97b1f4242648e40
parent 317227 adfce2ea31fca3353b9bfa7f9dea20f134b77846
child 317229 71e65051e33c9cb24171197df7eea10df29735f8
push id1079
push userjlund@mozilla.com
push dateFri, 15 Apr 2016 21:02:33 +0000
treeherdermozilla-release@575fbf6786d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1240161
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1240161 - Remove "only-if-cached" from RequestCache; r=bkelly
dom/cache/DBSchema.cpp
dom/cache/test/xpcshell/head.js
dom/cache/test/xpcshell/schema_15_profile.zip
dom/cache/test/xpcshell/test_migration.js
dom/webidl/Request.webidl
--- a/dom/cache/DBSchema.cpp
+++ b/dom/cache/DBSchema.cpp
@@ -32,17 +32,17 @@ namespace dom {
 namespace cache {
 namespace db {
 
 const int32_t kFirstShippedSchemaVersion = 15;
 
 namespace {
 
 // Update this whenever the DB schema is changed.
-const int32_t kLatestSchemaVersion = 17;
+const int32_t kLatestSchemaVersion = 18;
 
 // ---------
 // The following constants define the SQL schema.  These are defined in the
 // same order the SQL should be executed in CreateOrMigrateSchema().  They are
 // broken out as constants for convenient use in validation and migration.
 // ---------
 
 // The caches table is the single source of truth about what Cache
@@ -199,18 +199,17 @@ static_assert(int(RequestCredentials::Om
               int(RequestCredentials::Include) == 2 &&
               int(RequestCredentials::EndGuard_) == 3,
               "RequestCredentials values are as expected");
 static_assert(int(RequestCache::Default) == 0 &&
               int(RequestCache::No_store) == 1 &&
               int(RequestCache::Reload) == 2 &&
               int(RequestCache::No_cache) == 3 &&
               int(RequestCache::Force_cache) == 4 &&
-              int(RequestCache::Only_if_cached) == 5 &&
-              int(RequestCache::EndGuard_) == 6,
+              int(RequestCache::EndGuard_) == 5,
               "RequestCache values are as expected");
 static_assert(int(RequestRedirect::Follow) == 0 &&
               int(RequestRedirect::Error) == 1 &&
               int(RequestRedirect::Manual) == 2 &&
               int(RequestRedirect::EndGuard_) == 3,
               "RequestRedirect values are as expected");
 static_assert(int(ResponseType::Basic) == 0 &&
               int(ResponseType::Cors) == 1 &&
@@ -2406,21 +2405,23 @@ struct Migration
   int32_t mFromVersion;
   MigrationFunc mFunc;
 };
 
 // Declare migration functions here.  Each function should upgrade
 // the version by a single increment.  Don't skip versions.
 nsresult MigrateFrom15To16(mozIStorageConnection* aConn);
 nsresult MigrateFrom16To17(mozIStorageConnection* aConn);
+nsresult MigrateFrom17To18(mozIStorageConnection* aConn);
 
 // Configure migration functions to run for the given starting version.
 Migration sMigrationList[] = {
   Migration(15, MigrateFrom15To16),
   Migration(16, MigrateFrom16To17),
+  Migration(17, MigrateFrom17To18),
 };
 
 uint32_t sMigrationListLength = sizeof(sMigrationList) / sizeof(Migration);
 
 nsresult
 Migrate(mozIStorageConnection* aConn)
 {
   MOZ_ASSERT(!NS_IsMainThread());
@@ -2648,14 +2649,45 @@ MigrateFrom16To17(mozIStorageConnection*
   if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
 
   rv = aConn->SetSchemaVersion(17);
   if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
 
   return rv;
 }
 
+nsresult
+MigrateFrom17To18(mozIStorageConnection* aConn)
+{
+  MOZ_ASSERT(!NS_IsMainThread());
+  MOZ_ASSERT(aConn);
+
+  mozStorageTransaction trans(aConn, true,
+                              mozIStorageConnection::TRANSACTION_IMMEDIATE);
+
+  // This migration is needed in order to remove "only-if-cached" RequestCache
+  // values from the database.  This enum value was removed from the spec in
+  // https://github.com/whatwg/fetch/issues/39 but we unfortunately happily
+  // accepted this value in the Request constructor.
+  //
+  // There is no good value to upgrade this to, so we just stick to "default".
+
+  static_assert(int(RequestCache::Default) == 0,
+                "This is where the 0 below comes from!");
+  nsresult rv = aConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+    "UPDATE entries SET request_cache = 0 "
+      "WHERE request_cache = 5;"
+  ));
+  if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
+
+  rv = aConn->SetSchemaVersion(18);
+  if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
+
+  return rv;
+}
+
+
 } // anonymous namespace
 
 } // namespace db
 } // namespace cache
 } // namespace dom
 } // namespace mozilla
--- a/dom/cache/test/xpcshell/head.js
+++ b/dom/cache/test/xpcshell/head.js
@@ -13,16 +13,19 @@ var Cu = Components.utils;
 // services required be initialized in order to run CacheStorage
 var ss = Cc['@mozilla.org/storage/service;1']
          .createInstance(Ci.mozIStorageService);
 var sts = Cc['@mozilla.org/network/stream-transport-service;1']
           .getService(Ci.nsIStreamTransportService);
 var hash = Cc['@mozilla.org/security/hash;1']
            .createInstance(Ci.nsICryptoHash);
 
+var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
+prefs.setBoolPref("dom.requestcache.enabled", true);
+
 // Expose Cache and Fetch symbols on the global
 Cu.importGlobalProperties(['caches', 'fetch']);
 
 // Extract a zip file into the profile
 function create_test_profile(zipFileName) {
   do_get_profile();
 
   var directoryService = Cc['@mozilla.org/file/directory_service;1']
index 6d742275b30921a721dddbcbbd12439d3081bdce..246d01e07e3f2103645513c2ebe5b6995aa67c8d
GIT binary patch
literal 3111
zc$^FHW@h1H0D-DrJr4#Xz`-EHP+XE<l$f5X9~#2Rz`R^#MwpZ8jIh!QZU#n{uZ#=~
zEFwU40XR(%Kr$gEH7&6;r-Vq87#I|h4Pp?-Vp4KOQGPDeX@Y-58E_aV!oURd3dlgG
zU&ZsqfGk-cR={nbUT$hhVoG93BHUyUMl(4%VXF79yV@Ij8XFsREf;Ipn~Qd`B6(mF
zT2RR1wl6s`IRokq0acvg0`bOjps^fkjA0*GK!!3hXc00NOcv`E7v^M^q=N1E2@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/dom/cache/test/xpcshell/test_migration.js
+++ b/dom/cache/test/xpcshell/test_migration.js
@@ -15,16 +15,17 @@ function run_test() {
     cache = c;
     ok(cache, 'cache exists');
     return cache.keys();
   }).then(function(requestList) {
     ok(requestList.length > 0, 'should have at least one request in cache');
     requestList.forEach(function(request) {
       ok(request, 'each request in list should be non-null');
       ok(request.redirect === 'follow', 'request.redirect should default to "follow"');
+      ok(request.cache === 'default', 'request.cache should have been updated to "default"' + request.cache);
     });
     return Promise.all(requestList.map(function(request) {
       return cache.match(request);
     }));
   }).then(function(responseList) {
     ok(responseList.length > 0, 'should have at least one response in cache');
     responseList.forEach(function(response) {
       ok(response, 'each response in list should be non-null');
--- a/dom/webidl/Request.webidl
+++ b/dom/webidl/Request.webidl
@@ -52,10 +52,10 @@ enum RequestContext {
   "font", "form", "frame", "hyperlink", "iframe", "image", "imageset", "import",
   "internal", "location", "manifest", "object", "ping", "plugin", "prefetch", "script",
   "sharedworker", "subresource", "style", "track", "video", "worker", "xmlhttprequest",
   "xslt"
 };
 
 enum RequestMode { "same-origin", "no-cors", "cors" };
 enum RequestCredentials { "omit", "same-origin", "include" };
-enum RequestCache { "default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached" };
+enum RequestCache { "default", "no-store", "reload", "no-cache", "force-cache" };
 enum RequestRedirect { "follow", "error", "manual" };