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 17 matching lines...) Expand all Loading... |
28 using WindowManagerConnectionPtr = | 28 using WindowManagerConnectionPtr = |
29 base::ThreadLocalPointer<views::WindowManagerConnection>; | 29 base::ThreadLocalPointer<views::WindowManagerConnection>; |
30 | 30 |
31 // Env is thread local so that aura may be used on multiple threads. | 31 // Env is thread local so that aura may be used on multiple threads. |
32 base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr = | 32 base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr = |
33 LAZY_INSTANCE_INITIALIZER; | 33 LAZY_INSTANCE_INITIALIZER; |
34 | 34 |
35 } // namespace | 35 } // namespace |
36 | 36 |
37 // static | 37 // static |
38 void WindowManagerConnection::Create(shell::Connector* connector, | 38 std::unique_ptr<WindowManagerConnection> WindowManagerConnection::Create( |
39 const shell::Identity& identity) { | 39 shell::Connector* connector, |
| 40 const shell::Identity& identity) { |
40 DCHECK(!lazy_tls_ptr.Pointer()->Get()); | 41 DCHECK(!lazy_tls_ptr.Pointer()->Get()); |
41 lazy_tls_ptr.Pointer()->Set(new WindowManagerConnection(connector, identity)); | 42 WindowManagerConnection* connection = |
| 43 new WindowManagerConnection(connector, identity); |
| 44 DCHECK(lazy_tls_ptr.Pointer()->Get()); |
| 45 return base::WrapUnique(connection); |
42 } | 46 } |
43 | 47 |
44 // static | 48 // static |
45 WindowManagerConnection* WindowManagerConnection::Get() { | 49 WindowManagerConnection* WindowManagerConnection::Get() { |
46 WindowManagerConnection* connection = lazy_tls_ptr.Pointer()->Get(); | 50 WindowManagerConnection* connection = lazy_tls_ptr.Pointer()->Get(); |
47 DCHECK(connection); | 51 DCHECK(connection); |
48 return connection; | 52 return connection; |
49 } | 53 } |
50 | 54 |
51 // static | 55 // static |
52 bool WindowManagerConnection::Exists() { | 56 bool WindowManagerConnection::Exists() { |
53 return !!lazy_tls_ptr.Pointer()->Get(); | 57 return !!lazy_tls_ptr.Pointer()->Get(); |
54 } | 58 } |
55 | 59 |
56 // static | |
57 void WindowManagerConnection::Reset() { | |
58 delete Get(); | |
59 lazy_tls_ptr.Pointer()->Set(nullptr); | |
60 } | |
61 | |
62 mus::Window* WindowManagerConnection::NewWindow( | 60 mus::Window* WindowManagerConnection::NewWindow( |
63 const std::map<std::string, std::vector<uint8_t>>& properties) { | 61 const std::map<std::string, std::vector<uint8_t>>& properties) { |
64 return window_tree_connection_->NewTopLevelWindow(&properties); | 62 return window_tree_connection_->NewTopLevelWindow(&properties); |
65 } | 63 } |
66 | 64 |
67 NativeWidget* WindowManagerConnection::CreateNativeWidgetMus( | 65 NativeWidget* WindowManagerConnection::CreateNativeWidgetMus( |
68 const std::map<std::string, std::vector<uint8_t>>& props, | 66 const std::map<std::string, std::vector<uint8_t>>& props, |
69 const Widget::InitParams& init_params, | 67 const Widget::InitParams& init_params, |
70 internal::NativeWidgetDelegate* delegate) { | 68 internal::NativeWidgetDelegate* delegate) { |
71 std::map<std::string, std::vector<uint8_t>> properties = props; | 69 std::map<std::string, std::vector<uint8_t>> properties = props; |
(...skipping 23 matching lines...) Expand all Loading... |
95 // Last PointerWatcher removed, stop the event observer. | 93 // Last PointerWatcher removed, stop the event observer. |
96 window_tree_connection_->SetEventObserver(nullptr); | 94 window_tree_connection_->SetEventObserver(nullptr); |
97 } | 95 } |
98 } | 96 } |
99 | 97 |
100 WindowManagerConnection::WindowManagerConnection( | 98 WindowManagerConnection::WindowManagerConnection( |
101 shell::Connector* connector, | 99 shell::Connector* connector, |
102 const shell::Identity& identity) | 100 const shell::Identity& identity) |
103 : connector_(connector), | 101 : connector_(connector), |
104 identity_(identity), | 102 identity_(identity), |
105 window_tree_connection_(nullptr) { | 103 created_device_data_manager_(false) { |
| 104 lazy_tls_ptr.Pointer()->Set(this); |
106 window_tree_connection_.reset( | 105 window_tree_connection_.reset( |
107 mus::WindowTreeConnection::Create(this, connector_)); | 106 mus::WindowTreeConnection::Create(this, connector_)); |
108 | 107 |
109 screen_.reset(new ScreenMus(this)); | 108 screen_.reset(new ScreenMus(this)); |
110 screen_->Init(connector); | 109 screen_->Init(connector); |
111 | 110 |
112 // TODO(sad): We should have a DeviceDataManager implementation that talks to | 111 if (!ui::DeviceDataManager::HasInstance()) { |
113 // a mojo service to learn about the input-devices on the system. | 112 // TODO(sad): We should have a DeviceDataManager implementation that talks |
114 // http://crbug.com/601981 | 113 // to a mojo service to learn about the input-devices on the system. |
115 ui::DeviceDataManager::CreateInstance(); | 114 // http://crbug.com/601981 |
| 115 ui::DeviceDataManager::CreateInstance(); |
| 116 created_device_data_manager_ = true; |
| 117 } |
116 | 118 |
117 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind( | 119 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind( |
118 &WindowManagerConnection::CreateNativeWidgetMus, | 120 &WindowManagerConnection::CreateNativeWidgetMus, |
119 base::Unretained(this), | 121 base::Unretained(this), |
120 std::map<std::string, std::vector<uint8_t>>())); | 122 std::map<std::string, std::vector<uint8_t>>())); |
121 } | 123 } |
122 | 124 |
123 WindowManagerConnection::~WindowManagerConnection() { | 125 WindowManagerConnection::~WindowManagerConnection() { |
124 // ~WindowTreeConnection calls back to us (we're the WindowTreeDelegate), | 126 // ~WindowTreeConnection calls back to us (we're the WindowTreeDelegate), |
125 // destroy it while we are still valid. | 127 // destroy it while we are still valid. |
126 window_tree_connection_.reset(); | 128 window_tree_connection_.reset(); |
127 | 129 if (created_device_data_manager_) |
128 ui::DeviceDataManager::DeleteInstance(); | 130 ui::DeviceDataManager::DeleteInstance(); |
| 131 lazy_tls_ptr.Pointer()->Set(nullptr); |
129 } | 132 } |
130 | 133 |
131 bool WindowManagerConnection::HasPointerWatcher() { | 134 bool WindowManagerConnection::HasPointerWatcher() { |
132 // Check to see if we really have any observers left. This doesn't use | 135 // Check to see if we really have any observers left. This doesn't use |
133 // base::ObserverList<>::might_have_observers() because that returns true | 136 // base::ObserverList<>::might_have_observers() because that returns true |
134 // during iteration over the list even when the last observer is removed. | 137 // during iteration over the list even when the last observer is removed. |
135 base::ObserverList<PointerWatcher>::Iterator iterator(&pointer_watchers_); | 138 base::ObserverList<PointerWatcher>::Iterator iterator(&pointer_watchers_); |
136 return !!iterator.GetNext(); | 139 return !!iterator.GetNext(); |
137 } | 140 } |
138 | 141 |
(...skipping 30 matching lines...) Expand all Loading... |
169 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { | 172 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { |
170 if (window_tree_connection_) | 173 if (window_tree_connection_) |
171 NativeWidgetMus::NotifyFrameChanged(window_tree_connection_.get()); | 174 NativeWidgetMus::NotifyFrameChanged(window_tree_connection_.get()); |
172 } | 175 } |
173 | 176 |
174 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { | 177 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { |
175 return window_tree_connection_->GetCursorScreenPoint(); | 178 return window_tree_connection_->GetCursorScreenPoint(); |
176 } | 179 } |
177 | 180 |
178 } // namespace views | 181 } // namespace views |
OLD | NEW |