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

Side by Side Diff: lib/sync.js

Issue 6341149593698304: Issue 301 - Change for each to for .. of .. in lib/ (Closed)
Patch Set: Created April 10, 2014, 5:02 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/subscriptionClasses.js ('k') | lib/synchronizer.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 191
192 createRecord: function(id, collection) 192 createRecord: function(id, collection)
193 { 193 {
194 let record = new ABPEngine.prototype._recordObj(collection, id); 194 let record = new ABPEngine.prototype._recordObj(collection, id);
195 if (id == filtersRecordID) 195 if (id == filtersRecordID)
196 { 196 {
197 record.cleartext = { 197 record.cleartext = {
198 id: id, 198 id: id,
199 subscriptions: [], 199 subscriptions: [],
200 }; 200 };
201 for each (let subscription in FilterStorage.subscriptions) 201 for (let subscription of FilterStorage.subscriptions)
202 { 202 {
203 if (subscription instanceof ExternalSubscription) 203 if (subscription instanceof ExternalSubscription)
204 continue; 204 continue;
205 205
206 let subscriptionEntry = 206 let subscriptionEntry =
207 { 207 {
208 url: subscription.url, 208 url: subscription.url,
209 disabled: subscription.disabled 209 disabled: subscription.disabled
210 }; 210 };
211 if (subscription instanceof SpecialSubscription) 211 if (subscription instanceof SpecialSubscription)
212 { 212 {
213 subscriptionEntry.filters = []; 213 subscriptionEntry.filters = [];
214 for each (let filter in subscription.filters) 214 for (let filter of subscription.filters)
215 { 215 {
216 let filterEntry = {text: filter.text}; 216 let filterEntry = {text: filter.text};
217 if (filter instanceof ActiveFilter) 217 if (filter instanceof ActiveFilter)
218 filterEntry.disabled = filter.disabled; 218 filterEntry.disabled = filter.disabled;
219 subscriptionEntry.filters.push(filterEntry); 219 subscriptionEntry.filters.push(filterEntry);
220 } 220 }
221 } 221 }
222 else 222 else
223 subscriptionEntry.title = subscription.title; 223 subscriptionEntry.title = subscription.title;
224 record.cleartext.subscriptions.push(subscriptionEntry); 224 record.cleartext.subscriptions.push(subscriptionEntry);
(...skipping 19 matching lines...) Expand all
244 { 244 {
245 if (record.id != filtersRecordID) 245 if (record.id != filtersRecordID)
246 return; 246 return;
247 247
248 this._log.trace("Merging in remote data"); 248 this._log.trace("Merging in remote data");
249 249
250 let data = record.cleartext.subscriptions; 250 let data = record.cleartext.subscriptions;
251 251
252 // First make sure we have the same subscriptions on both sides 252 // First make sure we have the same subscriptions on both sides
253 let seenSubscription = {__proto__: null}; 253 let seenSubscription = {__proto__: null};
254 for each (let remoteSubscription in data) 254 for (let remoteSubscription of data)
255 { 255 {
256 seenSubscription[remoteSubscription.url] = true; 256 seenSubscription[remoteSubscription.url] = true;
257 if (remoteSubscription.url in FilterStorage.knownSubscriptions) 257 if (remoteSubscription.url in FilterStorage.knownSubscriptions)
258 { 258 {
259 let subscription = FilterStorage.knownSubscriptions[remoteSubscription.u rl]; 259 let subscription = FilterStorage.knownSubscriptions[remoteSubscription.u rl];
260 if (!trackerInstance.didSubscriptionChange(remoteSubscription)) 260 if (!trackerInstance.didSubscriptionChange(remoteSubscription))
261 { 261 {
262 // Only change local subscription if there were no changes, otherwise dismiss remote changes 262 // Only change local subscription if there were no changes, otherwise dismiss remote changes
263 subscription.disabled = remoteSubscription.disabled; 263 subscription.disabled = remoteSubscription.disabled;
264 if (subscription instanceof DownloadableSubscription) 264 if (subscription instanceof DownloadableSubscription)
(...skipping 10 matching lines...) Expand all
275 subscription.disabled = remoteSubscription.disabled; 275 subscription.disabled = remoteSubscription.disabled;
276 if (subscription instanceof DownloadableSubscription) 276 if (subscription instanceof DownloadableSubscription)
277 { 277 {
278 subscription.title = remoteSubscription.title; 278 subscription.title = remoteSubscription.title;
279 FilterStorage.addSubscription(subscription); 279 FilterStorage.addSubscription(subscription);
280 Synchronizer.execute(subscription); 280 Synchronizer.execute(subscription);
281 } 281 }
282 } 282 }
283 } 283 }
284 284
285 for each (let subscription in FilterStorage.subscriptions.slice()) 285 for (let subscription of FilterStorage.subscriptions.slice())
286 { 286 {
287 if (!(subscription.url in seenSubscription) && subscription instanceof Dow nloadableSubscription && !trackerInstance.didSubscriptionChange(subscription)) 287 if (!(subscription.url in seenSubscription) && subscription instanceof Dow nloadableSubscription && !trackerInstance.didSubscriptionChange(subscription))
288 { 288 {
289 // Subscription was removed remotely, remove it locally as well 289 // Subscription was removed remotely, remove it locally as well
290 FilterStorage.removeSubscription(subscription); 290 FilterStorage.removeSubscription(subscription);
291 } 291 }
292 } 292 }
293 293
294 // Now sync the custom filters 294 // Now sync the custom filters
295 let seenFilter = {__proto__: null}; 295 let seenFilter = {__proto__: null};
296 for each (let remoteSubscription in data) 296 for (let remoteSubscription of data)
297 { 297 {
298 if (!("filters" in remoteSubscription)) 298 if (!("filters" in remoteSubscription))
299 continue; 299 continue;
300 300
301 for each (let remoteFilter in remoteSubscription.filters) 301 for (let remoteFilter of remoteSubscription.filters)
302 { 302 {
303 seenFilter[remoteFilter.text] = true; 303 seenFilter[remoteFilter.text] = true;
304 304
305 let filter = Filter.fromText(remoteFilter.text); 305 let filter = Filter.fromText(remoteFilter.text);
306 if (trackerInstance.didFilterChange(filter)) 306 if (trackerInstance.didFilterChange(filter))
307 continue; 307 continue;
308 308
309 if (filter.subscriptions.some(function(subscription) subscription instan ceof SpecialSubscription)) 309 if (filter.subscriptions.some(function(subscription) subscription instan ceof SpecialSubscription))
310 { 310 {
311 // Filter might have been changed remotely 311 // Filter might have been changed remotely
312 if (filter instanceof ActiveFilter) 312 if (filter instanceof ActiveFilter)
313 filter.disabled = remoteFilter.disabled; 313 filter.disabled = remoteFilter.disabled;
314 } 314 }
315 else 315 else
316 { 316 {
317 // Filter was added remotely, add it locally as well 317 // Filter was added remotely, add it locally as well
318 FilterStorage.addFilter(filter); 318 FilterStorage.addFilter(filter);
319 } 319 }
320 } 320 }
321 } 321 }
322 322
323 for each (let subscription in FilterStorage.subscriptions) 323 for (let subscription of FilterStorage.subscriptions)
324 { 324 {
325 if (!(subscription instanceof SpecialSubscription)) 325 if (!(subscription instanceof SpecialSubscription))
326 continue; 326 continue;
327 327
328 for each (let filter in subscription.filters.slice()) 328 for (let filter of subscription.filters.slice())
329 { 329 {
330 if (!(filter.text in seenFilter) && !trackerInstance.didFilterChange(fil ter)) 330 if (!(filter.text in seenFilter) && !trackerInstance.didFilterChange(fil ter))
331 { 331 {
332 // Filter was removed remotely, remove it locally as well 332 // Filter was removed remotely, remove it locally as well
333 FilterStorage.removeFilter(filter); 333 FilterStorage.removeFilter(filter);
334 } 334 }
335 } 335 }
336 } 336 }
337 337
338 // Merge done, forget about local changes now 338 // Merge done, forget about local changes now
339 trackerInstance.clearPrivateChanges() 339 trackerInstance.clearPrivateChanges()
340 }, 340 },
341 341
342 remove: function(record) 342 remove: function(record)
343 { 343 {
344 // Shouldn't be called but if it is - ignore 344 // Shouldn't be called but if it is - ignore
345 }, 345 },
346 346
347 wipe: function() 347 wipe: function()
348 { 348 {
349 this._log.trace("Got wipe command, removing all data"); 349 this._log.trace("Got wipe command, removing all data");
350 350
351 for each (let subscription in FilterStorage.subscriptions.slice()) 351 for (let subscription of FilterStorage.subscriptions.slice())
352 { 352 {
353 if (subscription instanceof DownloadableSubscription) 353 if (subscription instanceof DownloadableSubscription)
354 FilterStorage.removeSubscription(subscription); 354 FilterStorage.removeSubscription(subscription);
355 else if (subscription instanceof SpecialSubscription) 355 else if (subscription instanceof SpecialSubscription)
356 { 356 {
357 for each (let filter in subscription.filters.slice()) 357 for (let filter of subscription.filters.slice())
358 FilterStorage.removeFilter(filter); 358 FilterStorage.removeFilter(filter);
359 } 359 }
360 } 360 }
361 361
362 // Data wiped, forget about local changes now 362 // Data wiped, forget about local changes now
363 trackerInstance.clearPrivateChanges() 363 trackerInstance.clearPrivateChanges()
364 } 364 }
365 }; 365 };
366 366
367 /** 367 /**
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 case "subscription.updated": 428 case "subscription.updated":
429 if ("oldSubscription" in item) 429 if ("oldSubscription" in item)
430 { 430 {
431 // Subscription moved to a new address 431 // Subscription moved to a new address
432 this.addPrivateChange("subscription " + item.url); 432 this.addPrivateChange("subscription " + item.url);
433 this.addPrivateChange("subscription " + item.oldSubscription.url); 433 this.addPrivateChange("subscription " + item.oldSubscription.url);
434 } 434 }
435 else if (item instanceof SpecialSubscription) 435 else if (item instanceof SpecialSubscription)
436 { 436 {
437 // User's filters changed via Preferences window 437 // User's filters changed via Preferences window
438 for each (let filter in item.filters) 438 for (let filter of item.filters)
439 this.addPrivateChange("filter " + filter.text); 439 this.addPrivateChange("filter " + filter.text);
440 for each (let filter in item.oldFilters) 440 for (let filter of item.oldFilters)
441 this.addPrivateChange("filter " + filter.text); 441 this.addPrivateChange("filter " + filter.text);
442 } 442 }
443 break; 443 break;
444 case "subscription.added": 444 case "subscription.added":
445 case "subscription.removed": 445 case "subscription.removed":
446 case "subscription.disabled": 446 case "subscription.disabled":
447 case "subscription.title": 447 case "subscription.title":
448 this.addPrivateChange("subscription " + item.url); 448 this.addPrivateChange("subscription " + item.url);
449 break; 449 break;
450 case "filter.added": 450 case "filter.added":
451 case "filter.removed": 451 case "filter.removed":
452 case "filter.disabled": 452 case "filter.disabled":
453 this.addPrivateChange("filter " + item.text); 453 this.addPrivateChange("filter " + item.text);
454 break; 454 break;
455 } 455 }
456 } 456 }
457 }; 457 };
458 458
459 SyncServiceObserver.init(); 459 SyncServiceObserver.init();
OLDNEW
« no previous file with comments | « lib/subscriptionClasses.js ('k') | lib/synchronizer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld