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

Side by Side Diff: chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.h

Issue 183893041: Move sockets APIs out of src/chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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
(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_SOCKETS_TCP_TCP_SOCKET_EVENT_DISPATCHER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKETS_TCP_TCP_SOCKET_EVENT_DISPATCHER_H_
7
8 #include "chrome/browser/extensions/api/api_resource_manager.h"
9 #include "chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.h"
10
11 namespace content {
12 class BrowserContext;
13 }
14
15 namespace extensions {
16 struct Event;
17 class ResumableTCPSocket;
18 }
19
20 namespace extensions {
21 namespace api {
22
23 // Dispatch events related to "sockets.tcp" sockets from callback on native
24 // socket instances. There is one instance per profile.
25 class TCPSocketEventDispatcher
26 : public BrowserContextKeyedAPI,
27 public base::SupportsWeakPtr<TCPSocketEventDispatcher> {
28 public:
29 explicit TCPSocketEventDispatcher(content::BrowserContext* context);
30 virtual ~TCPSocketEventDispatcher();
31
32 // Socket is active, start receving from it.
33 void OnSocketConnect(const std::string& extension_id, int socket_id);
34
35 // Socket is active again, start receiving data from it.
36 void OnSocketResume(const std::string& extension_id, int socket_id);
37
38 // BrowserContextKeyedAPI implementation.
39 static BrowserContextKeyedAPIFactory<TCPSocketEventDispatcher>*
40 GetFactoryInstance();
41
42 // Convenience method to get the SocketEventDispatcher for a profile.
43 static TCPSocketEventDispatcher* Get(content::BrowserContext* context);
44
45 private:
46 typedef ApiResourceManager<ResumableTCPSocket>::ApiResourceData SocketData;
47 friend class BrowserContextKeyedAPIFactory<TCPSocketEventDispatcher>;
48 // BrowserContextKeyedAPI implementation.
49 static const char* service_name() {
50 return "TCPSocketEventDispatcher";
51 }
52 static const bool kServiceHasOwnInstanceInIncognito = true;
53 static const bool kServiceIsNULLWhileTesting = true;
54
55 // base::Bind supports methods with up to 6 parameters. ReadParams is used
56 // as a workaround that limitation for invoking StartReceive.
57 struct ReadParams {
58 ReadParams();
59 ~ReadParams();
60
61 content::BrowserThread::ID thread_id;
62 void* browser_context_id;
63 std::string extension_id;
64 scoped_refptr<SocketData> sockets;
65 int socket_id;
66 };
67
68 // Start a receive and register a callback.
69 void StartSocketRead(const std::string& extension_id, int socket_id);
70
71 // Start a receive and register a callback.
72 static void StartRead(const ReadParams& params);
73
74 // Called when socket receive data.
75 static void ReadCallback(const ReadParams& params,
76 int bytes_read,
77 scoped_refptr<net::IOBuffer> io_buffer);
78
79 // Post an extension event from IO to UI thread
80 static void PostEvent(const ReadParams& params, scoped_ptr<Event> event);
81
82 // Dispatch an extension event on to EventRouter instance on UI thread.
83 static void DispatchEvent(void* browser_context_id,
84 const std::string& extension_id,
85 scoped_ptr<Event> event);
86
87 // Usually IO thread (except for unit testing).
88 content::BrowserThread::ID thread_id_;
89 content::BrowserContext* const browser_context_;
90 scoped_refptr<SocketData> sockets_;
91 };
92
93 } // namespace api
94 } // namespace extensions
95
96 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKETS_TCP_TCP_SOCKET_EVENT_DISPATCHER _H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698