Chromium Code Reviews| Index: ui/events/ozone/layout/keyboard_layout_engine_manager.cc |
| diff --git a/ui/events/ozone/layout/keyboard_layout_engine_manager.cc b/ui/events/ozone/layout/keyboard_layout_engine_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..95f63f4bb10828312d67809704af3f155fdab684 |
| --- /dev/null |
| +++ b/ui/events/ozone/layout/keyboard_layout_engine_manager.cc |
| @@ -0,0 +1,41 @@ |
| +// Copyright 2014 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. |
| + |
| +#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" |
| + |
| +#include "base/logging.h" |
| +#include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h" |
| + |
| +namespace ui { |
| + |
| +// static |
| +KeyboardLayoutEngineManager* KeyboardLayoutEngineManager::instance_ = nullptr; |
| + |
| +KeyboardLayoutEngineManager::KeyboardLayoutEngineManager( |
| + KeyboardLayoutEngine* engine) |
| + : keyboard_layout_engine_(engine) { |
| + CHECK(!instance_) << "Only one platform event source can be created."; |
|
spang
2014/12/02 18:38:26
forgot to update the message
kpschoedel
2014/12/02 19:34:20
Done.
|
| + instance_ = this; |
| +} |
| + |
| +KeyboardLayoutEngineManager::~KeyboardLayoutEngineManager() { |
| + CHECK_EQ(this, instance_); |
| + instance_ = NULL; |
| +} |
| + |
| +void KeyboardLayoutEngineManager::SetKeyboardLayoutEngine( |
| + scoped_ptr<KeyboardLayoutEngine> engine) { |
| + if (instance_) |
| + instance_->keyboard_layout_engine_.reset(engine.release()); |
| + else |
| + new KeyboardLayoutEngineManager(engine.release()); |
| +} |
| + |
| +KeyboardLayoutEngine* KeyboardLayoutEngineManager::GetKeyboardLayoutEngine() { |
| + if (!instance_) |
|
spang
2014/12/02 18:38:26
Why do we need to lazily construct this? Is there
kpschoedel
2014/12/02 19:34:20
Yes, all the tests that think they can get away wi
spang
2014/12/02 20:27:59
maybe TODO(): Fix tests that depend on layout engi
kpschoedel
2014/12/02 21:52:34
Done.
|
| + new KeyboardLayoutEngineManager(new StubKeyboardLayoutEngine()); |
| + return instance_->keyboard_layout_engine_.get(); |
| +} |
| + |
| +} // namespace ui |