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" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/posix/global_descriptors.h" | 13 #include "base/posix/global_descriptors.h" |
14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
15 #include "ipc/ipc_descriptors.h" | 15 #include "ipc/ipc_descriptors.h" |
16 #include "ipc/ipc_switches.h" | 16 #include "ipc/ipc_switches.h" |
17 | 17 |
18 namespace ipc_fuzzer { | 18 namespace ipc_fuzzer { |
19 | 19 |
20 ReplayProcess::ReplayProcess() | 20 ReplayProcess::ReplayProcess() |
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 |
| 29 // Signal this event before shutting down the service process. That way all |
| 30 // background threads can cleanup. |
| 31 shutdown_event_.Signal(); |
| 32 io_thread_.Stop(); |
28 } | 33 } |
29 | 34 |
30 bool ReplayProcess::Initialize(int argc, const char** argv) { | 35 bool ReplayProcess::Initialize(int argc, const char** argv) { |
31 base::CommandLine::Init(argc, argv); | 36 base::CommandLine::Init(argc, argv); |
32 | 37 |
33 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 38 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
34 switches::kIpcFuzzerTestcase)) { | 39 switches::kIpcFuzzerTestcase)) { |
35 LOG(ERROR) << "This binary shouldn't be executed directly, " | 40 LOG(ERROR) << "This binary shouldn't be executed directly, " |
36 << "please use tools/ipc_fuzzer/play_testcase.py"; | 41 << "please use tools/ipc_fuzzer/play_testcase.py"; |
37 return false; | 42 return false; |
38 } | 43 } |
39 | 44 |
40 // Log to default destination. | 45 // Log to default destination. |
41 logging::SetMinLogLevel(logging::LOG_ERROR); | 46 logging::SetMinLogLevel(logging::LOG_ERROR); |
42 logging::InitLogging(logging::LoggingSettings()); | 47 logging::InitLogging(logging::LoggingSettings()); |
43 | 48 |
44 io_thread_.StartWithOptions( | 49 io_thread_.StartWithOptions( |
45 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 50 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
46 | 51 |
| 52 #if defined(OS_POSIX) |
47 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); | 53 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); |
48 g_fds->Set(kPrimaryIPCChannel, | 54 g_fds->Set(kPrimaryIPCChannel, |
49 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); | 55 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); |
| 56 #endif |
| 57 |
50 return true; | 58 return true; |
51 } | 59 } |
52 | 60 |
53 void ReplayProcess::OpenChannel() { | 61 void ReplayProcess::OpenChannel() { |
54 std::string channel_name = | 62 std::string channel_name = |
55 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 63 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
56 switches::kProcessChannelID); | 64 switches::kProcessChannelID); |
57 | 65 |
58 channel_ = IPC::ChannelProxy::Create(channel_name, | 66 channel_ = IPC::ChannelProxy::Create(channel_name, |
59 IPC::Channel::MODE_CLIENT, | 67 IPC::Channel::MODE_CLIENT, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 return true; | 106 return true; |
99 } | 107 } |
100 | 108 |
101 void ReplayProcess::OnChannelError() { | 109 void ReplayProcess::OnChannelError() { |
102 LOG(ERROR) << "Channel error, quitting after " | 110 LOG(ERROR) << "Channel error, quitting after " |
103 << message_index_ << " messages"; | 111 << message_index_ << " messages"; |
104 base::MessageLoop::current()->Quit(); | 112 base::MessageLoop::current()->Quit(); |
105 } | 113 } |
106 | 114 |
107 } // namespace ipc_fuzzer | 115 } // namespace ipc_fuzzer |
OLD | NEW |