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

Side by Side Diff: ui/ozone/public/cursor_factory_ozone.cc

Issue 2978833002: Making CursorFactoryOzone thread-local (Closed)
Patch Set: Created 3 years, 5 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
« no previous file with comments | « ui/ozone/public/cursor_factory_ozone.h ('k') | 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 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 {
10 12
11 // static 13 namespace {
12 CursorFactoryOzone* CursorFactoryOzone::impl_ = NULL; 14
15 // TODO(mfomitchev): crbug.com/741106
16 // Until the above bug is fixed, CursorFactoryOzone singleton needs to be
17 // thread-local, because Ash creates its own instance.
18 base::LazyInstance<base::ThreadLocalPointer<CursorFactoryOzone>>::Leaky
19 lazy_tls_ptr = LAZY_INSTANCE_INITIALIZER;
20
21 } // namespace
13 22
14 CursorFactoryOzone::CursorFactoryOzone() { 23 CursorFactoryOzone::CursorFactoryOzone() {
15 DCHECK(!impl_) << "There should only be a single CursorFactoryOzone."; 24 DCHECK(!lazy_tls_ptr.Pointer()->Get())
16 impl_ = this; 25 << "There should only be a single CursorFactoryOzone per thread.";
26 lazy_tls_ptr.Pointer()->Set(this);
17 } 27 }
18 28
19 CursorFactoryOzone::~CursorFactoryOzone() { 29 CursorFactoryOzone::~CursorFactoryOzone() {
20 DCHECK_EQ(impl_, this); 30 DCHECK_EQ(lazy_tls_ptr.Pointer()->Get(), this);
21 impl_ = NULL; 31 lazy_tls_ptr.Pointer()->Set(nullptr);
22 } 32 }
23 33
24 CursorFactoryOzone* CursorFactoryOzone::GetInstance() { 34 CursorFactoryOzone* CursorFactoryOzone::GetInstance() {
25 DCHECK(impl_) << "No CursorFactoryOzone implementation set."; 35 CursorFactoryOzone* result = lazy_tls_ptr.Pointer()->Get();
26 return impl_; 36 DCHECK(result) << "No CursorFactoryOzone implementation set.";
37 return result;
27 } 38 }
28 39
29 PlatformCursor CursorFactoryOzone::GetDefaultCursor(CursorType type) { 40 PlatformCursor CursorFactoryOzone::GetDefaultCursor(CursorType type) {
30 NOTIMPLEMENTED(); 41 NOTIMPLEMENTED();
31 return NULL; 42 return NULL;
32 } 43 }
33 44
34 PlatformCursor CursorFactoryOzone::CreateImageCursor(const SkBitmap& bitmap, 45 PlatformCursor CursorFactoryOzone::CreateImageCursor(const SkBitmap& bitmap,
35 const gfx::Point& hotspot, 46 const gfx::Point& hotspot,
36 float bitmap_dpi) { 47 float bitmap_dpi) {
(...skipping 12 matching lines...) Expand all
49 60
50 void CursorFactoryOzone::RefImageCursor(PlatformCursor cursor) { 61 void CursorFactoryOzone::RefImageCursor(PlatformCursor cursor) {
51 NOTIMPLEMENTED(); 62 NOTIMPLEMENTED();
52 } 63 }
53 64
54 void CursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) { 65 void CursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) {
55 NOTIMPLEMENTED(); 66 NOTIMPLEMENTED();
56 } 67 }
57 68
58 } // namespace ui 69 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/public/cursor_factory_ozone.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698