blob: 72914c9f681abcc220f687fd5d1aeb2b2bf223a4 [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"
avie4d7b6f2015-12-26 00:59:1810#include "base/macros.h"
[email protected]9a47c432013-04-19 20:33:5511#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]9a47c432013-04-19 20:33:5514
15// Composes a basic ProcessSingleton with ProcessSingletonStartupLock and
16// ProcessSingletonModalDialogLock.
17//
Greg Thompsoneafda51e2017-09-05 23:09:4518// 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]9a47c432013-04-19 20:33:5521// NotificationCallback.
22//
Greg Thompsoneafda51e2017-09-05 23:09:4523// 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]9a47c432013-04-19 20:33:5527class ChromeProcessSingleton {
28 public:
29 ChromeProcessSingleton(
30 const base::FilePath& user_data_dir,
31 const ProcessSingleton::NotificationCallback& notification_callback);
32
Peter Boström53c6c5952021-09-17 09:41:2633 ChromeProcessSingleton(const ChromeProcessSingleton&) = delete;
34 ChromeProcessSingleton& operator=(const ChromeProcessSingleton&) = delete;
35
[email protected]9a47c432013-04-19 20:33:5536 ~ChromeProcessSingleton();
37
38 // Notify another process, if available. Otherwise sets ourselves as the
39 // singleton instance. Returns PROCESS_NONE if we became the singleton
40 // instance. Callers are guaranteed to either have notified an existing
41 // process or have grabbed the singleton (unless the profile is locked by an
42 // unreachable process).
43 ProcessSingleton::NotifyResult NotifyOtherProcessOrCreate();
44
45 // Clear any lock state during shutdown.
46 void Cleanup();
47
Greg Thompsoneafda51e2017-09-05 23:09:4548 // Receives a callback to be run to close the active modal dialog, or an empty
49 // closure if the active dialog is dismissed.
Alexander Cooper4bcb0ce2020-07-16 23:10:3850 void SetModalDialogNotificationHandler(
51 base::RepeatingClosure notification_handler);
[email protected]9a47c432013-04-19 20:33:5552
53 // Executes previously queued command-line invocations and allows future
54 // invocations to be executed immediately.
55 // This only has an effect the first time it is called.
56 void Unlock();
57
58 private:
59 // We compose these two locks with the client-supplied notification callback.
60 // First |modal_dialog_lock_| will discard any notifications that arrive while
61 // a modal dialog is active. Otherwise, it will pass the notification to
62 // |startup_lock_|, which will queue notifications until |Unlock()| is called.
63 // Notifications passing through both locks are finally delivered to our
64 // client.
65 ProcessSingletonStartupLock startup_lock_;
66 ProcessSingletonModalDialogLock modal_dialog_lock_;
67
68 // The basic ProcessSingleton
69 ProcessSingleton process_singleton_;
[email protected]9a47c432013-04-19 20:33:5570};
71
72#endif // CHROME_BROWSER_CHROME_PROCESS_SINGLETON_H_