ipc/glue/BackgroundParent.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/glue/BackgroundParent.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,83 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef mozilla_ipc_backgroundparent_h__
     1.9 +#define mozilla_ipc_backgroundparent_h__
    1.10 +
    1.11 +#include "base/process.h"
    1.12 +#include "mozilla/Attributes.h"
    1.13 +#include "mozilla/ipc/Transport.h"
    1.14 +
    1.15 +template <class> class already_AddRefed;
    1.16 +
    1.17 +namespace mozilla {
    1.18 +namespace dom {
    1.19 +
    1.20 +class ContentParent;
    1.21 +
    1.22 +} // namespace dom
    1.23 +
    1.24 +namespace ipc {
    1.25 +
    1.26 +class PBackgroundParent;
    1.27 +
    1.28 +// This class is not designed for public consumption beyond the few static
    1.29 +// member functions.
    1.30 +class BackgroundParent MOZ_FINAL
    1.31 +{
    1.32 +  friend class mozilla::dom::ContentParent;
    1.33 +
    1.34 +  typedef base::ProcessId ProcessId;
    1.35 +  typedef mozilla::dom::ContentParent ContentParent;
    1.36 +  typedef mozilla::ipc::Transport Transport;
    1.37 +
    1.38 +public:
    1.39 +  // This function allows the caller to determine if the given parent actor
    1.40 +  // corresponds to a child actor from another process or a child actor from a
    1.41 +  // different thread in the same process.
    1.42 +  // This function may only be called on the background thread.
    1.43 +  static bool
    1.44 +  IsOtherProcessActor(PBackgroundParent* aBackgroundActor);
    1.45 +
    1.46 +  // This function returns the ContentParent associated with the parent actor if
    1.47 +  // the parent actor corresponds to a child actor from another process. If the
    1.48 +  // parent actor corresponds to a child actor from a different thread in the
    1.49 +  // same process then this function returns null.
    1.50 +  // This function may only be called on the background thread. However,
    1.51 +  // ContentParent is not threadsafe and the returned pointer may not be used on
    1.52 +  // any thread other than the main thread. Callers must take care to use (and
    1.53 +  // release) the returned pointer appropriately.
    1.54 +  static already_AddRefed<ContentParent>
    1.55 +  GetContentParent(PBackgroundParent* aBackgroundActor);
    1.56 +
    1.57 +private:
    1.58 +  // Only called by ContentParent for cross-process actors.
    1.59 +  static PBackgroundParent*
    1.60 +  Alloc(ContentParent* aContent,
    1.61 +        Transport* aTransport,
    1.62 +        ProcessId aOtherProcess);
    1.63 +};
    1.64 +
    1.65 +// Implemented in BackgroundImpl.cpp.
    1.66 +bool
    1.67 +IsOnBackgroundThread();
    1.68 +
    1.69 +#ifdef DEBUG
    1.70 +
    1.71 +// Implemented in BackgroundImpl.cpp.
    1.72 +void
    1.73 +AssertIsOnBackgroundThread();
    1.74 +
    1.75 +#else
    1.76 +
    1.77 +inline void
    1.78 +AssertIsOnBackgroundThread()
    1.79 +{ }
    1.80 +
    1.81 +#endif // DEBUG
    1.82 +
    1.83 +} // namespace ipc
    1.84 +} // namespace mozilla
    1.85 +
    1.86 +#endif // mozilla_ipc_backgroundparent_h__

mercurial