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 #include "chrome/installer/util/installer_state.h" | 5 #include "chrome/installer/util/installer_state.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <functional> | 10 #include <functional> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/file_version_info.h" | |
15 #include "base/files/file_enumerator.h" | |
16 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
17 #include "base/logging.h" | 15 #include "base/logging.h" |
18 #include "base/macros.h" | 16 #include "base/macros.h" |
19 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
20 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
21 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
22 #include "base/win/registry.h" | 20 #include "base/win/registry.h" |
23 #include "base/win/scoped_handle.h" | 21 #include "base/win/scoped_handle.h" |
24 #include "chrome/installer/util/delete_tree_work_item.h" | 22 #include "chrome/installer/util/delete_tree_work_item.h" |
25 #include "chrome/installer/util/helper.h" | 23 #include "chrome/installer/util/helper.h" |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 for (int i = 0; i < NUM_BINARIES; ++i) { | 505 for (int i = 0; i < NUM_BINARIES; ++i) { |
508 if (!(file_bits & (1U << i))) | 506 if (!(file_bits & (1U << i))) |
509 continue; | 507 continue; |
510 base::FilePath file(directory.Append(kBinaryFileNames[i])); | 508 base::FilePath file(directory.Append(kBinaryFileNames[i])); |
511 if (base::PathExists(file) && IsFileInUse(file)) | 509 if (base::PathExists(file) && IsFileInUse(file)) |
512 return true; | 510 return true; |
513 } | 511 } |
514 return false; | 512 return false; |
515 } | 513 } |
516 | 514 |
517 void InstallerState::GetExistingExeVersions( | |
518 std::set<std::string>* existing_versions) const { | |
519 | |
520 static const wchar_t* const kChromeFilenames[] = { | |
521 installer::kChromeExe, | |
522 installer::kChromeNewExe, | |
523 installer::kChromeOldExe, | |
524 }; | |
525 | |
526 for (size_t i = 0; i < arraysize(kChromeFilenames); ++i) { | |
527 base::FilePath chrome_exe(target_path().Append(kChromeFilenames[i])); | |
528 scoped_ptr<FileVersionInfo> file_version_info( | |
529 FileVersionInfo::CreateFileVersionInfo(chrome_exe)); | |
530 if (file_version_info) { | |
531 base::string16 version_string = file_version_info->file_version(); | |
532 if (!version_string.empty() && base::IsStringASCII(version_string)) | |
533 existing_versions->insert(base::UTF16ToASCII(version_string)); | |
534 } | |
535 } | |
536 } | |
537 | |
538 void InstallerState::RemoveOldVersionDirectories( | |
539 const Version& new_version, | |
540 Version* existing_version, | |
541 const base::FilePath& temp_path) const { | |
542 Version version; | |
543 scoped_ptr<WorkItem> item; | |
544 | |
545 std::set<std::string> existing_version_strings; | |
546 existing_version_strings.insert(new_version.GetString()); | |
547 if (existing_version) | |
548 existing_version_strings.insert(existing_version->GetString()); | |
549 | |
550 // Make sure not to delete any version dir that is "referenced" by an existing | |
551 // Chrome executable. | |
552 GetExistingExeVersions(&existing_version_strings); | |
553 | |
554 // Try to delete all directories that are not in the set we care to keep. | |
555 base::FileEnumerator version_enum(target_path(), false, | |
556 base::FileEnumerator::DIRECTORIES); | |
557 for (base::FilePath next_version = version_enum.Next(); !next_version.empty(); | |
558 next_version = version_enum.Next()) { | |
559 base::FilePath dir_name(next_version.BaseName()); | |
560 version = Version(base::UTF16ToASCII(dir_name.value())); | |
561 // Delete the version folder if it is less than the new version and not | |
562 // equal to the old version (if we have an old version). | |
563 if (version.IsValid() && | |
564 existing_version_strings.count(version.GetString()) == 0) { | |
565 // Note: temporarily log old version deletion at ERROR level to make it | |
566 // more likely we see this in the installer log. | |
567 LOG(ERROR) << "Deleting old version directory: " << next_version.value(); | |
568 | |
569 // Attempt to recursively delete the old version dir. | |
570 bool delete_succeeded = base::DeleteFile(next_version, true); | |
571 | |
572 // Note: temporarily log old version deletion at ERROR level to make it | |
573 // more likely we see this in the installer log. | |
574 LOG_IF(ERROR, !delete_succeeded) | |
575 << "Failed to delete old version directory: " << next_version.value(); | |
576 } | |
577 } | |
578 } | |
579 | |
580 void InstallerState::AddComDllList( | 515 void InstallerState::AddComDllList( |
581 std::vector<base::FilePath>* com_dll_list) const { | 516 std::vector<base::FilePath>* com_dll_list) const { |
582 for (auto* product : products_) | 517 for (auto* product : products_) |
583 product->AddComDllList(com_dll_list); | 518 product->AddComDllList(com_dll_list); |
584 } | 519 } |
585 | 520 |
586 void InstallerState::UpdateStage(installer::InstallerStage stage) const { | 521 void InstallerState::UpdateStage(installer::InstallerStage stage) const { |
587 InstallUtil::UpdateInstallerStage(system_install(), state_key_, stage); | 522 InstallUtil::UpdateInstallerStage(system_install(), state_key_, stage); |
588 } | 523 } |
589 | 524 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 } | 625 } |
691 if (!install_list->Do()) | 626 if (!install_list->Do()) |
692 LOG(ERROR) << "Failed to record installer error information in registry."; | 627 LOG(ERROR) << "Failed to record installer error information in registry."; |
693 } | 628 } |
694 | 629 |
695 bool InstallerState::RequiresActiveSetup() const { | 630 bool InstallerState::RequiresActiveSetup() const { |
696 return system_install() && FindProduct(BrowserDistribution::CHROME_BROWSER); | 631 return system_install() && FindProduct(BrowserDistribution::CHROME_BROWSER); |
697 } | 632 } |
698 | 633 |
699 } // namespace installer | 634 } // namespace installer |
OLD | NEW |