Skip to content

Commit

Permalink
views/mus: Have explicit ownership of views::WindowManagerConnection.
Browse files Browse the repository at this point in the history
TBR=ben@chromium.org for API call update in //services/navigation
BUG=none

Review-Url: https://codereview.chromium.org/2026623002
Cr-Commit-Position: refs/heads/master@{#398343}
  • Loading branch information
sadrulhc authored and Commit bot committed Jun 7, 2016
1 parent e873b56 commit 4b04c1d
Show file tree
Hide file tree
Showing 25 changed files with 72 additions and 40 deletions.
4 changes: 3 additions & 1 deletion ash/sysui/sysui_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ class AshInit {
InitializeResourceBundle(connector);
aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak"));
MaterialDesignController::Initialize();
views::WindowManagerConnection::Create(connector, identity);
window_manager_connection_ =
views::WindowManagerConnection::Create(connector, identity);

display::Screen* screen = display::Screen::GetScreen();
DCHECK(screen);
Expand Down Expand Up @@ -300,6 +301,7 @@ class AshInit {
std::unique_ptr<views::AuraInit> aura_init_;
ShellDelegateMus* ash_delegate_ = nullptr;
std::unique_ptr<NativeWidgetFactory> native_widget_factory_;
std::unique_ptr<views::WindowManagerConnection> window_manager_connection_;

DISALLOW_COPY_AND_ASSIGN(AshInit);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ void ChromeBrowserMainExtraPartsViews::PreProfileInit() {
content::MojoShellConnection* mojo_shell_connection =
content::MojoShellConnection::Get();
if (mojo_shell_connection && mojo_shell_connection->UsingExternalShell()) {
views::WindowManagerConnection::Create(
window_manager_connection_ = views::WindowManagerConnection::Create(
mojo_shell_connection->GetConnector(),
mojo_shell_connection->GetIdentity());
}
#endif
#endif // defined(USE_AURA) && defined(MOJO_SHELL_CLIENT)
ChromeBrowserMainExtraParts::PreProfileInit();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace views {
class ViewsDelegate;
class WindowManagerConnection;
}

#if defined(USE_AURA)
Expand All @@ -36,6 +37,9 @@ class ChromeBrowserMainExtraPartsViews : public ChromeBrowserMainExtraParts {
#if defined(USE_AURA)
std::unique_ptr<wm::WMState> wm_state_;
#endif
#if defined(USE_AURA) && defined(MOJO_SHELL_CLIENT)
std::unique_ptr<views::WindowManagerConnection> window_manager_connection_;
#endif

DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainExtraPartsViews);
};
Expand Down
3 changes: 2 additions & 1 deletion mash/browser/browser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ void Browser::Initialize(shell::Connector* connector,
tracing_.Initialize(connector, identity.name());

aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak"));
views::WindowManagerConnection::Create(connector, identity);
window_manager_connection_ =
views::WindowManagerConnection::Create(connector, identity);
}

bool Browser::AcceptConnection(shell::Connection* connection) {
Expand Down
2 changes: 2 additions & 0 deletions mash/browser/browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace views {
class AuraInit;
class Widget;
class WindowManagerConnection;
}

namespace mash {
Expand Down Expand Up @@ -54,6 +55,7 @@ class Browser : public shell::ShellClient,

mojo::TracingImpl tracing_;
std::unique_ptr<views::AuraInit> aura_init_;
std::unique_ptr<views::WindowManagerConnection> window_manager_connection_;

DISALLOW_COPY_AND_ASSIGN(Browser);
};
Expand Down
3 changes: 2 additions & 1 deletion mash/catalog_viewer/catalog_viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ void CatalogViewer::Initialize(shell::Connector* connector,
tracing_.Initialize(connector, identity.name());

aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak"));
views::WindowManagerConnection::Create(connector, identity);
window_manager_connection_ =
views::WindowManagerConnection::Create(connector, identity);
}

bool CatalogViewer::AcceptConnection(shell::Connection* connection) {
Expand Down
2 changes: 2 additions & 0 deletions mash/catalog_viewer/catalog_viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace views {
class AuraInit;
class Widget;
class WindowManagerConnection;
}

namespace mash {
Expand Down Expand Up @@ -53,6 +54,7 @@ class CatalogViewer : public shell::ShellClient,

mojo::TracingImpl tracing_;
std::unique_ptr<views::AuraInit> aura_init_;
std::unique_ptr<views::WindowManagerConnection> window_manager_connection_;

DISALLOW_COPY_AND_ASSIGN(CatalogViewer);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ void ViewsExamplesApplicationDelegate::Initialize(
uint32_t id) {
tracing_.Initialize(connector, identity.name());
aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak"));
views::WindowManagerConnection::Create(connector, identity);
window_manager_connection_ =
views::WindowManagerConnection::Create(connector, identity);
}

bool ViewsExamplesApplicationDelegate::AcceptConnection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace views {
class AuraInit;
class WindowManagerConnection;
}

class ViewsExamplesApplicationDelegate
Expand Down Expand Up @@ -43,6 +44,7 @@ class ViewsExamplesApplicationDelegate

mojo::TracingImpl tracing_;
std::unique_ptr<views::AuraInit> aura_init_;
std::unique_ptr<views::WindowManagerConnection> window_manager_connection_;

DISALLOW_COPY_AND_ASSIGN(ViewsExamplesApplicationDelegate);
};
Expand Down
3 changes: 2 additions & 1 deletion mash/example/window_type_launcher/window_type_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ void WindowTypeLauncher::Initialize(shell::Connector* connector,
connector_ = connector;
aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak"));

views::WindowManagerConnection::Create(connector, identity);
window_manager_connection_ =
views::WindowManagerConnection::Create(connector, identity);
}

bool WindowTypeLauncher::AcceptConnection(shell::Connection* connection) {
Expand Down
2 changes: 2 additions & 0 deletions mash/example/window_type_launcher/window_type_launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace views {
class AuraInit;
class Widget;
class WindowManagerConnection;
}

class WindowTypeLauncher
Expand Down Expand Up @@ -46,6 +47,7 @@ class WindowTypeLauncher
std::vector<views::Widget*> windows_;

std::unique_ptr<views::AuraInit> aura_init_;
std::unique_ptr<views::WindowManagerConnection> window_manager_connection_;

DISALLOW_COPY_AND_ASSIGN(WindowTypeLauncher);
};
Expand Down
20 changes: 10 additions & 10 deletions mash/login/login.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ class UI : public views::WidgetDelegateView,
const shell::Identity& identity,
Login* login) {
UI* ui = new UI(login, connector);
ui->StartWindowManager();

views::WindowManagerConnection::Create(connector, identity);
ui->StartWindowManager(identity);

views::Widget* widget = new views::Widget;
views::Widget::InitParams params(
Expand Down Expand Up @@ -79,7 +77,7 @@ class UI : public views::WidgetDelegateView,
}
~UI() override {
// Prevent the window manager from restarting during graceful shutdown.
window_manager_connection_->SetConnectionLostClosure(base::Closure());
mash_wm_connection_->SetConnectionLostClosure(base::Closure());
base::MessageLoop::current()->QuitWhenIdle();
}

Expand Down Expand Up @@ -114,10 +112,12 @@ class UI : public views::WidgetDelegateView,
// Overridden from views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;

void StartWindowManager() {
window_manager_connection_ = connector_->Connect("mojo:ash");
window_manager_connection_->SetConnectionLostClosure(
base::Bind(&UI::StartWindowManager, base::Unretained(this)));
void StartWindowManager(const shell::Identity& identity) {
mash_wm_connection_ = connector_->Connect("mojo:ash");
mash_wm_connection_->SetConnectionLostClosure(
base::Bind(&UI::StartWindowManager, base::Unretained(this), identity));
window_manager_connection_ =
views::WindowManagerConnection::Create(connector_, identity);
}

Login* login_;
Expand All @@ -126,7 +126,8 @@ class UI : public views::WidgetDelegateView,
const std::string user_id_2_;
views::LabelButton* login_button_1_;
views::LabelButton* login_button_2_;
std::unique_ptr<shell::Connection> window_manager_connection_;
std::unique_ptr<shell::Connection> mash_wm_connection_;
std::unique_ptr<views::WindowManagerConnection> window_manager_connection_;

DISALLOW_COPY_AND_ASSIGN(UI);
};
Expand Down Expand Up @@ -182,7 +183,6 @@ class Login : public shell::ShellClient,
std::unique_ptr<views::AuraInit> aura_init_;
mojo::BindingSet<mojom::Login> bindings_;
mus::mojom::UserAccessManagerPtr user_access_manager_;
std::unique_ptr<shell::Connection> window_manager_connection_;

DISALLOW_COPY_AND_ASSIGN(Login);
};
Expand Down
3 changes: 2 additions & 1 deletion mash/quick_launch/quick_launch_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ void QuickLaunchApplication::Initialize(shell::Connector* connector,
tracing_.Initialize(connector, identity.name());

aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak"));
views::WindowManagerConnection::Create(connector, identity);
window_manager_connection_ =
views::WindowManagerConnection::Create(connector, identity);

Launch(mojom::kWindow, mojom::LaunchMode::MAKE_NEW);
}
Expand Down
2 changes: 2 additions & 0 deletions mash/quick_launch/quick_launch_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace views {
class AuraInit;
class Widget;
class WindowManagerConnection;
}

namespace mash {
Expand Down Expand Up @@ -51,6 +52,7 @@ class QuickLaunchApplication

mojo::TracingImpl tracing_;
std::unique_ptr<views::AuraInit> aura_init_;
std::unique_ptr<views::WindowManagerConnection> window_manager_connection_;

DISALLOW_COPY_AND_ASSIGN(QuickLaunchApplication);
};
Expand Down
3 changes: 2 additions & 1 deletion mash/screenlock/screenlock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ void Screenlock::Initialize(shell::Connector* connector,
bindings_.CreateInterfacePtrAndBind(this));

aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak"));
views::WindowManagerConnection::Create(connector, identity);
window_manager_connection_ =
views::WindowManagerConnection::Create(connector, identity);

views::Widget* widget = new views::Widget;
views::Widget::InitParams params(
Expand Down
2 changes: 2 additions & 0 deletions mash/screenlock/screenlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace views {
class AuraInit;
class WindowManagerConnection;
}

namespace mash {
Expand All @@ -38,6 +39,7 @@ class Screenlock : public shell::ShellClient,

mojo::TracingImpl tracing_;
std::unique_ptr<views::AuraInit> aura_init_;
std::unique_ptr<views::WindowManagerConnection> window_manager_connection_;
mojo::BindingSet<session::mojom::ScreenlockStateListener> bindings_;

DISALLOW_COPY_AND_ASSIGN(Screenlock);
Expand Down
3 changes: 2 additions & 1 deletion mash/task_viewer/task_viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ void TaskViewer::Initialize(shell::Connector* connector,
tracing_.Initialize(connector, identity.name());

aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak"));
views::WindowManagerConnection::Create(connector, identity);
window_manager_connection_ =
views::WindowManagerConnection::Create(connector, identity);
}

bool TaskViewer::AcceptConnection(shell::Connection* connection) {
Expand Down
2 changes: 2 additions & 0 deletions mash/task_viewer/task_viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace views {
class AuraInit;
class Widget;
class WindowManagerConnection;
}

namespace mash {
Expand Down Expand Up @@ -52,6 +53,7 @@ class TaskViewer : public shell::ShellClient,

mojo::TracingImpl tracing_;
std::unique_ptr<views::AuraInit> aura_init_;
std::unique_ptr<views::WindowManagerConnection> window_manager_connection_;

DISALLOW_COPY_AND_ASSIGN(TaskViewer);
};
Expand Down
3 changes: 2 additions & 1 deletion mash/webtest/webtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ void Webtest::Initialize(shell::Connector* connector,
tracing_.Initialize(connector, identity.name());

aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak"));
views::WindowManagerConnection::Create(connector, identity);
window_manager_connection_ =
views::WindowManagerConnection::Create(connector, identity);
}

bool Webtest::AcceptConnection(shell::Connection* connection) {
Expand Down
2 changes: 2 additions & 0 deletions mash/webtest/webtest.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace views {
class AuraInit;
class Widget;
class WindowManagerConnection;
}

namespace mash {
Expand Down Expand Up @@ -52,6 +53,7 @@ class Webtest

mojo::TracingImpl tracing_;
std::unique_ptr<views::AuraInit> aura_init_;
std::unique_ptr<views::WindowManagerConnection> window_manager_connection_;

DISALLOW_COPY_AND_ASSIGN(Webtest);
};
Expand Down
2 changes: 1 addition & 1 deletion services/navigation/content_client/browser_main_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void BrowserMainParts::PreMainMessageLoopRun() {
content::MojoShellConnection* mojo_shell_connection =
content::MojoShellConnection::Get();
if (mojo_shell_connection) {
views::WindowManagerConnection::Create(
window_manager_connection_ = views::WindowManagerConnection::Create(
mojo_shell_connection->GetConnector(),
mojo_shell_connection->GetIdentity());
}
Expand Down
2 changes: 2 additions & 0 deletions services/navigation/content_client/browser_main_parts.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class NetLog;

namespace views {
class ViewsDelegate;
class WindowManagerConnection;
}

namespace navigation {
Expand Down Expand Up @@ -48,6 +49,7 @@ class BrowserMainParts : public content::BrowserMainParts {
std::unique_ptr<net::NetLog> net_log_;
std::unique_ptr<content::ShellBrowserContext> browser_context_;
std::unique_ptr<views::ViewsDelegate> views_delegate_;
std::unique_ptr<views::WindowManagerConnection> window_manager_connection_;

Navigation* navigation_ = nullptr;

Expand Down
8 changes: 4 additions & 4 deletions ui/views/mus/views_mus_test_suite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ class PlatformTestHelperMus : public PlatformTestHelper {
const shell::Identity& identity) {
// It is necessary to recreate the WindowManagerConnection for each test,
// since a new MessageLoop is created for each test.
WindowManagerConnection::Create(connector, identity);
connection_ = WindowManagerConnection::Create(connector, identity);
}
~PlatformTestHelperMus() override { WindowManagerConnection::Reset(); }
~PlatformTestHelperMus() override {}

private:
std::unique_ptr<WindowManagerConnection> connection_;

DISALLOW_COPY_AND_ASSIGN(PlatformTestHelperMus);
};

Expand Down Expand Up @@ -85,8 +87,6 @@ class ShellConnection {
}

~ShellConnection() {
if (views::WindowManagerConnection::Exists())
views::WindowManagerConnection::Reset();
base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC,
base::WaitableEvent::InitialState::NOT_SIGNALED);
thread_.task_runner()->PostTask(
Expand Down
Loading

0 comments on commit 4b04c1d

Please sign in to comment.