Backed out changeset b06f19b95b94 (bug 1784438) for causing build bustages CLOSED...
[gecko.git] / toolkit / components / remote / nsRemoteService.h
blob55d4adb6b77add923ce8cf34f6ea311ec41a5faa
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef TOOLKIT_COMPONENTS_REMOTE_NSREMOTESERVER_H_
9 #define TOOLKIT_COMPONENTS_REMOTE_NSREMOTESERVER_H_
11 #include "nsRemoteServer.h"
12 #include "nsIObserver.h"
13 #include "nsIRemoteService.h"
14 #include "mozilla/ThreadSafeWeakPtr.h"
15 #include "mozilla/UniquePtr.h"
16 #include "nsIFile.h"
17 #include "nsProfileLock.h"
18 #include "mozilla/MozPromise.h"
20 class nsStartupLock final
21 : public mozilla::SupportsThreadSafeWeakPtr<nsStartupLock> {
22 public:
23 MOZ_DECLARE_REFCOUNTED_TYPENAME(nsStartupLock)
24 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsStartupLock)
26 nsStartupLock(nsIFile* aDir, nsProfileLock& aLock);
28 private:
29 ~nsStartupLock();
31 nsCOMPtr<nsIFile> mDir;
32 nsProfileLock mLock;
35 class nsRemoteService final : public nsIObserver, public nsIRemoteService {
36 public:
37 // We will be a static singleton, so don't use the ordinary methods.
38 NS_DECL_ISUPPORTS
39 NS_DECL_NSIOBSERVER
40 NS_DECL_NSIREMOTESERVICE
42 nsRemoteService();
43 void SetProgram(const char* aProgram);
44 void SetProfile(nsACString& aProfile);
45 #ifdef MOZ_WIDGET_GTK
46 void SetStartupToken(nsACString& aStartupToken);
47 #endif
49 using StartupLockPromise =
50 mozilla::MozPromise<RefPtr<nsStartupLock>, nsresult, false>;
52 /**
53 * Attempts to asynchronously lock Firefox startup files. Resolves when the
54 * lock is acquired or the timeout is reached
56 * Locking is attempted by polling so if multiple instances are attempting to
57 * lock it is undefined which one will acquire it when it becomes available.
58 * If this instance already has the lock then this returns the same lock.
59 * The lock will be released once all instances of `nsStartupLock` have been
60 * released.
62 * Since this blocks the main thread it should only be called during startup.
64 RefPtr<StartupLockPromise> AsyncLockStartup(double aTimeout);
66 /**
67 * Attempts to synchronously lock startup files. Returns then the lock is
68 * acquired or a timeout is reached. In the event of a timeout or other
69 * failure a nullptr is returned. Since this blocks the main thread it should
70 * only be called during startup.
72 * Locking is attempted by polling so if multiple instances are attempting to
73 * lock it is undefined which one will acquire it when it becomes available.
74 * If this instance already has the lock then this returns the same lock.
75 * The lock will be released once all instances of `nsStartupLock` have been
76 * released.
78 already_AddRefed<nsStartupLock> LockStartup();
80 nsresult StartClient();
81 void StartupServer();
82 void ShutdownServer();
84 private:
85 friend nsStartupLock;
87 mozilla::ThreadSafeWeakPtr<nsStartupLock> mStartupLock;
88 RefPtr<nsRemoteService::StartupLockPromise> mStartupLockPromise;
90 ~nsRemoteService();
91 nsresult SendCommandLine(const nsACString& aProfile, size_t aArgc,
92 const char** aArgv, bool aRaise);
94 mozilla::UniquePtr<nsRemoteServer> mRemoteServer;
95 nsCString mProgram;
96 nsCString mProfile;
97 #ifdef MOZ_WIDGET_GTK
98 nsCString mStartupToken;
99 #endif
102 #endif // TOOLKIT_COMPONENTS_REMOTE_NSREMOTESERVER_H_