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

Unified Diff: ui/aura/env.cc

Issue 1871253002: aura: Require explicit ownership of the Env instance. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tot.merge Created 4 years, 8 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/aura/env.h ('k') | ui/aura/test/aura_test_helper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/env.cc
diff --git a/ui/aura/env.cc b/ui/aura/env.cc
index 7e82d4e13cdba8de340959236efcea0cff0e1c4d..672f4db8b026d73066293a633eb2a80796fbf03e 100644
--- a/ui/aura/env.cc
+++ b/ui/aura/env.cc
@@ -24,23 +24,29 @@ namespace {
base::LazyInstance<base::ThreadLocalPointer<Env> >::Leaky lazy_tls_ptr =
LAZY_INSTANCE_INITIALIZER;
-#if defined(USE_OZONE)
// Returns true if running inside of mus. Checks for mojo specific flag.
bool RunningInsideMus() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
"primordial-pipe-token");
}
-#endif
} // namespace
////////////////////////////////////////////////////////////////////////////////
// Env, public:
+Env::~Env() {
+ FOR_EACH_OBSERVER(EnvObserver, observers_, OnWillDestroyEnv());
+ DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get());
+ lazy_tls_ptr.Pointer()->Set(NULL);
+}
+
// static
-void Env::CreateInstance(bool create_event_source) {
- if (!lazy_tls_ptr.Pointer()->Get())
- (new Env())->Init(create_event_source);
+std::unique_ptr<Env> Env::CreateInstance() {
+ DCHECK(!lazy_tls_ptr.Pointer()->Get());
+ std::unique_ptr<Env> env(new Env());
+ env->Init();
+ return env;
}
// static
@@ -56,11 +62,6 @@ Env* Env::GetInstanceDontCreate() {
return lazy_tls_ptr.Pointer()->Get();
}
-// static
-void Env::DeleteInstance() {
- delete lazy_tls_ptr.Pointer()->Get();
-}
-
void Env::AddObserver(EnvObserver* observer) {
observers_.AddObserver(observer);
}
@@ -86,21 +87,14 @@ Env::Env()
lazy_tls_ptr.Pointer()->Set(this);
}
-Env::~Env() {
- FOR_EACH_OBSERVER(EnvObserver, observers_, OnWillDestroyEnv());
- DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get());
- lazy_tls_ptr.Pointer()->Set(NULL);
-}
-
-void Env::Init(bool create_event_source) {
- if (!create_event_source)
+void Env::Init() {
+ if (RunningInsideMus())
return;
#if defined(USE_OZONE)
// The ozone platform can provide its own event source. So initialize the
// platform before creating the default event source. If running inside mus
// let the mus process initialize ozone instead.
- if (!RunningInsideMus())
- ui::OzonePlatform::InitializeForUI();
+ ui::OzonePlatform::InitializeForUI();
#endif
if (!ui::PlatformEventSource::GetInstance())
event_source_ = ui::PlatformEventSource::CreateDefault();
« no previous file with comments | « ui/aura/env.h ('k') | ui/aura/test/aura_test_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698