OLD | NEW |
---|---|
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 |
29 | |
28 namespace installer { | 30 namespace installer { |
29 | 31 |
30 bool InstallerState::IsMultiInstallUpdate(const MasterPreferences& prefs, | 32 bool InstallerState::IsMultiInstallUpdate(const MasterPreferences& prefs, |
31 const InstallationState& machine_state) { | 33 const InstallationState& machine_state) { |
32 // First, is the package present? | 34 // First, is the package present? |
33 const ProductState* package = | 35 const ProductState* package = |
34 machine_state.GetProductState(level_ == SYSTEM_LEVEL, | 36 machine_state.GetProductState(level_ == SYSTEM_LEVEL, |
35 BrowserDistribution::CHROME_BINARIES); | 37 BrowserDistribution::CHROME_BINARIES); |
36 if (package == NULL) { | 38 if (package == NULL) { |
37 // The multi-install package has not been installed, so it certainly isn't | 39 // The multi-install package has not been installed, so it certainly isn't |
(...skipping 30 matching lines...) Expand all Loading... | |
68 } | 70 } |
69 | 71 |
70 InstallerState::InstallerState() | 72 InstallerState::InstallerState() |
71 : operation_(UNINITIALIZED), | 73 : operation_(UNINITIALIZED), |
72 multi_package_distribution_(NULL), | 74 multi_package_distribution_(NULL), |
73 level_(UNKNOWN_LEVEL), | 75 level_(UNKNOWN_LEVEL), |
74 package_type_(UNKNOWN_PACKAGE_TYPE), | 76 package_type_(UNKNOWN_PACKAGE_TYPE), |
75 state_type_(BrowserDistribution::CHROME_BROWSER), | 77 state_type_(BrowserDistribution::CHROME_BROWSER), |
76 root_key_(NULL), | 78 root_key_(NULL), |
77 msi_(false), | 79 msi_(false), |
78 verbose_logging_(false) { | 80 verbose_logging_(false), |
81 is_chrome_frame_running_(false) { | |
79 } | 82 } |
80 | 83 |
81 InstallerState::InstallerState(Level level) | 84 InstallerState::InstallerState(Level level) |
82 : operation_(UNINITIALIZED), | 85 : operation_(UNINITIALIZED), |
83 multi_package_distribution_(NULL), | 86 multi_package_distribution_(NULL), |
84 level_(UNKNOWN_LEVEL), | 87 level_(UNKNOWN_LEVEL), |
85 package_type_(UNKNOWN_PACKAGE_TYPE), | 88 package_type_(UNKNOWN_PACKAGE_TYPE), |
86 state_type_(BrowserDistribution::CHROME_BROWSER), | 89 state_type_(BrowserDistribution::CHROME_BROWSER), |
87 root_key_(NULL), | 90 root_key_(NULL), |
88 msi_(false), | 91 msi_(false), |
89 verbose_logging_(false) { | 92 verbose_logging_(false), |
93 is_chrome_frame_running_(false) { | |
90 // Use set_level() so that root_key_ is updated properly. | 94 // Use set_level() so that root_key_ is updated properly. |
91 set_level(level); | 95 set_level(level); |
92 } | 96 } |
93 | 97 |
94 void InstallerState::Initialize(const CommandLine& command_line, | 98 void InstallerState::Initialize(const CommandLine& command_line, |
95 const MasterPreferences& prefs, | 99 const MasterPreferences& prefs, |
96 const InstallationState& machine_state) { | 100 const InstallationState& machine_state) { |
97 bool pref_bool; | 101 bool pref_bool; |
98 if (!prefs.GetBool(master_preferences::kSystemLevel, &pref_bool)) | 102 if (!prefs.GetBool(master_preferences::kSystemLevel, &pref_bool)) |
99 pref_bool = false; | 103 pref_bool = false; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 | 152 |
149 if (operand == NULL) { | 153 if (operand == NULL) { |
150 operand = BrowserDistribution::GetSpecificDistribution( | 154 operand = BrowserDistribution::GetSpecificDistribution( |
151 prefs.install_chrome() ? | 155 prefs.install_chrome() ? |
152 BrowserDistribution::CHROME_BROWSER : | 156 BrowserDistribution::CHROME_BROWSER : |
153 BrowserDistribution::CHROME_FRAME); | 157 BrowserDistribution::CHROME_FRAME); |
154 } | 158 } |
155 | 159 |
156 state_key_ = operand->GetStateKey(); | 160 state_key_ = operand->GetStateKey(); |
157 state_type_ = operand->GetType(); | 161 state_type_ = operand->GetType(); |
162 | |
163 is_chrome_frame_running_ = DetectChromeFrameInUse(machine_state); | |
158 } | 164 } |
159 | 165 |
160 void InstallerState::set_level(Level level) { | 166 void InstallerState::set_level(Level level) { |
161 level_ = level; | 167 level_ = level; |
162 switch (level) { | 168 switch (level) { |
163 case USER_LEVEL: | 169 case USER_LEVEL: |
164 root_key_ = HKEY_CURRENT_USER; | 170 root_key_ = HKEY_CURRENT_USER; |
165 break; | 171 break; |
166 case SYSTEM_LEVEL: | 172 case SYSTEM_LEVEL: |
167 root_key_ = HKEY_LOCAL_MACHINE; | 173 root_key_ = HKEY_LOCAL_MACHINE; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 bool InstallerState::system_install() const { | 339 bool InstallerState::system_install() const { |
334 DCHECK(level_ == USER_LEVEL || level_ == SYSTEM_LEVEL); | 340 DCHECK(level_ == USER_LEVEL || level_ == SYSTEM_LEVEL); |
335 return level_ == SYSTEM_LEVEL; | 341 return level_ == SYSTEM_LEVEL; |
336 } | 342 } |
337 | 343 |
338 bool InstallerState::is_multi_install() const { | 344 bool InstallerState::is_multi_install() const { |
339 DCHECK(package_type_ == SINGLE_PACKAGE || package_type_ == MULTI_PACKAGE); | 345 DCHECK(package_type_ == SINGLE_PACKAGE || package_type_ == MULTI_PACKAGE); |
340 return package_type_ != SINGLE_PACKAGE; | 346 return package_type_ != SINGLE_PACKAGE; |
341 } | 347 } |
342 | 348 |
349 bool InstallerState::is_chrome_frame_running() const { | |
grt (UTC plus 2)
2011/07/14 14:25:29
move this trivial method into the header. (the tw
robertshield
2011/07/15 13:49:18
Done.
| |
350 return is_chrome_frame_running_; | |
351 } | |
352 | |
343 bool InstallerState::RemoveProduct(const Product* product) { | 353 bool InstallerState::RemoveProduct(const Product* product) { |
344 ScopedVector<Product>::iterator it = | 354 ScopedVector<Product>::iterator it = |
345 std::find(products_.begin(), products_.end(), product); | 355 std::find(products_.begin(), products_.end(), product); |
346 if (it != products_.end()) { | 356 if (it != products_.end()) { |
347 products_->erase(it); | 357 products_->erase(it); |
348 return true; | 358 return true; |
349 } | 359 } |
350 return false; | 360 return false; |
351 } | 361 } |
352 | 362 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
409 current_version.reset(version->Clone()); | 419 current_version.reset(version->Clone()); |
410 } | 420 } |
411 | 421 |
412 return current_version.release(); | 422 return current_version.release(); |
413 } | 423 } |
414 | 424 |
415 FilePath InstallerState::GetInstallerDirectory(const Version& version) const { | 425 FilePath InstallerState::GetInstallerDirectory(const Version& version) const { |
416 return target_path().Append(ASCIIToWide(version.GetString())) | 426 return target_path().Append(ASCIIToWide(version.GetString())) |
417 .Append(kInstallerDir); | 427 .Append(kInstallerDir); |
418 } | 428 } |
419 | 429 |
grt (UTC plus 2)
2011/07/14 14:25:29
add "// static" comment
robertshield
2011/07/15 13:49:18
Done.
| |
430 bool InstallerState::IsFileInUse(const FilePath& file) { | |
431 bool in_use = true; | |
432 // Call CreateFile with a share mode of 0 which should cause this to fail | |
433 // with ERROR_SHARING_VIOLATION if the file exists and is in-use. | |
434 base::win::ScopedHandle file_handle(CreateFile(file.value().c_str(), | |
grt (UTC plus 2)
2011/07/14 14:25:29
this function could be reduced to:
return !base::
robertshield
2011/07/15 13:49:18
Done.
| |
435 GENERIC_WRITE, 0, NULL, | |
436 OPEN_EXISTING, 0, 0)); | |
437 if (file_handle.IsValid()) { | |
438 in_use = false; | |
439 } | |
440 return in_use; | |
441 } | |
442 | |
grt (UTC plus 2)
2011/07/14 14:25:29
consider adding a brief comment here explaining th
robertshield
2011/07/15 13:49:18
Done.
| |
443 bool InstallerState::DetectChromeFrameInUse( | |
444 const InstallationState& machine_state) { | |
445 bool in_use = false; | |
446 scoped_ptr<Version> current_version(GetCurrentVersion(machine_state)); | |
447 if (current_version != NULL) { | |
448 FilePath cf_install_path( | |
449 target_path().AppendASCII(current_version->GetString()) | |
450 .Append(kChromeFrameDll)); | |
451 in_use = IsFileInUse(cf_install_path); | |
452 } | |
453 return in_use; | |
454 } | |
455 | |
420 void InstallerState::RemoveOldVersionDirectories( | 456 void InstallerState::RemoveOldVersionDirectories( |
421 const Version& new_version, | 457 const Version& new_version, |
422 Version* existing_version, | 458 Version* existing_version, |
423 const FilePath& temp_path) const { | 459 const FilePath& temp_path) const { |
424 file_util::FileEnumerator version_enum(target_path(), false, | 460 file_util::FileEnumerator version_enum(target_path(), false, |
425 file_util::FileEnumerator::DIRECTORIES); | 461 file_util::FileEnumerator::DIRECTORIES); |
426 scoped_ptr<Version> version; | 462 scoped_ptr<Version> version; |
427 std::vector<FilePath> key_files; | 463 std::vector<FilePath> key_files; |
428 | 464 |
429 // We try to delete all directories whose versions are lower than | 465 // We try to delete all directories whose versions are lower than |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
579 if (is_multi_install()) { | 615 if (is_multi_install()) { |
580 InstallUtil::AddInstallerResultItems( | 616 InstallUtil::AddInstallerResultItems( |
581 system_install, multi_package_binaries_distribution()->GetStateKey(), | 617 system_install, multi_package_binaries_distribution()->GetStateKey(), |
582 status, string_resource_id, launch_cmd, install_list.get()); | 618 status, string_resource_id, launch_cmd, install_list.get()); |
583 } | 619 } |
584 if (!install_list->Do()) | 620 if (!install_list->Do()) |
585 LOG(ERROR) << "Failed to record installer error information in registry."; | 621 LOG(ERROR) << "Failed to record installer error information in registry."; |
586 } | 622 } |
587 | 623 |
588 } // namespace installer | 624 } // namespace installer |
OLD | NEW |