Index: ui/ozone/ozone_platform.cc |
diff --git a/ui/ozone/ozone_platform.cc b/ui/ozone/ozone_platform.cc |
index 12925c04ed25344d46baf5b3b8111307a2307824..26ee825106047300561e98d7d558cf8fd38f73a1 100644 |
--- a/ui/ozone/ozone_platform.cc |
+++ b/ui/ozone/ozone_platform.cc |
@@ -5,6 +5,9 @@ |
#include "base/command_line.h" |
#include "base/debug/trace_event.h" |
#include "base/logging.h" |
+#include "base/scoped_native_library.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "base/threading/thread_restrictions.h" |
#include "ui/ozone/ozone_platform.h" |
#include "ui/ozone/ozone_platform_list.h" |
#include "ui/ozone/ozone_switches.h" |
@@ -19,11 +22,37 @@ bool g_platform_initialized_gpu = false; |
// Helper to construct an OzonePlatform by name using the platform list. |
OzonePlatform* CreatePlatform(const std::string& platform_name) { |
// Search for a matching platform in the list. |
- for (int i = 0; i < kOzonePlatformCount; ++i) |
+ for (int i = 0; i < kOzonePlatformCount; ++i) { |
if (platform_name == kOzonePlatforms[i].name) |
return kOzonePlatforms[i].constructor(); |
+ } |
+ |
+ // Try to load the module for the paltform. |
+ base::ThreadRestrictions::ScopedAllowIO allow_io; |
+ base::NativeLibraryLoadError load_error; |
+ base::string16 platform_module_path = |
+ base::GetNativeLibraryName(base::ASCIIToUTF16(platform_name)); |
+ const char kPlatformConstructor[] = "CreateOzonePlatform"; |
+ base::NativeLibrary platform_module = base::LoadNativeLibrary( |
+ base::FilePath(base::UTF16ToASCII(platform_module_path)), &load_error); |
+ if (!platform_module) { |
+ LOG(FATAL) << "Failed to load library (error: " << load_error.ToString() |
+ << ")"; |
+ } else { |
+ OzonePlatformConstructor platform_constructor = |
+ reinterpret_cast<OzonePlatformConstructor>( |
+ base::GetFunctionPointerFromNativeLibrary(platform_module, |
+ kPlatformConstructor)); |
+ if (platform_constructor) { |
+ return platform_constructor(); |
+ } else { |
+ LOG(FATAL) << "Module " << platform_module_path |
+ << " does not have the constructor function (" |
+ << kPlatformConstructor << ") to initialize the platform."; |
+ } |
+ } |
- LOG(FATAL) << "Invalid ozone platform: " << platform_name; |
+ NOTREACHED(); |
return NULL; // not reached |
} |