| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ozone/public/cursor_factory_ozone.h" | 5 #include "ui/ozone/public/cursor_factory_ozone.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/threading/thread_local.h" |
| 8 | 10 |
| 9 namespace ui { | 11 namespace ui { |
| 12 namespace { |
| 10 | 13 |
| 11 // static | 14 base::LazyInstance<base::ThreadLocalPointer<CursorFactoryOzone>>::Leaky |
| 12 CursorFactoryOzone* CursorFactoryOzone::impl_ = NULL; | 15 lazy_tls_ptr = LAZY_INSTANCE_INITIALIZER; |
| 16 } |
| 13 | 17 |
| 14 CursorFactoryOzone::CursorFactoryOzone() { | 18 CursorFactoryOzone::CursorFactoryOzone() { |
| 15 DCHECK(!impl_) << "There should only be a single CursorFactoryOzone."; | 19 DCHECK(!lazy_tls_ptr.Pointer()->Get()) |
| 16 impl_ = this; | 20 << "There should only be a single CursorFactoryOzone per thread."; |
| 21 lazy_tls_ptr.Pointer()->Set(this); |
| 17 } | 22 } |
| 18 | 23 |
| 19 CursorFactoryOzone::~CursorFactoryOzone() { | 24 CursorFactoryOzone::~CursorFactoryOzone() { |
| 20 DCHECK_EQ(impl_, this); | 25 DCHECK_EQ(lazy_tls_ptr.Pointer()->Get(), this); |
| 21 impl_ = NULL; | 26 lazy_tls_ptr.Pointer()->Set(nullptr); |
| 22 } | 27 } |
| 23 | 28 |
| 24 CursorFactoryOzone* CursorFactoryOzone::GetInstance() { | 29 CursorFactoryOzone* CursorFactoryOzone::GetInstance() { |
| 25 DCHECK(impl_) << "No CursorFactoryOzone implementation set."; | 30 CursorFactoryOzone* result = lazy_tls_ptr.Pointer()->Get(); |
| 26 return impl_; | 31 DCHECK(result) << "No CursorFactoryOzone implementation set."; |
| 32 return result; |
| 27 } | 33 } |
| 28 | 34 |
| 29 PlatformCursor CursorFactoryOzone::GetDefaultCursor(CursorType type) { | 35 PlatformCursor CursorFactoryOzone::GetDefaultCursor(CursorType type) { |
| 30 NOTIMPLEMENTED(); | 36 NOTIMPLEMENTED(); |
| 31 return NULL; | 37 return NULL; |
| 32 } | 38 } |
| 33 | 39 |
| 34 PlatformCursor CursorFactoryOzone::CreateImageCursor(const SkBitmap& bitmap, | 40 PlatformCursor CursorFactoryOzone::CreateImageCursor(const SkBitmap& bitmap, |
| 35 const gfx::Point& hotspot, | 41 const gfx::Point& hotspot, |
| 36 float bitmap_dpi) { | 42 float bitmap_dpi) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 49 | 55 |
| 50 void CursorFactoryOzone::RefImageCursor(PlatformCursor cursor) { | 56 void CursorFactoryOzone::RefImageCursor(PlatformCursor cursor) { |
| 51 NOTIMPLEMENTED(); | 57 NOTIMPLEMENTED(); |
| 52 } | 58 } |
| 53 | 59 |
| 54 void CursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) { | 60 void CursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) { |
| 55 NOTIMPLEMENTED(); | 61 NOTIMPLEMENTED(); |
| 56 } | 62 } |
| 57 | 63 |
| 58 } // namespace ui | 64 } // namespace ui |
| OLD | NEW |