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

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

Issue 11417038: IsFileInUse should return false when the file doesn't exist. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync past r168281 Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/installer/util/installer_state_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/file_version_info.h" 13 #include "base/file_version_info.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "base/win/registry.h" 18 #include "base/win/registry.h"
19 #include "base/win/scoped_handle.h"
20 #include "chrome/installer/util/delete_tree_work_item.h" 19 #include "chrome/installer/util/delete_tree_work_item.h"
21 #include "chrome/installer/util/helper.h" 20 #include "chrome/installer/util/helper.h"
22 #include "chrome/installer/util/install_util.h" 21 #include "chrome/installer/util/install_util.h"
23 #include "chrome/installer/util/installation_state.h" 22 #include "chrome/installer/util/installation_state.h"
24 #include "chrome/installer/util/master_preferences.h" 23 #include "chrome/installer/util/master_preferences.h"
25 #include "chrome/installer/util/master_preferences_constants.h" 24 #include "chrome/installer/util/master_preferences_constants.h"
26 #include "chrome/installer/util/product.h" 25 #include "chrome/installer/util/product.h"
27 #include "chrome/installer/util/work_item.h" 26 #include "chrome/installer/util/work_item.h"
28 #include "chrome/installer/util/work_item_list.h" 27 #include "chrome/installer/util/work_item_list.h"
29 28
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 574
576 FilePath InstallerState::GetInstallerDirectory(const Version& version) const { 575 FilePath InstallerState::GetInstallerDirectory(const Version& version) const {
577 return target_path().Append(ASCIIToWide(version.GetString())) 576 return target_path().Append(ASCIIToWide(version.GetString()))
578 .Append(kInstallerDir); 577 .Append(kInstallerDir);
579 } 578 }
580 579
581 // static 580 // static
582 bool InstallerState::IsFileInUse(const FilePath& file) { 581 bool InstallerState::IsFileInUse(const FilePath& file) {
583 // Call CreateFile with a share mode of 0 which should cause this to fail 582 // Call CreateFile with a share mode of 0 which should cause this to fail
584 // with ERROR_SHARING_VIOLATION if the file exists and is in-use. 583 // with ERROR_SHARING_VIOLATION if the file exists and is in-use.
585 return !base::win::ScopedHandle(CreateFile(file.value().c_str(), 584 HANDLE file_handle = CreateFile(file.value().c_str(), GENERIC_WRITE, 0, NULL,
586 GENERIC_WRITE, 0, NULL, 585 OPEN_EXISTING, 0, 0);
587 OPEN_EXISTING, 0, 0)).IsValid(); 586 bool in_use = false;
587 if (file_handle != INVALID_HANDLE_VALUE)
588 CloseHandle(file_handle);
589 else if (GetLastError() != ERROR_FILE_NOT_FOUND)
590 in_use = true;
591 return in_use;
588 } 592 }
589 593
590 594
591 void InstallerState::GetExistingExeVersions( 595 void InstallerState::GetExistingExeVersions(
592 std::set<std::string>* existing_versions) const { 596 std::set<std::string>* existing_versions) const {
593 597
594 static const wchar_t* const kChromeFilenames[] = { 598 static const wchar_t* const kChromeFilenames[] = {
595 installer::kChromeExe, 599 installer::kChromeExe,
596 installer::kChromeNewExe, 600 installer::kChromeNewExe,
597 installer::kChromeOldExe, 601 installer::kChromeOldExe,
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 if (is_multi_install()) { 767 if (is_multi_install()) {
764 InstallUtil::AddInstallerResultItems( 768 InstallUtil::AddInstallerResultItems(
765 system_install, multi_package_binaries_distribution()->GetStateKey(), 769 system_install, multi_package_binaries_distribution()->GetStateKey(),
766 status, string_resource_id, launch_cmd, install_list.get()); 770 status, string_resource_id, launch_cmd, install_list.get());
767 } 771 }
768 if (!install_list->Do()) 772 if (!install_list->Do())
769 LOG(ERROR) << "Failed to record installer error information in registry."; 773 LOG(ERROR) << "Failed to record installer error information in registry.";
770 } 774 }
771 775
772 } // namespace installer 776 } // namespace installer
OLDNEW
« no previous file with comments | « no previous file | chrome/installer/util/installer_state_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698