16e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
26e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
36e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// found in the LICENSE file.
46e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
56e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/dbus_client_bundle.h"
66e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
76e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "base/command_line.h"
86e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "base/strings/string_split.h"
96e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "base/strings/string_util.h"
106e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/chromeos_switches.h"
116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/bluetooth_adapter_client.h"
126e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/bluetooth_agent_manager_client.h"
136e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/bluetooth_device_client.h"
146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/bluetooth_gatt_characteristic_client.h"
156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/bluetooth_gatt_descriptor_client.h"
166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/bluetooth_gatt_manager_client.h"
176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/bluetooth_gatt_service_client.h"
186e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/bluetooth_input_client.h"
196e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/bluetooth_profile_manager_client.h"
206e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/cras_audio_client.h"
216e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/cras_audio_client_stub_impl.h"
226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/cros_disks_client.h"
236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/cryptohome_client.h"
246e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/debug_daemon_client.h"
256e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/easy_unlock_client.h"
266e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_bluetooth_adapter_client.h"
276e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_bluetooth_agent_manager_client.h"
286e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_bluetooth_device_client.h"
296e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h"
306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_bluetooth_gatt_descriptor_client.h"
316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_bluetooth_gatt_manager_client.h"
326e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_bluetooth_gatt_service_client.h"
336e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_bluetooth_input_client.h"
346e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_bluetooth_profile_manager_client.h"
356e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_cryptohome_client.h"
366e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_debug_daemon_client.h"
376e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_easy_unlock_client.h"
386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_gsm_sms_client.h"
396e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_image_burner_client.h"
406e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_introspectable_client.h"
416e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_lorgnette_manager_client.h"
426e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_modem_messaging_client.h"
436e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_nfc_adapter_client.h"
446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_nfc_device_client.h"
456e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_nfc_manager_client.h"
466e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_nfc_record_client.h"
476e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_nfc_tag_client.h"
486e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_permission_broker_client.h"
496e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_shill_device_client.h"
506e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_shill_ipconfig_client.h"
516e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_shill_manager_client.h"
526e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_shill_profile_client.h"
536e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_shill_service_client.h"
546e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_sms_client.h"
556e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/fake_system_clock_client.h"
566e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/gsm_sms_client.h"
576e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/image_burner_client.h"
586e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/introspectable_client.h"
596e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/lorgnette_manager_client.h"
606e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/modem_messaging_client.h"
616e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/nfc_adapter_client.h"
626e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/nfc_device_client.h"
636e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/nfc_manager_client.h"
646e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/nfc_record_client.h"
656e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/nfc_tag_client.h"
666e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/permission_broker_client.h"
676e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/power_manager_client.h"
686e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/power_policy_controller.h"
696e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/session_manager_client.h"
706e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/shill_device_client.h"
716e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/shill_ipconfig_client.h"
726e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/shill_manager_client.h"
736e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/shill_profile_client.h"
746e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/shill_service_client.h"
756e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/sms_client.h"
766e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/system_clock_client.h"
776e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromeos/dbus/update_engine_client.h"
786e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
796e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)namespace chromeos {
806e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
816e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)namespace {
826e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
836e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Command line switch mapping for --dbus-unstub-clients.
846e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)const struct {
856e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  const char* param_name;
866e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  DBusClientBundle::DBusClientType client_type;
876e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} client_type_map[] = {
886e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "bluetooth",  DBusClientBundle::BLUETOOTH },
896e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "cras",  DBusClientBundle::CRAS },
906e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "cros_disks",  DBusClientBundle::CROS_DISKS },
916e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "cryptohome",  DBusClientBundle::CRYPTOHOME },
926e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "debug_daemon",  DBusClientBundle::DEBUG_DAEMON },
936e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "easy_unlock",  DBusClientBundle::EASY_UNLOCK },
946e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "lorgnette_manager",  DBusClientBundle::LORGNETTE_MANAGER },
956e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "shill",  DBusClientBundle::SHILL },
966e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "gsm_sms",  DBusClientBundle::GSM_SMS },
976e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "image_burner",  DBusClientBundle::IMAGE_BURNER },
986e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "introspectable",  DBusClientBundle::INTROSPECTABLE },
996e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "modem_messaging",  DBusClientBundle::MODEM_MESSAGING },
1006e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "nfc",  DBusClientBundle::NFC },
1016e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "permission_broker",  DBusClientBundle::PERMISSION_BROKER },
1026e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "power_manager",  DBusClientBundle::POWER_MANAGER },
1036e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "session_manager",  DBusClientBundle::SESSION_MANAGER },
1046e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "sms",  DBusClientBundle::SMS },
1056e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "system_clock",  DBusClientBundle::SYSTEM_CLOCK },
1066e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    { "update_engine",  DBusClientBundle::UPDATE_ENGINE },
1076e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)};
1086e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Parses single command line param value for dbus subsystem. If successful,
1101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// returns its enum representation. Otherwise returns NO_CLIENT.
1116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)DBusClientBundle::DBusClientType GetDBusClientType(
1121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    const std::string& client_type_name) {
1136e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  for (size_t i = 0; i < arraysize(client_type_map); i++) {
1141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    if (LowerCaseEqualsASCII(client_type_name, client_type_map[i].param_name))
1156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      return client_type_map[i].client_type;
1166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  }
1171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return DBusClientBundle::NO_CLIENT;
1186e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}
1196e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1206e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}  // namespace
1216e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciDBusClientBundle::DBusClientBundle(DBusClientTypeMask unstub_client_mask)
1231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    : unstub_client_mask_(unstub_client_mask) {
1241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!IsUsingStub(BLUETOOTH)) {
1256e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create());
1266e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    bluetooth_agent_manager_client_.reset(
1276e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        BluetoothAgentManagerClient::Create());
1286e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    bluetooth_device_client_.reset(BluetoothDeviceClient::Create());
1296e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    bluetooth_input_client_.reset(BluetoothInputClient::Create());
1306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    bluetooth_profile_manager_client_.reset(
1316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        BluetoothProfileManagerClient::Create());
1326e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    bluetooth_gatt_characteristic_client_.reset(
1336e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        BluetoothGattCharacteristicClient::Create());
1346e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    bluetooth_gatt_descriptor_client_.reset(
1356e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        BluetoothGattDescriptorClient::Create());
1366e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    bluetooth_gatt_manager_client_.reset(
1376e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        BluetoothGattManagerClient::Create());
1386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    bluetooth_gatt_service_client_.reset(
1396e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        BluetoothGattServiceClient::Create());
1406e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  } else {
1416e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    bluetooth_adapter_client_.reset(new FakeBluetoothAdapterClient);
1426e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    bluetooth_agent_manager_client_.reset(new FakeBluetoothAgentManagerClient);
1436e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    bluetooth_device_client_.reset(new FakeBluetoothDeviceClient);
1446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    bluetooth_input_client_.reset(new FakeBluetoothInputClient);
1456e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    bluetooth_profile_manager_client_.reset(
1466e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        new FakeBluetoothProfileManagerClient);
1476e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    bluetooth_gatt_characteristic_client_.reset(
1486e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        new FakeBluetoothGattCharacteristicClient);
1496e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    bluetooth_gatt_descriptor_client_.reset(
1506e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        new FakeBluetoothGattDescriptorClient);
1516e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    bluetooth_gatt_manager_client_.reset(new FakeBluetoothGattManagerClient);
1526e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    bluetooth_gatt_service_client_.reset(new FakeBluetoothGattServiceClient);
1536e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  }
1546e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!IsUsingStub(CRAS))
1566e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    cras_audio_client_.reset(CrasAudioClient::Create());
1576e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  else
1586e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    cras_audio_client_.reset(new CrasAudioClientStubImpl);
1596e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1606e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  cros_disks_client_.reset(CrosDisksClient::Create(
1611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      IsUsingStub(CROS_DISKS) ? STUB_DBUS_CLIENT_IMPLEMENTATION
1621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                              : REAL_DBUS_CLIENT_IMPLEMENTATION));
1636e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!IsUsingStub(CRYPTOHOME))
1656e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    cryptohome_client_.reset(CryptohomeClient::Create());
1666e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  else
1676e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    cryptohome_client_.reset(new FakeCryptohomeClient);
1686e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!IsUsingStub(DEBUG_DAEMON))
1706e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    debug_daemon_client_.reset(DebugDaemonClient::Create());
1716e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  else
1726e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    debug_daemon_client_.reset(new FakeDebugDaemonClient);
1736e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!IsUsingStub(EASY_UNLOCK))
1756e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    easy_unlock_client_.reset(EasyUnlockClient::Create());
1766e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  else
1776e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    easy_unlock_client_.reset(new FakeEasyUnlockClient);
1786e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!IsUsingStub(LORGNETTE_MANAGER))
1806e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    lorgnette_manager_client_.reset(LorgnetteManagerClient::Create());
1816e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  else
1826e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    lorgnette_manager_client_.reset(new FakeLorgnetteManagerClient);
1836e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!IsUsingStub(SHILL)) {
1856e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    shill_manager_client_.reset(ShillManagerClient::Create());
1866e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    shill_device_client_.reset(ShillDeviceClient::Create());
1876e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    shill_ipconfig_client_.reset(ShillIPConfigClient::Create());
1886e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    shill_service_client_.reset(ShillServiceClient::Create());
1896e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    shill_profile_client_.reset(ShillProfileClient::Create());
1906e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  } else {
1916e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    shill_manager_client_.reset(new FakeShillManagerClient);
1926e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    shill_device_client_.reset(new FakeShillDeviceClient);
1936e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    shill_ipconfig_client_.reset(new FakeShillIPConfigClient);
1946e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    shill_service_client_.reset(new FakeShillServiceClient);
1956e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    shill_profile_client_.reset(new FakeShillProfileClient);
1966e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  }
1976e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!IsUsingStub(GSM_SMS)) {
1996e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    gsm_sms_client_.reset(GsmSMSClient::Create());
2006e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  } else {
2016e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    FakeGsmSMSClient* gsm_sms_client = new FakeGsmSMSClient();
2026e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    gsm_sms_client->set_sms_test_message_switch_present(
2036e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        CommandLine::ForCurrentProcess()->HasSwitch(
2046e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)            chromeos::switches::kSmsTestMessages));
2056e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    gsm_sms_client_.reset(gsm_sms_client);
2066e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  }
2076e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
2081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!IsUsingStub(IMAGE_BURNER))
2096e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    image_burner_client_.reset(ImageBurnerClient::Create());
2106e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  else
2116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    image_burner_client_.reset(new FakeImageBurnerClient);
2126e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
2131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!IsUsingStub(INTROSPECTABLE))
2146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    introspectable_client_.reset(IntrospectableClient::Create());
2156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  else
2166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    introspectable_client_.reset(new FakeIntrospectableClient);
2176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
2181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!IsUsingStub(MODEM_MESSAGING))
2196e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    modem_messaging_client_.reset(ModemMessagingClient::Create());
2206e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  else
2211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    modem_messaging_client_.reset(new FakeModemMessagingClient);
2226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
2236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Create the NFC clients in the correct order based on their dependencies.
2241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!IsUsingStub(NFC)) {
2256e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    nfc_manager_client_.reset(NfcManagerClient::Create());
2266e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    nfc_adapter_client_.reset(
2276e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        NfcAdapterClient::Create(nfc_manager_client_.get()));
2286e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    nfc_device_client_.reset(
2296e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        NfcDeviceClient::Create(nfc_adapter_client_.get()));
2306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    nfc_tag_client_.reset(NfcTagClient::Create(nfc_adapter_client_.get()));
2316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    nfc_record_client_.reset(NfcRecordClient::Create(nfc_device_client_.get(),
2326e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                                     nfc_tag_client_.get()));
2336e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  } else {
2346e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    nfc_manager_client_.reset(new FakeNfcManagerClient);
2356e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    nfc_adapter_client_.reset(new FakeNfcAdapterClient);
2366e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    nfc_device_client_.reset(new FakeNfcDeviceClient);
2376e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    nfc_tag_client_.reset(new FakeNfcTagClient);
2386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    nfc_record_client_.reset(new FakeNfcRecordClient);
2396e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  }
2406e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
2411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!IsUsingStub(PERMISSION_BROKER))
2426e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    permission_broker_client_.reset(PermissionBrokerClient::Create());
2436e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  else
2446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    permission_broker_client_.reset(new FakePermissionBrokerClient);
2456e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
2466e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  power_manager_client_.reset(PowerManagerClient::Create(
2471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      IsUsingStub(POWER_MANAGER) ? STUB_DBUS_CLIENT_IMPLEMENTATION
2481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                 : REAL_DBUS_CLIENT_IMPLEMENTATION));
2496e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
2506e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  session_manager_client_.reset(SessionManagerClient::Create(
2511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      IsUsingStub(SESSION_MANAGER) ? STUB_DBUS_CLIENT_IMPLEMENTATION
2521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                   : REAL_DBUS_CLIENT_IMPLEMENTATION));
2536e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
2541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!IsUsingStub(SMS))
2556e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    sms_client_.reset(SMSClient::Create());
2566e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  else
2576e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    sms_client_.reset(new FakeSMSClient);
2586e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
2591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!IsUsingStub(SYSTEM_CLOCK))
2606e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    system_clock_client_.reset(SystemClockClient::Create());
2616e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  else
2626e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    system_clock_client_.reset(new FakeSystemClockClient);
2636e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
2646e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  update_engine_client_.reset(UpdateEngineClient::Create(
2651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      IsUsingStub(UPDATE_ENGINE) ? STUB_DBUS_CLIENT_IMPLEMENTATION
2661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                 : REAL_DBUS_CLIENT_IMPLEMENTATION));
2676e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}
2686e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
2696e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)DBusClientBundle::~DBusClientBundle() {
2706e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}
2716e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
2721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibool DBusClientBundle::IsUsingStub(DBusClientType client) {
2731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return !(unstub_client_mask_ & client);
2741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
2751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibool DBusClientBundle::IsUsingAnyRealClient() {
2771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // 'Using any real client' is equivalent to 'Unstubbed any client'.
2781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return unstub_client_mask_ != 0;
2791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
2801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2816e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)void DBusClientBundle::SetupDefaultEnvironment() {
2826e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  ShillManagerClient::TestInterface* manager =
2836e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      shill_manager_client_->GetTestInterface();
2846e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  if (manager)
2856e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    manager->SetupDefaultEnvironment();
2866e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}
2876e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
2886e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// static
2896e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)DBusClientBundle::DBusClientTypeMask DBusClientBundle::ParseUnstubList(
2906e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    const std::string& unstub_list) {
2916e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  DBusClientTypeMask unstub_mask = 0;
2926e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  std::vector<std::string> unstub_components;
2936e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  base::SplitString(unstub_list, ',', &unstub_components);
2946e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  for (std::vector<std::string>::const_iterator iter =
2956e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)          unstub_components.begin();
2966e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)       iter != unstub_components.end(); ++iter) {
2976e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    DBusClientBundle::DBusClientType client = GetDBusClientType(*iter);
2981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    if (client != NO_CLIENT) {
2996e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      LOG(WARNING) << "Unstubbing dbus client for " << *iter;
3006e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      unstub_mask |= client;
3016e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    } else {
3026e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      LOG(ERROR) << "Unknown dbus client: " << *iter;
3036e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    }
3046e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  }
3056e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
3066e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  return unstub_mask;
3076e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}
3086e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
3096e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}  // namespace chromeos
310