| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "base/memory/ptr_util.h" |
| 6 #include "base/process/process.h" | 7 #include "base/process/process.h" |
| 7 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 8 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 9 #include "ipc/ipc_channel_proxy.h" | 10 #include "ipc/ipc_channel_proxy.h" |
| 10 #include "tools/ipc_fuzzer/message_lib/message_file.h" | 11 #include "tools/ipc_fuzzer/message_lib/message_file.h" |
| 11 | 12 |
| 12 #if defined(OS_WIN) | 13 #if defined(OS_WIN) |
| 13 #define PidToStringType base::UintToString16 | 14 #define PidToStringType base::UintToString16 |
| 14 #define MESSAGE_DUMP_EXPORT __declspec(dllexport) | 15 #define MESSAGE_DUMP_EXPORT __declspec(dllexport) |
| 15 #else | 16 #else |
| 16 #define PidToStringType base::IntToString | 17 #define PidToStringType base::IntToString |
| 17 #define MESSAGE_DUMP_EXPORT __attribute__((visibility("default"))) | 18 #define MESSAGE_DUMP_EXPORT __attribute__((visibility("default"))) |
| 18 #endif | 19 #endif |
| 19 | 20 |
| 20 namespace ipc_fuzzer { | 21 namespace ipc_fuzzer { |
| 21 | 22 |
| 22 class IPCDump : public IPC::ChannelProxy::OutgoingMessageFilter { | 23 class IPCDump : public IPC::ChannelProxy::OutgoingMessageFilter { |
| 23 public: | 24 public: |
| 24 ~IPCDump() { | 25 ~IPCDump() { |
| 25 base::FilePath::StringType pid_string = | 26 base::FilePath::StringType pid_string = |
| 26 PidToStringType(base::Process::Current().Pid()); | 27 PidToStringType(base::Process::Current().Pid()); |
| 27 base::FilePath output_file_path = | 28 base::FilePath output_file_path = |
| 28 dump_directory().Append(pid_string + FILE_PATH_LITERAL(".ipcdump")); | 29 dump_directory().Append(pid_string + FILE_PATH_LITERAL(".ipcdump")); |
| 29 | 30 |
| 30 MessageFile::Write(output_file_path, messages_); | 31 MessageFile::Write(output_file_path, messages_); |
| 31 } | 32 } |
| 32 | 33 |
| 33 IPC::Message* Rewrite(IPC::Message* message) override { | 34 IPC::Message* Rewrite(IPC::Message* message) override { |
| 34 messages_.push_back(new IPC::Message(*message)); | 35 messages_.push_back(base::MakeUnique<IPC::Message>(*message)); |
| 35 return message; | 36 return message; |
| 36 } | 37 } |
| 37 | 38 |
| 38 base::FilePath dump_directory() const { return dump_directory_; } | 39 base::FilePath dump_directory() const { return dump_directory_; } |
| 39 | 40 |
| 40 void set_dump_directory(const base::FilePath& dump_directory) { | 41 void set_dump_directory(const base::FilePath& dump_directory) { |
| 41 dump_directory_ = dump_directory; | 42 dump_directory_ = dump_directory; |
| 42 } | 43 } |
| 43 | 44 |
| 44 private: | 45 private: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 56 MESSAGE_DUMP_EXPORT void SetDumpDirectory(const base::FilePath& dump_directory); | 57 MESSAGE_DUMP_EXPORT void SetDumpDirectory(const base::FilePath& dump_directory); |
| 57 } | 58 } |
| 58 | 59 |
| 59 IPC::ChannelProxy::OutgoingMessageFilter* GetFilter(void) { | 60 IPC::ChannelProxy::OutgoingMessageFilter* GetFilter(void) { |
| 60 return &ipc_fuzzer::g_ipcdump; | 61 return &ipc_fuzzer::g_ipcdump; |
| 61 } | 62 } |
| 62 | 63 |
| 63 void SetDumpDirectory(const base::FilePath& dump_directory) { | 64 void SetDumpDirectory(const base::FilePath& dump_directory) { |
| 64 ipc_fuzzer::g_ipcdump.set_dump_directory(dump_directory); | 65 ipc_fuzzer::g_ipcdump.set_dump_directory(dump_directory); |
| 65 } | 66 } |
| OLD | NEW |