OLD | NEW |
---|---|
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 "ui/views/widget/desktop_aura/desktop_factory_ozone.h" | 5 #include "ui/views/widget/desktop_aura/desktop_factory_ozone.h" |
6 | 6 |
7 #include <memory> | |
8 | |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/ozone/platform_object.h" | |
8 | 11 |
9 namespace views { | 12 namespace views { |
10 | 13 |
11 // static | 14 // static |
12 DesktopFactoryOzone* DesktopFactoryOzone::impl_ = NULL; | 15 DesktopFactoryOzone* DesktopFactoryOzone::impl_ = nullptr; |
13 | 16 |
14 DesktopFactoryOzone::DesktopFactoryOzone() { | 17 DesktopFactoryOzone::DesktopFactoryOzone() { |
18 DCHECK(!impl_) << "There should only be a single DesktopFactoryOzone."; | |
19 impl_ = this; | |
15 } | 20 } |
16 | 21 |
17 DesktopFactoryOzone::~DesktopFactoryOzone() { | 22 DesktopFactoryOzone::~DesktopFactoryOzone() { |
23 DCHECK_EQ(impl_, this); | |
24 impl_ = nullptr; | |
18 } | 25 } |
19 | 26 |
20 DesktopFactoryOzone* DesktopFactoryOzone::GetInstance() { | 27 DesktopFactoryOzone* DesktopFactoryOzone::GetInstance() { |
21 CHECK(impl_) << "DesktopFactoryOzone accessed before constructed"; | 28 if (!impl_) { |
29 std::unique_ptr<DesktopFactoryOzone> factory = | |
30 ui::PlatformObject<DesktopFactoryOzone>::Create(); | |
31 | |
32 // TODO(tonikitoo): Currently need to leak this object. | |
Michael Forney
2016/06/06 20:08:21
I wasn't sure about this, but it looks like this i
| |
33 DesktopFactoryOzone* leaky = factory.release(); | |
34 DCHECK_EQ(impl_, leaky); | |
35 } | |
22 return impl_; | 36 return impl_; |
23 } | 37 } |
24 | 38 |
25 void DesktopFactoryOzone::SetInstance(DesktopFactoryOzone* impl) { | |
26 impl_ = impl; | |
27 } | |
28 | |
29 } // namespace views | 39 } // namespace views |
OLD | NEW |