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

Unified Diff: ui/views/mus/window_manager_connection.cc

Issue 2026623002: views/mus: Have explicit ownership of views::WindowManagerConnection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
Index: ui/views/mus/window_manager_connection.cc
diff --git a/ui/views/mus/window_manager_connection.cc b/ui/views/mus/window_manager_connection.cc
index 9924b2d56fed2024a57e2a4fb4968fc21991a6ca..743c2d0260743e26ec005a57f576836374da6103 100644
--- a/ui/views/mus/window_manager_connection.cc
+++ b/ui/views/mus/window_manager_connection.cc
@@ -35,10 +35,14 @@ base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr =
} // namespace
// static
-void WindowManagerConnection::Create(shell::Connector* connector,
- const shell::Identity& identity) {
+std::unique_ptr<WindowManagerConnection> WindowManagerConnection::Create(
+ shell::Connector* connector,
+ const shell::Identity& identity) {
DCHECK(!lazy_tls_ptr.Pointer()->Get());
- lazy_tls_ptr.Pointer()->Set(new WindowManagerConnection(connector, identity));
+ WindowManagerConnection* connection =
+ new WindowManagerConnection(connector, identity);
+ DCHECK(lazy_tls_ptr.Pointer()->Get());
+ return base::WrapUnique(connection);
}
// static
@@ -53,12 +57,6 @@ bool WindowManagerConnection::Exists() {
return !!lazy_tls_ptr.Pointer()->Get();
}
-// static
-void WindowManagerConnection::Reset() {
- delete Get();
- lazy_tls_ptr.Pointer()->Set(nullptr);
-}
-
mus::Window* WindowManagerConnection::NewWindow(
const std::map<std::string, std::vector<uint8_t>>& properties) {
return window_tree_connection_->NewTopLevelWindow(&properties);
@@ -102,17 +100,21 @@ WindowManagerConnection::WindowManagerConnection(
const shell::Identity& identity)
: connector_(connector),
identity_(identity),
- window_tree_connection_(nullptr) {
+ created_device_data_manager_(false) {
+ lazy_tls_ptr.Pointer()->Set(this);
window_tree_connection_.reset(
mus::WindowTreeConnection::Create(this, connector_));
screen_.reset(new ScreenMus(this));
screen_->Init(connector);
- // TODO(sad): We should have a DeviceDataManager implementation that talks to
- // a mojo service to learn about the input-devices on the system.
- // http://crbug.com/601981
- ui::DeviceDataManager::CreateInstance();
+ if (!ui::DeviceDataManager::HasInstance()) {
+ // TODO(sad): We should have a DeviceDataManager implementation that talks
+ // to a mojo service to learn about the input-devices on the system.
+ // http://crbug.com/601981
+ ui::DeviceDataManager::CreateInstance();
+ created_device_data_manager_ = true;
+ }
ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind(
&WindowManagerConnection::CreateNativeWidgetMus,
@@ -124,8 +126,9 @@ WindowManagerConnection::~WindowManagerConnection() {
// ~WindowTreeConnection calls back to us (we're the WindowTreeDelegate),
// destroy it while we are still valid.
window_tree_connection_.reset();
-
- ui::DeviceDataManager::DeleteInstance();
+ if (created_device_data_manager_)
+ ui::DeviceDataManager::DeleteInstance();
+ lazy_tls_ptr.Pointer()->Set(nullptr);
}
bool WindowManagerConnection::HasPointerWatcher() {
« mash/quick_launch/quick_launch_application.h ('K') | « ui/views/mus/window_manager_connection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698