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

Unified Diff: chrome/browser/process_singleton_win.cc

Issue 57082: Greatly reduce the race window in ProcessSingleton... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/process_singleton_win.cc
===================================================================
--- chrome/browser/process_singleton_win.cc (revision 12754)
+++ chrome/browser/process_singleton_win.cc (working copy)
@@ -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 @@
} // 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 @@
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};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698