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

Side by Side Diff: ui/aura/env.cc

Issue 1297173003: Revert of aura: Require explicit ownership of the Env instance. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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/aura/env.h ('k') | ui/aura/test/aura_test_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/aura/env.h" 5 #include "ui/aura/env.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/threading/thread_local.h" 8 #include "base/threading/thread_local.h"
9 #include "ui/aura/env_observer.h" 9 #include "ui/aura/env_observer.h"
10 #include "ui/aura/input_state_lookup.h" 10 #include "ui/aura/input_state_lookup.h"
(...skipping 10 matching lines...) Expand all
21 21
22 // Env is thread local so that aura may be used on multiple threads. 22 // Env is thread local so that aura may be used on multiple threads.
23 base::LazyInstance<base::ThreadLocalPointer<Env> >::Leaky lazy_tls_ptr = 23 base::LazyInstance<base::ThreadLocalPointer<Env> >::Leaky lazy_tls_ptr =
24 LAZY_INSTANCE_INITIALIZER; 24 LAZY_INSTANCE_INITIALIZER;
25 25
26 } // namespace 26 } // namespace
27 27
28 //////////////////////////////////////////////////////////////////////////////// 28 ////////////////////////////////////////////////////////////////////////////////
29 // Env, public: 29 // Env, public:
30 30
31 Env::~Env() { 31 // static
32 FOR_EACH_OBSERVER(EnvObserver, observers_, OnWillDestroyEnv()); 32 void Env::CreateInstance(bool create_event_source) {
33 DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get()); 33 if (!lazy_tls_ptr.Pointer()->Get())
34 lazy_tls_ptr.Pointer()->Set(NULL); 34 (new Env())->Init(create_event_source);
35 } 35 }
36 36
37 // static 37 // static
38 scoped_ptr<Env> Env::CreateInstance() {
39 DCHECK(!lazy_tls_ptr.Pointer()->Get());
40 scoped_ptr<Env> env(new Env());
41 env->Init();
42 return env.Pass();
43 }
44
45 // static
46 Env* Env::GetInstance() { 38 Env* Env::GetInstance() {
47 Env* env = lazy_tls_ptr.Pointer()->Get(); 39 Env* env = lazy_tls_ptr.Pointer()->Get();
48 DCHECK(env) << "Env::CreateInstance must be called before getting the " 40 DCHECK(env) << "Env::CreateInstance must be called before getting the "
49 "instance of Env."; 41 "instance of Env.";
50 return env; 42 return env;
51 } 43 }
52 44
53 // static 45 // static
54 Env* Env::GetInstanceDontCreate() { 46 Env* Env::GetInstanceDontCreate() {
55 return lazy_tls_ptr.Pointer()->Get(); 47 return lazy_tls_ptr.Pointer()->Get();
56 } 48 }
57 49
50 // static
51 void Env::DeleteInstance() {
52 delete lazy_tls_ptr.Pointer()->Get();
53 }
54
58 void Env::AddObserver(EnvObserver* observer) { 55 void Env::AddObserver(EnvObserver* observer) {
59 observers_.AddObserver(observer); 56 observers_.AddObserver(observer);
60 } 57 }
61 58
62 void Env::RemoveObserver(EnvObserver* observer) { 59 void Env::RemoveObserver(EnvObserver* observer) {
63 observers_.RemoveObserver(observer); 60 observers_.RemoveObserver(observer);
64 } 61 }
65 62
66 bool Env::IsMouseButtonDown() const { 63 bool Env::IsMouseButtonDown() const {
67 return input_state_lookup_.get() ? input_state_lookup_->IsMouseButtonDown() : 64 return input_state_lookup_.get() ? input_state_lookup_->IsMouseButtonDown() :
68 mouse_button_flags_ != 0; 65 mouse_button_flags_ != 0;
69 } 66 }
70 67
71 //////////////////////////////////////////////////////////////////////////////// 68 ////////////////////////////////////////////////////////////////////////////////
72 // Env, private: 69 // Env, private:
73 70
74 Env::Env() 71 Env::Env()
75 : mouse_button_flags_(0), 72 : mouse_button_flags_(0),
76 is_touch_down_(false), 73 is_touch_down_(false),
77 input_state_lookup_(InputStateLookup::Create().Pass()), 74 input_state_lookup_(InputStateLookup::Create().Pass()),
78 context_factory_(NULL) { 75 context_factory_(NULL) {
79 DCHECK(lazy_tls_ptr.Pointer()->Get() == NULL); 76 DCHECK(lazy_tls_ptr.Pointer()->Get() == NULL);
80 lazy_tls_ptr.Pointer()->Set(this); 77 lazy_tls_ptr.Pointer()->Set(this);
81 } 78 }
82 79
83 void Env::Init() { 80 Env::~Env() {
81 FOR_EACH_OBSERVER(EnvObserver, observers_, OnWillDestroyEnv());
82 DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get());
83 lazy_tls_ptr.Pointer()->Set(NULL);
84 }
85
86 void Env::Init(bool create_event_source) {
84 #if defined(USE_OZONE) 87 #if defined(USE_OZONE)
85 // The ozone platform can provide its own event source. So initialize the 88 // The ozone platform can provide its own event source. So initialize the
86 // platform before creating the default event source. 89 // platform before creating the default event source.
87 ui::OzonePlatform::InitializeForUI(); 90 ui::OzonePlatform::InitializeForUI();
88 #endif 91 #endif
89 if (!ui::PlatformEventSource::GetInstance()) 92 if (create_event_source && !ui::PlatformEventSource::GetInstance())
90 event_source_ = ui::PlatformEventSource::CreateDefault(); 93 event_source_ = ui::PlatformEventSource::CreateDefault();
91 } 94 }
92 95
93 void Env::NotifyWindowInitialized(Window* window) { 96 void Env::NotifyWindowInitialized(Window* window) {
94 FOR_EACH_OBSERVER(EnvObserver, observers_, OnWindowInitialized(window)); 97 FOR_EACH_OBSERVER(EnvObserver, observers_, OnWindowInitialized(window));
95 } 98 }
96 99
97 void Env::NotifyHostInitialized(WindowTreeHost* host) { 100 void Env::NotifyHostInitialized(WindowTreeHost* host) {
98 FOR_EACH_OBSERVER(EnvObserver, observers_, OnHostInitialized(host)); 101 FOR_EACH_OBSERVER(EnvObserver, observers_, OnHostInitialized(host));
99 } 102 }
(...skipping 16 matching lines...) Expand all
116 scoped_ptr<ui::EventTargetIterator> Env::GetChildIterator() const { 119 scoped_ptr<ui::EventTargetIterator> Env::GetChildIterator() const {
117 return nullptr; 120 return nullptr;
118 } 121 }
119 122
120 ui::EventTargeter* Env::GetEventTargeter() { 123 ui::EventTargeter* Env::GetEventTargeter() {
121 NOTREACHED(); 124 NOTREACHED();
122 return NULL; 125 return NULL;
123 } 126 }
124 127
125 } // namespace aura 128 } // namespace aura
OLDNEW
« 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