~ubuntu-branches/ubuntu/trusty/ubufox/trusty-proposed

« back to all changes in this revision

Viewing changes to components/UpdateNotifier.js

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-11-12 13:27:26 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20121112132726-ssrixfmjgibo8f3s
Tags: 2.6-0ubuntu1
* New upstream release.
  - Translation updates, thanks to Adolfo Jayme Barrientos and David Planella

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
45
45
Cu.import("resource://gre/modules/FileUtils.jsm");
46
46
Cu.import("resource://gre/modules/ctypes.jsm");
 
47
Cu.import("resource://ubufox/modules/utils.jsm");
 
48
Cu.import("resource://ubufox/libs/gio.jsm");
 
49
Cu.import("resource://ubufox/libs/gobject.jsm");
47
50
Cu.import("resource://ubufox/libs/glib.jsm");
48
 
Cu.import("resource://ubufox/libs/gobject.jsm");
49
 
Cu.import("resource://ubufox/libs/gio.jsm");
50
51
 
51
52
const NS_XPCOM_CURRENT_PROCESS_DIR        = "XCurProcD";
52
53
const NS_GRE_DIR                          = "GreD";
57
58
const XRE_SYS_SHARE_EXTENSION_PARENT_DIR  = "XRESysSExtPD";
58
59
const XRE_EXTENSIONS_DIR_LIST             = "XREExtDL";
59
60
 
60
 
["LOG", "WARN", "ERROR"].forEach(function(aName) {
61
 
  this.__defineGetter__(aName, function() {
62
 
    Components.utils.import("resource://gre/modules/AddonLogging.jsm");
63
 
 
64
 
    LogManager.getLogger("ubufox.urn", this);
65
 
    return this[aName];
66
 
  });
67
 
}, this);
 
61
addLogger(this, "update-notifier");
68
62
 
69
63
function UpdateNotifier() {
70
64
  LOG("Starting");
104
98
          aListener[event].apply(aListener, dispatched[event]);
105
99
        }
106
100
      } catch(e) {
107
 
        Cu.reportError(e);
 
101
        ERROR("Listener threw", e);
108
102
      }
109
103
    }
110
104
  };
138
132
          listener[aEvent].apply(listener);
139
133
        }
140
134
      } catch(e) {
141
 
        Cu.reportError(e);
 
135
        ERROR("Listener threw", e);
142
136
      }
143
137
    });
144
138
  }
272
266
  }
273
267
 
274
268
  function handler(aFile, aEventType, aIsDir) {
275
 
    let cpath = new ctypes.char.ptr;
276
 
    try {
277
 
      if (aEventType == gio.G_FILE_MONITOR_EVENT_CHANGED ||
278
 
          aEventType == gio.G_FILE_MONITOR_EVENT_DELETED ||
279
 
          aEventType == gio.G_FILE_MONITOR_EVENT_CREATED ||
280
 
          aEventType == gio.G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED) {
281
 
        cpath = gio.g_file_get_path(aFile);
282
 
        path = cpath.readString();
283
 
        var type;
284
 
        if (!(path in watches) && aIsDir) {
285
 
          type = watches[(new FileUtils.File(path)).parent.path].type;
286
 
        } else {
287
 
          type = watches[path].type;
288
 
        }
289
 
 
290
 
        if (!type) {
291
 
          Cu.reportError("Got event for a path not in our watch list: " +
292
 
                         path)
293
 
          return;
294
 
        }
295
 
 
296
 
        // Wait for the location to settle before dispatching the notification
297
 
        if (!(type in timers)) {
298
 
          timers[type] = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
299
 
          timers[type].initWithCallback(function() {
300
 
            delete timers[type];
301
 
            ((new Object({"app"    : handleAppUpdated,
302
 
                          "plugins": handlePluginsChanged,
303
 
                          "addons" : handleAddonsChanged}))[type])();
304
 
          }, 10000, Ci.nsITimer.TYPE_ONE_SHOT);
305
 
        } else {
306
 
          timers[type].delay = 10000;
307
 
        }
308
 
      }
309
 
    } finally {
310
 
      glib.g_free(cpath);
 
269
    if (aEventType == gio.GFileMonitorEventEnums.G_FILE_MONITOR_EVENT_CHANGED ||
 
270
        aEventType == gio.GFileMonitorEventEnums.G_FILE_MONITOR_EVENT_DELETED ||
 
271
        aEventType == gio.GFileMonitorEventEnums.G_FILE_MONITOR_EVENT_CREATED ||
 
272
        aEventType == gio.GFileMonitorEventEnums.G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED) {
 
273
      let path = gio.g_file_get_path(aFile);
 
274
      let type;
 
275
      if (!(path in watches) && aIsDir) {
 
276
        type = watches[(new FileUtils.File(path)).parent.path].type;
 
277
      } else {
 
278
        type = watches[path].type;
 
279
      }
 
280
 
 
281
      if (!type) {
 
282
        ERROR("Got event for a path not in our watch list: " + path);
 
283
        return;
 
284
      }
 
285
 
 
286
      // Wait for the location to settle before dispatching the notification
 
287
      if (!(type in timers)) {
 
288
        timers[type] = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
 
289
        timers[type].initWithCallback(function() {
 
290
          delete timers[type];
 
291
          ((new Object({"app"    : handleAppUpdated,
 
292
                        "plugins": handlePluginsChanged,
 
293
                        "addons" : handleAddonsChanged}))[type])();
 
294
        }, 10000, Ci.nsITimer.TYPE_ONE_SHOT);
 
295
      } else {
 
296
        timers[type].delay = 10000;
 
297
      }
311
298
    }
312
299
  }
313
300
 
320
307
 
321
308
    let file = gio.g_file_new_for_path(aFile.path);
322
309
    if (file.isNull()) {
323
 
      Cu.reportError("OOM: Failed to get GFile for path " + aFile.path);
 
310
      ERROR("OOM: Failed to get GFile for path " + aFile.path);
324
311
      return;
325
312
    }
326
313
 
327
 
    let mon = gio.g_file_monitor_file(file, gio.G_FILE_MONITOR_NONE,
 
314
    let mon = gio.g_file_monitor_file(file,
 
315
                                      gio.GFileMonitorFlagsFlags.G_FILE_MONITOR_NONE,
328
316
                                      null, null);
329
317
    gobject.g_object_unref(file);
330
318
    if (mon.isNull()) {
331
 
      Cu.reportError("Failed to create monitor for path " + aFile.path);
 
319
      ERROR("Failed to create monitor for path " + aFile.path);
332
320
      return;
333
321
    }
334
322
 
335
 
    let id = gobject.GSignalConnect(mon, "changed", function(aMonitor,
336
 
                                                             aFile,
337
 
                                                             aOtherFile,
338
 
                                                             aEventType,
339
 
                                                             aUserData) {
 
323
    let id = gobject.g_signal_connect(mon, "changed",
 
324
                                      function(aMonitor, aFile, aOtherFile,
 
325
                                               aEventType) {
340
326
      handler(aFile, aEventType, false);    
341
 
    }, ctypes.void_t, [gio.GFileMonitor.ptr, gio.GFile.ptr, gio.GFile.ptr,
342
 
                       gio.GFileMonitorEvent, glib.gpointer]);
 
327
    });
343
328
    watches[aFile.path] = {monitor: mon, sig_id: id, type: aType};
344
329
    LOG("Watching " + aFile.path);
345
330
  }
366
351
 
367
352
    let file = gio.g_file_new_for_path(nsifile.path);
368
353
    if (file.isNull()) {
369
 
      Cu.reportError("OOM: Failed to get GFile for path " + nsifile.path);
 
354
      ERROR("OOM: Failed to get GFile for path " + nsifile.path);
370
355
      return;
371
356
    }
372
357
 
373
 
    let mon = gio.g_file_monitor_directory(file, gio.G_FILE_MONITOR_NONE,
 
358
    let mon = gio.g_file_monitor_directory(file,
 
359
                                           gio.GFileMonitorFlagsFlags.G_FILE_MONITOR_NONE,
374
360
                                           null, null);
375
361
    gobject.g_object_unref(file);
376
362
    if (mon.isNull()) {
377
 
      Cu.reportError("Failed to create monitor for path " + nsifile.path);
 
363
      ERROR("Failed to create monitor for path " + nsifile.path);
378
364
      return;
379
365
    }
380
366
 
381
 
    let id = gobject.GSignalConnect(mon, "changed", function(aMonitor,
382
 
                                                             aFile,
383
 
                                                             aOtherFile,
384
 
                                                             aEventType,
385
 
                                                             aUserData) {
 
367
    let id = gobject.g_signal_connect(mon, "changed",
 
368
                                      function(aMonitor, aFile, aOtherFile,
 
369
                                               aEventType) {
386
370
      handler(aFile, aEventType, true);
387
 
    }, ctypes.void_t, [gio.GFileMonitor.ptr, gio.GFile.ptr, gio.GFile.ptr,
388
 
                       gio.GFileMonitorEvent, glib.gpointer]);
 
371
    });
389
372
    watches[nsifile.path] = {monitor: mon, sig_id: id, type: aType};
390
373
    LOG("Watching " + nsifile.path);
391
374
  }
424
407
    if (aSubject == "xpcom-shutdown") {
425
408
      Services.obs.removeObserver(arguments.callee, "xpcom-shutdown", false);
426
409
      for (let path in watches) {
427
 
        gobject.GSignalHandlerDisconnect(watches[path].monitor,
428
 
                                         watches[path].sig_id);
 
410
        gobject.g_signal_handler_disconnect(watches[path].monitor,
 
411
                                            watches[path].sig_id);
429
412
        gobject.g_object_unref(watches[path].monitor);
430
413
      }
431
414
    }