PageRenderTime 11ms CodeModel.GetById 7ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/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*/
39Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
40Components.utils.import("resource://gre/modules/FileUtils.jsm");
41
42const Ci = Components.interfaces;
43
44const DIR_UPDATES         = "updates";
45const FILE_UPDATE_STATUS  = "update.status";
46
47const KEY_APPDIR          = "XCurProcD";
48
49#ifdef XP_WIN
50#define USE_UPDROOT
51#elifdef ANDROID
52#define USE_UPDROOT
53#endif
54
55#ifdef USE_UPDROOT
56const KEY_UPDROOT         = "UpdRootD";
57#endif
58
59/**
60#  Gets the specified directory at the specified hierarchy under the update root
61#  directory without creating it if it doesn't exist.
62#  @param   pathArray
63#           An array of path components to locate beneath the directory
64#           specified by |key|
65#  @return  nsIFile object for the location specified.
66 */
67function getUpdateDirNoCreate(pathArray) {
68#ifdef USE_UPDROOT
69  try {
70    let dir = FileUtils.getDir(KEY_UPDROOT, pathArray, false);
71    return dir;
72  } catch (e) {
73  }
74#endif
75  return FileUtils.getDir(KEY_APPDIR, pathArray, false);
76}
77
78function UpdateServiceStub() {
79  let statusFile = getUpdateDirNoCreate([DIR_UPDATES, "0"]);
80  statusFile.append(FILE_UPDATE_STATUS);
81  // If the update.status file exists then initiate post update processing.
82  if (statusFile.exists()) {
83    let aus = Components.classes["@mozilla.org/updates/update-service;1"].
84              getService(Ci.nsIApplicationUpdateService).
85              QueryInterface(Ci.nsIObserver);
86    aus.observe(null, "post-update-processing", "");
87  }
88}
89UpdateServiceStub.prototype = {
90  observe: function(){},
91  classID: Components.ID("{e43b0010-04ba-4da6-b523-1f92580bc150}"),
92  QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver])
93};
94
95var NSGetFactory = XPCOMUtils.generateNSGetFactory([UpdateServiceStub]);