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

Side by Side Diff: ui/ozone/ozone_platform.cc

Issue 274193005: ozone: Allow loading the platform implementation from a system library. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « PRESUBMIT.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/debug/trace_event.h" 6 #include "base/debug/trace_event.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/scoped_native_library.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/threading/thread_restrictions.h"
8 #include "ui/base/cursor/ozone/cursor_factory_ozone.h" 11 #include "ui/base/cursor/ozone/cursor_factory_ozone.h"
9 #include "ui/events/ozone/event_factory_ozone.h" 12 #include "ui/events/ozone/event_factory_ozone.h"
10 #include "ui/gfx/ozone/surface_factory_ozone.h" 13 #include "ui/gfx/ozone/surface_factory_ozone.h"
11 #include "ui/ozone/ime/input_method_context_factory_ozone.h" 14 #include "ui/ozone/ime/input_method_context_factory_ozone.h"
12 #include "ui/ozone/ozone_platform.h" 15 #include "ui/ozone/ozone_platform.h"
13 #include "ui/ozone/ozone_platform_list.h" 16 #include "ui/ozone/ozone_platform_list.h"
14 #include "ui/ozone/ozone_switches.h" 17 #include "ui/ozone/ozone_switches.h"
15 18
16 namespace ui { 19 namespace ui {
17 20
18 namespace { 21 namespace {
19 22
20 // Helper to construct an OzonePlatform by name using the platform list. 23 // Helper to construct an OzonePlatform by name using the platform list.
21 OzonePlatform* CreatePlatform(const std::string& platform_name) { 24 OzonePlatform* CreatePlatform(const std::string& platform_name) {
22 // Search for a matching platform in the list. 25 // Search for a matching platform in the list.
23 for (int i = 0; i < kOzonePlatformCount; ++i) 26 for (int i = 0; i < kOzonePlatformCount; ++i) {
24 if (platform_name == kOzonePlatforms[i].name) 27 if (platform_name == kOzonePlatforms[i].name)
25 return kOzonePlatforms[i].constructor(); 28 return kOzonePlatforms[i].constructor();
29 }
26 30
27 LOG(FATAL) << "Invalid ozone platform: " << platform_name; 31 // Try to load the module for the paltform.
32 base::ThreadRestrictions::ScopedAllowIO allow_io;
33 base::NativeLibraryLoadError load_error;
34 base::string16 platform_module_path =
35 base::GetNativeLibraryName(base::ASCIIToUTF16(platform_name));
36 const char kPlatformConstructor[] = "CreateOzonePlatform";
37 base::NativeLibrary platform_module = base::LoadNativeLibrary(
38 base::FilePath(base::UTF16ToASCII(platform_module_path)), &load_error);
39 if (!platform_module) {
40 LOG(FATAL) << "Failed to load library (error: " << load_error.ToString()
41 << ")";
42 } else {
43 OzonePlatformConstructor platform_constructor =
44 reinterpret_cast<OzonePlatformConstructor>(
45 base::GetFunctionPointerFromNativeLibrary(platform_module,
46 kPlatformConstructor));
47 if (platform_constructor) {
48 return platform_constructor();
49 } else {
50 LOG(FATAL) << "Module " << platform_module_path
51 << " does not have the constructor function ("
52 << kPlatformConstructor << ") to initialize the platform.";
53 }
54 }
55
56 NOTREACHED();
28 return NULL; // not reached 57 return NULL; // not reached
29 } 58 }
30 59
31 // Returns the name of the platform to use (value of --ozone-platform flag). 60 // Returns the name of the platform to use (value of --ozone-platform flag).
32 std::string GetPlatformName() { 61 std::string GetPlatformName() {
33 // The first platform is the default. 62 // The first platform is the default.
34 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kOzonePlatform) && 63 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kOzonePlatform) &&
35 kOzonePlatformCount > 0) 64 kOzonePlatformCount > 0)
36 return kOzonePlatforms[0].name; 65 return kOzonePlatforms[0].name;
37 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 66 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // static 99 // static
71 OzonePlatform* OzonePlatform::GetInstance() { 100 OzonePlatform* OzonePlatform::GetInstance() {
72 CHECK(instance_) << "OzonePlatform is not initialized"; 101 CHECK(instance_) << "OzonePlatform is not initialized";
73 return instance_; 102 return instance_;
74 } 103 }
75 104
76 // static 105 // static
77 OzonePlatform* OzonePlatform::instance_; 106 OzonePlatform* OzonePlatform::instance_;
78 107
79 } // namespace ui 108 } // namespace ui
OLDNEW
« no previous file with comments | « PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698