blob: 73b7e7c13c7d77119cbda91f167bee6aaed7d341 [file] [log] [blame]
[email protected]9a47c432013-04-19 20:33:551// 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.
4
5#ifndef CHROME_BROWSER_PROCESS_SINGLETON_MODAL_DIALOG_LOCK_H_
6#define CHROME_BROWSER_PROCESS_SINGLETON_MODAL_DIALOG_LOCK_H_
7
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"
12
[email protected]9a47c432013-04-19 20:33:5513namespace base {
[email protected]2f3b1cc2014-03-17 23:07:1514class CommandLine;
[email protected]9a47c432013-04-19 20:33:5515class FilePath;
16}
17
18// Provides a ProcessSingleton::NotificationCallback that prevents
19// command-line handling when a modal dialog is active during startup. The
20// client must ensure that SetActiveModalDialog is called appropriately when
21// such dialogs are displayed or dismissed.
22//
23// While a dialog is active, the ProcessSingleton notification
24// callback will handle but ignore notifications:
25// 1. Neither this process nor the invoking process will handle the command
26// line.
27// 2. The active dialog is brought to the foreground and/or the taskbar icon
28// flashed (using ::SetForegroundWindow on Windows).
29//
30// Otherwise, the notification is forwarded to a wrapped NotificationCallback.
31class ProcessSingletonModalDialogLock {
32 public:
33 typedef base::Callback<void(gfx::NativeWindow)> SetForegroundWindowHandler;
34 explicit ProcessSingletonModalDialogLock(
35 const ProcessSingleton::NotificationCallback& original_callback);
36
37 ProcessSingletonModalDialogLock(
38 const ProcessSingleton::NotificationCallback& original_callback,
39 const SetForegroundWindowHandler& set_foreground_window_handler);
40
41 ~ProcessSingletonModalDialogLock();
42
43 // Receives a handle to the active modal dialog, or NULL if the active dialog
44 // is dismissed.
45 void SetActiveModalDialog(gfx::NativeWindow active_dialog);
46
47 // Returns the ProcessSingleton::NotificationCallback.
48 // The callback is only valid during the lifetime of the
49 // ProcessSingletonModalDialogLock instance.
50 ProcessSingleton::NotificationCallback AsNotificationCallback();
51
52 private:
[email protected]2f3b1cc2014-03-17 23:07:1553 bool NotificationCallbackImpl(const base::CommandLine& command_line,
[email protected]9a47c432013-04-19 20:33:5554 const base::FilePath& current_directory);
55
56 gfx::NativeWindow active_dialog_;
57 ProcessSingleton::NotificationCallback original_callback_;
58 SetForegroundWindowHandler set_foreground_window_handler_;
59
60 DISALLOW_COPY_AND_ASSIGN(ProcessSingletonModalDialogLock);
61};
62
63#endif // CHROME_BROWSER_PROCESS_SINGLETON_MODAL_DIALOG_LOCK_H_