Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: chrome/browser/chrome_process_finder_win.cc

Issue 981223004: Add test for ProcessSingleton hung rendezvous case. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Gab's remaining comments. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/chrome_process_finder_win.h" 5 #include "chrome/browser/chrome_process_finder_win.h"
6 6
7 #include <shellapi.h> 7 #include <shellapi.h>
8 #include <string> 8 #include <string>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 10 matching lines...) Expand all
21 #include "base/win/scoped_handle.h" 21 #include "base/win/scoped_handle.h"
22 #include "base/win/win_util.h" 22 #include "base/win/win_util.h"
23 #include "base/win/windows_version.h" 23 #include "base/win/windows_version.h"
24 #include "chrome/browser/metro_utils/metro_chrome_win.h" 24 #include "chrome/browser/metro_utils/metro_chrome_win.h"
25 #include "chrome/common/chrome_constants.h" 25 #include "chrome/common/chrome_constants.h"
26 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
27 27
28 28
29 namespace { 29 namespace {
30 30
31 const int kTimeoutInSeconds = 20; 31 const int kDefaultTimeoutInSeconds = 20;
sky 2015/03/11 19:15:51 There is no point in this constant now. Initialize
Sigurður Ásgeirsson 2015/03/11 20:15:31 Done.
32
33 int g_timeout_in_seconds = kDefaultTimeoutInSeconds;
sky 2015/03/11 19:15:51 This isn't global, it's file local. It should be t
Sigurður Ásgeirsson 2015/03/11 20:15:31 Done.
gab 2015/03/11 20:25:35 Interesting, I've seen g_ prefixes used for file l
sky 2015/03/11 20:27:59 I agree that g_foo is more readable, but it's my t
32 34
33 // The following is copied from net/base/escape.cc. We don't want to depend on 35 // The following is copied from net/base/escape.cc. We don't want to depend on
34 // net here because this gets compiled into chrome.exe to facilitate 36 // net here because this gets compiled into chrome.exe to facilitate
35 // fast-rendezvous (see https://codereview.chromium.org/14617003/). 37 // fast-rendezvous (see https://codereview.chromium.org/14617003/).
36 38
37 // TODO(koz): Move these functions out of net/base/escape.cc into base/escape.cc 39 // TODO(koz): Move these functions out of net/base/escape.cc into base/escape.cc
38 // so we can depend on it directly. 40 // so we can depend on it directly.
39 41
40 // BEGIN COPY from net/base/escape.cc 42 // BEGIN COPY from net/base/escape.cc
41 43
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 136
135 // Allow the current running browser window to make itself the foreground 137 // Allow the current running browser window to make itself the foreground
136 // window (otherwise it will just flash in the taskbar). 138 // window (otherwise it will just flash in the taskbar).
137 ::AllowSetForegroundWindow(process_id); 139 ::AllowSetForegroundWindow(process_id);
138 140
139 COPYDATASTRUCT cds; 141 COPYDATASTRUCT cds;
140 cds.dwData = 0; 142 cds.dwData = 0;
141 cds.cbData = static_cast<DWORD>((to_send.length() + 1) * sizeof(wchar_t)); 143 cds.cbData = static_cast<DWORD>((to_send.length() + 1) * sizeof(wchar_t));
142 cds.lpData = const_cast<wchar_t*>(to_send.c_str()); 144 cds.lpData = const_cast<wchar_t*>(to_send.c_str());
143 DWORD_PTR result = 0; 145 DWORD_PTR result = 0;
144 if (::SendMessageTimeout(remote_window, 146 if (::SendMessageTimeout(remote_window, WM_COPYDATA, NULL,
145 WM_COPYDATA, 147 reinterpret_cast<LPARAM>(&cds), SMTO_ABORTIFHUNG,
146 NULL, 148 g_timeout_in_seconds * 1000, &result)) {
147 reinterpret_cast<LPARAM>(&cds),
148 SMTO_ABORTIFHUNG,
149 kTimeoutInSeconds * 1000,
150 &result)) {
151 return result ? NOTIFY_SUCCESS : NOTIFY_FAILED; 149 return result ? NOTIFY_SUCCESS : NOTIFY_FAILED;
152 } 150 }
153 151
154 // It is possible that the process owning this window may have died by now. 152 // It is possible that the process owning this window may have died by now.
155 if (!::IsWindow(remote_window)) 153 if (!::IsWindow(remote_window))
156 return NOTIFY_FAILED; 154 return NOTIFY_FAILED;
157 155
158 // If the window couldn't be notified but still exists, assume it is hung. 156 // If the window couldn't be notified but still exists, assume it is hung.
159 return NOTIFY_WINDOW_HUNG; 157 return NOTIFY_WINDOW_HUNG;
160 } 158 }
161 159
160 int SetNotificationTimeoutInSecondsForTesting(int new_timeout) {
161 int old_timeout = g_timeout_in_seconds;
162 g_timeout_in_seconds = new_timeout;
163 return old_timeout;
164 }
165
162 } // namespace chrome 166 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698