| Index: chrome/browser/process_singleton_win.cc
|
| diff --git a/chrome/browser/process_singleton_win.cc b/chrome/browser/process_singleton_win.cc
|
| index 43adccc5b8203129f61d7ac92cacb2604e4f3615..8f2ea42b78441f1867cc1a456c9b4ef9d3b30fd2 100644
|
| --- a/chrome/browser/process_singleton_win.cc
|
| +++ b/chrome/browser/process_singleton_win.cc
|
| @@ -20,6 +20,7 @@
|
| #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/shell_integration.h"
|
| #include "chrome/browser/ui/metro_chrome_win.h"
|
| #include "chrome/browser/ui/simple_message_box.h"
|
| @@ -39,9 +40,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
|
| @@ -239,8 +237,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;
|
| @@ -291,73 +288,8 @@ 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);
|
| - }
|
| - 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());
|
| - 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;
|
| - }
|
| + if (chrome::AttemptToNotifyRunningChrome(remote_window_))
|
| return PROCESS_NOTIFIED;
|
| - }
|
|
|
| // It is possible that the process owning this window may have died by now.
|
| if (!::IsWindow(remote_window_)) {
|
| @@ -407,9 +339,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
|
| @@ -425,9 +355,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
|
| @@ -476,9 +404,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_);
|
| }
|
| }
|
|
|
|
|