/toolkit/mozapps/update/nsUpdateServiceStub.js

http://github.com/zpao/v8monkey · JavaScript · 95 lines · 41 code · 8 blank · 46 comment · 1 complexity · bcace7fdde925afbe001b2ed1cfdbf70 MD5 · raw file

  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3. # ***** BEGIN LICENSE BLOCK *****
  4. # Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5. #
  6. # The contents of this file are subject to the Mozilla Public License Version
  7. # 1.1 (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. # http://www.mozilla.org/MPL/
  10. #
  11. # Software distributed under the License is distributed on an "AS IS" basis,
  12. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. # for the specific language governing rights and limitations under the
  14. # License.
  15. #
  16. # The Original Code is the Update Service Stub.
  17. #
  18. # The Initial Developer of the Original Code is Mozilla Foundation
  19. # Portions created by the Initial Developer are Copyright (C) 2009
  20. # the Initial Developer. All Rights Reserved.
  21. #
  22. # Contributor(s):
  23. # Robert Strong <robert.bugzilla@gmail.com> (Original Author)
  24. #
  25. # Alternatively, the contents of this file may be used under the terms of
  26. # either the GNU General Public License Version 2 or later (the "GPL"), or
  27. # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28. # in which case the provisions of the GPL or the LGPL are applicable instead
  29. # of those above. If you wish to allow use of your version of this file only
  30. # under the terms of either the GPL or the LGPL, and not to allow others to
  31. # use your version of this file under the terms of the MPL, indicate your
  32. # decision by deleting the provisions above and replace them with the notice
  33. # and other provisions required by the GPL or the LGPL. If you do not delete
  34. # the provisions above, a recipient may use your version of this file under
  35. # the terms of any one of the MPL, the GPL or the LGPL.
  36. #
  37. # ***** END LICENSE BLOCK ***** */
  38. */
  39. Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
  40. Components.utils.import("resource://gre/modules/FileUtils.jsm");
  41. const Ci = Components.interfaces;
  42. const DIR_UPDATES = "updates";
  43. const FILE_UPDATE_STATUS = "update.status";
  44. const KEY_APPDIR = "XCurProcD";
  45. #ifdef XP_WIN
  46. #define USE_UPDROOT
  47. #elifdef ANDROID
  48. #define USE_UPDROOT
  49. #endif
  50. #ifdef USE_UPDROOT
  51. const KEY_UPDROOT = "UpdRootD";
  52. #endif
  53. /**
  54. # Gets the specified directory at the specified hierarchy under the update root
  55. # directory without creating it if it doesn't exist.
  56. # @param pathArray
  57. # An array of path components to locate beneath the directory
  58. # specified by |key|
  59. # @return nsIFile object for the location specified.
  60. */
  61. function getUpdateDirNoCreate(pathArray) {
  62. #ifdef USE_UPDROOT
  63. try {
  64. let dir = FileUtils.getDir(KEY_UPDROOT, pathArray, false);
  65. return dir;
  66. } catch (e) {
  67. }
  68. #endif
  69. return FileUtils.getDir(KEY_APPDIR, pathArray, false);
  70. }
  71. function UpdateServiceStub() {
  72. let statusFile = getUpdateDirNoCreate([DIR_UPDATES, "0"]);
  73. statusFile.append(FILE_UPDATE_STATUS);
  74. // If the update.status file exists then initiate post update processing.
  75. if (statusFile.exists()) {
  76. let aus = Components.classes["@mozilla.org/updates/update-service;1"].
  77. getService(Ci.nsIApplicationUpdateService).
  78. QueryInterface(Ci.nsIObserver);
  79. aus.observe(null, "post-update-processing", "");
  80. }
  81. }
  82. UpdateServiceStub.prototype = {
  83. observe: function(){},
  84. classID: Components.ID("{e43b0010-04ba-4da6-b523-1f92580bc150}"),
  85. QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver])
  86. };
  87. var NSGetFactory = XPCOMUtils.generateNSGetFactory([UpdateServiceStub]);