1 // Copyright (c) 2013 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/fake_bluetooth_agent_manager_client.h" 6 7 #include "base/bind.h" 8 #include "base/logging.h" 9 #include "chromeos/dbus/fake_bluetooth_agent_service_provider.h" 10 #include "dbus/object_path.h" 11 #include "third_party/cros_system_api/dbus/service_constants.h" 12 13 namespace chromeos { 14 15 FakeBluetoothAgentManagerClient::FakeBluetoothAgentManagerClient() 16 : service_provider_(NULL) { 17 } 18 19 FakeBluetoothAgentManagerClient::~FakeBluetoothAgentManagerClient() { 20 } 21 22 void FakeBluetoothAgentManagerClient::Init(dbus::Bus* bus) { 23 } 24 25 void FakeBluetoothAgentManagerClient::RegisterAgent( 26 const dbus::ObjectPath& agent_path, 27 const std::string& capability, 28 const base::Closure& callback, 29 const ErrorCallback& error_callback) { 30 VLOG(1) << "RegisterAgent: " << agent_path.value(); 31 32 if (service_provider_ == NULL) { 33 error_callback.Run(bluetooth_agent_manager::kErrorInvalidArguments, 34 "No agent created"); 35 } else if (service_provider_->object_path_ != agent_path) { 36 error_callback.Run(bluetooth_agent_manager::kErrorAlreadyExists, 37 "Agent already registered"); 38 } else { 39 callback.Run(); 40 } 41 } 42 43 void FakeBluetoothAgentManagerClient::UnregisterAgent( 44 const dbus::ObjectPath& agent_path, 45 const base::Closure& callback, 46 const ErrorCallback& error_callback) { 47 VLOG(1) << "UnregisterAgent: " << agent_path.value(); 48 if (service_provider_ == NULL) { 49 error_callback.Run(bluetooth_agent_manager::kErrorDoesNotExist, 50 "No agent registered"); 51 } else if (service_provider_->object_path_ != agent_path) { 52 error_callback.Run(bluetooth_agent_manager::kErrorDoesNotExist, 53 "Agent still registered"); 54 } else { 55 callback.Run(); 56 } 57 } 58 59 void FakeBluetoothAgentManagerClient::RequestDefaultAgent( 60 const dbus::ObjectPath& agent_path, 61 const base::Closure& callback, 62 const ErrorCallback& error_callback) { 63 VLOG(1) << "RequestDefaultAgent: " << agent_path.value(); 64 callback.Run(); 65 } 66 67 void FakeBluetoothAgentManagerClient::RegisterAgentServiceProvider( 68 FakeBluetoothAgentServiceProvider* service_provider) { 69 service_provider_ = service_provider; 70 } 71 72 void FakeBluetoothAgentManagerClient::UnregisterAgentServiceProvider( 73 FakeBluetoothAgentServiceProvider* service_provider) { 74 if (service_provider_ == service_provider) 75 service_provider_ = NULL; 76 } 77 78 FakeBluetoothAgentServiceProvider* 79 FakeBluetoothAgentManagerClient::GetAgentServiceProvider() { 80 return service_provider_; 81 } 82 83 } // namespace chromeos 84