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

Side by Side Diff: chrome/installer/setup/setup_util.cc

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) 2011 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 #include "chrome/installer/setup/setup_util.h" 7 #include "chrome/installer/setup/setup_util.h"
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 PLOG(ERROR) << "VirtualAllocEx"; 131 PLOG(ERROR) << "VirtualAllocEx";
132 ::TerminateProcess(pi.hProcess, ~0); 132 ::TerminateProcess(pi.hProcess, ~0);
133 } 133 }
134 ::CloseHandle(pi.hThread); 134 ::CloseHandle(pi.hThread);
135 ::CloseHandle(pi.hProcess); 135 ::CloseHandle(pi.hProcess);
136 } 136 }
137 137
138 return ok != FALSE; 138 return ok != FALSE;
139 } 139 }
140 140
141 // Open |path| with minimal access to obtain information about it, returning
142 // true and populating |handle| on success.
143 // static
144 bool ProgramCompare::OpenForInfo(const FilePath& path,
145 base::win::ScopedHandle* handle) {
146 DCHECK(handle);
147 handle->Set(base::CreatePlatformFile(path, base::PLATFORM_FILE_OPEN, NULL,
148 NULL));
149 return handle->IsValid();
150 }
151
152 // Populate |info| for |handle|, returning true on success.
153 // static
154 bool ProgramCompare::GetInfo(const base::win::ScopedHandle& handle,
155 BY_HANDLE_FILE_INFORMATION* info) {
156 DCHECK(handle.IsValid());
157 return GetFileInformationByHandle(
158 const_cast<base::win::ScopedHandle&>(handle), info) != 0;
159 }
160
161 ProgramCompare::ProgramCompare(const FilePath& path_to_match)
162 : path_to_match_(path_to_match),
163 file_handle_(base::kInvalidPlatformFileValue),
164 file_info_() {
165 DCHECK(!path_to_match_.empty());
166 if (!OpenForInfo(path_to_match_, &file_handle_)) {
167 PLOG(WARNING) << "Failed opening " << path_to_match_.value()
168 << "; falling back to path string comparisons.";
169 } else if (!GetInfo(file_handle_, &file_info_)) {
170 PLOG(WARNING) << "Failed getting information for "
171 << path_to_match_.value()
172 << "; falling back to path string comparisons.";
173 file_handle_.Close();
174 }
175 }
176
177 ProgramCompare::~ProgramCompare() {
178 }
179
180 bool ProgramCompare::Evaluate(const std::wstring& value) const {
181 // Suss out the exe portion of the value, which is expected to be a command
182 // line kinda (or exactly) like:
183 // "c:\foo\bar\chrome.exe" -- "%1"
184 FilePath program(CommandLine::FromString(value).GetProgram());
185 if (program.empty()) {
186 LOG(WARNING) << "Failed to parse an executable name from command line: \""
187 << value << "\"";
188 return false;
189 }
190
191 // Try the simple thing first: do the paths happen to match?
192 if (FilePath::CompareEqualIgnoreCase(path_to_match_.value(), program.value()))
193 return true;
194
195 // If the paths don't match and we couldn't open the expected file, we've done
196 // our best.
197 if (!file_handle_.IsValid())
198 return false;
199
200 // Open the program and see if it references the expected file.
201 base::win::ScopedHandle handle;
202 BY_HANDLE_FILE_INFORMATION info = {};
203
204 return (OpenForInfo(program, &handle) &&
205 GetInfo(handle, &info) &&
206 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber &&
207 info.nFileIndexHigh == file_info_.nFileIndexHigh &&
208 info.nFileIndexLow == file_info_.nFileIndexLow);
209 }
210
211 } // namespace installer 141 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698