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