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

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

Issue 284253006: ozone: Make sure the platform doesn't get initialized more than once. (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 | « no previous file | 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 "ui/base/cursor/ozone/cursor_factory_ozone.h" 8 #include "ui/base/cursor/ozone/cursor_factory_ozone.h"
9 #include "ui/events/ozone/event_factory_ozone.h" 9 #include "ui/events/ozone/event_factory_ozone.h"
10 #include "ui/gfx/ozone/surface_factory_ozone.h" 10 #include "ui/gfx/ozone/surface_factory_ozone.h"
11 #include "ui/ozone/ime/input_method_context_factory_ozone.h" 11 #include "ui/ozone/ime/input_method_context_factory_ozone.h"
12 #include "ui/ozone/ozone_platform.h" 12 #include "ui/ozone/ozone_platform.h"
13 #include "ui/ozone/ozone_platform_list.h" 13 #include "ui/ozone/ozone_platform_list.h"
14 #include "ui/ozone/ozone_switches.h" 14 #include "ui/ozone/ozone_switches.h"
15 15
16 namespace ui { 16 namespace ui {
17 17
18 namespace { 18 namespace {
19 19
20 bool g_platform_initialized_ui = false;
21 bool g_platform_initialized_gpu = false;
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();
26 29
27 LOG(FATAL) << "Invalid ozone platform: " << platform_name; 30 LOG(FATAL) << "Invalid ozone platform: " << platform_name;
28 return NULL; // not reached 31 return NULL; // not reached
29 } 32 }
30 33
31 // Returns the name of the platform to use (value of --ozone-platform flag). 34 // Returns the name of the platform to use (value of --ozone-platform flag).
32 std::string GetPlatformName() { 35 std::string GetPlatformName() {
33 // The first platform is the default. 36 // The first platform is the default.
34 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kOzonePlatform) && 37 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kOzonePlatform) &&
35 kOzonePlatformCount > 0) 38 kOzonePlatformCount > 0)
36 return kOzonePlatforms[0].name; 39 return kOzonePlatforms[0].name;
37 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 40 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
38 switches::kOzonePlatform); 41 switches::kOzonePlatform);
39 } 42 }
40 43
41 } // namespace 44 } // namespace
42 45
43 OzonePlatform::OzonePlatform() { 46 OzonePlatform::OzonePlatform() {
44 CHECK(!instance_) << "There should only be a single OzonePlatform."; 47 CHECK(!instance_) << "There should only be a single OzonePlatform.";
45 instance_ = this; 48 instance_ = this;
49 g_platform_initialized_ui = false;
50 g_platform_initialized_gpu = false;
46 } 51 }
47 52
48 OzonePlatform::~OzonePlatform() { 53 OzonePlatform::~OzonePlatform() {
49 CHECK_EQ(instance_, this); 54 CHECK_EQ(instance_, this);
50 instance_ = NULL; 55 instance_ = NULL;
51 } 56 }
52 57
53 // static 58 // static
54 void OzonePlatform::InitializeForUI() { 59 void OzonePlatform::InitializeForUI() {
55 CreateInstance(); 60 CreateInstance();
61 if (g_platform_initialized_ui)
62 return;
63 g_platform_initialized_ui = true;
56 instance_->InitializeUI(); 64 instance_->InitializeUI();
57 ui::InputMethodContextFactoryOzone::SetInstance( 65 ui::InputMethodContextFactoryOzone::SetInstance(
58 instance_->GetInputMethodContextFactoryOzone()); 66 instance_->GetInputMethodContextFactoryOzone());
59 } 67 }
60 68
61 // static 69 // static
62 void OzonePlatform::InitializeForGPU() { 70 void OzonePlatform::InitializeForGPU() {
63 CreateInstance(); 71 CreateInstance();
72 if (g_platform_initialized_gpu)
73 return;
74 g_platform_initialized_gpu = true;
64 instance_->InitializeGPU(); 75 instance_->InitializeGPU();
65 } 76 }
66 77
67 // static 78 // static
68 OzonePlatform* OzonePlatform::GetInstance() { 79 OzonePlatform* OzonePlatform::GetInstance() {
69 CHECK(instance_) << "OzonePlatform is not initialized"; 80 CHECK(instance_) << "OzonePlatform is not initialized";
70 return instance_; 81 return instance_;
71 } 82 }
72 83
73 // static 84 // static
74 void OzonePlatform::CreateInstance() { 85 void OzonePlatform::CreateInstance() {
75 if (!instance_) { 86 if (!instance_) {
76 std::string platform = GetPlatformName(); 87 std::string platform = GetPlatformName();
77 TRACE_EVENT1("ozone", "OzonePlatform::Initialize", "platform", platform); 88 TRACE_EVENT1("ozone", "OzonePlatform::Initialize", "platform", platform);
78 CreatePlatform(platform); 89 CreatePlatform(platform);
79 } 90 }
80 } 91 }
81 92
82 // static 93 // static
83 OzonePlatform* OzonePlatform::instance_; 94 OzonePlatform* OzonePlatform::instance_;
84 95
85 } // namespace ui 96 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698