OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 |
| 5 #include "base/command_line.h" |
| 6 #include "base/lazy_instance.h" |
| 7 #include "base/logging.h" |
| 8 #include "base/trace_event/trace_event.h" |
| 9 #include "ui/ozone/platform_object.h" |
| 10 #include "ui/ozone/platform_selection.h" |
| 11 #include "ui/ozone/public/ozone_client.h" |
| 12 #include "ui/ozone/public/ozone_platform.h" |
| 13 #include "ui/ozone/public/ozone_switches.h" |
| 14 |
| 15 namespace ui { |
| 16 |
| 17 namespace { |
| 18 |
| 19 OzoneClient* g_instance = nullptr; |
| 20 |
| 21 } // namespace |
| 22 |
| 23 OzoneClient::OzoneClient() { |
| 24 DCHECK(!g_instance) << "There should only be a single OzoneClient."; |
| 25 g_instance = this; |
| 26 } |
| 27 |
| 28 OzoneClient::~OzoneClient() { |
| 29 DCHECK_EQ(g_instance, this); |
| 30 g_instance = nullptr; |
| 31 } |
| 32 |
| 33 // static |
| 34 void OzoneClient::InitializeForUI() { |
| 35 if (g_instance) |
| 36 return; |
| 37 |
| 38 CreateInstance(); |
| 39 g_instance->InitializeUI(); |
| 40 } |
| 41 |
| 42 // static |
| 43 void OzoneClient::InitializeForRenderer() { |
| 44 if (g_instance) |
| 45 return; |
| 46 |
| 47 CreateInstance(); |
| 48 g_instance->InitializeRenderer(); |
| 49 } |
| 50 |
| 51 // static |
| 52 OzoneClient* OzoneClient::GetInstance() { |
| 53 DCHECK(g_instance) << "OzoneClient is not initialized"; |
| 54 return g_instance; |
| 55 } |
| 56 |
| 57 // static |
| 58 void OzoneClient::CreateInstance() { |
| 59 if (!g_instance) { |
| 60 TRACE_EVENT1("ozone", "OzoneClient::CreateInstance", "platform", |
| 61 GetOzonePlatformName()); |
| 62 scoped_ptr<OzoneClient> platform = PlatformObject<OzoneClient>::Create(); |
| 63 |
| 64 // TODO(spang): Currently need to leak this object. |
| 65 OzoneClient* pl = platform.release(); |
| 66 DCHECK_EQ(g_instance, pl); |
| 67 } |
| 68 } |
| 69 |
| 70 } // namespace ui |
OLD | NEW |