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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/installer/setup/setup_util.cc
diff --git a/chrome/installer/setup/setup_util.cc b/chrome/installer/setup/setup_util.cc
index 3fe4e1652f85ac0dbcf200beb17cbc549147247b..768ac1091b364a7e414f17cdebdff7a2ea671dfc 100644
--- a/chrome/installer/setup/setup_util.cc
+++ b/chrome/installer/setup/setup_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
@@ -138,74 +138,4 @@ bool DeleteFileFromTempProcess(const FilePath& path,
return ok != FALSE;
}
-// Open |path| with minimal access to obtain information about it, returning
-// true and populating |handle| on success.
-// static
-bool ProgramCompare::OpenForInfo(const FilePath& path,
- base::win::ScopedHandle* handle) {
- DCHECK(handle);
- handle->Set(base::CreatePlatformFile(path, base::PLATFORM_FILE_OPEN, NULL,
- NULL));
- return handle->IsValid();
-}
-
-// Populate |info| for |handle|, returning true on success.
-// static
-bool ProgramCompare::GetInfo(const base::win::ScopedHandle& handle,
- BY_HANDLE_FILE_INFORMATION* info) {
- DCHECK(handle.IsValid());
- return GetFileInformationByHandle(
- const_cast<base::win::ScopedHandle&>(handle), info) != 0;
-}
-
-ProgramCompare::ProgramCompare(const FilePath& path_to_match)
- : path_to_match_(path_to_match),
- file_handle_(base::kInvalidPlatformFileValue),
- file_info_() {
- DCHECK(!path_to_match_.empty());
- if (!OpenForInfo(path_to_match_, &file_handle_)) {
- PLOG(WARNING) << "Failed opening " << path_to_match_.value()
- << "; falling back to path string comparisons.";
- } else if (!GetInfo(file_handle_, &file_info_)) {
- PLOG(WARNING) << "Failed getting information for "
- << path_to_match_.value()
- << "; falling back to path string comparisons.";
- file_handle_.Close();
- }
-}
-
-ProgramCompare::~ProgramCompare() {
-}
-
-bool ProgramCompare::Evaluate(const std::wstring& value) const {
- // Suss out the exe portion of the value, which is expected to be a command
- // line kinda (or exactly) like:
- // "c:\foo\bar\chrome.exe" -- "%1"
- FilePath program(CommandLine::FromString(value).GetProgram());
- if (program.empty()) {
- LOG(WARNING) << "Failed to parse an executable name from command line: \""
- << value << "\"";
- return false;
- }
-
- // Try the simple thing first: do the paths happen to match?
- if (FilePath::CompareEqualIgnoreCase(path_to_match_.value(), program.value()))
- return true;
-
- // If the paths don't match and we couldn't open the expected file, we've done
- // our best.
- if (!file_handle_.IsValid())
- return false;
-
- // Open the program and see if it references the expected file.
- base::win::ScopedHandle handle;
- BY_HANDLE_FILE_INFORMATION info = {};
-
- return (OpenForInfo(program, &handle) &&
- GetInfo(handle, &info) &&
- info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber &&
- info.nFileIndexHigh == file_info_.nFileIndexHigh &&
- info.nFileIndexLow == file_info_.nFileIndexLow);
-}
-
} // namespace installer

Powered by Google App Engine
This is Rietveld 408576698