Index: chrome/installer/util/installer_state.cc |
=================================================================== |
--- chrome/installer/util/installer_state.cc (revision 91508) |
+++ chrome/installer/util/installer_state.cc (working copy) |
@@ -15,6 +15,7 @@ |
#include "base/string_util.h" |
#include "base/utf_string_conversions.h" |
#include "base/win/registry.h" |
+#include "base/win/scoped_handle.h" |
#include "chrome/installer/util/delete_tree_work_item.h" |
#include "chrome/installer/util/helper.h" |
#include "chrome/installer/util/install_util.h" |
@@ -25,6 +26,7 @@ |
#include "chrome/installer/util/work_item.h" |
#include "chrome/installer/util/work_item_list.h" |
+ |
namespace installer { |
bool InstallerState::IsMultiInstallUpdate(const MasterPreferences& prefs, |
@@ -75,7 +77,8 @@ |
state_type_(BrowserDistribution::CHROME_BROWSER), |
root_key_(NULL), |
msi_(false), |
- verbose_logging_(false) { |
+ verbose_logging_(false), |
+ is_chrome_frame_running_(false) { |
} |
InstallerState::InstallerState(Level level) |
@@ -86,7 +89,8 @@ |
state_type_(BrowserDistribution::CHROME_BROWSER), |
root_key_(NULL), |
msi_(false), |
- verbose_logging_(false) { |
+ verbose_logging_(false), |
+ is_chrome_frame_running_(false) { |
// Use set_level() so that root_key_ is updated properly. |
set_level(level); |
} |
@@ -155,6 +159,8 @@ |
state_key_ = operand->GetStateKey(); |
state_type_ = operand->GetType(); |
+ |
+ is_chrome_frame_running_ = DetectChromeFrameInUse(machine_state); |
} |
void InstallerState::set_level(Level level) { |
@@ -340,6 +346,10 @@ |
return package_type_ != SINGLE_PACKAGE; |
} |
+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.
|
+ return is_chrome_frame_running_; |
+} |
+ |
bool InstallerState::RemoveProduct(const Product* product) { |
ScopedVector<Product>::iterator it = |
std::find(products_.begin(), products_.end(), product); |
@@ -417,6 +427,32 @@ |
.Append(kInstallerDir); |
} |
grt (UTC plus 2)
2011/07/14 14:25:29
add "// static" comment
robertshield
2011/07/15 13:49:18
Done.
|
+bool InstallerState::IsFileInUse(const FilePath& file) { |
+ bool in_use = true; |
+ // Call CreateFile with a share mode of 0 which should cause this to fail |
+ // with ERROR_SHARING_VIOLATION if the file exists and is in-use. |
+ 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.
|
+ GENERIC_WRITE, 0, NULL, |
+ OPEN_EXISTING, 0, 0)); |
+ if (file_handle.IsValid()) { |
+ in_use = false; |
+ } |
+ return in_use; |
+} |
+ |
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.
|
+bool InstallerState::DetectChromeFrameInUse( |
+ const InstallationState& machine_state) { |
+ bool in_use = false; |
+ scoped_ptr<Version> current_version(GetCurrentVersion(machine_state)); |
+ if (current_version != NULL) { |
+ FilePath cf_install_path( |
+ target_path().AppendASCII(current_version->GetString()) |
+ .Append(kChromeFrameDll)); |
+ in_use = IsFileInUse(cf_install_path); |
+ } |
+ return in_use; |
+} |
+ |
void InstallerState::RemoveOldVersionDirectories( |
const Version& new_version, |
Version* existing_version, |