OLD | NEW |
| (Empty) |
1 // Copyright 2013 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 | |
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_EVENT_DISPATCHER_H_ | |
6 #define CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_EVENT_DISPATCHER_H_ | |
7 | |
8 #include "chrome/common/extensions/api/serial.h" | |
9 #include "extensions/browser/api/api_resource_manager.h" | |
10 | |
11 class Profile; | |
12 | |
13 namespace extensions { | |
14 | |
15 struct Event; | |
16 class SerialConnection; | |
17 | |
18 namespace api { | |
19 | |
20 // Per-profile dispatcher for events on serial connections. | |
21 class SerialEventDispatcher : public BrowserContextKeyedAPI { | |
22 public: | |
23 explicit SerialEventDispatcher(content::BrowserContext* context); | |
24 virtual ~SerialEventDispatcher(); | |
25 | |
26 // Start receiving data and firing events for a connection. | |
27 void PollConnection(const std::string& extension_id, int connection_id); | |
28 | |
29 static SerialEventDispatcher* Get(content::BrowserContext* context); | |
30 | |
31 // BrowserContextKeyedAPI implementation. | |
32 static BrowserContextKeyedAPIFactory<SerialEventDispatcher>* | |
33 GetFactoryInstance(); | |
34 | |
35 private: | |
36 typedef ApiResourceManager<SerialConnection>::ApiResourceData ConnectionData; | |
37 friend class BrowserContextKeyedAPIFactory<SerialEventDispatcher>; | |
38 | |
39 // BrowserContextKeyedAPI implementation. | |
40 static const char* service_name() { return "SerialEventDispatcher"; } | |
41 static const bool kServiceHasOwnInstanceInIncognito = true; | |
42 static const bool kServiceIsNULLWhileTesting = true; | |
43 | |
44 struct ReceiveParams { | |
45 ReceiveParams(); | |
46 ~ReceiveParams(); | |
47 | |
48 content::BrowserThread::ID thread_id; | |
49 void* profile_id; | |
50 std::string extension_id; | |
51 scoped_refptr<ConnectionData> connections; | |
52 int connection_id; | |
53 }; | |
54 | |
55 static void StartReceive(const ReceiveParams& params); | |
56 | |
57 static void ReceiveCallback(const ReceiveParams& params, | |
58 const std::string& data, | |
59 serial::ReceiveError error); | |
60 | |
61 static void PostEvent(const ReceiveParams& params, | |
62 scoped_ptr<extensions::Event> event); | |
63 | |
64 static void DispatchEvent(void* profile_id, | |
65 const std::string& extension_id, | |
66 scoped_ptr<extensions::Event> event); | |
67 | |
68 content::BrowserThread::ID thread_id_; | |
69 Profile* const profile_; | |
70 scoped_refptr<ConnectionData> connections_; | |
71 }; | |
72 | |
73 } // namespace api | |
74 | |
75 } // namespace extensions | |
76 | |
77 #endif // CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_EVENT_DISPATCHER_H_ | |
OLD | NEW |