Chromium Code Reviews| Index: chrome/browser/process_singleton_modal_dialog_lock.cc |
| diff --git a/chrome/browser/process_singleton_modal_dialog_lock.cc b/chrome/browser/process_singleton_modal_dialog_lock.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f08cbce912956cf91ae4c3f802380b518a4e4d88 |
| --- /dev/null |
| +++ b/chrome/browser/process_singleton_modal_dialog_lock.cc |
| @@ -0,0 +1,65 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/process_singleton_modal_dialog_lock.h" |
| + |
| +#if defined(OS_WIN) |
| +#include <Windows.h> |
| +#endif |
| + |
| +#include "base/bind.h" |
| +#include "base/command_line.h" |
| +#include "base/files/file_path.h" |
| +#include "base/logging.h" |
| + |
| +namespace { |
| + |
| +#if !defined(OS_WIN) || defined(USE_AURA) |
|
gab
2013/03/28 13:45:53
Are you splitting the method in two ifdef'd impls
erikwright (departed)
2013/04/04 01:39:51
On Windows, these two signatures are equivalent. O
|
| +void DoSetForegroundWindow(gfx::NativeWindow /* target_window */) { |
| + NOTREACHED(); |
| +} |
| +#else |
| +void DoSetForegroundWindow(HWND target_window) { |
| + ::SetForegroundWindow(target_window); |
| +} |
| +#endif |
| + |
| +} // namespace |
| + |
| +ProcessSingletonModalDialogLock::ProcessSingletonModalDialogLock( |
| + const ProcessSingleton::NotificationCallback& original_callback) |
| + : active_dialog_(NULL), |
| + original_callback_(original_callback), |
| + set_foreground_window_handler_(base::Bind(&DoSetForegroundWindow)) {} |
| + |
| +ProcessSingletonModalDialogLock::ProcessSingletonModalDialogLock( |
| + const ProcessSingleton::NotificationCallback& original_callback, |
| + const SetForegroundWindowHandler& set_foreground_window_handler) |
| + : active_dialog_(NULL), |
| + original_callback_(original_callback), |
| + set_foreground_window_handler_(set_foreground_window_handler) {} |
| + |
| +ProcessSingletonModalDialogLock::~ProcessSingletonModalDialogLock() {} |
| + |
| +void ProcessSingletonModalDialogLock::SetActiveModalDialog( |
| + gfx::NativeWindow active_dialog) { |
| + active_dialog_ = active_dialog; |
| +} |
| + |
| +ProcessSingleton::NotificationCallback |
| +ProcessSingletonModalDialogLock::AsNotificationCallback() { |
| + return base::Bind(&ProcessSingletonModalDialogLock::NotificationCallbackImpl, |
| + base::Unretained(this)); |
| +} |
| + |
| +bool ProcessSingletonModalDialogLock::NotificationCallbackImpl( |
| + const CommandLine& command_line, |
| + const base::FilePath& current_directory) { |
| + if (active_dialog_ != NULL) { |
| + set_foreground_window_handler_.Run(active_dialog_); |
|
gab
2013/03/28 13:45:53
I don't really see a use-case for using a callback
erikwright (departed)
2013/04/04 01:39:51
This mechanism support unit-testing. Please see th
gab
2013/04/04 02:31:45
Ah nice, had somehow missed the test.
QQ, why not
erikwright (departed)
2013/04/07 02:27:29
I find friend declarations harmful and distasteful
|
| + return true; |
| + } else { |
| + return original_callback_.Run(command_line, current_directory); |
| + } |
| +} |