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 #include "tools/ipc_fuzzer/message_replay/replay_process.h" | 5 #include "tools/ipc_fuzzer/message_replay/replay_process.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
| 8 |
8 #include <string> | 9 #include <string> |
| 10 #include <utility> |
9 | 11 |
10 #include "base/bind.h" | 12 #include "base/bind.h" |
11 #include "base/command_line.h" | 13 #include "base/command_line.h" |
12 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
13 #include "base/logging.h" | 15 #include "base/logging.h" |
14 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
15 #include "build/build_config.h" | 17 #include "build/build_config.h" |
16 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
17 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
18 #include "content/public/common/mojo_channel_switches.h" | 20 #include "content/public/common/mojo_channel_switches.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 switches::kIpcFuzzerTestcase); | 124 switches::kIpcFuzzerTestcase); |
123 return MessageFile::Read(path, &messages_); | 125 return MessageFile::Read(path, &messages_); |
124 } | 126 } |
125 | 127 |
126 void ReplayProcess::SendNextMessage() { | 128 void ReplayProcess::SendNextMessage() { |
127 if (message_index_ >= messages_.size()) { | 129 if (message_index_ >= messages_.size()) { |
128 base::MessageLoop::current()->QuitWhenIdle(); | 130 base::MessageLoop::current()->QuitWhenIdle(); |
129 return; | 131 return; |
130 } | 132 } |
131 | 133 |
132 // Take next message and release it from vector. | 134 std::unique_ptr<IPC::Message> message = |
133 IPC::Message* message = messages_[message_index_]; | 135 std::move(messages_[message_index_++]); |
134 messages_[message_index_++] = NULL; | |
135 | 136 |
136 if (!channel_->Send(message)) { | 137 if (!channel_->Send(message.release())) { |
137 LOG(ERROR) << "ChannelProxy::Send() failed after " | 138 LOG(ERROR) << "ChannelProxy::Send() failed after " |
138 << message_index_ << " messages"; | 139 << message_index_ << " messages"; |
139 base::MessageLoop::current()->QuitWhenIdle(); | 140 base::MessageLoop::current()->QuitWhenIdle(); |
140 } | 141 } |
141 } | 142 } |
142 | 143 |
143 void ReplayProcess::Run() { | 144 void ReplayProcess::Run() { |
144 timer_.reset(new base::Timer(false, true)); | 145 timer_.reset(new base::Timer(false, true)); |
145 timer_->Start(FROM_HERE, | 146 timer_->Start(FROM_HERE, |
146 base::TimeDelta::FromMilliseconds(1), | 147 base::TimeDelta::FromMilliseconds(1), |
147 base::Bind(&ReplayProcess::SendNextMessage, | 148 base::Bind(&ReplayProcess::SendNextMessage, |
148 base::Unretained(this))); | 149 base::Unretained(this))); |
149 base::RunLoop().Run(); | 150 base::RunLoop().Run(); |
150 } | 151 } |
151 | 152 |
152 bool ReplayProcess::OnMessageReceived(const IPC::Message& msg) { | 153 bool ReplayProcess::OnMessageReceived(const IPC::Message& msg) { |
153 return true; | 154 return true; |
154 } | 155 } |
155 | 156 |
156 void ReplayProcess::OnChannelError() { | 157 void ReplayProcess::OnChannelError() { |
157 LOG(ERROR) << "Channel error, quitting after " | 158 LOG(ERROR) << "Channel error, quitting after " |
158 << message_index_ << " messages"; | 159 << message_index_ << " messages"; |
159 base::MessageLoop::current()->QuitWhenIdle(); | 160 base::MessageLoop::current()->QuitWhenIdle(); |
160 } | 161 } |
161 | 162 |
162 } // namespace ipc_fuzzer | 163 } // namespace ipc_fuzzer |
OLD | NEW |