Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Unified Diff: third_party/WebKit/Source/devtools/front_end/common/Settings.js

Issue 1449143002: DevTools: remove Object.observe usage, it is being deprecated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removeAll added Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/main/Main.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/devtools/front_end/common/Settings.js
diff --git a/third_party/WebKit/Source/devtools/front_end/common/Settings.js b/third_party/WebKit/Source/devtools/front_end/common/Settings.js
index d7d5ecab2b9f7d87e8660899e818b63789a30814..5db4f9d7c353b814f0ccb5f3923bce535f9c8405 100644
--- a/third_party/WebKit/Source/devtools/front_end/common/Settings.js
+++ b/third_party/WebKit/Source/devtools/front_end/common/Settings.js
@@ -30,11 +30,13 @@
/**
* @constructor
- * @param {!Object<string, string>} prefs
+ * @param {!WebInspector.SettingsStorage} storage
*/
-WebInspector.Settings = function(prefs)
+WebInspector.Settings = function(storage)
{
- this._settingsStorage = prefs;
+ this._settingsStorage = storage;
+ this._localStorage = new WebInspector.SettingsStorage(window.localStorage || {});
+
this._eventSupport = new WebInspector.Object();
/** @type {!Map<string, !WebInspector.Setting>} */
this._registry = new Map();
@@ -91,7 +93,7 @@ WebInspector.Settings.prototype = {
createSetting: function(key, defaultValue, isLocal)
{
if (!this._registry.get(key))
- this._registry.set(key, new WebInspector.Setting(this, key, defaultValue, this._eventSupport, isLocal ? (window.localStorage || {}) : this._settingsStorage));
+ this._registry.set(key, new WebInspector.Setting(this, key, defaultValue, this._eventSupport, isLocal ? this._localStorage : this._settingsStorage));
return /** @type {!WebInspector.Setting} */ (this._registry.get(key));
},
@@ -115,16 +117,14 @@ WebInspector.Settings.prototype = {
createRegExpSetting: function(key, defaultValue, regexFlags, isLocal)
{
if (!this._registry.get(key))
- this._registry.set(key, new WebInspector.RegExpSetting(this, key, defaultValue, this._eventSupport, isLocal ? (window.localStorage || {}) : this._settingsStorage, regexFlags));
+ this._registry.set(key, new WebInspector.RegExpSetting(this, key, defaultValue, this._eventSupport, isLocal ? this._localStorage : this._settingsStorage, regexFlags));
return /** @type {!WebInspector.RegExpSetting} */ (this._registry.get(key));
},
clearAll: function()
{
- if (window.localStorage)
- window.localStorage.clear();
- for (var key in this._settingsStorage)
- delete this._settingsStorage[key];
+ this._settingsStorage.removeAll();
+ this._localStorage.removeAll();
var versionSetting = WebInspector.settings.createSetting(WebInspector.VersionController._currentVersionName, 0);
versionSetting.set(WebInspector.VersionController.currentVersion);
}
@@ -132,11 +132,91 @@ WebInspector.Settings.prototype = {
/**
* @constructor
+ * @param {!Object} object
+ * @param {function(string, string)=} setCallback
+ * @param {function(string)=} removeCallback
+ * @param {function(string)=} removeAllCallback
+ */
+WebInspector.SettingsStorage = function(object, setCallback, removeCallback, removeAllCallback)
+{
+ this._object = object;
+ this._setCallback = setCallback || function() {};
+ this._removeCallback = removeCallback || function() {};
+ this._removeAllCallback = removeAllCallback || function() {};
+}
+
+WebInspector.SettingsStorage.prototype = {
+ /**
+ * @param {string} name
+ * @param {string} value
+ */
+ set: function(name, value)
+ {
+ this._object[name] = value;
+ this._setCallback(name, value);
+ },
+
+ /**
+ * @param {string} name
+ * @return {boolean}
+ */
+ has: function(name)
+ {
+ return name in this._object;
+ },
+
+ /**
+ * @param {string} name
+ * @return {string}
+ */
+ get: function(name)
+ {
+ return this._object[name];
+ },
+
+ /**
+ * @param {string} name
+ */
+ remove: function(name)
+ {
+ delete this._object[name];
+ this._removeCallback(name);
+ },
+
+ removeAll: function()
+ {
+ this._object = {};
+ this._removeAllCallback();
+ },
+
+ _dumpSizes: function()
+ {
+ WebInspector.console.log("Ten largest settings: ");
+
+ var sizes = { __proto__: null };
+ for (var key in this._object)
+ sizes[key] = this._object[key].length;
+ var keys = Object.keys(sizes);
+
+ function comparator(key1, key2)
+ {
+ return sizes[key2] - sizes[key1];
+ }
+
+ keys.sort(comparator);
+
+ for (var i = 0; i < 10 && i < keys.length; ++i)
+ WebInspector.console.log("Setting: '" + keys[i] + "', size: " + sizes[keys[i]]);
+ }
+}
+
+/**
+ * @constructor
* @param {!WebInspector.Settings} settings
* @param {string} name
* @param {V} defaultValue
* @param {!WebInspector.Object} eventSupport
- * @param {!Object} storage
+ * @param {!WebInspector.SettingsStorage} storage
* @template V
*/
WebInspector.Setting = function(settings, name, defaultValue, eventSupport, storage)
@@ -181,9 +261,9 @@ WebInspector.Setting.prototype = {
return this._value;
this._value = this._defaultValue;
- if (this._name in this._storage) {
+ if (this._storage.has(this._name)) {
try {
- this._value = JSON.parse(this._storage[this._name]);
+ this._value = JSON.parse(this._storage.get(this._name));
} catch(e) {
this.remove();
}
@@ -200,7 +280,7 @@ WebInspector.Setting.prototype = {
try {
var settingString = JSON.stringify(value);
try {
- this._storage[this._name] = settingString;
+ this._storage.set(this._name, settingString);
} catch(e) {
this._printSettingsSavingError(e.message, this._name, settingString);
}
@@ -214,7 +294,7 @@ WebInspector.Setting.prototype = {
{
this._settings._registry.delete(this._name);
this._settings._moduleSettings.delete(this._name);
- delete this._storage[this._name];
+ this._storage.remove(this._name);
},
/**
@@ -227,22 +307,7 @@ WebInspector.Setting.prototype = {
var errorMessage = "Error saving setting with name: " + this._name + ", value length: " + value.length + ". Error: " + message;
console.error(errorMessage);
WebInspector.console.error(errorMessage);
- WebInspector.console.log("Ten largest settings: ");
-
- var sizes = { __proto__: null };
- for (var key in this._storage)
- sizes[key] = this._storage[key].length;
- var keys = Object.keys(sizes);
-
- function comparator(key1, key2)
- {
- return sizes[key2] - sizes[key1];
- }
-
- keys.sort(comparator);
-
- for (var i = 0; i < 10 && i < keys.length; ++i)
- WebInspector.console.log("Setting: '" + keys[i] + "', size: " + sizes[keys[i]]);
+ this._storage._dumpSizes();
}
}
@@ -253,7 +318,7 @@ WebInspector.Setting.prototype = {
* @param {string} name
* @param {string} defaultValue
* @param {!WebInspector.Object} eventSupport
- * @param {!Object<string, string>} storage
+ * @param {!WebInspector.SettingsStorage} storage
* @param {string=} regexFlags
*/
WebInspector.RegExpSetting = function(settings, name, defaultValue, eventSupport, storage, regexFlags)
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/main/Main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698