base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / ui / events / ozone / layout / keyboard_layout_engine_manager.cc
blob4b350e37b5de71b4117a491b0456a920ffc7a34e
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
7 #include "base/logging.h"
8 #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h"
10 namespace ui {
12 // static
13 KeyboardLayoutEngineManager* KeyboardLayoutEngineManager::instance_ = nullptr;
15 KeyboardLayoutEngineManager::KeyboardLayoutEngineManager(
16 KeyboardLayoutEngine* engine)
17 : keyboard_layout_engine_(engine) {
18 CHECK(!instance_) << "Only one keyboard layout manager can be created.";
19 instance_ = this;
22 KeyboardLayoutEngineManager::~KeyboardLayoutEngineManager() {
23 CHECK_EQ(this, instance_);
24 instance_ = NULL;
27 void KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
28 scoped_ptr<KeyboardLayoutEngine> engine) {
29 new KeyboardLayoutEngineManager(engine.release());
32 KeyboardLayoutEngine* KeyboardLayoutEngineManager::GetKeyboardLayoutEngine() {
33 // TODO(kpschoedel): crbug.com/430194 This lazy initialization is a
34 // workaround for not yet initializing KeyboardLayoutEngineManager
35 // expliclity in all tests that need it.
36 if (!instance_)
37 new KeyboardLayoutEngineManager(new StubKeyboardLayoutEngine());
38 return instance_->keyboard_layout_engine_.get();
41 } // namespace ui