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 <memory> | 11 #include <memory> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/file_version_info.h" | |
16 #include "base/files/file_enumerator.h" | |
17 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
18 #include "base/logging.h" | 16 #include "base/logging.h" |
19 #include "base/macros.h" | 17 #include "base/macros.h" |
20 #include "base/strings/string_util.h" | |
21 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
22 #include "base/win/registry.h" | 19 #include "base/win/registry.h" |
23 #include "base/win/scoped_handle.h" | 20 #include "base/win/scoped_handle.h" |
24 #include "chrome/installer/util/delete_tree_work_item.h" | 21 #include "chrome/installer/util/delete_tree_work_item.h" |
25 #include "chrome/installer/util/google_update_settings.h" | 22 #include "chrome/installer/util/google_update_settings.h" |
26 #include "chrome/installer/util/helper.h" | 23 #include "chrome/installer/util/helper.h" |
27 #include "chrome/installer/util/install_util.h" | 24 #include "chrome/installer/util/install_util.h" |
28 #include "chrome/installer/util/installation_state.h" | 25 #include "chrome/installer/util/installation_state.h" |
29 #include "chrome/installer/util/master_preferences.h" | 26 #include "chrome/installer/util/master_preferences.h" |
30 #include "chrome/installer/util/master_preferences_constants.h" | 27 #include "chrome/installer/util/master_preferences_constants.h" |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 for (int i = 0; i < NUM_BINARIES; ++i) { | 504 for (int i = 0; i < NUM_BINARIES; ++i) { |
508 if (!(file_bits & (1U << i))) | 505 if (!(file_bits & (1U << i))) |
509 continue; | 506 continue; |
510 base::FilePath file(directory.Append(kBinaryFileNames[i])); | 507 base::FilePath file(directory.Append(kBinaryFileNames[i])); |
511 if (base::PathExists(file) && IsFileInUse(file)) | 508 if (base::PathExists(file) && IsFileInUse(file)) |
512 return true; | 509 return true; |
513 } | 510 } |
514 return false; | 511 return false; |
515 } | 512 } |
516 | 513 |
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 std::unique_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 base::Version& new_version, | |
540 base::Version* existing_version, | |
541 const base::FilePath& temp_path) const { | |
542 base::Version version; | |
543 std::unique_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 = base::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( | 514 void InstallerState::AddComDllList( |
581 std::vector<base::FilePath>* com_dll_list) const { | 515 std::vector<base::FilePath>* com_dll_list) const { |
582 for (auto* product : products_) | 516 for (auto* product : products_) |
583 product->AddComDllList(com_dll_list); | 517 product->AddComDllList(com_dll_list); |
584 } | 518 } |
585 | 519 |
586 void InstallerState::SetStage(InstallerStage stage) const { | 520 void InstallerState::SetStage(InstallerStage stage) const { |
587 GoogleUpdateSettings::SetProgress(system_install(), state_key_, | 521 GoogleUpdateSettings::SetProgress(system_install(), state_key_, |
588 progress_calculator_.Calculate(stage)); | 522 progress_calculator_.Calculate(stage)); |
589 } | 523 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 status, string_resource_id, launch_cmd, install_list.get()); | 626 status, string_resource_id, launch_cmd, install_list.get()); |
693 } | 627 } |
694 install_list->Do(); | 628 install_list->Do(); |
695 } | 629 } |
696 | 630 |
697 bool InstallerState::RequiresActiveSetup() const { | 631 bool InstallerState::RequiresActiveSetup() const { |
698 return system_install() && FindProduct(BrowserDistribution::CHROME_BROWSER); | 632 return system_install() && FindProduct(BrowserDistribution::CHROME_BROWSER); |
699 } | 633 } |
700 | 634 |
701 } // namespace installer | 635 } // namespace installer |
OLD | NEW |