/extensions/browser/api/serial/serial_event_dispatcher.h

https://gitlab.com/0072016/Facebook-SDK- · C Header · 83 lines · 53 code · 23 blank · 7 comment · 0 complexity · d2f3d443bb39188c44cff7dd54017a1a MD5 · raw file

  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef EXTENSIONS_BROWSER_API_SERIAL_SERIAL_EVENT_DISPATCHER_H_
  5. #define EXTENSIONS_BROWSER_API_SERIAL_SERIAL_EVENT_DISPATCHER_H_
  6. #include <string>
  7. #include <vector>
  8. #include "extensions/browser/api/api_resource_manager.h"
  9. #include "extensions/common/api/serial.h"
  10. namespace content {
  11. class BrowserContext;
  12. }
  13. namespace extensions {
  14. struct Event;
  15. class SerialConnection;
  16. namespace api {
  17. // Per-browser-context dispatcher for events on serial connections.
  18. class SerialEventDispatcher : public BrowserContextKeyedAPI {
  19. public:
  20. explicit SerialEventDispatcher(content::BrowserContext* context);
  21. ~SerialEventDispatcher() override;
  22. // Start receiving data and firing events for a connection.
  23. void PollConnection(const std::string& extension_id, int connection_id);
  24. static SerialEventDispatcher* Get(content::BrowserContext* context);
  25. // BrowserContextKeyedAPI implementation.
  26. static BrowserContextKeyedAPIFactory<SerialEventDispatcher>*
  27. GetFactoryInstance();
  28. private:
  29. typedef ApiResourceManager<SerialConnection>::ApiResourceData ConnectionData;
  30. friend class BrowserContextKeyedAPIFactory<SerialEventDispatcher>;
  31. // BrowserContextKeyedAPI implementation.
  32. static const char* service_name() { return "SerialEventDispatcher"; }
  33. static const bool kServiceHasOwnInstanceInIncognito = true;
  34. static const bool kServiceIsNULLWhileTesting = true;
  35. struct ReceiveParams {
  36. ReceiveParams();
  37. ReceiveParams(const ReceiveParams& other);
  38. ~ReceiveParams();
  39. content::BrowserThread::ID thread_id;
  40. void* browser_context_id;
  41. std::string extension_id;
  42. scoped_refptr<ConnectionData> connections;
  43. int connection_id;
  44. };
  45. static void StartReceive(const ReceiveParams& params);
  46. static void ReceiveCallback(const ReceiveParams& params,
  47. const std::vector<char>& data,
  48. serial::ReceiveError error);
  49. static void PostEvent(const ReceiveParams& params,
  50. scoped_ptr<extensions::Event> event);
  51. static void DispatchEvent(void* browser_context_id,
  52. const std::string& extension_id,
  53. scoped_ptr<extensions::Event> event);
  54. content::BrowserThread::ID thread_id_;
  55. content::BrowserContext* const context_;
  56. scoped_refptr<ConnectionData> connections_;
  57. };
  58. } // namespace api
  59. } // namespace extensions
  60. #endif // EXTENSIONS_BROWSER_API_SERIAL_SERIAL_EVENT_DISPATCHER_H_