diff options
author | youngki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-18 22:15:23 +0000 |
---|---|---|
committer | youngki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-18 22:15:23 +0000 |
commit | cab208eb0702d3541a7fa430889c26a3d1182120 (patch) | |
tree | a5ddeb04c32edd7ca0288ea8614d33caf2bb01e1 | |
parent | 2b392e59ab9a72858d224bad9e422fe40a696a69 (diff) | |
download | chromium_src-cab208eb0702d3541a7fa430889c26a3d1182120.zip chromium_src-cab208eb0702d3541a7fa430889c26a3d1182120.tar.gz chromium_src-cab208eb0702d3541a7fa430889c26a3d1182120.tar.bz2 |
Moved bluetooth adapter files from chrome/browser/chromeos/bluetooth/ to device/bluetooth/. device/bluetooth/ is a new directory to host the bluetooth related files.
I also changed the namespace from chromeos to bluetooth under new directory.
BUG=135470
Review URL: https://chromiumcodereview.appspot.com/11075006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162811 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | build/all.gyp | 9 | ||||
-rw-r--r-- | chrome/app/generated_resources.grd | 81 | ||||
-rw-r--r-- | chrome/browser/DEPS | 1 | ||||
-rw-r--r-- | chrome/browser/chromeos/DEPS | 1 | ||||
-rw-r--r-- | chrome/browser/chromeos/system/ash_system_tray_delegate.cc | 37 | ||||
-rw-r--r-- | chrome/browser/extensions/api/bluetooth/bluetooth_api.cc | 266 | ||||
-rw-r--r-- | chrome/browser/extensions/api/bluetooth/bluetooth_api.h | 49 | ||||
-rw-r--r-- | chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc | 15 | ||||
-rw-r--r-- | chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h | 13 | ||||
-rw-r--r-- | chrome/browser/extensions/api/bluetooth/bluetooth_apitest_chromeos.cc | 54 | ||||
-rw-r--r-- | chrome/browser/extensions/bluetooth_event_router.cc (renamed from chrome/browser/chromeos/extensions/bluetooth_event_router.cc) | 39 | ||||
-rw-r--r-- | chrome/browser/extensions/bluetooth_event_router.h (renamed from chrome/browser/chromeos/extensions/bluetooth_event_router.h) | 51 | ||||
-rw-r--r-- | chrome/browser/extensions/event_names.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/event_names.h | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_service.cc | 7 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_service.h | 10 | ||||
-rw-r--r-- | chrome/browser/ui/webui/DEPS | 1 | ||||
-rw-r--r-- | chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc | 49 | ||||
-rw-r--r-- | chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h | 81 | ||||
-rw-r--r-- | chrome/chrome_browser_chromeos.gypi | 20 | ||||
-rw-r--r-- | chrome/chrome_browser_extensions.gypi | 3 | ||||
-rw-r--r-- | chrome/chrome_browser_ui.gypi | 1 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 11 | ||||
-rw-r--r-- | chromeos/chromeos.gyp | 1 | ||||
-rw-r--r-- | chromeos/dbus/DEPS | 1 | ||||
-rw-r--r-- | chromeos/dbus/bluetooth_out_of_band_client.cc | 23 | ||||
-rw-r--r-- | chromeos/dbus/bluetooth_out_of_band_client.h | 11 | ||||
-rw-r--r-- | chromeos/dbus/mock_bluetooth_out_of_band_client.h | 4 | ||||
-rw-r--r-- | device/DEPS | 4 | ||||
-rw-r--r-- | device/bluetooth/DEPS | 11 | ||||
-rw-r--r-- | device/bluetooth/OWNERS (renamed from chrome/browser/chromeos/bluetooth/OWNERS) | 0 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter.cc (renamed from chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc) | 8 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter.h (renamed from chrome/browser/chromeos/bluetooth/bluetooth_adapter.h) | 10 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_chromeos.cc (renamed from chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.cc) | 14 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_chromeos.h (renamed from chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h) | 57 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_chromeos_devices_unittest.cc (renamed from chrome/browser/chromeos/bluetooth/bluetooth_adapter_devices_chromeos_unittest.cc) | 21 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_chromeos_unittest.cc (renamed from chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos_unittest.cc) | 12 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_factory.cc (renamed from chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.cc) | 33 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_factory.h (renamed from chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.h) | 15 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device.cc (renamed from chrome/browser/chromeos/bluetooth/bluetooth_device.cc) | 6 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device.h (renamed from chrome/browser/chromeos/bluetooth/bluetooth_device.h) | 12 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_chromeos.cc (renamed from chrome/browser/chromeos/bluetooth/bluetooth_device_chromeos.cc) | 21 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_chromeos.h (renamed from chrome/browser/chromeos/bluetooth/bluetooth_device_chromeos.h) | 34 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_out_of_band_pairing_data.h (renamed from chromeos/dbus/bluetooth_out_of_band_pairing_data.h) | 14 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_service_record.cc (renamed from chrome/browser/chromeos/bluetooth/bluetooth_service_record.cc) | 10 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_service_record.h (renamed from chrome/browser/chromeos/bluetooth/bluetooth_service_record.h) | 14 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_service_record_unittest.cc (renamed from chrome/browser/chromeos/bluetooth/bluetooth_service_record_unittest.cc) | 17 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_socket.h (renamed from chrome/browser/chromeos/bluetooth/bluetooth_socket.h) | 10 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_socket_chromeos.cc (renamed from chrome/browser/chromeos/bluetooth/bluetooth_socket_chromeos.cc) | 11 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_socket_chromeos.h (renamed from chrome/browser/chromeos/bluetooth/bluetooth_socket_chromeos.h) | 21 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_utils.cc (renamed from chrome/browser/chromeos/bluetooth/bluetooth_utils.cc) | 10 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_utils.h (renamed from chrome/browser/chromeos/bluetooth/bluetooth_utils.h) | 14 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_utils_unittest.cc (renamed from chrome/browser/chromeos/bluetooth/bluetooth_utils_unittest.cc) | 14 | ||||
-rw-r--r-- | device/bluetooth/test/mock_bluetooth_adapter.cc (renamed from chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.cc) | 6 | ||||
-rw-r--r-- | device/bluetooth/test/mock_bluetooth_adapter.h (renamed from chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h) | 15 | ||||
-rw-r--r-- | device/bluetooth/test/mock_bluetooth_device.cc (renamed from chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.cc) | 8 | ||||
-rw-r--r-- | device/bluetooth/test/mock_bluetooth_device.h (renamed from chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.h) | 18 | ||||
-rw-r--r-- | device/device.gyp | 111 | ||||
-rw-r--r-- | device/test/data/bluetooth/invalid_uuid.xml (renamed from chrome/test/data/chromeos/bluetooth/invalid_uuid.xml) | 0 | ||||
-rw-r--r-- | device/test/data/bluetooth/medium_uuid.xml (renamed from chrome/test/data/chromeos/bluetooth/medium_uuid.xml) | 0 | ||||
-rw-r--r-- | device/test/data/bluetooth/rfcomm.xml (renamed from chrome/test/data/chromeos/bluetooth/rfcomm.xml) | 0 | ||||
-rw-r--r-- | device/test/data/bluetooth/short_uuid.xml (renamed from chrome/test/data/chromeos/bluetooth/short_uuid.xml) | 0 | ||||
-rw-r--r-- | device/test/data/bluetooth/uppercase_uuid.xml (renamed from chrome/test/data/chromeos/bluetooth/uppercase_uuid.xml) | 0 | ||||
-rw-r--r-- | device/test/device_test_suite.cc | 18 | ||||
-rw-r--r-- | device/test/device_test_suite.h | 19 | ||||
-rw-r--r-- | device/test/run_all_unittests.cc | 10 |
66 files changed, 819 insertions, 622 deletions
diff --git a/build/all.gyp b/build/all.gyp index e7b50dd..7985110 100644 --- a/build/all.gyp +++ b/build/all.gyp @@ -33,6 +33,7 @@ 'dependencies': [ '../cc/cc_tests.gyp:*', '../chrome/chrome.gyp:*', + '../device/device.gyp:*', '../gpu/gpu.gyp:*', '../gpu/tools/tools.gyp:*', '../ipc/ipc.gyp:*', @@ -196,6 +197,7 @@ '../cloud_print/cloud_print.gyp:cloud_print_unittests', '../content/content.gyp:content_browsertests', '../content/content.gyp:content_unittests', + '../device/device.gyp:device_unittests', '../gpu/gpu.gyp:gpu_unittests', '../gpu/gles2_conform_support/gles2_conform_support.gyp:gles2_conform_support', '../ipc/ipc.gyp:ipc_tests', @@ -364,6 +366,7 @@ '../cloud_print/cloud_print.gyp:cloud_print_unittests', '../content/content.gyp:content_browsertests', '../content/content.gyp:content_unittests', + '../device/device.gyp:device_unittests', '../ui/ui.gyp:ui_unittests', '../gpu/gpu.gyp:gpu_unittests', '../ipc/ipc.gyp:ipc_tests', @@ -395,6 +398,7 @@ '../cloud_print/cloud_print.gyp:cloud_print_unittests', '../content/content.gyp:content_browsertests', '../content/content.gyp:content_unittests', + '../device/device.gyp:device_unittests', '../ui/ui.gyp:ui_unittests', '../gpu/gpu.gyp:gpu_unittests', '../ipc/ipc.gyp:ipc_tests', @@ -453,6 +457,7 @@ '../chrome/chrome.gyp:safe_browsing_tests', '../chrome/chrome.gyp:unit_tests', '../content/content.gyp:content_unittests', + '../device/device.gyp:device_unittests', '../ui/ui.gyp:ui_unittests', '../jingle/jingle.gyp:jingle_unittests', '../sql/sql.gyp:sql_unittests', @@ -495,6 +500,7 @@ '../chrome_frame/chrome_frame.gyp:chrome_frame_unittests', '../chrome_frame/chrome_frame.gyp:npchrome_frame', '../courgette/courgette.gyp:courgette_unittests', + '../device/device.gyp:device_unittests', '../ui/ui.gyp:ui_unittests', '../gpu/gpu.gyp:gpu_unittests', '../ipc/ipc.gyp:ipc_tests', @@ -554,6 +560,7 @@ '../cloud_print/cloud_print.gyp:cloud_print_unittests', '../content/content.gyp:content_unittests', '../crypto/crypto.gyp:crypto_unittests', + '../device/device.gyp:device_unittests', '../ipc/ipc.gyp:ipc_tests', '../jingle/jingle.gyp:jingle_unittests', '../media/media.gyp:media_unittests', @@ -640,6 +647,7 @@ '../chrome/chrome.gyp:unit_tests', '../content/content.gyp:content_browsertests', '../content/content.gyp:content_unittests', + '../device/device.gyp:device_unittests', '../ppapi/ppapi_internal.gyp:ppapi_unittests', '../remoting/remoting.gyp:remoting_unittests', '../ui/aura/aura.gyp:*', @@ -686,6 +694,7 @@ 'dependencies!': [ '../chrome/chrome.gyp:chrome', '../chrome/chrome.gyp:unit_tests', + '../device/device.gyp:device_unittests', '../ui/views/views.gyp:views_unittests', ], }], diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 6ee27c8..2e854a6 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -14417,48 +14417,45 @@ Some features may be unavailable. Please check that the profile exists and you Expand </message> - <!-- Bluetooth device class strings --> - <if expr="pp_ifdef('chromeos')"> - <message name="IDS_BLUETOOTH_DEVICE_UNKNOWN" desc="Text to identify bluetooth devices of unknown or unsupported class."> - Unknown or Unsupported Device (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) - </message> - <message name="IDS_BLUETOOTH_DEVICE_COMPUTER" desc="Text to identify bluetooth devices of the computer class."> - Computer (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) - </message> - <message name="IDS_BLUETOOTH_DEVICE_PHONE" desc="Text to identify bluetooth devices of the phone class."> - Phone (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) - </message> - <message name="IDS_BLUETOOTH_DEVICE_MODEM" desc="Text to identify bluetooth devices of the modem class."> - Modem (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) - </message> - <message name="IDS_BLUETOOTH_DEVICE_AUDIO" desc="Text to identify bluetooth devices of the audio class."> - Audio (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) - </message> - <message name="IDS_BLUETOOTH_DEVICE_CAR_AUDIO" desc="Text to identify bluetooth devices of the car audio class."> - Car audio (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) - </message> - <message name="IDS_BLUETOOTH_DEVICE_VIDEO" desc="Text to identify bluetooth devices of the video class."> - Video (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) - </message> - <message name="IDS_BLUETOOTH_DEVICE_JOYSTICK" desc="Text to identify bluetooth devices of the joystick class."> - Joystick (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) - </message> - <message name="IDS_BLUETOOTH_DEVICE_GAMEPAD" desc="Text to identify bluetooth devices of the gamepad class."> - Gamepad (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) - </message> - <message name="IDS_BLUETOOTH_DEVICE_KEYBOARD" desc="Text to identify bluetooth devices of the keyboard class."> - Keyboard (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) - </message> - <message name="IDS_BLUETOOTH_DEVICE_TABLET" desc="Text to identify bluetooth devices of the tablet class."> - Tablet (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) - </message> - <message name="IDS_BLUETOOTH_DEVICE_MOUSE" desc="Text to identify bluetooth devices of the mouse class."> - Mouse (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) - </message> - <message name="IDS_BLUETOOTH_DEVICE_KEYBOARD_MOUSE_COMBO" desc="Text to identify bluetooth devices of both keyboard and mouse class."> - Keyboard/Mouse (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) - </message> - </if> + <message name="IDS_BLUETOOTH_DEVICE_UNKNOWN" desc="Text to identify bluetooth devices of unknown or unsupported class."> + Unknown or Unsupported Device (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) + </message> + <message name="IDS_BLUETOOTH_DEVICE_COMPUTER" desc="Text to identify bluetooth devices of the computer class."> + Computer (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) + </message> + <message name="IDS_BLUETOOTH_DEVICE_PHONE" desc="Text to identify bluetooth devices of the phone class."> + Phone (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) + </message> + <message name="IDS_BLUETOOTH_DEVICE_MODEM" desc="Text to identify bluetooth devices of the modem class."> + Modem (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) + </message> + <message name="IDS_BLUETOOTH_DEVICE_AUDIO" desc="Text to identify bluetooth devices of the audio class."> + Audio (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) + </message> + <message name="IDS_BLUETOOTH_DEVICE_CAR_AUDIO" desc="Text to identify bluetooth devices of the car audio class."> + Car audio (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) + </message> + <message name="IDS_BLUETOOTH_DEVICE_VIDEO" desc="Text to identify bluetooth devices of the video class."> + Video (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) + </message> + <message name="IDS_BLUETOOTH_DEVICE_JOYSTICK" desc="Text to identify bluetooth devices of the joystick class."> + Joystick (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) + </message> + <message name="IDS_BLUETOOTH_DEVICE_GAMEPAD" desc="Text to identify bluetooth devices of the gamepad class."> + Gamepad (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) + </message> + <message name="IDS_BLUETOOTH_DEVICE_KEYBOARD" desc="Text to identify bluetooth devices of the keyboard class."> + Keyboard (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) + </message> + <message name="IDS_BLUETOOTH_DEVICE_TABLET" desc="Text to identify bluetooth devices of the tablet class."> + Tablet (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) + </message> + <message name="IDS_BLUETOOTH_DEVICE_MOUSE" desc="Text to identify bluetooth devices of the mouse class."> + Mouse (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) + </message> + <message name="IDS_BLUETOOTH_DEVICE_KEYBOARD_MOUSE_COMBO" desc="Text to identify bluetooth devices of both keyboard and mouse class."> + Keyboard/Mouse (<ph name="ADDRESS">$1<ex>12:34:56:78:9A:BC</ex></ph>) + </message> <!-- High-constrast mode. --> <message name="IDS_HIGH_CONTRAST_NOTIFICATION" diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 50aefc2..3b6c334 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -5,6 +5,7 @@ include_rules = [ "+chrome/tools/profiles", # For history unit tests. "+chromeos", "+content/public/browser", + "+device", "+google/cacheinvalidation", # Sync invalidation API protobuf files. "+google_apis", "+google_update", diff --git a/chrome/browser/chromeos/DEPS b/chrome/browser/chromeos/DEPS index 770f46e..59bd733 100644 --- a/chrome/browser/chromeos/DEPS +++ b/chrome/browser/chromeos/DEPS @@ -1,6 +1,7 @@ include_rules = [ "+cros", "+dbus", + "+device/bluetooth", "+media/base/media_switches.h", # For media command line switches. "+third_party/mozc", "+webkit/chromeos/fileapi", diff --git a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc index 6221139..eb000b1 100644 --- a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc +++ b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc @@ -30,9 +30,6 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/chromeos/accessibility/accessibility_util.h" #include "chrome/browser/chromeos/audio/audio_handler.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/drive/drive_system_service.h" @@ -72,6 +69,9 @@ #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/user_metrics.h" +#include "device/bluetooth/bluetooth_adapter.h" +#include "device/bluetooth/bluetooth_adapter_factory.h" +#include "device/bluetooth/bluetooth_device.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" @@ -154,7 +154,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, public content::NotificationObserver, public input_method::InputMethodManager::Observer, public system::TimezoneSettings::Observer, - public BluetoothAdapter::Observer, + public device::BluetoothAdapter::Observer, public SystemKeyEventListener::CapsLockObserver, public ash::NetworkTrayDelegate { public: @@ -216,7 +216,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, network_icon_->SetResourceColorTheme(NetworkMenuIcon::COLOR_LIGHT); network_icon_dark_->SetResourceColorTheme(NetworkMenuIcon::COLOR_DARK); - bluetooth_adapter_ = BluetoothAdapterFactory::DefaultAdapter(); + bluetooth_adapter_ = device::BluetoothAdapterFactory::DefaultAdapter(); bluetooth_adapter_->AddObserver(this); } @@ -362,9 +362,10 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, virtual void GetAvailableBluetoothDevices( ash::BluetoothDeviceList* list) OVERRIDE { - BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); + device::BluetoothAdapter::DeviceList devices = + bluetooth_adapter_->GetDevices(); for (size_t i = 0; i < devices.size(); ++i) { - BluetoothDevice* device = devices[i]; + device::BluetoothDevice* device = devices[i]; if (!device->IsPaired()) continue; ash::BluetoothDeviceInfo info; @@ -376,7 +377,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, } virtual void ToggleBluetoothConnection(const std::string& address) OVERRIDE { - BluetoothDevice* device = bluetooth_adapter_->GetDevice(address); + device::BluetoothDevice* device = bluetooth_adapter_->GetDevice(address); if (!device) return; if (device->IsConnected()) { @@ -1155,34 +1156,34 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, } // Overridden from BluetoothAdapter::Observer. - virtual void AdapterPresentChanged(BluetoothAdapter* adapter, + virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter, bool present) OVERRIDE { NotifyRefreshBluetooth(); } - virtual void AdapterPoweredChanged(BluetoothAdapter* adapter, + virtual void AdapterPoweredChanged(device::BluetoothAdapter* adapter, bool powered) OVERRIDE { NotifyRefreshBluetooth(); } - virtual void AdapterDiscoveringChanged(BluetoothAdapter* adapter, + virtual void AdapterDiscoveringChanged(device::BluetoothAdapter* adapter, bool discovering) OVERRIDE { // TODO: Perhaps start/stop throbbing the icon, or some other visual // effects? } - virtual void DeviceAdded(BluetoothAdapter* adapter, - BluetoothDevice* device) OVERRIDE { + virtual void DeviceAdded(device::BluetoothAdapter* adapter, + device::BluetoothDevice* device) OVERRIDE { NotifyRefreshBluetooth(); } - virtual void DeviceChanged(BluetoothAdapter* adapter, - BluetoothDevice* device) OVERRIDE { + virtual void DeviceChanged(device::BluetoothAdapter* adapter, + device::BluetoothDevice* device) OVERRIDE { NotifyRefreshBluetooth(); } - virtual void DeviceRemoved(BluetoothAdapter* adapter, - BluetoothDevice* device) OVERRIDE { + virtual void DeviceRemoved(device::BluetoothAdapter* adapter, + device::BluetoothDevice* device) OVERRIDE { NotifyRefreshBluetooth(); } @@ -1251,7 +1252,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, std::string last_connection_string_; - scoped_refptr<BluetoothAdapter> bluetooth_adapter_; + scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; BooleanPrefMember accessibility_enabled_; diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc index 12b4350..6e425a4 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc @@ -10,45 +10,51 @@ #include <string> +#include "base/memory/ref_counted.h" #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" +#include "chrome/browser/extensions/bluetooth_event_router.h" #include "chrome/browser/extensions/event_names.h" #include "chrome/browser/extensions/event_router.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/extensions/api/experimental_bluetooth.h" #include "content/public/browser/browser_thread.h" +#include "device/bluetooth/bluetooth_adapter.h" +#include "device/bluetooth/bluetooth_device.h" +#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" +#include "device/bluetooth/bluetooth_service_record.h" +#include "device/bluetooth/bluetooth_socket.h" +#include "device/bluetooth/bluetooth_utils.h" #if defined(OS_CHROMEOS) -#include "base/memory/ref_counted.h" #include "base/safe_strerror_posix.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h" -#include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" -#include "chromeos/dbus/bluetooth_out_of_band_client.h" -#include "chromeos/dbus/bluetooth_out_of_band_pairing_data.h" +#endif + +using device::BluetoothAdapter; +using device::BluetoothDevice; +using device::BluetoothServiceRecord; +using device::BluetoothSocket; namespace { -chromeos::ExtensionBluetoothEventRouter* GetEventRouter(Profile* profile) { +extensions::ExtensionBluetoothEventRouter* GetEventRouter(Profile* profile) { return profile->GetExtensionService()->bluetooth_event_router(); } -const chromeos::BluetoothAdapter& GetAdapter(Profile* profile) { +const BluetoothAdapter* GetAdapter(Profile* profile) { return GetEventRouter(profile)->adapter(); } -chromeos::BluetoothAdapter* GetMutableAdapter(Profile* profile) { - chromeos::BluetoothAdapter* adapter = - GetEventRouter(profile)->GetMutableAdapter(); - CHECK(adapter); +BluetoothAdapter* GetMutableAdapter(Profile* profile) { + BluetoothAdapter* adapter = GetEventRouter(profile)->GetMutableAdapter(); return adapter; } +bool IsBluetoothSupported(Profile* profile) { + return GetAdapter(profile) != NULL; +} + } // namespace -#endif namespace { @@ -59,6 +65,8 @@ const char kCouldNotSetOutOfBandPairingData[] = const char kFailedToConnect[] = "Connection failed"; const char kInvalidDevice[] = "Invalid device"; const char kInvalidUuid[] = "Invalid UUID"; +const char kPlatformNotSupported[] = + "This operation is not supported on your platform"; const char kServiceDiscoveryFailed[] = "Service discovery failed"; const char kSocketNotFoundError[] = "Socket not found: invalid socket id"; const char kStartDiscoveryFailed[] = "Starting discovery failed"; @@ -78,25 +86,43 @@ namespace Write = extensions::api::experimental_bluetooth::Write; namespace extensions { namespace api { -#if defined(OS_CHROMEOS) - bool BluetoothIsAvailableFunction::RunImpl() { - SetResult(Value::CreateBooleanValue(GetAdapter(profile()).IsPresent())); + if (!IsBluetoothSupported(profile())) { + SetError(kPlatformNotSupported); + return false; + } + + SetResult(Value::CreateBooleanValue(GetAdapter(profile())->IsPresent())); return true; } bool BluetoothIsPoweredFunction::RunImpl() { - SetResult(Value::CreateBooleanValue(GetAdapter(profile()).IsPowered())); + if (!IsBluetoothSupported(profile())) { + SetError(kPlatformNotSupported); + return false; + } + + SetResult(Value::CreateBooleanValue(GetAdapter(profile())->IsPowered())); return true; } bool BluetoothGetAddressFunction::RunImpl() { - SetResult(Value::CreateStringValue(GetAdapter(profile()).address())); + if (!IsBluetoothSupported(profile())) { + SetError(kPlatformNotSupported); + return false; + } + + SetResult(Value::CreateStringValue(GetAdapter(profile())->address())); return true; } bool BluetoothGetNameFunction::RunImpl() { - SetResult(Value::CreateStringValue(GetAdapter(profile()).name())); + if (!IsBluetoothSupported(profile())) { + SetError(kPlatformNotSupported); + return false; + } + + SetResult(Value::CreateStringValue(GetAdapter(profile())->name())); return true; } @@ -105,7 +131,7 @@ BluetoothGetDevicesFunction::BluetoothGetDevicesFunction() device_events_sent_(0) {} void BluetoothGetDevicesFunction::DispatchDeviceSearchResult( - const chromeos::BluetoothDevice& device) { + const BluetoothDevice& device) { experimental_bluetooth::Device extension_device; experimental_bluetooth::BluetoothDeviceToApiDevice(device, &extension_device); GetEventRouter(profile())->DispatchDeviceEvent( @@ -116,8 +142,7 @@ void BluetoothGetDevicesFunction::DispatchDeviceSearchResult( } void BluetoothGetDevicesFunction::ProvidesServiceCallback( - const chromeos::BluetoothDevice* device, - bool providesService) { + const BluetoothDevice* device, bool providesService) { DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); CHECK(device); @@ -145,6 +170,11 @@ void BluetoothGetDevicesFunction::FinishDeviceSearch() { } bool BluetoothGetDevicesFunction::RunImpl() { + if (!IsBluetoothSupported(profile())) { + SetError(kPlatformNotSupported); + return false; + } + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); scoped_ptr<GetDevices::Params> params(GetDevices::Params::Create(*args_)); @@ -153,7 +183,7 @@ bool BluetoothGetDevicesFunction::RunImpl() { std::string uuid; if (options.uuid.get() != NULL) { - uuid = chromeos::bluetooth_utils::CanonicalUuid(*options.uuid.get()); + uuid = device::bluetooth_utils::CanonicalUuid(*options.uuid.get()); if (uuid.empty()) { SetError(kInvalidUuid); return false; @@ -162,11 +192,11 @@ bool BluetoothGetDevicesFunction::RunImpl() { CHECK_EQ(0, callbacks_pending_); - chromeos::BluetoothAdapter::DeviceList devices = + BluetoothAdapter::DeviceList devices = GetMutableAdapter(profile())->GetDevices(); - for (chromeos::BluetoothAdapter::DeviceList::iterator i = devices.begin(); + for (BluetoothAdapter::DeviceList::iterator i = devices.begin(); i != devices.end(); ++i) { - chromeos::BluetoothDevice* device = *i; + BluetoothDevice* device = *i; CHECK(device); if (!uuid.empty() && !(device->ProvidesServiceWithUUID(uuid))) @@ -197,10 +227,10 @@ bool BluetoothGetDevicesFunction::RunImpl() { void BluetoothGetServicesFunction::GetServiceRecordsCallback( base::ListValue* services, - const chromeos::BluetoothDevice::ServiceRecordList& records) { - for (chromeos::BluetoothDevice::ServiceRecordList::const_iterator i = - records.begin(); i != records.end(); ++i) { - const chromeos::BluetoothServiceRecord& record = **i; + const BluetoothDevice::ServiceRecordList& records) { + for (BluetoothDevice::ServiceRecordList::const_iterator i = records.begin(); + i != records.end(); ++i) { + const BluetoothServiceRecord& record = **i; experimental_bluetooth::ServiceRecord api_record; api_record.name = record.name(); if (!record.uuid().empty()) @@ -217,11 +247,16 @@ void BluetoothGetServicesFunction::OnErrorCallback() { } bool BluetoothGetServicesFunction::RunImpl() { + if (!IsBluetoothSupported(profile())) { + SetError(kPlatformNotSupported); + return false; + } + scoped_ptr<GetServices::Params> params(GetServices::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); const experimental_bluetooth::GetServicesOptions& options = params->options; - chromeos::BluetoothDevice* device = + BluetoothDevice* device = GetMutableAdapter(profile())->GetDevice(options.device_address); if (!device) { SetError(kInvalidDevice); @@ -242,9 +277,9 @@ bool BluetoothGetServicesFunction::RunImpl() { } void BluetoothConnectFunction::ConnectToServiceCallback( - const chromeos::BluetoothDevice* device, + const BluetoothDevice* device, const std::string& service_uuid, - scoped_refptr<chromeos::BluetoothSocket> socket) { + scoped_refptr<BluetoothSocket> socket) { if (socket.get()) { int socket_id = GetEventRouter(profile())->RegisterSocket(socket); @@ -262,18 +297,23 @@ void BluetoothConnectFunction::ConnectToServiceCallback( } bool BluetoothConnectFunction::RunImpl() { + if (!IsBluetoothSupported(profile())) { + SetError(kPlatformNotSupported); + return false; + } + scoped_ptr<Connect::Params> params(Connect::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); const experimental_bluetooth::ConnectOptions& options = params->options; - std::string uuid = chromeos::bluetooth_utils::CanonicalUuid( + std::string uuid = device::bluetooth_utils::CanonicalUuid( options.service_uuid); if (uuid.empty()) { SetError(kInvalidUuid); return false; } - chromeos::BluetoothDevice* device = + BluetoothDevice* device = GetMutableAdapter(profile())->GetDevice(options.device_address); if (!device) { SetError(kInvalidDevice); @@ -295,6 +335,9 @@ bool BluetoothDisconnectFunction::RunImpl() { return GetEventRouter(profile())->ReleaseSocket(options.socket_id); } +BluetoothReadFunction::BluetoothReadFunction() {} +BluetoothReadFunction::~BluetoothReadFunction() {} + bool BluetoothReadFunction::Prepare() { scoped_ptr<Read::Params> params(Read::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); @@ -311,8 +354,11 @@ bool BluetoothReadFunction::Prepare() { } void BluetoothReadFunction::Work() { + if (!socket_.get()) + return; + +#if defined(OS_CHROMEOS) DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); - CHECK(socket_.get() != NULL); char* all_bytes = NULL; ssize_t buffer_size = 0; @@ -343,12 +389,16 @@ void BluetoothReadFunction::Work() { if (!success_) SetError(safe_strerror(errsv)); +#endif } bool BluetoothReadFunction::Respond() { return success_; } +BluetoothWriteFunction::BluetoothWriteFunction() {} +BluetoothWriteFunction::~BluetoothWriteFunction() {} + bool BluetoothWriteFunction::Prepare() { // TODO(bryeung): update to new-style parameter passing when ArrayBuffer // support is added @@ -377,6 +427,7 @@ void BluetoothWriteFunction::Work() { if (socket_.get() == NULL) return; +#if defined(OS_CHROMEOS) ssize_t bytes_written = write(socket_->fd(), data_to_write_->GetBuffer(), data_to_write_->GetSize()); int errsv = errno; @@ -391,6 +442,7 @@ void BluetoothWriteFunction::Work() { if (!success_) SetError(safe_strerror(errsv)); +#endif } bool BluetoothWriteFunction::Respond() { @@ -407,6 +459,11 @@ void BluetoothSetOutOfBandPairingDataFunction::OnErrorCallback() { } bool BluetoothSetOutOfBandPairingDataFunction::RunImpl() { + if (!IsBluetoothSupported(profile())) { + SetError(kPlatformNotSupported); + return false; + } + // TODO(bryeung): update to new-style parameter passing when ArrayBuffer // support is added DictionaryValue* options; @@ -414,8 +471,7 @@ bool BluetoothSetOutOfBandPairingDataFunction::RunImpl() { std::string address; EXTENSION_FUNCTION_VALIDATE(options->GetString("deviceAddress", &address)); - chromeos::BluetoothDevice* device = - GetMutableAdapter(profile())->GetDevice(address); + BluetoothDevice* device = GetMutableAdapter(profile())->GetDevice(address); if (!device) { SetError(kInvalidDevice); return false; @@ -425,22 +481,22 @@ bool BluetoothSetOutOfBandPairingDataFunction::RunImpl() { DictionaryValue* data_in; EXTENSION_FUNCTION_VALIDATE(options->GetDictionary("data", &data_in)); - chromeos::BluetoothOutOfBandPairingData data_out; + device::BluetoothOutOfBandPairingData data_out; base::BinaryValue* tmp_data; EXTENSION_FUNCTION_VALIDATE(data_in->GetBinary("hash", &tmp_data)); EXTENSION_FUNCTION_VALIDATE( - tmp_data->GetSize() == chromeos::kBluetoothOutOfBandPairingDataSize); + tmp_data->GetSize() == device::kBluetoothOutOfBandPairingDataSize); memcpy(data_out.hash, reinterpret_cast<uint8_t*>(tmp_data->GetBuffer()), - chromeos::kBluetoothOutOfBandPairingDataSize); + device::kBluetoothOutOfBandPairingDataSize); EXTENSION_FUNCTION_VALIDATE(data_in->GetBinary("randomizer", &tmp_data)); EXTENSION_FUNCTION_VALIDATE( - tmp_data->GetSize() == chromeos::kBluetoothOutOfBandPairingDataSize); + tmp_data->GetSize() == device::kBluetoothOutOfBandPairingDataSize); memcpy(data_out.randomizer, reinterpret_cast<uint8_t*>(tmp_data->GetBuffer()), - chromeos::kBluetoothOutOfBandPairingDataSize); + device::kBluetoothOutOfBandPairingDataSize); device->SetOutOfBandPairingData( data_out, @@ -460,13 +516,13 @@ bool BluetoothSetOutOfBandPairingDataFunction::RunImpl() { } void BluetoothGetLocalOutOfBandPairingDataFunction::ReadCallback( - const chromeos::BluetoothOutOfBandPairingData& data) { + const device::BluetoothOutOfBandPairingData& data) { base::BinaryValue* hash = base::BinaryValue::CreateWithCopiedBuffer( reinterpret_cast<const char*>(data.hash), - chromeos::kBluetoothOutOfBandPairingDataSize); + device::kBluetoothOutOfBandPairingDataSize); base::BinaryValue* randomizer = base::BinaryValue::CreateWithCopiedBuffer( reinterpret_cast<const char*>(data.randomizer), - chromeos::kBluetoothOutOfBandPairingDataSize); + device::kBluetoothOutOfBandPairingDataSize); // TODO(bryeung): convert to experimental_bluetooth::OutOfBandPairingData // when ArrayBuffer support within objects is completed. @@ -485,6 +541,11 @@ void BluetoothGetLocalOutOfBandPairingDataFunction::ErrorCallback() { } bool BluetoothGetLocalOutOfBandPairingDataFunction::RunImpl() { + if (!IsBluetoothSupported(profile())) { + SetError(kPlatformNotSupported); + return false; + } + GetMutableAdapter(profile())->ReadLocalOutOfBandPairingData( base::Bind(&BluetoothGetLocalOutOfBandPairingDataFunction::ReadCallback, this), @@ -504,6 +565,11 @@ void BluetoothStartDiscoveryFunction::OnErrorCallback() { } bool BluetoothStartDiscoveryFunction::RunImpl() { + if (!IsBluetoothSupported(profile())) { + SetError(kPlatformNotSupported); + return false; + } + GetEventRouter(profile())->SetSendDiscoveryEvents(true); // If the adapter is already discovering, there is nothing else to do. @@ -528,6 +594,11 @@ void BluetoothStopDiscoveryFunction::OnErrorCallback() { } bool BluetoothStopDiscoveryFunction::RunImpl() { + if (!IsBluetoothSupported(profile())) { + SetError(kPlatformNotSupported); + return false; + } + GetEventRouter(profile())->SetSendDiscoveryEvents(false); if (GetEventRouter(profile())->IsResponsibleForDiscovery()) { GetMutableAdapter(profile())->SetDiscovering(false, @@ -537,102 +608,5 @@ bool BluetoothStopDiscoveryFunction::RunImpl() { return true; } -#else - -// ----------------------------------------------------------------------------- -// NIY stubs -// ----------------------------------------------------------------------------- -bool BluetoothIsAvailableFunction::RunImpl() { - NOTREACHED() << "Not implemented yet"; - return false; -} - -bool BluetoothIsPoweredFunction::RunImpl() { - NOTREACHED() << "Not implemented yet"; - return false; -} - -bool BluetoothGetAddressFunction::RunImpl() { - NOTREACHED() << "Not implemented yet"; - return false; -} - -bool BluetoothGetNameFunction::RunImpl() { - NOTREACHED() << "Not implemented yet"; - return false; -} - -bool BluetoothGetDevicesFunction::RunImpl() { - NOTREACHED() << "Not implemented yet"; - return false; -} - -bool BluetoothGetServicesFunction::RunImpl() { - NOTREACHED() << "Not implemented yet"; - return false; -} - -bool BluetoothConnectFunction::RunImpl() { - NOTREACHED() << "Not implemented yet"; - return false; -} - -bool BluetoothDisconnectFunction::RunImpl() { - NOTREACHED() << "Not implemented yet"; - return false; -} - -bool BluetoothReadFunction::Prepare() { - return true; -} - -void BluetoothReadFunction::Work() { -} - -bool BluetoothReadFunction::Respond() { - NOTREACHED() << "Not implemented yet"; - return false; -} - -bool BluetoothWriteFunction::Prepare() { - return true; -} - -void BluetoothWriteFunction::Work() { -} - -bool BluetoothWriteFunction::Respond() { - NOTREACHED() << "Not implemented yet"; - return false; -} - -bool BluetoothStartDiscoveryFunction::RunImpl() { - NOTREACHED() << "Not implemented yet"; - return false; -} - -bool BluetoothStopDiscoveryFunction::RunImpl() { - NOTREACHED() << "Not implemented yet"; - return false; -} - -bool BluetoothSetOutOfBandPairingDataFunction::RunImpl() { - NOTREACHED() << "Not implemented yet"; - return false; -} - -bool BluetoothGetLocalOutOfBandPairingDataFunction::RunImpl() { - NOTREACHED() << "Not implemented yet"; - return false; -} - -#endif - -BluetoothReadFunction::BluetoothReadFunction() {} -BluetoothReadFunction::~BluetoothReadFunction() {} - -BluetoothWriteFunction::BluetoothWriteFunction() {} -BluetoothWriteFunction::~BluetoothWriteFunction() {} - } // namespace api } // namespace extensions diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.h b/chrome/browser/extensions/api/bluetooth/bluetooth_api.h index 4db078a..3ae23b1 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.h +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.h @@ -7,21 +7,17 @@ #include <string> +#include "base/memory/ref_counted.h" #include "chrome/browser/extensions/api/api_function.h" #include "chrome/browser/extensions/extension_function.h" +#include "device/bluetooth/bluetooth_device.h" -#if defined(OS_CHROMEOS) -#include "base/memory/ref_counted.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h" - -namespace chromeos { +namespace device { class BluetoothSocket; struct BluetoothOutOfBandPairingData; -} // namespace chromeos -#endif +} // namespace device namespace extensions { namespace api { @@ -74,9 +70,7 @@ class BluetoothGetDevicesFunction : public AsyncExtensionFunction { public: DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.getDevices") -#if defined(OS_CHROMEOS) BluetoothGetDevicesFunction(); -#endif protected: virtual ~BluetoothGetDevicesFunction() {} @@ -85,15 +79,13 @@ class BluetoothGetDevicesFunction : public AsyncExtensionFunction { virtual bool RunImpl() OVERRIDE; private: -#if defined(OS_CHROMEOS) - void DispatchDeviceSearchResult(const chromeos::BluetoothDevice& device); - void ProvidesServiceCallback(const chromeos::BluetoothDevice* device, + void DispatchDeviceSearchResult(const device::BluetoothDevice& device); + void ProvidesServiceCallback(const device::BluetoothDevice* device, bool providesService); void FinishDeviceSearch(); int callbacks_pending_; int device_events_sent_; -#endif }; class BluetoothGetServicesFunction : public AsyncExtensionFunction { @@ -106,13 +98,11 @@ class BluetoothGetServicesFunction : public AsyncExtensionFunction { // ExtensionFunction: virtual bool RunImpl() OVERRIDE; -#if defined(OS_CHROMEOS) private: void GetServiceRecordsCallback( base::ListValue* services, - const chromeos::BluetoothDevice::ServiceRecordList& records); + const device::BluetoothDevice::ServiceRecordList& records); void OnErrorCallback(); -#endif }; class BluetoothConnectFunction : public AsyncExtensionFunction { @@ -125,12 +115,10 @@ class BluetoothConnectFunction : public AsyncExtensionFunction { virtual bool RunImpl() OVERRIDE; private: -#if defined(OS_CHROMEOS) void ConnectToServiceCallback( - const chromeos::BluetoothDevice* device, + const device::BluetoothDevice* device, const std::string& service_uuid, - scoped_refptr<chromeos::BluetoothSocket> socket); -#endif + scoped_refptr<device::BluetoothSocket> socket); }; class BluetoothDisconnectFunction : public SyncExtensionFunction { @@ -158,10 +146,8 @@ class BluetoothReadFunction : public AsyncApiFunction { virtual void Work() OVERRIDE; private: -#if defined(OS_CHROMEOS) bool success_; - scoped_refptr<chromeos::BluetoothSocket> socket_; -#endif + scoped_refptr<device::BluetoothSocket> socket_; }; class BluetoothWriteFunction : public AsyncApiFunction { @@ -178,11 +164,9 @@ class BluetoothWriteFunction : public AsyncApiFunction { virtual void Work() OVERRIDE; private: -#if defined(OS_CHROMEOS) bool success_; const base::BinaryValue* data_to_write_; // memory is owned by args_ - scoped_refptr<chromeos::BluetoothSocket> socket_; -#endif + scoped_refptr<device::BluetoothSocket> socket_; }; class BluetoothSetOutOfBandPairingDataFunction @@ -194,10 +178,8 @@ class BluetoothSetOutOfBandPairingDataFunction protected: virtual ~BluetoothSetOutOfBandPairingDataFunction() {} -#if defined(OS_CHROMEOS) void OnSuccessCallback(); void OnErrorCallback(); -#endif // ExtensionFunction: virtual bool RunImpl() OVERRIDE; @@ -212,10 +194,9 @@ class BluetoothGetLocalOutOfBandPairingDataFunction protected: virtual ~BluetoothGetLocalOutOfBandPairingDataFunction() {} -#if defined(OS_CHROMEOS) - void ReadCallback(const chromeos::BluetoothOutOfBandPairingData& data); + void ReadCallback( + const device::BluetoothOutOfBandPairingData& data); void ErrorCallback(); -#endif // ExtensionFunction: virtual bool RunImpl() OVERRIDE; @@ -231,11 +212,9 @@ class BluetoothStartDiscoveryFunction : public AsyncExtensionFunction { // ExtensionFunction: virtual bool RunImpl() OVERRIDE; -#if defined(OS_CHROMEOS) private: void OnSuccessCallback(); void OnErrorCallback(); -#endif }; class BluetoothStopDiscoveryFunction : public AsyncExtensionFunction { @@ -248,11 +227,9 @@ class BluetoothStopDiscoveryFunction : public AsyncExtensionFunction { // ExtensionFunction: virtual bool RunImpl() OVERRIDE; -#if defined(OS_CHROMEOS) private: void OnSuccessCallback(); void OnErrorCallback(); -#endif }; } // namespace api diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc index 5503434..d7e25bc 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc @@ -4,21 +4,18 @@ #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" -#if defined(OS_CHROMEOS) - #include "base/utf_string_conversions.h" #include "base/values.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" #include "chrome/common/extensions/api/experimental_bluetooth.h" +#include "device/bluetooth/bluetooth_device.h" namespace extensions { namespace api { namespace experimental_bluetooth { -// Fill in a Device object from a chromeos::BluetoothDevice. -void BluetoothDeviceToApiDevice( - const chromeos::BluetoothDevice& device, - Device* out) { +// Fill in a Device object from a BluetoothDevice. +void BluetoothDeviceToApiDevice(const device::BluetoothDevice& device, + Device* out) { out->name = UTF16ToUTF8(device.GetName()); out->address = device.address(); out->paired = device.IsPaired(); @@ -27,7 +24,7 @@ void BluetoothDeviceToApiDevice( } // The caller takes ownership of the returned pointer. -base::Value* BluetoothDeviceToValue(const chromeos::BluetoothDevice& device) { +base::Value* BluetoothDeviceToValue(const device::BluetoothDevice& device) { extensions::api::experimental_bluetooth::Device api_device; BluetoothDeviceToApiDevice(device, &api_device); return api_device.ToValue().release(); @@ -36,5 +33,3 @@ base::Value* BluetoothDeviceToValue(const chromeos::BluetoothDevice& device) { } // namespace experimental_bluetooth } // namespace api } // namespace extensions - -#endif diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h b/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h index cb8d089..364a5d2 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h @@ -5,28 +5,25 @@ #ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_API_UTILS_H_ #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_API_UTILS_H_ -#if defined(OS_CHROMEOS) - #include "base/values.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" #include "chrome/common/extensions/api/experimental_bluetooth.h" +#include "device/bluetooth/bluetooth_device.h" namespace extensions { namespace api { namespace experimental_bluetooth { -// Fill in a Device object from a chromeos::BluetoothDevice. +// Fill in a Device object from a BluetoothDevice. void BluetoothDeviceToApiDevice( - const chromeos::BluetoothDevice& device, + const device::BluetoothDevice& device, Device* out); // The caller takes ownership of the returned pointer. -base::Value* BluetoothDeviceToValue(const chromeos::BluetoothDevice& device); +base::Value* BluetoothDeviceToValue( + const device::BluetoothDevice& device); } // namespace experimental_bluetooth } // namespace api } // namespace extensions -#endif - #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_API_UTILS_H_ diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_apitest_chromeos.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_apitest_chromeos.cc index 29922d0..562e6c0 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_apitest_chromeos.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_apitest_chromeos.cc @@ -4,11 +4,8 @@ #include <string.h> -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" -#include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" -#include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.h" -#include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" +#include "chrome/browser/extensions/bluetooth_event_router.h" #include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/extensions/extension_function_test_utils.h" #include "chrome/browser/extensions/extension_service.h" @@ -17,9 +14,17 @@ #include "chrome/common/chrome_switches.h" #include "chrome/test/base/ui_test_utils.h" #include "chromeos/dbus/bluetooth_out_of_band_client.h" -#include "chromeos/dbus/bluetooth_out_of_band_pairing_data.h" +#include "device/bluetooth/bluetooth_adapter.h" +#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" +#include "device/bluetooth/test/mock_bluetooth_adapter.h" +#include "device/bluetooth/test/mock_bluetooth_device.h" #include "testing/gmock/include/gmock/gmock.h" +using device::BluetoothAdapter; +using device::BluetoothDevice; +using device::BluetoothOutOfBandPairingData; +using device::MockBluetoothAdapter; +using device::MockBluetoothDevice; using extensions::Extension; namespace utils = extension_function_test_utils; @@ -41,14 +46,14 @@ class BluetoothApiTest : public ExtensionApiTest { virtual void SetUpOnMainThread() OVERRIDE { // The browser will clean this up when it is torn down - mock_adapter_ = new testing::StrictMock<chromeos::MockBluetoothAdapter>( + mock_adapter_ = new testing::StrictMock<MockBluetoothAdapter>( kAdapterAddress, kName); event_router()->SetAdapterForTest(mock_adapter_); - device1_.reset(new testing::NiceMock<chromeos::MockBluetoothDevice>( + device1_.reset(new testing::NiceMock<MockBluetoothDevice>( mock_adapter_, "d1", "11:12:13:14:15:16", true /* paired */, false /* bonded */, true /* connected */)); - device2_.reset(new testing::NiceMock<chromeos::MockBluetoothDevice>( + device2_.reset(new testing::NiceMock<MockBluetoothDevice>( mock_adapter_, "d2", "21:22:23:24:25:26", false /* paired */, true /* bonded */, false /* connected */)); } @@ -87,11 +92,11 @@ class BluetoothApiTest : public ExtensionApiTest { } protected: - testing::StrictMock<chromeos::MockBluetoothAdapter>* mock_adapter_; - scoped_ptr<testing::NiceMock<chromeos::MockBluetoothDevice> > device1_; - scoped_ptr<testing::NiceMock<chromeos::MockBluetoothDevice> > device2_; + testing::StrictMock<MockBluetoothAdapter>* mock_adapter_; + scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device1_; + scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device2_; - chromeos::ExtensionBluetoothEventRouter* event_router() { + extensions::ExtensionBluetoothEventRouter* event_router() { return browser()->profile()->GetExtensionService()-> bluetooth_event_router(); } @@ -104,12 +109,12 @@ class BluetoothApiTest : public ExtensionApiTest { static const char kOutOfBandPairingDataHash[] = "0123456789ABCDEh"; static const char kOutOfBandPairingDataRandomizer[] = "0123456789ABCDEr"; -static chromeos::BluetoothOutOfBandPairingData GetOutOfBandPairingData() { - chromeos::BluetoothOutOfBandPairingData data; +static BluetoothOutOfBandPairingData GetOutOfBandPairingData() { + BluetoothOutOfBandPairingData data; memcpy(&(data.hash), kOutOfBandPairingDataHash, - chromeos::kBluetoothOutOfBandPairingDataSize); + device::kBluetoothOutOfBandPairingDataSize); memcpy(&(data.randomizer), kOutOfBandPairingDataRandomizer, - chromeos::kBluetoothOutOfBandPairingDataSize); + device::kBluetoothOutOfBandPairingDataSize); return data; } @@ -119,16 +124,15 @@ static bool CallClosure(const base::Closure& callback) { } static void CallOutOfBandPairingDataCallback( - const chromeos::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& - callback, - const chromeos::BluetoothAdapter::ErrorCallback& error_callback) { + const BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& callback, + const BluetoothAdapter::ErrorCallback& error_callback) { callback.Run(GetOutOfBandPairingData()); } template <bool Value> static void CallProvidesServiceCallback( - const std::string& name, - const chromeos::BluetoothDevice::ProvidesServiceCallback& callback) { + const std::string& name, + const BluetoothDevice::ProvidesServiceCallback& callback) { callback.Run(Value); } @@ -365,7 +369,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Events) { // Load and wait for setup ExtensionTestMessageListener listener("ready", true); - const extensions::Extension* extension = + const Extension* extension = LoadExtension(test_data_dir_.AppendASCII("bluetooth")); GURL page_url = extension->GetResourceURL("test_events.html"); ui_test_utils::NavigateToURL(browser(), page_url); @@ -387,7 +391,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) { ResultCatcher catcher; catcher.RestrictToProfile(browser()->profile()); - chromeos::BluetoothAdapter::ConstDeviceList devices; + BluetoothAdapter::ConstDeviceList devices; devices.push_back(device1_.get()); devices.push_back(device2_.get()); @@ -420,12 +424,12 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevicesConcurrently) { ResultCatcher catcher; catcher.RestrictToProfile(browser()->profile()); - chromeos::BluetoothAdapter::ConstDeviceList devices; + BluetoothAdapter::ConstDeviceList devices; devices.push_back(device1_.get()); // Save the callback to delay execution so that we can force the calls to // happen concurrently. This will be called after the listener is satisfied. - chromeos::BluetoothDevice::ProvidesServiceCallback callback; + BluetoothDevice::ProvidesServiceCallback callback; EXPECT_CALL(*device1_, ProvidesServiceWithName(testing::_, testing::_)) .WillOnce(testing::SaveArg<1>(&callback)); diff --git a/chrome/browser/chromeos/extensions/bluetooth_event_router.cc b/chrome/browser/extensions/bluetooth_event_router.cc index 64331bf..90dfefe 100644 --- a/chrome/browser/chromeos/extensions/bluetooth_event_router.cc +++ b/chrome/browser/extensions/bluetooth_event_router.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" +#include "chrome/browser/extensions/bluetooth_event_router.h" #include <map> @@ -10,35 +10,37 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_vector.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_device_chromeos.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h" #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" #include "chrome/browser/extensions/event_names.h" #include "chrome/browser/extensions/event_router.h" #include "chrome/common/extensions/api/experimental_bluetooth.h" +#include "device/bluetooth/bluetooth_adapter.h" +#include "device/bluetooth/bluetooth_adapter_factory.h" +#include "device/bluetooth/bluetooth_device.h" +#include "device/bluetooth/bluetooth_socket.h" namespace experimental_bluetooth = extensions::api::experimental_bluetooth; -namespace chromeos { +namespace extensions { ExtensionBluetoothEventRouter::ExtensionBluetoothEventRouter(Profile* profile) : profile_(profile), - adapter_(chromeos::BluetoothAdapterFactory::DefaultAdapter()), + adapter_(device::BluetoothAdapterFactory::DefaultAdapter()), next_socket_id_(1) { DCHECK(profile_); - DCHECK(adapter_.get()); - adapter_->AddObserver(this); + if (adapter_.get()) + adapter_->AddObserver(this); } ExtensionBluetoothEventRouter::~ExtensionBluetoothEventRouter() { - adapter_->RemoveObserver(this); + if (adapter_.get()) + adapter_->RemoveObserver(this); + socket_map_.clear(); } int ExtensionBluetoothEventRouter::RegisterSocket( - scoped_refptr<BluetoothSocket> socket) { + scoped_refptr<device::BluetoothSocket> socket) { // If there is a socket registered with the same fd, just return it's id for (SocketMap::const_iterator i = socket_map_.begin(); i != socket_map_.end(); ++i) { @@ -59,8 +61,8 @@ bool ExtensionBluetoothEventRouter::ReleaseSocket(int id) { return true; } -scoped_refptr<BluetoothSocket> ExtensionBluetoothEventRouter::GetSocket( - int id) { +scoped_refptr<device::BluetoothSocket> +ExtensionBluetoothEventRouter::GetSocket(int id) { SocketMap::iterator socket_entry = socket_map_.find(id); if (socket_entry == socket_map_.end()) return NULL; @@ -102,7 +104,7 @@ void ExtensionBluetoothEventRouter::DispatchDeviceEvent( } void ExtensionBluetoothEventRouter::AdapterPresentChanged( - chromeos::BluetoothAdapter* adapter, bool present) { + device::BluetoothAdapter* adapter, bool present) { if (adapter != adapter_.get()) { DVLOG(1) << "Ignoring event for adapter " << adapter->address(); return; @@ -114,7 +116,7 @@ void ExtensionBluetoothEventRouter::AdapterPresentChanged( } void ExtensionBluetoothEventRouter::AdapterPoweredChanged( - chromeos::BluetoothAdapter* adapter, bool has_power) { + device::BluetoothAdapter* adapter, bool has_power) { if (adapter != adapter_.get()) { DVLOG(1) << "Ignoring event for adapter " << adapter->address(); return; @@ -126,7 +128,7 @@ void ExtensionBluetoothEventRouter::AdapterPoweredChanged( } void ExtensionBluetoothEventRouter::AdapterDiscoveringChanged( - chromeos::BluetoothAdapter* adapter, bool discovering) { + device::BluetoothAdapter* adapter, bool discovering) { if (adapter != adapter_.get()) { DVLOG(1) << "Ignoring event for adapter " << adapter->address(); return; @@ -144,7 +146,8 @@ void ExtensionBluetoothEventRouter::AdapterDiscoveringChanged( } void ExtensionBluetoothEventRouter::DeviceAdded( - chromeos::BluetoothAdapter* adapter, chromeos::BluetoothDevice* device) { + device::BluetoothAdapter* adapter, + device::BluetoothDevice* device) { if (adapter != adapter_.get()) { DVLOG(1) << "Ignoring event for adapter " << adapter->address(); return; @@ -170,4 +173,4 @@ void ExtensionBluetoothEventRouter::DispatchBooleanValueEvent( event_name, args.Pass(), NULL, GURL()); } -} // namespace chromeos +} // namespace extensions diff --git a/chrome/browser/chromeos/extensions/bluetooth_event_router.h b/chrome/browser/extensions/bluetooth_event_router.h index 6715c4e..36df64b 100644 --- a/chrome/browser/chromeos/extensions/bluetooth_event_router.h +++ b/chrome/browser/extensions/bluetooth_event_router.h @@ -2,42 +2,49 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ -#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ +#ifndef CHROME_BROWSER_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ +#define CHROME_BROWSER_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ #include <map> #include "base/memory/ref_counted.h" #include "base/memory/scoped_vector.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/extensions/api/experimental_bluetooth.h" +#include "device/bluetooth/bluetooth_adapter.h" +#include "device/bluetooth/bluetooth_socket.h" -namespace chromeos { +namespace extensions { class ExtensionBluetoothEventRouter - : public chromeos::BluetoothAdapter::Observer { + : public device::BluetoothAdapter::Observer { public: explicit ExtensionBluetoothEventRouter(Profile* profile); virtual ~ExtensionBluetoothEventRouter(); - const chromeos::BluetoothAdapter& adapter() const { return *adapter_.get(); } + // adapter() will return NULL if the bluetooth adapter is not supported in the + // current platform. + const device::BluetoothAdapter* adapter() const { + return adapter_.get(); + } - // GetMutableAdapter will never return NULL. - chromeos::BluetoothAdapter* GetMutableAdapter() { return adapter_.get(); } + // GetMutableAdapter will return NULL if the bluetooth adapter is not + // supported in the current platform. + device::BluetoothAdapter* GetMutableAdapter() { + return adapter_.get(); + } // Register the BluetoothSocket |socket| for use by the extensions system. // This class will hold onto the socket for its lifetime, or until // ReleaseSocket is called for the socket. Returns an id for the socket. - int RegisterSocket(scoped_refptr<BluetoothSocket> socket); + int RegisterSocket(scoped_refptr<device::BluetoothSocket> socket); // Release the BluetoothSocket corresponding to |id|. Returns true if // the socket was found and released, false otherwise. bool ReleaseSocket(int id); // Get the BluetoothSocket corresponding to |id|. - scoped_refptr<BluetoothSocket> GetSocket(int id); + scoped_refptr<device::BluetoothSocket> GetSocket(int id); // Sets whether this Profile is responsible for the discovering state of the // adapter. @@ -52,18 +59,18 @@ class ExtensionBluetoothEventRouter const char* event_name, const extensions::api::experimental_bluetooth::Device& device); - // Override from chromeos::BluetoothAdapter::Observer - virtual void AdapterPresentChanged(chromeos::BluetoothAdapter* adapter, + // Override from device::BluetoothAdapter::Observer + virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter, bool present) OVERRIDE; - virtual void AdapterPoweredChanged(chromeos::BluetoothAdapter* adapter, + virtual void AdapterPoweredChanged(device::BluetoothAdapter* adapter, bool has_power) OVERRIDE; - virtual void AdapterDiscoveringChanged(chromeos::BluetoothAdapter* adapter, + virtual void AdapterDiscoveringChanged(device::BluetoothAdapter* adapter, bool discovering) OVERRIDE; - virtual void DeviceAdded(chromeos::BluetoothAdapter* adapter, - chromeos::BluetoothDevice* device) OVERRIDE; + virtual void DeviceAdded(device::BluetoothAdapter* adapter, + device::BluetoothDevice* device) OVERRIDE; // Exposed for testing. - void SetAdapterForTest(chromeos::BluetoothAdapter* adapter) { + void SetAdapterForTest(device::BluetoothAdapter* adapter) { adapter_ = adapter; } private: @@ -73,14 +80,14 @@ class ExtensionBluetoothEventRouter bool responsible_for_discovery_; Profile* profile_; - scoped_refptr<chromeos::BluetoothAdapter> adapter_; + scoped_refptr<device::BluetoothAdapter> adapter_; // The next id to use for referring to a BluetoothSocket. We avoid using // the fd of the socket because we don't want to leak that information to // the extension javascript. int next_socket_id_; - typedef std::map<int, scoped_refptr<BluetoothSocket> > SocketMap; + typedef std::map<int, scoped_refptr<device::BluetoothSocket> > SocketMap; SocketMap socket_map_; typedef ScopedVector<extensions::api::experimental_bluetooth::Device> @@ -90,6 +97,6 @@ class ExtensionBluetoothEventRouter DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); }; -} // namespace chromeos +} // namespace extensions -#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ +#endif // CHROME_BROWSER_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ diff --git a/chrome/browser/extensions/event_names.cc b/chrome/browser/extensions/event_names.cc index 9171dd0..83d60a3 100644 --- a/chrome/browser/extensions/event_names.cc +++ b/chrome/browser/extensions/event_names.cc @@ -57,7 +57,6 @@ const char kOnTerminalProcessOutput[] = "terminalPrivate.onProcessOutput"; const char kOnOffscreenTabUpdated[] = "experimental.offscreenTabs.onUpdated"; -#if defined(OS_CHROMEOS) const char kBluetoothOnAvailabilityChanged[] = "experimental.bluetooth.onAvailabilityChanged"; const char kBluetoothOnDeviceDiscovered[] = @@ -70,7 +69,6 @@ const char kBluetoothOnDiscoveringChanged[] = "experimental.bluetooth.onDiscoveringChanged"; const char kBluetoothOnPowerChanged[] = "experimental.bluetooth.onPowerChanged"; -#endif const char kOnPushMessage[] = "experimental.pushMessaging.onMessage"; diff --git a/chrome/browser/extensions/event_names.h b/chrome/browser/extensions/event_names.h index 823c478..8a7e88d 100644 --- a/chrome/browser/extensions/event_names.h +++ b/chrome/browser/extensions/event_names.h @@ -65,7 +65,6 @@ extern const char kOnTerminalProcessOutput[]; // OffscreenTabs. extern const char kOnOffscreenTabUpdated[]; -#if defined(OS_CHROMEOS) // Bluetooth. extern const char kBluetoothOnAvailabilityChanged[]; extern const char kBluetoothOnDeviceDiscovered[]; @@ -73,7 +72,6 @@ extern const char kBluetoothOnDeviceSearchFinished[]; extern const char kBluetoothOnDeviceSearchResult[]; extern const char kBluetoothOnDiscoveringChanged[]; extern const char kBluetoothOnPowerChanged[]; -#endif // Push messaging. extern const char kOnPushMessage[]; diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc index 18a4fd5..7446508 100644 --- a/chrome/browser/extensions/extension_service.cc +++ b/chrome/browser/extensions/extension_service.cc @@ -44,6 +44,7 @@ #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" #include "chrome/browser/extensions/app_notification_manager.h" #include "chrome/browser/extensions/app_sync_data.h" +#include "chrome/browser/extensions/bluetooth_event_router.h" #include "chrome/browser/extensions/browser_event_router.h" #include "chrome/browser/extensions/component_loader.h" #include "chrome/browser/extensions/crx_installer.h" @@ -118,7 +119,6 @@ #include "webkit/database/database_util.h" #if defined(OS_CHROMEOS) #include "chrome/browser/chromeos/cros/cros_library.h" -#include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" #include "chrome/browser/chromeos/extensions/input_method_event_router.h" #include "chrome/browser/chromeos/extensions/media_player_event_router.h" @@ -517,14 +517,13 @@ void ExtensionService::InitEventRouters() { push_messaging_event_router_->Init(); media_galleries_private_event_router_.reset( new extensions::MediaGalleriesPrivateEventRouter(profile_)); + bluetooth_event_router_.reset( + new extensions::ExtensionBluetoothEventRouter(profile_)); #if defined(OS_CHROMEOS) FileBrowserEventRouterFactory::GetForProfile( profile_)->ObserveFileSystemEvents(); - bluetooth_event_router_.reset( - new chromeos::ExtensionBluetoothEventRouter(profile_)); - input_method_event_router_.reset( new chromeos::ExtensionInputMethodEventRouter); diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h index 29693d3..9bc1664 100644 --- a/chrome/browser/extensions/extension_service.h +++ b/chrome/browser/extensions/extension_service.h @@ -56,7 +56,6 @@ class Profile; class Version; namespace chromeos { -class ExtensionBluetoothEventRouter; class ExtensionInputMethodEventRouter; } @@ -69,6 +68,7 @@ class ContentSettingsStore; class CrxInstaller; class Extension; class ExtensionActionStorageManager; +class ExtensionBluetoothEventRouter; class ExtensionCookiesEventRouter; class ExtensionManagedModeEventRouter; class ExtensionSyncData; @@ -519,10 +519,11 @@ class ExtensionService return window_event_router_.get(); } -#if defined(OS_CHROMEOS) - chromeos::ExtensionBluetoothEventRouter* bluetooth_event_router() { + extensions::ExtensionBluetoothEventRouter* bluetooth_event_router() { return bluetooth_event_router_.get(); } + +#if defined(OS_CHROMEOS) chromeos::ExtensionInputMethodEventRouter* input_method_event_router() { return input_method_event_router_.get(); } @@ -861,8 +862,9 @@ class ExtensionService scoped_ptr<extensions::ExtensionManagedModeEventRouter> managed_mode_event_router_; + scoped_ptr<extensions::ExtensionBluetoothEventRouter> bluetooth_event_router_; + #if defined(OS_CHROMEOS) - scoped_ptr<chromeos::ExtensionBluetoothEventRouter> bluetooth_event_router_; scoped_ptr<chromeos::ExtensionInputMethodEventRouter> input_method_event_router_; #endif diff --git a/chrome/browser/ui/webui/DEPS b/chrome/browser/ui/webui/DEPS index 189f541..6461fcc 100644 --- a/chrome/browser/ui/webui/DEPS +++ b/chrome/browser/ui/webui/DEPS @@ -6,6 +6,7 @@ include_rules = [ "+sync/internal_api/public/util/weak_handle.h", # Other libraries. + "+device/bluetooth", "+third_party/angle", # For ANGLE version. "+third_party/zlib/zlib.h", # For compression level constants. ] diff --git a/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc index f69fc34..e40533f 100644 --- a/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc +++ b/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc @@ -11,10 +11,10 @@ #include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" #include "base/values.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" #include "content/public/browser/web_ui.h" +#include "device/bluetooth/bluetooth_adapter.h" +#include "device/bluetooth/bluetooth_adapter_factory.h" +#include "device/bluetooth/bluetooth_device.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "third_party/cros_system_api/dbus/service_constants.h" @@ -124,8 +124,9 @@ void BluetoothOptionsHandler::GetLocalizedValues( // TODO(kevers): Reorder methods to match ordering in the header file. -void BluetoothOptionsHandler::AdapterPresentChanged(BluetoothAdapter* adapter, - bool present) { +void BluetoothOptionsHandler::AdapterPresentChanged( + device::BluetoothAdapter* adapter, + bool present) { DCHECK(adapter == adapter_.get()); if (present) { web_ui()->CallJavascriptFunction( @@ -140,8 +141,9 @@ void BluetoothOptionsHandler::AdapterPresentChanged(BluetoothAdapter* adapter, } } -void BluetoothOptionsHandler::AdapterPoweredChanged(BluetoothAdapter* adapter, - bool powered) { +void BluetoothOptionsHandler::AdapterPoweredChanged( + device::BluetoothAdapter* adapter, + bool powered) { DCHECK(adapter == adapter_.get()); base::FundamentalValue checked(powered); web_ui()->CallJavascriptFunction( @@ -167,7 +169,8 @@ void BluetoothOptionsHandler::RegisterMessages() { } void BluetoothOptionsHandler::InitializeHandler() { - adapter_ = BluetoothAdapterFactory::DefaultAdapter(); + adapter_ = device::BluetoothAdapterFactory::DefaultAdapter(); + DCHECK(adapter_.get()); adapter_->AddObserver(this); } @@ -216,7 +219,7 @@ void BluetoothOptionsHandler::UpdateDeviceCallback( std::string address; args->GetString(kUpdateDeviceAddressIndex, &address); - BluetoothDevice* device = adapter_->GetDevice(address); + device::BluetoothDevice* device = adapter_->GetDevice(address); if (!device) return; @@ -324,15 +327,15 @@ void BluetoothOptionsHandler::StopDiscoveryError() { void BluetoothOptionsHandler::GetPairedDevicesCallback( const ListValue* args) { - BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); + device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); - for (BluetoothAdapter::DeviceList::iterator iter = devices.begin(); + for (device::BluetoothAdapter::DeviceList::iterator iter = devices.begin(); iter != devices.end(); ++iter) SendDeviceNotification(*iter, NULL); } void BluetoothOptionsHandler::SendDeviceNotification( - const BluetoothDevice* device, + const device::BluetoothDevice* device, base::DictionaryValue* params) { base::DictionaryValue js_properties; js_properties.SetString("name", device->GetName()); @@ -348,19 +351,19 @@ void BluetoothOptionsHandler::SendDeviceNotification( js_properties); } -void BluetoothOptionsHandler::RequestPinCode(BluetoothDevice* device) { +void BluetoothOptionsHandler::RequestPinCode(device::BluetoothDevice* device) { DictionaryValue params; params.SetString("pairing", kEnterPinCode); SendDeviceNotification(device, ¶ms); } -void BluetoothOptionsHandler::RequestPasskey(BluetoothDevice* device) { +void BluetoothOptionsHandler::RequestPasskey(device::BluetoothDevice* device) { DictionaryValue params; params.SetString("pairing", kEnterPasskey); SendDeviceNotification(device, ¶ms); } -void BluetoothOptionsHandler::DisplayPinCode(BluetoothDevice* device, +void BluetoothOptionsHandler::DisplayPinCode(device::BluetoothDevice* device, const std::string& pincode) { DictionaryValue params; params.SetString("pairing", kRemotePinCode); @@ -368,7 +371,7 @@ void BluetoothOptionsHandler::DisplayPinCode(BluetoothDevice* device, SendDeviceNotification(device, ¶ms); } -void BluetoothOptionsHandler::DisplayPasskey(BluetoothDevice* device, +void BluetoothOptionsHandler::DisplayPasskey(device::BluetoothDevice* device, uint32 passkey) { DictionaryValue params; params.SetString("pairing", kRemotePasskey); @@ -376,7 +379,7 @@ void BluetoothOptionsHandler::DisplayPasskey(BluetoothDevice* device, SendDeviceNotification(device, ¶ms); } -void BluetoothOptionsHandler::ConfirmPasskey(BluetoothDevice* device, +void BluetoothOptionsHandler::ConfirmPasskey(device::BluetoothDevice* device, uint32 passkey) { DictionaryValue params; params.SetString("pairing", kConfirmPasskey); @@ -400,22 +403,22 @@ void BluetoothOptionsHandler::ReportError( properties); } -void BluetoothOptionsHandler::DeviceAdded(BluetoothAdapter* adapter, - BluetoothDevice* device) { +void BluetoothOptionsHandler::DeviceAdded(device::BluetoothAdapter* adapter, + device::BluetoothDevice* device) { DCHECK(adapter == adapter_.get()); DCHECK(device); SendDeviceNotification(device, NULL); } -void BluetoothOptionsHandler::DeviceChanged(BluetoothAdapter* adapter, - BluetoothDevice* device) { +void BluetoothOptionsHandler::DeviceChanged(device::BluetoothAdapter* adapter, + device::BluetoothDevice* device) { DCHECK(adapter == adapter_.get()); DCHECK(device); SendDeviceNotification(device, NULL); } -void BluetoothOptionsHandler::DeviceRemoved(BluetoothAdapter* adapter, - BluetoothDevice* device) { +void BluetoothOptionsHandler::DeviceRemoved(device::BluetoothAdapter* adapter, + device::BluetoothDevice* device) { DCHECK(adapter == adapter_.get()); DCHECK(device); diff --git a/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h b/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h index b98763a..80d2d75 100644 --- a/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h +++ b/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h @@ -11,9 +11,9 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" #include "chrome/browser/ui/webui/options/options_ui.h" +#include "device/bluetooth/bluetooth_adapter.h" +#include "device/bluetooth/bluetooth_device.h" namespace base { class DictionaryValue; @@ -23,9 +23,10 @@ namespace chromeos { namespace options { // Handler for Bluetooth options on the system options page. -class BluetoothOptionsHandler : public ::options::OptionsPageUIHandler, - public chromeos::BluetoothAdapter::Observer, - public BluetoothDevice::PairingDelegate { +class BluetoothOptionsHandler + : public ::options::OptionsPageUIHandler, + public device::BluetoothAdapter::Observer, + public device::BluetoothDevice::PairingDelegate { public: BluetoothOptionsHandler(); virtual ~BluetoothOptionsHandler(); @@ -40,10 +41,10 @@ class BluetoothOptionsHandler : public ::options::OptionsPageUIHandler, // Sends a notification to the Web UI of the status of a Bluetooth device. // |device| is the Bluetooth device. // |params| is an optional set of parameters. - void SendDeviceNotification(const BluetoothDevice* device, + void SendDeviceNotification(const device::BluetoothDevice* device, base::DictionaryValue* params); - // BluetoothDevice::PairingDelegate override. + // device::BluetoothDevice::PairingDelegate override. // // This method will be called when the Bluetooth daemon requires a // PIN Code for authentication of the device |device|, the UI will display @@ -51,9 +52,9 @@ class BluetoothOptionsHandler : public ::options::OptionsPageUIHandler, // // PIN Codes are generally required for Bluetooth 2.0 and earlier devices // for which there is no automatic pairing or special handling. - virtual void RequestPinCode(BluetoothDevice* device) OVERRIDE; + virtual void RequestPinCode(device::BluetoothDevice* device) OVERRIDE; - // BluetoothDevice::PairingDelegate override. + // device::BluetoothDevice::PairingDelegate override. // // This method will be called when the Bluetooth daemon requires a // Passkey for authentication of the device |device|, the UI will display @@ -63,9 +64,9 @@ class BluetoothOptionsHandler : public ::options::OptionsPageUIHandler, // Passkeys are generally required for Bluetooth 2.1 and later devices // which cannot provide input or display on their own, and don't accept // passkey-less pairing. - virtual void RequestPasskey(BluetoothDevice* device) OVERRIDE; + virtual void RequestPasskey(device::BluetoothDevice* device) OVERRIDE; - // BluetoothDevice::PairingDelegate override. + // device::BluetoothDevice::PairingDelegate override. // // This method will be called when the Bluetooth daemon requires that the // user enter the PIN code |pincode| into the device |device| so that it @@ -75,10 +76,10 @@ class BluetoothOptionsHandler : public ::options::OptionsPageUIHandler, // This is used for Bluetooth 2.0 and earlier keyboard devices, the // |pincode| will always be a six-digit numeric in the range 000000-999999 // for compatibilty with later specifications. - virtual void DisplayPinCode(BluetoothDevice* device, + virtual void DisplayPinCode(device::BluetoothDevice* device, const std::string& pincode) OVERRIDE; - // BluetoothDevice::PairingDelegate override. + // device::BluetoothDevice::PairingDelegate override. // // This method will be called when the Bluetooth daemon requires that the // user enter the Passkey |passkey| into the device |device| so that it @@ -89,9 +90,10 @@ class BluetoothOptionsHandler : public ::options::OptionsPageUIHandler, // but not display, such as keyboards. The Passkey is a numeric in the // range 0-999999 and should be always presented zero-padded to six // digits. - virtual void DisplayPasskey(BluetoothDevice* device, uint32 passkey) OVERRIDE; + virtual void DisplayPasskey( + device::BluetoothDevice* device, uint32 passkey) OVERRIDE; - // BluetoothDevice::PairingDelegate override. + // device::BluetoothDevice::PairingDelegate override. // // This method will be called when the Bluetooth daemon requires that the // user confirm that the Passkey |passkey| is displayed on the screen @@ -102,9 +104,10 @@ class BluetoothOptionsHandler : public ::options::OptionsPageUIHandler, // such as other computers or phones. The Passkey is a numeric in the // range 0-999999 and should be always present zero-padded to six // digits. - virtual void ConfirmPasskey(BluetoothDevice* device, uint32 passkey) OVERRIDE; + virtual void ConfirmPasskey( + device::BluetoothDevice* device, uint32 passkey) OVERRIDE; - // BluetoothDevice::PairingDelegate override. + // device::BluetoothDevice::PairingDelegate override. // // This method will be called when any previous DisplayPinCode(), // DisplayPasskey() or ConfirmPasskey() request should be concluded @@ -117,41 +120,41 @@ class BluetoothOptionsHandler : public ::options::OptionsPageUIHandler, // string if the error is not specific to a single device. void ReportError(const std::string& error, const std::string& address); - // BluetoothAdapter::Observer implementation. - virtual void AdapterPresentChanged(BluetoothAdapter* adapter, + // device::BluetoothAdapter::Observer implementation. + virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter, bool present) OVERRIDE; - virtual void AdapterPoweredChanged(BluetoothAdapter* adapter, + virtual void AdapterPoweredChanged(device::BluetoothAdapter* adapter, bool powered) OVERRIDE; - virtual void DeviceAdded(BluetoothAdapter* adapter, - BluetoothDevice* device) OVERRIDE; - virtual void DeviceChanged(BluetoothAdapter* adapter, - BluetoothDevice* device) OVERRIDE; - virtual void DeviceRemoved(BluetoothAdapter* adapter, - BluetoothDevice* device) OVERRIDE; + virtual void DeviceAdded(device::BluetoothAdapter* adapter, + device::BluetoothDevice* device) OVERRIDE; + virtual void DeviceChanged(device::BluetoothAdapter* adapter, + device::BluetoothDevice* device) OVERRIDE; + virtual void DeviceRemoved(device::BluetoothAdapter* adapter, + device::BluetoothDevice* device) OVERRIDE; private: - // Called by BluetoothAdapter in response to a failure to change the power - // status of the adapter. + // Called by device::BluetoothAdapter in response to a failure to + // change the power status of the adapter. void EnableChangeError(); - // Called by BluetoothAdapter in response to a failure to set the adapter into - // discovery mode. + // Called by device::BluetoothAdapter in response to a failure to + // set the adapter into discovery mode. void FindDevicesError(); - // Called by BluetoothAdapter in response to a failure to remove the adapter - // from discovery mode. + // Called by device::BluetoothAdapter in response to a failure to + // remove the adapter from discovery mode. void StopDiscoveryError(); - // Called by BluetoothDevice in response to a failure to connect to the device - // with bluetooth address |address|. + // Called by device::BluetoothDevice in response to a failure to + // connect to the device with bluetooth address |address|. void ConnectError(const std::string& address); - // Called by BluetoothDevice in response to a failure to disconnect the device - // with bluetooth address |address|. + // Called by device::BluetoothDevice in response to a failure to + // disconnect the device with bluetooth address |address|. void DisconnectError(const std::string& address); - // Called by BluetoothDevice in response to a failure to disconnect and unpair - // the device with bluetooth address |address|. + // Called by device::BluetoothDevice in response to a failure to + // disconnect and unpair the device with bluetooth address |address|. void ForgetError(const std::string& address); // Called when the 'Enable bluetooth' checkbox value is changed. @@ -182,7 +185,7 @@ class BluetoothOptionsHandler : public ::options::OptionsPageUIHandler, void GetPairedDevicesCallback(const base::ListValue* args); // Default bluetooth adapter, used for all operations. - scoped_refptr<BluetoothAdapter> adapter_; + scoped_refptr<device::BluetoothAdapter> adapter_; // Weak pointer factory for generating 'this' pointers that might live longer // than this object does. diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi index 78ea081..731e22e 100644 --- a/chrome/chrome_browser_chromeos.gypi +++ b/chrome/chrome_browser_chromeos.gypi @@ -51,6 +51,7 @@ '../content/content.gyp:content_common', '../crypto/crypto.gyp:crypto', '../dbus/dbus.gyp:dbus', + '../device/device.gyp:device_bluetooth', '../media/media.gyp:media', '../net/net.gyp:net', '../ppapi/ppapi_internal.gyp:ppapi_ipc', # For PpapiMsg_LoadPlugin @@ -123,23 +124,6 @@ 'browser/chromeos/audio/audio_mixer_cras.h', 'browser/chromeos/background/ash_user_wallpaper_delegate.cc', 'browser/chromeos/background/ash_user_wallpaper_delegate.h', - 'browser/chromeos/bluetooth/bluetooth_adapter.cc', - 'browser/chromeos/bluetooth/bluetooth_adapter.h', - 'browser/chromeos/bluetooth/bluetooth_adapter_chromeos.cc', - 'browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h', - 'browser/chromeos/bluetooth/bluetooth_adapter_factory.h', - 'browser/chromeos/bluetooth/bluetooth_adapter_factory.cc', - 'browser/chromeos/bluetooth/bluetooth_device.cc', - 'browser/chromeos/bluetooth/bluetooth_device.h', - 'browser/chromeos/bluetooth/bluetooth_device_chromeos.cc', - 'browser/chromeos/bluetooth/bluetooth_device_chromeos.h', - 'browser/chromeos/bluetooth/bluetooth_service_record.cc', - 'browser/chromeos/bluetooth/bluetooth_service_record.h', - 'browser/chromeos/bluetooth/bluetooth_socket.h', - 'browser/chromeos/bluetooth/bluetooth_socket_chromeos.cc', - 'browser/chromeos/bluetooth/bluetooth_socket_chromeos.h', - 'browser/chromeos/bluetooth/bluetooth_utils.cc', - 'browser/chromeos/bluetooth/bluetooth_utils.h', 'browser/chromeos/boot_times_loader.cc', 'browser/chromeos/boot_times_loader.h', 'browser/chromeos/choose_mobile_network_dialog.cc', @@ -274,8 +258,6 @@ 'browser/chromeos/enrollment_dialog_view.h', 'browser/chromeos/enterprise_extension_observer.cc', 'browser/chromeos/enterprise_extension_observer.h', - 'browser/chromeos/extensions/bluetooth_event_router.cc', - 'browser/chromeos/extensions/bluetooth_event_router.h', 'browser/chromeos/extensions/echo_private_api.cc', 'browser/chromeos/extensions/echo_private_api.h', 'browser/chromeos/extensions/file_browser_event_router.cc', diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi index cc8d5e6..b951223 100644 --- a/chrome/chrome_browser_extensions.gypi +++ b/chrome/chrome_browser_extensions.gypi @@ -31,6 +31,7 @@ '../build/temp_gyp/googleurl.gyp:googleurl', '../content/content.gyp:content_browser', '../crypto/crypto.gyp:crypto', + '../device/device.gyp:device_bluetooth', '../net/net.gyp:net', '../skia/skia.gyp:skia', '../sync/sync.gyp:sync_notifier', @@ -355,6 +356,8 @@ 'browser/extensions/app_sync_bundle.h', 'browser/extensions/app_sync_data.cc', 'browser/extensions/app_sync_data.h', + 'browser/extensions/bluetooth_event_router.cc', + 'browser/extensions/bluetooth_event_router.h', 'browser/extensions/browser_action_test_util.h', 'browser/extensions/browser_action_test_util_gtk.cc', 'browser/extensions/browser_action_test_util_mac.mm', diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index 63db09f..c2bb5ef 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -39,6 +39,7 @@ '../content/content.gyp:content_browser', '../content/content.gyp:content_common', '../crypto/crypto.gyp:crypto', + '../device/device.gyp:device_bluetooth', '../media/media.gyp:media', '../net/net.gyp:net_with_v8', '../ppapi/ppapi_internal.gyp:ppapi_ipc', # For PpapiMsg_LoadPlugin diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index ad41928..3589aa2 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1098,12 +1098,6 @@ 'browser/chrome_browser_application_mac_unittest.mm', 'browser/chrome_browser_main_unittest.cc', 'browser/chrome_page_zoom_unittest.cc', - 'browser/chromeos/bluetooth/bluetooth_service_record_unittest.cc', - 'browser/chromeos/bluetooth/bluetooth_utils_unittest.cc', - 'browser/chromeos/bluetooth/bluetooth_adapter_chromeos_unittest.cc', - 'browser/chromeos/bluetooth/bluetooth_adapter_devices_chromeos_unittest.cc', - 'browser/chromeos/bluetooth/test/mock_bluetooth_adapter.cc', - 'browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h', 'browser/chromeos/contacts/contact_database_unittest.cc', 'browser/chromeos/contacts/contact_manager_stub.cc', 'browser/chromeos/contacts/contact_manager_stub.h', @@ -2746,6 +2740,7 @@ '../base/base.gyp:base', '../base/base.gyp:base_i18n', '../base/base.gyp:test_support_base', + '../device/device.gyp:device_bluetooth_mocks', '../net/net.gyp:net', '../net/net.gyp:net_test_support', '../skia/skia.gyp:skia', @@ -2796,10 +2791,6 @@ 'browser/chrome_main_browsertest.cc', 'browser/chrome_plugin_browsertest.cc', 'browser/chrome_switches_browsertest.cc', - 'browser/chromeos/bluetooth/test/mock_bluetooth_adapter.cc', - 'browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h', - 'browser/chromeos/bluetooth/test/mock_bluetooth_device.cc', - 'browser/chromeos/bluetooth/test/mock_bluetooth_device.h', 'browser/chromeos/contacts/contact_test_util.cc', 'browser/chromeos/contacts/gdata_contacts_service_browsertest.cc', 'browser/chromeos/cros/cros_in_process_browser_test.cc', diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp index 5313d5d..519fe91 100644 --- a/chromeos/chromeos.gyp +++ b/chromeos/chromeos.gyp @@ -45,7 +45,6 @@ 'dbus/bluetooth_node_client.h', 'dbus/bluetooth_out_of_band_client.cc', 'dbus/bluetooth_out_of_band_client.h', - 'dbus/bluetooth_out_of_band_pairing_data.h', 'dbus/bluetooth_property.cc', 'dbus/bluetooth_property.h', 'dbus/cashew_client.cc', diff --git a/chromeos/dbus/DEPS b/chromeos/dbus/DEPS index d6abdda..2b3c5e1 100644 --- a/chromeos/dbus/DEPS +++ b/chromeos/dbus/DEPS @@ -1,3 +1,4 @@ include_rules = [ "+dbus", + "+device/bluetooth/bluetooth_out_of_band_pairing_data.h", ] diff --git a/chromeos/dbus/bluetooth_out_of_band_client.cc b/chromeos/dbus/bluetooth_out_of_band_client.cc index 88b243b..457cf82 100644 --- a/chromeos/dbus/bluetooth_out_of_band_client.cc +++ b/chromeos/dbus/bluetooth_out_of_band_client.cc @@ -10,11 +10,11 @@ #include "base/bind.h" #include "base/logging.h" #include "chromeos/dbus/bluetooth_adapter_client.h" -#include "chromeos/dbus/bluetooth_out_of_band_pairing_data.h" #include "dbus/bus.h" #include "dbus/message.h" #include "dbus/object_path.h" #include "dbus/object_proxy.h" +#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" #include "third_party/cros_system_api/dbus/service_constants.h" namespace chromeos { @@ -49,7 +49,7 @@ class BluetoothOutOfBandClientImpl: public BluetoothOutOfBandClient { virtual void AddRemoteData( const dbus::ObjectPath& object_path, const std::string& address, - const BluetoothOutOfBandPairingData& data, + const device::BluetoothOutOfBandPairingData& data, const SuccessCallback& callback) OVERRIDE { dbus::MethodCall method_call( bluetooth_outofband::kBluetoothOutOfBandInterface, @@ -57,9 +57,10 @@ class BluetoothOutOfBandClientImpl: public BluetoothOutOfBandClient { dbus::MessageWriter writer(&method_call); writer.AppendString(address); - writer.AppendArrayOfBytes(data.hash, kBluetoothOutOfBandPairingDataSize); - writer.AppendArrayOfBytes(data.randomizer, - kBluetoothOutOfBandPairingDataSize); + writer.AppendArrayOfBytes( + data.hash, device::kBluetoothOutOfBandPairingDataSize); + writer.AppendArrayOfBytes( + data.randomizer, device::kBluetoothOutOfBandPairingDataSize); dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path); @@ -115,16 +116,16 @@ class BluetoothOutOfBandClientImpl: public BluetoothOutOfBandClient { void OnReadLocalData(const DataCallback& callback, dbus::Response* response) { bool success = false; - BluetoothOutOfBandPairingData data; + device::BluetoothOutOfBandPairingData data; if (response != NULL) { dbus::MessageReader reader(response); uint8_t* bytes = NULL; - size_t length = kBluetoothOutOfBandPairingDataSize; + size_t length = device::kBluetoothOutOfBandPairingDataSize; if (reader.PopArrayOfBytes(&bytes, &length)) { - if (length == kBluetoothOutOfBandPairingDataSize) { + if (length == device::kBluetoothOutOfBandPairingDataSize) { memcpy(&data.hash, bytes, length); if (reader.PopArrayOfBytes(&bytes, &length)) { - if (length == kBluetoothOutOfBandPairingDataSize) { + if (length == device::kBluetoothOutOfBandPairingDataSize) { memcpy(&data.randomizer, bytes, length); success = true; } @@ -162,7 +163,7 @@ class BluetoothOutOfBandClientStubImpl : public BluetoothOutOfBandClient { const dbus::ObjectPath& object_path, const DataCallback& callback) OVERRIDE { VLOG(1) << "ReadLocalData: " << object_path.value(); - BluetoothOutOfBandPairingData data; + device::BluetoothOutOfBandPairingData data; callback.Run(data, false); } @@ -170,7 +171,7 @@ class BluetoothOutOfBandClientStubImpl : public BluetoothOutOfBandClient { virtual void AddRemoteData( const dbus::ObjectPath& object_path, const std::string& address, - const BluetoothOutOfBandPairingData& data, + const device::BluetoothOutOfBandPairingData& data, const SuccessCallback& callback) OVERRIDE { VLOG(1) << "AddRemoteData: " << object_path.value(); callback.Run(false); diff --git a/chromeos/dbus/bluetooth_out_of_band_client.h b/chromeos/dbus/bluetooth_out_of_band_client.h index 8468528..e39cd61 100644 --- a/chromeos/dbus/bluetooth_out_of_band_client.h +++ b/chromeos/dbus/bluetooth_out_of_band_client.h @@ -16,9 +16,11 @@ namespace dbus { class Bus; } // namespace dbus -namespace chromeos { - +namespace device { struct BluetoothOutOfBandPairingData; +} // namespace device + +namespace chromeos { // BluetoothOutOfBandClient is used to manage Out Of Band Pairing // Data for the local adapter and remote devices. @@ -26,7 +28,8 @@ class CHROMEOS_EXPORT BluetoothOutOfBandClient { public: virtual ~BluetoothOutOfBandClient(); - typedef base::Callback<void(const BluetoothOutOfBandPairingData& data, + typedef base::Callback<void( + const device::BluetoothOutOfBandPairingData& data, bool success)> DataCallback; typedef base::Callback<void(bool success)> SuccessCallback; @@ -41,7 +44,7 @@ class CHROMEOS_EXPORT BluetoothOutOfBandClient { virtual void AddRemoteData( const dbus::ObjectPath& object_path, const std::string& address, - const BluetoothOutOfBandPairingData& data, + const device::BluetoothOutOfBandPairingData& data, const SuccessCallback& callback) = 0; // Clears the Out Of Band Pairing Data for the device at |address|, indicating diff --git a/chromeos/dbus/mock_bluetooth_out_of_band_client.h b/chromeos/dbus/mock_bluetooth_out_of_band_client.h index a1291ee..9b4be7f 100644 --- a/chromeos/dbus/mock_bluetooth_out_of_band_client.h +++ b/chromeos/dbus/mock_bluetooth_out_of_band_client.h @@ -9,7 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "chromeos/dbus/bluetooth_out_of_band_client.h" -#include "chromeos/dbus/bluetooth_out_of_band_pairing_data.h" +#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" #include "testing/gmock/include/gmock/gmock.h" namespace chromeos { @@ -25,7 +25,7 @@ class MockBluetoothOutOfBandClient : public BluetoothOutOfBandClient { MOCK_METHOD4(AddRemoteData, void(const dbus::ObjectPath&, const std::string&, - const BluetoothOutOfBandPairingData&, + const device::BluetoothOutOfBandPairingData&, const SuccessCallback&)); MOCK_METHOD3(RemoveRemoteData, void(const dbus::ObjectPath&, diff --git a/device/DEPS b/device/DEPS new file mode 100644 index 0000000..2beaf5d --- /dev/null +++ b/device/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + "+content/public/common", + "+content/public/test", +] diff --git a/device/bluetooth/DEPS b/device/bluetooth/DEPS new file mode 100644 index 0000000..730c30e --- /dev/null +++ b/device/bluetooth/DEPS @@ -0,0 +1,11 @@ +include_rules = [ + "+chrome/common", + "+chrome/test/base", + "+content/public/test", + "+chromeos/dbus", + "+dbus", + "+grit", + "+ui/base/l10n", + "+third_party/cros_system_api/dbus", + "+third_party/libxml/chromium", +] diff --git a/chrome/browser/chromeos/bluetooth/OWNERS b/device/bluetooth/OWNERS index 47f6cfa..47f6cfa 100644 --- a/chrome/browser/chromeos/bluetooth/OWNERS +++ b/device/bluetooth/OWNERS diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc b/device/bluetooth/bluetooth_adapter.cc index 7108b41..b36cd0b 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc +++ b/device/bluetooth/bluetooth_adapter.cc @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" +#include "device/bluetooth/bluetooth_adapter.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" +#include "device/bluetooth/bluetooth_device.h" -namespace chromeos { +namespace device { BluetoothAdapter::~BluetoothAdapter() { } @@ -31,4 +31,4 @@ BluetoothAdapter::DeviceList BluetoothAdapter::GetDevices() { return devices; } -} // namespace chromeos +} // namespace device diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_adapter.h b/device/bluetooth/bluetooth_adapter.h index 14a94a1..86de361 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_adapter.h +++ b/device/bluetooth/bluetooth_adapter.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_H_ -#define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_H_ +#ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ +#define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ #include <string> #include <vector> @@ -11,7 +11,7 @@ #include "base/callback.h" #include "base/memory/ref_counted.h" -namespace chromeos { +namespace device { class BluetoothDevice; @@ -150,6 +150,6 @@ class BluetoothAdapter : public base::RefCounted<BluetoothAdapter> { std::string name_; }; -} // namespace chromeos +} // namespace device -#endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_H_ +#endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.cc b/device/bluetooth/bluetooth_adapter_chromeos.cc index d71dae4..36699e5 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.cc +++ b/device/bluetooth/bluetooth_adapter_chromeos.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h" +#include "device/bluetooth/bluetooth_adapter_chromeos.h" #include <string> @@ -10,14 +10,18 @@ #include "base/logging.h" #include "base/stl_util.h" #include "base/values.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_device_chromeos.h" #include "chromeos/dbus/bluetooth_adapter_client.h" #include "chromeos/dbus/bluetooth_device_client.h" #include "chromeos/dbus/bluetooth_manager_client.h" #include "chromeos/dbus/bluetooth_out_of_band_client.h" -#include "chromeos/dbus/bluetooth_out_of_band_pairing_data.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "dbus/object_path.h" +#include "device/bluetooth/bluetooth_device_chromeos.h" +#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" + +using device::BluetoothAdapter; +using device::BluetoothDevice; +using device::BluetoothOutOfBandPairingData; namespace chromeos { @@ -127,7 +131,7 @@ const BluetoothDevice* BluetoothAdapterChromeOs::GetDevice( } void BluetoothAdapterChromeOs::ReadLocalOutOfBandPairingData( - const BluetoothOutOfBandPairingDataCallback& callback, + const BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& callback, const ErrorCallback& error_callback) { DBusThreadManager::Get()->GetBluetoothOutOfBandClient()-> ReadLocalData(object_path_, @@ -294,7 +298,7 @@ void BluetoothAdapterChromeOs::DiscoveringChanged(bool discovering) { } void BluetoothAdapterChromeOs::OnReadLocalData( - const BluetoothOutOfBandPairingDataCallback& callback, + const BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& callback, const ErrorCallback& error_callback, const BluetoothOutOfBandPairingData& data, bool success) { diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h b/device/bluetooth/bluetooth_adapter_chromeos.h index 2a0db65..18cb7aa 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h +++ b/device/bluetooth/bluetooth_adapter_chromeos.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ -#define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ +#ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ +#define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ #include <map> #include <string> @@ -12,28 +12,37 @@ #include "base/basictypes.h" #include "base/callback.h" #include "base/observer_list.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" #include "chromeos/dbus/bluetooth_adapter_client.h" #include "chromeos/dbus/bluetooth_device_client.h" #include "chromeos/dbus/bluetooth_manager_client.h" #include "dbus/object_path.h" +#include "device/bluetooth/bluetooth_adapter.h" + +namespace device { + +class BluetoothAdapterFactory; +class MockBluetoothAdapter; +struct BluetoothOutOfBandPairingData; + +} // namespace device namespace chromeos { class BluetoothDeviceChromeOs; -struct BluetoothOutOfBandPairingData; - // The BluetoothAdapterChromeOs class is an implementation of BluetoothAdapter // for Chrome OS platform. -class BluetoothAdapterChromeOs : public BluetoothAdapter, - public BluetoothManagerClient::Observer, - public BluetoothAdapterClient::Observer, - public BluetoothDeviceClient::Observer { +class BluetoothAdapterChromeOs + : public device::BluetoothAdapter, + public BluetoothManagerClient::Observer, + public BluetoothAdapterClient::Observer, + public BluetoothDeviceClient::Observer { public: // BluetoothAdapter override - virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE; - virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE; + virtual void AddObserver( + device::BluetoothAdapter::Observer* observer) OVERRIDE; + virtual void RemoveObserver( + device::BluetoothAdapter::Observer* observer) OVERRIDE; virtual bool IsPresent() const OVERRIDE; virtual bool IsPowered() const OVERRIDE; virtual void SetPowered( @@ -46,17 +55,19 @@ class BluetoothAdapterChromeOs : public BluetoothAdapter, const base::Closure& callback, const ErrorCallback& error_callback) OVERRIDE; virtual ConstDeviceList GetDevices() const OVERRIDE; - virtual BluetoothDevice* GetDevice(const std::string& address) OVERRIDE; - virtual const BluetoothDevice* GetDevice( + virtual device::BluetoothDevice* GetDevice( + const std::string& address) OVERRIDE; + virtual const device::BluetoothDevice* GetDevice( const std::string& address) const OVERRIDE; virtual void ReadLocalOutOfBandPairingData( - const BluetoothOutOfBandPairingDataCallback& callback, + const device::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& + callback, const ErrorCallback& error_callback) OVERRIDE; private: - friend class BluetoothAdapterFactory; friend class BluetoothDeviceChromeOs; - friend class MockBluetoothAdapter; + friend class device::BluetoothAdapterFactory; + friend class device::MockBluetoothAdapter; BluetoothAdapterChromeOs(); virtual ~BluetoothAdapterChromeOs(); @@ -125,10 +136,12 @@ class BluetoothAdapterChromeOs : public BluetoothAdapter, void DiscoveringChanged(bool discovering); // Called by dbus:: in response to the ReadLocalData method call. - void OnReadLocalData(const BluetoothOutOfBandPairingDataCallback& callback, - const ErrorCallback& error_callback, - const BluetoothOutOfBandPairingData& data, - bool success); + void OnReadLocalData( + const device::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& + callback, + const ErrorCallback& error_callback, + const device::BluetoothOutOfBandPairingData& data, + bool success); // BluetoothAdapterClient::Observer override. // @@ -200,7 +213,7 @@ class BluetoothAdapterChromeOs : public BluetoothAdapter, const std::string& address) OVERRIDE; // List of observers interested in event notifications from us. - ObserverList<BluetoothAdapter::Observer> observers_; + ObserverList<device::BluetoothAdapter::Observer> observers_; // Object path of adapter for this instance, this is fixed at creation time // unless |track_default_| is true in which case we update it to always @@ -229,4 +242,4 @@ class BluetoothAdapterChromeOs : public BluetoothAdapter, } // namespace chromeos -#endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ +#endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_adapter_devices_chromeos_unittest.cc b/device/bluetooth/bluetooth_adapter_chromeos_devices_unittest.cc index d1c1805..0ff8d3d 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_adapter_devices_chromeos_unittest.cc +++ b/device/bluetooth/bluetooth_adapter_chromeos_devices_unittest.cc @@ -2,17 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.h" -#include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" #include "chromeos/dbus/mock_bluetooth_adapter_client.h" #include "chromeos/dbus/mock_bluetooth_device_client.h" #include "chromeos/dbus/mock_bluetooth_manager_client.h" #include "chromeos/dbus/mock_dbus_thread_manager.h" #include "dbus/object_path.h" +#include "device/bluetooth/bluetooth_adapter.h" +#include "device/bluetooth/bluetooth_adapter_chromeos.h" +#include "device/bluetooth/bluetooth_adapter_factory.h" +#include "device/bluetooth/test/mock_bluetooth_adapter.h" #include "testing/gtest/include/gtest/gtest.h" +using device::BluetoothAdapter; +using device::BluetoothAdapterFactory; +using device::BluetoothDevice; +using device::MockBluetoothAdapter; using ::testing::_; using ::testing::Mock; using ::testing::Return; @@ -20,7 +24,7 @@ using ::testing::SaveArg; namespace chromeos { -class BluetoothAdapterDevicesChromeOsTest : public testing::Test { +class BluetoothAdapterChromeOsDevicesTest : public testing::Test { public: virtual void SetUp() { MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager; @@ -49,6 +53,7 @@ class BluetoothAdapterDevicesChromeOsTest : public testing::Test { .Times(1); adapter_ = BluetoothAdapterFactory::DefaultAdapter(); + ASSERT_TRUE(adapter_.get() != NULL); // Call the adapter callback; // BluetoothAdapterClient::GetProperties will be called once to obtain @@ -103,12 +108,12 @@ class BluetoothAdapterDevicesChromeOsTest : public testing::Test { MockBluetoothAdapter::Observer adapter_observer_; }; -const dbus::ObjectPath BluetoothAdapterDevicesChromeOsTest::adapter_path_( +const dbus::ObjectPath BluetoothAdapterChromeOsDevicesTest::adapter_path_( "/fake/hci0"); -const std::string BluetoothAdapterDevicesChromeOsTest::adapter_address_ = +const std::string BluetoothAdapterChromeOsDevicesTest::adapter_address_ = "CA:FE:4A:C0:FE:FE"; -TEST_F(BluetoothAdapterDevicesChromeOsTest, DeviceRemovedAfterFound) { +TEST_F(BluetoothAdapterChromeOsDevicesTest, DeviceRemovedAfterFound) { const dbus::ObjectPath device_path("/fake/hci0/dev_ba_c0_11_00_00_01"); const std::string device_address = "BA:C0:11:00:00:01"; diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos_unittest.cc b/device/bluetooth/bluetooth_adapter_chromeos_unittest.cc index d909559..890d241 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos_unittest.cc +++ b/device/bluetooth/bluetooth_adapter_chromeos_unittest.cc @@ -2,16 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.h" -#include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" #include "chromeos/dbus/mock_bluetooth_adapter_client.h" #include "chromeos/dbus/mock_bluetooth_manager_client.h" #include "chromeos/dbus/mock_dbus_thread_manager.h" #include "dbus/object_path.h" +#include "device/bluetooth/bluetooth_adapter.h" +#include "device/bluetooth/bluetooth_adapter_chromeos.h" +#include "device/bluetooth/bluetooth_adapter_factory.h" +#include "device/bluetooth/test/mock_bluetooth_adapter.h" #include "testing/gtest/include/gtest/gtest.h" +using device::BluetoothAdapter; +using device::BluetoothAdapterFactory; +using device::MockBluetoothAdapter; using ::testing::_; using ::testing::InSequence; using ::testing::Return; @@ -67,6 +70,7 @@ TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterNotPresent) { scoped_refptr<BluetoothAdapter> adapter = BluetoothAdapterFactory::DefaultAdapter(); + ASSERT_TRUE(adapter.get() != NULL); // Call the adapter callback; make out it failed. // BluetoothAdapter::Observer::AdapterPresentChanged must not be called. diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.cc b/device/bluetooth/bluetooth_adapter_factory.cc index eb62622..03d633f 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.cc +++ b/device/bluetooth/bluetooth_adapter_factory.cc @@ -1,14 +1,17 @@ // Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// -// TODO(youngki): Guard the ChromeOS specific part with "#ifdef CHROME_OS" block -// once we move this code into common directory. + +#include "device/bluetooth/bluetooth_adapter_factory.h" #include "base/lazy_instance.h" #include "base/memory/ref_counted.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.h" +#include "base/memory/weak_ptr.h" +#include "device/bluetooth/bluetooth_adapter.h" + +#if defined(OS_CHROMEOS) +#include "device/bluetooth/bluetooth_adapter_chromeos.h" +#endif namespace { @@ -16,19 +19,22 @@ namespace { // if nobody is using it so use a WeakPtr and create the object when needed; // since Google C++ Style (and clang's static analyzer) forbids us having // exit-time destructors we use a leaky lazy instance for it. -base::LazyInstance<base::WeakPtr<chromeos::BluetoothAdapter> >::Leaky +base::LazyInstance<base::WeakPtr<device::BluetoothAdapter> >::Leaky default_adapter = LAZY_INSTANCE_INITIALIZER; } // namespace -namespace chromeos { +namespace device { // static scoped_refptr<BluetoothAdapter> BluetoothAdapterFactory::DefaultAdapter() { if (!default_adapter.Get().get()) { - BluetoothAdapterChromeOs* new_adapter = new BluetoothAdapterChromeOs; +#if defined(OS_CHROMEOS) + chromeos::BluetoothAdapterChromeOs* new_adapter = + new chromeos::BluetoothAdapterChromeOs; new_adapter->TrackDefaultAdapter(); default_adapter.Get() = new_adapter->weak_ptr_factory_.GetWeakPtr(); +#endif } return scoped_refptr<BluetoothAdapter>(default_adapter.Get()); @@ -36,9 +42,14 @@ scoped_refptr<BluetoothAdapter> BluetoothAdapterFactory::DefaultAdapter() { // static BluetoothAdapter* BluetoothAdapterFactory::Create(const std::string& address) { - BluetoothAdapterChromeOs* adapter = new BluetoothAdapterChromeOs; - adapter->FindAdapter(address); + BluetoothAdapter* adapter = NULL; +#if defined(OS_CHROMEOS) + chromeos::BluetoothAdapterChromeOs* adapter_chromeos = + new chromeos::BluetoothAdapterChromeOs; + adapter_chromeos->FindAdapter(address); + adapter = adapter_chromeos; +#endif return adapter; } -} // namespace chromeos +} // namespace device diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.h b/device/bluetooth/bluetooth_adapter_factory.h index 0cd4b24..82e1e6f 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.h +++ b/device/bluetooth/bluetooth_adapter_factory.h @@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_ -#define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_ +#ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_ +#define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_ #include <string> #include "base/memory/ref_counted.h" -namespace chromeos { +namespace device { class BluetoothAdapter; @@ -19,14 +19,15 @@ class BluetoothAdapter; class BluetoothAdapterFactory { public: // Returns the shared instance for the default adapter, whichever that may - // be at the time. Use IsPresent() and the AdapterPresentChanged() observer - // method to determine whether an adapter is actually available or not. + // be at the time. Check the returned scoped_refptr does not point to NULL and + // use IsPresent() and the AdapterPresentChanged() observer method to + // determine whether an adapter is actually available or not. static scoped_refptr<BluetoothAdapter> DefaultAdapter(); // Creates an instance for a specific adapter at address |address|. static BluetoothAdapter* Create(const std::string& address); }; -} // namespace chromeos +} // namespace device -#endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_ +#endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_ diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_device.cc b/device/bluetooth/bluetooth_device.cc index f91189a..378c6ce 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_device.cc +++ b/device/bluetooth/bluetooth_device.cc @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" +#include "device/bluetooth/bluetooth_device.h" #include "base/utf_string_conversions.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" -namespace chromeos { +namespace device { BluetoothDevice::BluetoothDevice() : bluetooth_class_(0), @@ -167,4 +167,4 @@ bool BluetoothDevice::IsConnected() const { return connected_; } -} // namespace chromeos +} // namespace device diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_device.h b/device/bluetooth/bluetooth_device.h index ddd4f80..90e420b 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_device.h +++ b/device/bluetooth/bluetooth_device.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_ -#define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_ +#ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ +#define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ #include <string> #include <vector> @@ -12,7 +12,7 @@ #include "base/string16.h" #include "base/memory/ref_counted.h" -namespace chromeos { +namespace device { class BluetoothServiceRecord; class BluetoothSocket; @@ -181,7 +181,7 @@ class BluetoothDevice { const ErrorCallback& error_callback) = 0; // Indicates whether this device provides the given service. |uuid| should - // be in canonical form (see bluetooth_utils::CanonicalUuid). + // be in canonical form (see utils::CanonicalUuid). virtual bool ProvidesServiceWithUUID(const std::string& uuid) const = 0; // The ProvidesServiceCallback is used by ProvidesServiceWithName to indicate @@ -313,6 +313,6 @@ class BluetoothDevice { string16 GetAddressWithLocalizedDeviceTypeName() const; }; -} // namespace chromeos +} // namespace device -#endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_ +#endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_device_chromeos.cc b/device/bluetooth/bluetooth_device_chromeos.cc index aa060d5..2a09cac 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_device_chromeos.cc +++ b/device/bluetooth/bluetooth_device_chromeos.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/bluetooth/bluetooth_device_chromeos.h" +#include "device/bluetooth/bluetooth_device_chromeos.h" #include <map> #include <string> @@ -16,22 +16,27 @@ #include "base/string16.h" #include "base/string_util.h" #include "base/values.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_socket_chromeos.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h" #include "chromeos/dbus/bluetooth_adapter_client.h" #include "chromeos/dbus/bluetooth_agent_service_provider.h" #include "chromeos/dbus/bluetooth_device_client.h" #include "chromeos/dbus/bluetooth_input_client.h" #include "chromeos/dbus/bluetooth_out_of_band_client.h" -#include "chromeos/dbus/bluetooth_out_of_band_pairing_data.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/introspectable_client.h" #include "dbus/bus.h" #include "dbus/object_path.h" +#include "device/bluetooth/bluetooth_adapter_chromeos.h" +#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" +#include "device/bluetooth/bluetooth_service_record.h" +#include "device/bluetooth/bluetooth_socket_chromeos.h" +#include "device/bluetooth/bluetooth_utils.h" #include "third_party/cros_system_api/dbus/service_constants.h" +using device::BluetoothDevice; +using device::BluetoothOutOfBandPairingData; +using device::BluetoothServiceRecord; +using device::BluetoothSocket; + namespace chromeos { BluetoothDeviceChromeOs::BluetoothDeviceChromeOs( @@ -74,7 +79,7 @@ bool BluetoothDeviceChromeOs::ProvidesServiceWithUUID( for (BluetoothDevice::ServiceList::const_iterator iter = services.begin(); iter != services.end(); ++iter) { - if (bluetooth_utils::CanonicalUuid(*iter) == uuid) + if (device::bluetooth_utils::CanonicalUuid(*iter) == uuid) return true; } return false; @@ -259,7 +264,7 @@ void BluetoothDeviceChromeOs::ConnectToService(const std::string& service_uuid, } void BluetoothDeviceChromeOs::SetOutOfBandPairingData( - const chromeos::BluetoothOutOfBandPairingData& data, + const BluetoothOutOfBandPairingData& data, const base::Closure& callback, const ErrorCallback& error_callback) { DBusThreadManager::Get()->GetBluetoothOutOfBandClient()-> diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_device_chromeos.h b/device/bluetooth/bluetooth_device_chromeos.h index a4202c5..4b2d3b5 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_device_chromeos.h +++ b/device/bluetooth/bluetooth_device_chromeos.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H_ -#define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H_ +#ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H_ +#define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H_ #include <string> #include <vector> @@ -13,23 +13,29 @@ #include "base/memory/scoped_vector.h" #include "base/memory/weak_ptr.h" #include "base/string16.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" #include "chromeos/dbus/bluetooth_agent_service_provider.h" #include "chromeos/dbus/bluetooth_device_client.h" #include "dbus/object_path.h" +#include "device/bluetooth/bluetooth_device.h" -namespace chromeos { +namespace device { -class BluetoothAdapterChromeOs; class BluetoothServiceRecord; - +class MockBluetoothDevice; struct BluetoothOutOfBandPairingData; +} // namespace device + +namespace chromeos { + +class BluetoothAdapterChromeOs; + // The BluetoothDeviceChromeOs class is an implementation of BluetoothDevice // for Chrome OS platform. -class BluetoothDeviceChromeOs : public BluetoothDevice, - public BluetoothDeviceClient::Observer, - public BluetoothAgentServiceProvider::Delegate { +class BluetoothDeviceChromeOs + : public device::BluetoothDevice, + public BluetoothDeviceClient::Observer, + public BluetoothAgentServiceProvider::Delegate { public: virtual ~BluetoothDeviceChromeOs(); @@ -47,7 +53,7 @@ class BluetoothDeviceChromeOs : public BluetoothDevice, virtual bool ExpectingPasskey() const OVERRIDE; virtual bool ExpectingConfirmation() const OVERRIDE; virtual void Connect( - BluetoothDevice::PairingDelegate* pairing_delegate, + device::BluetoothDevice::PairingDelegate* pairing_delegate, const base::Closure& callback, const ErrorCallback& error_callback) OVERRIDE; virtual void SetPinCode(const std::string& pincode) OVERRIDE; @@ -63,7 +69,7 @@ class BluetoothDeviceChromeOs : public BluetoothDevice, const std::string& service_uuid, const SocketCallback& callback) OVERRIDE; virtual void SetOutOfBandPairingData( - const chromeos::BluetoothOutOfBandPairingData& data, + const device::BluetoothOutOfBandPairingData& data, const base::Closure& callback, const ErrorCallback& error_callback) OVERRIDE; virtual void ClearOutOfBandPairingData( @@ -72,7 +78,7 @@ class BluetoothDeviceChromeOs : public BluetoothDevice, private: friend class BluetoothAdapterChromeOs; - friend class MockBluetoothDevice; + friend class device::MockBluetoothDevice; explicit BluetoothDeviceChromeOs(BluetoothAdapterChromeOs* adapter); @@ -341,7 +347,7 @@ class BluetoothDeviceChromeOs : public BluetoothDevice, // During pairing this is set to an object that we don't own, but on which // we can make method calls to request, display or confirm PIN Codes and // Passkeys. Generally it is the object that owns this one. - BluetoothDevice::PairingDelegate* pairing_delegate_; + device::BluetoothDevice::PairingDelegate* pairing_delegate_; // During pairing this is set to an instance of a D-Bus agent object // intialized with our own class as its delegate. @@ -366,4 +372,4 @@ class BluetoothDeviceChromeOs : public BluetoothDevice, } // namespace chromeos -#endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H_ +#endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H_ diff --git a/chromeos/dbus/bluetooth_out_of_band_pairing_data.h b/device/bluetooth/bluetooth_out_of_band_pairing_data.h index 0c8e2bc..1b45bb0 100644 --- a/chromeos/dbus/bluetooth_out_of_band_pairing_data.h +++ b/device/bluetooth/bluetooth_out_of_band_pairing_data.h @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROMEOS_DBUS_BLUETOOTH_OUT_OF_BAND_PAIRING_DATA_H_ -#define CHROMEOS_DBUS_BLUETOOTH_OUT_OF_BAND_PAIRING_DATA_H_ +#ifndef DEVICE_BLUETOOTH_BLUETOOTH_OUT_OF_BAND_PAIRING_DATA_H_ +#define DEVICE_BLUETOOTH_BLUETOOTH_OUT_OF_BAND_PAIRING_DATA_H_ #include "base/basictypes.h" -namespace chromeos { +namespace device { const size_t kBluetoothOutOfBandPairingDataSize = 16; @@ -16,12 +16,12 @@ const size_t kBluetoothOutOfBandPairingDataSize = 16; // http://mclean-linsky.net/joel/cv/Simple%20Pairing_WP_V10r00.pdf struct BluetoothOutOfBandPairingData { // Simple Pairing Hash C. - uint8_t hash[kBluetoothOutOfBandPairingDataSize]; + uint8 hash[kBluetoothOutOfBandPairingDataSize]; // Simple Pairing Randomizer R. - uint8_t randomizer[kBluetoothOutOfBandPairingDataSize]; + uint8 randomizer[kBluetoothOutOfBandPairingDataSize]; }; -} // namespace chromeos +} // namespace device -#endif // CHROMEOS_DBUS_BLUETOOTH_OUT_OF_BAND_PAIRING_DATA_H_ +#endif // DEVICE_BLUETOOTH_BLUETOOTH_OUT_OF_BAND_PAIRING_DATA_H_ diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_service_record.cc b/device/bluetooth/bluetooth_service_record.cc index b80ce29..0ea18d7 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_service_record.cc +++ b/device/bluetooth/bluetooth_service_record.cc @@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h" +#include "device/bluetooth/bluetooth_service_record.h" #include <string> #include <vector> #include "base/logging.h" #include "base/string_number_conversions.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h" +#include "device/bluetooth/bluetooth_utils.h" #include "third_party/libxml/chromium/libxml_utils.h" namespace { @@ -44,7 +44,7 @@ bool ExtractTextValue(XmlReader* reader, std::string* value_out) { } // namespace -namespace chromeos { +namespace device { BluetoothServiceRecord::BluetoothServiceRecord( const std::string& address, @@ -116,7 +116,7 @@ void BluetoothServiceRecord::ExtractUuid(XmlReader* reader) { } while (AdvanceToTag(reader, kSequenceNode) && reader->Depth() != start_depth); - uuid_ = bluetooth_utils::CanonicalUuid(uuid_); + uuid_ = device::bluetooth_utils::CanonicalUuid(uuid_); } -} // namespace chromeos +} // namespace device diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_service_record.h b/device/bluetooth/bluetooth_service_record.h index 2e43d72..e04d73a 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_service_record.h +++ b/device/bluetooth/bluetooth_service_record.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_SERVICE_RECORD_H_ -#define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_SERVICE_RECORD_H_ +#ifndef DEVICE_BLUETOOTH_BLUETOOTH_SERVICE_RECORD_H_ +#define DEVICE_BLUETOOTH_BLUETOOTH_SERVICE_RECORD_H_ #include <string> @@ -11,7 +11,7 @@ class XmlReader; -namespace chromeos { +namespace device { // BluetoothServiceRecord represents an SDP service record. // @@ -38,7 +38,7 @@ class BluetoothServiceRecord { // The RFCOMM channel to use, if this service supports RFCOMM communication. // The return value is undefined if SupportsRfcomm() returns false. - uint8_t rfcomm_channel() const { return rfcomm_channel_; } + uint8 rfcomm_channel() const { return rfcomm_channel_; } private: void ExtractChannels(XmlReader* reader); @@ -49,11 +49,11 @@ class BluetoothServiceRecord { std::string uuid_; bool supports_rfcomm_; - uint8_t rfcomm_channel_; + uint8 rfcomm_channel_; DISALLOW_COPY_AND_ASSIGN(BluetoothServiceRecord); }; -} // namespace chromeos +} // namespace device -#endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_SERVICE_RECORD_H_ +#endif // DEVICE_BLUETOOTH_BLUETOOTH_SERVICE_RECORD_H_ diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_service_record_unittest.cc b/device/bluetooth/bluetooth_service_record_unittest.cc index 11bcd98..b59474f5 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_service_record_unittest.cc +++ b/device/bluetooth/bluetooth_service_record_unittest.cc @@ -4,11 +4,12 @@ #include <string> +#include "base/base_paths.h" +#include "base/basictypes.h" #include "base/file_path.h" #include "base/file_util.h" #include "base/path_service.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h" -#include "chrome/common/chrome_paths.h" +#include "device/bluetooth/bluetooth_service_record.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -19,14 +20,16 @@ static const char* kSerialUuid = "00001101-0000-1000-8000-00805f9b34fb"; } // namespace -namespace chromeos { +namespace device { class BluetoothServiceRecordTest : public testing::Test { public: FilePath GetTestDataFilePath(const char* file) { FilePath path; - PathService::Get(chrome::DIR_TEST_DATA, &path); - path = path.AppendASCII("chromeos"); + PathService::Get(base::DIR_SOURCE_ROOT, &path); + path = path.AppendASCII("device"); + path = path.AppendASCII("test"); + path = path.AppendASCII("data"); path = path.AppendASCII("bluetooth"); path = path.AppendASCII(file); return path; @@ -41,7 +44,7 @@ TEST_F(BluetoothServiceRecordTest, RfcommService) { EXPECT_EQ(kAddress, service_record.address()); EXPECT_EQ("Headset Audio Gateway", service_record.name()); EXPECT_TRUE(service_record.SupportsRfcomm()); - EXPECT_EQ((uint8_t)12, service_record.rfcomm_channel()); + EXPECT_EQ((uint8)12, service_record.rfcomm_channel()); EXPECT_EQ(kCustomUuid, service_record.uuid()); } @@ -72,4 +75,4 @@ TEST_F(BluetoothServiceRecordTest, CleanUuid) { EXPECT_EQ("", invalid_service_record.uuid()); } -} // namespace chromeos +} // namespace device diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_socket.h b/device/bluetooth/bluetooth_socket.h index 326c0f7..b444110 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_socket.h +++ b/device/bluetooth/bluetooth_socket.h @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_SOCKET_H_ -#define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_SOCKET_H_ +#ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_ +#define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_ #include "base/memory/ref_counted.h" -namespace chromeos { +namespace device { // BluetoothSocket represents a socket to a specific service on a // BluetoothDevice. BluetoothSocket objects are ref counted and may outlive @@ -25,6 +25,6 @@ class BluetoothSocket : public base::RefCounted<BluetoothSocket> { virtual ~BluetoothSocket() {} }; -} // namespace chromeos +} // namespace device -#endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_SOCKET_H_ +#endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_ diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_socket_chromeos.cc b/device/bluetooth/bluetooth_socket_chromeos.cc index f86f9c5..7e75a9d 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_socket_chromeos.cc +++ b/device/bluetooth/bluetooth_socket_chromeos.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/bluetooth/bluetooth_socket_chromeos.h" +#include "device/bluetooth/bluetooth_socket_chromeos.h" #include <vector> @@ -15,8 +15,11 @@ #include <unistd.h> #include "base/logging.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h" +#include "device/bluetooth/bluetooth_service_record.h" +#include "device/bluetooth/bluetooth_utils.h" + +using device::BluetoothServiceRecord; +using device::BluetoothSocket; namespace chromeos { @@ -40,7 +43,7 @@ scoped_refptr<BluetoothSocket> BluetoothSocketChromeOs::CreateBluetoothSocket( struct sockaddr_rc socket_address = { 0 }; socket_address.rc_family = AF_BLUETOOTH; socket_address.rc_channel = service_record.rfcomm_channel(); - bluetooth_utils::str2ba(service_record.address(), + device::bluetooth_utils::str2ba(service_record.address(), &socket_address.rc_bdaddr); int status = connect(socket_fd, (struct sockaddr *)&socket_address, diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_socket_chromeos.h b/device/bluetooth/bluetooth_socket_chromeos.h index 7d0328c..0685830 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_socket_chromeos.h +++ b/device/bluetooth/bluetooth_socket_chromeos.h @@ -2,23 +2,28 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ -#define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ +#ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ +#define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ #include <string> #include "base/memory/ref_counted.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h" +#include "device/bluetooth/bluetooth_socket.h" + +namespace device { + +class BluetoothServiceRecord; + +} // namespace device namespace chromeos { // This class is an implementation of BluetoothSocket class for Chrome OS // platform. -class BluetoothSocketChromeOs : public BluetoothSocket { +class BluetoothSocketChromeOs : public device::BluetoothSocket { public: - static scoped_refptr<BluetoothSocket> CreateBluetoothSocket( - const BluetoothServiceRecord& service_record); + static scoped_refptr<device::BluetoothSocket> CreateBluetoothSocket( + const device::BluetoothServiceRecord& service_record); // BluetoothSocket override virtual int fd() const OVERRIDE; @@ -37,4 +42,4 @@ class BluetoothSocketChromeOs : public BluetoothSocket { } // namespace chromeos -#endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ +#endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_utils.cc b/device/bluetooth/bluetooth_utils.cc index 02643c6..6d06409 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_utils.cc +++ b/device/bluetooth/bluetooth_utils.cc @@ -2,11 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h" +#include "device/bluetooth/bluetooth_utils.h" #include <vector> +#if defined(OS_CHROMEOS) #include <bluetooth/bluetooth.h> +#endif #include "base/logging.h" #include "base/string_number_conversions.h" @@ -18,9 +20,10 @@ static const char* kCommonUuidPrefix = "0000"; static const int kUuidSize = 36; } // namespace -namespace chromeos { +namespace device { namespace bluetooth_utils { +#if defined(OS_CHROMEOS) bool str2ba(const std::string& in_address, bdaddr_t* out_address) { if (!out_address) return false; @@ -47,6 +50,7 @@ bool str2ba(const std::string& in_address, bdaddr_t* out_address) { return false; } +#endif std::string CanonicalUuid(std::string uuid) { if (uuid.empty()) @@ -85,4 +89,4 @@ std::string CanonicalUuid(std::string uuid) { } } // namespace bluetooth_utils -} // namespace chromeos +} // namespace device diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_utils.h b/device/bluetooth/bluetooth_utils.h index 78f8ff5..f796d5d 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_utils.h +++ b/device/bluetooth/bluetooth_utils.h @@ -2,22 +2,26 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_UTILS_H_ -#define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_UTILS_H_ +#ifndef DEVICE_BLUETOOTH_BLUETOOTH_UTILS_H_ +#define DEVICE_BLUETOOTH_BLUETOOTH_UTILS_H_ #include <string> +#if defined(OS_CHROMEOS) #include <bluetooth/bluetooth.h> +#endif -namespace chromeos { +namespace device { namespace bluetooth_utils { +#if defined(OS_CHROMEOS) // Converts a bluetooth address in the format "B0:D0:9C:0F:3A:2D" into a // bdaddr_t struct. Returns true on success, false on failure. The contents // of |out_address| are zeroed on failure. // Note that the order is reversed upon conversion. For example, // "B0:D0:9C:0F:3A:2D" -> {"0x2d", "0x3a", "0x0f", "0x9c", "0xd0", "0xb0"} bool str2ba(const std::string& in_address, bdaddr_t* out_address); +#endif // Takes a 4, 8 or 36 character UUID, validates it and returns it in 36 // character format with all hex digits lower case. If |uuid| is invalid, the @@ -32,7 +36,7 @@ bool str2ba(const std::string& in_address, bdaddr_t* out_address); std::string CanonicalUuid(std::string uuid); } // namespace bluetooth_utils -} // namespace chromeos +} // namespace device -#endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_UTILS_H_ +#endif // DEVICE_BLUETOOTH_BLUETOOTH_UTILS_H_ diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_utils_unittest.cc b/device/bluetooth/bluetooth_utils_unittest.cc index 6dad3a0..0e05f8e 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_utils_unittest.cc +++ b/device/bluetooth/bluetooth_utils_unittest.cc @@ -2,13 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if defined(OS_CHROMEOS) #include <bluetooth/bluetooth.h> +#endif -#include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h" +#include "device/bluetooth/bluetooth_utils.h" #include "testing/gtest/include/gtest/gtest.h" -namespace chromeos { +namespace device { +#if defined(OS_CHROMEOS) TEST(BluetoothUtilsTest, str2ba) { bdaddr_t bluetooth_address; @@ -22,10 +25,11 @@ TEST(BluetoothUtilsTest, str2ba) { EXPECT_FALSE(bluetooth_utils::str2ba("obviously wrong", &bluetooth_address)); EXPECT_FALSE(bluetooth_utils::str2ba("00:00", &bluetooth_address)); - EXPECT_FALSE(bluetooth_utils::str2ba("00:00:00:00:00:00:00", - &bluetooth_address)); + EXPECT_FALSE( + bluetooth_utils::str2ba("00:00:00:00:00:00:00", &bluetooth_address)); EXPECT_FALSE(bluetooth_utils::str2ba("01:02:03:0A:10:A0", NULL)); } +#endif TEST(BluetoothUtilsTest, CanonicalUuid) { // Does nothing for an already canonical UUID @@ -69,4 +73,4 @@ TEST(BluetoothUtilsTest, CanonicalUuid) { bluetooth_utils::CanonicalUuid("0x00001101-0000-1000-8000-00805f9b34fb")); } -} // namespace chromeos +} // namespace device diff --git a/chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.cc b/device/bluetooth/test/mock_bluetooth_adapter.cc index b3e6375..cae8829 100644 --- a/chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.cc +++ b/device/bluetooth/test/mock_bluetooth_adapter.cc @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" +#include "device/bluetooth/test/mock_bluetooth_adapter.h" -namespace chromeos { +namespace device { MockBluetoothAdapter::Observer::Observer() {} MockBluetoothAdapter::Observer::~Observer() {} @@ -17,4 +17,4 @@ MockBluetoothAdapter::MockBluetoothAdapter(const std::string& address, MockBluetoothAdapter::~MockBluetoothAdapter() {} -} // namespace chromeos +} // namespace device diff --git a/chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h b/device/bluetooth/test/mock_bluetooth_adapter.h index ba94c20..33f7afb 100644 --- a/chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h +++ b/device/bluetooth/test/mock_bluetooth_adapter.h @@ -2,18 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_TEST_MOCK_BLUETOOTH_ADAPTER_H_ -#define CHROME_BROWSER_CHROMEOS_BLUETOOTH_TEST_MOCK_BLUETOOTH_ADAPTER_H_ +#ifndef DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_ADAPTER_H_ +#define DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_ADAPTER_H_ #include <string> #include "base/callback.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" -#include "chromeos/dbus/bluetooth_out_of_band_client.h" +#include "device/bluetooth/bluetooth_adapter.h" +#include "device/bluetooth/bluetooth_device.h" #include "testing/gmock/include/gmock/gmock.h" -namespace chromeos { +namespace device { class MockBluetoothAdapter : public BluetoothAdapter { public: @@ -57,6 +56,6 @@ class MockBluetoothAdapter : public BluetoothAdapter { virtual ~MockBluetoothAdapter(); }; -} // namespace chromeos +} // namespace device -#endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_TEST_MOCK_BLUETOOTH_ADAPTER_H_ +#endif // DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_ADAPTER_H_ diff --git a/chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.cc b/device/bluetooth/test/mock_bluetooth_device.cc index 1387fd2..f2f358d 100644 --- a/chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.cc +++ b/device/bluetooth/test/mock_bluetooth_device.cc @@ -3,10 +3,10 @@ // found in the LICENSE file. #include "base/utf_string_conversions.h" -#include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" -#include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.h" +#include "device/bluetooth/test/mock_bluetooth_adapter.h" +#include "device/bluetooth/test/mock_bluetooth_device.h" -namespace chromeos { +namespace device { MockBluetoothDevice::MockBluetoothDevice(MockBluetoothAdapter* adapter, const std::string& name, @@ -38,4 +38,4 @@ MockBluetoothDevice::MockBluetoothDevice(MockBluetoothAdapter* adapter, MockBluetoothDevice::~MockBluetoothDevice() {} -} // namespace chromeos +} // namespace device diff --git a/chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.h b/device/bluetooth/test/mock_bluetooth_device.h index 650928c..e917a30 100644 --- a/chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.h +++ b/device/bluetooth/test/mock_bluetooth_device.h @@ -2,17 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_TEST_MOCK_BLUETOOTH_DEVICE_H_ -#define CHROME_BROWSER_CHROMEOS_BLUETOOTH_TEST_MOCK_BLUETOOTH_DEVICE_H_ +#ifndef DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_DEVICE_H_ +#define DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_DEVICE_H_ #include <string> #include "base/string16.h" -#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" -#include "chromeos/dbus/bluetooth_out_of_band_pairing_data.h" +#include "device/bluetooth/bluetooth_device.h" +#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" #include "testing/gmock/include/gmock/gmock.h" -namespace chromeos { +namespace device { + +class MockBluetoothAdapter; class MockBluetoothDevice : public BluetoothDevice { public: @@ -59,7 +61,7 @@ class MockBluetoothDevice : public BluetoothDevice { const BluetoothDevice::SocketCallback&)); MOCK_METHOD3(SetOutOfBandPairingData, - void(const chromeos::BluetoothOutOfBandPairingData& data, + void(const BluetoothOutOfBandPairingData& data, const base::Closure& callback, const BluetoothDevice::ErrorCallback& error_callback)); MOCK_METHOD2(ClearOutOfBandPairingData, @@ -72,6 +74,6 @@ class MockBluetoothDevice : public BluetoothDevice { BluetoothDevice::ServiceList service_list_; }; -} // namespace chromeos +} // namespace device -#endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_TEST_MOCK_BLUETOOTH_DEVICE_H_ +#endif // DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_DEVICE_H_ diff --git a/device/device.gyp b/device/device.gyp new file mode 100644 index 0000000..4b4c1ad --- /dev/null +++ b/device/device.gyp @@ -0,0 +1,111 @@ +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +{ + 'variables': { + }, + 'targets': [ + { + 'target_name': 'device_bluetooth', + 'type': '<(library)', + 'dependencies': [ + '../chrome/chrome_resources.gyp:chrome_strings', + '../third_party/libxml/libxml.gyp:libxml', + '../ui/ui.gyp:ui' + ], + 'sources': [ + 'bluetooth/bluetooth_adapter.cc', + 'bluetooth/bluetooth_adapter.h', + 'bluetooth/bluetooth_adapter_chromeos.cc', + 'bluetooth/bluetooth_adapter_chromeos.h', + 'bluetooth/bluetooth_adapter_factory.cc', + 'bluetooth/bluetooth_adapter_factory.h', + 'bluetooth/bluetooth_device.cc', + 'bluetooth/bluetooth_device.h', + 'bluetooth/bluetooth_device_chromeos.cc', + 'bluetooth/bluetooth_device_chromeos.h', + 'bluetooth/bluetooth_out_of_band_pairing_data.h', + 'bluetooth/bluetooth_service_record.cc', + 'bluetooth/bluetooth_service_record.h', + 'bluetooth/bluetooth_socket.h', + 'bluetooth/bluetooth_socket_chromeos.cc', + 'bluetooth/bluetooth_socket_chromeos.h', + 'bluetooth/bluetooth_utils.cc', + 'bluetooth/bluetooth_utils.h', + ], + 'conditions': [ + ['chromeos==0', { + 'sources!': [ + # ChromeOs-only; exclude on other platforms. + 'bluetooth/bluetooth_adapter_chromeos.cc', + 'bluetooth/bluetooth_adapter_chromeos.h', + 'bluetooth/bluetooth_device_chromeos.cc', + 'bluetooth/bluetooth_device_chromeos.h', + 'bluetooth/bluetooth_socket_chromeos.cc', + 'bluetooth/bluetooth_socket_chromeos.h', + ] + }, { # chromeos==1 + 'dependencies': [ + '../build/linux/system.gyp:dbus-glib', + '../chromeos/chromeos.gyp:chromeos', + '../dbus/dbus.gyp:dbus', + ] + }], + ], + }, + { + 'target_name': 'device_bluetooth_mocks', + 'type': '<(library)', + 'dependencies': [ + 'device_bluetooth', + '../testing/gmock.gyp:gmock', + ], + 'sources': [ + 'bluetooth/test/mock_bluetooth_adapter.cc', + 'bluetooth/test/mock_bluetooth_adapter.h', + 'bluetooth/test/mock_bluetooth_device.cc', + 'bluetooth/test/mock_bluetooth_device.h', + ], + 'include_dirs': [ + '..', + ], + }, + { + 'target_name': 'device_unittests', + 'type': '<(gtest_target_type)', + 'dependencies': [ + 'device_bluetooth', + 'device_bluetooth_mocks', + '../base/base.gyp:test_support_base', + '../content/content.gyp:test_support_content', + '../testing/gmock.gyp:gmock', + '../testing/gtest.gyp:gtest', + ], + 'sources': [ + 'bluetooth/bluetooth_adapter_chromeos_unittest.cc', + 'bluetooth/bluetooth_adapter_chromeos_devices_unittest.cc', + 'bluetooth/bluetooth_service_record_unittest.cc', + 'bluetooth/bluetooth_utils_unittest.cc', + 'test/device_test_suite.cc', + 'test/device_test_suite.h', + 'test/run_all_unittests.cc', + ], + 'conditions': [ + ['chromeos==0', { + 'sources!': [ + # ChromeOs-only; exclude on other platforms. + 'bluetooth/bluetooth_adapter_chromeos_unittest.cc', + 'bluetooth/bluetooth_adapter_chromeos_devices_unittest.cc', + ] + }, { # chromeos==1 + 'dependencies': [ + '../build/linux/system.gyp:dbus-glib', + '../chromeos/chromeos.gyp:chromeos_test_support', + '../dbus/dbus.gyp:dbus', + ] + }], + ], + }, + ], +} diff --git a/chrome/test/data/chromeos/bluetooth/invalid_uuid.xml b/device/test/data/bluetooth/invalid_uuid.xml index 2b33304..2b33304 100644 --- a/chrome/test/data/chromeos/bluetooth/invalid_uuid.xml +++ b/device/test/data/bluetooth/invalid_uuid.xml diff --git a/chrome/test/data/chromeos/bluetooth/medium_uuid.xml b/device/test/data/bluetooth/medium_uuid.xml index 432d7fe..432d7fe 100644 --- a/chrome/test/data/chromeos/bluetooth/medium_uuid.xml +++ b/device/test/data/bluetooth/medium_uuid.xml diff --git a/chrome/test/data/chromeos/bluetooth/rfcomm.xml b/device/test/data/bluetooth/rfcomm.xml index ec3bdec..ec3bdec 100644 --- a/chrome/test/data/chromeos/bluetooth/rfcomm.xml +++ b/device/test/data/bluetooth/rfcomm.xml diff --git a/chrome/test/data/chromeos/bluetooth/short_uuid.xml b/device/test/data/bluetooth/short_uuid.xml index 9ad3c9f..9ad3c9f 100644 --- a/chrome/test/data/chromeos/bluetooth/short_uuid.xml +++ b/device/test/data/bluetooth/short_uuid.xml diff --git a/chrome/test/data/chromeos/bluetooth/uppercase_uuid.xml b/device/test/data/bluetooth/uppercase_uuid.xml index 4e0574f..4e0574f 100644 --- a/chrome/test/data/chromeos/bluetooth/uppercase_uuid.xml +++ b/device/test/data/bluetooth/uppercase_uuid.xml diff --git a/device/test/device_test_suite.cc b/device/test/device_test_suite.cc new file mode 100644 index 0000000..6556076 --- /dev/null +++ b/device/test/device_test_suite.cc @@ -0,0 +1,18 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "device/test/device_test_suite.h" + +#include "content/public/common/content_client.h" + +DeviceTestSuite::DeviceTestSuite(int argc, char** argv) + : content::ContentTestSuiteBase(argc, argv) { +} + +DeviceTestSuite::~DeviceTestSuite() { +} + +content::ContentClient* DeviceTestSuite::CreateClientForInitialization() { + return new content::ContentClient(); +} diff --git a/device/test/device_test_suite.h b/device/test/device_test_suite.h new file mode 100644 index 0000000..15059ab --- /dev/null +++ b/device/test/device_test_suite.h @@ -0,0 +1,19 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef DEVICE_TEST_DEVICE_TEST_SUITE_H_ +#define DEVICE_TEST_DEVICE_TEST_SUITE_H_ + +#include "content/public/test/content_test_suite_base.h" + +class DeviceTestSuite : public content::ContentTestSuiteBase { + public: + DeviceTestSuite(int argc, char** argv); + virtual ~DeviceTestSuite(); + + protected: + virtual content::ContentClient* CreateClientForInitialization() OVERRIDE; +}; + +#endif // DEVICE_TEST_DEVICE_TEST_SUITE_H_ diff --git a/device/test/run_all_unittests.cc b/device/test/run_all_unittests.cc new file mode 100644 index 0000000..36e6e51 --- /dev/null +++ b/device/test/run_all_unittests.cc @@ -0,0 +1,10 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/public/test/unittest_test_suite.h" +#include "device/test/device_test_suite.h" + +int main(int argc, char **argv) { + return content::UnitTestTestSuite(new DeviceTestSuite(argc, argv)).Run(); +} |