| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // This file declares util functions for setup project. | 5 // This file declares util functions for setup project. |
| 6 | 6 |
| 7 #ifndef CHROME_INSTALLER_SETUP_SETUP_UTIL_H_ | 7 #ifndef CHROME_INSTALLER_SETUP_SETUP_UTIL_H_ |
| 8 #define CHROME_INSTALLER_SETUP_SETUP_UTIL_H_ | 8 #define CHROME_INSTALLER_SETUP_SETUP_UTIL_H_ |
| 9 | 9 |
| 10 #include <windows.h> |
| 11 |
| 12 #include "base/basictypes.h" |
| 10 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/string16.h" |
| 11 #include "base/version.h" | 15 #include "base/version.h" |
| 16 #include "base/win/scoped_handle.h" |
| 17 #include "chrome/installer/util/browser_distribution.h" |
| 12 | 18 |
| 13 namespace installer { | 19 namespace installer { |
| 14 | 20 |
| 15 class InstallerState; | 21 class InstallerState; |
| 16 | 22 |
| 17 // Apply a diff patch to source file. First tries to apply it using courgette | 23 // Apply a diff patch to source file. First tries to apply it using courgette |
| 18 // since it checks for courgette header and fails quickly. If that fails | 24 // since it checks for courgette header and fails quickly. If that fails |
| 19 // tries to apply the patch using regular bsdiff. Returns status code. | 25 // tries to apply the patch using regular bsdiff. Returns status code. |
| 20 // The installer stage is updated if |installer_state| is non-NULL. | 26 // The installer stage is updated if |installer_state| is non-NULL. |
| 21 int ApplyDiffPatch(const FilePath& src, | 27 int ApplyDiffPatch(const FilePath& src, |
| 22 const FilePath& patch, | 28 const FilePath& patch, |
| 23 const FilePath& dest, | 29 const FilePath& dest, |
| 24 const InstallerState* installer_state); | 30 const InstallerState* installer_state); |
| 25 | 31 |
| 26 // Find the version of Chrome from an install source directory. | 32 // Find the version of Chrome from an install source directory. |
| 27 // Chrome_path should contain at least one version folder. | 33 // Chrome_path should contain at least one version folder. |
| 28 // Returns the maximum version found or NULL if no version is found. | 34 // Returns the maximum version found or NULL if no version is found. |
| 29 Version* GetMaxVersionFromArchiveDir(const FilePath& chrome_path); | 35 Version* GetMaxVersionFromArchiveDir(const FilePath& chrome_path); |
| 30 | 36 |
| 31 // Spawns a new process that waits for a specified amount of time before | 37 // Spawns a new process that waits for a specified amount of time before |
| 32 // attempting to delete |path|. This is useful for setup to delete the | 38 // attempting to delete |path|. This is useful for setup to delete the |
| 33 // currently running executable or a file that we cannot close right away but | 39 // currently running executable or a file that we cannot close right away but |
| 34 // estimate that it will be possible after some period of time. | 40 // estimate that it will be possible after some period of time. |
| 35 // Returns true if a new process was started, false otherwise. Note that | 41 // Returns true if a new process was started, false otherwise. Note that |
| 36 // given the nature of this function, it is not possible to know if the | 42 // given the nature of this function, it is not possible to know if the |
| 37 // delete operation itself succeeded. | 43 // delete operation itself succeeded. |
| 38 bool DeleteFileFromTempProcess(const FilePath& path, | 44 bool DeleteFileFromTempProcess(const FilePath& path, |
| 39 uint32 delay_before_delete_ms); | 45 uint32 delay_before_delete_ms); |
| 40 | 46 |
| 47 // Get the path to this distribution's Active Setup registry entries. |
| 48 // e.g. Software\Microsoft\Active Setup\Installed Components\<dist_guid> |
| 49 string16 GetActiveSetupPath(BrowserDistribution* dist); |
| 50 |
| 51 // This class will enable the privilege defined by |privilege_name| on the |
| 52 // current process' token. The privilege will be disabled upon the |
| 53 // ScopedTokenPrivilege's destruction (unless it was already enabled when the |
| 54 // ScopedTokenPrivilege object was constructed). |
| 55 // Some privileges might require admin rights to be enabled (check is_enabled() |
| 56 // to know whether |privilege_name| was successfully enabled). |
| 57 class ScopedTokenPrivilege { |
| 58 public: |
| 59 explicit ScopedTokenPrivilege(const wchar_t* privilege_name); |
| 60 ~ScopedTokenPrivilege(); |
| 61 |
| 62 // Always returns true unless the privilege could not be enabled. |
| 63 bool is_enabled() const { return is_enabled_; } |
| 64 |
| 65 private: |
| 66 // Always true unless the privilege could not be enabled. |
| 67 bool is_enabled_; |
| 68 |
| 69 // A scoped handle to the current process' token. This will be closed |
| 70 // preemptively should enabling the privilege fail in the constructor. |
| 71 base::win::ScopedHandle token_; |
| 72 |
| 73 // The previous state of the privilege this object is responsible for. As set |
| 74 // by AdjustTokenPrivileges() upon construction. |
| 75 TOKEN_PRIVILEGES previous_privileges_; |
| 76 |
| 77 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedTokenPrivilege); |
| 78 }; |
| 79 |
| 41 } // namespace installer | 80 } // namespace installer |
| 42 | 81 |
| 43 #endif // CHROME_INSTALLER_SETUP_SETUP_UTIL_H_ | 82 #endif // CHROME_INSTALLER_SETUP_SETUP_UTIL_H_ |
| OLD | NEW |