| 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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 --len; // Subtract terminating \0. | 523 --len; // Subtract terminating \0. |
| 524 } else { | 524 } else { |
| 525 PLOG(DFATAL) << "GetDateFormat"; | 525 PLOG(DFATAL) << "GetDateFormat"; |
| 526 } | 526 } |
| 527 | 527 |
| 528 return base::string16(date_str, len); | 528 return base::string16(date_str, len); |
| 529 } | 529 } |
| 530 | 530 |
| 531 // Open |path| with minimal access to obtain information about it, returning | 531 // Open |path| with minimal access to obtain information about it, returning |
| 532 // true and populating |file| on success. | 532 // true and populating |file| on success. |
| 533 // static |
| 533 bool InstallUtil::ProgramCompare::OpenForInfo(const base::FilePath& path, | 534 bool InstallUtil::ProgramCompare::OpenForInfo(const base::FilePath& path, |
| 534 base::File* file, | 535 base::File* file) { |
| 535 ComparisonType comparison_type) { | |
| 536 DCHECK(file); | 536 DCHECK(file); |
| 537 uint32_t flags = base::File::FLAG_OPEN; | 537 file->Initialize(path, base::File::FLAG_OPEN); |
| 538 if (comparison_type == ComparisonType::FILE_OR_DIRECTORY) | |
| 539 flags |= base::File::FLAG_BACKUP_SEMANTICS; | |
| 540 file->Initialize(path, flags); | |
| 541 return file->IsValid(); | 538 return file->IsValid(); |
| 542 } | 539 } |
| 543 | 540 |
| 544 // Populate |info| for |file|, returning true on success. | 541 // Populate |info| for |file|, returning true on success. |
| 545 // static | 542 // static |
| 546 bool InstallUtil::ProgramCompare::GetInfo(const base::File& file, | 543 bool InstallUtil::ProgramCompare::GetInfo(const base::File& file, |
| 547 BY_HANDLE_FILE_INFORMATION* info) { | 544 BY_HANDLE_FILE_INFORMATION* info) { |
| 548 DCHECK(file.IsValid()); | 545 DCHECK(file.IsValid()); |
| 549 return GetFileInformationByHandle(file.GetPlatformFile(), info) != 0; | 546 return GetFileInformationByHandle(file.GetPlatformFile(), info) != 0; |
| 550 } | 547 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 list->AddDeleteRegValueWorkItem(root, dist->GetStateKey(), KEY_WOW64_32KEY, | 581 list->AddDeleteRegValueWorkItem(root, dist->GetStateKey(), KEY_WOW64_32KEY, |
| 585 kRegDowngradeVersion); | 582 kRegDowngradeVersion); |
| 586 } else if (*current_version > new_version && !downgrade_version.IsValid()) { | 583 } else if (*current_version > new_version && !downgrade_version.IsValid()) { |
| 587 list->AddSetRegValueWorkItem( | 584 list->AddSetRegValueWorkItem( |
| 588 root, dist->GetStateKey(), KEY_WOW64_32KEY, kRegDowngradeVersion, | 585 root, dist->GetStateKey(), KEY_WOW64_32KEY, kRegDowngradeVersion, |
| 589 base::ASCIIToUTF16(current_version->GetString()), true); | 586 base::ASCIIToUTF16(current_version->GetString()), true); |
| 590 } | 587 } |
| 591 } | 588 } |
| 592 | 589 |
| 593 InstallUtil::ProgramCompare::ProgramCompare(const base::FilePath& path_to_match) | 590 InstallUtil::ProgramCompare::ProgramCompare(const base::FilePath& path_to_match) |
| 594 : ProgramCompare(path_to_match, ComparisonType::FILE) {} | |
| 595 | |
| 596 InstallUtil::ProgramCompare::ProgramCompare(const base::FilePath& path_to_match, | |
| 597 ComparisonType comparison_type) | |
| 598 : path_to_match_(path_to_match), | 591 : path_to_match_(path_to_match), |
| 599 file_info_(), | 592 file_info_() { |
| 600 comparison_type_(comparison_type) { | |
| 601 DCHECK(!path_to_match_.empty()); | 593 DCHECK(!path_to_match_.empty()); |
| 602 if (!OpenForInfo(path_to_match_, &file_, comparison_type_)) { | 594 if (!OpenForInfo(path_to_match_, &file_)) { |
| 603 PLOG(WARNING) << "Failed opening " << path_to_match_.value() | 595 PLOG(WARNING) << "Failed opening " << path_to_match_.value() |
| 604 << "; falling back to path string comparisons."; | 596 << "; falling back to path string comparisons."; |
| 605 } else if (!GetInfo(file_, &file_info_)) { | 597 } else if (!GetInfo(file_, &file_info_)) { |
| 606 PLOG(WARNING) << "Failed getting information for " | 598 PLOG(WARNING) << "Failed getting information for " |
| 607 << path_to_match_.value() | 599 << path_to_match_.value() |
| 608 << "; falling back to path string comparisons."; | 600 << "; falling back to path string comparisons."; |
| 609 file_.Close(); | 601 file_.Close(); |
| 610 } | 602 } |
| 611 } | 603 } |
| 612 | 604 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 636 | 628 |
| 637 // If the paths don't match and we couldn't open the expected file, we've done | 629 // If the paths don't match and we couldn't open the expected file, we've done |
| 638 // our best. | 630 // our best. |
| 639 if (!file_.IsValid()) | 631 if (!file_.IsValid()) |
| 640 return false; | 632 return false; |
| 641 | 633 |
| 642 // Open the program and see if it references the expected file. | 634 // Open the program and see if it references the expected file. |
| 643 base::File file; | 635 base::File file; |
| 644 BY_HANDLE_FILE_INFORMATION info = {}; | 636 BY_HANDLE_FILE_INFORMATION info = {}; |
| 645 | 637 |
| 646 return (OpenForInfo(path, &file, comparison_type_) && GetInfo(file, &info) && | 638 return (OpenForInfo(path, &file) && |
| 639 GetInfo(file, &info) && |
| 647 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber && | 640 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber && |
| 648 info.nFileIndexHigh == file_info_.nFileIndexHigh && | 641 info.nFileIndexHigh == file_info_.nFileIndexHigh && |
| 649 info.nFileIndexLow == file_info_.nFileIndexLow); | 642 info.nFileIndexLow == file_info_.nFileIndexLow); |
| 650 } | 643 } |
| OLD | NEW |