| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "services/ui/ime/ime_server_impl.h" | 5 #include "services/ui/ime/ime_driver_bridge.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "services/service_manager/public/cpp/connector.h" | 8 #include "services/service_manager/public/cpp/connector.h" |
| 9 #include "services/ui/ime/ime_registrar_impl.h" | 9 #include "services/ui/ime/ime_registrar_impl.h" |
| 10 | 10 |
| 11 namespace ui { | 11 namespace ui { |
| 12 | 12 |
| 13 IMEServerImpl::IMEServerImpl() : current_id_(0) {} | 13 IMEDriverBridge::IMEDriverBridge() {} |
| 14 | 14 |
| 15 IMEServerImpl::~IMEServerImpl() {} | 15 IMEDriverBridge::~IMEDriverBridge() {} |
| 16 | 16 |
| 17 void IMEServerImpl::Init(service_manager::Connector* connector, | 17 void IMEDriverBridge::Init(service_manager::Connector* connector, |
| 18 bool is_test_config) { | 18 bool is_test_config) { |
| 19 if (is_test_config) | 19 if (is_test_config) |
| 20 connector->StartService("test_ime_driver"); | 20 connector->StartService("test_ime_driver"); |
| 21 // For non test configs we assume a client registers with us. | 21 // For non test configs we assume a client registers with us. |
| 22 } | 22 } |
| 23 | 23 |
| 24 void IMEServerImpl::AddBinding(mojom::IMEServerRequest request) { | 24 void IMEDriverBridge::AddBinding(mojom::IMEDriverRequest request) { |
| 25 bindings_.AddBinding(this, std::move(request)); | 25 bindings_.AddBinding(this, std::move(request)); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void IMEServerImpl::OnDriverChanged(mojom::IMEDriverPtr driver) { | 28 void IMEDriverBridge::SetDriver(mojom::IMEDriverPtr driver) { |
| 29 // TODO(moshayedi): crbug.com/669681. Handle switching drivers properly. For | 29 // TODO(moshayedi): crbug.com/669681. Handle switching drivers properly. For |
| 30 // now we only register the first driver to avoid clients of the previous | 30 // now we only register the first driver to avoid clients of the previous |
| 31 // driver from hanging. | 31 // driver from hanging. |
| 32 if (driver_) | 32 if (driver_) |
| 33 return; | 33 return; |
| 34 | 34 |
| 35 driver_ = std::move(driver); | 35 driver_ = std::move(driver); |
| 36 | 36 |
| 37 while (!pending_requests_.empty()) { | 37 while (!pending_requests_.empty()) { |
| 38 driver_->StartSession(current_id_++, std::move(pending_requests_.front())); | 38 driver_->StartSession(std::move(pending_requests_.front())); |
| 39 pending_requests_.pop(); | 39 pending_requests_.pop(); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 void IMEServerImpl::StartSession(mojom::StartSessionDetailsPtr details) { | 43 void IMEDriverBridge::StartSession(mojom::StartSessionDetailsPtr details) { |
| 44 if (driver_.get()) { | 44 if (driver_.get()) { |
| 45 // TODO(moshayedi): crbug.com/634431. This will forward all calls from | 45 // TODO(moshayedi): crbug.com/634431. This will forward all calls from |
| 46 // clients to the driver as they are. We may need to check |caret_bounds| | 46 // clients to the driver as they are. We may need to check |caret_bounds| |
| 47 // parameter of InputMethod::OnCaretBoundsChanged() here and limit them to | 47 // parameter of InputMethod::OnCaretBoundsChanged() here and limit them to |
| 48 // client's focused window. | 48 // client's focused window. |
| 49 driver_->StartSession(current_id_++, std::move(details)); | 49 driver_->StartSession(std::move(details)); |
| 50 } else { | 50 } else { |
| 51 pending_requests_.push(std::move(details)); | 51 pending_requests_.push(std::move(details)); |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 } // namespace ui | 55 } // namespace ui |
| OLD | NEW |