Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / process_singleton_modal_dialog_lock.h
blobd287865df0285a8b29f7942ac62798dd9d076fe2
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_PROCESS_SINGLETON_MODAL_DIALOG_LOCK_H_
6 #define CHROME_BROWSER_PROCESS_SINGLETON_MODAL_DIALOG_LOCK_H_
8 #include "base/basictypes.h"
9 #include "base/callback_forward.h"
10 #include "chrome/browser/process_singleton.h"
11 #include "ui/gfx/native_widget_types.h"
13 class CommandLine;
15 namespace base {
16 class FilePath;
19 // Provides a ProcessSingleton::NotificationCallback that prevents
20 // command-line handling when a modal dialog is active during startup. The
21 // client must ensure that SetActiveModalDialog is called appropriately when
22 // such dialogs are displayed or dismissed.
24 // While a dialog is active, the ProcessSingleton notification
25 // callback will handle but ignore notifications:
26 // 1. Neither this process nor the invoking process will handle the command
27 // line.
28 // 2. The active dialog is brought to the foreground and/or the taskbar icon
29 // flashed (using ::SetForegroundWindow on Windows).
31 // Otherwise, the notification is forwarded to a wrapped NotificationCallback.
32 class ProcessSingletonModalDialogLock {
33 public:
34 typedef base::Callback<void(gfx::NativeWindow)> SetForegroundWindowHandler;
35 explicit ProcessSingletonModalDialogLock(
36 const ProcessSingleton::NotificationCallback& original_callback);
38 ProcessSingletonModalDialogLock(
39 const ProcessSingleton::NotificationCallback& original_callback,
40 const SetForegroundWindowHandler& set_foreground_window_handler);
42 ~ProcessSingletonModalDialogLock();
44 // Receives a handle to the active modal dialog, or NULL if the active dialog
45 // is dismissed.
46 void SetActiveModalDialog(gfx::NativeWindow active_dialog);
48 // Returns the ProcessSingleton::NotificationCallback.
49 // The callback is only valid during the lifetime of the
50 // ProcessSingletonModalDialogLock instance.
51 ProcessSingleton::NotificationCallback AsNotificationCallback();
53 private:
54 bool NotificationCallbackImpl(const CommandLine& command_line,
55 const base::FilePath& current_directory);
57 gfx::NativeWindow active_dialog_;
58 ProcessSingleton::NotificationCallback original_callback_;
59 SetForegroundWindowHandler set_foreground_window_handler_;
61 DISALLOW_COPY_AND_ASSIGN(ProcessSingletonModalDialogLock);
64 #endif // CHROME_BROWSER_PROCESS_SINGLETON_MODAL_DIALOG_LOCK_H_