Skip to content

Commit

Permalink
Remove the singleton instance get/delete methods from RootWindow (yay)
Browse files Browse the repository at this point in the history
http://crbug.com/112131
TEST=none

Review URL: http://codereview.chromium.org/9535025

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124635 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
ben@chromium.org committed Mar 2, 2012
1 parent 2712116 commit 58482fa
Show file tree
Hide file tree
Showing 26 changed files with 128 additions and 144 deletions.
21 changes: 13 additions & 8 deletions ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,7 @@ internal::WorkspaceController* Shell::TestApi::workspace_controller() {
// Shell, public:

Shell::Shell(ShellDelegate* delegate)
: root_filter_(new internal::RootWindowEventFilter),
#if !defined(OS_MACOSX)
nested_dispatcher_controller_(new NestedDispatcherController),
accelerator_controller_(new AcceleratorController),
#endif
: root_window_(new aura::RootWindow),
delegate_(delegate),
audio_controller_(NULL),
brightness_controller_(NULL),
Expand All @@ -283,8 +279,6 @@ Shell::Shell(ShellDelegate* delegate)
desktop_background_mode_(BACKGROUND_IMAGE),
root_window_layout_(NULL),
status_widget_(NULL) {
// Pass ownership of the filter to the root window.
GetRootWindow()->SetEventFilter(root_filter_);
}

Shell::~Shell() {
Expand Down Expand Up @@ -320,7 +314,10 @@ Shell::~Shell() {

// These need a valid Shell instance to clean up properly, so explicitly
// delete them before invalidating the instance.
// Alphabetical.
activation_controller_.reset();
drag_drop_controller_.reset();
shadow_controller_.reset();
window_cycle_controller_.reset();

// Launcher widget has a InputMethodBridge that references to
Expand Down Expand Up @@ -356,10 +353,18 @@ void Shell::DeleteInstance() {

// static
aura::RootWindow* Shell::GetRootWindow() {
return aura::RootWindow::GetInstance();
return GetInstance()->root_window_.get();
}

void Shell::Init() {
root_filter_ = new internal::RootWindowEventFilter;
#if !defined(OS_MACOSX)
nested_dispatcher_controller_.reset(new NestedDispatcherController);
accelerator_controller_.reset(new AcceleratorController);
#endif
// Pass ownership of the filter to the root window.
GetRootWindow()->SetEventFilter(root_filter_);

DCHECK(!GetRootWindowEventFilterCount());

// PartialScreenshotEventFilter must be the first one to capture key
Expand Down
2 changes: 2 additions & 0 deletions ash/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ class ASH_EXPORT Shell {
// when the screen is initially created.
static bool initially_hide_cursor_;

scoped_ptr<aura::RootWindow> root_window_;

internal::RootWindowEventFilter* root_filter_; // not owned

std::vector<WindowAndBoundsPair> to_restore_;
Expand Down
1 change: 0 additions & 1 deletion ash/shell/shell_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ int main(int argc, char** argv) {

ash::Shell::DeleteInstance();

aura::RootWindow::DeleteInstance();
aura::Env::DeleteInstance();

ui::CompositorTestSupport::Terminate();
Expand Down
13 changes: 5 additions & 8 deletions ash/test/ash_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,22 @@ namespace ash {
namespace test {

AshTestBase::AshTestBase() {
helper_.InitRootWindow(Shell::GetRootWindow());
}

AshTestBase::~AshTestBase() {
// Ensure that we don't use the previously-allocated static RootWindow object
// later -- on Linux, it holds a reference to our message loop's X connection.
aura::RootWindow::DeleteInstance();
}

void AshTestBase::SetUp() {
helper_.SetUp();

// Creates Shell and hook with Desktop.
TestShellDelegate* delegate = new TestShellDelegate;
Shell::WindowMode window_mode = Shell::MODE_OVERLAPPING;
if (GetOverrideWindowMode(&window_mode))
delegate->SetOverrideWindowMode(window_mode);
ash::Shell::CreateInstance(delegate);

helper_.SetUp();
helper_.InitRootWindow(Shell::GetRootWindow());

// Disable animations during tests.
ui::LayerAnimator::set_disable_animations_for_test(true);
}
Expand All @@ -40,10 +37,10 @@ void AshTestBase::TearDown() {
// Flush the message loop to finish pending release tasks.
RunAllPendingInMessageLoop();

helper_.TearDown();

// Tear down the shell.
Shell::DeleteInstance();

helper_.TearDown();
}

bool AshTestBase::GetOverrideWindowMode(Shell::WindowMode* window_mode) {
Expand Down
1 change: 0 additions & 1 deletion chrome/browser/chrome_browser_main_extra_parts_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,5 @@ void ChromeBrowserMainExtraPartsAura::PostProfileInit() {

void ChromeBrowserMainExtraPartsAura::PostMainMessageLoopRun() {
ash::Shell::DeleteInstance();
aura::RootWindow::DeleteInstance();
aura::Env::DeleteInstance();
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ DesktopNotificationsTest::~DesktopNotificationsTest() {
}

void DesktopNotificationsTest::SetUp() {
#if defined(USE_AURA)
#if defined(USE_ASH)
// Make sure a root window has been instantiated.
ash::Shell::GetRootWindow();
ash::Shell::CreateInstance(NULL);
#endif
browser::RegisterLocalState(&local_state_);
profile_.reset(new TestingProfile());
Expand All @@ -129,6 +129,9 @@ void DesktopNotificationsTest::TearDown() {
service_.reset(NULL);
ui_manager_.reset(NULL);
profile_.reset(NULL);
#if defined(USE_ASH)
ash::Shell::DeleteInstance();
#endif
}

content::ShowDesktopNotificationHostMsgParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ DesktopNotificationsTest::~DesktopNotificationsTest() {
}

void DesktopNotificationsTest::SetUp() {
#if defined(USE_AURA)
#if defined(USE_ASH)
WebKit::initialize(&webkit_platform_support_);
// MockBalloonCollection retrieves information about the screen on creation.
// So it is necessary to make sure the desktop gets created first.
ash::Shell::GetRootWindow();
ash::Shell::CreateInstance(NULL);
#endif

browser::RegisterLocalState(&local_state_);
Expand All @@ -111,8 +111,8 @@ void DesktopNotificationsTest::TearDown() {
service_.reset(NULL);
ui_manager_.reset(NULL);
profile_.reset(NULL);
#if defined(USE_AURA)
aura::RootWindow::DeleteInstance();
#if defined(USE_ASH)
ash::Shell::DeleteInstance();
aura::Env::DeleteInstance();
WebKit::shutdown();
#endif
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -121,15 +121,16 @@ class AccessibilityEventRouterViewsTest
virtual void SetUp() {
views::ViewsDelegate::views_delegate = new AccessibilityViewsDelegate();
#if defined(USE_AURA)
aura::RootWindow* root_window = aura::RootWindow::GetInstance();
root_window_.reset(new aura::RootWindow);
test_stacking_client_.reset(
new aura::test::TestStackingClient(root_window));
new aura::test::TestStackingClient(root_window_.get()));
#endif
}

virtual void TearDown() {
#if defined(USE_AURA)
test_stacking_client_.reset();
root_window_.reset();
#endif
delete views::ViewsDelegate::views_delegate;
views::ViewsDelegate::views_delegate = NULL;
Expand Down Expand Up @@ -165,6 +166,7 @@ class AccessibilityEventRouterViewsTest
std::string last_control_name_;
std::string last_control_context_;
#if defined(USE_AURA)
scoped_ptr<aura::RootWindow> root_window_;
scoped_ptr<aura::test::TestStackingClient> test_stacking_client_;
#endif
};
Expand Down
6 changes: 6 additions & 0 deletions chrome/chrome_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,12 @@
'../base/allocator/allocator.gyp:allocator',
],
}],
['use_aura==1', {
'sources/': [
['exclude', '^browser/accessibility/accessibility_win_browsertest.cc'],
['exclude', '^browser/accessibility/browser_views_accessibility_browsertest.cc'],
],
}],
],
'configurations': {
'Debug_Base': {
Expand Down
8 changes: 4 additions & 4 deletions chrome/test/base/browser_with_test_window_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ void BrowserWithTestWindowTest::SetUp() {
window_.reset(new TestBrowserWindow(browser()));
browser_->SetWindowForTesting(window_.get());
#if defined(USE_AURA)
aura::RootWindow* root_window = aura::RootWindow::GetInstance();
root_window_.reset(new aura::RootWindow);
test_activation_client_.reset(
new aura::test::TestActivationClient(root_window));
new aura::test::TestActivationClient(root_window_.get()));
test_stacking_client_.reset(
new aura::test::TestStackingClient(root_window));
new aura::test::TestStackingClient(root_window_.get()));
#endif
}

Expand All @@ -61,7 +61,7 @@ void BrowserWithTestWindowTest::TearDown() {
#if defined(USE_AURA)
test_activation_client_.reset();
test_stacking_client_.reset();
aura::RootWindow::DeleteInstance();
root_window_.reset();
#endif
}

Expand Down
2 changes: 2 additions & 0 deletions chrome/test/base/browser_with_test_window_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class GURL;

#if defined(USE_AURA)
namespace aura {
class RootWindow;
namespace test {
class TestActivationClient;
class TestStackingClient;
Expand Down Expand Up @@ -124,6 +125,7 @@ class BrowserWithTestWindowTest : public testing::Test {
TestRenderViewHostFactory rvh_factory_;

#if defined(USE_AURA)
scoped_ptr<aura::RootWindow> root_window_;
scoped_ptr<aura::test::TestActivationClient> test_activation_client_;
scoped_ptr<aura::test::TestStackingClient> test_stacking_client_;
#endif
Expand Down
3 changes: 1 addition & 2 deletions chrome/test/base/chrome_render_view_host_test_harness.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -33,7 +33,6 @@ void ChromeRenderViewHostTestHarness::TearDown() {
RenderViewHostTestHarness::TearDown();
#if defined(USE_AURA)
ash::Shell::DeleteInstance();
aura::RootWindow::DeleteInstance();
aura::Env::DeleteInstance();
#endif
}
1 change: 0 additions & 1 deletion chrome/test/base/ui_test_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ void RunMessageLoop() {
MessageLoop::ScopedNestableTaskAllower allow(loop);
if (ui_loop) {
#if defined(USE_AURA)
ash::Shell::GetRootWindow()->ShowRootWindow();
ui_loop->Run();
#elif defined(TOOLKIT_VIEWS)
views::AcceleratorHandler handler;
Expand Down
8 changes: 3 additions & 5 deletions chrome/test/base/view_event_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ ViewEventTestBase::ViewEventTestBase()
void ViewEventTestBase::Done() {
MessageLoop::current()->Quit();

#if defined(OS_WIN)
#if defined(OS_WIN) && !defined(USE_AURA)
// We need to post a message to tickle the Dispatcher getting called and
// exiting out of the nested loop. Without this the quit never runs.
PostMessage(window_->GetNativeWindow(), WM_USER, 0, 0);
Expand All @@ -87,15 +87,14 @@ void ViewEventTestBase::SetUp() {
#endif
ui::CompositorTestSupport::Initialize();
#if defined(USE_AURA)
ash::Shell::GetRootWindow();
ash::Shell::CreateInstance(NULL);
#endif
window_ = views::Widget::CreateWindow(this);
}

void ViewEventTestBase::TearDown() {
if (window_) {
#if defined(OS_WIN)
#if defined(OS_WIN) && !defined(USE_AURA)
DestroyWindow(window_->GetNativeWindow());
#else
window_->Close();
Expand All @@ -105,7 +104,6 @@ void ViewEventTestBase::TearDown() {
}
#if defined(USE_AURA)
ash::Shell::DeleteInstance();
aura::RootWindow::DeleteInstance();
aura::Env::DeleteInstance();
#endif
ui::CompositorTestSupport::Terminate();
Expand Down Expand Up @@ -145,7 +143,7 @@ void ViewEventTestBase::StartMessageLoopAndRunTest() {
window_->Show();
// Make sure the window is the foreground window, otherwise none of the
// mouse events are going to be targeted correctly.
#if defined(OS_WIN)
#if defined(OS_WIN) && !defined(USE_AURA)
SetForegroundWindow(window_->GetNativeWindow());
#endif

Expand Down
6 changes: 4 additions & 2 deletions content/browser/renderer_host/test_render_view_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,9 @@ void RenderViewHostTestHarness::Reload() {

void RenderViewHostTestHarness::SetUp() {
#if defined(USE_AURA)
aura::RootWindow* root_window = aura::RootWindow::GetInstance();
test_stacking_client_.reset(new aura::test::TestStackingClient(root_window));
root_window_.reset(new aura::RootWindow);
test_stacking_client_.reset(
new aura::test::TestStackingClient(root_window_.get()));
#endif
SetContents(CreateTestTabContents());
}
Expand All @@ -410,6 +411,7 @@ void RenderViewHostTestHarness::TearDown() {
SetContents(NULL);
#if defined(USE_AURA)
test_stacking_client_.reset();
root_window_.reset();
#endif

// Make sure that we flush any messages related to TabContents destruction
Expand Down
2 changes: 2 additions & 0 deletions content/browser/renderer_host/test_render_view_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#if defined(USE_AURA)
namespace aura {
class RootWindow;
namespace test {
class TestStackingClient;
}
Expand Down Expand Up @@ -374,6 +375,7 @@ class RenderViewHostTestHarness : public testing::Test {
private:
scoped_ptr<TestTabContents> contents_;
#if defined(USE_AURA)
scoped_ptr<aura::RootWindow> root_window_;
scoped_ptr<aura::test::TestStackingClient> test_stacking_client_;
#endif

Expand Down
4 changes: 2 additions & 2 deletions ui/aura/demo/demo_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int main(int argc, char** argv) {
MessageLoop message_loop(MessageLoop::TYPE_UI);
ui::CompositorTestSupport::Initialize();

aura::RootWindow::GetInstance();
scoped_ptr<aura::RootWindow> root_window(new aura::RootWindow);

// Create a hierarchy of test windows.
DemoWindowDelegate window_delegate1(SK_ColorBLUE);
Expand All @@ -115,7 +115,7 @@ int main(int argc, char** argv) {
window3.Show();
window3.SetParent(&window2);

aura::RootWindow::GetInstance()->ShowRootWindow();
root_window->ShowRootWindow();
MessageLoopForUI::current()->Run();

ui::CompositorTestSupport::Terminate();
Expand Down
Loading

0 comments on commit 58482fa

Please sign in to comment.