Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: ipc/mojo/ipc_mojo_bootstrap.h

Issue 553283002: IPC::ChannelMojo: Introduce IPC::MojoBootstrap for Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef IPC_MOJO_IPC_MOJO_BOOTSTRAP_H_
6 #define IPC_MOJO_IPC_MOJO_BOOTSTRAP_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "base/process/process_handle.h"
10 #include "ipc/ipc_channel.h"
11 #include "ipc/ipc_listener.h"
12 #include "mojo/embedder/scoped_platform_handle.h"
13
14 namespace IPC {
15
16 // MojoBootstrap establishes a bootstrap pipe between two processes in
17 // Chrome. It creates a native IPC::Channel first, then sends one
18 // side of a newly created pipe to peer process. The pipe is intended
19 // to be wrapped by Mojo MessagePipe.
20 //
21 // Clients should implement MojoBootstrapDelegate to get the pipe
22 // from MojoBootstrap object. It should also tell the client process handle
23 // using OnClientLaunched().
24 class IPC_MOJO_EXPORT MojoBootstrap : public Listener {
25 public:
26 class Delegate {
27 public:
28 virtual void OnPipeAvailable(
29 mojo::embedder::ScopedPlatformHandle handle) = 0;
30 virtual void OnBootstrapError() = 0;
31 };
32
33 // Create the MojoBootstrap instance.
34 // Instead of creating IPC::Channel, passs its ChannelHandle as |handle|,
35 // mode as |mode|. The result is notified to passed |delegate|.
36 static scoped_ptr<MojoBootstrap> Create(ChannelHandle handle,
37 Channel::Mode mode,
38 Delegate* delegate);
39
40 MojoBootstrap();
41 virtual ~MojoBootstrap();
42
43 // Start the handshake over the underlying platform channel.
44 bool Connect();
45
46 // Each client should call this once the process handle becomes known.
47 virtual void OnClientLaunched(base::ProcessHandle process) = 0;
48
49 #if defined(OS_POSIX) && !defined(OS_NACL)
50 int GetClientFileDescriptor() const;
51 int TakeClientFileDescriptor();
52 #endif // defined(OS_POSIX) && !defined(OS_NACL)
53
54 protected:
55 enum State { STATE_INITIALIZED, STATE_WAITING_ACK, STATE_READY };
56
57 Delegate* delegate() const { return delegate_; }
58 bool Send(Message* message);
59
60 State state() const { return state_; }
61 void set_state(State state) { state_ = state; }
62
63 private:
64 void Init(scoped_ptr<Channel> channel, Delegate* delegate);
65
66 // Listener implementations
67 virtual void OnBadMessageReceived(const Message& message) OVERRIDE;
68 virtual void OnChannelError() OVERRIDE;
69
70 scoped_ptr<Channel> channel_;
71 Delegate* delegate_;
72 State state_;
73
74 DISALLOW_COPY_AND_ASSIGN(MojoBootstrap);
75 };
76
77 } // namespace IPC
78
79 #endif // IPC_MOJO_IPC_MOJO_BOOTSTRAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698