summaryrefslogtreecommitdiffstats
path: root/device/core
diff options
context:
space:
mode:
authorreillyg <reillyg@chromium.org>2014-08-28 18:58:43 -0700
committerCommit bot <commit-bot@chromium.org>2014-08-29 01:59:51 +0000
commite471fab8c731cfc2eacceca8cc5be524c2d6f4b4 (patch)
tree3ecc233a2dc5c66b1f980e335f1a92f027f2d95f /device/core
parenta859ef1cc6d20bd833c84cd2d126cf49440b16f7 (diff)
downloadchromium_src-e471fab8c731cfc2eacceca8cc5be524c2d6f4b4.zip
chromium_src-e471fab8c731cfc2eacceca8cc5be524c2d6f4b4.tar.gz
chromium_src-e471fab8c731cfc2eacceca8cc5be524c2d6f4b4.tar.bz2
Remove BrowserThread dependency from usb_service.
Instead of explicitly depending on specific browser threads the USB service can assume that it is instantiated on BrowserThread::FILE (or equivalent) and save a TaskRunner reference from this instantiation for later use when called from other threads. To reach BrowserThread::UI (required for DBus on Chrome OS) a reference to the appropriate TaskRunner must be provided when calling UsbService::GetInstance(). BUG= Review URL: https://codereview.chromium.org/507503002 Cr-Commit-Position: refs/heads/master@{#292546}
Diffstat (limited to 'device/core')
-rw-r--r--device/core/BUILD.gn10
-rw-r--r--device/core/core.gyp22
-rw-r--r--device/core/device_client.cc38
-rw-r--r--device/core/device_client.h39
4 files changed, 109 insertions, 0 deletions
diff --git a/device/core/BUILD.gn b/device/core/BUILD.gn
new file mode 100644
index 0000000..7d1671f
--- /dev/null
+++ b/device/core/BUILD.gn
@@ -0,0 +1,10 @@
+# Copyright 2014 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.
+
+source_set("core") {
+ sources = [
+ "device_client.cc",
+ "device_client.h",
+ ]
+}
diff --git a/device/core/core.gyp b/device/core/core.gyp
new file mode 100644
index 0000000..09bd315
--- /dev/null
+++ b/device/core/core.gyp
@@ -0,0 +1,22 @@
+# Copyright 2014 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': {
+ 'chromium_code': 1,
+ },
+ 'targets': [
+ {
+ 'target_name': 'device_core',
+ 'type': 'static_library',
+ 'include_dirs': [
+ '../..',
+ ],
+ 'sources': [
+ 'device_client.cc',
+ 'device_client.h',
+ ],
+ },
+ ],
+}
diff --git a/device/core/device_client.cc b/device/core/device_client.cc
new file mode 100644
index 0000000..ad96b1e
--- /dev/null
+++ b/device/core/device_client.cc
@@ -0,0 +1,38 @@
+// Copyright 2014 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/core/device_client.h"
+
+#include "base/logging.h"
+
+namespace device {
+
+namespace {
+
+DeviceClient* g_instance = NULL;
+
+} // namespace
+
+DeviceClient::DeviceClient() {
+ DCHECK(!g_instance);
+ g_instance = this;
+}
+
+DeviceClient::~DeviceClient() {
+ g_instance = NULL;
+}
+
+/* static */
+DeviceClient* DeviceClient::Get() {
+ DCHECK(g_instance);
+ return g_instance;
+}
+
+usb_service::UsbService* DeviceClient::GetUsbService() {
+ // This should never be called by clients which do not support the USB API.
+ NOTREACHED();
+ return NULL;
+}
+
+} // namespace device
diff --git a/device/core/device_client.h b/device/core/device_client.h
new file mode 100644
index 0000000..d8d938b
--- /dev/null
+++ b/device/core/device_client.h
@@ -0,0 +1,39 @@
+// Copyright 2014 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_CORE_DEVICE_CLIENT_H_
+#define DEVICE_CORE_DEVICE_CLIENT_H_
+
+#include "base/macros.h"
+
+namespace usb_service {
+class UsbService;
+}
+
+namespace device {
+
+// Interface used by consumers of //device APIs to get pointers to the service
+// singletons appropriate for a given embedding application. For an example see
+// //chrome/browser/chrome_device_client.h.
+class DeviceClient {
+ public:
+ // Construction sets the single instance.
+ DeviceClient();
+
+ // Destruction clears the single instance.
+ ~DeviceClient();
+
+ // Returns the single instance of |this|.
+ static DeviceClient* Get();
+
+ // Returns the UsbService instance for this embedder.
+ virtual usb_service::UsbService* GetUsbService();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DeviceClient);
+};
+
+} // namespace device
+
+#endif // DEVICE_CORE_DEVICE_CLIENT_H_