Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / common / external_ipc_dumper.cc
blob3b9bbbbfc5c04dd4a7b0ae039c9a904a37fca7fe
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.
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"
11 typedef IPC::ChannelProxy::OutgoingMessageFilter* (*GetFilterFunction)();
12 typedef void (*SetDumpDirectoryFunction)(const base::FilePath&);
14 const char kFilterEntryName[] = "GetFilter";
15 const char kSetDumpDirectoryEntryName[] = "SetDumpDirectory";
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
23 IPC::ChannelProxy::OutgoingMessageFilter* LoadExternalIPCDumper(
24 const base::FilePath& dump_directory) {
25 base::FilePath module_path;
26 if (!PathService::Get(base::DIR_MODULE, &module_path)) {
27 LOG(ERROR) << "Unable to get message dump module directory.";
28 return NULL;
31 base::FilePath library_path = module_path.Append(IPC_MESSAGE_DUMP_MODULE);
32 base::NativeLibraryLoadError load_error;
33 base::NativeLibrary library =
34 base::LoadNativeLibrary(library_path, &load_error);
36 if (!library) {
37 LOG(ERROR) << load_error.ToString();
38 return NULL;
41 SetDumpDirectoryFunction set_directory_entry_point =
42 reinterpret_cast<SetDumpDirectoryFunction>(
43 base::GetFunctionPointerFromNativeLibrary(
44 library, kSetDumpDirectoryEntryName));
45 if (!set_directory_entry_point) {
46 LOG(ERROR) << kSetDumpDirectoryEntryName
47 << " not exported by message dump module.";
48 return NULL;
50 set_directory_entry_point(dump_directory);
52 GetFilterFunction filter_entry_point = reinterpret_cast<GetFilterFunction>(
53 base::GetFunctionPointerFromNativeLibrary(library, kFilterEntryName));
54 if (!filter_entry_point) {
55 LOG(ERROR) << kFilterEntryName << " not exported by message dump module.";
56 return NULL;
59 return filter_entry_point();