Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Side by Side Diff: chrome/installer/util/installer_state.cc

Issue 2258243002: Consistently use namespaced base::Version in chrome/installer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 BrowserDistribution::CHROME_BROWSER : 156 BrowserDistribution::CHROME_BROWSER :
157 BrowserDistribution::CHROME_BINARIES); 157 BrowserDistribution::CHROME_BINARIES);
158 } 158 }
159 159
160 state_key_ = operand->GetStateKey(); 160 state_key_ = operand->GetStateKey();
161 state_type_ = operand->GetType(); 161 state_type_ = operand->GetType();
162 162
163 // Parse --critical-update-version=W.X.Y.Z 163 // Parse --critical-update-version=W.X.Y.Z
164 std::string critical_version_value( 164 std::string critical_version_value(
165 command_line.GetSwitchValueASCII(switches::kCriticalUpdateVersion)); 165 command_line.GetSwitchValueASCII(switches::kCriticalUpdateVersion));
166 critical_update_version_ = Version(critical_version_value); 166 critical_update_version_ = base::Version(critical_version_value);
167 } 167 }
168 168
169 void InstallerState::set_level(Level level) { 169 void InstallerState::set_level(Level level) {
170 level_ = level; 170 level_ = level;
171 switch (level) { 171 switch (level) {
172 case USER_LEVEL: 172 case USER_LEVEL:
173 root_key_ = HKEY_CURRENT_USER; 173 root_key_ = HKEY_CURRENT_USER;
174 break; 174 break;
175 case SYSTEM_LEVEL: 175 case SYSTEM_LEVEL:
176 root_key_ = HKEY_LOCAL_MACHINE; 176 root_key_ = HKEY_LOCAL_MACHINE;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 const Product* InstallerState::FindProduct( 361 const Product* InstallerState::FindProduct(
362 BrowserDistribution::Type distribution_type) const { 362 BrowserDistribution::Type distribution_type) const {
363 for (Products::const_iterator scan = products_.begin(), end = products_.end(); 363 for (Products::const_iterator scan = products_.begin(), end = products_.end();
364 scan != end; ++scan) { 364 scan != end; ++scan) {
365 if ((*scan)->is_type(distribution_type)) 365 if ((*scan)->is_type(distribution_type))
366 return *scan; 366 return *scan;
367 } 367 }
368 return NULL; 368 return NULL;
369 } 369 }
370 370
371 Version* InstallerState::GetCurrentVersion( 371 base::Version* InstallerState::GetCurrentVersion(
372 const InstallationState& machine_state) const { 372 const InstallationState& machine_state) const {
373 DCHECK(!products_.empty()); 373 DCHECK(!products_.empty());
374 std::unique_ptr<Version> current_version; 374 std::unique_ptr<base::Version> current_version;
375 // If we're doing a multi-install, the current version may be either an 375 // If we're doing a multi-install, the current version may be either an
376 // existing multi or an existing single product that is being migrated 376 // existing multi or an existing single product that is being migrated
377 // in place (i.e., Chrome). In the latter case, there is no existing 377 // in place (i.e., Chrome). In the latter case, there is no existing
378 // CHROME_BINARIES installation so we need to search for the product. 378 // CHROME_BINARIES installation so we need to search for the product.
379 BrowserDistribution::Type prod_type; 379 BrowserDistribution::Type prod_type;
380 if (package_type_ == MULTI_PACKAGE) { 380 if (package_type_ == MULTI_PACKAGE) {
381 prod_type = BrowserDistribution::CHROME_BINARIES; 381 prod_type = BrowserDistribution::CHROME_BINARIES;
382 if (machine_state.GetProductState(level_ == SYSTEM_LEVEL, 382 if (machine_state.GetProductState(level_ == SYSTEM_LEVEL,
383 prod_type) == NULL) { 383 prod_type) == NULL) {
384 // Search for a product on which we're operating that is installed in our 384 // Search for a product on which we're operating that is installed in our
(...skipping 11 matching lines...) Expand all
396 } 396 }
397 } 397 }
398 } 398 }
399 } else { 399 } else {
400 prod_type = products_[0]->distribution()->GetType(); 400 prod_type = products_[0]->distribution()->GetType();
401 } 401 }
402 const ProductState* product_state = 402 const ProductState* product_state =
403 machine_state.GetProductState(level_ == SYSTEM_LEVEL, prod_type); 403 machine_state.GetProductState(level_ == SYSTEM_LEVEL, prod_type);
404 404
405 if (product_state != NULL) { 405 if (product_state != NULL) {
406 const Version* version = NULL; 406 const base::Version* version = NULL;
407 407
408 // Be aware that there might be a pending "new_chrome.exe" already in the 408 // Be aware that there might be a pending "new_chrome.exe" already in the
409 // installation path. If so, we use old_version, which holds the version of 409 // installation path. If so, we use old_version, which holds the version of
410 // "chrome.exe" itself. 410 // "chrome.exe" itself.
411 if (base::PathExists(target_path().Append(kChromeNewExe))) 411 if (base::PathExists(target_path().Append(kChromeNewExe)))
412 version = product_state->old_version(); 412 version = product_state->old_version();
413 413
414 if (version == NULL) 414 if (version == NULL)
415 version = &product_state->version(); 415 version = &product_state->version();
416 416
417 current_version.reset(new Version(*version)); 417 current_version.reset(new base::Version(*version));
418 } 418 }
419 419
420 return current_version.release(); 420 return current_version.release();
421 } 421 }
422 422
423 Version InstallerState::DetermineCriticalVersion( 423 base::Version InstallerState::DetermineCriticalVersion(
424 const Version* current_version, 424 const base::Version* current_version,
425 const Version& new_version) const { 425 const base::Version& new_version) const {
426 DCHECK(current_version == NULL || current_version->IsValid()); 426 DCHECK(current_version == NULL || current_version->IsValid());
427 DCHECK(new_version.IsValid()); 427 DCHECK(new_version.IsValid());
428 if (critical_update_version_.IsValid() && 428 if (critical_update_version_.IsValid() &&
429 (current_version == NULL || 429 (current_version == NULL ||
430 (current_version->CompareTo(critical_update_version_) < 0)) && 430 (current_version->CompareTo(critical_update_version_) < 0)) &&
431 new_version.CompareTo(critical_update_version_) >= 0) { 431 new_version.CompareTo(critical_update_version_) >= 0) {
432 return critical_update_version_; 432 return critical_update_version_;
433 } 433 }
434 return Version(); 434 return base::Version();
435 } 435 }
436 436
437 bool InstallerState::IsChromeFrameRunning( 437 bool InstallerState::IsChromeFrameRunning(
438 const InstallationState& machine_state) const { 438 const InstallationState& machine_state) const {
439 return AnyExistsAndIsInUse(machine_state, CHROME_FRAME_DLL); 439 return AnyExistsAndIsInUse(machine_state, CHROME_FRAME_DLL);
440 } 440 }
441 441
442 bool InstallerState::AreBinariesInUse( 442 bool InstallerState::AreBinariesInUse(
443 const InstallationState& machine_state) const { 443 const InstallationState& machine_state) const {
444 return AnyExistsAndIsInUse( 444 return AnyExistsAndIsInUse(
445 machine_state, 445 machine_state,
446 (CHROME_FRAME_HELPER_EXE | CHROME_FRAME_HELPER_DLL | 446 (CHROME_FRAME_HELPER_EXE | CHROME_FRAME_HELPER_DLL |
447 CHROME_FRAME_DLL | CHROME_DLL)); 447 CHROME_FRAME_DLL | CHROME_DLL));
448 } 448 }
449 449
450 base::FilePath InstallerState::GetInstallerDirectory( 450 base::FilePath InstallerState::GetInstallerDirectory(
451 const Version& version) const { 451 const base::Version& version) const {
452 return target_path().AppendASCII(version.GetString()).Append(kInstallerDir); 452 return target_path().AppendASCII(version.GetString()).Append(kInstallerDir);
453 } 453 }
454 454
455 // static 455 // static
456 bool InstallerState::IsFileInUse(const base::FilePath& file) { 456 bool InstallerState::IsFileInUse(const base::FilePath& file) {
457 // Call CreateFile with a share mode of 0 which should cause this to fail 457 // Call CreateFile with a share mode of 0 which should cause this to fail
458 // with ERROR_SHARING_VIOLATION if the file exists and is in-use. 458 // with ERROR_SHARING_VIOLATION if the file exists and is in-use.
459 return !base::win::ScopedHandle(CreateFile(file.value().c_str(), 459 return !base::win::ScopedHandle(CreateFile(file.value().c_str(),
460 GENERIC_WRITE, 0, NULL, 460 GENERIC_WRITE, 0, NULL,
461 OPEN_EXISTING, 0, 0)).IsValid(); 461 OPEN_EXISTING, 0, 0)).IsValid();
(...skipping 28 matching lines...) Expand all
490 static_assert(CHROME_FRAME_DLL == 2, 490 static_assert(CHROME_FRAME_DLL == 2,
491 "binary file names and values must match"); 491 "binary file names and values must match");
492 static_assert(CHROME_FRAME_HELPER_DLL == 4, 492 static_assert(CHROME_FRAME_HELPER_DLL == 4,
493 "binary file names and values must match"); 493 "binary file names and values must match");
494 static_assert(CHROME_FRAME_HELPER_EXE == 8, 494 static_assert(CHROME_FRAME_HELPER_EXE == 8,
495 "binary file names and values must match"); 495 "binary file names and values must match");
496 496
497 // Check only for the current version (i.e., the version we are upgrading 497 // Check only for the current version (i.e., the version we are upgrading
498 // _from_). Later versions from pending in-use updates need not be checked 498 // _from_). Later versions from pending in-use updates need not be checked
499 // since the current version is guaranteed to be in use if any such are. 499 // since the current version is guaranteed to be in use if any such are.
500 std::unique_ptr<Version> current_version(GetCurrentVersion(machine_state)); 500 std::unique_ptr<base::Version> current_version(
501 GetCurrentVersion(machine_state));
501 if (!current_version) 502 if (!current_version)
502 return false; 503 return false;
503 base::FilePath directory( 504 base::FilePath directory(
504 target_path().AppendASCII(current_version->GetString())); 505 target_path().AppendASCII(current_version->GetString()));
505 for (int i = 0; i < NUM_BINARIES; ++i) { 506 for (int i = 0; i < NUM_BINARIES; ++i) {
506 if (!(file_bits & (1U << i))) 507 if (!(file_bits & (1U << i)))
507 continue; 508 continue;
508 base::FilePath file(directory.Append(kBinaryFileNames[i])); 509 base::FilePath file(directory.Append(kBinaryFileNames[i]));
509 if (base::PathExists(file) && IsFileInUse(file)) 510 if (base::PathExists(file) && IsFileInUse(file))
510 return true; 511 return true;
(...skipping 16 matching lines...) Expand all
527 FileVersionInfo::CreateFileVersionInfo(chrome_exe)); 528 FileVersionInfo::CreateFileVersionInfo(chrome_exe));
528 if (file_version_info) { 529 if (file_version_info) {
529 base::string16 version_string = file_version_info->file_version(); 530 base::string16 version_string = file_version_info->file_version();
530 if (!version_string.empty() && base::IsStringASCII(version_string)) 531 if (!version_string.empty() && base::IsStringASCII(version_string))
531 existing_versions->insert(base::UTF16ToASCII(version_string)); 532 existing_versions->insert(base::UTF16ToASCII(version_string));
532 } 533 }
533 } 534 }
534 } 535 }
535 536
536 void InstallerState::RemoveOldVersionDirectories( 537 void InstallerState::RemoveOldVersionDirectories(
537 const Version& new_version, 538 const base::Version& new_version,
538 Version* existing_version, 539 base::Version* existing_version,
539 const base::FilePath& temp_path) const { 540 const base::FilePath& temp_path) const {
540 Version version; 541 base::Version version;
541 std::unique_ptr<WorkItem> item; 542 std::unique_ptr<WorkItem> item;
542 543
543 std::set<std::string> existing_version_strings; 544 std::set<std::string> existing_version_strings;
544 existing_version_strings.insert(new_version.GetString()); 545 existing_version_strings.insert(new_version.GetString());
545 if (existing_version) 546 if (existing_version)
546 existing_version_strings.insert(existing_version->GetString()); 547 existing_version_strings.insert(existing_version->GetString());
547 548
548 // Make sure not to delete any version dir that is "referenced" by an existing 549 // Make sure not to delete any version dir that is "referenced" by an existing
549 // Chrome executable. 550 // Chrome executable.
550 GetExistingExeVersions(&existing_version_strings); 551 GetExistingExeVersions(&existing_version_strings);
551 552
552 // Try to delete all directories that are not in the set we care to keep. 553 // Try to delete all directories that are not in the set we care to keep.
553 base::FileEnumerator version_enum(target_path(), false, 554 base::FileEnumerator version_enum(target_path(), false,
554 base::FileEnumerator::DIRECTORIES); 555 base::FileEnumerator::DIRECTORIES);
555 for (base::FilePath next_version = version_enum.Next(); !next_version.empty(); 556 for (base::FilePath next_version = version_enum.Next(); !next_version.empty();
556 next_version = version_enum.Next()) { 557 next_version = version_enum.Next()) {
557 base::FilePath dir_name(next_version.BaseName()); 558 base::FilePath dir_name(next_version.BaseName());
558 version = Version(base::UTF16ToASCII(dir_name.value())); 559 version = base::Version(base::UTF16ToASCII(dir_name.value()));
559 // Delete the version folder if it is less than the new version and not 560 // Delete the version folder if it is less than the new version and not
560 // equal to the old version (if we have an old version). 561 // equal to the old version (if we have an old version).
561 if (version.IsValid() && 562 if (version.IsValid() &&
562 existing_version_strings.count(version.GetString()) == 0) { 563 existing_version_strings.count(version.GetString()) == 0) {
563 // Note: temporarily log old version deletion at ERROR level to make it 564 // Note: temporarily log old version deletion at ERROR level to make it
564 // more likely we see this in the installer log. 565 // more likely we see this in the installer log.
565 LOG(ERROR) << "Deleting old version directory: " << next_version.value(); 566 LOG(ERROR) << "Deleting old version directory: " << next_version.value();
566 567
567 // Attempt to recursively delete the old version dir. 568 // Attempt to recursively delete the old version dir.
568 bool delete_succeeded = base::DeleteFile(next_version, true); 569 bool delete_succeeded = base::DeleteFile(next_version, true);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 status, string_resource_id, launch_cmd, install_list.get()); 690 status, string_resource_id, launch_cmd, install_list.get());
690 } 691 }
691 install_list->Do(); 692 install_list->Do();
692 } 693 }
693 694
694 bool InstallerState::RequiresActiveSetup() const { 695 bool InstallerState::RequiresActiveSetup() const {
695 return system_install() && FindProduct(BrowserDistribution::CHROME_BROWSER); 696 return system_install() && FindProduct(BrowserDistribution::CHROME_BROWSER);
696 } 697 }
697 698
698 } // namespace installer 699 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/installer/util/installation_validator_unittest.cc ('k') | chrome/installer/util/installer_state_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698