OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * Class handling saving and restoring of per-host options. | 7 * Class handling saving and restoring of per-host options. |
8 */ | 8 */ |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 /** | 68 /** |
69 * Helper function for both load and save. | 69 * Helper function for both load and save. |
70 * | 70 * |
71 * @param {string} hostId The host identifer for which to load options. | 71 * @param {string} hostId The host identifer for which to load options. |
72 * @param {function(Object, Object):void} callback Callback to which the | 72 * @param {function(Object, Object):void} callback Callback to which the |
73 * current settings for the specified host and for all hosts are passed. | 73 * current settings for the specified host and for all hosts are passed. |
74 * @return {void} Nothing. | 74 * @return {void} Nothing. |
75 */ | 75 */ |
76 remoting.HostSettings.loadInternal_ = function(hostId, callback) { | 76 remoting.HostSettings.loadInternal_ = function(hostId, callback) { |
77 /** | 77 /** |
78 * @param {Object.<string>} allHosts The current options for all hosts. | 78 * @param {Object<string>} allHosts The current options for all hosts. |
79 * @return {void} Nothing. | 79 * @return {void} Nothing. |
80 */ | 80 */ |
81 var onDone = function(allHosts) { | 81 var onDone = function(allHosts) { |
82 var result = {}; | 82 var result = {}; |
83 try { | 83 try { |
84 var hosts = allHosts[remoting.HostSettings.KEY_]; | 84 var hosts = allHosts[remoting.HostSettings.KEY_]; |
85 if (hosts) { | 85 if (hosts) { |
86 result = base.jsonParseSafe(hosts); | 86 result = base.jsonParseSafe(hosts); |
87 if (typeof(result) != 'object') { | 87 if (typeof(result) != 'object') { |
88 console.error("Error loading host settings: Not an object"); | 88 console.error("Error loading host settings: Not an object"); |
89 result = {}; | 89 result = {}; |
90 } else if (/** @type {Object} */ (result).hasOwnProperty(hostId) && | 90 } else if (/** @type {Object} */ (result).hasOwnProperty(hostId) && |
91 typeof(result[hostId]) == 'object') { | 91 typeof(result[hostId]) == 'object') { |
92 callback(result[hostId], result); | 92 callback(result[hostId], result); |
93 return; | 93 return; |
94 } | 94 } |
95 } | 95 } |
96 } catch (/** @type {*} */ err) { | 96 } catch (/** @type {*} */ err) { |
97 console.error('Error loading host settings:', err); | 97 console.error('Error loading host settings:', err); |
98 } | 98 } |
99 callback({}, /** @type {Object} */ (result)); | 99 callback({}, /** @type {Object} */ (result)); |
100 }; | 100 }; |
101 chrome.storage.local.get(remoting.HostSettings.KEY_, onDone); | 101 chrome.storage.local.get(remoting.HostSettings.KEY_, onDone); |
102 }; | 102 }; |
103 | 103 |
104 /** @type {string} @private */ | 104 /** @type {string} @private */ |
105 remoting.HostSettings.KEY_ = 'remoting-host-options'; | 105 remoting.HostSettings.KEY_ = 'remoting-host-options'; |
OLD | NEW |