| 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 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 if (len) { | 601 if (len) { |
| 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. If |support_directories| is true, |
| 612 // static | 612 // |path| can be a directory. |
| 613 bool InstallUtil::ProgramCompare::OpenForInfo(const base::FilePath& path, | 613 bool InstallUtil::ProgramCompare::OpenForInfo(const base::FilePath& path, |
| 614 base::File* file) { | 614 base::File* file, |
| 615 bool support_directories) { |
| 615 DCHECK(file); | 616 DCHECK(file); |
| 616 file->Initialize(path, base::File::FLAG_OPEN); | 617 uint32_t flags = base::File::FLAG_OPEN; |
| 618 if (support_directories) |
| 619 flags |= base::File::FLAG_BACKUP_SEMANTICS; |
| 620 file->Initialize(path, flags); |
| 617 return file->IsValid(); | 621 return file->IsValid(); |
| 618 } | 622 } |
| 619 | 623 |
| 620 // Populate |info| for |file|, returning true on success. | 624 // Populate |info| for |file|, returning true on success. |
| 621 // static | 625 // static |
| 622 bool InstallUtil::ProgramCompare::GetInfo(const base::File& file, | 626 bool InstallUtil::ProgramCompare::GetInfo(const base::File& file, |
| 623 BY_HANDLE_FILE_INFORMATION* info) { | 627 BY_HANDLE_FILE_INFORMATION* info) { |
| 624 DCHECK(file.IsValid()); | 628 DCHECK(file.IsValid()); |
| 625 return GetFileInformationByHandle(file.GetPlatformFile(), info) != 0; | 629 return GetFileInformationByHandle(file.GetPlatformFile(), info) != 0; |
| 626 } | 630 } |
| 627 | 631 |
| 628 InstallUtil::ProgramCompare::ProgramCompare(const base::FilePath& path_to_match) | 632 InstallUtil::ProgramCompare::ProgramCompare(const base::FilePath& path_to_match) |
| 633 : ProgramCompare(path_to_match, false) {} |
| 634 |
| 635 InstallUtil::ProgramCompare::ProgramCompare(const base::FilePath& path_to_match, |
| 636 bool support_directories) |
| 629 : path_to_match_(path_to_match), | 637 : path_to_match_(path_to_match), |
| 630 file_info_() { | 638 file_info_(), |
| 639 support_directories_(support_directories) { |
| 631 DCHECK(!path_to_match_.empty()); | 640 DCHECK(!path_to_match_.empty()); |
| 632 if (!OpenForInfo(path_to_match_, &file_)) { | 641 if (!OpenForInfo(path_to_match_, &file_, support_directories_)) { |
| 633 PLOG(WARNING) << "Failed opening " << path_to_match_.value() | 642 PLOG(WARNING) << "Failed opening " << path_to_match_.value() |
| 634 << "; falling back to path string comparisons."; | 643 << "; falling back to path string comparisons."; |
| 635 } else if (!GetInfo(file_, &file_info_)) { | 644 } else if (!GetInfo(file_, &file_info_)) { |
| 636 PLOG(WARNING) << "Failed getting information for " | 645 PLOG(WARNING) << "Failed getting information for " |
| 637 << path_to_match_.value() | 646 << path_to_match_.value() |
| 638 << "; falling back to path string comparisons."; | 647 << "; falling back to path string comparisons."; |
| 639 file_.Close(); | 648 file_.Close(); |
| 640 } | 649 } |
| 641 } | 650 } |
| 642 | 651 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 666 | 675 |
| 667 // If the paths don't match and we couldn't open the expected file, we've done | 676 // If the paths don't match and we couldn't open the expected file, we've done |
| 668 // our best. | 677 // our best. |
| 669 if (!file_.IsValid()) | 678 if (!file_.IsValid()) |
| 670 return false; | 679 return false; |
| 671 | 680 |
| 672 // Open the program and see if it references the expected file. | 681 // Open the program and see if it references the expected file. |
| 673 base::File file; | 682 base::File file; |
| 674 BY_HANDLE_FILE_INFORMATION info = {}; | 683 BY_HANDLE_FILE_INFORMATION info = {}; |
| 675 | 684 |
| 676 return (OpenForInfo(path, &file) && | 685 return (OpenForInfo(path, &file, support_directories_) && |
| 677 GetInfo(file, &info) && | 686 GetInfo(file, &info) && |
| 678 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber && | 687 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber && |
| 679 info.nFileIndexHigh == file_info_.nFileIndexHigh && | 688 info.nFileIndexHigh == file_info_.nFileIndexHigh && |
| 680 info.nFileIndexLow == file_info_.nFileIndexLow); | 689 info.nFileIndexLow == file_info_.nFileIndexLow); |
| 681 } | 690 } |
| OLD | NEW |