Blink roll 148954:148987
[chromium-blink-merge.git] / chrome_frame / pin_module.cc
blobb4cebbe2674a9169d1766e84c82b5dc565600f93
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
3 // found in the LICENSE file.
5 #include "chrome_frame/pin_module.h"
7 #include <windows.h>
9 #include "base/logging.h"
10 #include "chrome_frame/utils.h"
12 extern "C" IMAGE_DOS_HEADER __ImageBase;
14 namespace chrome_frame {
16 namespace {
18 PinModuleCallbackFn g_pin_module_callback = NULL;
20 } // namespace
22 void SetPinModuleCallback(PinModuleCallbackFn callback) {
23 g_pin_module_callback = callback;
26 void PinModule() {
27 static bool s_pinned = false;
28 if (!s_pinned && !IsUnpinnedMode()) {
29 wchar_t system_buffer[MAX_PATH];
30 HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase);
31 system_buffer[0] = 0;
32 if (GetModuleFileName(this_module, system_buffer,
33 arraysize(system_buffer)) != 0) {
34 HMODULE unused;
35 if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_PIN, system_buffer,
36 &unused)) {
37 DPLOG(FATAL) << "Failed to pin module " << system_buffer;
38 } else {
39 s_pinned = true;
40 if (g_pin_module_callback)
41 g_pin_module_callback();
43 } else {
44 DPLOG(FATAL) << "Could not get module path.";
49 } // namespace chrome_frame