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

Side by Side Diff: extensions/browser/api/serial/serial_event_dispatcher.h

Issue 369893008: Move the serial API to extensions/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add missing dependency from usb_service to chromeos Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_EVENT_DISPATCHER_H_ 5 #ifndef EXTENSIONS_BROWSER_API_SERIAL_SERIAL_EVENT_DISPATCHER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_EVENT_DISPATCHER_H_ 6 #define EXTENSIONS_BROWSER_API_SERIAL_SERIAL_EVENT_DISPATCHER_H_
7 7
8 #include "chrome/common/extensions/api/serial.h" 8 #include <string>
9
9 #include "extensions/browser/api/api_resource_manager.h" 10 #include "extensions/browser/api/api_resource_manager.h"
11 #include "extensions/common/api/serial.h"
10 12
11 class Profile; 13 namespace content {
14 class BrowserContext;
15 }
12 16
13 namespace extensions { 17 namespace extensions {
14 18
15 struct Event; 19 struct Event;
16 class SerialConnection; 20 class SerialConnection;
17 21
18 namespace api { 22 namespace core_api {
19 23
20 // Per-profile dispatcher for events on serial connections. 24 // Per-browser-context dispatcher for events on serial connections.
21 class SerialEventDispatcher : public BrowserContextKeyedAPI { 25 class SerialEventDispatcher : public BrowserContextKeyedAPI {
22 public: 26 public:
23 explicit SerialEventDispatcher(content::BrowserContext* context); 27 explicit SerialEventDispatcher(content::BrowserContext* context);
24 virtual ~SerialEventDispatcher(); 28 virtual ~SerialEventDispatcher();
25 29
26 // Start receiving data and firing events for a connection. 30 // Start receiving data and firing events for a connection.
27 void PollConnection(const std::string& extension_id, int connection_id); 31 void PollConnection(const std::string& extension_id, int connection_id);
28 32
29 static SerialEventDispatcher* Get(content::BrowserContext* context); 33 static SerialEventDispatcher* Get(content::BrowserContext* context);
30 34
31 // BrowserContextKeyedAPI implementation. 35 // BrowserContextKeyedAPI implementation.
32 static BrowserContextKeyedAPIFactory<SerialEventDispatcher>* 36 static BrowserContextKeyedAPIFactory<SerialEventDispatcher>*
33 GetFactoryInstance(); 37 GetFactoryInstance();
34 38
35 private: 39 private:
36 typedef ApiResourceManager<SerialConnection>::ApiResourceData ConnectionData; 40 typedef ApiResourceManager<SerialConnection>::ApiResourceData ConnectionData;
37 friend class BrowserContextKeyedAPIFactory<SerialEventDispatcher>; 41 friend class BrowserContextKeyedAPIFactory<SerialEventDispatcher>;
38 42
39 // BrowserContextKeyedAPI implementation. 43 // BrowserContextKeyedAPI implementation.
40 static const char* service_name() { return "SerialEventDispatcher"; } 44 static const char* service_name() { return "SerialEventDispatcher"; }
41 static const bool kServiceHasOwnInstanceInIncognito = true; 45 static const bool kServiceHasOwnInstanceInIncognito = true;
42 static const bool kServiceIsNULLWhileTesting = true; 46 static const bool kServiceIsNULLWhileTesting = true;
43 47
44 struct ReceiveParams { 48 struct ReceiveParams {
45 ReceiveParams(); 49 ReceiveParams();
46 ~ReceiveParams(); 50 ~ReceiveParams();
47 51
48 content::BrowserThread::ID thread_id; 52 content::BrowserThread::ID thread_id;
49 void* profile_id; 53 void* browser_context_id;
50 std::string extension_id; 54 std::string extension_id;
51 scoped_refptr<ConnectionData> connections; 55 scoped_refptr<ConnectionData> connections;
52 int connection_id; 56 int connection_id;
53 }; 57 };
54 58
55 static void StartReceive(const ReceiveParams& params); 59 static void StartReceive(const ReceiveParams& params);
56 60
57 static void ReceiveCallback(const ReceiveParams& params, 61 static void ReceiveCallback(const ReceiveParams& params,
58 const std::string& data, 62 const std::string& data,
59 serial::ReceiveError error); 63 serial::ReceiveError error);
60 64
61 static void PostEvent(const ReceiveParams& params, 65 static void PostEvent(const ReceiveParams& params,
62 scoped_ptr<extensions::Event> event); 66 scoped_ptr<extensions::Event> event);
63 67
64 static void DispatchEvent(void* profile_id, 68 static void DispatchEvent(void* browser_context_id,
65 const std::string& extension_id, 69 const std::string& extension_id,
66 scoped_ptr<extensions::Event> event); 70 scoped_ptr<extensions::Event> event);
67 71
68 content::BrowserThread::ID thread_id_; 72 content::BrowserThread::ID thread_id_;
69 Profile* const profile_; 73 content::BrowserContext* const context_;
70 scoped_refptr<ConnectionData> connections_; 74 scoped_refptr<ConnectionData> connections_;
71 }; 75 };
72 76
73 } // namespace api 77 } // namespace core_api
74 78
75 } // namespace extensions 79 } // namespace extensions
76 80
77 #endif // CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_EVENT_DISPATCHER_H_ 81 #endif // EXTENSIONS_BROWSER_API_SERIAL_SERIAL_EVENT_DISPATCHER_H_
OLDNEW
« no previous file with comments | « extensions/browser/api/serial/serial_connection.cc ('k') | extensions/browser/api/serial/serial_event_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698