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

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

Issue 313963007: ozone: Implement PlatformObject<T> for platform-specific objects (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix namespacing Created 6 years, 6 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
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 "ui/ozone/ozone_platform.h" 8 #include "ui/ozone/ozone_platform.h"
9 #include "ui/ozone/ozone_platform_list.h"
10 #include "ui/ozone/ozone_switches.h" 9 #include "ui/ozone/ozone_switches.h"
10 #include "ui/ozone/platform_object.h"
11 #include "ui/ozone/platform_selection.h"
11 12
12 namespace ui { 13 namespace ui {
13 14
14 namespace { 15 namespace {
15 16
16 bool g_platform_initialized_ui = false; 17 bool g_platform_initialized_ui = false;
17 bool g_platform_initialized_gpu = false; 18 bool g_platform_initialized_gpu = false;
18 19
19 // Helper to construct an OzonePlatform by name using the platform list.
20 OzonePlatform* CreatePlatform(const std::string& platform_name) {
21 // 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();
25
26 LOG(FATAL) << "Invalid ozone platform: " << platform_name;
27 return NULL; // not reached
28 } 20 }
29 21
30 // Returns the name of the platform to use (value of --ozone-platform flag).
31 std::string GetPlatformName() {
32 // The first platform is the default.
33 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kOzonePlatform) &&
34 kOzonePlatformCount > 0)
35 return kOzonePlatforms[0].name;
36 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
37 switches::kOzonePlatform);
38 }
39
40 } // namespace
41
42 OzonePlatform::OzonePlatform() { 22 OzonePlatform::OzonePlatform() {
43 CHECK(!instance_) << "There should only be a single OzonePlatform."; 23 CHECK(!instance_) << "There should only be a single OzonePlatform.";
44 instance_ = this; 24 instance_ = this;
45 g_platform_initialized_ui = false; 25 g_platform_initialized_ui = false;
46 g_platform_initialized_gpu = false; 26 g_platform_initialized_gpu = false;
47 } 27 }
48 28
49 OzonePlatform::~OzonePlatform() { 29 OzonePlatform::~OzonePlatform() {
50 CHECK_EQ(instance_, this); 30 CHECK_EQ(instance_, this);
51 instance_ = NULL; 31 instance_ = NULL;
(...skipping 19 matching lines...) Expand all
71 51
72 // static 52 // static
73 OzonePlatform* OzonePlatform::GetInstance() { 53 OzonePlatform* OzonePlatform::GetInstance() {
74 CHECK(instance_) << "OzonePlatform is not initialized"; 54 CHECK(instance_) << "OzonePlatform is not initialized";
75 return instance_; 55 return instance_;
76 } 56 }
77 57
78 // static 58 // static
79 void OzonePlatform::CreateInstance() { 59 void OzonePlatform::CreateInstance() {
80 if (!instance_) { 60 if (!instance_) {
81 std::string platform = GetPlatformName(); 61 TRACE_EVENT1("ozone",
82 TRACE_EVENT1("ozone", "OzonePlatform::Initialize", "platform", platform); 62 "OzonePlatform::Initialize",
83 CreatePlatform(platform); 63 "platform",
64 GetOzonePlatformName());
65 scoped_ptr<OzonePlatform> platform =
66 PlatformObject<OzonePlatform>::Create();
67
68 // TODO(spang): Currently need to leak this object.
69 CHECK_EQ(instance_, platform.release());
84 } 70 }
85 } 71 }
86 72
87 // static 73 // static
88 OzonePlatform* OzonePlatform::instance_; 74 OzonePlatform* OzonePlatform::instance_;
89 75
90 } // namespace ui 76 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/ozone.gyp ('k') | ui/ozone/ozone_platform_list.h » ('j') | ui/ozone/platform_object.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698