| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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. | |
| 4 | |
| 5 #include "chromeos/dbus/ibus/mock_ibus_engine_factory_service.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 | |
| 9 namespace chromeos { | |
| 10 | |
| 11 MockIBusEngineFactoryService::MockIBusEngineFactoryService() | |
| 12 : set_create_engine_handler_call_count_(0), | |
| 13 unset_create_engine_handler_call_count_(0), | |
| 14 weak_ptr_factory_(this) { | |
| 15 } | |
| 16 | |
| 17 MockIBusEngineFactoryService::~MockIBusEngineFactoryService() { | |
| 18 } | |
| 19 | |
| 20 void MockIBusEngineFactoryService::SetCreateEngineHandler( | |
| 21 const std::string& engine_id, | |
| 22 const CreateEngineHandler& create_engine_handler) { | |
| 23 handler_map_[engine_id] = create_engine_handler; | |
| 24 set_create_engine_handler_call_count_++; | |
| 25 } | |
| 26 | |
| 27 void MockIBusEngineFactoryService::UnsetCreateEngineHandler( | |
| 28 const std::string& engine_id) { | |
| 29 unset_create_engine_handler_call_count_++; | |
| 30 handler_map_[engine_id].Reset(); | |
| 31 } | |
| 32 | |
| 33 dbus::ObjectPath MockIBusEngineFactoryService::GenerateUniqueObjectPath() { | |
| 34 return dbus::ObjectPath("/org/freedesktop/IBus/Engine/1"); | |
| 35 } | |
| 36 | |
| 37 bool MockIBusEngineFactoryService::CallCreateEngine( | |
| 38 const std::string& engine_id) { | |
| 39 if (handler_map_.find(engine_id) != handler_map_.end() && | |
| 40 !handler_map_[engine_id].is_null()) { | |
| 41 handler_map_[engine_id].Run( | |
| 42 base::Bind(&MockIBusEngineFactoryService::OnEngineCreated, | |
| 43 weak_ptr_factory_.GetWeakPtr(), | |
| 44 engine_id)); | |
| 45 return true; | |
| 46 } | |
| 47 return false; | |
| 48 } | |
| 49 | |
| 50 dbus::ObjectPath MockIBusEngineFactoryService::GetObjectPathByEngineId( | |
| 51 const std::string& engine_id) { | |
| 52 if (object_path_map_.find(engine_id) != object_path_map_.end()) | |
| 53 return dbus::ObjectPath(); | |
| 54 return object_path_map_[engine_id]; | |
| 55 } | |
| 56 | |
| 57 void MockIBusEngineFactoryService::OnEngineCreated( | |
| 58 const std::string& engine_id, | |
| 59 const dbus::ObjectPath& path) { | |
| 60 object_path_map_[engine_id] = path; | |
| 61 } | |
| 62 | |
| 63 } // namespace chromeos | |
| OLD | NEW |