OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/views/mus/window_manager_connection.h" | 5 #include "ui/views/mus/window_manager_connection.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 using WindowManagerConnectionPtr = | 30 using WindowManagerConnectionPtr = |
31 base::ThreadLocalPointer<views::WindowManagerConnection>; | 31 base::ThreadLocalPointer<views::WindowManagerConnection>; |
32 | 32 |
33 // Env is thread local so that aura may be used on multiple threads. | 33 // Env is thread local so that aura may be used on multiple threads. |
34 base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr = | 34 base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr = |
35 LAZY_INSTANCE_INITIALIZER; | 35 LAZY_INSTANCE_INITIALIZER; |
36 | 36 |
37 } // namespace | 37 } // namespace |
38 | 38 |
| 39 WindowManagerConnection::~WindowManagerConnection() { |
| 40 // ~WindowTreeClient calls back to us (we're its delegate), destroy it while |
| 41 // we are still valid. |
| 42 client_.reset(); |
| 43 ui::Clipboard::DestroyClipboardForCurrentThread(); |
| 44 ui::GpuService::Terminate(); |
| 45 lazy_tls_ptr.Pointer()->Set(nullptr); |
| 46 |
| 47 if (ViewsDelegate::GetInstance()) { |
| 48 ViewsDelegate::GetInstance()->set_native_widget_factory( |
| 49 ViewsDelegate::NativeWidgetFactory()); |
| 50 } |
| 51 } |
| 52 |
39 // static | 53 // static |
40 std::unique_ptr<WindowManagerConnection> WindowManagerConnection::Create( | 54 std::unique_ptr<WindowManagerConnection> WindowManagerConnection::Create( |
41 shell::Connector* connector, | 55 shell::Connector* connector, |
42 const shell::Identity& identity) { | 56 const shell::Identity& identity) { |
43 DCHECK(!lazy_tls_ptr.Pointer()->Get()); | 57 DCHECK(!lazy_tls_ptr.Pointer()->Get()); |
44 WindowManagerConnection* connection = | 58 WindowManagerConnection* connection = |
45 new WindowManagerConnection(connector, identity); | 59 new WindowManagerConnection(connector, identity); |
46 DCHECK(lazy_tls_ptr.Pointer()->Get()); | 60 DCHECK(lazy_tls_ptr.Pointer()->Get()); |
47 return base::WrapUnique(connection); | 61 return base::WrapUnique(connection); |
48 } | 62 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 std::unique_ptr<ClipboardMus> clipboard(new ClipboardMus); | 163 std::unique_ptr<ClipboardMus> clipboard(new ClipboardMus); |
150 clipboard->Init(connector); | 164 clipboard->Init(connector); |
151 ui::Clipboard::SetClipboardForCurrentThread(std::move(clipboard)); | 165 ui::Clipboard::SetClipboardForCurrentThread(std::move(clipboard)); |
152 | 166 |
153 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind( | 167 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind( |
154 &WindowManagerConnection::CreateNativeWidgetMus, | 168 &WindowManagerConnection::CreateNativeWidgetMus, |
155 base::Unretained(this), | 169 base::Unretained(this), |
156 std::map<std::string, std::vector<uint8_t>>())); | 170 std::map<std::string, std::vector<uint8_t>>())); |
157 } | 171 } |
158 | 172 |
159 WindowManagerConnection::~WindowManagerConnection() { | |
160 // ~WindowTreeClient calls back to us (we're its delegate), destroy it while | |
161 // we are still valid. | |
162 client_.reset(); | |
163 ui::Clipboard::DestroyClipboardForCurrentThread(); | |
164 ui::GpuService::Terminate(); | |
165 lazy_tls_ptr.Pointer()->Set(nullptr); | |
166 | |
167 if (ViewsDelegate::GetInstance()) { | |
168 ViewsDelegate::GetInstance()->set_native_widget_factory( | |
169 ViewsDelegate::NativeWidgetFactory()); | |
170 } | |
171 } | |
172 | |
173 bool WindowManagerConnection::HasPointerDownWatcher() { | 173 bool WindowManagerConnection::HasPointerDownWatcher() { |
174 // Check to see if we really have any observers left. This doesn't use | 174 // Check to see if we really have any observers left. This doesn't use |
175 // base::ObserverList<>::might_have_observers() because that returns true | 175 // base::ObserverList<>::might_have_observers() because that returns true |
176 // during iteration over the list even when the last observer is removed. | 176 // during iteration over the list even when the last observer is removed. |
177 base::ObserverList<PointerDownWatcher>::Iterator iterator( | 177 base::ObserverList<PointerDownWatcher>::Iterator iterator( |
178 &pointer_down_watchers_); | 178 &pointer_down_watchers_); |
179 return !!iterator.GetNext(); | 179 return !!iterator.GetNext(); |
180 } | 180 } |
181 | 181 |
182 bool WindowManagerConnection::HasTouchEventWatcher() { | 182 bool WindowManagerConnection::HasTouchEventWatcher() { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { | 234 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { |
235 if (client_) | 235 if (client_) |
236 NativeWidgetMus::NotifyFrameChanged(client_.get()); | 236 NativeWidgetMus::NotifyFrameChanged(client_.get()); |
237 } | 237 } |
238 | 238 |
239 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { | 239 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { |
240 return client_->GetCursorScreenPoint(); | 240 return client_->GetCursorScreenPoint(); |
241 } | 241 } |
242 | 242 |
243 } // namespace views | 243 } // namespace views |
OLD | NEW |