blob: 71df237770433ce96d19335d254322995c36cf1c [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
[email protected]9a47c432013-04-19 20:33:5533 ~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 Thompsoneafda51e2017-09-05 23:09:4545 // 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]9a47c432013-04-19 20:33:5548
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_;
62 ProcessSingletonModalDialogLock modal_dialog_lock_;
63
64 // The basic ProcessSingleton
65 ProcessSingleton process_singleton_;
66
67 DISALLOW_COPY_AND_ASSIGN(ChromeProcessSingleton);
68};
69
70#endif // CHROME_BROWSER_CHROME_PROCESS_SINGLETON_H_