Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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 #include "metro_driver_win.h" | |
|
darin (slow to review)
2012/03/19 16:30:45
nit: new line above here
| |
| 5 | |
| 6 #include <windows.h> | |
|
darin (slow to review)
2012/03/19 16:30:45
nit: already have this include from the header fil
| |
| 7 | |
| 8 namespace { | |
| 9 // The windows 8 metro driver dll name and entry point. | |
| 10 const char kMetroDriverDll[] = "metro_driver.dll"; | |
| 11 typedef int (*InitMetro)(LPTHREAD_START_ROUTINE thread_proc, void* context); | |
|
darin (slow to review)
2012/03/19 16:30:45
nit: recommend placing typedef apart from the cons
| |
| 12 // This environment variable controls the loading of the metro driver DLL. | |
| 13 const char* kMetroModeEnvVar = "CHROME_METRO_DLL"; | |
| 14 | |
| 15 struct Context { | |
| 16 MainFn fn; | |
| 17 HINSTANCE instance; | |
| 18 }; | |
| 19 | |
| 20 DWORD WINAPI MainThread(void* param) { | |
| 21 Context* context = reinterpret_cast<Context*>(param); | |
| 22 int rv = context->fn(context->instance); | |
| 23 delete context; | |
| 24 return rv; | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 MetroDriver::MetroDriver() : init_metro_fn_(NULL) { | |
| 30 if (0 != ::GetEnvironmentVariableA(kMetroModeEnvVar, NULL, 0)) | |
| 31 return; | |
| 32 // We haven't tried to load the metro driver, this probably means we are the | |
| 33 // browser. Find it or not we set the environment variable because we don't | |
| 34 // want to keep trying in the child processes. | |
| 35 HMODULE metro_dll = ::LoadLibraryA(kMetroDriverDll); | |
| 36 ::SetEnvironmentVariableA(kMetroModeEnvVar, metro_dll ? "1" : "0"); | |
| 37 if (!metro_dll) | |
| 38 return; | |
| 39 init_metro_fn_ = | |
| 40 ::GetProcAddress(::GetModuleHandleA(kMetroDriverDll), "InitMetro"); | |
| 41 } | |
| 42 | |
| 43 int MetroDriver::RunInMetro(HINSTANCE instance, MainFn main_fn) { | |
| 44 Context* context = new Context; | |
| 45 context->fn = main_fn; | |
| 46 context->instance = instance; | |
| 47 | |
| 48 return reinterpret_cast<InitMetro>(init_metro_fn_)(&MainThread, context); | |
| 49 } | |
| OLD | NEW |