OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 MOJO_EDK_SYSTEM_PARENT_TOKEN_SERIALIZER_STATE_WIN_H_ | |
6 #define MOJO_EDK_SYSTEM_PARENT_TOKEN_SERIALIZER_STATE_WIN_H_ | |
7 | |
8 #include "base/compiler_specific.h" | |
9 #include "base/containers/hash_tables.h" | |
10 #include "base/memory/singleton.h" | |
11 #include "base/synchronization/lock.h" | |
12 #include "base/threading/thread.h" | |
13 #include "mojo/edk/embedder/scoped_platform_handle.h" | |
14 #include "mojo/edk/system/system_impl_export.h" | |
15 #include "mojo/edk/system/token_serializer_win.h" | |
16 | |
17 namespace mojo { | |
18 namespace edk { | |
19 | |
20 // Common state that has to live in a parent process on Windows. There is one | |
21 // instance of this class in the parent process. This class also implements the | |
22 // TokenSerializer interface for use by code in the parent process. | |
23 class MOJO_SYSTEM_IMPL_EXPORT ParentTokenSerializerState | |
24 : NON_EXPORTED_BASE(public TokenSerializer) { | |
25 public: | |
26 static ParentTokenSerializerState* GetInstance(); | |
27 | |
28 // TokenSerializer implementation. | |
29 void CreatePlatformChannelPair(ScopedPlatformHandle* server, | |
30 ScopedPlatformHandle* client) override; | |
31 void HandleToToken(const PlatformHandle* platform_handles, | |
32 size_t count, | |
33 uint64_t* tokens) override; | |
34 void TokenToHandle(const uint64_t* tokens, | |
35 size_t count, | |
36 PlatformHandle* handles) override; | |
37 | |
38 scoped_refptr<base::TaskRunner> token_serialize_thread() { | |
39 return token_serialize_thread_.task_runner(); | |
40 } | |
41 | |
42 private: | |
43 friend struct base::DefaultSingletonTraits<ParentTokenSerializerState>; | |
44 | |
45 ParentTokenSerializerState(); | |
46 ~ParentTokenSerializerState() override; | |
47 | |
48 // A separate thread to handle sync IPCs from child processes for exchanging | |
49 // platform handles with tokens. We use a separate thread because latency is | |
50 // very sensitive (since any time a pipe is created or sent, a child process | |
51 // makes a sync call to this class). | |
52 base::Thread token_serialize_thread_; | |
53 | |
54 // Used in the parent (unsandboxed) process to hold a mapping between HANDLES | |
55 // and tokens. When a child process wants to send a HANDLE to another process, | |
56 // it exchanges it to a token and then the other process exchanges that token | |
57 // back to a HANDLE. | |
58 base::Lock lock_; // Guards access to below. | |
59 base::hash_map<uint64_t, HANDLE> token_map_; | |
60 }; | |
61 | |
62 } // namespace edk | |
63 } // namespace mojo | |
64 | |
65 #endif // MOJO_EDK_SYSTEM_PARENT_TOKEN_SERIALIZER_STATE_WIN_H_ | |
OLD | NEW |