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

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

Issue 7353030: Cause new_chrome.exe to always be written if Chrome Frame is in use, resulting in updates being d... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "base/win/registry.h" 17 #include "base/win/registry.h"
18 #include "base/win/scoped_handle.h"
18 #include "chrome/installer/util/delete_tree_work_item.h" 19 #include "chrome/installer/util/delete_tree_work_item.h"
19 #include "chrome/installer/util/helper.h" 20 #include "chrome/installer/util/helper.h"
20 #include "chrome/installer/util/install_util.h" 21 #include "chrome/installer/util/install_util.h"
21 #include "chrome/installer/util/installation_state.h" 22 #include "chrome/installer/util/installation_state.h"
22 #include "chrome/installer/util/master_preferences.h" 23 #include "chrome/installer/util/master_preferences.h"
23 #include "chrome/installer/util/master_preferences_constants.h" 24 #include "chrome/installer/util/master_preferences_constants.h"
24 #include "chrome/installer/util/product.h" 25 #include "chrome/installer/util/product.h"
25 #include "chrome/installer/util/work_item.h" 26 #include "chrome/installer/util/work_item.h"
26 #include "chrome/installer/util/work_item_list.h" 27 #include "chrome/installer/util/work_item_list.h"
27 28
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 69 }
69 70
70 InstallerState::InstallerState() 71 InstallerState::InstallerState()
71 : operation_(UNINITIALIZED), 72 : operation_(UNINITIALIZED),
72 multi_package_distribution_(NULL), 73 multi_package_distribution_(NULL),
73 level_(UNKNOWN_LEVEL), 74 level_(UNKNOWN_LEVEL),
74 package_type_(UNKNOWN_PACKAGE_TYPE), 75 package_type_(UNKNOWN_PACKAGE_TYPE),
75 state_type_(BrowserDistribution::CHROME_BROWSER), 76 state_type_(BrowserDistribution::CHROME_BROWSER),
76 root_key_(NULL), 77 root_key_(NULL),
77 msi_(false), 78 msi_(false),
78 verbose_logging_(false) { 79 verbose_logging_(false),
80 is_chrome_frame_running_(false) {
79 } 81 }
80 82
81 InstallerState::InstallerState(Level level) 83 InstallerState::InstallerState(Level level)
82 : operation_(UNINITIALIZED), 84 : operation_(UNINITIALIZED),
83 multi_package_distribution_(NULL), 85 multi_package_distribution_(NULL),
84 level_(UNKNOWN_LEVEL), 86 level_(UNKNOWN_LEVEL),
85 package_type_(UNKNOWN_PACKAGE_TYPE), 87 package_type_(UNKNOWN_PACKAGE_TYPE),
86 state_type_(BrowserDistribution::CHROME_BROWSER), 88 state_type_(BrowserDistribution::CHROME_BROWSER),
87 root_key_(NULL), 89 root_key_(NULL),
88 msi_(false), 90 msi_(false),
89 verbose_logging_(false) { 91 verbose_logging_(false),
92 is_chrome_frame_running_(false) {
90 // Use set_level() so that root_key_ is updated properly. 93 // Use set_level() so that root_key_ is updated properly.
91 set_level(level); 94 set_level(level);
92 } 95 }
93 96
94 void InstallerState::Initialize(const CommandLine& command_line, 97 void InstallerState::Initialize(const CommandLine& command_line,
95 const MasterPreferences& prefs, 98 const MasterPreferences& prefs,
96 const InstallationState& machine_state) { 99 const InstallationState& machine_state) {
97 bool pref_bool; 100 bool pref_bool;
98 if (!prefs.GetBool(master_preferences::kSystemLevel, &pref_bool)) 101 if (!prefs.GetBool(master_preferences::kSystemLevel, &pref_bool))
99 pref_bool = false; 102 pref_bool = false;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 151
149 if (operand == NULL) { 152 if (operand == NULL) {
150 operand = BrowserDistribution::GetSpecificDistribution( 153 operand = BrowserDistribution::GetSpecificDistribution(
151 prefs.install_chrome() ? 154 prefs.install_chrome() ?
152 BrowserDistribution::CHROME_BROWSER : 155 BrowserDistribution::CHROME_BROWSER :
153 BrowserDistribution::CHROME_FRAME); 156 BrowserDistribution::CHROME_FRAME);
154 } 157 }
155 158
156 state_key_ = operand->GetStateKey(); 159 state_key_ = operand->GetStateKey();
157 state_type_ = operand->GetType(); 160 state_type_ = operand->GetType();
161
162 is_chrome_frame_running_ = DetectChromeFrameInUse(machine_state);
158 } 163 }
159 164
160 void InstallerState::set_level(Level level) { 165 void InstallerState::set_level(Level level) {
161 level_ = level; 166 level_ = level;
162 switch (level) { 167 switch (level) {
163 case USER_LEVEL: 168 case USER_LEVEL:
164 root_key_ = HKEY_CURRENT_USER; 169 root_key_ = HKEY_CURRENT_USER;
165 break; 170 break;
166 case SYSTEM_LEVEL: 171 case SYSTEM_LEVEL:
167 root_key_ = HKEY_LOCAL_MACHINE; 172 root_key_ = HKEY_LOCAL_MACHINE;
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 } 415 }
411 416
412 return current_version.release(); 417 return current_version.release();
413 } 418 }
414 419
415 FilePath InstallerState::GetInstallerDirectory(const Version& version) const { 420 FilePath InstallerState::GetInstallerDirectory(const Version& version) const {
416 return target_path().Append(ASCIIToWide(version.GetString())) 421 return target_path().Append(ASCIIToWide(version.GetString()))
417 .Append(kInstallerDir); 422 .Append(kInstallerDir);
418 } 423 }
419 424
425 // static
426 bool InstallerState::IsFileInUse(const FilePath& file) {
427 // Call CreateFile with a share mode of 0 which should cause this to fail
428 // with ERROR_SHARING_VIOLATION if the file exists and is in-use.
429 return !base::win::ScopedHandle(CreateFile(file.value().c_str(),
430 GENERIC_WRITE, 0, NULL,
431 OPEN_EXISTING, 0, 0)).IsValid();
432 }
433
434 bool InstallerState::DetectChromeFrameInUse(
435 const InstallationState& machine_state) {
436 // We check only for the current version (e.g. the version we are upgrading
437 // _from_). We don't need to check interstitial versions if any (as would
438 // occur in the case of multiple updates) since if they are in use, we are
439 // guaranteed that the current version is in use too.
440 bool in_use = false;
441 scoped_ptr<Version> current_version(GetCurrentVersion(machine_state));
442 if (current_version != NULL) {
443 FilePath cf_install_path(
444 target_path().AppendASCII(current_version->GetString())
445 .Append(kChromeFrameDll));
446 in_use = IsFileInUse(cf_install_path);
447 }
448 return in_use;
449 }
450
420 void InstallerState::RemoveOldVersionDirectories( 451 void InstallerState::RemoveOldVersionDirectories(
421 const Version& new_version, 452 const Version& new_version,
422 Version* existing_version, 453 Version* existing_version,
423 const FilePath& temp_path) const { 454 const FilePath& temp_path) const {
424 file_util::FileEnumerator version_enum(target_path(), false, 455 file_util::FileEnumerator version_enum(target_path(), false,
425 file_util::FileEnumerator::DIRECTORIES); 456 file_util::FileEnumerator::DIRECTORIES);
426 scoped_ptr<Version> version; 457 scoped_ptr<Version> version;
427 std::vector<FilePath> key_files; 458 std::vector<FilePath> key_files;
428 459
429 // We try to delete all directories whose versions are lower than 460 // We try to delete all directories whose versions are lower than
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 if (is_multi_install()) { 610 if (is_multi_install()) {
580 InstallUtil::AddInstallerResultItems( 611 InstallUtil::AddInstallerResultItems(
581 system_install, multi_package_binaries_distribution()->GetStateKey(), 612 system_install, multi_package_binaries_distribution()->GetStateKey(),
582 status, string_resource_id, launch_cmd, install_list.get()); 613 status, string_resource_id, launch_cmd, install_list.get());
583 } 614 }
584 if (!install_list->Do()) 615 if (!install_list->Do())
585 LOG(ERROR) << "Failed to record installer error information in registry."; 616 LOG(ERROR) << "Failed to record installer error information in registry.";
586 } 617 }
587 618
588 } // namespace installer 619 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/installer/util/installer_state.h ('k') | chrome/installer/util/installer_state_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698