Home | History | Annotate | Download | only in setup
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 //
      5 // This file declares util functions for setup project. It also declares a
      6 // few functions that the Chrome component updater uses for patching binary
      7 // deltas.
      8 
      9 #ifndef CHROME_INSTALLER_SETUP_SETUP_UTIL_H_
     10 #define CHROME_INSTALLER_SETUP_SETUP_UTIL_H_
     11 
     12 #include <windows.h>
     13 
     14 #include "base/basictypes.h"
     15 #include "base/strings/string16.h"
     16 #include "base/win/scoped_handle.h"
     17 #include "chrome/installer/util/browser_distribution.h"
     18 #include "chrome/installer/util/util_constants.h"
     19 
     20 class CommandLine;
     21 
     22 namespace base {
     23 class FilePath;
     24 class Version;
     25 }
     26 
     27 namespace installer {
     28 
     29 class InstallationState;
     30 class InstallerState;
     31 class ProductState;
     32 
     33 // Applies a patch file to source file using Courgette. Returns 0 in case of
     34 // success. In case of errors, it returns kCourgetteErrorOffset + a Courgette
     35 // status code, as defined in courgette/courgette.h
     36 int CourgettePatchFiles(const base::FilePath& src,
     37                         const base::FilePath& patch,
     38                         const base::FilePath& dest);
     39 
     40 // Applies a patch file to source file using bsdiff. This function uses
     41 // Courgette's flavor of bsdiff. Returns 0 in case of success, or
     42 // kBsdiffErrorOffset + a bsdiff status code in case of errors.
     43 // See courgette/third_party/bsdiff.h for details.
     44 int BsdiffPatchFiles(const base::FilePath& src,
     45                      const base::FilePath& patch,
     46                      const base::FilePath& dest);
     47 
     48 // Find the version of Chrome from an install source directory.
     49 // Chrome_path should contain at least one version folder.
     50 // Returns the maximum version found or NULL if no version is found.
     51 Version* GetMaxVersionFromArchiveDir(const base::FilePath& chrome_path);
     52 
     53 // Returns the uncompressed archive of the installed version that serves as the
     54 // source for patching.
     55 base::FilePath FindArchiveToPatch(const InstallationState& original_state,
     56                                   const InstallerState& installer_state);
     57 
     58 // Spawns a new process that waits for a specified amount of time before
     59 // attempting to delete |path|.  This is useful for setup to delete the
     60 // currently running executable or a file that we cannot close right away but
     61 // estimate that it will be possible after some period of time.
     62 // Returns true if a new process was started, false otherwise.  Note that
     63 // given the nature of this function, it is not possible to know if the
     64 // delete operation itself succeeded.
     65 bool DeleteFileFromTempProcess(const base::FilePath& path,
     66                                uint32 delay_before_delete_ms);
     67 
     68 // Returns true and populates |setup_exe| with the path to an existing product
     69 // installer if one is found that is newer than the currently running installer
     70 // (|installer_version|).
     71 bool GetExistingHigherInstaller(const InstallationState& original_state,
     72                                 bool system_install,
     73                                 const base::Version& installer_version,
     74                                 base::FilePath* setup_exe);
     75 
     76 // Invokes the pre-existing |setup_exe| to handle the current operation (as
     77 // dictated by |command_line|). An installerdata file, if specified, is first
     78 // unconditionally copied into place so that it will be in effect in case the
     79 // invoked |setup_exe| runs the newly installed product prior to exiting.
     80 // Returns true if |setup_exe| was launched, false otherwise.
     81 bool DeferToExistingInstall(const base::FilePath& setup_exe,
     82                             const CommandLine& command_line,
     83                             const InstallerState& installer_state,
     84                             const base::FilePath& temp_path,
     85                             InstallStatus* install_status);
     86 
     87 // Returns true if the product |type| will be installed after the current
     88 // setup.exe instance have carried out installation / uninstallation, at
     89 // the level specified by |installer_state|.
     90 // This function only returns meaningful results for install and update
     91 // operations if called after CheckPreInstallConditions (see setup_main.cc).
     92 bool WillProductBePresentAfterSetup(
     93     const installer::InstallerState& installer_state,
     94     const installer::InstallationState& machine_state,
     95     BrowserDistribution::Type type);
     96 
     97 // Drops the process down to background processing mode on supported OSes if it
     98 // was launched below the normal process priority. Returns true when background
     99 // procesing mode is entered.
    100 bool AdjustProcessPriority();
    101 
    102 // Makes registry adjustments to migrate the Google Update state of |to_migrate|
    103 // from multi-install to single-install. This includes copying the usagestats
    104 // value and adjusting the ap values of all multi-install products.
    105 void MigrateGoogleUpdateStateMultiToSingle(
    106     bool system_level,
    107     BrowserDistribution::Type to_migrate,
    108     const installer::InstallationState& machine_state);
    109 
    110 // This class will enable the privilege defined by |privilege_name| on the
    111 // current process' token. The privilege will be disabled upon the
    112 // ScopedTokenPrivilege's destruction (unless it was already enabled when the
    113 // ScopedTokenPrivilege object was constructed).
    114 // Some privileges might require admin rights to be enabled (check is_enabled()
    115 // to know whether |privilege_name| was successfully enabled).
    116 class ScopedTokenPrivilege {
    117  public:
    118   explicit ScopedTokenPrivilege(const wchar_t* privilege_name);
    119   ~ScopedTokenPrivilege();
    120 
    121   // Always returns true unless the privilege could not be enabled.
    122   bool is_enabled() const { return is_enabled_; }
    123 
    124  private:
    125   // Always true unless the privilege could not be enabled.
    126   bool is_enabled_;
    127 
    128   // A scoped handle to the current process' token. This will be closed
    129   // preemptively should enabling the privilege fail in the constructor.
    130   base::win::ScopedHandle token_;
    131 
    132   // The previous state of the privilege this object is responsible for. As set
    133   // by AdjustTokenPrivileges() upon construction.
    134   TOKEN_PRIVILEGES previous_privileges_;
    135 
    136   DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedTokenPrivilege);
    137 };
    138 
    139 }  // namespace installer
    140 
    141 #endif  // CHROME_INSTALLER_SETUP_SETUP_UTIL_H_
    142