Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2639)

Unified Diff: chrome/browser/extensions/api/bluetooth/bluetooth_socket_event_dispatcher.h

Issue 180163009: chrome.bluetooth API improvements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix ChromeOS Full build. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/bluetooth/bluetooth_socket_event_dispatcher.h
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_socket_event_dispatcher.h b/chrome/browser/extensions/api/bluetooth/bluetooth_socket_event_dispatcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..9f0c2a578e2db5470ecb5ab4ef28671b0cc0eb10
--- /dev/null
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_socket_event_dispatcher.h
@@ -0,0 +1,81 @@
+// 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 CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_SOCKET_EVENT_DISPATCHER_H_
+#define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_SOCKET_EVENT_DISPATCHER_H_
+
+#include "chrome/browser/extensions/api/bluetooth/bluetooth_api_socket.h"
+#include "extensions/browser/api/api_resource_manager.h"
+#include "extensions/browser/browser_context_keyed_api_factory.h"
+
+namespace content {
+class BrowserContext;
+}
+
+namespace extensions {
+struct Event;
+class BluetoothApiSocket;
+}
+
+namespace extensions {
+namespace api {
+
+// Dispatch events related to "bluetooth" sockets from callback on native socket
+// instances. There is one instance per browser context.
+class BluetoothSocketEventDispatcher
+ : public base::RefCountedThreadSafe<BluetoothSocketEventDispatcher> {
+ public:
+ typedef ApiResourceManager<BluetoothApiSocket>::ApiResourceData SocketData;
+ explicit BluetoothSocketEventDispatcher(
+ content::BrowserContext* context,
+ scoped_refptr<SocketData> socket_data);
+
+ // Socket is active again, start receiving data from it.
+ void OnSocketResume(const std::string& extension_id, int socket_id);
+
+ private:
+ friend class base::RefCountedThreadSafe<BluetoothSocketEventDispatcher>;
+ virtual ~BluetoothSocketEventDispatcher();
+
+ // base::Bind supports methods with up to 6 parameters. ReceiveParams is used
+ // as a workaround that limitation for invoking StartReceive.
+ struct ReceiveParams {
+ ReceiveParams();
+ ~ReceiveParams();
+
+ std::string extension_id;
+ int socket_id;
+ };
+
+ // Start a receive and register a callback.
+ void StartReceive(const ReceiveParams& params);
+
+ // Called when socket receive data.
+ void ReceiveCallback(const ReceiveParams& params,
+ int bytes_read,
+ scoped_refptr<net::IOBuffer> io_buffer);
+
+ // Called when socket receive data.
+ void ReceiveErrorCallback(const ReceiveParams& params,
+ BluetoothApiSocket::ErrorReason error_reason,
+ const std::string& error);
+
+ // Post an extension event from IO to UI thread
+ void PostEvent(const ReceiveParams& params, scoped_ptr<Event> event);
+
+ // Dispatch an extension event on to EventRouter instance on UI thread.
+ void DispatchEvent(const std::string& extension_id, scoped_ptr<Event> event);
+
+ // Usually FILE thread (except for unit testing).
+ content::BrowserThread::ID thread_id_;
+ void* browser_context_id_;
+ scoped_refptr<SocketData> socket_data_;
+
+ DISALLOW_COPY_AND_ASSIGN(BluetoothSocketEventDispatcher);
+};
+
+} // namespace api
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_SOCKET_EVENT_DISPATCHER_H_

Powered by Google App Engine
This is Rietveld 408576698