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

Side by Side Diff: chrome/browser/resources/options/preferences.js

Issue 2939273002: DO NOT SUBMIT: what chrome/browser/resources/ could eventually look like with clang-format (Closed)
Patch Set: Created 3 years, 6 months 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 unified diff | Download patch
OLDNEW
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 cr.define('options', function() { 5 cr.define('options', function() {
6 6
7 ///////////////////////////////////////////////////////////////////////////// 7 /////////////////////////////////////////////////////////////////////////////
8 // Preferences class: 8 // Preferences class:
9 9
10 /** 10 /**
(...skipping 15 matching lines...) Expand all
26 * @param {boolean} commit Whether to commit the change to Chrome. 26 * @param {boolean} commit Whether to commit the change to Chrome.
27 * @param {string=} opt_metric User metrics identifier. 27 * @param {string=} opt_metric User metrics identifier.
28 */ 28 */
29 Preferences.setBooleanPref = function(name, value, commit, opt_metric) { 29 Preferences.setBooleanPref = function(name, value, commit, opt_metric) {
30 if (!commit) { 30 if (!commit) {
31 Preferences.getInstance().setPrefNoCommit_(name, 'bool', Boolean(value)); 31 Preferences.getInstance().setPrefNoCommit_(name, 'bool', Boolean(value));
32 return; 32 return;
33 } 33 }
34 34
35 var argumentList = [name, Boolean(value)]; 35 var argumentList = [name, Boolean(value)];
36 if (opt_metric != undefined) argumentList.push(opt_metric); 36 if (opt_metric != undefined)
37 argumentList.push(opt_metric);
37 chrome.send('setBooleanPref', argumentList); 38 chrome.send('setBooleanPref', argumentList);
38 }; 39 };
39 40
40 /** 41 /**
41 * Sets an integer preference and signals its new value. 42 * Sets an integer preference and signals its new value.
42 * @param {string} name Preference name. 43 * @param {string} name Preference name.
43 * @param {number} value New preference value. 44 * @param {number} value New preference value.
44 * @param {boolean} commit Whether to commit the change to Chrome. 45 * @param {boolean} commit Whether to commit the change to Chrome.
45 * @param {string} metric User metrics identifier. 46 * @param {string} metric User metrics identifier.
46 */ 47 */
47 Preferences.setIntegerPref = function(name, value, commit, metric) { 48 Preferences.setIntegerPref = function(name, value, commit, metric) {
48 if (!commit) { 49 if (!commit) {
49 Preferences.getInstance().setPrefNoCommit_(name, 'int', Number(value)); 50 Preferences.getInstance().setPrefNoCommit_(name, 'int', Number(value));
50 return; 51 return;
51 } 52 }
52 53
53 var argumentList = [name, Number(value)]; 54 var argumentList = [name, Number(value)];
54 if (metric != undefined) argumentList.push(metric); 55 if (metric != undefined)
56 argumentList.push(metric);
55 chrome.send('setIntegerPref', argumentList); 57 chrome.send('setIntegerPref', argumentList);
56 }; 58 };
57 59
58 /** 60 /**
59 * Sets a double-valued preference and signals its new value. 61 * Sets a double-valued preference and signals its new value.
60 * @param {string} name Preference name. 62 * @param {string} name Preference name.
61 * @param {number} value New preference value. 63 * @param {number} value New preference value.
62 * @param {boolean} commit Whether to commit the change to Chrome. 64 * @param {boolean} commit Whether to commit the change to Chrome.
63 * @param {string} metric User metrics identifier. 65 * @param {string} metric User metrics identifier.
64 */ 66 */
65 Preferences.setDoublePref = function(name, value, commit, metric) { 67 Preferences.setDoublePref = function(name, value, commit, metric) {
66 if (!commit) { 68 if (!commit) {
67 Preferences.getInstance().setPrefNoCommit_(name, 'double', Number(value)); 69 Preferences.getInstance().setPrefNoCommit_(name, 'double', Number(value));
68 return; 70 return;
69 } 71 }
70 72
71 var argumentList = [name, Number(value)]; 73 var argumentList = [name, Number(value)];
72 if (metric != undefined) argumentList.push(metric); 74 if (metric != undefined)
75 argumentList.push(metric);
73 chrome.send('setDoublePref', argumentList); 76 chrome.send('setDoublePref', argumentList);
74 }; 77 };
75 78
76 /** 79 /**
77 * Sets a string preference and signals its new value. 80 * Sets a string preference and signals its new value.
78 * @param {string} name Preference name. 81 * @param {string} name Preference name.
79 * @param {string} value New preference value. 82 * @param {string} value New preference value.
80 * @param {boolean} commit Whether to commit the change to Chrome. 83 * @param {boolean} commit Whether to commit the change to Chrome.
81 * @param {string} metric User metrics identifier. 84 * @param {string} metric User metrics identifier.
82 */ 85 */
83 Preferences.setStringPref = function(name, value, commit, metric) { 86 Preferences.setStringPref = function(name, value, commit, metric) {
84 if (!commit) { 87 if (!commit) {
85 Preferences.getInstance().setPrefNoCommit_(name, 'string', String(value)); 88 Preferences.getInstance().setPrefNoCommit_(name, 'string', String(value));
86 return; 89 return;
87 } 90 }
88 91
89 var argumentList = [name, String(value)]; 92 var argumentList = [name, String(value)];
90 if (metric != undefined) argumentList.push(metric); 93 if (metric != undefined)
94 argumentList.push(metric);
91 chrome.send('setStringPref', argumentList); 95 chrome.send('setStringPref', argumentList);
92 }; 96 };
93 97
94 /** 98 /**
95 * Sets a string preference that represents a URL and signals its new value. 99 * Sets a string preference that represents a URL and signals its new value.
96 * The value will be fixed to be a valid URL when it gets committed to Chrome. 100 * The value will be fixed to be a valid URL when it gets committed to Chrome.
97 * @param {string} name Preference name. 101 * @param {string} name Preference name.
98 * @param {string} value New preference value. 102 * @param {string} value New preference value.
99 * @param {boolean} commit Whether to commit the change to Chrome. 103 * @param {boolean} commit Whether to commit the change to Chrome.
100 * @param {string} metric User metrics identifier. 104 * @param {string} metric User metrics identifier.
101 */ 105 */
102 Preferences.setURLPref = function(name, value, commit, metric) { 106 Preferences.setURLPref = function(name, value, commit, metric) {
103 if (!commit) { 107 if (!commit) {
104 Preferences.getInstance().setPrefNoCommit_(name, 'url', String(value)); 108 Preferences.getInstance().setPrefNoCommit_(name, 'url', String(value));
105 return; 109 return;
106 } 110 }
107 111
108 var argumentList = [name, String(value)]; 112 var argumentList = [name, String(value)];
109 if (metric != undefined) argumentList.push(metric); 113 if (metric != undefined)
114 argumentList.push(metric);
110 chrome.send('setURLPref', argumentList); 115 chrome.send('setURLPref', argumentList);
111 }; 116 };
112 117
113 /** 118 /**
114 * Sets a JSON list preference and signals its new value. 119 * Sets a JSON list preference and signals its new value.
115 * @param {string} name Preference name. 120 * @param {string} name Preference name.
116 * @param {Array} value New preference value. 121 * @param {Array} value New preference value.
117 * @param {boolean} commit Whether to commit the change to Chrome. 122 * @param {boolean} commit Whether to commit the change to Chrome.
118 * @param {string} metric User metrics identifier. 123 * @param {string} metric User metrics identifier.
119 */ 124 */
120 Preferences.setListPref = function(name, value, commit, metric) { 125 Preferences.setListPref = function(name, value, commit, metric) {
121 if (!commit) { 126 if (!commit) {
122 Preferences.getInstance().setPrefNoCommit_(name, 'list', value); 127 Preferences.getInstance().setPrefNoCommit_(name, 'list', value);
123 return; 128 return;
124 } 129 }
125 130
126 var argumentList = [name, JSON.stringify(value)]; 131 var argumentList = [name, JSON.stringify(value)];
127 if (metric != undefined) argumentList.push(metric); 132 if (metric != undefined)
133 argumentList.push(metric);
128 chrome.send('setListPref', argumentList); 134 chrome.send('setListPref', argumentList);
129 }; 135 };
130 136
131 /** 137 /**
132 * Clears the user setting for a preference and signals its new effective 138 * Clears the user setting for a preference and signals its new effective
133 * value. 139 * value.
134 * @param {string} name Preference name. 140 * @param {string} name Preference name.
135 * @param {boolean} commit Whether to commit the change to Chrome. 141 * @param {boolean} commit Whether to commit the change to Chrome.
136 * @param {string=} opt_metric User metrics identifier. 142 * @param {string=} opt_metric User metrics identifier.
137 */ 143 */
138 Preferences.clearPref = function(name, commit, opt_metric) { 144 Preferences.clearPref = function(name, commit, opt_metric) {
139 if (!commit) { 145 if (!commit) {
140 Preferences.getInstance().clearPrefNoCommit_(name); 146 Preferences.getInstance().clearPrefNoCommit_(name);
141 return; 147 return;
142 } 148 }
143 149
144 var argumentList = [name]; 150 var argumentList = [name];
145 if (opt_metric != undefined) argumentList.push(opt_metric); 151 if (opt_metric != undefined)
152 argumentList.push(opt_metric);
146 chrome.send('clearPref', argumentList); 153 chrome.send('clearPref', argumentList);
147 }; 154 };
148 155
149 Preferences.prototype = { 156 Preferences.prototype = {
150 __proto__: cr.EventTarget.prototype, 157 __proto__: cr.EventTarget.prototype,
151 158
152 /** 159 /**
153 * Adds an event listener to the target. 160 * Adds an event listener to the target.
154 * @param {string} type The name of the event. 161 * @param {string} type The name of the event.
155 * @param {EventListenerType} handler The handler for the event. This is 162 * @param {EventListenerType} handler The handler for the event. This is
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 Preferences.prefsChangedCallback = function(notification) { 331 Preferences.prefsChangedCallback = function(notification) {
325 var event = new Event(notification[0]); 332 var event = new Event(notification[0]);
326 event.value = notification[1]; 333 event.value = notification[1];
327 var prefs = Preferences.getInstance(); 334 var prefs = Preferences.getInstance();
328 prefs.registeredPreferences_[notification[0]] = {orig: notification[1]}; 335 prefs.registeredPreferences_[notification[0]] = {orig: notification[1]};
329 if (event.value) 336 if (event.value)
330 prefs.dispatchEvent(event); 337 prefs.dispatchEvent(event);
331 }; 338 };
332 339
333 // Export 340 // Export
334 return { 341 return {Preferences: Preferences};
335 Preferences: Preferences
336 };
337 342
338 }); 343 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698