summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreillyg <reillyg@chromium.org>2015-11-18 08:42:58 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-18 16:44:01 +0000
commitcf1af6314b8732015b8474badce1d15bef4cfada (patch)
tree65175cdc1ab371d1acec33193b37341f041598ec
parent648108e6446226e9e8727f6828d9135c810ab19c (diff)
downloadchromium_src-cf1af6314b8732015b8474badce1d15bef4cfada.zip
chromium_src-cf1af6314b8732015b8474badce1d15bef4cfada.tar.gz
chromium_src-cf1af6314b8732015b8474badce1d15bef4cfada.tar.bz2
Provide a stub implementation of device::UsbService on Android.
By stubbing out the Android implementation of UsbService we can avoid the #ifdefs necessary to disable WebUSB on Android since it will be implemented eventually anyways. BUG=549257 Review URL: https://codereview.chromium.org/1450733002 Cr-Commit-Position: refs/heads/master@{#360346}
-rw-r--r--chrome/app/generated_resources.grd2
-rw-r--r--chrome/browser/BUILD.gn14
-rw-r--r--chrome/browser/browser_process_impl.cc4
-rw-r--r--chrome/browser/browser_process_impl.h2
-rw-r--r--chrome/browser/chrome_content_browser_client.cc2
-rw-r--r--chrome/browser/chrome_device_client.cc2
-rw-r--r--chrome/chrome_browser.gypi34
-rw-r--r--components/components.gyp2
-rw-r--r--device/BUILD.gn11
-rw-r--r--device/device_tests.gyp7
-rw-r--r--device/usb/BUILD.gn39
-rw-r--r--device/usb/usb.gyp21
-rw-r--r--device/usb/usb_service.cc9
-rw-r--r--device/usb/usb_service_android.cc28
-rw-r--r--device/usb/usb_service_android.h25
15 files changed, 142 insertions, 60 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 25b9089..2947e73 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -15312,7 +15312,7 @@ Please check your email at <ph name="ACCOUNT_EMAIL">$2<ex>jane.doe@gmail.com</ex
</message>
</if>
- <if expr="not is_android and not is_ios">
+ <if expr="not is_ios">
<!-- WebUSB permission bypass flag. -->
<message name="IDS_FLAGS_ENABLE_WEBUSB_ON_ANY_ORIGIN_NAME" desc="Title for the flag that bypasses WebUSB permission prompts.">
Allow WebUSB from any origin.
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 7950009..65923fb 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -319,8 +319,13 @@ source_set("browser") {
"//components/visitedlink/common",
"//components/web_cache/browser",
"//components/web_modal",
+ "//components/webusb",
"//content/app/resources",
+ "//device/core",
+ "//device/devices_app/public/cpp",
+ "//device/devices_app/public/cpp:factory",
"//device/devices_app/usb/public/interfaces",
+ "//device/usb",
"//media",
"//media/midi",
"//mojo/application/public/cpp",
@@ -698,14 +703,7 @@ source_set("browser") {
sources += rebase_path(gypi_values.chrome_browser_non_mobile_sources,
".",
"//chrome")
- deps += [
- "//components/feedback",
- "//components/webusb",
- "//device/core",
- "//device/devices_app/public/cpp",
- "//device/devices_app/public/cpp:factory",
- "//device/usb",
- ]
+ deps += [ "//components/feedback" ]
}
if (!is_chrome_branded) {
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 047ff60..79333e4 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -29,6 +29,7 @@
#include "chrome/browser/chrome_browser_main.h"
#include "chrome/browser/chrome_child_process_watcher.h"
#include "chrome/browser/chrome_content_browser_client.h"
+#include "chrome/browser/chrome_device_client.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/component_updater/chrome_component_updater_configurator.h"
#include "chrome/browser/component_updater/supervised_user_whitelist_installer.h"
@@ -111,7 +112,6 @@
#endif
#if !defined(OS_ANDROID)
-#include "chrome/browser/chrome_device_client.h"
#include "chrome/browser/ui/user_manager.h"
#include "components/gcm_driver/gcm_client_factory.h"
#include "components/gcm_driver/gcm_desktop_utils.h"
@@ -217,9 +217,7 @@ BrowserProcessImpl::BrowserProcessImpl(
ui::InitIdleMonitor();
#endif
-#if !defined(OS_ANDROID)
device_client_.reset(new ChromeDeviceClient);
-#endif
#if defined(ENABLE_EXTENSIONS)
// Athena sets its own instance during Athena's init process.
diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h
index e5e85896..c68f13d 100644
--- a/chrome/browser/browser_process_impl.h
+++ b/chrome/browser/browser_process_impl.h
@@ -319,9 +319,7 @@ class BrowserProcessImpl : public BrowserProcess,
scoped_ptr<ChromeChildProcessWatcher> child_process_watcher_;
-#if !defined(OS_ANDROID)
scoped_ptr<ChromeDeviceClient> device_client_;
-#endif
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
// Any change to this #ifdef must be reflected as well in
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index dd8724d..fc1d416 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -639,7 +639,6 @@ void GetGuestViewDefaultContentSettingRules(
void CreateUsbDeviceManager(
RenderFrameHost* render_frame_host,
mojo::InterfaceRequest<device::usb::DeviceManager> request) {
-#if !defined(OS_ANDROID) && !defined(OS_IOS)
WebContents* web_contents =
WebContents::FromRenderFrameHost(render_frame_host);
if (!web_contents) {
@@ -650,7 +649,6 @@ void CreateUsbDeviceManager(
UsbTabHelper* tab_helper =
UsbTabHelper::GetOrCreateForWebContents(web_contents);
tab_helper->CreateDeviceManager(render_frame_host, request.Pass());
-#endif // !defined(OS_ANDROID) && !defined(OS_IOS)
}
} // namespace
diff --git a/chrome/browser/chrome_device_client.cc b/chrome/browser/chrome_device_client.cc
index e3ffbe7..b388d97 100644
--- a/chrome/browser/chrome_device_client.cc
+++ b/chrome/browser/chrome_device_client.cc
@@ -26,9 +26,11 @@ device::UsbService* ChromeDeviceClient::GetUsbService() {
device::HidService* ChromeDeviceClient::GetHidService() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
+#if !defined(OS_ANDROID)
if (!hid_service_) {
hid_service_ = device::HidService::Create(
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
}
+#endif
return hid_service_.get();
}
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index d6a9b8e..79bd4d4 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -387,6 +387,8 @@
'browser/chrome_content_browser_client.cc',
'browser/chrome_content_browser_client.h',
'browser/chrome_content_browser_client_parts.h',
+ 'browser/chrome_device_client.cc',
+ 'browser/chrome_device_client.h',
'browser/chrome_elf_init_win.cc',
'browser/chrome_elf_init_win.h',
'browser/chrome_net_benchmarking_message_filter.cc',
@@ -396,6 +398,8 @@
'browser/chrome_quota_permission_context.h',
'browser/chrome_select_file_dialog_factory_win.cc',
'browser/chrome_select_file_dialog_factory_win.h',
+ 'browser/chrome_webusb_browser_client.cc',
+ 'browser/chrome_webusb_browser_client.h',
'browser/command_observer.h',
'browser/command_updater.cc',
'browser/command_updater.h',
@@ -874,6 +878,14 @@
'browser/translate/translate_service.h',
'browser/update_client/chrome_update_query_params_delegate.cc',
'browser/update_client/chrome_update_query_params_delegate.h',
+ 'browser/usb/usb_chooser_context.cc',
+ 'browser/usb/usb_chooser_context.h',
+ 'browser/usb/usb_chooser_context_factory.cc',
+ 'browser/usb/usb_chooser_context_factory.h',
+ 'browser/usb/usb_tab_helper.cc',
+ 'browser/usb/usb_tab_helper.h',
+ 'browser/usb/web_usb_permission_provider.cc',
+ 'browser/usb/web_usb_permission_provider.h',
'browser/web_data_service_factory.cc',
'browser/web_data_service_factory.h',
],
@@ -1047,12 +1059,8 @@
'browser/chrome_browser_field_trials_desktop.h',
'browser/chrome_browser_main_posix.cc',
'browser/chrome_browser_main_posix.h',
- 'browser/chrome_device_client.cc',
- 'browser/chrome_device_client.h',
'browser/chrome_process_singleton.cc',
'browser/chrome_process_singleton.h',
- 'browser/chrome_webusb_browser_client.cc',
- 'browser/chrome_webusb_browser_client.h',
'browser/component_updater/widevine_cdm_component_installer.cc',
'browser/component_updater/widevine_cdm_component_installer.h',
'browser/custom_handlers/register_protocol_handler_permission_request.cc',
@@ -1304,16 +1312,8 @@
'browser/sync/sync_ui_util.h',
'browser/tracing/chrome_tracing_delegate.cc',
'browser/tracing/chrome_tracing_delegate.h',
- 'browser/usb/usb_chooser_context.cc',
- 'browser/usb/usb_chooser_context.h',
- 'browser/usb/usb_chooser_context_factory.cc',
- 'browser/usb/usb_chooser_context_factory.h',
'browser/upgrade_detector.cc',
'browser/upgrade_detector.h',
- 'browser/usb/usb_tab_helper.cc',
- 'browser/usb/usb_tab_helper.h',
- 'browser/usb/web_usb_permission_provider.cc',
- 'browser/usb/web_usb_permission_provider.h',
],
'chrome_browser_win_sources': [
'browser/browser_process_platform_part_aurawin.cc',
@@ -3243,9 +3243,14 @@
'../components/components.gyp:web_cache_browser',
'../components/components.gyp:web_modal',
'../components/components.gyp:web_resource',
+ '../components/components.gyp:webusb',
'../components/components_resources.gyp:components_resources',
'../content/app/resources/content_resources.gyp:content_resources',
+ '../device/core/core.gyp:device_core',
+ '../device/devices_app/devices_app.gyp:devices_app_public_cpp',
+ '../device/devices_app/devices_app.gyp:devices_app_public_cpp_factory',
'../device/devices_app/devices_app.gyp:device_usb_mojo_bindings_lib',
+ '../device/usb/usb.gyp:device_usb',
'../gpu/gpu.gyp:gpu',
'../media/media.gyp:media',
'../media/midi/midi.gyp:midi',
@@ -3642,11 +3647,6 @@
'sources': [ '<@(chrome_browser_non_mobile_sources)' ],
'dependencies': [
'../components/components.gyp:feedback_component',
- '../components/components.gyp:webusb',
- '../device/core/core.gyp:device_core',
- '../device/devices_app/devices_app.gyp:devices_app_public_cpp',
- '../device/devices_app/devices_app.gyp:devices_app_public_cpp_factory',
- '../device/usb/usb.gyp:device_usb',
'../net/net.gyp:net_browser_services',
]
}],
diff --git a/components/components.gyp b/components/components.gyp
index bce3ab7..03da51c 100644
--- a/components/components.gyp
+++ b/components/components.gyp
@@ -129,6 +129,7 @@
'web_cache.gypi',
'web_contents_delegate_android.gypi',
'web_modal.gypi',
+ 'webusb.gypi',
],
}],
['OS == "ios"', {
@@ -143,7 +144,6 @@
'feedback.gypi',
'proximity_auth.gypi',
'storage_monitor.gypi',
- 'webusb.gypi',
]
}],
['chromeos == 1', {
diff --git a/device/BUILD.gn b/device/BUILD.gn
index 467f781..1a72de1 100644
--- a/device/BUILD.gn
+++ b/device/BUILD.gn
@@ -104,8 +104,8 @@ test("device_unittests") {
deps += [ "//device/udev_linux" ]
}
- # USB does not compile on mobile platforms.
- if (!is_android && !is_ios) {
+ # USB does not compile on iOS.
+ if (!is_ios) {
sources += [
"devices_app/usb/device_impl_unittest.cc",
"devices_app/usb/device_manager_impl_unittest.cc",
@@ -114,7 +114,6 @@ test("device_unittests") {
"test/test_device_client.cc",
"test/test_device_client.h",
"test/usb_test_gadget_impl.cc",
- "usb/usb_context_unittest.cc",
"usb/usb_descriptors_unittest.cc",
"usb/usb_device_filter_unittest.cc",
"usb/usb_device_handle_unittest.cc",
@@ -128,10 +127,14 @@ test("device_unittests") {
"//device/devices_app/usb/public/interfaces",
"//device/usb",
"//device/usb:mocks",
- "//third_party/libusb",
]
}
+ # UsbContext is a libusb-specific object.
+ if (!is_android && !is_ios) {
+ sources += [ "usb/usb_context_unittest.cc" ]
+ }
+
if (is_android) {
sources -= [ "battery/battery_status_service_unittest.cc" ]
deps -= [ "//device/battery" ]
diff --git a/device/device_tests.gyp b/device/device_tests.gyp
index c7491ac..c0915ff 100644
--- a/device/device_tests.gyp
+++ b/device/device_tests.gyp
@@ -77,7 +77,6 @@
'test/test_device_client.cc',
'test/test_device_client.h',
'test/usb_test_gadget_impl.cc',
- 'usb/usb_context_unittest.cc',
'usb/usb_descriptors_unittest.cc',
'usb/usb_device_filter_unittest.cc',
'usb/usb_device_handle_unittest.cc',
@@ -111,11 +110,7 @@
}],
['OS=="android"', {
'dependencies!': [
- '../tools/usb_gadget/usb_gadget.gyp:usb_gadget',
'battery/battery.gyp:device_battery',
- 'devices_app/devices_app.gyp:devices_app_lib',
- 'usb/usb.gyp:device_usb',
- 'usb/usb.gyp:device_usb_mocks',
'serial/serial.gyp:device_serial',
'serial/serial.gyp:device_serial_test_util',
'hid/hid.gyp:device_hid',
@@ -128,10 +123,10 @@
'sources/': [
['exclude', '(^|/)hid'],
['exclude', '(^|/)serial'],
- ['exclude', '(^|/)usb'],
],
'sources!': [
'battery/battery_status_service_unittest.cc',
+ 'usb/usb_context_unittest.cc',
],
}],
['OS=="mac"', {
diff --git a/device/usb/BUILD.gn b/device/usb/BUILD.gn
index 8a9f47f..a139092 100644
--- a/device/usb/BUILD.gn
+++ b/device/usb/BUILD.gn
@@ -11,8 +11,6 @@ generated_ids = "$target_gen_dir/usb_ids_gen.cc"
source_set("usb") {
sources = [
- "usb_context.cc",
- "usb_context.h",
"usb_descriptors.cc",
"usb_descriptors.h",
"usb_device.cc",
@@ -21,18 +19,10 @@ source_set("usb") {
"usb_device_filter.h",
"usb_device_handle.cc",
"usb_device_handle.h",
- "usb_device_handle_impl.cc",
- "usb_device_handle_impl.h",
- "usb_device_impl.cc",
- "usb_device_impl.h",
- "usb_error.cc",
- "usb_error.h",
"usb_ids.cc",
"usb_ids.h",
"usb_service.cc",
"usb_service.h",
- "usb_service_impl.cc",
- "usb_service_impl.h",
"webusb_descriptors.cc",
"webusb_descriptors.h",
generated_ids,
@@ -45,23 +35,40 @@ source_set("usb") {
"//components/device_event_log",
"//device/core",
"//net",
- "//third_party/libusb",
]
if (use_udev) {
deps += [ "//device/udev_linux" ]
}
+
+ if (is_android) {
+ sources += [
+ "usb_service_android.cc",
+ "usb_service_android.h",
+ ]
+ } else {
+ sources += [
+ "usb_context.cc",
+ "usb_context.h",
+ "usb_device_handle_impl.cc",
+ "usb_device_handle_impl.h",
+ "usb_device_impl.cc",
+ "usb_device_impl.h",
+ "usb_error.cc",
+ "usb_error.h",
+ "usb_service_impl.cc",
+ "usb_service_impl.h",
+ ]
+
+ deps += [ "//third_party/libusb" ]
+ }
+
if (is_chromeos) {
deps += [
"//chromeos",
"//dbus",
]
}
-
- # TODO(moshayedi): crbug.com/549257. Add USB support for Aura on Android.
- if (is_android) {
- deps -= [ "//third_party/libusb" ]
- }
}
source_set("mocks") {
diff --git a/device/usb/usb.gyp b/device/usb/usb.gyp
index 1d3493f8..c7bf776 100644
--- a/device/usb/usb.gyp
+++ b/device/usb/usb.gyp
@@ -73,6 +73,27 @@
'../udev_linux/udev.gyp:udev_linux',
],
}],
+ ['OS=="android"', {
+ 'dependencies!': [
+ '../../third_party/libusb/libusb.gyp:libusb',
+ ],
+ 'sources': [
+ 'usb_service_android.cc',
+ 'usb_service_android.h',
+ ],
+ 'sources!': [
+ 'usb_context.cc',
+ 'usb_context.h',
+ 'usb_device_handle_impl.cc',
+ 'usb_device_handle_impl.h',
+ 'usb_device_impl.cc',
+ 'usb_device_impl.h',
+ 'usb_error.cc',
+ 'usb_error.h',
+ 'usb_service_impl.cc',
+ 'usb_service_impl.h',
+ ]
+ }],
['chromeos==1', {
'dependencies': [
'../../chromeos/chromeos.gyp:chromeos',
diff --git a/device/usb/usb_service.cc b/device/usb/usb_service.cc
index de9716f..807934e 100644
--- a/device/usb/usb_service.cc
+++ b/device/usb/usb_service.cc
@@ -8,7 +8,12 @@
#include "base/bind.h"
#include "components/device_event_log/device_event_log.h"
#include "device/usb/usb_device.h"
+
+#if defined(OS_ANDROID)
+#include "device/usb/usb_service_android.h"
+#else
#include "device/usb/usb_service_impl.h"
+#endif
namespace device {
@@ -29,7 +34,11 @@ void UsbService::Observer::WillDestroyUsbService() {}
// static
scoped_ptr<UsbService> UsbService::Create(
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) {
+#if defined(OS_ANDROID)
+ return make_scoped_ptr(new UsbServiceAndroid());
+#else
return make_scoped_ptr(new UsbServiceImpl(blocking_task_runner));
+#endif
}
UsbService::~UsbService() {
diff --git a/device/usb/usb_service_android.cc b/device/usb/usb_service_android.cc
new file mode 100644
index 0000000..45ce499
--- /dev/null
+++ b/device/usb/usb_service_android.cc
@@ -0,0 +1,28 @@
+// Copyright 2015 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/usb/usb_service_android.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/thread_task_runner_handle.h"
+#include "device/usb/usb_device.h"
+
+namespace device {
+
+UsbServiceAndroid::UsbServiceAndroid() {}
+
+UsbServiceAndroid::~UsbServiceAndroid() {}
+
+scoped_refptr<UsbDevice> UsbServiceAndroid::GetDevice(const std::string& guid) {
+ return nullptr;
+}
+
+void UsbServiceAndroid::GetDevices(const GetDevicesCallback& callback) {
+ std::vector<scoped_refptr<UsbDevice>> empty;
+ base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
+ base::Bind(callback, empty));
+}
+
+} // namespace device
diff --git a/device/usb/usb_service_android.h b/device/usb/usb_service_android.h
new file mode 100644
index 0000000..d1ffd9d
--- /dev/null
+++ b/device/usb/usb_service_android.h
@@ -0,0 +1,25 @@
+// Copyright 2015 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_USB_USB_SERVICE_ANDROID_H_
+#define DEVICE_USB_USB_SERVICE_ANDROID_H_
+
+#include "device/usb/usb_service.h"
+
+namespace device {
+
+// USB service implementation for Android. This is a stub implementation that
+// does not return any devices.
+class UsbServiceAndroid : public UsbService {
+ public:
+ UsbServiceAndroid();
+ ~UsbServiceAndroid() override;
+
+ scoped_refptr<UsbDevice> GetDevice(const std::string& guid) override;
+ void GetDevices(const GetDevicesCallback& callback) override;
+};
+
+} // namespace device
+
+#endif // DEVICE_USB_USB_SERVICE_ANDROID_H_