Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: lib/prefs.js

Issue 5251132066627584: Issue 1488 - Add pre-configurable preference to suppress first run page (Closed)
Left Patch Set: Rebased Created March 20, 2015, 3:37 p.m.
Right Patch Set: Rebased and renamed onProgress() to checkLoaded() Created April 8, 2015, 3:09 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « chrome/managed-storage-schema.json ('k') | metadata.chrome » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 90 }
91 91
92 function init() 92 function init()
93 { 93 {
94 let prefs = Object.keys(defaults); 94 let prefs = Object.keys(defaults);
95 prefs.forEach(addPreference); 95 prefs.forEach(addPreference);
96 96
97 let localLoaded = false; 97 let localLoaded = false;
98 let managedLoaded = false; 98 let managedLoaded = false;
99 99
100 let checkLoaded = function()
101 {
102 if (!localLoaded || !managedLoaded)
103 return;
104
105 ext.storage.onChanged.addListener(function(changes)
106 {
107 for (let key in changes)
108 {
109 let pref = keyToPref(key);
110 if (pref && pref in defaults)
111 {
112 let change = changes[key];
113 if ("newValue" in change && change.newValue != defaults[pref])
114 overrides[pref] = change.newValue;
115 else
116 delete overrides[pref];
117
118 Prefs.onChanged._dispatch(pref);
119 }
120 }
121 });
122
123 Prefs.onLoaded._dispatch();
124 };
125
100 // Migrate preferences for users updating from old versions. 126 // Migrate preferences for users updating from old versions.
101 // TODO: Remove the migration code after a few releases. 127 // TODO: Remove the migration code after a few releases.
102 ext.storage.migratePrefs({ 128 ext.storage.migratePrefs({
103 map: function(key, value) 129 map: function(key, value)
104 { 130 {
105 if (key in defaults) 131 if (key in defaults)
106 { 132 {
107 if (key != "currentVersion") 133 if (key != "currentVersion")
108 { 134 {
109 try 135 try
(...skipping 12 matching lines...) Expand all
122 return null; 148 return null;
123 }, 149 },
124 150
125 done: function() 151 done: function()
126 { 152 {
127 ext.storage.get(prefs.map(prefToKey), function(items) 153 ext.storage.get(prefs.map(prefToKey), function(items)
128 { 154 {
129 for (let key in items) 155 for (let key in items)
130 overrides[keyToPref(key)] = items[key]; 156 overrides[keyToPref(key)] = items[key];
131 157
132 ext.storage.onChanged.addListener(function(changes)
133 {
134 for (let key in changes)
135 {
136 let pref = keyToPref(key);
137 if (pref && pref in defaults)
138 {
139 let change = changes[key];
140 if ("newValue" in change && change.newValue != defaults[pref])
141 overrides[pref] = change.newValue;
142 else
143 delete overrides[pref];
144
145 Prefs.onChanged._dispatch(pref);
146 }
147 }
148 });
149
150 localLoaded = true; 158 localLoaded = true;
151 if (localLoaded && managedLoaded) 159 checkLoaded();
152 Prefs.onLoaded._dispatch();
153 }); 160 });
154 } 161 }
155 }); 162 });
156 163
157 if (require("info").platform == "chromium" && "managed" in chrome.storage) 164 if (require("info").platform == "chromium" && "managed" in chrome.storage)
158 { 165 {
159 chrome.storage.managed.get(null, function(items) 166 chrome.storage.managed.get(null, function(items)
160 { 167 {
161 for (let key in items) 168 for (let key in items)
162 defaults[key] = items[key]; 169 defaults[key] = items[key];
163 170
164 managedLoaded = true; 171 managedLoaded = true;
165 if (localLoaded && managedLoaded) 172 checkLoaded();
166 Prefs.onLoaded._dispatch();
167 }); 173 });
168 } 174 }
169 else 175 else
170 { 176 {
171 managedLoaded = true; 177 managedLoaded = true;
178 checkLoaded();
172 } 179 }
173 } 180 }
174 181
175 init(); 182 init();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld