OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/files/file_path.h" | |
6 #include "base/logging.h" | |
7 #include "base/native_library.h" | |
8 #include "base/path_service.h" | |
9 #include "chrome/common/external_ipc_dumper.h" | |
10 | |
11 typedef IPC::ChannelProxy::OutgoingMessageFilter* (*GetFilterFunction)(); | |
12 typedef void (*SetDumpDirectoryFunction)(const base::FilePath&); | |
13 | |
14 const char kFilterEntryName[] = "GetFilter"; | |
15 const char kSetDumpDirectoryEntryName[] = "SetDumpDirectory"; | |
16 | |
17 #if defined(OS_WIN) | |
18 #define IPC_MESSAGE_DUMP_MODULE FILE_PATH_LITERAL("ipc_message_dump.dll") | |
19 #else | |
20 #define IPC_MESSAGE_DUMP_MODULE FILE_PATH_LITERAL("libipc_message_dump.so") | |
21 #endif | |
22 | |
23 IPC::ChannelProxy::OutgoingMessageFilter* LoadExternalIPCDumper( | |
24 const base::FilePath& dump_directory) { | |
25 IPC::ChannelProxy::OutgoingMessageFilter* result = NULL; | |
26 | |
27 base::FilePath module_path; | |
28 if (!PathService::Get(base::DIR_MODULE, &module_path)) { | |
29 LOG(ERROR) << "Unable to get message dump module directory."; | |
30 return result; | |
31 } | |
32 | |
33 base::FilePath library_path = module_path.Append(IPC_MESSAGE_DUMP_MODULE); | |
34 base::NativeLibraryLoadError load_error; | |
35 base::NativeLibrary library = | |
36 base::LoadNativeLibrary(library_path, &load_error); | |
37 | |
38 if (!library) { | |
39 LOG(ERROR) << load_error.ToString(); | |
40 return result; | |
41 } | |
42 | |
43 SetDumpDirectoryFunction set_directory_entry_point = | |
44 reinterpret_cast<SetDumpDirectoryFunction>( | |
45 base::GetFunctionPointerFromNativeLibrary( | |
46 library, kSetDumpDirectoryEntryName)); | |
47 if (set_directory_entry_point) | |
48 set_directory_entry_point(dump_directory); | |
49 else | |
50 LOG(ERROR) << kSetDumpDirectoryEntryName | |
inferno
2015/03/05 22:54:52
else needs { }. or better way is to follow the sam
| |
51 << " not exported by message dump module."; | |
52 | |
53 GetFilterFunction filter_entry_point = reinterpret_cast<GetFilterFunction>( | |
54 base::GetFunctionPointerFromNativeLibrary(library, kFilterEntryName)); | |
55 if (filter_entry_point) | |
56 result = filter_entry_point(); | |
57 else | |
58 LOG(ERROR) << kFilterEntryName << " not exported by message dump module."; | |
inferno
2015/03/05 22:54:52
or better way is to follow the same "if (!" and re
| |
59 | |
60 return result; | |
61 } | |
OLD | NEW |