Skip to content

Commit

Permalink
Makes PlatformEventSource creation in Env conditional
Browse files Browse the repository at this point in the history
Currently mojo runs all services in the same process. We have separate
services that manage the display and one that runs aura. The display
one needs to create PlatformEventSource (as it gets events). The
service running aura doesn't need a PlatformEventSource as it gets
events from the display one. This means I need the ability to create
aura::Env without a PlatformEventSource.

I believe the long term plan is to move some services out of
process. When this happens this boolean shouldn't be needed.

BUG=365012
TEST=none
R=sadrul@chromium.org

Review URL: https://codereview.chromium.org/262883011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268148 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
sky@chromium.org committed May 5, 2014
1 parent 7f27503 commit 5b883ab
Show file tree
Hide file tree
Showing 18 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ void Shell::Init() {
// 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();
aura::Env::CreateInstance(true);

// The WindowModalityController needs to be at the front of the input event
// pretarget handler list to ensure that it processes input events when modal
Expand Down
2 changes: 1 addition & 1 deletion ash/test/ash_test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void AshTestHelper::TearDown() {

void AshTestHelper::RunAllPendingInMessageLoop() {
DCHECK(base::MessageLoopForUI::current() == message_loop_);
aura::Env::CreateInstance();
aura::Env::CreateInstance(true);
base::RunLoop run_loop;
run_loop.RunUntilIdle();
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/extensions/test_extension_environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ TestExtensionEnvironment::TestExtensionEnvironment()
extension_service_(NULL),
extension_prefs_(NULL) {
#if defined(USE_AURA)
aura::Env::CreateInstance();
aura::Env::CreateInstance(true);
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion chrome/test/base/view_event_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void ViewEventTestBase::SetUp() {
context = ash::Shell::GetPrimaryRootWindow();
context->GetHost()->Show();
#endif // !OS_WIN
aura::Env::CreateInstance();
aura::Env::CreateInstance(true);
#elif defined(USE_AURA)
// Instead of using the ash shell, use an AuraTestHelper to create and manage
// the test screen.
Expand Down
2 changes: 1 addition & 1 deletion content/browser/browser_main_loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ bool BrowserMainLoop::InitializeToolkit() {

// Env creates the compositor. Aura widgets need the compositor to be created
// before they can be initialized by the browser.
aura::Env::CreateInstance();
aura::Env::CreateInstance(true);
#endif // defined(USE_AURA)

if (parts_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TouchEmulatorTest : public testing::Test,
// testing::Test
virtual void SetUp() OVERRIDE {
#if defined(USE_AURA)
aura::Env::CreateInstance();
aura::Env::CreateInstance(true);
screen_.reset(aura::TestScreen::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ class RenderWidgetHostTest : public testing::Test {
#if defined(USE_AURA)
ImageTransportFactory::InitializeForUnitTests(
scoped_ptr<ui::ContextFactory>(new ui::InProcessContextFactory));
aura::Env::CreateInstance();
aura::Env::CreateInstance(true);
screen_.reset(aura::TestScreen::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
#endif
Expand Down
2 changes: 1 addition & 1 deletion content/browser/web_contents/web_contents_view_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,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();
aura::Env::CreateInstance(true);
window_.reset(new aura::Window(this));
window_->set_owned_by_parent(false);
window_->SetType(ui::wm::WINDOW_TYPE_CONTROL);
Expand Down
2 changes: 1 addition & 1 deletion mojo/examples/aura_demo/aura_demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ extern "C" AURA_DEMO_EXPORT MojoResult CDECL MojoMain(
// TODO(beng): This crashes in a DCHECK on X11 because this thread's
// MessageLoop is not of TYPE_UI. I think we need a way to build
// Aura that doesn't define platform-specific stuff.
aura::Env::CreateInstance();
aura::Env::CreateInstance(true);
mojo::examples::AuraDemo app(shell_handle);
loop.Run();

Expand Down
2 changes: 1 addition & 1 deletion mojo/examples/launcher/launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ extern "C" LAUNCHER_EXPORT MojoResult CDECL MojoMain(
// TODO(beng): This crashes in a DCHECK on X11 because this thread's
// MessageLoop is not of TYPE_UI. I think we need a way to build
// Aura that doesn't define platform-specific stuff.
aura::Env::CreateInstance();
aura::Env::CreateInstance(true);
mojo::examples::LauncherImpl launcher(shell_handle);
loop.Run();

Expand Down
2 changes: 1 addition & 1 deletion ui/aura/bench/bench_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ int main(int argc, char** argv) {
base::i18n::InitializeICU();

base::MessageLoopForUI message_loop;
aura::Env::CreateInstance();
aura::Env::CreateInstance(true);
scoped_ptr<aura::TestScreen> test_screen(
aura::TestScreen::CreateFullscreen());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get());
Expand Down
2 changes: 1 addition & 1 deletion ui/aura/demo/demo_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ int DemoMain() {
// Create the message-loop here before creating the root window.
base::MessageLoopForUI message_loop;

aura::Env::CreateInstance();
aura::Env::CreateInstance(true);
scoped_ptr<aura::TestScreen> test_screen(aura::TestScreen::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get());
scoped_ptr<aura::WindowTreeHost> host(
Expand Down
8 changes: 4 additions & 4 deletions ui/aura/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ Env::~Env() {
}

//static
void Env::CreateInstance() {
void Env::CreateInstance(bool create_event_source) {
if (!instance_) {
instance_ = new Env;
instance_->Init();
instance_->Init(create_event_source);
}
}

Expand Down Expand Up @@ -67,10 +67,10 @@ bool Env::IsMouseButtonDown() const {
////////////////////////////////////////////////////////////////////////////////
// Env, private:

void Env::Init() {
void Env::Init(bool create_event_source) {
ui::Compositor::Initialize();

if (!ui::PlatformEventSource::GetInstance())
if (create_event_source && !ui::PlatformEventSource::GetInstance())
event_source_ = ui::PlatformEventSource::CreateDefault();
}

Expand Down
9 changes: 7 additions & 2 deletions ui/aura/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ class AURA_EXPORT Env : public ui::EventTarget {
Env();
virtual ~Env();

static void CreateInstance();
// Creates the single Env instance (if it hasn't been created yet). If
// |create_event_source| is true a PlatformEventSource is created.
// TODO(sky): nuke |create_event_source|. Only necessary while mojo's
// nativeviewportservice lives in the same process as the viewmanager.
static void CreateInstance(bool create_event_source);
static Env* GetInstance();
static void DeleteInstance();

Expand Down Expand Up @@ -63,7 +67,8 @@ class AURA_EXPORT Env : public ui::EventTarget {
friend class Window;
friend class WindowTreeHost;

void Init();
// See description of CreateInstance() for deatils of |create_event_source|.
void Init(bool create_event_source);

// Called by the Window when it is initialized. Notifies observers.
void NotifyWindowInitialized(Window* window);
Expand Down
2 changes: 1 addition & 1 deletion ui/aura/test/aura_test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ AuraTestHelper::~AuraTestHelper() {
void AuraTestHelper::SetUp() {
setup_called_ = true;

Env::CreateInstance();
Env::CreateInstance(true);
// Unit tests generally don't want to query the system, rather use the state
// from RootWindow.
EnvTestHelper(Env::GetInstance()).SetInputStateLookup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void ExamplesBrowserMainParts::PreMainMessageLoopRun() {
// Ensure Aura knows where to open new windows.
window_context = wm_test_helper_->host()->window();
#else
aura::Env::CreateInstance();
aura::Env::CreateInstance(true);
gfx::Screen::SetScreenInstance(
gfx::SCREEN_TYPE_NATIVE, CreateDesktopScreen());
#endif
Expand Down
2 changes: 1 addition & 1 deletion ui/views/examples/examples_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int main(int argc, char** argv) {

ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);

aura::Env::CreateInstance();
aura::Env::CreateInstance(true);

ui::InitializeInputMethodForTesting();

Expand Down
2 changes: 1 addition & 1 deletion ui/wm/test/wm_test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace wm {

WMTestHelper::WMTestHelper(const gfx::Size& default_window_size) {
aura::Env::CreateInstance();
aura::Env::CreateInstance(true);
host_.reset(aura::WindowTreeHost::Create(gfx::Rect(default_window_size)));
host_->InitHost();
aura::client::SetWindowTreeClient(host_->window(), this);
Expand Down

0 comments on commit 5b883ab

Please sign in to comment.