Chromium Code Reviews| Index: chrome/common/external_ipc_dumper.cc |
| diff --git a/chrome/common/external_ipc_dumper.cc b/chrome/common/external_ipc_dumper.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fb2be047483d26862454c35187a1f68867d0d50b |
| --- /dev/null |
| +++ b/chrome/common/external_ipc_dumper.cc |
| @@ -0,0 +1,54 @@ |
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/files/file_path.h" |
| +#include "base/logging.h" |
| +#include "base/native_library.h" |
| +#include "base/path_service.h" |
| +#include "chrome/common/external_ipc_dumper.h" |
| + |
| +typedef IPC::ChannelProxy::OutgoingMessageFilter* (*GetFilterFunction)(); |
| +typedef void (*SetDumpDirectoryFunction)(const base::FilePath&); |
| +const char kSetDumpDirectoryEntryName[] = "SetDumpDirectory"; |
|
inferno
2015/03/05 22:11:59
newline before this line.
inferno
2015/03/05 22:11:59
this line should come after kFilterEntryName.
|
| +const char kFilterEntryName[] = "GetFilter"; |
| +#if defined(OS_WIN) |
|
inferno
2015/03/05 22:11:59
newline before this line.
|
| +#define LIBRARY_NAME FILE_PATH_LITERAL("ipc_message_dump.dll") |
|
inferno
2015/03/05 22:11:59
s/LIBRARY_NAME/IPC_MESSAGE_DUMP_MODULE/LIB/similar
|
| +#else |
| +#define LIBRARY_NAME FILE_PATH_LITERAL("libipc_message_dump.so") |
| +#endif |
| + |
| +IPC::ChannelProxy::OutgoingMessageFilter* LoadExternalIPCDumper( |
| + const base::FilePath& dump_directory) { |
| + IPC::ChannelProxy::OutgoingMessageFilter* result = NULL; |
| + |
| + base::FilePath module_path; |
| + if (!PathService::Get(base::DIR_MODULE, &module_path)) { |
| + LOG(ERROR) << "PathService::Get failed."; |
|
inferno
2015/03/05 22:11:59
Too cryptic error message. Something like "Ipc dum
|
| + return result; |
| + } |
| + |
| + base::FilePath library_path = module_path.Append(LIBRARY_NAME); |
| + base::NativeLibraryLoadError load_error; |
| + base::NativeLibrary library = |
| + base::LoadNativeLibrary(library_path, &load_error); |
| + |
| + if (!library) { |
| + LOG(ERROR) << load_error.ToString(); |
| + return result; |
| + } |
| + |
| + SetDumpDirectoryFunction set_directory_entry_point = |
| + reinterpret_cast<SetDumpDirectoryFunction>( |
| + base::GetFunctionPointerFromNativeLibrary( |
| + library, kSetDumpDirectoryEntryName)); |
| + if (set_directory_entry_point) |
| + set_directory_entry_point(dump_directory); |
|
inferno
2015/03/05 22:11:59
Should be LOG(ERROR) on failures for line 45 and l
|
| + |
| + GetFilterFunction filter_entry_point = reinterpret_cast<GetFilterFunction>( |
| + base::GetFunctionPointerFromNativeLibrary(library, kFilterEntryName)); |
| + if (filter_entry_point) |
| + result = filter_entry_point(); |
| + |
| + return result; |
| +} |