Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Unified Diff: chrome/app/metro_driver_win.cc

Issue 9718001: Load the metro driver dll at startup (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/app/metro_driver_win.h ('k') | chrome/chrome_exe.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/app/metro_driver_win.cc
===================================================================
--- chrome/app/metro_driver_win.cc (revision 0)
+++ chrome/app/metro_driver_win.cc (revision 0)
@@ -0,0 +1,49 @@
+// Copyright (c) 2011 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 "metro_driver_win.h"
+
+namespace {
+// The windows 8 metro driver dll name and entry point.
+const char kMetroDriverDll[] = "metro_driver.dll";
+// This environment variable controls the loading of the metro driver DLL.
+const char* kMetroModeEnvVar = "CHROME_METRO_DLL";
+
+typedef int (*InitMetro)(LPTHREAD_START_ROUTINE thread_proc, void* context);
+
+struct Context {
+ MetroDriver::MainFn fn;
+ HINSTANCE instance;
+};
+
+DWORD WINAPI MainThread(void* param) {
+ Context* context = reinterpret_cast<Context*>(param);
+ int rv = context->fn(context->instance);
+ delete context;
+ return rv;
+}
+
+} // namespace
+
+MetroDriver::MetroDriver() : init_metro_fn_(NULL) {
+ if (0 != ::GetEnvironmentVariableA(kMetroModeEnvVar, NULL, 0))
+ return;
+ // We haven't tried to load the metro driver, this probably means we are the
+ // browser. Find it or not we set the environment variable because we don't
+ // want to keep trying in the child processes.
+ HMODULE metro_dll = ::LoadLibraryA(kMetroDriverDll);
+ ::SetEnvironmentVariableA(kMetroModeEnvVar, metro_dll ? "1" : "0");
+ if (!metro_dll)
+ return;
+ init_metro_fn_ =
+ ::GetProcAddress(::GetModuleHandleA(kMetroDriverDll), "InitMetro");
+}
+
+int MetroDriver::RunInMetro(HINSTANCE instance, MainFn main_fn) {
+ Context* context = new Context;
+ context->fn = main_fn;
+ context->instance = instance;
+
+ return reinterpret_cast<InitMetro>(init_metro_fn_)(&MainThread, context);
+}
Property changes on: chrome\app\metro_driver_win.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « chrome/app/metro_driver_win.h ('k') | chrome/chrome_exe.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698