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/replay/replay_process.h" | 5 #include "tools/ipc_fuzzer/replay/replay_process.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <string> | 8 #include <string> |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 : io_thread_("Chrome_ChildIOThread"), | 21 : io_thread_("Chrome_ChildIOThread"), |
22 shutdown_event_(true, false), | 22 shutdown_event_(true, false), |
23 message_index_(0) { | 23 message_index_(0) { |
24 } | 24 } |
25 | 25 |
26 ReplayProcess::~ReplayProcess() { | 26 ReplayProcess::~ReplayProcess() { |
27 channel_.reset(); | 27 channel_.reset(); |
28 } | 28 } |
29 | 29 |
30 bool ReplayProcess::Initialize(int argc, const char** argv) { | 30 bool ReplayProcess::Initialize(int argc, const char** argv) { |
31 CommandLine::Init(argc, argv); | 31 base::CommandLine::Init(argc, argv); |
32 | 32 |
33 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 33 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
34 switches::kIpcFuzzerTestcase)) { | 34 switches::kIpcFuzzerTestcase)) { |
35 LOG(ERROR) << "This binary shouldn't be executed directly, " | 35 LOG(ERROR) << "This binary shouldn't be executed directly, " |
36 << "please use tools/ipc_fuzzer/play_testcase.py"; | 36 << "please use tools/ipc_fuzzer/play_testcase.py"; |
37 return false; | 37 return false; |
38 } | 38 } |
39 | 39 |
40 // Log to default destination. | 40 // Log to default destination. |
41 logging::SetMinLogLevel(logging::LOG_ERROR); | 41 logging::SetMinLogLevel(logging::LOG_ERROR); |
42 logging::InitLogging(logging::LoggingSettings()); | 42 logging::InitLogging(logging::LoggingSettings()); |
43 | 43 |
44 io_thread_.StartWithOptions( | 44 io_thread_.StartWithOptions( |
45 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 45 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
46 | 46 |
47 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); | 47 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); |
48 g_fds->Set(kPrimaryIPCChannel, | 48 g_fds->Set(kPrimaryIPCChannel, |
49 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); | 49 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); |
50 return true; | 50 return true; |
51 } | 51 } |
52 | 52 |
53 void ReplayProcess::OpenChannel() { | 53 void ReplayProcess::OpenChannel() { |
54 std::string channel_name = | 54 std::string channel_name = |
55 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 55 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
56 switches::kProcessChannelID); | 56 switches::kProcessChannelID); |
57 | 57 |
58 channel_ = IPC::ChannelProxy::Create(channel_name, | 58 channel_ = IPC::ChannelProxy::Create(channel_name, |
59 IPC::Channel::MODE_CLIENT, | 59 IPC::Channel::MODE_CLIENT, |
60 this, | 60 this, |
61 io_thread_.message_loop_proxy()); | 61 io_thread_.message_loop_proxy()); |
62 } | 62 } |
63 | 63 |
64 bool ReplayProcess::OpenTestcase() { | 64 bool ReplayProcess::OpenTestcase() { |
65 base::FilePath path = CommandLine::ForCurrentProcess()->GetSwitchValuePath( | 65 base::FilePath path = |
66 switches::kIpcFuzzerTestcase); | 66 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
| 67 switches::kIpcFuzzerTestcase); |
67 return MessageFile::Read(path, &messages_); | 68 return MessageFile::Read(path, &messages_); |
68 } | 69 } |
69 | 70 |
70 void ReplayProcess::SendNextMessage() { | 71 void ReplayProcess::SendNextMessage() { |
71 if (message_index_ >= messages_.size()) { | 72 if (message_index_ >= messages_.size()) { |
72 base::MessageLoop::current()->Quit(); | 73 base::MessageLoop::current()->Quit(); |
73 return; | 74 return; |
74 } | 75 } |
75 | 76 |
76 // Take next message and release it from vector. | 77 // Take next message and release it from vector. |
(...skipping 20 matching lines...) Expand all Loading... |
97 return true; | 98 return true; |
98 } | 99 } |
99 | 100 |
100 void ReplayProcess::OnChannelError() { | 101 void ReplayProcess::OnChannelError() { |
101 LOG(ERROR) << "Channel error, quitting after " | 102 LOG(ERROR) << "Channel error, quitting after " |
102 << message_index_ << " messages"; | 103 << message_index_ << " messages"; |
103 base::MessageLoop::current()->Quit(); | 104 base::MessageLoop::current()->Quit(); |
104 } | 105 } |
105 | 106 |
106 } // namespace ipc_fuzzer | 107 } // namespace ipc_fuzzer |
OLD | NEW |