OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef IPC_IPC_CHANNEL_MOJO_HOST_H_ | 5 #ifndef IPC_IPC_CHANNEL_MOJO_HOST_H_ |
6 #define IPC_IPC_CHANNEL_MOJO_HOST_H_ | 6 #define IPC_IPC_CHANNEL_MOJO_HOST_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
11 #include "ipc/ipc_export.h" | 11 #include "ipc/ipc_export.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 class TaskRunner; | 14 class TaskRunner; |
15 } | 15 } |
16 | 16 |
17 namespace IPC { | 17 namespace IPC { |
18 | 18 |
19 class ChannelMojo; | 19 class ChannelMojo; |
20 | 20 |
21 // Through ChannelMojoHost, ChannelMojo gets extra information that | 21 // Through ChannelMojoHost, ChannelMojo gets extra information that |
22 // its client provides, including the child process's process handle. Every | 22 // its client provides, including the child process's process handle. Every |
23 // server process that uses ChannelMojo must have a ChannelMojoHost | 23 // server process that uses ChannelMojo must have a ChannelMojoHost |
24 // instance and call OnClientLaunched(). | 24 // instance and call OnClientLaunched(). |
25 // | |
26 // Thread safety: | |
27 // ChannelMojoHost is accessed from both UI thread (from its clients) | |
28 // and IO thread (from hosting channels). | |
29 // The public API including OnClientLaunched is available for UI thread, | |
30 // some API which touches |channel_| is safe only in IO thread. | |
viettrungluu
2014/09/25 19:38:34
You should explicitly say which things are I/O-thr
| |
31 // As its weak ptr is held by the hosting channel, clients should delete | |
32 // ChannelMojoHost in IO thread using ChannelMojoHostDeleter. | |
33 // | |
25 class IPC_MOJO_EXPORT ChannelMojoHost { | 34 class IPC_MOJO_EXPORT ChannelMojoHost { |
26 public: | 35 public: |
27 explicit ChannelMojoHost(scoped_refptr<base::TaskRunner> task_runner); | 36 explicit ChannelMojoHost(scoped_refptr<base::TaskRunner> task_runner); |
viettrungluu
2014/09/25 19:38:34
You should document what task runner this is (or m
Hajime Morrita
2014/09/25 22:00:04
Done.
| |
28 ~ChannelMojoHost(); | 37 ~ChannelMojoHost(); |
29 | 38 |
30 void OnClientLaunched(base::ProcessHandle process); | 39 void OnClientLaunched(base::ProcessHandle process); |
40 scoped_refptr<base::TaskRunner> task_runner() const { return task_runner_; } | |
viettrungluu
2014/09/25 19:38:34
Does this need to be public? Why?
Hajime Morrita
2014/09/25 22:00:03
Removed. Garbage made by try-n-error :-(
| |
31 | 41 |
32 private: | 42 private: |
33 friend class ChannelMojo; | 43 friend class ChannelMojo; |
44 friend class ChannelMojoHostDeleter; | |
34 | 45 |
35 void OnChannelCreated(ChannelMojo* channel); | 46 base::WeakPtr<ChannelMojoHost> ToWeakPtr(); |
36 void OnChannelDestroyed(); | 47 void OnChannelCreated(base::WeakPtr<ChannelMojo> channel); |
37 | 48 void DeleteThisSoon(); |
38 void InvokeOnClientLaunched(base::ProcessHandle process); | |
39 | 49 |
40 base::WeakPtrFactory<ChannelMojoHost> weak_factory_; | 50 base::WeakPtrFactory<ChannelMojoHost> weak_factory_; |
41 scoped_refptr<base::TaskRunner> task_runner_; | 51 scoped_refptr<base::TaskRunner> task_runner_; |
viettrungluu
2014/09/25 19:38:34
Can this be made const?
Hajime Morrita
2014/09/25 22:00:03
Done.
| |
42 ChannelMojo* channel_; | 52 base::WeakPtr<ChannelMojo> channel_; |
viettrungluu
2014/09/25 19:38:34
You should say that this should only be used on th
| |
43 | 53 |
44 DISALLOW_COPY_AND_ASSIGN(ChannelMojoHost); | 54 DISALLOW_COPY_AND_ASSIGN(ChannelMojoHost); |
45 }; | 55 }; |
46 | 56 |
57 // Specialized to post the deletion to the ChannelMojoHost::task_runner() | |
58 // thread. | |
59 // This is needed as IPC::ChannelMojo touches its host when it dies. | |
60 class IPC_MOJO_EXPORT ChannelMojoHostDeleter { | |
61 public: | |
62 void operator()(IPC::ChannelMojoHost* ptr) const; | |
63 }; | |
64 | |
47 } // namespace IPC | 65 } // namespace IPC |
48 | 66 |
49 #endif // IPC_IPC_CHANNEL_MOJO_HOST_H_ | 67 #endif // IPC_IPC_CHANNEL_MOJO_HOST_H_ |
OLD | NEW |