blob: 7f330289608e15ce3ea0db2380994541e16c0f32 [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).
Peter Kvitekb95e2232021-12-10 00:40:0842 // The guarantee is a bit different if we're running in Native Headless mode,
43 // in which case an existing process is not notified and this method returns
44 // PROFILE_IN_USE if it happens to use the same profile directory.
[email protected]9a47c432013-04-19 20:33:5545 ProcessSingleton::NotifyResult NotifyOtherProcessOrCreate();
46
47 // Clear any lock state during shutdown.
48 void Cleanup();
49
Greg Thompsoneafda51e2017-09-05 23:09:4550 // Receives a callback to be run to close the active modal dialog, or an empty
51 // closure if the active dialog is dismissed.
Alexander Cooper4bcb0ce2020-07-16 23:10:3852 void SetModalDialogNotificationHandler(
53 base::RepeatingClosure notification_handler);
[email protected]9a47c432013-04-19 20:33:5554
55 // Executes previously queued command-line invocations and allows future
56 // invocations to be executed immediately.
57 // This only has an effect the first time it is called.
58 void Unlock();
59
60 private:
61 // We compose these two locks with the client-supplied notification callback.
62 // First |modal_dialog_lock_| will discard any notifications that arrive while
63 // a modal dialog is active. Otherwise, it will pass the notification to
64 // |startup_lock_|, which will queue notifications until |Unlock()| is called.
65 // Notifications passing through both locks are finally delivered to our
66 // client.
67 ProcessSingletonStartupLock startup_lock_;
68 ProcessSingletonModalDialogLock modal_dialog_lock_;
69
70 // The basic ProcessSingleton
71 ProcessSingleton process_singleton_;
[email protected]9a47c432013-04-19 20:33:5572};
73
74#endif // CHROME_BROWSER_CHROME_PROCESS_SINGLETON_H_