=== modified file 'includes/bootstrap.inc'
--- includes/bootstrap.inc	2011-01-13 01:04:13 +0000
+++ includes/bootstrap.inc	2011-02-13 00:03:20 +0000
@@ -547,12 +547,13 @@ function drupal_settings_initialize() {
   global $base_url, $base_path, $base_root;
 
   // Export the following settings.php variables to the global namespace
-  global $databases, $cookie_domain, $conf, $installed_profile, $update_free_access, $db_url, $db_prefix, $drupal_hash_salt, $is_https, $base_secure_url, $base_insecure_url;
+  global $databases, $cookie_domain, $conf, $installed_profile, $update_free_access, $db_url, $db_prefix, $drupal_hash_salt, $is_https, $base_secure_url, $base_insecure_url, $settings_key;
   $conf = array();
 
   if (file_exists(DRUPAL_ROOT . '/' . conf_path() . '/settings.php')) {
     include_once DRUPAL_ROOT . '/' . conf_path() . '/settings.php';
   }
+  settings_initalize();
   $is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on';
 
   if (isset($base_url)) {
@@ -722,6 +723,122 @@ function drupal_get_filename($type, $nam
   }
 }
 
+function plugin_get($slot, $target = 'default') {
+  static $drupal_static_fast;
+  if (!isset($drupal_static_fast)) {
+    $drupal_static_fast['plugin_objects'] = &drupal_static(__FUNCTION__);
+  }
+  $plugin_objects = &$drupal_static_fast['plugin_objects'];
+  if (!isset($plugin_objects[$slot][$target])) {
+    $class = settings_get('plugin_' . $slot . '_class_' . $target);
+    if (!isset($class)) {
+      $class = settings_get('plugin_' . $slot . '_default_class');
+    }
+    $plugin_objects[$slot][$target] = new $class($target);
+  }
+  return $plugin_objects[$slot][$target];
+}
+
+/**
+ * Write the name of the class serving a slot and an optional target.
+ */
+function plugin_set($slot, $class, $target = NULL) {
+  $name = isset($target) ? 'plugin_' . $slot . '_class_' . $target : 'plugin_' . $slot . '_default_class';
+  settings_set($name, $class);
+}
+
+/**
+ * Get the settings object.
+ *
+ * As plugin_get() and plugin_set() relies on the setting system, this needs
+ * a different factory.
+ */
+function _settings_get_object() {
+  static $drupal_static_fast;
+  global $conf;
+  if (!isset($drupal_static_fast)) {
+    $drupal_static_fast['settings_object'] = &drupal_static(__FUNCTION__);
+  }
+  $setting_object = &$drupal_static_fast['settings_object'];
+  if (!isset($setting_object)) {
+    // Can't use variable_get() because it would create an infinite loop:
+    // variable_get() uses plugin_get() which uses settings_get().
+    $class = isset($conf['settings_class']) ? $conf['settings_class'] : 'DrupalSettings';
+    $setting_object = new $class();
+  }
+  return $setting_object;
+}
+
+function settings_initalize() {
+  return _settings_get_object('settings')->initalize();
+}
+
+function settings_get($name, $default = NULL) {
+  return _settings_get_object('settings')->get($name, $default);
+}
+
+function settings_set($name, $value, $write = TRUE) {
+  return _settings_get_object('settings')->set($name, $value, $write);
+}
+
+function settings_check() {
+  return _settings_get_object('settings')->check();
+}
+
+interface DrupalSettingsInterface {
+  function initalize();
+  function check();
+  function get($name, $default = NULL);
+  function set($name, $value, $write = TRUE);
+}
+
+class DrupalSettings {
+  public $json_hash;
+
+  function initalize() {
+    $settings_file = DRUPAL_ROOT . '/' . conf_path() . '/settings.txt';
+    if (file_exists($settings_file)) {
+      $settings = file_get_contents($settings_file);
+      $json_hash = substr($settings, 0, 64);
+      $json_data = substr($settings, 64);
+      if (hash_hmac('sha256', $json_data, $GLOBALS['settings_key']) == $json_hash && ($json_conf = json_decode($json_data))) {
+        $this->json_hash = $json_hash;
+        $this->settings = $json_conf;
+      }
+    }
+  }
+
+  function check() {
+    $db_hash = variable_get('settings_hash');
+    if ($db_hash && $this->json_hash != $db_hash) {
+      $this->settings = json_decode(db_query('SELECT settings FROM {settings} WHERE hash = :hash', array(':hash' => $db_hash))->fetchField());
+      $this->write();
+    }
+  }
+
+  function get($name, $default = NULL) {
+    return isset($this->settings->$name) ? $this->settings->$name : $default;
+  }
+
+  function set($name, $value, $write = TRUE) {
+    $this->settings->$name = $value;
+    if ($write) {
+      $this->write();
+    }
+  }
+
+  function write() {
+    $json_data = json_encode($this->settings);
+    $this->json_hash = hash_hmac('sha256', $json_data, $GLOBALS['settings_key']);
+    file_put_contents(DRUPAL_ROOT . '/' . conf_path() . '/settings.txt', $this->json_hash . $json_data);
+    variable_set('settings_hash', $this->json_hash);
+    db_merge('settings')
+      ->key(array('hash' => $this->json_hash))
+      ->fields(array('settings' => $json_data))
+      ->execute();
+  }
+}
+
 /**
  * Load the persistent variable table.
  *
@@ -2131,6 +2248,7 @@ function _drupal_bootstrap_variables() {
 
   // Load variables from the database, but do not overwrite variables set in settings.php.
   $conf = variable_initialize(isset($conf) ? $conf : array());
+  settings_check();
   // Load bootstrap modules.
   require_once DRUPAL_ROOT . '/includes/module.inc';
   module_load_all(TRUE);

=== modified file 'includes/cache.inc'
--- includes/cache.inc	2010-12-01 00:26:03 +0000
+++ includes/cache.inc	2011-02-12 14:07:42 +0000
@@ -2,34 +2,6 @@
 // $Id: cache.inc,v 1.51 2010/12/01 00:26:03 webchick Exp $
 
 /**
- * Get the cache object for a cache bin.
- *
- * By default, this returns an instance of the DrupalDatabaseCache class.
- * Classes implementing DrupalCacheInterface can register themselves both as a
- * default implementation and for specific bins.
- *
- * @see DrupalCacheInterface
- *
- * @param $bin
- *   The cache bin for which the cache object should be returned.
- * @return DrupalCacheInterface
- *   The cache object associated with the specified bin.
- */
-function _cache_get_object($bin) {
-  // We do not use drupal_static() here because we do not want to change the
-  // storage of a cache bin mid-request.
-  static $cache_objects;
-  if (!isset($cache_objects[$bin])) {
-    $class = variable_get('cache_class_' . $bin);
-    if (!isset($class)) {
-      $class = variable_get('cache_default_class', 'DrupalDatabaseCache');
-    }
-    $cache_objects[$bin] = new $class($bin);
-  }
-  return $cache_objects[$bin];
-}
-
-/**
  * Return data from the persistent cache
  *
  * Data may be stored as either plain text or as serialized data. cache_get
@@ -47,7 +19,7 @@ function _cache_get_object($bin) {
  *   The cache or FALSE on failure.
  */
 function cache_get($cid, $bin = 'cache') {
-  return _cache_get_object($bin)->get($cid);
+  return plugin_get('cache', $bin)->get($cid);
 }
 
 /**
@@ -62,7 +34,7 @@ function cache_get($cid, $bin = 'cache')
  *   An array of the items successfully returned from cache indexed by cid.
  */
 function cache_get_multiple(array &$cids, $bin = 'cache') {
-  return _cache_get_object($bin)->getMultiple($cids);
+  return plugin_get('cache', $bin)->getMultiple($cids);
 }
 
 /**
@@ -135,7 +107,7 @@ function cache_get_multiple(array &$cids
  *     the given time, after which it behaves like CACHE_TEMPORARY.
  */
 function cache_set($cid, $data, $bin = 'cache', $expire = CACHE_PERMANENT) {
-  return _cache_get_object($bin)->set($cid, $data, $expire);
+  return plugin_get('cache', $bin)->set($cid, $data, $expire);
 }
 
 /**
@@ -167,7 +139,7 @@ function cache_clear_all($cid = NULL, $b
     cache_clear_all(NULL, 'cache_page');
     return;
   }
-  return _cache_get_object($bin)->clear($cid, $wildcard);
+  return plugin_get('cache', $bin)->clear($cid, $wildcard);
 }
 
 /**
@@ -182,7 +154,7 @@ function cache_clear_all($cid = NULL, $b
  *   TRUE if the cache bin specified is empty.
  */
 function cache_is_empty($bin) {
-  return _cache_get_object($bin)->isEmpty();
+  return plugin_get('cache', $bin)->isEmpty();
 }
 
 /**

=== modified file 'includes/install.core.inc'
--- includes/install.core.inc	2011-01-03 15:48:11 +0000
+++ includes/install.core.inc	2011-02-12 23:13:45 +0000
@@ -273,7 +273,7 @@ function install_begin_request(&$install
   // suspect, due to the fact that Drupal is not fully set up yet.
   require_once DRUPAL_ROOT . '/includes/cache.inc';
   require_once DRUPAL_ROOT . '/includes/cache-install.inc';
-  $conf['cache_default_class'] = 'DrupalFakeCache';
+  settings_set('plugin_cache_default_class', 'DrupalFakeCache', FALSE);
 
   // Prepare for themed output. We need to run this at the beginning of the
   // page request to avoid a different theme accidentally getting set. (We also
@@ -969,6 +969,10 @@ function install_settings_form_submit($f
     'value'    => drupal_hash_base64(drupal_random_bytes(55)),
     'required' => TRUE,
   );
+  $settings['settings_key'] = array(
+    'value' => drupal_hash_base64(drupal_random_bytes(55)),
+    'required' => TRUE,
+  );
   drupal_rewrite_settings($settings);
   // Indicate that the settings file has been verified, and check the database
   // for the last completed task, now that we have a valid connection. This

=== modified file 'modules/system/system.install'
--- modules/system/system.install	2011-01-02 17:26:39 +0000
+++ modules/system/system.install	2011-02-12 22:51:14 +0000
@@ -519,6 +519,8 @@ function system_install() {
   // Populate the cron key variable.
   $cron_key = drupal_hash_base64(drupal_random_bytes(55));
   variable_set('cron_key', $cron_key);
+  plugin_set('cache', 'DrupalDatabaseCache');
+  plugin_set('queue', 'SystemQueue');
 }
 
 /**
@@ -1537,6 +1539,26 @@ function system_schema() {
     ),
   );
 
+  $schema['settings'] = array(
+    'description' => 'Canonical for store for the default settings storage.',
+    'fields' => array(
+      'hash' => array(
+        'description' => 'The hash of these settings.',
+        'type' => 'varchar',
+        'length' => 64,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'settings' => array(
+        'description' => 'The serialized hash array.',
+        'type' => 'text',
+      ),
+    ),
+    'primary key' => array(
+      'hash',
+    ),
+  );
+
   $schema['system'] = array(
     'description' => "A list of all modules, themes, and theme engines that are or have been installed in Drupal's file system.",
     'fields' => array(

=== modified file 'modules/system/system.queue.inc'
--- modules/system/system.queue.inc	2011-01-03 18:03:54 +0000
+++ modules/system/system.queue.inc	2011-02-12 14:09:33 +0000
@@ -55,48 +55,6 @@
  * code might time out before it finishes).
  */
 
-/**
- * Factory class for interacting with queues.
- */
-class DrupalQueue {
-  /**
-   * Returns the queue object for a given name.
-   *
-   * The following variables can be set by variable_set or $conf overrides:
-   * - queue_class_$name: the class to be used for the queue $name.
-   * - queue_default_class: the class to use when queue_class_$name is not
-   *   defined. Defaults to SystemQueue, a reliable backend using SQL.
-   * - queue_default_reliable_class: the class to use when queue_class_$name is
-   *   not defined and the queue_default_class is not reliable. Defaults to
-   *   SystemQueue.
-   *
-   * @param $name
-   *   Arbitrary string. The name of the queue to work with.
-   * @param $reliable
-   *   TRUE if the ordering of items and guaranteeing every item executes at
-   *   least once is important, FALSE if scalability is the main concern.
-   *
-   * @return
-   *   The queue object for a given name.
-   */
-  public static function get($name, $reliable = FALSE) {
-    static $queues;
-    if (!isset($queues[$name])) {
-      $class = variable_get('queue_class_' . $name, NULL);
-      if (!$class) {
-        $class = variable_get('queue_default_class', 'SystemQueue');
-      }
-      $object = new $class($name);
-      if ($reliable && !$object instanceof DrupalReliableQueueInterface) {
-        $class = variable_get('queue_default_reliable_class', 'SystemQueue');
-        $object = new $class($name);
-      }
-      $queues[$name] = $object;
-    }
-    return $queues[$name];
-  }
-}
-
 interface DrupalQueueInterface {
   /**
    * Start working with a queue.

=== modified file 'modules/update/update.fetch.inc'
--- modules/update/update.fetch.inc	2010-05-06 05:59:30 +0000
+++ modules/update/update.fetch.inc	2011-02-12 14:45:18 +0000
@@ -29,7 +29,7 @@ function update_manual_status() {
  * Process a step in the batch for fetching available update data.
  */
 function update_fetch_data_batch(&$context) {
-  $queue = DrupalQueue::get('update_fetch_tasks');
+  $queue = plugin_get('queue', 'update_fetch_tasks');
   if (empty($context['sandbox']['max'])) {
     $context['finished'] = 0;
     $context['sandbox']['max'] = $queue->numberOfItems();
@@ -100,7 +100,7 @@ function update_fetch_data_finished($suc
  * Attempt to drain the queue of tasks for release history data to fetch.
  */
 function _update_fetch_data() {
-  $queue = DrupalQueue::get('update_fetch_tasks');
+  $queue = plugin_get('queue', 'update_fetch_tasks');
   $end = time() + variable_get('update_max_fetch_time', UPDATE_MAX_FETCH_TIME);
   while (time() < $end && ($item = $queue->claimItem())) {
     _update_process_fetch_task($item->data);
@@ -236,7 +236,7 @@ function _update_create_fetch_task($proj
   }
   $cid = 'fetch_task::' . $project['name'];
   if (empty($fetch_tasks[$cid])) {
-    $queue = DrupalQueue::get('update_fetch_tasks');
+    $queue = plugin_get('queue', 'update_fetch_tasks');
     $queue->createItem($project);
     db_insert('cache_update')
       ->fields(array(

=== modified file 'modules/update/update.install'
--- modules/update/update.install	2011-01-02 17:26:39 +0000
+++ modules/update/update.install	2011-02-12 23:52:45 +0000
@@ -71,7 +71,8 @@ function update_schema() {
  * Implements hook_install().
  */
 function update_install() {
-  $queue = DrupalQueue::get('update_fetch_tasks', TRUE);
+  $queue = plugin_get('queue', 'update_fetch_tasks');
+//, TRUE);
   $queue->createQueue();
 }
 

=== modified file 'sites/default/default.settings.php'
--- sites/default/default.settings.php	2011-01-28 07:03:57 +0000
+++ sites/default/default.settings.php	2011-02-12 23:20:48 +0000
@@ -213,6 +213,11 @@ $update_free_access = FALSE;
 $drupal_hash_salt = '';
 
 /**
+ * A key for settings, see above for harden.
+ */
+$settings_key = '';
+
+/**
  * Base URL (optional).
  *
  * If Drupal is generating incorrect URLs on your site, which could

