Chromium Code Reviews| Index: win8/metro_driver/metro_driver.cc |
| diff --git a/win8/metro_driver/metro_driver.cc b/win8/metro_driver/metro_driver.cc |
| index eb87754c7120c389cc4bc757b5cc1eb881d48e46..a60af6b2405a054d3d6c17282d731fd06bcaf6a1 100644 |
| --- a/win8/metro_driver/metro_driver.cc |
| +++ b/win8/metro_driver/metro_driver.cc |
| @@ -13,11 +13,9 @@ |
| #include "base/logging.h" |
| #include "base/logging_win.h" |
| #include "base/win/scoped_comptr.h" |
| +#include "base/win/windows_version.h" |
| #include "win8/metro_driver/winrt_utils.h" |
| -// TODO(siggi): Move this to GYP. |
| -#pragma comment(lib, "runtimeobject.lib") |
| - |
| namespace { |
| LONG WINAPI ErrorReportingHandler(EXCEPTION_POINTERS* ex_info) { |
| @@ -37,6 +35,17 @@ LONG WINAPI ErrorReportingHandler(EXCEPTION_POINTERS* ex_info) { |
| return EXCEPTION_CONTINUE_SEARCH; |
| } |
| +void SetMetroReportingFlags() { |
| +#if !defined(NDEBUG) |
| + // Set the error reporting flags to always raise an exception, |
| + // which is then processed by our vectored exception handling |
| + // above to log the error message. |
| + winfoundtn::Diagnostics::SetErrorReportingFlags( |
| + winfoundtn::Diagnostics::UseSetErrorInfo | |
| + winfoundtn::Diagnostics::ForceExceptions); |
| +#endif |
| +} |
| + |
| // TODO(robertshield): This GUID is hard-coded in a bunch of places that |
| // don't allow explicit includes. Find a single place for it to live. |
| // {7FE69228-633E-4f06-80C1-527FEA23E3A7} |
| @@ -44,7 +53,7 @@ const GUID kChromeTraceProviderName = { |
| 0x7fe69228, 0x633e, 0x4f06, |
| { 0x80, 0xc1, 0x52, 0x7f, 0xea, 0x23, 0xe3, 0xa7 } }; |
| -} |
| +} // namespace |
| #if !defined(COMPONENT_BUILD) |
| // Required for base initialization. |
| @@ -54,53 +63,58 @@ const GUID kChromeTraceProviderName = { |
| base::AtExitManager at_exit; |
| #endif |
| +mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows8() { |
| + SetMetroReportingFlags(); |
| + HRESULT hr = ::Windows::Foundation::Initialize(RO_INIT_MULTITHREADED); |
| + if (FAILED(hr)) |
| + CHECK(false); |
| + mswr::ComPtr<winapp::Core::ICoreApplication> core_app; |
| + hr = winrt_utils::CreateActivationFactory( |
| + RuntimeClass_Windows_ApplicationModel_Core_CoreApplication, |
| + core_app.GetAddressOf()); |
| + if (FAILED(hr)) |
| + CHECK(false); |
| + return core_app; |
| +} |
| + |
| +mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7(); |
| + |
| extern "C" __declspec(dllexport) |
| int InitMetro() { |
| + // Metro mode or its emulation is not supported in Vista or XP. |
| + if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| + return 1; |
| // Initialize the command line. |
| CommandLine::Init(0, NULL); |
| + // Initialize the logging system. |
| logging::LoggingSettings settings; |
| settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| logging::InitLogging(settings); |
| - |
| #if defined(NDEBUG) |
| logging::SetMinLogLevel(logging::LOG_ERROR); |
| #else |
| logging::SetMinLogLevel(logging::LOG_VERBOSE); |
| - // Set the error reporting flags to always raise an exception, |
| - // which is then processed by our vectored exception handling |
| - // above to log the error message. |
| - winfoundtn::Diagnostics::SetErrorReportingFlags( |
| - winfoundtn::Diagnostics::UseSetErrorInfo | |
| - winfoundtn::Diagnostics::ForceExceptions); |
| - |
| - HANDLE registration = |
| + HANDLE registration = |
| ::AddVectoredExceptionHandler(TRUE, ErrorReportingHandler); |
| #endif |
| - |
| // Enable trace control and transport through event tracing for Windows. |
| logging::LogEventProvider::Initialize(kChromeTraceProviderName); |
| - |
| DVLOG(1) << "InitMetro"; |
| - mswrw::RoInitializeWrapper ro_initializer(RO_INIT_MULTITHREADED); |
| - CheckHR(ro_initializer, "RoInitialize failed"); |
| - |
| + // OS specific initialization. |
| mswr::ComPtr<winapp::Core::ICoreApplication> core_app; |
| - HRESULT hr = winrt_utils::CreateActivationFactory( |
| - RuntimeClass_Windows_ApplicationModel_Core_CoreApplication, |
| - core_app.GetAddressOf()); |
| - CheckHR(hr, "Failed to create app factory"); |
| - if (FAILED(hr)) |
| - return 1; |
| + if (base::win::GetVersion() < base::win::VERSION_WIN8) |
| + core_app = InitWindows7(); |
| + else |
| + core_app = InitWindows8(); |
| auto view_factory = mswr::Make<ChromeAppViewFactory>(core_app.Get()); |
|
zturner
2014/03/20 18:14:14
I know this isn't your code, but I don't think we'
|
| - hr = core_app->Run(view_factory.Get()); |
| + HRESULT hr = core_app->Run(view_factory.Get()); |
| DVLOG(1) << "exiting InitMetro, hr=" << hr; |
| #if !defined(NDEBUG) |
| ::RemoveVectoredExceptionHandler(registration); |
| #endif |
| - |
| return hr; |
| } |