| 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 // See the corresponding header file for description of the functions in this | 5 // See the corresponding header file for description of the functions in this |
| 6 // file. | 6 // file. |
| 7 | 7 |
| 8 #include "chrome/installer/util/install_util.h" | 8 #include "chrome/installer/util/install_util.h" |
| 9 | 9 |
| 10 #include <shellapi.h> | 10 #include <shellapi.h> |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 --len; // Subtract terminating \0. | 602 --len; // Subtract terminating \0. |
| 603 } else { | 603 } else { |
| 604 PLOG(DFATAL) << "GetDateFormat"; | 604 PLOG(DFATAL) << "GetDateFormat"; |
| 605 } | 605 } |
| 606 | 606 |
| 607 return base::string16(date_str, len); | 607 return base::string16(date_str, len); |
| 608 } | 608 } |
| 609 | 609 |
| 610 // Open |path| with minimal access to obtain information about it, returning | 610 // Open |path| with minimal access to obtain information about it, returning |
| 611 // true and populating |file| on success. | 611 // true and populating |file| on success. |
| 612 // static | |
| 613 bool InstallUtil::ProgramCompare::OpenForInfo(const base::FilePath& path, | 612 bool InstallUtil::ProgramCompare::OpenForInfo(const base::FilePath& path, |
| 614 base::File* file) { | 613 base::File* file, |
| 614 ComparisonType comparison_type) { |
| 615 DCHECK(file); | 615 DCHECK(file); |
| 616 file->Initialize(path, base::File::FLAG_OPEN); | 616 uint32_t flags = base::File::FLAG_OPEN; |
| 617 if (comparison_type == ComparisonType::FILE_OR_DIRECTORY) |
| 618 flags |= base::File::FLAG_BACKUP_SEMANTICS; |
| 619 file->Initialize(path, flags); |
| 617 return file->IsValid(); | 620 return file->IsValid(); |
| 618 } | 621 } |
| 619 | 622 |
| 620 // Populate |info| for |file|, returning true on success. | 623 // Populate |info| for |file|, returning true on success. |
| 621 // static | 624 // static |
| 622 bool InstallUtil::ProgramCompare::GetInfo(const base::File& file, | 625 bool InstallUtil::ProgramCompare::GetInfo(const base::File& file, |
| 623 BY_HANDLE_FILE_INFORMATION* info) { | 626 BY_HANDLE_FILE_INFORMATION* info) { |
| 624 DCHECK(file.IsValid()); | 627 DCHECK(file.IsValid()); |
| 625 return GetFileInformationByHandle(file.GetPlatformFile(), info) != 0; | 628 return GetFileInformationByHandle(file.GetPlatformFile(), info) != 0; |
| 626 } | 629 } |
| 627 | 630 |
| 628 InstallUtil::ProgramCompare::ProgramCompare(const base::FilePath& path_to_match) | 631 InstallUtil::ProgramCompare::ProgramCompare(const base::FilePath& path_to_match) |
| 632 : ProgramCompare(path_to_match, ComparisonType::FILE) {} |
| 633 |
| 634 InstallUtil::ProgramCompare::ProgramCompare(const base::FilePath& path_to_match, |
| 635 ComparisonType comparison_type) |
| 629 : path_to_match_(path_to_match), | 636 : path_to_match_(path_to_match), |
| 630 file_info_() { | 637 file_info_(), |
| 638 comparison_type_(comparison_type) { |
| 631 DCHECK(!path_to_match_.empty()); | 639 DCHECK(!path_to_match_.empty()); |
| 632 if (!OpenForInfo(path_to_match_, &file_)) { | 640 if (!OpenForInfo(path_to_match_, &file_, comparison_type_)) { |
| 633 PLOG(WARNING) << "Failed opening " << path_to_match_.value() | 641 PLOG(WARNING) << "Failed opening " << path_to_match_.value() |
| 634 << "; falling back to path string comparisons."; | 642 << "; falling back to path string comparisons."; |
| 635 } else if (!GetInfo(file_, &file_info_)) { | 643 } else if (!GetInfo(file_, &file_info_)) { |
| 636 PLOG(WARNING) << "Failed getting information for " | 644 PLOG(WARNING) << "Failed getting information for " |
| 637 << path_to_match_.value() | 645 << path_to_match_.value() |
| 638 << "; falling back to path string comparisons."; | 646 << "; falling back to path string comparisons."; |
| 639 file_.Close(); | 647 file_.Close(); |
| 640 } | 648 } |
| 641 } | 649 } |
| 642 | 650 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 666 | 674 |
| 667 // If the paths don't match and we couldn't open the expected file, we've done | 675 // If the paths don't match and we couldn't open the expected file, we've done |
| 668 // our best. | 676 // our best. |
| 669 if (!file_.IsValid()) | 677 if (!file_.IsValid()) |
| 670 return false; | 678 return false; |
| 671 | 679 |
| 672 // Open the program and see if it references the expected file. | 680 // Open the program and see if it references the expected file. |
| 673 base::File file; | 681 base::File file; |
| 674 BY_HANDLE_FILE_INFORMATION info = {}; | 682 BY_HANDLE_FILE_INFORMATION info = {}; |
| 675 | 683 |
| 676 return (OpenForInfo(path, &file) && | 684 return (OpenForInfo(path, &file, comparison_type_) && GetInfo(file, &info) && |
| 677 GetInfo(file, &info) && | |
| 678 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber && | 685 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber && |
| 679 info.nFileIndexHigh == file_info_.nFileIndexHigh && | 686 info.nFileIndexHigh == file_info_.nFileIndexHigh && |
| 680 info.nFileIndexLow == file_info_.nFileIndexLow); | 687 info.nFileIndexLow == file_info_.nFileIndexLow); |
| 681 } | 688 } |
| OLD | NEW |