Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_plugins_MiniShmParent_h
8 #define mozilla_plugins_MiniShmParent_h
10 #include "MiniShmBase.h"
12 #include <string>
14 namespace mozilla {
15 namespace plugins {
17 /**
18 * This class provides a lightweight shared memory interface for a parent
19 * process in Win32.
20 * This code assumes that there is a parent-child relationship between
21 * processes, as it creates inheritable handles.
22 * Note that this class is *not* an IPDL actor.
23 *
24 * @see MiniShmChild
25 */
26 class MiniShmParent : public MiniShmBase
27 {
28 public:
29 MiniShmParent();
30 virtual ~MiniShmParent();
32 static const unsigned int kDefaultMiniShmSectionSize;
34 /**
35 * Initialize shared memory on the parent side.
36 *
37 * @param aObserver A MiniShmObserver object to receive event notifications.
38 * @param aTimeout Timeout in milliseconds.
39 * @param aSectionSize Desired size of the shared memory section. This is
40 * expected to be a multiple of 0x1000 (4KiB).
41 * @return nsresult error code
42 */
43 nsresult
44 Init(MiniShmObserver* aObserver, const DWORD aTimeout,
45 const unsigned int aSectionSize = kDefaultMiniShmSectionSize);
47 /**
48 * Destroys the shared memory section. Useful to explicitly release
49 * resources if it is known that they won't be needed again.
50 */
51 void
52 CleanUp();
54 /**
55 * Provides a cookie string that should be passed to MiniShmChild
56 * during its initialization.
57 *
58 * @param aCookie A std::wstring variable to receive the cookie.
59 * @return nsresult error code
60 */
61 nsresult
62 GetCookie(std::wstring& aCookie);
64 virtual nsresult
65 Send() MOZ_OVERRIDE;
67 bool
68 IsConnected() const;
70 protected:
71 void
72 OnEvent() MOZ_OVERRIDE;
74 private:
75 void
76 FinalizeConnection();
78 unsigned int mSectionSize;
79 HANDLE mParentEvent;
80 HANDLE mParentGuard;
81 HANDLE mChildEvent;
82 HANDLE mChildGuard;
83 HANDLE mRegWait;
84 HANDLE mFileMapping;
85 LPVOID mView;
86 bool mIsConnected;
87 DWORD mTimeout;
89 DISALLOW_COPY_AND_ASSIGN(MiniShmParent);
90 };
92 } // namespace plugins
93 } // namespace mozilla
95 #endif // mozilla_plugins_MiniShmParent_h