Index: chrome/browser/process_singleton_win.cc |
diff --git a/chrome/browser/process_singleton_win.cc b/chrome/browser/process_singleton_win.cc |
index f8aaf81999912f968867027f6dbac119261ea758..332346e8b95501439336e2efa0be5c1d57846eeb 100644 |
--- a/chrome/browser/process_singleton_win.cc |
+++ b/chrome/browser/process_singleton_win.cc |
@@ -23,8 +23,9 @@ |
#include "base/win/windows_version.h" |
#include "base/win/wrapped_window_proc.h" |
#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/chrome_process_finder_win.h" |
+#include "chrome/browser/metro_utils/metro_chrome_win.h" |
#include "chrome/browser/shell_integration.h" |
-#include "chrome/browser/ui/metro_chrome_win.h" |
#include "chrome/browser/ui/simple_message_box.h" |
#include "chrome/common/chrome_constants.h" |
#include "chrome/common/chrome_paths.h" |
@@ -42,9 +43,6 @@ namespace { |
const char kLockfile[] = "lockfile"; |
-const char kSearchUrl[] = |
- "http://www.google.com/search?q=%s&sourceid=chrome&ie=UTF-8"; |
- |
const int kMetroChromeActivationTimeoutMs = 3000; |
// A helper class that acquires the given |mutex| while the AutoLockMutex is in |
@@ -246,8 +244,7 @@ bool ProcessSingleton::EscapeVirtualization( |
HWND hwnd = 0; |
::Sleep(90); |
for (int tries = 200; tries; --tries) { |
- hwnd = ::FindWindowEx(HWND_MESSAGE, NULL, chrome::kMessageWindowClass, |
- user_data_dir.value().c_str()); |
+ hwnd = chrome::FindRunningChromeWindow(user_data_dir); |
if (hwnd) { |
::SetForegroundWindow(hwnd); |
break; |
@@ -298,79 +295,10 @@ ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() { |
return PROCESS_NONE; |
} |
- if (base::win::IsMetroProcess()) { |
- // Interesting corner case. We are launched as a metro process but we |
- // found another chrome running. Since metro enforces single instance then |
- // the other chrome must be desktop chrome and this must be a search charm |
- // activation. This scenario is unique; other cases should be properly |
- // handled by the delegate_execute which will not activate a second chrome. |
- string16 terms; |
- base::win::MetroLaunchType launch = base::win::GetMetroLaunchParams(&terms); |
- if (launch != base::win::METRO_SEARCH) { |
- LOG(WARNING) << "In metro mode, but and launch is " << launch; |
- } else { |
- std::string query = net::EscapeQueryParamValue(UTF16ToUTF8(terms), true); |
- std::string url = base::StringPrintf(kSearchUrl, query.c_str()); |
- SHELLEXECUTEINFOA sei = { sizeof(sei) }; |
- sei.fMask = SEE_MASK_FLAG_LOG_USAGE; |
- sei.nShow = SW_SHOWNORMAL; |
- sei.lpFile = url.c_str(); |
- ::OutputDebugStringA(sei.lpFile); |
- sei.lpDirectory = ""; |
- ::ShellExecuteExA(&sei); |
- } |
+ if (chrome::AttemptToNotifyRunningChrome(remote_window_)) |
return PROCESS_NOTIFIED; |
- } |
- |
- // Non-metro mode, send our command line to the other chrome message window. |
- // format is "START\0<<<current directory>>>\0<<<commandline>>>". |
- std::wstring to_send(L"START\0", 6); // want the NULL in the string. |
- base::FilePath cur_dir; |
- if (!PathService::Get(base::DIR_CURRENT, &cur_dir)) |
- return PROCESS_NONE; |
- to_send.append(cur_dir.value()); |
- to_send.append(L"\0", 1); // Null separator. |
- to_send.append(::GetCommandLineW()); |
- // Add the process start time as a flag. |
- to_send.append(L" --"); |
- to_send.append(ASCIIToWide(switches::kOriginalProcessStartTime)); |
- to_send.append(L"="); |
- to_send.append(base::Int64ToString16( |
- base::CurrentProcessInfo::CreationTime()->ToInternalValue())); |
- to_send.append(L"\0", 1); // Null separator. |
- |
- base::win::ScopedHandle process_handle; |
- if (base::win::GetVersion() >= base::win::VERSION_WIN8 && |
- base::OpenProcessHandleWithAccess( |
- process_id, PROCESS_QUERY_INFORMATION, |
- process_handle.Receive()) && |
- base::win::IsProcessImmersive(process_handle.Get())) { |
- chrome::ActivateMetroChrome(); |
- } |
- |
- // Allow the current running browser window making itself the foreground |
- // window (otherwise it will just flash in the taskbar). |
- ::AllowSetForegroundWindow(process_id); |
- |
- COPYDATASTRUCT cds; |
- cds.dwData = 0; |
- cds.cbData = static_cast<DWORD>((to_send.length() + 1) * sizeof(wchar_t)); |
- cds.lpData = const_cast<wchar_t*>(to_send.c_str()); |
- DWORD_PTR result = 0; |
- if (::SendMessageTimeout(remote_window_, |
- WM_COPYDATA, |
- NULL, |
- reinterpret_cast<LPARAM>(&cds), |
- SMTO_ABORTIFHUNG, |
- kTimeoutInSeconds * 1000, |
- &result)) { |
- // It is possible that the process owning this window may have died by now. |
- if (!result) { |
- remote_window_ = NULL; |
- return PROCESS_NONE; |
- } |
- return PROCESS_NOTIFIED; |
- } |
+ else |
+ remote_window_ = NULL; |
// It is possible that the process owning this window may have died by now. |
if (!::IsWindow(remote_window_)) { |
@@ -420,9 +348,7 @@ bool ProcessSingleton::Create() { |
static const wchar_t kMetroActivationEventName[] = |
L"Local\\ChromeProcessSingletonStartupMetroActivation!"; |
- remote_window_ = ::FindWindowEx(HWND_MESSAGE, NULL, |
- chrome::kMessageWindowClass, |
- user_data_dir_.value().c_str()); |
+ remote_window_ = chrome::FindRunningChromeWindow(user_data_dir_); |
if (!remote_window_ && !EscapeVirtualization(user_data_dir_)) { |
// Make sure we will be the one and only process creating the window. |
// We use a named Mutex since we are protecting against multi-process |
@@ -438,9 +364,7 @@ bool ProcessSingleton::Create() { |
// window at this time, but we must still check if someone created it |
// between the time where we looked for it above and the time the mutex |
// was given to us. |
- remote_window_ = ::FindWindowEx(HWND_MESSAGE, NULL, |
- chrome::kMessageWindowClass, |
- user_data_dir_.value().c_str()); |
+ remote_window_ = chrome::FindRunningChromeWindow(user_data_dir_); |
// In Win8+, a new Chrome process launched in Desktop mode may need to be |
@@ -489,9 +413,7 @@ bool ProcessSingleton::Create() { |
// Check if this singleton was successfully grabbed by another process |
// (hopefully Metro Chrome). Failing to do so, this process will grab |
// the singleton and launch in Desktop mode. |
- remote_window_ = ::FindWindowEx(HWND_MESSAGE, NULL, |
- chrome::kMessageWindowClass, |
- user_data_dir_.value().c_str()); |
+ remote_window_ = chrome::FindRunningChromeWindow(user_data_dir_); |
} |
} |