Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: chrome/installer/util/install_util.h

Issue 10446095: Move ProgramCompare from setup_util to install_util. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move tests Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 utility functions for the installer. The original reason 5 // This file declares utility functions for the installer. The original reason
6 // for putting these functions in installer\util library is so that we can 6 // for putting these functions in installer\util library is so that we can
7 // separate out the critical logic and write unit tests for it. 7 // separate out the critical logic and write unit tests for it.
8 8
9 #ifndef CHROME_INSTALLER_UTIL_INSTALL_UTIL_H_ 9 #ifndef CHROME_INSTALLER_UTIL_INSTALL_UTIL_H_
10 #define CHROME_INSTALLER_UTIL_INSTALL_UTIL_H_ 10 #define CHROME_INSTALLER_UTIL_INSTALL_UTIL_H_
11 #pragma once 11 #pragma once
12 12
13 #include <tchar.h> 13 #include <tchar.h>
14 #include <windows.h> 14 #include <windows.h>
15 #include <string>
16 15
17 #include "base/basictypes.h" 16 #include "base/basictypes.h"
18 #include "base/command_line.h" 17 #include "base/command_line.h"
18 #include "base/string16.h"
19 #include "base/win/scoped_handle.h"
19 #include "chrome/installer/util/browser_distribution.h" 20 #include "chrome/installer/util/browser_distribution.h"
20 #include "chrome/installer/util/util_constants.h" 21 #include "chrome/installer/util/util_constants.h"
21 22
22 class Version; 23 class Version;
23 class WorkItemList; 24 class WorkItemList;
24 25
25 // This is a utility class that provides common installation related 26 // This is a utility class that provides common installation related
26 // utility methods that can be used by installer and also unit tested 27 // utility methods that can be used by installer and also unit tested
27 // independently. 28 // independently.
28 class InstallUtil { 29 class InstallUtil {
(...skipping 26 matching lines...) Expand all
55 56
56 // This function checks if the current OS is supported for Chromium. 57 // This function checks if the current OS is supported for Chromium.
57 static bool IsOSSupported(); 58 static bool IsOSSupported();
58 59
59 // Adds work items to |install_list|, which should be a 60 // Adds work items to |install_list|, which should be a
60 // NoRollbackWorkItemList, to set installer error information in the registry 61 // NoRollbackWorkItemList, to set installer error information in the registry
61 // for consumption by Google Update. |state_key| must be the full path to an 62 // for consumption by Google Update. |state_key| must be the full path to an
62 // app's ClientState key. See InstallerState::WriteInstallerResult for more 63 // app's ClientState key. See InstallerState::WriteInstallerResult for more
63 // details. 64 // details.
64 static void AddInstallerResultItems(bool system_install, 65 static void AddInstallerResultItems(bool system_install,
65 const std::wstring& state_key, 66 const string16& state_key,
66 installer::InstallStatus status, 67 installer::InstallStatus status,
67 int string_resource_id, 68 int string_resource_id,
68 const std::wstring* const launch_cmd, 69 const string16* const launch_cmd,
69 WorkItemList* install_list); 70 WorkItemList* install_list);
70 71
71 // Update the installer stage reported by Google Update. |state_key_path| 72 // Update the installer stage reported by Google Update. |state_key_path|
72 // should be obtained via the state_key method of an InstallerState instance 73 // should be obtained via the state_key method of an InstallerState instance
73 // created before the machine state is modified by the installer. 74 // created before the machine state is modified by the installer.
74 static void UpdateInstallerStage(bool system_install, 75 static void UpdateInstallerStage(bool system_install,
75 const std::wstring& state_key_path, 76 const string16& state_key_path,
76 installer::InstallerStage stage); 77 installer::InstallerStage stage);
77 78
78 // Returns true if this installation path is per user, otherwise returns 79 // Returns true if this installation path is per user, otherwise returns
79 // false (per machine install, meaning: the exe_path contains path to 80 // false (per machine install, meaning: the exe_path contains path to
80 // Program Files). 81 // Program Files).
81 static bool IsPerUserInstall(const wchar_t* const exe_path); 82 static bool IsPerUserInstall(const wchar_t* const exe_path);
82 83
83 // Returns true if the installation represented by the pair of |dist| and 84 // Returns true if the installation represented by the pair of |dist| and
84 // |system_level| is a multi install. 85 // |system_level| is a multi install.
85 static bool IsMultiInstall(BrowserDistribution* dist, bool system_install); 86 static bool IsMultiInstall(BrowserDistribution* dist, bool system_install);
86 87
87 // Returns true if this is running setup process for Chrome SxS (as 88 // Returns true if this is running setup process for Chrome SxS (as
88 // indicated by the presence of --chrome-sxs on the command line) or if this 89 // indicated by the presence of --chrome-sxs on the command line) or if this
89 // is running Chrome process from the Chrome SxS installation (as indicated 90 // is running Chrome process from the Chrome SxS installation (as indicated
90 // by either --chrome-sxs or the executable path). 91 // by either --chrome-sxs or the executable path).
91 static bool IsChromeSxSProcess(); 92 static bool IsChromeSxSProcess();
92 93
93 // Returns true if the Chrome installed at |chrome_exe| has a Windows shell 94 // Returns true if the Chrome installed at |chrome_exe| has a Windows shell
94 // DelegateExecute verb handler. 95 // DelegateExecute verb handler.
95 static bool HasDelegateExecuteHandler(BrowserDistribution* dist, 96 static bool HasDelegateExecuteHandler(BrowserDistribution* dist,
96 const string16& chrome_exe); 97 const string16& chrome_exe);
97 98
98 // Deletes the registry key at path key_path under the key given by root_key. 99 // Deletes the registry key at path key_path under the key given by root_key.
99 static bool DeleteRegistryKey(HKEY root_key, const std::wstring& key_path); 100 static bool DeleteRegistryKey(HKEY root_key, const string16& key_path);
100 101
101 // Deletes the registry value named value_name at path key_path under the key 102 // Deletes the registry value named value_name at path key_path under the key
102 // given by reg_root. 103 // given by reg_root.
103 static bool DeleteRegistryValue(HKEY reg_root, const std::wstring& key_path, 104 static bool DeleteRegistryValue(HKEY reg_root, const string16& key_path,
104 const std::wstring& value_name); 105 const string16& value_name);
105 106
106 // An interface to a predicate function for use by DeleteRegistryKeyIf and 107 // An interface to a predicate function for use by DeleteRegistryKeyIf and
107 // DeleteRegistryValueIf. 108 // DeleteRegistryValueIf.
108 class RegistryValuePredicate { 109 class RegistryValuePredicate {
109 public: 110 public:
110 virtual ~RegistryValuePredicate() { } 111 virtual ~RegistryValuePredicate() { }
111 virtual bool Evaluate(const std::wstring& value) const = 0; 112 virtual bool Evaluate(const string16& value) const = 0;
112 }; 113 };
113 114
114 // The result of a conditional delete operation (i.e., DeleteFOOIf). 115 // The result of a conditional delete operation (i.e., DeleteFOOIf).
115 enum ConditionalDeleteResult { 116 enum ConditionalDeleteResult {
116 NOT_FOUND, // The condition was not satisfied. 117 NOT_FOUND, // The condition was not satisfied.
117 DELETED, // The condition was satisfied and the delete succeeded. 118 DELETED, // The condition was satisfied and the delete succeeded.
118 DELETE_FAILED // The condition was satisfied but the delete failed. 119 DELETE_FAILED // The condition was satisfied but the delete failed.
119 }; 120 };
120 121
121 // Deletes the key |key_to_delete_path| under |root_key| iff the value 122 // Deletes the key |key_to_delete_path| under |root_key| iff the value
122 // |value_name| in the key |key_to_test_path| under |root_key| satisfies 123 // |value_name| in the key |key_to_test_path| under |root_key| satisfies
123 // |predicate|. |value_name| must be an empty string to test the key's 124 // |predicate|. |value_name| must be an empty string to test the key's
124 // default value. 125 // default value.
125 static ConditionalDeleteResult DeleteRegistryKeyIf( 126 static ConditionalDeleteResult DeleteRegistryKeyIf(
126 HKEY root_key, 127 HKEY root_key,
127 const std::wstring& key_to_delete_path, 128 const string16& key_to_delete_path,
128 const std::wstring& key_to_test_path, 129 const string16& key_to_test_path,
129 const wchar_t* value_name, 130 const wchar_t* value_name,
130 const RegistryValuePredicate& predicate); 131 const RegistryValuePredicate& predicate);
131 132
132 // Deletes the value |value_name| in the key |key_path| under |root_key| iff 133 // Deletes the value |value_name| in the key |key_path| under |root_key| iff
133 // its current value satisfies |predicate|. |value_name| must be an empty 134 // its current value satisfies |predicate|. |value_name| must be an empty
134 // string to test the key's default value. 135 // string to test the key's default value.
135 static ConditionalDeleteResult DeleteRegistryValueIf( 136 static ConditionalDeleteResult DeleteRegistryValueIf(
136 HKEY root_key, 137 HKEY root_key,
137 const wchar_t* key_path, 138 const wchar_t* key_path,
138 const wchar_t* value_name, 139 const wchar_t* value_name,
139 const RegistryValuePredicate& predicate); 140 const RegistryValuePredicate& predicate);
140 141
141 // A predicate that performs a case-sensitive string comparison. 142 // A predicate that performs a case-sensitive string comparison.
142 class ValueEquals : public RegistryValuePredicate { 143 class ValueEquals : public RegistryValuePredicate {
143 public: 144 public:
144 explicit ValueEquals(const std::wstring& value_to_match) 145 explicit ValueEquals(const string16& value_to_match)
145 : value_to_match_(value_to_match) { } 146 : value_to_match_(value_to_match) { }
146 virtual bool Evaluate(const std::wstring& value) const OVERRIDE; 147 virtual bool Evaluate(const string16& value) const OVERRIDE;
147 protected: 148 protected:
148 std::wstring value_to_match_; 149 string16 value_to_match_;
149 private: 150 private:
150 DISALLOW_COPY_AND_ASSIGN(ValueEquals); 151 DISALLOW_COPY_AND_ASSIGN(ValueEquals);
151 }; 152 };
152 153
153 // Returns zero on install success, or an InstallStatus value otherwise. 154 // Returns zero on install success, or an InstallStatus value otherwise.
154 static int GetInstallReturnCode(installer::InstallStatus install_status); 155 static int GetInstallReturnCode(installer::InstallStatus install_status);
155 156
156 // Composes |program| and |arguments| into |command_line|. 157 // Composes |program| and |arguments| into |command_line|.
157 static void MakeUninstallCommand(const std::wstring& program, 158 static void MakeUninstallCommand(const string16& program,
158 const std::wstring& arguments, 159 const string16& arguments,
159 CommandLine* command_line); 160 CommandLine* command_line);
160 161
161 // Returns a string in the form YYYYMMDD of the current date. 162 // Returns a string in the form YYYYMMDD of the current date.
162 static std::wstring GetCurrentDate(); 163 static string16 GetCurrentDate();
164
165 // A predicate that compares the program portion of a command line with a
166 // given file path. First, the file paths are compared directly. If they do
167 // not match, the filesystem is consulted to determine if the paths reference
168 // the same file.
169 class ProgramCompare : public RegistryValuePredicate {
170 public:
171 explicit ProgramCompare(const FilePath& path_to_match);
172 virtual ~ProgramCompare();
173 virtual bool Evaluate(const string16& value) const OVERRIDE;
174
175 protected:
176 static bool OpenForInfo(const FilePath& path,
177 base::win::ScopedHandle* handle);
178 static bool GetInfo(const base::win::ScopedHandle& handle,
179 BY_HANDLE_FILE_INFORMATION* info);
180
181 FilePath path_to_match_;
182 base::win::ScopedHandle file_handle_;
183 BY_HANDLE_FILE_INFORMATION file_info_;
184
185 private:
186 DISALLOW_COPY_AND_ASSIGN(ProgramCompare);
187 }; // class ProgramCompare
163 188
164 private: 189 private:
165 DISALLOW_COPY_AND_ASSIGN(InstallUtil); 190 DISALLOW_COPY_AND_ASSIGN(InstallUtil);
166 }; 191 };
167 192
168 193
169 #endif // CHROME_INSTALLER_UTIL_INSTALL_UTIL_H_ 194 #endif // CHROME_INSTALLER_UTIL_INSTALL_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698