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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/ozone/public/cursor_factory_ozone.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/ozone/public/cursor_factory_ozone.cc
diff --git a/ui/ozone/public/cursor_factory_ozone.cc b/ui/ozone/public/cursor_factory_ozone.cc
index 356bd127b80cf434f9266882158cbfffa361db0d..7efc26c22bffb003c81de9d0844f2c064b6772c4 100644
--- a/ui/ozone/public/cursor_factory_ozone.cc
+++ b/ui/ozone/public/cursor_factory_ozone.cc
@@ -4,26 +4,37 @@
#include "ui/ozone/public/cursor_factory_ozone.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
+#include "base/threading/thread_local.h"
namespace ui {
-// static
-CursorFactoryOzone* CursorFactoryOzone::impl_ = NULL;
+namespace {
+
+// TODO(mfomitchev): crbug.com/741106
+// Until the above bug is fixed, CursorFactoryOzone singleton needs to be
+// thread-local, because Ash creates its own instance.
+base::LazyInstance<base::ThreadLocalPointer<CursorFactoryOzone>>::Leaky
+ lazy_tls_ptr = LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
CursorFactoryOzone::CursorFactoryOzone() {
- DCHECK(!impl_) << "There should only be a single CursorFactoryOzone.";
- impl_ = this;
+ DCHECK(!lazy_tls_ptr.Pointer()->Get())
+ << "There should only be a single CursorFactoryOzone per thread.";
+ lazy_tls_ptr.Pointer()->Set(this);
}
CursorFactoryOzone::~CursorFactoryOzone() {
- DCHECK_EQ(impl_, this);
- impl_ = NULL;
+ DCHECK_EQ(lazy_tls_ptr.Pointer()->Get(), this);
+ lazy_tls_ptr.Pointer()->Set(nullptr);
}
CursorFactoryOzone* CursorFactoryOzone::GetInstance() {
- DCHECK(impl_) << "No CursorFactoryOzone implementation set.";
- return impl_;
+ CursorFactoryOzone* result = lazy_tls_ptr.Pointer()->Get();
+ DCHECK(result) << "No CursorFactoryOzone implementation set.";
+ return result;
}
PlatformCursor CursorFactoryOzone::GetDefaultCursor(CursorType type) {
« 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