[email protected] | 9a47c43 | 2013-04-19 20:33:55 | [diff] [blame] | 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 | |
| 5 | #ifndef CHROME_BROWSER_CHROME_PROCESS_SINGLETON_H_ |
| 6 | #define CHROME_BROWSER_CHROME_PROCESS_SINGLETON_H_ |
| 7 | |
Greg Thompson | eafda51e | 2017-09-05 23:09:45 | [diff] [blame^] | 8 | #include "base/callback.h" |
[email protected] | 9a47c43 | 2013-04-19 20:33:55 | [diff] [blame] | 9 | #include "base/files/file_path.h" |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 10 | #include "base/macros.h" |
[email protected] | 9a47c43 | 2013-04-19 20:33:55 | [diff] [blame] | 11 | #include "chrome/browser/process_singleton.h" |
| 12 | #include "chrome/browser/process_singleton_modal_dialog_lock.h" |
| 13 | #include "chrome/browser/process_singleton_startup_lock.h" |
[email protected] | 9a47c43 | 2013-04-19 20:33:55 | [diff] [blame] | 14 | |
| 15 | // Composes a basic ProcessSingleton with ProcessSingletonStartupLock and |
| 16 | // ProcessSingletonModalDialogLock. |
| 17 | // |
Greg Thompson | eafda51e | 2017-09-05 23:09:45 | [diff] [blame^] | 18 | // Notifications from ProcessSingleton will first close a modal dialog if |
| 19 | // active. Otherwise, until |Unlock()| is called, they will be queued up. Once |
| 20 | // unlocked, notifications will be passed to the client-supplied |
[email protected] | 9a47c43 | 2013-04-19 20:33:55 | [diff] [blame] | 21 | // NotificationCallback. |
| 22 | // |
Greg Thompson | eafda51e | 2017-09-05 23:09:45 | [diff] [blame^] | 23 | // The client must ensure that SetModalDialogNotificationHandler is called |
| 24 | // appropriately when dialogs are displayed or dismissed during startup. If a |
| 25 | // dialog is active, it is closed (via the provided handler) and then the |
| 26 | // notification is processed as normal. |
[email protected] | 9a47c43 | 2013-04-19 20:33:55 | [diff] [blame] | 27 | class ChromeProcessSingleton { |
| 28 | public: |
| 29 | ChromeProcessSingleton( |
| 30 | const base::FilePath& user_data_dir, |
| 31 | const ProcessSingleton::NotificationCallback& notification_callback); |
| 32 | |
[email protected] | 9a47c43 | 2013-04-19 20:33:55 | [diff] [blame] | 33 | ~ChromeProcessSingleton(); |
| 34 | |
| 35 | // Notify another process, if available. Otherwise sets ourselves as the |
| 36 | // singleton instance. Returns PROCESS_NONE if we became the singleton |
| 37 | // instance. Callers are guaranteed to either have notified an existing |
| 38 | // process or have grabbed the singleton (unless the profile is locked by an |
| 39 | // unreachable process). |
| 40 | ProcessSingleton::NotifyResult NotifyOtherProcessOrCreate(); |
| 41 | |
| 42 | // Clear any lock state during shutdown. |
| 43 | void Cleanup(); |
| 44 | |
Greg Thompson | eafda51e | 2017-09-05 23:09:45 | [diff] [blame^] | 45 | // Receives a callback to be run to close the active modal dialog, or an empty |
| 46 | // closure if the active dialog is dismissed. |
| 47 | void SetModalDialogNotificationHandler(base::Closure notification_handler); |
[email protected] | 9a47c43 | 2013-04-19 20:33:55 | [diff] [blame] | 48 | |
| 49 | // Executes previously queued command-line invocations and allows future |
| 50 | // invocations to be executed immediately. |
| 51 | // This only has an effect the first time it is called. |
| 52 | void Unlock(); |
| 53 | |
| 54 | private: |
| 55 | // We compose these two locks with the client-supplied notification callback. |
| 56 | // First |modal_dialog_lock_| will discard any notifications that arrive while |
| 57 | // a modal dialog is active. Otherwise, it will pass the notification to |
| 58 | // |startup_lock_|, which will queue notifications until |Unlock()| is called. |
| 59 | // Notifications passing through both locks are finally delivered to our |
| 60 | // client. |
| 61 | ProcessSingletonStartupLock startup_lock_; |
|
|