blob: 3a2e52c1ae5567c3530b679012b14c895a3eff54 [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_CHROME_PROCESS_SINGLETON_H_
6#define CHROME_BROWSER_CHROME_PROCESS_SINGLETON_H_
7
Greg Thompsoneafda51e2017-09-05 23:09:458#include "base/callback.h"
[email protected]9a47c432013-04-19 20:33:559#include "base/files/file_path.h"
[email protected]9a47c432013-04-19 20:33:5510#include "chrome/browser/process_singleton.h"
11#include "chrome/browser/process_singleton_modal_dialog_lock.h"
12#include "chrome/browser/process_singleton_startup_lock.h"
[email protected]9a47c432013-04-19 20:33:5513
14// Composes a basic ProcessSingleton with ProcessSingletonStartupLock and
15// ProcessSingletonModalDialogLock.
16//
Greg Thompsoneafda51e2017-09-05 23:09:4517// Notifications from ProcessSingleton will first close a modal dialog if
18// active. Otherwise, until |Unlock()| is called, they will be queued up. Once
19// unlocked, notifications will be passed to the client-supplied
[email protected]9a47c432013-04-19 20:33:5520// NotificationCallback.
21//
Greg Thompsoneafda51e2017-09-05 23:09:4522// The client must ensure that SetModalDialogNotificationHandler is called
23// appropriately when dialogs are displayed or dismissed during startup. If a
24// dialog is active, it is closed (via the provided handler) and then the
25// notification is processed as normal.
[email protected]9a47c432013-04-19 20:33:5526class ChromeProcessSingleton {
27 public:
28 ChromeProcessSingleton(
29 const base::FilePath& user_data_dir,
30 const ProcessSingleton::NotificationCallback& notification_callback);
31
Peter Boström53c6c5952021-09-17 09:41:2632 ChromeProcessSingleton(const ChromeProcessSingleton&) = delete;
33 ChromeProcessSingleton& operator=(const ChromeProcessSingleton&) = delete;
34
[email protected]9a47c432013-04-19 20:33:5535 ~ChromeProcessSingleton();
36
37 // Notify another process, if available. Otherwise sets ourselves as the
38 // singleton instance. Returns PROCESS_NONE if we became the singleton
39 // instance. Callers are guaranteed to either have notified an existing
40 // process or have grabbed the singleton (unless the profile is locked by an
41 // unreachable process).
42 ProcessSingleton::NotifyResult NotifyOtherProcessOrCreate();
43
44 // Clear any lock state during shutdown.
45 void Cleanup();
46
Greg Thompsoneafda51e2017-09-05 23:09:4547 // Receives a callback to be run to close the active modal dialog, or an empty
48 // closure if the active dialog is dismissed.
Alexander Cooper4bcb0ce2020-07-16 23:10:3849 void SetModalDialogNotificationHandler(
50 base::RepeatingClosure notification_handler);
[email protected]9a47c432013-04-19 20:33:5551
52 // Executes previously queued command-line invocations and allows future
53 // invocations to be executed immediately.
54 // This only has an effect the first time it is called.
55 void Unlock();
56
57 private:
58 // We compose these two locks with the client-supplied notification callback.
59 // First |modal_dialog_lock_| will discard any notifications that arrive while
60 // a modal dialog is active. Otherwise, it will pass the notification to
61 // |startup_lock_|, which will queue notifications until |Unlock()| is called.
62 // Notifications passing through both locks are finally delivered to our
63 // client.
64 ProcessSingletonStartupLock startup_lock_;
65 ProcessSingletonModalDialogLock modal_dialog_lock_;
66
67 // The basic ProcessSingleton
68 ProcessSingleton process_singleton_;
[email protected]9a47c432013-04-19 20:33:5569};
70
71#endif // CHROME_BROWSER_CHROME_PROCESS_SINGLETON_H_