Remove support for specifying version on command line.
[chromium-blink-merge.git] / ui / ozone / ozone_platform.cc
blobb87dc8ffcae2c8d5476a5ea638d23669a7c444f8
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
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/logging.h"
7 #include "ui/ozone/ozone_platform.h"
8 #include "ui/ozone/ozone_platform_list.h"
9 #include "ui/ozone/ozone_switches.h"
11 namespace ui {
13 namespace {
15 // Helper to construct an OzonePlatform by name using the platform list.
16 OzonePlatform* CreatePlatform(const std::string& platform_name) {
17 // The first platform is the defualt.
18 if (platform_name == "default" && kOzonePlatformCount > 0)
19 return kOzonePlatforms[0].constructor();
21 // Otherwise, search for a matching platform in the list.
22 for (int i = 0; i < kOzonePlatformCount; ++i)
23 if (platform_name == kOzonePlatforms[i].name)
24 return kOzonePlatforms[i].constructor();
26 LOG(FATAL) << "Invalid ozone platform: " << platform_name;
27 return NULL; // not reached
30 // Returns the name of the platform to use (value of --ozone-platform flag).
31 std::string GetRequestedPlatform() {
32 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kOzonePlatform))
33 return "default";
34 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
35 switches::kOzonePlatform);
38 } // namespace
40 OzonePlatform::OzonePlatform() {}
42 OzonePlatform::~OzonePlatform() {
43 gfx::SurfaceFactoryOzone::SetInstance(NULL);
44 ui::EventFactoryOzone::SetInstance(NULL);
47 // static
48 void OzonePlatform::Initialize() {
49 if (instance_)
50 return;
52 instance_ = CreatePlatform(GetRequestedPlatform());
54 // Inject ozone interfaces.
55 gfx::SurfaceFactoryOzone::SetInstance(instance_->GetSurfaceFactoryOzone());
56 ui::EventFactoryOzone::SetInstance(instance_->GetEventFactoryOzone());
57 ui::InputMethodContextFactoryOzone::SetInstance(
58 instance_->GetInputMethodContextFactoryOzone());
61 // static
62 OzonePlatform* OzonePlatform::instance_;
64 } // namespace ui