OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/process_singleton.h" | 5 #include "chrome/browser/process_singleton.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 user_data_dir.value().c_str(), | 192 user_data_dir.value().c_str(), |
193 0, 0, 0, 0, 0, HWND_MESSAGE, 0, hinst, this); | 193 0, 0, 0, 0, 0, HWND_MESSAGE, 0, hinst, this); |
194 CHECK(window_); | 194 CHECK(window_); |
195 } | 195 } |
196 BOOL success = ReleaseMutex(only_me); | 196 BOOL success = ReleaseMutex(only_me); |
197 DCHECK(success) << "GetLastError = " << GetLastError(); | 197 DCHECK(success) << "GetLastError = " << GetLastError(); |
198 } | 198 } |
199 } | 199 } |
200 | 200 |
201 ProcessSingleton::~ProcessSingleton() { | 201 ProcessSingleton::~ProcessSingleton() { |
202 Cleanup(); | 202 // We need to unregister the window as late as possible so that we can detect |
| 203 // another instance of chrome running. Otherwise we may end up writing out |
| 204 // data while a new chrome is starting up. |
| 205 if (window_) { |
| 206 ::DestroyWindow(window_); |
| 207 ::UnregisterClass(chrome::kMessageWindowClass, |
| 208 base::GetModuleFromAddress(&ThunkWndProc)); |
| 209 } |
203 } | 210 } |
204 | 211 |
205 ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() { | 212 ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() { |
206 if (is_virtualized_) | 213 if (is_virtualized_) |
207 return PROCESS_NOTIFIED; // We already spawned the process in this case. | 214 return PROCESS_NOTIFIED; // We already spawned the process in this case. |
208 else if (!remote_window_) | 215 else if (!remote_window_) |
209 return PROCESS_NONE; | 216 return PROCESS_NONE; |
210 | 217 |
211 // Found another window, send our command line to it | 218 // Found another window, send our command line to it |
212 // format is "START\0<<<current directory>>>\0<<<commandline>>>". | 219 // format is "START\0<<<current directory>>>\0<<<commandline>>>". |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 DCHECK(!remote_window_); | 302 DCHECK(!remote_window_); |
296 DCHECK(notification_callback_.is_null()); | 303 DCHECK(notification_callback_.is_null()); |
297 | 304 |
298 if (window_ != NULL) | 305 if (window_ != NULL) |
299 notification_callback_ = notification_callback; | 306 notification_callback_ = notification_callback; |
300 | 307 |
301 return window_ != NULL; | 308 return window_ != NULL; |
302 } | 309 } |
303 | 310 |
304 void ProcessSingleton::Cleanup() { | 311 void ProcessSingleton::Cleanup() { |
305 // Window classes registered by DLLs are not cleaned up automatically on | |
306 // process exit, so we must unregister at the earliest chance possible. | |
307 // During the fast shutdown sequence, ProcessSingleton::Cleanup() is | |
308 // called if our process was the first to start. Therefore we try cleaning | |
309 // up here, and again in the destructor if needed to catch as many cases | |
310 // as possible. | |
311 if (window_) { | |
312 ::DestroyWindow(window_); | |
313 ::UnregisterClass(chrome::kMessageWindowClass, | |
314 base::GetModuleFromAddress(&ThunkWndProc)); | |
315 window_ = NULL; | |
316 } | |
317 } | 312 } |
318 | 313 |
319 LRESULT ProcessSingleton::OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds) { | 314 LRESULT ProcessSingleton::OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds) { |
320 // If locked, it means we are not ready to process this message because | 315 // If locked, it means we are not ready to process this message because |
321 // we are probably in a first run critical phase. | 316 // we are probably in a first run critical phase. |
322 if (locked_) { | 317 if (locked_) { |
323 #if defined(USE_AURA) | 318 #if defined(USE_AURA) |
324 NOTIMPLEMENTED(); | 319 NOTIMPLEMENTED(); |
325 #else | 320 #else |
326 // Attempt to place ourselves in the foreground / flash the task bar. | 321 // Attempt to place ourselves in the foreground / flash the task bar. |
(...skipping 25 matching lines...) Expand all Loading... |
352 switch (message) { | 347 switch (message) { |
353 case WM_COPYDATA: | 348 case WM_COPYDATA: |
354 return OnCopyData(reinterpret_cast<HWND>(wparam), | 349 return OnCopyData(reinterpret_cast<HWND>(wparam), |
355 reinterpret_cast<COPYDATASTRUCT*>(lparam)); | 350 reinterpret_cast<COPYDATASTRUCT*>(lparam)); |
356 default: | 351 default: |
357 break; | 352 break; |
358 } | 353 } |
359 | 354 |
360 return ::DefWindowProc(hwnd, message, wparam, lparam); | 355 return ::DefWindowProc(hwnd, message, wparam, lparam); |
361 } | 356 } |
OLD | NEW |