-
Notifications
You must be signed in to change notification settings - Fork 29
/
0001-Patch-installer-to-close-previous-browser-instance-o.patch
94 lines (88 loc) · 3.79 KB
/
0001-Patch-installer-to-close-previous-browser-instance-o.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
From 2bb22c22280c1aff5adbf8e5bd2940f4a089ca73 Mon Sep 17 00:00:00 2001
From: Hibiki Tachibana <57486057+Hibbiki@users.noreply.github.com>
Date: Thu, 5 Aug 2021 02:09:34 +0200
Subject: [PATCH 1/4] Patch installer to close previous browser instance on
system-level install
Signed-off-by: Hibiki Tachibana <57486057+Hibbiki@users.noreply.github.com>
---
chrome/installer/setup/install_worker.cc | 48 ++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/chrome/installer/setup/install_worker.cc b/chrome/installer/setup/install_worker.cc
index 2e0693a5add30..1ee1ac330317c 100644
--- a/chrome/installer/setup/install_worker.cc
+++ b/chrome/installer/setup/install_worker.cc
@@ -29,6 +29,8 @@
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
+#include "base/process/kill.h"
+#include "base/process/process_iterator.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/version.h"
@@ -38,6 +40,7 @@
#include "base/win/win_util.h"
#include "base/win/windows_version.h"
#include "build/branding_buildflags.h"
+#include "content/public/common/result_codes.h"
#include "chrome/install_static/buildflags.h"
#include "chrome/install_static/install_details.h"
#include "chrome/install_static/install_modes.h"
@@ -222,6 +225,46 @@ void AddDeleteUninstallEntryForMSIWorkItems(
delete_reg_key->set_best_effort(true);
}
+// Filter for processes whose base name matches and whose path starts with a
+// specified prefix.
+class ProcessPathPrefixFilter : public base::ProcessFilter {
+ public:
+ explicit ProcessPathPrefixFilter(
+ const base::FilePath::StringPieceType& process_path_prefix)
+ : process_path_prefix_(process_path_prefix) {}
+
+ // base::ProcessFilter:
+ bool Includes(const base::ProcessEntry& entry) const override {
+ // Test if |entry|'s file path starts with the prefix we're looking for.
+ base::Process process(::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION,
+ FALSE, entry.th32ProcessID));
+ if (!process.IsValid())
+ return false;
+
+ DWORD path_len = MAX_PATH;
+ wchar_t path_string[MAX_PATH];
+ if (::QueryFullProcessImageName(process.Handle(), 0, path_string,
+ &path_len)) {
+ base::FilePath file_path(path_string);
+ return base::StartsWith(file_path.value(), process_path_prefix_,
+ base::CompareCase::INSENSITIVE_ASCII);
+ }
+ PLOG(WARNING) << "QueryFullProcessImageName failed for PID "
+ << entry.th32ProcessID;
+ return false;
+ }
+
+ private:
+ const base::FilePath::StringPieceType process_path_prefix_;
+};
+
+// Gracefully closes previous Chrome process in |target_path|.
+void ClosePreviousChromeProcess(const base::FilePath& target_path) {
+ ProcessPathPrefixFilter target_path_filter(target_path.value());
+ base::CleanupProcesses(installer::kChromeExe, base::TimeDelta(),
+ content::RESULT_CODE_NORMAL_EXIT, &target_path_filter);
+}
+
// Adds Chrome specific install work items to |install_list|.
void AddChromeWorkItems(const InstallParams& install_params,
WorkItemList* install_list) {
@@ -234,6 +277,11 @@ void AddChromeWorkItems(const InstallParams& install_params,
const base::FilePath& target_path = installer_state.target_path();
+ // patch(Hibbiki): Close previous instance on system-install as we are missing
+ // required GoogleUpdate component to elevate and rename new_chrome.exe on exit.
+ if (installer_state.system_install())
+ ClosePreviousChromeProcess(target_path);
+
if (current_version.IsValid()) {
// Delete the archive from an existing install to save some disk space.
base::FilePath old_installer_dir(
--
2.41.0.windows.1