process_singleton_modal_dialog_lock.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.
  4. #ifndef CHROME_BROWSER_PROCESS_SINGLETON_MODAL_DIALOG_LOCK_H_
  5. #define CHROME_BROWSER_PROCESS_SINGLETON_MODAL_DIALOG_LOCK_H_
  6. #include "base/callback.h"
  7. #include "chrome/browser/process_singleton.h"
  8. namespace base {
  9. class CommandLine;
  10. class FilePath;
  11. }
  12. // Provides a ProcessSingleton::NotificationCallback that allows for closing a
  13. // modal dialog that is active during startup. The client must ensure that
  14. // SetModalDialogCallback is called appropriately when such dialogs are
  15. // displayed or dismissed.
  16. //
  17. // After invoking the modal dialog's callback, this process will continue normal
  18. // processing of the command line by forwarding the notification to a wrapped
  19. // NotificationCallback.
  20. class ProcessSingletonModalDialogLock {
  21. public:
  22. explicit ProcessSingletonModalDialogLock(
  23. const ProcessSingleton::NotificationCallback& original_callback);
  24. ProcessSingletonModalDialogLock(const ProcessSingletonModalDialogLock&) =
  25. delete;
  26. ProcessSingletonModalDialogLock& operator=(
  27. const ProcessSingletonModalDialogLock&) = delete;
  28. ~ProcessSingletonModalDialogLock();
  29. // Receives a callback to be run to close the active modal dialog, or an empty
  30. // closure if the active dialog is dismissed.
  31. void SetModalDialogNotificationHandler(
  32. base::RepeatingClosure notification_handler);
  33. // Returns the ProcessSingleton::NotificationCallback.
  34. // The callback is only valid during the lifetime of the
  35. // ProcessSingletonModalDialogLock instance.
  36. ProcessSingleton::NotificationCallback AsNotificationCallback();
  37. private:
  38. bool NotificationCallbackImpl(const base::CommandLine& command_line,
  39. const base::FilePath& current_directory);
  40. base::RepeatingClosure notification_handler_;
  41. ProcessSingleton::NotificationCallback original_callback_;
  42. };
  43. #endif // CHROME_BROWSER_PROCESS_SINGLETON_MODAL_DIALOG_LOCK_H_