Web Inspector: [Settings] Use registry to track settings objects.
authoreustas@chromium.org <eustas@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Mar 2013 07:45:45 +0000 (07:45 +0000)
committereustas@chromium.org <eustas@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Mar 2013 07:45:45 +0000 (07:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=113008

Reviewed by Pavel Feldman.

Currently .createSetting creates new instance any time it is invoked.
When one instance saves value, the other instance do not know about it.

To resolve this issue we can use registry to make .createSetting return
same object for specific key.

* inspector/front-end/Settings.js:
(WebInspector.Settings.prototype.createSetting): Use registry.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@146745 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/Settings.js

index f1a2f94..1c4b638 100644 (file)
@@ -1,3 +1,19 @@
+2013-03-25  Eugene Klyuchnikov  <eustas@chromium.org>
+
+        Web Inspector: [Settings] Use registry to track settings objects.
+        https://bugs.webkit.org/show_bug.cgi?id=113008
+
+        Reviewed by Pavel Feldman.
+
+        Currently .createSetting creates new instance any time it is invoked.
+        When one instance saves value, the other instance do not know about it.
+
+        To resolve this issue we can use registry to make .createSetting return
+        same object for specific key.
+
+        * inspector/front-end/Settings.js:
+        (WebInspector.Settings.prototype.createSetting): Use registry.
+
 2013-03-24  Matt Falkenhagen  <falken@chromium.org>
 
         Refactoring: Pull Node::disabled() and Node::isInert() down to Element.
index 8e6fc41..38348b6 100644 (file)
@@ -72,6 +72,7 @@ var Capabilities = {
 WebInspector.Settings = function()
 {
     this._eventSupport = new WebInspector.Object();
+    this._registry = /** @type {!Object.<string, !WebInspector.Setting>} */ ({});
 
     this.colorFormat = this.createSetting("colorFormat", "original");
     this.consoleHistory = this.createSetting("consoleHistory", []);
@@ -132,11 +133,15 @@ WebInspector.Settings = function()
 
 WebInspector.Settings.prototype = {
     /**
-     * @return {WebInspector.Setting}
+     * @param {string} key
+     * @param {*} defaultValue
+     * @return {!WebInspector.Setting}
      */
     createSetting: function(key, defaultValue)
     {
-        return new WebInspector.Setting(key, defaultValue, this._eventSupport, window.localStorage);
+        if (!this._registry[key])
+            this._registry[key] = new WebInspector.Setting(key, defaultValue, this._eventSupport, window.localStorage);
+        return this._registry[key];
     }
 }
 
@@ -209,7 +214,7 @@ WebInspector.ExperimentsSettings = function()
     this._setting = WebInspector.settings.createSetting("experiments", {});
     this._experiments = [];
     this._enabledForTest = {};
-    
+
     // Add currently running experiments here.
     this.snippetsSupport = this._createExperiment("snippetsSupport", "Snippets support");
     this.nativeMemorySnapshots = this._createExperiment("nativeMemorySnapshots", "Native memory profiling");
@@ -238,7 +243,7 @@ WebInspector.ExperimentsSettings.prototype = {
     {
         return this._experiments.slice();
     },
-    
+
     /**
      * @return {boolean}
      */
@@ -246,7 +251,7 @@ WebInspector.ExperimentsSettings.prototype = {
     {
         return Preferences.experimentsEnabled || ("experiments" in WebInspector.queryParamsObject);
     },
-    
+
     /**
      * @param {string} experimentName
      * @param {string} experimentTitle
@@ -258,7 +263,7 @@ WebInspector.ExperimentsSettings.prototype = {
         this._experiments.push(experiment);
         return experiment;
     },
-    
+
     /**
      * @param {string} experimentName
      * @return {boolean}
@@ -274,7 +279,7 @@ WebInspector.ExperimentsSettings.prototype = {
         var experimentsSetting = this._setting.get();
         return experimentsSetting[experimentName];
     },
-    
+
     /**
      * @param {string} experimentName
      * @param {boolean} enabled
@@ -328,7 +333,7 @@ WebInspector.Experiment.prototype = {
     {
         return this._name;
     },
-    
+
     /**
      * @return {string}
      */
@@ -336,7 +341,7 @@ WebInspector.Experiment.prototype = {
     {
         return this._title;
     },
-    
+
     /**
      * @return {boolean}
      */
@@ -344,7 +349,7 @@ WebInspector.Experiment.prototype = {
     {
         return this._experimentsSettings.isEnabled(this._name);
     },
-    
+
     /**
      * @param {boolean} enabled
      */