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 <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 | 405 |
406 // Be aware that there might be a pending "new_chrome.exe" already in the | 406 // Be aware that there might be a pending "new_chrome.exe" already in the |
407 // installation path. If so, we use old_version, which holds the version of | 407 // installation path. If so, we use old_version, which holds the version of |
408 // "chrome.exe" itself. | 408 // "chrome.exe" itself. |
409 if (file_util::PathExists(target_path().Append(kChromeNewExe))) | 409 if (file_util::PathExists(target_path().Append(kChromeNewExe))) |
410 version = product_state->old_version(); | 410 version = product_state->old_version(); |
411 | 411 |
412 if (version == NULL) | 412 if (version == NULL) |
413 version = &product_state->version(); | 413 version = &product_state->version(); |
414 | 414 |
415 current_version.reset(version->Clone()); | 415 current_version.reset(new Version(*version)); |
416 } | 416 } |
417 | 417 |
418 return current_version.release(); | 418 return current_version.release(); |
419 } | 419 } |
420 | 420 |
421 Version InstallerState::DetermineCriticalVersion( | 421 Version InstallerState::DetermineCriticalVersion( |
422 const Version* current_version, | 422 const Version* current_version, |
423 const Version& new_version) const { | 423 const Version& new_version) const { |
424 DCHECK(current_version == NULL || current_version->IsValid()); | 424 DCHECK(current_version == NULL || current_version->IsValid()); |
425 DCHECK(new_version.IsValid()); | 425 DCHECK(new_version.IsValid()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 // with ERROR_SHARING_VIOLATION if the file exists and is in-use. | 460 // with ERROR_SHARING_VIOLATION if the file exists and is in-use. |
461 return !base::win::ScopedHandle(CreateFile(file.value().c_str(), | 461 return !base::win::ScopedHandle(CreateFile(file.value().c_str(), |
462 GENERIC_WRITE, 0, NULL, | 462 GENERIC_WRITE, 0, NULL, |
463 OPEN_EXISTING, 0, 0)).IsValid(); | 463 OPEN_EXISTING, 0, 0)).IsValid(); |
464 } | 464 } |
465 | 465 |
466 void InstallerState::RemoveOldVersionDirectories( | 466 void InstallerState::RemoveOldVersionDirectories( |
467 const Version& new_version, | 467 const Version& new_version, |
468 Version* existing_version, | 468 Version* existing_version, |
469 const FilePath& temp_path) const { | 469 const FilePath& temp_path) const { |
470 scoped_ptr<Version> version; | 470 Version version; |
471 std::vector<FilePath> key_files; | 471 std::vector<FilePath> key_files; |
472 scoped_ptr<WorkItem> item; | 472 scoped_ptr<WorkItem> item; |
473 | 473 |
474 // Try to delete all directories whose versions are lower than latest_version | 474 // Try to delete all directories whose versions are lower than latest_version |
475 // and not equal to the existing version (opv). | 475 // and not equal to the existing version (opv). |
476 file_util::FileEnumerator version_enum(target_path(), false, | 476 file_util::FileEnumerator version_enum(target_path(), false, |
477 file_util::FileEnumerator::DIRECTORIES); | 477 file_util::FileEnumerator::DIRECTORIES); |
478 for (FilePath next_version = version_enum.Next(); !next_version.empty(); | 478 for (FilePath next_version = version_enum.Next(); !next_version.empty(); |
479 next_version = version_enum.Next()) { | 479 next_version = version_enum.Next()) { |
480 FilePath dir_name(next_version.BaseName()); | 480 FilePath dir_name(next_version.BaseName()); |
481 version.reset(Version::GetVersionFromString(WideToASCII(dir_name.value()))); | 481 version = Version(WideToASCII(dir_name.value())); |
482 // Delete the version folder if it is less than the new version and not | 482 // Delete the version folder if it is less than the new version and not |
483 // equal to the old version (if we have an old version). | 483 // equal to the old version (if we have an old version). |
484 if (version.get() && | 484 if (version.IsValid() && |
485 version->CompareTo(new_version) < 0 && | 485 version.CompareTo(new_version) < 0 && |
486 (existing_version == NULL || !version->Equals(*existing_version))) { | 486 (existing_version == NULL || !version.Equals(*existing_version))) { |
487 // Collect the key files (relative to the version dir) for all products. | 487 // Collect the key files (relative to the version dir) for all products. |
488 key_files.clear(); | 488 key_files.clear(); |
489 std::for_each(products_.begin(), products_.end(), | 489 std::for_each(products_.begin(), products_.end(), |
490 std::bind2nd(std::mem_fun(&Product::AddKeyFiles), | 490 std::bind2nd(std::mem_fun(&Product::AddKeyFiles), |
491 &key_files)); | 491 &key_files)); |
492 // Make the key_paths absolute. | 492 // Make the key_paths absolute. |
493 const std::vector<FilePath>::iterator end = key_files.end(); | 493 const std::vector<FilePath>::iterator end = key_files.end(); |
494 for (std::vector<FilePath>::iterator scan = key_files.begin(); | 494 for (std::vector<FilePath>::iterator scan = key_files.begin(); |
495 scan != end; ++scan) { | 495 scan != end; ++scan) { |
496 *scan = next_version.Append(*scan); | 496 *scan = next_version.Append(*scan); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 if (is_multi_install()) { | 617 if (is_multi_install()) { |
618 InstallUtil::AddInstallerResultItems( | 618 InstallUtil::AddInstallerResultItems( |
619 system_install, multi_package_binaries_distribution()->GetStateKey(), | 619 system_install, multi_package_binaries_distribution()->GetStateKey(), |
620 status, string_resource_id, launch_cmd, install_list.get()); | 620 status, string_resource_id, launch_cmd, install_list.get()); |
621 } | 621 } |
622 if (!install_list->Do()) | 622 if (!install_list->Do()) |
623 LOG(ERROR) << "Failed to record installer error information in registry."; | 623 LOG(ERROR) << "Failed to record installer error information in registry."; |
624 } | 624 } |
625 | 625 |
626 } // namespace installer | 626 } // namespace installer |
OLD | NEW |