summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorortuno <ortuno@chromium.org>2016-01-15 18:08:31 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-16 02:09:32 +0000
commitd7279d06259a35be809d5a07301b1242532c31c2 (patch)
treeba4273dc58a4eef122ab37076a24bb9dbb18488f
parent3d8548c073acb19f6172d3c77c2d57ef11fbc010 (diff)
downloadchromium_src-d7279d06259a35be809d5a07301b1242532c31c2.zip
chromium_src-d7279d06259a35be809d5a07301b1242532c31c2.tar.gz
chromium_src-d7279d06259a35be809d5a07301b1242532c31c2.tar.bz2
bluetooth: Expose Bluetooth on Linux to everyone
Also fix Web Bluetooth LayoutTests and some random fixes and comments. To fix Web Bluetooth LayoutTests we have to initialize the DBusThread Manager for Content Shell. Since some of Content Shell's clients don't use DBus we add a wrapper around the Linux DBus managers, which has a stub implementation on targets that don't use DBus. BUG=552488, 563741 Review URL: https://codereview.chromium.org/1487183002 Cr-Commit-Position: refs/heads/master@{#369922}
-rw-r--r--content/shell/browser/shell_browser_main_parts.cc28
-rw-r--r--content/shell/browser/shell_browser_main_parts.h1
-rw-r--r--content/shell/browser/shell_views.cc13
-rw-r--r--device/bluetooth/BUILD.gn17
-rw-r--r--device/bluetooth/bluetooth.gyp22
-rw-r--r--device/bluetooth/bluetooth_adapter_factory.cc10
-rw-r--r--device/bluetooth/bluetooth_advertisement_bluez_unittest.cc3
-rw-r--r--device/bluetooth/bluetooth_audio_sink_bluez_unittest.cc3
-rw-r--r--device/bluetooth/dbus/dbus_bluez_manager_wrapper_linux.cc26
-rw-r--r--device/bluetooth/dbus/dbus_bluez_manager_wrapper_linux.h27
-rw-r--r--device/bluetooth/dbus/dbus_bluez_manager_wrapper_stub_linux.cc17
-rw-r--r--extensions/browser/api/bluetooth/bluetooth_event_router.cc3
12 files changed, 138 insertions, 32 deletions
diff --git a/content/shell/browser/shell_browser_main_parts.cc b/content/shell/browser/shell_browser_main_parts.cc
index 48a87e3..520c918 100644
--- a/content/shell/browser/shell_browser_main_parts.cc
+++ b/content/shell/browser/shell_browser_main_parts.cc
@@ -25,6 +25,7 @@
#include "content/shell/browser/shell_devtools_manager_delegate.h"
#include "content/shell/browser/shell_net_log.h"
#include "content/shell/common/shell_switches.h"
+#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "net/base/filename_util.h"
#include "net/base/net_module.h"
#include "net/grit/net_resources.h"
@@ -43,6 +44,12 @@
#if !defined(OS_CHROMEOS) && defined(USE_AURA) && defined(OS_LINUX)
#include "ui/base/ime/input_method_initializer.h"
#endif
+#if defined(OS_CHROMEOS)
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "device/bluetooth/dbus/bluez_dbus_manager.h"
+#elif defined(OS_LINUX)
+#include "device/bluetooth/dbus/dbus_bluez_manager_wrapper_linux.h"
+#endif
namespace content {
@@ -105,6 +112,16 @@ void ShellBrowserMainParts::PostMainMessageLoopStart() {
#if defined(OS_ANDROID)
base::MessageLoopForUI::current()->Start();
#endif
+
+#if defined(OS_CHROMEOS)
+ chromeos::DBusThreadManager::Initialize();
+ bluez::BluezDBusManager::Initialize(
+ chromeos::DBusThreadManager::Get()->GetSystemBus(),
+ chromeos::DBusThreadManager::Get()->IsUsingStub(
+ chromeos::DBusClientBundle::BLUETOOTH));
+#elif defined(OS_LINUX)
+ bluez::DBusBluezManagerWrapperLinux::Initialize();
+#endif
}
void ShellBrowserMainParts::PreEarlyInitialization() {
@@ -168,4 +185,15 @@ void ShellBrowserMainParts::PostMainMessageLoopRun() {
off_the_record_browser_context_.reset();
}
+void ShellBrowserMainParts::PostDestroyThreads() {
+#if defined(OS_CHROMEOS)
+ device::BluetoothAdapterFactory::Shutdown();
+ bluez::BluezDBusManager::Shutdown();
+ chromeos::DBusThreadManager::Shutdown();
+#elif defined(OS_LINUX)
+ device::BluetoothAdapterFactory::Shutdown();
+ bluez::DBusBluezManagerWrapperLinux::Shutdown();
+#endif
+}
+
} // namespace
diff --git a/content/shell/browser/shell_browser_main_parts.h b/content/shell/browser/shell_browser_main_parts.h
index c64d030..e506bff 100644
--- a/content/shell/browser/shell_browser_main_parts.h
+++ b/content/shell/browser/shell_browser_main_parts.h
@@ -44,6 +44,7 @@ class ShellBrowserMainParts : public BrowserMainParts {
void PreMainMessageLoopRun() override;
bool MainMessageLoopRun(int* result_code) override;
void PostMainMessageLoopRun() override;
+ void PostDestroyThreads() override;
devtools_http_handler::DevToolsHttpHandler* devtools_http_handler() {
return devtools_http_handler_.get();
diff --git a/content/shell/browser/shell_views.cc b/content/shell/browser/shell_views.cc
index 72aebc7..2e1e4ff 100644
--- a/content/shell/browser/shell_views.cc
+++ b/content/shell/browser/shell_views.cc
@@ -15,7 +15,6 @@
#include "content/public/browser/web_contents.h"
#include "content/public/common/context_menu_params.h"
#include "content/shell/browser/shell_platform_data_aura.h"
-#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
@@ -41,8 +40,6 @@
#include "ui/views/widget/widget_delegate.h"
#if defined(OS_CHROMEOS)
-#include "chromeos/dbus/dbus_thread_manager.h"
-#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "ui/aura/test/test_screen.h"
#include "ui/wm/test/wm_test_helper.h"
#else // !defined(OS_CHROMEOS)
@@ -416,11 +413,6 @@ void Shell::PlatformInitialize(const gfx::Size& default_window_size) {
_setmode(_fileno(stderr), _O_BINARY);
#endif
#if defined(OS_CHROMEOS)
- chromeos::DBusThreadManager::Initialize();
- bluez::BluezDBusManager::Initialize(
- chromeos::DBusThreadManager::Get()->GetSystemBus(),
- chromeos::DBusThreadManager::Get()->IsUsingStub(
- chromeos::DBusClientBundle::BLUETOOTH));
test_screen_ = aura::TestScreen::Create(gfx::Size());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_);
wm_test_helper_ = new wm::WMTestHelper(default_window_size,
@@ -444,11 +436,6 @@ void Shell::PlatformExit() {
views_delegate_ = NULL;
delete platform_;
platform_ = NULL;
-#if defined(OS_CHROMEOS)
- device::BluetoothAdapterFactory::Shutdown();
- bluez::BluezDBusManager::Shutdown();
- chromeos::DBusThreadManager::Shutdown();
-#endif
aura::Env::DeleteInstance();
}
diff --git a/device/bluetooth/BUILD.gn b/device/bluetooth/BUILD.gn
index 0abb9d4..d964a6a 100644
--- a/device/bluetooth/BUILD.gn
+++ b/device/bluetooth/BUILD.gn
@@ -211,8 +211,6 @@ component("bluetooth") {
"dbus/bluez_dbus_client.h",
"dbus/bluez_dbus_manager.cc",
"dbus/bluez_dbus_manager.h",
- "dbus/dbus_thread_manager_linux.cc",
- "dbus/dbus_thread_manager_linux.h",
"dbus/fake_bluetooth_adapter_client.cc",
"dbus/fake_bluetooth_adapter_client.h",
"dbus/fake_bluetooth_agent_manager_client.cc",
@@ -252,10 +250,23 @@ component("bluetooth") {
"dbus/fake_bluetooth_profile_service_provider.cc",
"dbus/fake_bluetooth_profile_service_provider.h",
]
-
+ if (is_linux) {
+ sources += [
+ "dbus/dbus_bluez_manager_wrapper_linux.cc",
+ "dbus/dbus_bluez_manager_wrapper_linux.h",
+ "dbus/dbus_thread_manager_linux.cc",
+ "dbus/dbus_thread_manager_linux.h",
+ ]
+ }
deps += [ "//dbus" ]
} else { # !use_dbus
sources += [ "bluetooth_adapter_stub.cc" ]
+ if (is_linux) {
+ sources += [
+ "dbus/dbus_bluez_manager_wrapper_linux.h",
+ "dbus/dbus_bluez_manager_wrapper_stub_linux.cc",
+ ]
+ }
}
}
}
diff --git a/device/bluetooth/bluetooth.gyp b/device/bluetooth/bluetooth.gyp
index b7fec2c..1cbf220 100644
--- a/device/bluetooth/bluetooth.gyp
+++ b/device/bluetooth/bluetooth.gyp
@@ -187,8 +187,6 @@
'dbus/bluez_dbus_client.h',
'dbus/bluez_dbus_manager.cc',
'dbus/bluez_dbus_manager.h',
- 'dbus/dbus_thread_manager_linux.cc',
- 'dbus/dbus_thread_manager_linux.h',
'dbus/fake_bluetooth_adapter_client.cc',
'dbus/fake_bluetooth_adapter_client.h',
'dbus/fake_bluetooth_le_advertising_manager_client.cc',
@@ -228,6 +226,16 @@
'dbus/fake_bluetooth_profile_service_provider.cc',
'dbus/fake_bluetooth_profile_service_provider.h',
],
+ 'conditions': [
+ ['OS=="linux"', {
+ 'sources': [
+ 'dbus/dbus_bluez_manager_wrapper_linux.cc',
+ 'dbus/dbus_bluez_manager_wrapper_linux.h',
+ 'dbus/dbus_thread_manager_linux.cc',
+ 'dbus/dbus_thread_manager_linux.h',
+ ]
+ }]
+ ],
'dependencies': [
'../../build/linux/system.gyp:dbus',
'../../dbus/dbus.gyp:dbus',
@@ -236,7 +244,15 @@
'../../build/linux/system.gyp:dbus'
]
}, { # !use_dbus
- 'sources': [ 'bluetooth_adapter_stub.cc' ]
+ 'sources': [ 'bluetooth_adapter_stub.cc' ],
+ 'conditions': [
+ ['OS=="linux"', {
+ 'sources': [
+ 'dbus/dbus_bluez_manager_wrapper_linux.h',
+ 'dbus/dbus_bluez_manager_wrapper_stub_linux.cc',
+ ]
+ }],
+ ]
}],
],
}],
diff --git a/device/bluetooth/bluetooth_adapter_factory.cc b/device/bluetooth/bluetooth_adapter_factory.cc
index fc2af86..2bcfbe90 100644
--- a/device/bluetooth/bluetooth_adapter_factory.cc
+++ b/device/bluetooth/bluetooth_adapter_factory.cc
@@ -59,9 +59,8 @@ bool BluetoothAdapterFactory::IsBluetoothAdapterAvailable() {
// instance even on platforms that would otherwise not support it.
if (default_adapter.Get())
return true;
-// Even though the adapter is available on Linux, we only want to use it for
-// the Chrome API, which is why defines(OS_LINUX) is missing from here.
-#if defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_WIN)
+#if defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_WIN) || \
+ defined(OS_LINUX)
return true;
#elif defined(OS_MACOSX)
return base::mac::IsOSLionOrLater();
@@ -72,12 +71,7 @@ bool BluetoothAdapterFactory::IsBluetoothAdapterAvailable() {
// static
void BluetoothAdapterFactory::GetAdapter(const AdapterCallback& callback) {
-// TODO(rkc): This is a very slight hack to allow us to be able to create
-// an adapter on Linux, 'without' exposing the adapter to all Bluetooth
-// services within the browser.
-#if !defined(OS_LINUX)
DCHECK(IsBluetoothAdapterAvailable());
-#endif
#if defined(OS_WIN)
if (!default_adapter.Get()) {
diff --git a/device/bluetooth/bluetooth_advertisement_bluez_unittest.cc b/device/bluetooth/bluetooth_advertisement_bluez_unittest.cc
index ea933fc..27b2c8f 100644
--- a/device/bluetooth/bluetooth_advertisement_bluez_unittest.cc
+++ b/device/bluetooth/bluetooth_advertisement_bluez_unittest.cc
@@ -53,7 +53,8 @@ class TestAdvertisementObserver : public BluetoothAdvertisement::Observer {
class BluetoothAdvertisementBlueZTest : public testing::Test {
public:
void SetUp() override {
- bluez::BluezDBusManager::Initialize(NULL, true);
+ bluez::BluezDBusManager::Initialize(nullptr /* bus */,
+ true /* use_dbus_stub */);
callback_count_ = 0;
error_callback_count_ = 0;
diff --git a/device/bluetooth/bluetooth_audio_sink_bluez_unittest.cc b/device/bluetooth/bluetooth_audio_sink_bluez_unittest.cc
index 6b6e3aa..25b53d5 100644
--- a/device/bluetooth/bluetooth_audio_sink_bluez_unittest.cc
+++ b/device/bluetooth/bluetooth_audio_sink_bluez_unittest.cc
@@ -85,7 +85,8 @@ class TestAudioSinkObserver : public BluetoothAudioSink::Observer {
class BluetoothAudioSinkBlueZTest : public testing::Test {
public:
void SetUp() override {
- bluez::BluezDBusManager::Initialize(NULL, true);
+ bluez::BluezDBusManager::Initialize(nullptr /* bus */,
+ true /* use_dbus_stub */);
callback_count_ = 0;
error_callback_count_ = 0;
diff --git a/device/bluetooth/dbus/dbus_bluez_manager_wrapper_linux.cc b/device/bluetooth/dbus/dbus_bluez_manager_wrapper_linux.cc
new file mode 100644
index 0000000..5b8b573
--- /dev/null
+++ b/device/bluetooth/dbus/dbus_bluez_manager_wrapper_linux.cc
@@ -0,0 +1,26 @@
+// Copyright 2016 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/bluetooth/dbus/dbus_bluez_manager_wrapper_linux.h"
+
+#include "device/bluetooth/dbus/bluez_dbus_manager.h"
+#include "device/bluetooth/dbus/dbus_thread_manager_linux.h"
+
+namespace bluez {
+
+// static
+void DBusBluezManagerWrapperLinux::Initialize() {
+ DBusThreadManagerLinux::Initialize();
+ BluezDBusManager::Initialize(
+ bluez::DBusThreadManagerLinux::Get()->GetSystemBus(),
+ false /* use_dbus_stub */);
+}
+
+// static
+void DBusBluezManagerWrapperLinux::Shutdown() {
+ bluez::BluezDBusManager::Shutdown();
+ bluez::DBusThreadManagerLinux::Shutdown();
+}
+
+} // namespace bluez
diff --git a/device/bluetooth/dbus/dbus_bluez_manager_wrapper_linux.h b/device/bluetooth/dbus/dbus_bluez_manager_wrapper_linux.h
new file mode 100644
index 0000000..ccd9623
--- /dev/null
+++ b/device/bluetooth/dbus/dbus_bluez_manager_wrapper_linux.h
@@ -0,0 +1,27 @@
+// Copyright 2016 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_BLUETOOTH_DBUS_DBUS_BLUEZ_MANAGER_WRAPPER_LINUX_H_
+#define DEVICE_BLUETOOTH_DBUS_DBUS_BLUEZ_MANAGER_WRAPPER_LINUX_H_
+
+#include "base/macros.h"
+#include "device/bluetooth/bluetooth_export.h"
+
+namespace bluez {
+
+// This class abstracts the initialization of DBusThreadManagerLinux and
+// BluezDBusManager. Targets that don't use DBus can provide stub
+// implementations.
+class DEVICE_BLUETOOTH_EXPORT DBusBluezManagerWrapperLinux {
+ public:
+ static void Initialize();
+ static void Shutdown();
+
+ private:
+ DISALLOW_IMPLICIT_CONSTRUCTORS(DBusBluezManagerWrapperLinux);
+};
+
+} // namespace bluez
+
+#endif // DEVICE_BLUETOOTH_DBUS_DBUS_BLUEZ_MANAGER_WRAPPER_LINUX_H_
diff --git a/device/bluetooth/dbus/dbus_bluez_manager_wrapper_stub_linux.cc b/device/bluetooth/dbus/dbus_bluez_manager_wrapper_stub_linux.cc
new file mode 100644
index 0000000..18c2bfe
--- /dev/null
+++ b/device/bluetooth/dbus/dbus_bluez_manager_wrapper_stub_linux.cc
@@ -0,0 +1,17 @@
+// Copyright 2016 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/bluetooth/dbus/dbus_bluez_manager_wrapper_linux.h"
+
+namespace bluez {
+
+// Stub implementation for targets that don't use DBus.
+// static
+void DBusBluezManagerWrapperLinux::Initialize() {}
+
+// Stub implementation for targets that don't use DBus.
+// static
+void DBusBluezManagerWrapperLinux::Shutdown() {}
+
+} // namespace bluez
diff --git a/extensions/browser/api/bluetooth/bluetooth_event_router.cc b/extensions/browser/api/bluetooth/bluetooth_event_router.cc
index 32606fab..d11d17e 100644
--- a/extensions/browser/api/bluetooth/bluetooth_event_router.cc
+++ b/extensions/browser/api/bluetooth/bluetooth_event_router.cc
@@ -73,9 +73,6 @@ BluetoothEventRouter::~BluetoothEventRouter() {
}
bool BluetoothEventRouter::IsBluetoothSupported() const {
-#if defined(OS_LINUX)
- return true;
-#endif
return adapter_.get() ||
device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable();
}