diff options
author | cpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-08 00:20:32 +0000 |
---|---|---|
committer | cpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-08 00:20:32 +0000 |
commit | f891fb36c971320d64a399c0eba55391ab2cb74b (patch) | |
tree | dd824a30513f565d07aaefdfc70356b18937be1f /chrome | |
parent | 4e41709d76504c389bb8c29b61a71773b5db6239 (diff) | |
download | chromium_src-f891fb36c971320d64a399c0eba55391ab2cb74b.zip chromium_src-f891fb36c971320d64a399c0eba55391ab2cb74b.tar.gz chromium_src-f891fb36c971320d64a399c0eba55391ab2cb74b.tar.bz2 |
Greatly reduce the race window in ProcessSingleton
- fix only for windows
- Anantha has a good test to be commited RSN
BUG=9593
Review URL: http://codereview.chromium.org/57082
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13313 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/process_singleton_win.cc | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/chrome/browser/process_singleton_win.cc b/chrome/browser/process_singleton_win.cc index af61e22..289e4d1 100644 --- a/chrome/browser/process_singleton_win.cc +++ b/chrome/browser/process_singleton_win.cc @@ -22,7 +22,7 @@ namespace { -// Checks the visiblilty of the enumerated window and signals once a visible +// Checks the visibility of the enumerated window and signals once a visible // window has been found. BOOL CALLBACK BrowserWindowEnumeration(HWND window, LPARAM param) { bool* result = reinterpret_cast<bool*>(param); @@ -33,14 +33,15 @@ BOOL CALLBACK BrowserWindowEnumeration(HWND window, LPARAM param) { } // namespace +// Look for a Chrome instance that uses the same profile directory. ProcessSingleton::ProcessSingleton(const FilePath& user_data_dir) - : window_(NULL), - locked_(false) { - // Look for a Chrome instance that uses the same profile directory: - remote_window_ = FindWindowEx(HWND_MESSAGE, - NULL, - chrome::kMessageWindowClass, + : window_(NULL), locked_(false) { + // FindWindoEx and Create() should be one atomic operation in order to not + // have a race condition. + remote_window_ = FindWindowEx(HWND_MESSAGE, NULL, chrome::kMessageWindowClass, user_data_dir.ToWStringHack().c_str()); + if (!remote_window_) + Create(); } ProcessSingleton::~ProcessSingleton() { @@ -126,9 +127,14 @@ bool ProcessSingleton::NotifyOtherProcess() { return false; } +// For windows, there is no need to call Create() since the call is made in +// the constructor but to avoid having more platform specific code in +// browser_main.cc we tolerate a second call which will do nothing. void ProcessSingleton::Create() { - DCHECK(!window_); DCHECK(!remote_window_); + if (window_) + return; + HINSTANCE hinst = GetModuleHandle(NULL); WNDCLASSEX wc = {0}; |