1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
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"
17 #include "nsProfileLock.h"
18 #include "mozilla/MozPromise.h"
20 class nsStartupLock final
21 : public mozilla::SupportsThreadSafeWeakPtr
<nsStartupLock
> {
23 MOZ_DECLARE_REFCOUNTED_TYPENAME(nsStartupLock
)
24 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsStartupLock
)
26 nsStartupLock(nsIFile
* aDir
, nsProfileLock
& aLock
);
31 nsCOMPtr
<nsIFile
> mDir
;
35 class nsRemoteService final
: public nsIObserver
, public nsIRemoteService
{
37 // We will be a static singleton, so don't use the ordinary methods.
40 NS_DECL_NSIREMOTESERVICE
43 void SetProgram(const char* aProgram
);
44 void SetProfile(nsACString
& aProfile
);
46 void SetStartupToken(nsACString
& aStartupToken
);
49 using StartupLockPromise
=
50 mozilla::MozPromise
<RefPtr
<nsStartupLock
>, nsresult
, false>;
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
62 * Since this blocks the main thread it should only be called during startup.
64 RefPtr
<StartupLockPromise
> AsyncLockStartup(double aTimeout
);
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
78 already_AddRefed
<nsStartupLock
> LockStartup();
80 nsresult
StartClient();
82 void ShutdownServer();
87 mozilla::ThreadSafeWeakPtr
<nsStartupLock
> mStartupLock
;
88 RefPtr
<nsRemoteService::StartupLockPromise
> mStartupLockPromise
;
91 nsresult
SendCommandLine(const nsACString
& aProfile
, size_t aArgc
,
92 const char** aArgv
, bool aRaise
);
94 mozilla::UniquePtr
<nsRemoteServer
> mRemoteServer
;
98 nsCString mStartupToken
;
102 #endif // TOOLKIT_COMPONENTS_REMOTE_NSREMOTESERVER_H_