Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <atlbase.h> | 5 #include <atlbase.h> |
| 6 #include <atlcom.h> | 6 #include <atlcom.h> |
| 7 #include <atlctl.h> | 7 #include <atlctl.h> |
| 8 #include <initguid.h> | 8 #include <initguid.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 | 10 |
| 11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/process/kill.h" | 15 #include "base/process/kill.h" |
| 16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 17 #include "base/win/scoped_com_initializer.h" | 17 #include "base/win/scoped_com_initializer.h" |
| 18 #include "base/win/scoped_comptr.h" | 18 #include "base/win/scoped_comptr.h" |
| 19 #include "base/win/scoped_handle.h" | 19 #include "base/win/scoped_handle.h" |
| 20 #include "base/win/windows_version.h" | |
| 20 #include "breakpad/src/client/windows/handler/exception_handler.h" | 21 #include "breakpad/src/client/windows/handler/exception_handler.h" |
| 21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/installer/util/browser_distribution.h" | 23 #include "chrome/installer/util/browser_distribution.h" |
| 23 #include "win8/delegate_execute/command_execute_impl.h" | 24 #include "win8/delegate_execute/command_execute_impl.h" |
| 24 #include "win8/delegate_execute/crash_server_init.h" | 25 #include "win8/delegate_execute/crash_server_init.h" |
| 25 #include "win8/delegate_execute/delegate_execute_operation.h" | 26 #include "win8/delegate_execute/delegate_execute_operation.h" |
| 26 #include "win8/delegate_execute/resource.h" | 27 #include "win8/delegate_execute/resource.h" |
| 27 | 28 |
| 28 using namespace ATL; | 29 using namespace ATL; |
| 29 | 30 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 DWORD pid = operation.GetParentPid(); | 110 DWORD pid = operation.GetParentPid(); |
| 110 AtlTrace("%ds timeout. Killing Chrome %d\n", kWaitSeconds, pid); | 111 AtlTrace("%ds timeout. Killing Chrome %d\n", kWaitSeconds, pid); |
| 111 base::KillProcessById(pid, 0, false); | 112 base::KillProcessById(pid, 0, false); |
| 112 } else { | 113 } else { |
| 113 AtlTrace("Failed to wait for relaunch mutex, result is 0x%x\n", result); | 114 AtlTrace("Failed to wait for relaunch mutex, result is 0x%x\n", result); |
| 114 } | 115 } |
| 115 } else { | 116 } else { |
| 116 // It is possible that chrome exits so fast that the mutex is not there. | 117 // It is possible that chrome exits so fast that the mutex is not there. |
| 117 AtlTrace("No relaunch mutex found\n"); | 118 AtlTrace("No relaunch mutex found\n"); |
| 118 } | 119 } |
| 119 | 120 |
|
cpu_(ooo_6.6-7.5)
2014/08/22 21:47:11
lets add a comment here about why we launch the wi
ananta
2014/08/22 22:17:53
Done.
| |
| 120 base::win::ScopedCOMInitializer com_initializer; | 121 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
| 122 base::win::ScopedCOMInitializer com_initializer; | |
| 121 | 123 |
| 122 base::string16 relaunch_flags(operation.relaunch_flags()); | 124 base::string16 relaunch_flags(operation.relaunch_flags()); |
| 123 SHELLEXECUTEINFO sei = { sizeof(sei) }; | 125 SHELLEXECUTEINFO sei = { sizeof(sei) }; |
| 124 sei.fMask = SEE_MASK_FLAG_LOG_USAGE; | 126 sei.fMask = SEE_MASK_FLAG_LOG_USAGE; |
| 125 sei.nShow = SW_SHOWNORMAL; | 127 sei.nShow = SW_SHOWNORMAL; |
| 126 sei.lpFile = operation.shortcut().value().c_str(); | 128 sei.lpFile = operation.shortcut().value().c_str(); |
| 127 sei.lpParameters = relaunch_flags.c_str(); | 129 sei.lpParameters = relaunch_flags.c_str(); |
| 128 | 130 |
| 129 AtlTrace(L"Relaunching Chrome via shortcut [%ls]\n", sei.lpFile); | 131 AtlTrace(L"Relaunching Chrome via shortcut [%ls]\n", sei.lpFile); |
| 130 | 132 |
| 131 if (!::ShellExecuteExW(&sei)) { | 133 if (!::ShellExecuteExW(&sei)) { |
| 132 int error = HRESULT_FROM_WIN32(::GetLastError()); | 134 int error = HRESULT_FROM_WIN32(::GetLastError()); |
| 133 AtlTrace("ShellExecute returned 0x%08X\n", error); | 135 AtlTrace("ShellExecute returned 0x%08X\n", error); |
| 134 return error; | 136 return error; |
| 137 } | |
| 138 } else { | |
| 139 base::FilePath chrome_exe_path; | |
| 140 bool found_exe = CommandExecuteImpl::FindChromeExe(&chrome_exe_path); | |
| 141 DCHECK(found_exe); | |
| 142 if (found_exe) { | |
| 143 bool launch_ash = CommandLine::ForCurrentProcess()->HasSwitch( | |
| 144 switches::kForceImmersive); | |
| 145 if (launch_ash) { | |
| 146 AtlTrace(L"Relaunching Chrome into Windows ASH on Windows 7\n"); | |
| 147 } else { | |
| 148 AtlTrace(L"Relaunching Chrome into Desktop From ASH on Windows 7\n"); | |
| 149 } | |
| 150 SHELLEXECUTEINFO sei = { sizeof(sei) }; | |
| 151 sei.fMask = SEE_MASK_FLAG_LOG_USAGE; | |
| 152 sei.nShow = SW_SHOWNORMAL; | |
| 153 // No point in using the shortcut if we are launching into ASH as any | |
| 154 // additonal command line switches specified in the shortcut will be | |
| 155 // ignored. This is because we don't have a good way to send the command | |
| 156 // line switches from the viewer to the browser process. | |
| 157 sei.lpFile = (launch_ash || operation.shortcut().empty()) ? | |
| 158 chrome_exe_path.value().c_str() : | |
| 159 operation.shortcut().value().c_str(); | |
| 160 sei.lpParameters = | |
| 161 launch_ash ? L"-ServerName:DefaultBrowserServer" : NULL; | |
| 162 if (!::ShellExecuteExW(&sei)) { | |
| 163 int error = HRESULT_FROM_WIN32(::GetLastError()); | |
| 164 AtlTrace("ShellExecute returned 0x%08X\n", error); | |
| 165 return error; | |
| 166 } | |
| 167 } | |
| 135 } | 168 } |
| 136 return S_OK; | 169 return S_OK; |
| 137 } | 170 } |
| 138 | 171 |
| 139 extern "C" int WINAPI _tWinMain(HINSTANCE , HINSTANCE, LPTSTR, int nShowCmd) { | 172 extern "C" int WINAPI _tWinMain(HINSTANCE , HINSTANCE, LPTSTR, int nShowCmd) { |
| 140 scoped_ptr<google_breakpad::ExceptionHandler> breakpad = | 173 scoped_ptr<google_breakpad::ExceptionHandler> breakpad = |
| 141 delegate_execute::InitializeCrashReporting(); | 174 delegate_execute::InitializeCrashReporting(); |
| 142 | 175 |
| 143 base::AtExitManager exit_manager; | 176 base::AtExitManager exit_manager; |
| 144 AtlTrace("delegate_execute enter\n"); | 177 AtlTrace("delegate_execute enter\n"); |
| 145 | 178 |
| 146 CommandLine::Init(0, NULL); | 179 CommandLine::Init(0, NULL); |
| 147 HRESULT ret_code = E_UNEXPECTED; | 180 HRESULT ret_code = E_UNEXPECTED; |
| 148 DelegateExecuteOperation operation; | 181 DelegateExecuteOperation operation; |
| 149 if (operation.Init(CommandLine::ForCurrentProcess())) { | 182 if (operation.Init(CommandLine::ForCurrentProcess())) { |
| 150 switch (operation.operation_type()) { | 183 switch (operation.operation_type()) { |
| 151 case DelegateExecuteOperation::DELEGATE_EXECUTE: | 184 case DelegateExecuteOperation::DELEGATE_EXECUTE: |
| 152 ret_code = _AtlModule.WinMain(nShowCmd); | 185 ret_code = _AtlModule.WinMain(nShowCmd); |
| 153 break; | 186 break; |
| 154 case DelegateExecuteOperation::RELAUNCH_CHROME: | 187 case DelegateExecuteOperation::RELAUNCH_CHROME: |
| 155 ret_code = RelaunchChrome(operation); | 188 ret_code = RelaunchChrome(operation); |
| 156 break; | 189 break; |
| 157 default: | 190 default: |
| 158 NOTREACHED(); | 191 NOTREACHED(); |
| 159 } | 192 } |
| 160 } | 193 } |
| 161 AtlTrace("delegate_execute exit, code = %d\n", ret_code); | 194 AtlTrace("delegate_execute exit, code = %d\n", ret_code); |
| 162 return ret_code; | 195 return ret_code; |
| 163 } | 196 } |
| OLD | NEW |