[email protected] | e9469c6 | 2014-06-06 17:02:29 | [diff] [blame] | 1 | // Copyright 2014 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 | |||||
[email protected] | 592cb97 | 2014-06-12 18:18:01 | [diff] [blame] | 5 | #include "ui/ozone/platform_selection.h" |
6 | |||||
[email protected] | e9469c6 | 2014-06-06 17:02:29 | [diff] [blame] | 7 | #include "base/command_line.h" |
8 | #include "base/logging.h" | ||||
[email protected] | e9469c6 | 2014-06-06 17:02:29 | [diff] [blame] | 9 | #include "ui/ozone/platform_list.h" |
[email protected] | f88a8f7 | 2014-07-11 18:07:49 | [diff] [blame] | 10 | #include "ui/ozone/public/ozone_switches.h" |
[email protected] | e9469c6 | 2014-06-06 17:02:29 | [diff] [blame] | 11 | |
12 | namespace ui { | ||||
13 | |||||
14 | namespace { | ||||
15 | |||||
16 | // Returns the name of the platform to use (value of --ozone-platform flag). | ||||
17 | std::string GetPlatformName() { | ||||
18 | // The first platform is the default. | ||||
avi | 6b10fd0 | 2014-12-23 05:51:23 | [diff] [blame] | 19 | if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
20 | switches::kOzonePlatform) && | ||||
[email protected] | e9469c6 | 2014-06-06 17:02:29 | [diff] [blame] | 21 | kPlatformCount > 0) |
22 | return kPlatformNames[0]; | ||||
avi | 6b10fd0 | 2014-12-23 05:51:23 | [diff] [blame] | 23 | return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
[email protected] | e9469c6 | 2014-06-06 17:02:29 | [diff] [blame] | 24 | switches::kOzonePlatform); |
25 | } | ||||
26 | |||||
27 | int g_selected_platform = -1; | ||||
28 | |||||
29 | } // namespace | ||||
30 | |||||
31 | int GetOzonePlatformId() { | ||||
32 | if (g_selected_platform >= 0) | ||||
33 | return g_selected_platform; | ||||
34 | |||||
35 | std::string platform_name = GetPlatformName(); | ||||
[email protected] | e9469c6 | 2014-06-06 17:02:29 | [diff] [blame] | 36 | |
37 | // Search for a matching platform in the list. | ||||
38 | for (int platform_id = 0; platform_id < kPlatformCount; ++platform_id) { | ||||
39 | if (platform_name == kPlatformNames[platform_id]) { | ||||
40 | g_selected_platform = platform_id; | ||||
41 | return g_selected_platform; | ||||
42 | } | ||||
43 | } | ||||
44 | |||||
45 | LOG(FATAL) << "Invalid ozone platform: " << platform_name; | ||||
46 | return -1; // not reached | ||||
47 | } | ||||
48 | |||||
49 | const char* GetOzonePlatformName() { | ||||
50 | return kPlatformNames[GetOzonePlatformId()]; | ||||
51 | } | ||||
52 | |||||
53 | } // namespace ui |