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 #include "mojo/spy/spy.h" | 5 #include "mojo/spy/spy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 handle_count_[0] = 0; | 43 handle_count_[0] = 0; |
44 handle_count_[1] = 0; | 44 handle_count_[1] = 0; |
45 } | 45 } |
46 | 46 |
47 void Start(mojo::ScopedMessagePipeHandle client, | 47 void Start(mojo::ScopedMessagePipeHandle client, |
48 mojo::ScopedMessagePipeHandle interceptor) { | 48 mojo::ScopedMessagePipeHandle interceptor) { |
49 std::vector<mojo::MessagePipeHandle> pipes; | 49 std::vector<mojo::MessagePipeHandle> pipes; |
50 pipes.push_back(client.get()); | 50 pipes.push_back(client.get()); |
51 pipes.push_back(interceptor.get()); | 51 pipes.push_back(interceptor.get()); |
52 std::vector<MojoHandleSignals> handle_signals; | 52 std::vector<MojoHandleSignals> handle_signals; |
53 handle_signals.push_back(MOJO_WAIT_FLAG_READABLE); | 53 handle_signals.push_back(MOJO_HANDLE_SIGNAL_READABLE); |
54 handle_signals.push_back(MOJO_WAIT_FLAG_READABLE); | 54 handle_signals.push_back(MOJO_HANDLE_SIGNAL_READABLE); |
55 | 55 |
56 scoped_ptr<char[]> mbuf(new char[kMessageBufSize]); | 56 scoped_ptr<char[]> mbuf(new char[kMessageBufSize]); |
57 scoped_ptr<MojoHandle[]> hbuf(new MojoHandle[kHandleBufSize]); | 57 scoped_ptr<MojoHandle[]> hbuf(new MojoHandle[kHandleBufSize]); |
58 | 58 |
59 // Main processing loop: | 59 // Main processing loop: |
60 // 1- Wait for an endpoint to have a message. | 60 // 1- Wait for an endpoint to have a message. |
61 // 2- Read the message | 61 // 2- Read the message |
62 // 3- Log data | 62 // 3- Log data |
63 // 4- Wait until the opposite port is ready for writting | 63 // 4- Wait until the opposite port is ready for writting |
64 // 4- Write the message to opposite port. | 64 // 4- Write the message to opposite port. |
(...skipping 18 matching lines...) Expand all Loading... |
83 continue; | 83 continue; |
84 | 84 |
85 if (handles_read) | 85 if (handles_read) |
86 handle_count_[r] += handles_read; | 86 handle_count_[r] += handles_read; |
87 | 87 |
88 ++message_count_[r]; | 88 ++message_count_[r]; |
89 bytes_transfered_ += bytes_read; | 89 bytes_transfered_ += bytes_read; |
90 | 90 |
91 mojo::MessagePipeHandle write_handle = (r == 0) ? pipes[1] : pipes[0]; | 91 mojo::MessagePipeHandle write_handle = (r == 0) ? pipes[1] : pipes[0]; |
92 if (!CheckResult(Wait(write_handle, | 92 if (!CheckResult(Wait(write_handle, |
93 MOJO_WAIT_FLAG_WRITABLE, | 93 MOJO_HANDLE_SIGNAL_WRITABLE, |
94 MOJO_DEADLINE_INDEFINITE))) | 94 MOJO_DEADLINE_INDEFINITE))) |
95 break; | 95 break; |
96 | 96 |
97 if (!CheckResult(WriteMessageRaw(write_handle, | 97 if (!CheckResult(WriteMessageRaw(write_handle, |
98 mbuf.get(), bytes_read, | 98 mbuf.get(), bytes_read, |
99 hbuf.get(), handles_read, | 99 hbuf.get(), handles_read, |
100 MOJO_WRITE_MESSAGE_FLAG_NONE))) { | 100 MOJO_WRITE_MESSAGE_FLAG_NONE))) { |
101 // On failure we own the handles. For now just close them. | 101 // On failure we own the handles. For now just close them. |
102 if (handles_read) | 102 if (handles_read) |
103 CloseHandles(hbuf.get(), handles_read); | 103 CloseHandles(hbuf.get(), handles_read); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 // Start intercepting mojo services. | 206 // Start intercepting mojo services. |
207 service_manager->SetInterceptor(new SpyInterceptor()); | 207 service_manager->SetInterceptor(new SpyInterceptor()); |
208 } | 208 } |
209 | 209 |
210 Spy::~Spy(){ | 210 Spy::~Spy(){ |
211 // TODO(cpu): Do not leak the interceptor. Lifetime between the | 211 // TODO(cpu): Do not leak the interceptor. Lifetime between the |
212 // service_manager and the spy is still unclear hence the leak. | 212 // service_manager and the spy is still unclear hence the leak. |
213 } | 213 } |
214 | 214 |
215 } // namespace mojo | 215 } // namespace mojo |
OLD | NEW |