| 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 client_->NewTopLevelWindow(&properties); | 62 return client_->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 // TYPE_CONTROL widgets require a NativeWidgetAura. So we let this fall | 69 // TYPE_CONTROL widgets require a NativeWidgetAura. So we let this fall |
| (...skipping 29 matching lines...) Expand all Loading... |
| 101 client_->SetEventObserver(nullptr); | 99 client_->SetEventObserver(nullptr); |
| 102 } | 100 } |
| 103 } | 101 } |
| 104 | 102 |
| 105 WindowManagerConnection::WindowManagerConnection( | 103 WindowManagerConnection::WindowManagerConnection( |
| 106 shell::Connector* connector, | 104 shell::Connector* connector, |
| 107 const shell::Identity& identity) | 105 const shell::Identity& identity) |
| 108 : connector_(connector), | 106 : connector_(connector), |
| 109 identity_(identity), | 107 identity_(identity), |
| 110 created_device_data_manager_(false) { | 108 created_device_data_manager_(false) { |
| 109 lazy_tls_ptr.Pointer()->Set(this); |
| 111 client_.reset(new mus::WindowTreeClient(this, nullptr, nullptr)); | 110 client_.reset(new mus::WindowTreeClient(this, nullptr, nullptr)); |
| 112 client_->ConnectViaWindowTreeFactory(connector_); | 111 client_->ConnectViaWindowTreeFactory(connector_); |
| 113 | 112 |
| 114 screen_.reset(new ScreenMus(this)); | 113 screen_.reset(new ScreenMus(this)); |
| 115 screen_->Init(connector); | 114 screen_->Init(connector); |
| 116 | 115 |
| 117 if (!ui::DeviceDataManager::HasInstance()) { | 116 if (!ui::DeviceDataManager::HasInstance()) { |
| 118 // TODO(sad): We should have a DeviceDataManager implementation that talks | 117 // TODO(sad): We should have a DeviceDataManager implementation that talks |
| 119 // to a mojo service to learn about the input-devices on the system. | 118 // to a mojo service to learn about the input-devices on the system. |
| 120 // http://crbug.com/601981 | 119 // http://crbug.com/601981 |
| 121 ui::DeviceDataManager::CreateInstance(); | 120 ui::DeviceDataManager::CreateInstance(); |
| 122 created_device_data_manager_ = true; | 121 created_device_data_manager_ = true; |
| 123 } | 122 } |
| 124 | 123 |
| 125 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind( | 124 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind( |
| 126 &WindowManagerConnection::CreateNativeWidgetMus, | 125 &WindowManagerConnection::CreateNativeWidgetMus, |
| 127 base::Unretained(this), | 126 base::Unretained(this), |
| 128 std::map<std::string, std::vector<uint8_t>>())); | 127 std::map<std::string, std::vector<uint8_t>>())); |
| 129 } | 128 } |
| 130 | 129 |
| 131 WindowManagerConnection::~WindowManagerConnection() { | 130 WindowManagerConnection::~WindowManagerConnection() { |
| 132 // ~WindowTreeClient calls back to us (we're its delegate), destroy it while | 131 // ~WindowTreeClient calls back to us (we're its delegate), destroy it while |
| 133 // we are still valid. | 132 // we are still valid. |
| 134 client_.reset(); | 133 client_.reset(); |
| 135 if (created_device_data_manager_) | 134 if (created_device_data_manager_) |
| 136 ui::DeviceDataManager::DeleteInstance(); | 135 ui::DeviceDataManager::DeleteInstance(); |
| 136 lazy_tls_ptr.Pointer()->Set(nullptr); |
| 137 | 137 |
| 138 if (ViewsDelegate::GetInstance()) { | 138 if (ViewsDelegate::GetInstance()) { |
| 139 ViewsDelegate::GetInstance()->set_native_widget_factory( | 139 ViewsDelegate::GetInstance()->set_native_widget_factory( |
| 140 ViewsDelegate::NativeWidgetFactory()); | 140 ViewsDelegate::NativeWidgetFactory()); |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 | 143 |
| 144 bool WindowManagerConnection::HasPointerWatcher() { | 144 bool WindowManagerConnection::HasPointerWatcher() { |
| 145 // Check to see if we really have any observers left. This doesn't use | 145 // Check to see if we really have any observers left. This doesn't use |
| 146 // base::ObserverList<>::might_have_observers() because that returns true | 146 // base::ObserverList<>::might_have_observers() because that returns true |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { | 182 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { |
| 183 if (client_) | 183 if (client_) |
| 184 NativeWidgetMus::NotifyFrameChanged(client_.get()); | 184 NativeWidgetMus::NotifyFrameChanged(client_.get()); |
| 185 } | 185 } |
| 186 | 186 |
| 187 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { | 187 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { |
| 188 return client_->GetCursorScreenPoint(); | 188 return client_->GetCursorScreenPoint(); |
| 189 } | 189 } |
| 190 | 190 |
| 191 } // namespace views | 191 } // namespace views |
| OLD | NEW |