Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | bc38c25 | 2011-04-12 21:46:57 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Daniel Cheng | 7d9e3d5 | 2022-02-26 09:03:24 | [diff] [blame] | 5 | #include "chrome/browser/first_run/upgrade_util_win.h" |
[email protected] | bc38c25 | 2011-04-12 21:46:57 | [diff] [blame] | 6 | |
Takuto Ikuta | c8d6b16f | 2024-04-15 16:59:19 | [diff] [blame] | 7 | #include <objbase.h> |
| 8 | |
[email protected] | 770c6d8 | 2012-09-06 22:21:32 | [diff] [blame] | 9 | #include <windows.h> |
Nico Weber | eaa0841 | 2019-08-14 01:24:37 | [diff] [blame] | 10 | |
[email protected] | fdbea98d | 2014-05-16 19:29:20 | [diff] [blame] | 11 | #include <psapi.h> |
[email protected] | 770c6d8 | 2012-09-06 22:21:32 | [diff] [blame] | 12 | #include <shellapi.h> |
Robert Liao | b2bc703d | 2017-10-17 20:52:35 | [diff] [blame] | 13 | #include <wrl/client.h> |
[email protected] | 770c6d8 | 2012-09-06 22:21:32 | [diff] [blame] | 14 | |
[email protected] | bc38c25 | 2011-04-12 21:46:57 | [diff] [blame] | 15 | #include <algorithm> |
Greg Thompson | a1f9512 | 2019-01-31 22:46:45 | [diff] [blame] | 16 | #include <ios> |
[email protected] | bc38c25 | 2011-04-12 21:46:57 | [diff] [blame] | 17 | #include <string> |
| 18 | |
| 19 | #include "base/base_paths.h" |
Etienne Bergeron | 7a0ef61 | 2023-09-15 18:28:08 | [diff] [blame] | 20 | #include "base/check.h" |
[email protected] | bc38c25 | 2011-04-12 21:46:57 | [diff] [blame] | 21 | #include "base/command_line.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 22 | #include "base/files/file_path.h" |
thestig | 18dfb7a5 | 2014-08-26 10:44:04 | [diff] [blame] | 23 | #include "base/files/file_util.h" |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 24 | #include "base/functional/bind.h" |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 25 | #include "base/functional/function_ref.h" |
[email protected] | bc38c25 | 2011-04-12 21:46:57 | [diff] [blame] | 26 | #include "base/logging.h" |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 27 | #include "base/memory/ref_counted.h" |
| 28 | #include "base/memory/scoped_refptr.h" |
S. Ganesh | 4854086 | 2024-08-12 18:09:39 | [diff] [blame] | 29 | #include "base/metrics/histogram_functions.h" |
[email protected] | bc38c25 | 2011-04-12 21:46:57 | [diff] [blame] | 30 | #include "base/path_service.h" |
[email protected] | d09a4ce1c | 2013-07-24 17:37:02 | [diff] [blame] | 31 | #include "base/process/launch.h" |
| 32 | #include "base/process/process_handle.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 33 | #include "base/strings/string_number_conversions.h" |
[email protected] | d883056 | 2013-06-10 22:01:54 | [diff] [blame] | 34 | #include "base/strings/string_util.h" |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 35 | #include "base/synchronization/waitable_event.h" |
S. Ganesh | bb1d4fc | 2024-08-14 19:16:32 | [diff] [blame] | 36 | #include "base/system/sys_info.h" |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 37 | #include "base/task/sequenced_task_runner.h" |
| 38 | #include "base/task/task_traits.h" |
| 39 | #include "base/task/thread_pool.h" |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 40 | #include "base/threading/platform_thread.h" |
Gabriel Charette | 12b58ac | 2021-09-22 18:08:55 | [diff] [blame] | 41 | #include "base/time/time.h" |
S. Ganesh | 4854086 | 2024-08-12 18:09:39 | [diff] [blame] | 42 | #include "base/timer/elapsed_timer.h" |
Gabriel Charette | 12b58ac | 2021-09-22 18:08:55 | [diff] [blame] | 43 | #include "base/trace_event/trace_event.h" |
S. Ganesh | 4854086 | 2024-08-12 18:09:39 | [diff] [blame] | 44 | #include "base/values.h" |
[email protected] | bc38c25 | 2011-04-12 21:46:57 | [diff] [blame] | 45 | #include "base/win/registry.h" |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 46 | #include "base/win/scoped_bstr.h" |
| 47 | #include "base/win/scoped_variant.h" |
[email protected] | 770c6d8 | 2012-09-06 22:21:32 | [diff] [blame] | 48 | #include "base/win/windows_version.h" |
Nico Weber | eaa0841 | 2019-08-14 01:24:37 | [diff] [blame] | 49 | #include "build/branding_buildflags.h" |
ananta | 069fc88 | 2014-09-13 01:22:12 | [diff] [blame] | 50 | #include "chrome/browser/browser_process.h" |
Etienne Bergeron | 7a0ef61 | 2023-09-15 18:28:08 | [diff] [blame] | 51 | #include "chrome/browser/chrome_process_singleton.h" |
Daniel Cheng | 7d9e3d5 | 2022-02-26 09:03:24 | [diff] [blame] | 52 | #include "chrome/browser/first_run/upgrade_util.h" |
[email protected] | 3f69d6e61 | 2012-08-03 18:52:27 | [diff] [blame] | 53 | #include "chrome/browser/shell_integration.h" |
Javier Flores Assad | 9c26f9b9 | 2022-05-21 01:20:43 | [diff] [blame] | 54 | #include "chrome/browser/win/browser_util.h" |
[email protected] | 80274b9 | 2011-07-15 17:20:38 | [diff] [blame] | 55 | #include "chrome/common/chrome_switches.h" |
ananta | 069fc88 | 2014-09-13 01:22:12 | [diff] [blame] | 56 | #include "chrome/common/pref_names.h" |
grt | 4474dad | 2017-02-27 21:00:46 | [diff] [blame] | 57 | #include "chrome/install_static/install_util.h" |
S. Ganesh | f77e2a5 | 2022-11-22 18:40:19 | [diff] [blame] | 58 | #include "chrome/installer/util/app_command.h" |
S. Ganesh | 4854086 | 2024-08-12 18:09:39 | [diff] [blame] | 59 | #include "chrome/installer/util/per_install_values.h" |
[email protected] | bc38c25 | 2011-04-12 21:46:57 | [diff] [blame] | 60 | #include "chrome/installer/util/util_constants.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 61 | #include "components/prefs/pref_service.h" |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 62 | #include "third_party/abseil-cpp/absl/cleanup/cleanup.h" |
ananta | 069fc88 | 2014-09-13 01:22:12 | [diff] [blame] | 63 | #include "ui/base/ui_base_switches.h" |
[email protected] | bc38c25 | 2011-04-12 21:46:57 | [diff] [blame] | 64 | |
Nico Weber | eaa0841 | 2019-08-14 01:24:37 | [diff] [blame] | 65 | #if BUILDFLAG(GOOGLE_CHROME_BRANDING) |
S. Ganesh | 6adf04c | 2023-06-07 19:34:55 | [diff] [blame] | 66 | #include "chrome/updater/app/server/win/updater_legacy_idl.h" |
grt | 235b3f09 | 2015-05-27 21:42:48 | [diff] [blame] | 67 | #endif |
| 68 | |
[email protected] | bc38c25 | 2011-04-12 21:46:57 | [diff] [blame] | 69 | namespace { |
| 70 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 71 | bool GetNewerChromeFile(base::FilePath* path) { |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 72 | if (!base::PathService::Get(base::DIR_EXE, path)) |
[email protected] | bc38c25 | 2011-04-12 21:46:57 | [diff] [blame] | 73 | return false; |
| 74 | *path = path->Append(installer::kChromeNewExe); |
| 75 | return true; |
| 76 | } |
| 77 | |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 78 | #if BUILDFLAG(GOOGLE_CHROME_BRANDING) |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 79 | // Holds the result of the IPC to CoCreate `GoogleUpdate3Web`. |
| 80 | struct CreateGoogleUpdate3WebResult |
| 81 | : public base::RefCountedThreadSafe<CreateGoogleUpdate3WebResult> { |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 82 | Microsoft::WRL::ComPtr<IStream> stream; |
| 83 | base::WaitableEvent completion_event; |
| 84 | |
| 85 | private: |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 86 | friend class base::RefCountedThreadSafe<CreateGoogleUpdate3WebResult>; |
| 87 | ~CreateGoogleUpdate3WebResult() = default; |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 88 | }; |
| 89 | |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 90 | // CoCreates the `GoogleUpdate3Web` class, and if successful, marshals the |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 91 | // resulting interface into `result->stream`. Signals `result->completion_event` |
| 92 | // on successful or failed completion. |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 93 | void CreateAndMarshalGoogleUpdate3Web( |
| 94 | scoped_refptr<CreateGoogleUpdate3WebResult> result) { |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 95 | const absl::Cleanup signal_completion_event = [&result] { |
| 96 | result->completion_event.Signal(); |
| 97 | }; |
| 98 | |
| 99 | Microsoft::WRL::ComPtr<IUnknown> unknown; |
| 100 | { |
| 101 | TRACE_EVENT0("startup", "InvokeGoogleUpdateForRename CoCreateInstance"); |
| 102 | const HRESULT hr = |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 103 | ::CoCreateInstance(__uuidof(GoogleUpdate3WebSystemClass), nullptr, |
| 104 | CLSCTX_ALL, IID_PPV_ARGS(&unknown)); |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 105 | if (FAILED(hr)) { |
| 106 | TRACE_EVENT_INSTANT1( |
| 107 | "startup", "InvokeGoogleUpdateForRename CoCreateInstance failed", |
| 108 | TRACE_EVENT_SCOPE_THREAD, "hr", hr); |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 109 | LOG(ERROR) << "CoCreate GoogleUpdate3WebSystemClass failed; hr = " |
| 110 | << std::hex << hr; |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 111 | return; |
| 112 | } |
| 113 | } |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 114 | const HRESULT hr = ::CoMarshalInterThreadInterfaceInStream( |
| 115 | __uuidof(IUnknown), unknown.Get(), &result->stream); |
| 116 | if (FAILED(hr)) { |
| 117 | TRACE_EVENT_INSTANT1("startup", |
| 118 | "InvokeGoogleUpdateForRename " |
| 119 | "CoMarshalInterThreadInterfaceInStream failed", |
| 120 | TRACE_EVENT_SCOPE_THREAD, "hr", hr); |
| 121 | LOG(ERROR) << "CoMarshalInterThreadInterfaceInStream " |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 122 | "GoogleUpdate3WebSystemClass failed; hr = " |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 123 | << std::hex << hr; |
| 124 | } |
| 125 | } |
| 126 | |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 127 | // CoCreates the Google Update `GoogleUpdate3WebSystemClass` in a `ThreadPool` |
| 128 | // thread with a timeout, if the `ThreadPool` is operational. The starting value |
| 129 | // for the timeout is 15 seconds. If the CoCreate times out, the timeout is |
S. Ganesh | 4854086 | 2024-08-12 18:09:39 | [diff] [blame] | 130 | // increased by 15 seconds at each failed attempt and persisted for the next |
| 131 | // attempt. |
| 132 | // |
| 133 | // If the `ThreadPool` is not operational, the CoCreate is done |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 134 | // without a timeout. |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 135 | Microsoft::WRL::ComPtr<IUnknown> CreateGoogleUpdate3Web() { |
S. Ganesh | 4854086 | 2024-08-12 18:09:39 | [diff] [blame] | 136 | constexpr int kDefaultTimeoutIncrementSeconds = 15; |
S. Ganesh | bb1d4fc | 2024-08-14 19:16:32 | [diff] [blame] | 137 | constexpr base::TimeDelta kMaxTimeAfterSystemStartup = base::Seconds(150); |
S. Ganesh | 4854086 | 2024-08-12 18:09:39 | [diff] [blame] | 138 | |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 139 | auto result = base::MakeRefCounted<CreateGoogleUpdate3WebResult>(); |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 140 | if (base::ThreadPool::CreateCOMSTATaskRunner( |
| 141 | {base::MayBlock(), base::TaskPriority::USER_BLOCKING}) |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 142 | ->PostTask( |
| 143 | FROM_HERE, |
| 144 | base::BindOnce(&CreateAndMarshalGoogleUpdate3Web, result))) { |
S. Ganesh | 4854086 | 2024-08-12 18:09:39 | [diff] [blame] | 145 | installer::PerInstallValue creation_timeout( |
| 146 | L"ProcessLauncherCreationTimeout"); |
| 147 | const base::TimeDelta timeout = base::Seconds( |
| 148 | creation_timeout.Get() |
| 149 | .value_or(base::Value(kDefaultTimeoutIncrementSeconds)) |
| 150 | .GetIfInt() |
| 151 | .value_or(kDefaultTimeoutIncrementSeconds)); |
| 152 | const base::ElapsedTimer timer; |
S. Ganesh | bb1d4fc | 2024-08-14 19:16:32 | [diff] [blame] | 153 | const bool is_at_startup = |
| 154 | base::SysInfo::Uptime() <= kMaxTimeAfterSystemStartup; |
S. Ganesh | 4854086 | 2024-08-12 18:09:39 | [diff] [blame] | 155 | if (!result->completion_event.TimedWait(timeout)) { |
| 156 | base::UmaHistogramMediumTimes( |
S. Ganesh | bb1d4fc | 2024-08-14 19:16:32 | [diff] [blame] | 157 | is_at_startup |
| 158 | ? "Startup.CreateProcessLauncher2.TimedWaitFailedAtStartup" |
| 159 | : "Startup.CreateProcessLauncher2.TimedWaitFailed", |
| 160 | timer.Elapsed()); |
S. Ganesh | 4854086 | 2024-08-12 18:09:39 | [diff] [blame] | 161 | creation_timeout.Set(base::Value(static_cast<int>(timeout.InSeconds()) + |
| 162 | kDefaultTimeoutIncrementSeconds)); |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 163 | TRACE_EVENT_INSTANT0( |
| 164 | "startup", "InvokeGoogleUpdateForRename CoCreateInstance timed out", |
| 165 | TRACE_EVENT_SCOPE_THREAD); |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 166 | LOG(ERROR) << "CoCreate GoogleUpdate3WebSystemClass timed out"; |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 167 | return {}; |
| 168 | } |
| 169 | |
| 170 | if (!result->stream) { |
| 171 | return {}; |
| 172 | } |
S. Ganesh | 4854086 | 2024-08-12 18:09:39 | [diff] [blame] | 173 | base::UmaHistogramMediumTimes( |
S. Ganesh | bb1d4fc | 2024-08-14 19:16:32 | [diff] [blame] | 174 | is_at_startup |
| 175 | ? "Startup.CreateProcessLauncher2.TimedWaitSucceededAtStartup" |
| 176 | : "Startup.CreateProcessLauncher2.TimedWaitSucceeded", |
| 177 | timer.Elapsed()); |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 178 | |
| 179 | Microsoft::WRL::ComPtr<IUnknown> unknown; |
| 180 | const HRESULT hr = |
| 181 | ::CoUnmarshalInterface(result->stream.Get(), __uuidof(IUnknown), |
| 182 | IID_PPV_ARGS_Helper(&unknown)); |
| 183 | if (FAILED(hr)) { |
| 184 | TRACE_EVENT_INSTANT1( |
| 185 | "startup", "InvokeGoogleUpdateForRename CoUnmarshalInterface failed", |
| 186 | TRACE_EVENT_SCOPE_THREAD, "hr", hr); |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 187 | LOG(ERROR) |
| 188 | << "CoUnmarshalInterface GoogleUpdate3WebSystemClass failed; hr = " |
| 189 | << std::hex << hr; |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 190 | return {}; |
| 191 | } |
| 192 | |
| 193 | return unknown; |
| 194 | } |
| 195 | |
| 196 | // The task could not be posted to the task runner, so CoCreate without a |
| 197 | // timeout. This could happen in shutdown, where the `ThreadPool` is not |
| 198 | // operational. |
| 199 | { |
| 200 | TRACE_EVENT0("startup", "InvokeGoogleUpdateForRename CoCreateInstance"); |
| 201 | Microsoft::WRL::ComPtr<IUnknown> unknown; |
| 202 | const HRESULT hr = |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 203 | ::CoCreateInstance(__uuidof(GoogleUpdate3WebSystemClass), nullptr, |
| 204 | CLSCTX_ALL, IID_PPV_ARGS(&unknown)); |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 205 | if (FAILED(hr)) { |
| 206 | TRACE_EVENT_INSTANT1( |
| 207 | "startup", "InvokeGoogleUpdateForRename CoCreateInstance failed", |
| 208 | TRACE_EVENT_SCOPE_THREAD, "hr", hr); |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 209 | LOG(ERROR) << "CoCreate GoogleUpdate3WebSystemClass failed; hr = " |
| 210 | << std::hex << hr; |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 211 | return {}; |
| 212 | } |
| 213 | |
| 214 | return unknown; |
| 215 | } |
| 216 | } |
| 217 | #endif // BUILDFLAG(GOOGLE_CHROME_BRANDING) |
| 218 | |
[email protected] | bc38c25 | 2011-04-12 21:46:57 | [diff] [blame] | 219 | bool InvokeGoogleUpdateForRename() { |
Nico Weber | eaa0841 | 2019-08-14 01:24:37 | [diff] [blame] | 220 | #if BUILDFLAG(GOOGLE_CHROME_BRANDING) |
Gabriel Charette | f7e8571 | 2021-12-10 20:46:22 | [diff] [blame] | 221 | // This has been identified as very slow on some startups. Detailed trace |
| 222 | // events below try to shine a light on each steps. crbug.com/1252004 |
Gabriel Charette | 12b58ac | 2021-09-22 18:08:55 | [diff] [blame] | 223 | TRACE_EVENT0("startup", "upgrade_util::InvokeGoogleUpdateForRename"); |
| 224 | |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 225 | Microsoft::WRL::ComPtr<IUnknown> unknown = CreateGoogleUpdate3Web(); |
S. Ganesh | cad4503 | 2024-07-18 17:43:11 | [diff] [blame] | 226 | if (!unknown) { |
| 227 | return false; |
| 228 | } |
| 229 | |
S. Ganesh | ea7ef087 | 2024-03-21 16:28:32 | [diff] [blame] | 230 | // Chrome queries for the SxS IIDs first, with a fallback to the legacy IID, |
| 231 | // to make sure that marshaling loads the proxy/stub from the correct (HKLM) |
| 232 | // hive. |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 233 | Microsoft::WRL::ComPtr<IGoogleUpdate3Web> update3web; |
| 234 | if (HRESULT hr = unknown.CopyTo(__uuidof(IGoogleUpdate3WebSystem), |
| 235 | IID_PPV_ARGS_Helper(&update3web)); |
| 236 | FAILED(hr)) { |
| 237 | hr = unknown.As(&update3web); |
S. Ganesh | ea7ef087 | 2024-03-21 16:28:32 | [diff] [blame] | 238 | if (FAILED(hr)) { |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 239 | TRACE_EVENT_INSTANT1( |
| 240 | "startup", "InvokeGoogleUpdateForRename QI IGoogleUpdate3Web failed", |
| 241 | TRACE_EVENT_SCOPE_THREAD, "hr", hr); |
| 242 | LOG(ERROR) << "QI IGoogleUpdate3Web failed; hr = " << std::hex << hr; |
S. Ganesh | ea7ef087 | 2024-03-21 16:28:32 | [diff] [blame] | 243 | return false; |
| 244 | } |
[email protected] | bc38c25 | 2011-04-12 21:46:57 | [diff] [blame] | 245 | } |
Greg Thompson | a1f9512 | 2019-01-31 22:46:45 | [diff] [blame] | 246 | |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 247 | Microsoft::WRL::ComPtr<IAppBundleWeb> bundle; |
Gabriel Charette | f7e8571 | 2021-12-10 20:46:22 | [diff] [blame] | 248 | { |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 249 | Microsoft::WRL::ComPtr<IDispatch> dispatch; |
| 250 | if (HRESULT hr = update3web->createAppBundleWeb(&dispatch); FAILED(hr)) { |
| 251 | TRACE_EVENT_INSTANT1( |
| 252 | "startup", "InvokeGoogleUpdateForRename createAppBundleWeb failed", |
| 253 | TRACE_EVENT_SCOPE_THREAD, "hr", hr); |
| 254 | LOG(ERROR) << "createAppBundleWeb failed; hr = " << std::hex << hr; |
| 255 | return false; |
| 256 | } |
| 257 | |
| 258 | if (HRESULT hr = dispatch.CopyTo(__uuidof(IAppBundleWebSystem), |
| 259 | IID_PPV_ARGS_Helper(&bundle)); |
| 260 | FAILED(hr)) { |
| 261 | hr = dispatch.As(&bundle); |
| 262 | if (FAILED(hr)) { |
| 263 | TRACE_EVENT_INSTANT1( |
| 264 | "startup", "InvokeGoogleUpdateForRename QI IAppBundleWeb failed", |
| 265 | TRACE_EVENT_SCOPE_THREAD, "hr", hr); |
| 266 | LOG(ERROR) << "QI IAppBundleWeb failed; hr = " << std::hex << hr; |
| 267 | return false; |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | if (HRESULT hr = bundle->initialize(); FAILED(hr)) { |
| 273 | TRACE_EVENT_INSTANT1( |
| 274 | "startup", "InvokeGoogleUpdateForRename bundle->initialize failed", |
| 275 | TRACE_EVENT_SCOPE_THREAD, "hr", hr); |
| 276 | LOG(ERROR) << "bundle->initialize failed; hr = " << std::hex << hr; |
| 277 | return false; |
| 278 | } |
| 279 | |
| 280 | if (HRESULT hr = bundle->createInstalledApp( |
| 281 | base::win::ScopedBstr(install_static::GetAppGuid()).Get()); |
| 282 | FAILED(hr)) { |
| 283 | TRACE_EVENT_INSTANT1( |
| 284 | "startup", |
| 285 | "InvokeGoogleUpdateForRename bundle->createInstalledApp failed", |
| 286 | TRACE_EVENT_SCOPE_THREAD, "hr", hr); |
| 287 | LOG(ERROR) << "bundle->createInstalledApp failed; hr = " << std::hex << hr; |
| 288 | return false; |
| 289 | } |
| 290 | |
| 291 | Microsoft::WRL::ComPtr<IAppWeb> app; |
| 292 | { |
| 293 | Microsoft::WRL::ComPtr<IDispatch> app_dispatch; |
| 294 | if (HRESULT hr = bundle->get_appWeb(0, &app_dispatch); FAILED(hr)) { |
| 295 | TRACE_EVENT_INSTANT1( |
| 296 | "startup", "InvokeGoogleUpdateForRename bundle->get_appWeb failed", |
| 297 | TRACE_EVENT_SCOPE_THREAD, "hr", hr); |
| 298 | LOG(ERROR) << "bundle->get_appWeb failed; hr = " << std::hex << hr; |
| 299 | return false; |
| 300 | } |
| 301 | |
| 302 | if (HRESULT hr = app_dispatch.CopyTo(__uuidof(IAppWebSystem), |
| 303 | IID_PPV_ARGS_Helper(&app)); |
| 304 | FAILED(hr)) { |
| 305 | hr = app_dispatch.As(&app); |
| 306 | if (FAILED(hr)) { |
| 307 | TRACE_EVENT_INSTANT1("startup", |
| 308 | "InvokeGoogleUpdateForRename QI IAppWeb failed", |
| 309 | TRACE_EVENT_SCOPE_THREAD, "hr", hr); |
| 310 | LOG(ERROR) << "QI IAppWeb failed; hr = " << std::hex << hr; |
| 311 | return false; |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | Microsoft::WRL::ComPtr<IAppCommandWeb> app_command_web; |
| 317 | { |
| 318 | Microsoft::WRL::ComPtr<IDispatch> command_dispatch; |
| 319 | if (HRESULT hr = app->get_command( |
| 320 | base::win::ScopedBstr(installer::kCmdRenameChromeExe).Get(), |
| 321 | &command_dispatch); |
| 322 | FAILED(hr)) { |
| 323 | TRACE_EVENT_INSTANT1( |
| 324 | "startup", "InvokeGoogleUpdateForRename app->get_command failed", |
| 325 | TRACE_EVENT_SCOPE_THREAD, "hr", hr); |
| 326 | LOG(ERROR) << "app->get_command failed; hr = " << std::hex << hr; |
| 327 | return false; |
| 328 | } |
| 329 | |
| 330 | if (HRESULT hr = |
| 331 | command_dispatch.CopyTo(__uuidof(IAppCommandWebSystem), |
| 332 | IID_PPV_ARGS_Helper(&app_command_web)); |
| 333 | FAILED(hr)) { |
| 334 | hr = command_dispatch.As(&app_command_web); |
| 335 | if (FAILED(hr)) { |
| 336 | TRACE_EVENT_INSTANT1( |
| 337 | "startup", "InvokeGoogleUpdateForRename QI IAppCommandWeb failed", |
| 338 | TRACE_EVENT_SCOPE_THREAD, "hr", hr); |
| 339 | LOG(ERROR) << "QI IAppCommandWeb failed; hr = " << std::hex << hr; |
| 340 | return false; |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | { |
| 346 | TRACE_EVENT0("startup", "InvokeGoogleUpdateForRename execute"); |
| 347 | if (HRESULT hr = |
| 348 | app_command_web->execute(base::win::ScopedVariant::kEmptyVariant, |
| 349 | base::win::ScopedVariant::kEmptyVariant, |
| 350 | base::win::ScopedVariant::kEmptyVariant, |
| 351 | base::win::ScopedVariant::kEmptyVariant, |
| 352 | base::win::ScopedVariant::kEmptyVariant, |
| 353 | base::win::ScopedVariant::kEmptyVariant, |
| 354 | base::win::ScopedVariant::kEmptyVariant, |
| 355 | base::win::ScopedVariant::kEmptyVariant, |
| 356 | base::win::ScopedVariant::kEmptyVariant); |
| 357 | FAILED(hr)) { |
| 358 | TRACE_EVENT_INSTANT1( |
| 359 | "startup", |
| 360 | "InvokeGoogleUpdateForRename app_command_web->execute failed", |
| 361 | TRACE_EVENT_SCOPE_THREAD, "hr", hr); |
| 362 | LOG(ERROR) << "app_command_web->execute failed; hr = " << std::hex << hr; |
Gabriel Charette | f7e8571 | 2021-12-10 20:46:22 | [diff] [blame] | 363 | return false; |
| 364 | } |
Greg Thompson | a1f9512 | 2019-01-31 22:46:45 | [diff] [blame] | 365 | } |
| 366 | |
Gabriel Charette | f7e8571 | 2021-12-10 20:46:22 | [diff] [blame] | 367 | { |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 368 | UINT status = 0; |
| 369 | for (const auto deadline = base::TimeTicks::Now() + base::Seconds(60); |
| 370 | base::TimeTicks::Now() < deadline; |
| 371 | base::PlatformThread::Sleep(base::Seconds(1))) { |
| 372 | if (HRESULT hr = app_command_web->get_status(&status); FAILED(hr)) { |
| 373 | TRACE_EVENT_INSTANT1( |
| 374 | "startup", |
| 375 | "InvokeGoogleUpdateForRename app_command_web->get_status failed", |
| 376 | TRACE_EVENT_SCOPE_THREAD, "hr", hr); |
| 377 | LOG(ERROR) << "app_command_web->get_status failed; hr = " << std::hex |
| 378 | << hr; |
| 379 | return false; |
| 380 | } |
| 381 | if (status == COMMAND_STATUS_COMPLETE) { |
| 382 | break; |
| 383 | } |
| 384 | } |
| 385 | if (status != COMMAND_STATUS_COMPLETE) { |
| 386 | TRACE_EVENT_INSTANT1( |
| 387 | "startup", "InvokeGoogleUpdateForRename !COMMAND_STATUS_COMPLETE", |
| 388 | TRACE_EVENT_SCOPE_THREAD, "status", status); |
| 389 | LOG(ERROR) << "AppCommand timed out with status code " << status; |
Gabriel Charette | f7e8571 | 2021-12-10 20:46:22 | [diff] [blame] | 390 | return false; |
| 391 | } |
Greg Thompson | a1f9512 | 2019-01-31 22:46:45 | [diff] [blame] | 392 | } |
| 393 | |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] | 394 | DWORD exit_code = 0; |
| 395 | if (HRESULT hr = app_command_web->get_exitCode(&exit_code); FAILED(hr)) { |
| 396 | TRACE_EVENT_INSTANT1( |
| 397 | "startup", |
| 398 | "InvokeGoogleUpdateForRename app_command_web->get_exitCode failed", |
| 399 | TRACE_EVENT_SCOPE_THREAD, "hr", hr); |
| 400 | LOG(ERROR) << "app_command_web->get_exitCode failed; hr = " << std::hex |
| 401 | << hr; |
| 402 | return false; |
| 403 | } |
| 404 | |
Greg Thompson | a1f9512 | 2019-01-31 22:46:45 | [diff] [blame] | 405 | if (exit_code != installer::RENAME_SUCCESSFUL) { |
S. Ganesh | 6822d2a | 2025-03-31 20:26:48 | [diff] [blame^] |
|