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 <shellapi.h> | 7 #include <shellapi.h> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 L"Local\\ChromeProcessSingletonStartupMetroActivation!"; | 349 L"Local\\ChromeProcessSingletonStartupMetroActivation!"; |
350 | 350 |
351 remote_window_ = chrome::FindRunningChromeWindow(user_data_dir_); | 351 remote_window_ = chrome::FindRunningChromeWindow(user_data_dir_); |
352 if (!remote_window_ && !EscapeVirtualization(user_data_dir_)) { | 352 if (!remote_window_ && !EscapeVirtualization(user_data_dir_)) { |
353 // Make sure we will be the one and only process creating the window. | 353 // Make sure we will be the one and only process creating the window. |
354 // We use a named Mutex since we are protecting against multi-process | 354 // We use a named Mutex since we are protecting against multi-process |
355 // access. As documented, it's clearer to NOT request ownership on creation | 355 // access. As documented, it's clearer to NOT request ownership on creation |
356 // since it isn't guaranteed we will get it. It is better to create it | 356 // since it isn't guaranteed we will get it. It is better to create it |
357 // without ownership and explicitly get the ownership afterward. | 357 // without ownership and explicitly get the ownership afterward. |
358 base::win::ScopedHandle only_me(::CreateMutex(NULL, FALSE, kMutexName)); | 358 base::win::ScopedHandle only_me(::CreateMutex(NULL, FALSE, kMutexName)); |
359 DPCHECK(only_me.IsValid()); | 359 if (!only_me.IsValid()) { |
| 360 DPLOG(FATAL) << "CreateMutex failed"; |
| 361 return false; |
| 362 } |
360 | 363 |
361 AutoLockMutex auto_lock_only_me(only_me); | 364 AutoLockMutex auto_lock_only_me(only_me.Get()); |
362 | 365 |
363 // We now own the mutex so we are the only process that can create the | 366 // We now own the mutex so we are the only process that can create the |
364 // window at this time, but we must still check if someone created it | 367 // window at this time, but we must still check if someone created it |
365 // between the time where we looked for it above and the time the mutex | 368 // between the time where we looked for it above and the time the mutex |
366 // was given to us. | 369 // was given to us. |
367 remote_window_ = chrome::FindRunningChromeWindow(user_data_dir_); | 370 remote_window_ = chrome::FindRunningChromeWindow(user_data_dir_); |
368 | 371 |
369 | 372 |
370 // In Win8+, a new Chrome process launched in Desktop mode may need to be | 373 // In Win8+, a new Chrome process launched in Desktop mode may need to be |
371 // transmuted into Metro Chrome (see ShouldLaunchInWindows8ImmersiveMode for | 374 // transmuted into Metro Chrome (see ShouldLaunchInWindows8ImmersiveMode for |
(...skipping 23 matching lines...) Expand all Loading... |
395 LOG(ERROR) << "Failed to launch immersive chrome"; | 398 LOG(ERROR) << "Failed to launch immersive chrome"; |
396 metro_activation_event.Close(); | 399 metro_activation_event.Close(); |
397 } | 400 } |
398 } | 401 } |
399 | 402 |
400 if (metro_activation_event.IsValid()) { | 403 if (metro_activation_event.IsValid()) { |
401 // Release |only_me| (to let Metro Chrome grab this singleton) and wait | 404 // Release |only_me| (to let Metro Chrome grab this singleton) and wait |
402 // until the event is signaled (i.e. Metro Chrome was successfully | 405 // until the event is signaled (i.e. Metro Chrome was successfully |
403 // activated). Ignore timeout waiting for |metro_activation_event|. | 406 // activated). Ignore timeout waiting for |metro_activation_event|. |
404 { | 407 { |
405 AutoUnlockMutex auto_unlock_only_me(only_me); | 408 AutoUnlockMutex auto_unlock_only_me(only_me.Get()); |
406 | 409 |
407 DWORD result = ::WaitForSingleObject(metro_activation_event, | 410 DWORD result = ::WaitForSingleObject(metro_activation_event.Get(), |
408 kMetroChromeActivationTimeoutMs); | 411 kMetroChromeActivationTimeoutMs); |
409 DPCHECK(result == WAIT_OBJECT_0 || result == WAIT_TIMEOUT) | 412 DPCHECK(result == WAIT_OBJECT_0 || result == WAIT_TIMEOUT) |
410 << "Result = " << result; | 413 << "Result = " << result; |
411 } | 414 } |
412 | 415 |
413 // Check if this singleton was successfully grabbed by another process | 416 // Check if this singleton was successfully grabbed by another process |
414 // (hopefully Metro Chrome). Failing to do so, this process will grab | 417 // (hopefully Metro Chrome). Failing to do so, this process will grab |
415 // the singleton and launch in Desktop mode. | 418 // the singleton and launch in Desktop mode. |
416 remote_window_ = chrome::FindRunningChromeWindow(user_data_dir_); | 419 remote_window_ = chrome::FindRunningChromeWindow(user_data_dir_); |
417 } | 420 } |
(...skipping 25 matching lines...) Expand all Loading... |
443 user_data_dir_.value()); | 446 user_data_dir_.value()); |
444 CHECK(result && window_.hwnd()); | 447 CHECK(result && window_.hwnd()); |
445 } | 448 } |
446 | 449 |
447 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | 450 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
448 // Make sure no one is still waiting on Metro activation whether it | 451 // Make sure no one is still waiting on Metro activation whether it |
449 // succeeded (i.e., this is the Metro process) or failed. | 452 // succeeded (i.e., this is the Metro process) or failed. |
450 base::win::ScopedHandle metro_activation_event( | 453 base::win::ScopedHandle metro_activation_event( |
451 ::OpenEvent(EVENT_MODIFY_STATE, FALSE, kMetroActivationEventName)); | 454 ::OpenEvent(EVENT_MODIFY_STATE, FALSE, kMetroActivationEventName)); |
452 if (metro_activation_event.IsValid()) | 455 if (metro_activation_event.IsValid()) |
453 ::SetEvent(metro_activation_event); | 456 ::SetEvent(metro_activation_event.Get()); |
454 } | 457 } |
455 } | 458 } |
456 } | 459 } |
457 | 460 |
458 return window_.hwnd() != NULL; | 461 return window_.hwnd() != NULL; |
459 } | 462 } |
460 | 463 |
461 void ProcessSingleton::Cleanup() { | 464 void ProcessSingleton::Cleanup() { |
462 } | 465 } |
OLD | NEW |