summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordnicoara@chromium.org <dnicoara@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-09 16:18:53 +0000
committerdnicoara@chromium.org <dnicoara@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-09 16:18:53 +0000
commitecca62bd54f6e04c8c96284b3a726f29af6badc0 (patch)
treecfd9cb892b7020fe9b9f1ea3544545cf9180b8df
parentd6066a8faa902dd9dec2889bf83a7cc755e30686 (diff)
downloadchromium_src-ecca62bd54f6e04c8c96284b3a726f29af6badc0.zip
chromium_src-ecca62bd54f6e04c8c96284b3a726f29af6badc0.tar.gz
chromium_src-ecca62bd54f6e04c8c96284b3a726f29af6badc0.tar.bz2
Explicit initialization of aura::Env for browser shell.
Most implementations (x11 aura with and without chromeos) do not explicitly call aura::Env::GetInstance() to initialize it. These build work as is because the call is done when performing other operations, such as adding observers. In OZONE there are no such calls, so the OZONE build fails when trying to create a compositor since the Compositor::Initialize hasn't been called. This patch adds an explicit initialization for aura based builds to fix this issue. BUG= Review URL: https://codereview.chromium.org/23882007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227745 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/shell.cc9
-rw-r--r--ash/test/ash_test_helper.cc1
-rw-r--r--chrome/browser/chrome_browser_main.cc10
-rw-r--r--chrome/browser/extensions/test_extension_environment.cc12
-rw-r--r--chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.cc1
-rw-r--r--chrome/test/base/view_event_test_base.cc7
-rw-r--r--chrome_frame/test/net/fake_external_tab.cc2
-rw-r--r--content/browser/renderer_host/render_widget_host_unittest.cc1
-rw-r--r--content/browser/web_contents/web_contents_view_aura.cc2
-rw-r--r--content/shell/browser/minimal_shell.cc2
-rw-r--r--ui/aura/bench/bench_main.cc2
-rw-r--r--ui/aura/demo/demo_main.cc2
-rw-r--r--ui/aura/env.cc16
-rw-r--r--ui/aura/env.h8
-rw-r--r--ui/aura/test/aura_test_helper.cc2
-rw-r--r--ui/views/bubble/bubble_delegate_unittest.cc1
16 files changed, 66 insertions, 12 deletions
diff --git a/ash/shell.cc b/ash/shell.cc
index 8b0e939..0fdb0b7 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -715,6 +715,11 @@ void Shell::Init() {
// Launcher, and WallPaper could be created by the factory.
views::FocusManagerFactory::Install(new AshFocusManagerFactory);
+ // Env creates the compositor. Historically it seems to have been implicitly
+ // initialized first by the ActivationController, but now that FocusController
+ // no longer does this we need to do it explicitly.
+ aura::Env::CreateInstance();
+
// The WindowModalityController needs to be at the front of the input event
// pretarget handler list to ensure that it processes input events when modal
// windows are active.
@@ -726,10 +731,6 @@ void Shell::Init() {
env_filter_.reset(new views::corewm::CompoundEventFilter);
AddPreTargetHandler(env_filter_.get());
- // Env creates the compositor. Historically it seems to have been implicitly
- // initialized first by the ActivationController, but now that FocusController
- // no longer does this we need to do it explicitly.
- aura::Env::GetInstance();
views::corewm::FocusController* focus_controller =
new views::corewm::FocusController(new wm::AshFocusRules);
focus_client_.reset(focus_controller);
diff --git a/ash/test/ash_test_helper.cc b/ash/test/ash_test_helper.cc
index 469504b..97c0ea4 100644
--- a/ash/test/ash_test_helper.cc
+++ b/ash/test/ash_test_helper.cc
@@ -118,6 +118,7 @@ void AshTestHelper::TearDown() {
void AshTestHelper::RunAllPendingInMessageLoop() {
DCHECK(base::MessageLoopForUI::current() == message_loop_);
+ aura::Env::CreateInstance();
base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher());
run_loop.RunUntilIdle();
}
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index a2dfd7a..a614a96 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -194,6 +194,10 @@
#include "ui/views/focus/accelerator_handler.h"
#endif
+#if defined(USE_AURA)
+#include "ui/aura/env.h"
+#endif
+
using content::BrowserThread;
namespace {
@@ -1466,6 +1470,12 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
if (!parsed_command_line().HasSwitch(switches::kDisableComponentUpdate))
RegisterComponentsForUpdate(parsed_command_line());
+#if defined(USE_AURA)
+ // Env creates the compositor. Aura widgets need the compositor to be created
+ // before they can be initialized by the browser.
+ aura::Env::CreateInstance();
+#endif
+
if (browser_creator_->Start(parsed_command_line(), base::FilePath(),
profile_, last_opened_profiles, &result_code)) {
#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
diff --git a/chrome/browser/extensions/test_extension_environment.cc b/chrome/browser/extensions/test_extension_environment.cc
index 8cc3bc3..9ebb3d5 100644
--- a/chrome/browser/extensions/test_extension_environment.cc
+++ b/chrome/browser/extensions/test_extension_environment.cc
@@ -18,6 +18,10 @@
#include "content/public/test/web_contents_tester.h"
#include "testing/gtest/include/gtest/gtest.h"
+#if defined(USE_AURA)
+#include "ui/aura/env.h"
+#endif
+
namespace extensions {
using content::BrowserThread;
@@ -32,9 +36,17 @@ TestExtensionEnvironment::TestExtensionEnvironment()
file_thread_.Start();
file_blocking_thread_.Start();
io_thread_.StartIOThread();
+
+#if defined(USE_AURA)
+ aura::Env::CreateInstance();
+#endif
}
TestExtensionEnvironment::~TestExtensionEnvironment() {
+#if defined(USE_AURA)
+ aura::Env::DeleteInstance();
+#endif
+
profile_.reset();
// Delete the profile, and then cycle the message loop to clear
// out delayed deletions.
diff --git a/chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.cc b/chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.cc
index a63ebce..fe60b8a 100644
--- a/chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.cc
+++ b/chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.cc
@@ -51,6 +51,7 @@ ChromeBrowserMainExtraPartsAura::~ChromeBrowserMainExtraPartsAura() {
void ChromeBrowserMainExtraPartsAura::ToolkitInitialized() {
#if !defined(OS_CHROMEOS)
#if defined(USE_ASH)
+ aura::Env::CreateInstance();
active_desktop_monitor_.reset(new ActiveDesktopMonitor(GetInitialDesktop()));
#endif
#endif
diff --git a/chrome/test/base/view_event_test_base.cc b/chrome/test/base/view_event_test_base.cc
index c37fe93..fa9f204 100644
--- a/chrome/test/base/view_event_test_base.cc
+++ b/chrome/test/base/view_event_test_base.cc
@@ -126,6 +126,10 @@ void ViewEventTestBase::SetUp() {
->SetActiveUserSessionStarted(true);
context = ash::Shell::GetPrimaryRootWindow();
#endif // !OS_WIN
+#if defined(USE_AURA)
+ aura::Env::CreateInstance();
+#endif
+
#elif defined(USE_AURA)
// Instead of using the ash shell, use an AuraTestHelper to create and manage
// the test screen.
@@ -158,8 +162,11 @@ void ViewEventTestBase::TearDown() {
// Ash Shell can't just live on its own without a browser process, we need to
// also shut down the message center.
message_center::MessageCenter::Shutdown();
+#endif
+#if defined(USE_AURA)
aura::Env::DeleteInstance();
#endif
+
#elif defined(USE_AURA)
aura_test_helper_->TearDown();
#endif
diff --git a/chrome_frame/test/net/fake_external_tab.cc b/chrome_frame/test/net/fake_external_tab.cc
index bcc7792..935b02c 100644
--- a/chrome_frame/test/net/fake_external_tab.cc
+++ b/chrome_frame/test/net/fake_external_tab.cc
@@ -75,6 +75,7 @@
#include "ui/base/ui_base_paths.h"
#if defined(USE_AURA)
+#include "ui/aura/env.h"
#include "ui/gfx/screen.h"
#include "ui/views/widget/desktop_aura/desktop_screen.h"
#endif
@@ -553,6 +554,7 @@ void FakeExternalTab::Initialize() {
void FakeExternalTab::InitializePostThreadsCreated() {
#if defined(USE_AURA)
+ aura::Env::CreateInstance();
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE,
views::CreateDesktopScreen());
#endif
diff --git a/content/browser/renderer_host/render_widget_host_unittest.cc b/content/browser/renderer_host/render_widget_host_unittest.cc
index becde79..ed306b2 100644
--- a/content/browser/renderer_host/render_widget_host_unittest.cc
+++ b/content/browser/renderer_host/render_widget_host_unittest.cc
@@ -623,6 +623,7 @@ class RenderWidgetHostTest : public testing::Test {
delegate_.reset(new MockRenderWidgetHostDelegate());
process_ = new RenderWidgetHostProcess(browser_context_.get());
#if defined(USE_AURA)
+ aura::Env::CreateInstance();
screen_.reset(aura::TestScreen::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
#endif
diff --git a/content/browser/web_contents/web_contents_view_aura.cc b/content/browser/web_contents/web_contents_view_aura.cc
index 3d0d16f..2b33dab 100644
--- a/content/browser/web_contents/web_contents_view_aura.cc
+++ b/content/browser/web_contents/web_contents_view_aura.cc
@@ -40,6 +40,7 @@
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/drag_drop_client.h"
#include "ui/aura/client/drag_drop_delegate.h"
+#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
#include "ui/aura/root_window_observer.h"
#include "ui/aura/window.h"
@@ -1142,6 +1143,7 @@ void WebContentsViewAura::CreateView(
// if the bookmark bar is not shown and you create a new tab). The right
// value is set shortly after this, so its safe to ignore.
+ aura::Env::CreateInstance();
window_.reset(new aura::Window(this));
window_->set_owned_by_parent(false);
window_->SetType(aura::client::WINDOW_TYPE_CONTROL);
diff --git a/content/shell/browser/minimal_shell.cc b/content/shell/browser/minimal_shell.cc
index e7e88f8..cc719db 100644
--- a/content/shell/browser/minimal_shell.cc
+++ b/content/shell/browser/minimal_shell.cc
@@ -5,6 +5,7 @@
#include "content/shell/browser/minimal_shell.h"
#include "ui/aura/client/default_capture_client.h"
+#include "ui/aura/env.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test/test_activation_client.h"
@@ -14,6 +15,7 @@
namespace content {
MinimalShell::MinimalShell(const gfx::Size& default_window_size) {
+ aura::Env::CreateInstance();
root_window_.reset(new aura::RootWindow(
aura::RootWindow::CreateParams(
gfx::Rect(default_window_size))));
diff --git a/ui/aura/bench/bench_main.cc b/ui/aura/bench/bench_main.cc
index 90b6434..a93bc1f 100644
--- a/ui/aura/bench/bench_main.cc
+++ b/ui/aura/bench/bench_main.cc
@@ -308,7 +308,7 @@ int main(int argc, char** argv) {
ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL);
base::MessageLoop message_loop(base::MessageLoop::TYPE_UI);
- aura::Env::GetInstance();
+ aura::Env::CreateInstance();
scoped_ptr<aura::TestScreen> test_screen(
aura::TestScreen::CreateFullscreen());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get());
diff --git a/ui/aura/demo/demo_main.cc b/ui/aura/demo/demo_main.cc
index dbf1c80..e56ab71 100644
--- a/ui/aura/demo/demo_main.cc
+++ b/ui/aura/demo/demo_main.cc
@@ -115,7 +115,7 @@ int DemoMain() {
bool allow_test_contexts = false;
ui::Compositor::InitializeContextFactoryForTests(allow_test_contexts);
- aura::Env::GetInstance();
+ aura::Env::CreateInstance();
scoped_ptr<aura::TestScreen> test_screen(aura::TestScreen::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get());
scoped_ptr<aura::RootWindow> root_window(
diff --git a/ui/aura/env.cc b/ui/aura/env.cc
index a4cf815..1f90a29 100644
--- a/ui/aura/env.cc
+++ b/ui/aura/env.cc
@@ -39,12 +39,18 @@ Env::~Env() {
ui::Compositor::Terminate();
}
-// static
-Env* Env::GetInstance() {
+//static
+void Env::CreateInstance() {
if (!instance_) {
instance_ = new Env;
instance_->Init();
}
+}
+
+// static
+Env* Env::GetInstance() {
+ DCHECK(instance_) << "Env::CreateInstance must be called before getting "
+ "the instance of Env.";
return instance_;
}
@@ -62,6 +68,8 @@ void Env::RemoveObserver(EnvObserver* observer) {
observers_.RemoveObserver(observer);
}
+#if !defined(OS_MACOSX) && !defined(OS_ANDROID) && \
+ !defined(USE_GTK_MESSAGE_PUMP)
base::MessageLoop::Dispatcher* Env::GetDispatcher() {
#if defined(USE_X11)
return base::MessagePumpX11::Current();
@@ -69,6 +77,7 @@ base::MessageLoop::Dispatcher* Env::GetDispatcher() {
return dispatcher_.get();
#endif
}
+#endif
void Env::RootWindowActivated(RootWindow* root_window) {
FOR_EACH_OBSERVER(EnvObserver, observers_,
@@ -79,7 +88,8 @@ void Env::RootWindowActivated(RootWindow* root_window) {
// Env, private:
void Env::Init() {
-#if !defined(USE_X11) && !defined(USE_OZONE)
+#if !defined(OS_MACOSX) && !defined(OS_ANDROID) && !defined(USE_X11) && \
+ !defined(USE_OZONE)
dispatcher_.reset(CreateDispatcher());
#endif
#if defined(USE_X11)
diff --git a/ui/aura/env.h b/ui/aura/env.h
index c52b892..337e94f 100644
--- a/ui/aura/env.h
+++ b/ui/aura/env.h
@@ -22,7 +22,7 @@ class EnvObserver;
class RootWindow;
class Window;
-#if !defined(USE_X11)
+#if !defined(OS_MACOSX) && !defined(OS_ANDROID) && !defined(USE_X11)
// Creates a platform-specific native event dispatcher.
base::MessageLoop::Dispatcher* CreateDispatcher();
#endif
@@ -34,6 +34,7 @@ class AURA_EXPORT Env : public ui::EventTarget {
Env();
virtual ~Env();
+ static void CreateInstance();
static Env* GetInstance();
static void DeleteInstance();
@@ -60,7 +61,10 @@ class AURA_EXPORT Env : public ui::EventTarget {
// Returns the native event dispatcher. The result should only be passed to
// base::RunLoop(dispatcher), or used to dispatch an event by
// |Dispatch(const NativeEvent&)| on it. It must never be stored.
+#if !defined(OS_MACOSX) && !defined(OS_ANDROID) && \
+ !defined(USE_GTK_MESSAGE_PUMP)
base::MessageLoop::Dispatcher* GetDispatcher();
+#endif
// Invoked by RootWindow when its host is activated.
void RootWindowActivated(RootWindow* root_window);
@@ -82,7 +86,7 @@ class AURA_EXPORT Env : public ui::EventTarget {
virtual ui::EventTarget* GetParentTarget() OVERRIDE;
ObserverList<EnvObserver> observers_;
-#if !defined(USE_X11)
+#if !defined(OS_MACOSX) && !defined(OS_ANDROID) && !defined(USE_X11)
scoped_ptr<base::MessageLoop::Dispatcher> dispatcher_;
#endif
diff --git a/ui/aura/test/aura_test_helper.cc b/ui/aura/test/aura_test_helper.cc
index d1a2afd..6cd9d68 100644
--- a/ui/aura/test/aura_test_helper.cc
+++ b/ui/aura/test/aura_test_helper.cc
@@ -65,7 +65,7 @@ void AuraTestHelper::SetUp() {
bool allow_test_contexts = true;
ui::Compositor::InitializeContextFactoryForTests(allow_test_contexts);
- Env::GetInstance();
+ Env::CreateInstance();
test_screen_.reset(TestScreen::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get());
root_window_.reset(test_screen_->CreateRootWindowForPrimaryDisplay());
diff --git a/ui/views/bubble/bubble_delegate_unittest.cc b/ui/views/bubble/bubble_delegate_unittest.cc
index 10763c3..183c41f 100644
--- a/ui/views/bubble/bubble_delegate_unittest.cc
+++ b/ui/views/bubble/bubble_delegate_unittest.cc
@@ -254,6 +254,7 @@ class BubbleWidgetClosingTest : public BubbleDelegateTest,
public:
BubbleWidgetClosingTest() : bubble_destroyed_(false) {
#if defined(USE_AURA)
+ aura::Env::CreateInstance();
loop_.set_dispatcher(aura::Env::GetInstance()->GetDispatcher());
#endif
}