OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 MOJO_SYSTEM_PLATFORM_CHANNEL_H_ | 5 #ifndef MOJO_SYSTEM_PLATFORM_CHANNEL_H_ |
6 #define MOJO_SYSTEM_PLATFORM_CHANNEL_H_ | 6 #define MOJO_SYSTEM_PLATFORM_CHANNEL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 }; | 40 }; |
41 | 41 |
42 class PlatformClientChannel; | 42 class PlatformClientChannel; |
43 | 43 |
44 // A server channel has an "implicit" client channel created with it. This may | 44 // A server channel has an "implicit" client channel created with it. This may |
45 // be a real channel (in the case of POSIX, in which case there's an actual FD | 45 // be a real channel (in the case of POSIX, in which case there's an actual FD |
46 // for it) or fake. | 46 // for it) or fake. |
47 // - That client channel may then be used in-process (e.g., for single process | 47 // - That client channel may then be used in-process (e.g., for single process |
48 // tests) by getting a |PlatformClientChannel| using |CreateClientChannel()|. | 48 // tests) by getting a |PlatformClientChannel| using |CreateClientChannel()|. |
49 // - Or it may be "passed" to a new child process using | 49 // - Or it may be "passed" to a new child process using |
50 // |PrepareToPassClientChannelToChildProcess()|, etc. (see below). The child | 50 // |GetDataNeededToPassClientChannelToChildProcess()|, etc. (see below). The |
51 // process would then get a |PlatformClientChannel| by using | 51 // child process would then get a |PlatformClientChannel| by using |
52 // |PlatformClientChannel::CreateFromParentProcess()|. | 52 // |PlatformClientChannel::CreateFromParentProcess()|. |
53 // - In both these cases, "ownership" of the client channel is transferred (to | 53 // - In both these cases, "ownership" of the client channel is transferred (to |
54 // the |PlatformClientChannel| or the child process). | 54 // the |PlatformClientChannel| or the child process). |
55 // TODO(vtl): Add ways of passing it to other existing processes. | 55 // TODO(vtl): Add ways of passing it to other existing processes. |
56 class MOJO_SYSTEM_EXPORT PlatformServerChannel : public PlatformChannel { | 56 class MOJO_SYSTEM_EXPORT PlatformServerChannel : public PlatformChannel { |
57 public: | 57 public: |
58 virtual ~PlatformServerChannel() {} | 58 virtual ~PlatformServerChannel() {} |
59 | 59 |
60 static scoped_ptr<PlatformServerChannel> Create(const std::string& name); | 60 static scoped_ptr<PlatformServerChannel> Create(const std::string& name); |
61 | 61 |
62 // For in-process use, from a server channel you can make a corresponding | 62 // For in-process use, from a server channel you can make a corresponding |
63 // client channel. | 63 // client channel. |
64 virtual scoped_ptr<PlatformClientChannel> CreateClientChannel() = 0; | 64 virtual scoped_ptr<PlatformClientChannel> CreateClientChannel() = 0; |
65 | 65 |
66 // Prepares to pass the client channel to a new child process, to be launched | 66 // Prepares to pass the client channel to a new child process, to be launched |
67 // using |LaunchProcess()| (from base/launch.h). Modifies |*command_line| and | 67 // using |LaunchProcess()| (from base/launch.h). Modifies |*command_line| and |
68 // |*file_handle_mapping| as needed. (|file_handle_mapping| may be null on | 68 // |*file_handle_mapping| as needed. (|file_handle_mapping| may be null on |
69 // platforms that don't need it, like Windows.) | 69 // platforms that don't need it, like Windows.) |
70 virtual void PrepareToPassClientChannelToChildProcess( | 70 virtual void GetDataNeededToPassClientChannelToChildProcess( |
71 CommandLine* command_line, | 71 CommandLine* command_line, |
72 base::FileHandleMappingVector* file_handle_mapping) = 0; | 72 base::FileHandleMappingVector* file_handle_mapping) const = 0; |
73 // To be called once the child process has been successfully launched, to do | 73 // To be called once the child process has been successfully launched, to do |
74 // any cleanup necessary. | 74 // any cleanup necessary. |
75 virtual void ChildProcessLaunched() = 0; | 75 virtual void ChildProcessLaunched() = 0; |
76 | 76 |
77 const std::string& name() const { return name_; } | 77 const std::string& name() const { return name_; } |
78 | 78 |
79 protected: | 79 protected: |
80 explicit PlatformServerChannel(const std::string& name); | 80 explicit PlatformServerChannel(const std::string& name); |
81 | 81 |
82 private: | 82 private: |
83 const std::string name_; | 83 const std::string name_; |
84 | 84 |
85 DISALLOW_COPY_AND_ASSIGN(PlatformServerChannel); | 85 DISALLOW_COPY_AND_ASSIGN(PlatformServerChannel); |
86 }; | 86 }; |
87 | 87 |
88 class MOJO_SYSTEM_EXPORT PlatformClientChannel : public PlatformChannel { | 88 class MOJO_SYSTEM_EXPORT PlatformClientChannel : public PlatformChannel { |
89 public: | 89 public: |
90 virtual ~PlatformClientChannel() {} | 90 virtual ~PlatformClientChannel() {} |
91 | 91 |
92 // Creates a client channel if you already have the underlying handle for it. | 92 // Creates a client channel if you already have the underlying handle for it. |
93 // Note: This takes ownership of |handle|. | 93 // Note: This takes ownership of |handle|. |
94 static scoped_ptr<PlatformClientChannel> CreateFromHandle( | 94 static scoped_ptr<PlatformClientChannel> CreateFromHandle( |
95 const PlatformChannelHandle& handle); | 95 const PlatformChannelHandle& handle); |
96 | 96 |
97 // To be called to get a client channel passed from the parent process, using | 97 // To be called to get a client channel passed from the parent process, using |
98 // |PlatformServerChannel::PrepareToPassClientChannelToChildProcess()|, etc. | 98 // |PlatformServerChannel::GetDataNeededToPassClientChannelToChildProcess()|, |
99 // Returns null on failure. | 99 // etc. Returns null on failure. |
100 static scoped_ptr<PlatformClientChannel> CreateFromParentProcess( | 100 static scoped_ptr<PlatformClientChannel> CreateFromParentProcess( |
101 const CommandLine& command_line); | 101 const CommandLine& command_line); |
102 | 102 |
103 private: | 103 private: |
104 PlatformClientChannel() {} | 104 PlatformClientChannel() {} |
105 | 105 |
106 DISALLOW_COPY_AND_ASSIGN(PlatformClientChannel); | 106 DISALLOW_COPY_AND_ASSIGN(PlatformClientChannel); |
107 }; | 107 }; |
108 | 108 |
109 } // namespace system | 109 } // namespace system |
110 } // namespace mojo | 110 } // namespace mojo |
111 | 111 |
112 #endif // MOJO_SYSTEM_PLATFORM_CHANNEL_H_ | 112 #endif // MOJO_SYSTEM_PLATFORM_CHANNEL_H_ |
OLD | NEW |