OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_COPRESENCE_SOCKET_COPRESENCE_SOCKET_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_SOCKET_COPRESENCE_SOCKET_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_SOCKET_COPRESENCE_SOCKET_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_SOCKET_COPRESENCE_SOCKET_API_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 void DispatchOnConnectedEvent( | 37 void DispatchOnConnectedEvent( |
38 int peer_id, | 38 int peer_id, |
39 scoped_ptr<copresence_sockets::CopresenceSocket> socket); | 39 scoped_ptr<copresence_sockets::CopresenceSocket> socket); |
40 void DispatchOnReceiveEvent(int socket_id, | 40 void DispatchOnReceiveEvent(int socket_id, |
41 const scoped_refptr<net::IOBuffer>& buffer, | 41 const scoped_refptr<net::IOBuffer>& buffer, |
42 int size); | 42 int size); |
43 | 43 |
44 protected: | 44 protected: |
45 // ExtensionFunction overrides: | 45 // ExtensionFunction overrides: |
46 virtual ExtensionFunction::ResponseAction Run() override; | 46 ExtensionFunction::ResponseAction Run() override; |
47 | 47 |
48 // Override this and do actual work here. | 48 // Override this and do actual work here. |
49 virtual ExtensionFunction::ResponseAction Execute() = 0; | 49 virtual ExtensionFunction::ResponseAction Execute() = 0; |
50 | 50 |
51 // Takes ownership of peer. | 51 // Takes ownership of peer. |
52 int AddPeer(CopresencePeerResource* peer); | 52 int AddPeer(CopresencePeerResource* peer); |
53 // Takes ownership of socket. | 53 // Takes ownership of socket. |
54 int AddSocket(CopresenceSocketResource* socket); | 54 int AddSocket(CopresenceSocketResource* socket); |
55 | 55 |
56 // Takes ownership of peer. | 56 // Takes ownership of peer. |
57 void ReplacePeer(const std::string& extension_id, | 57 void ReplacePeer(const std::string& extension_id, |
58 int peer_id, | 58 int peer_id, |
59 CopresencePeerResource* peer); | 59 CopresencePeerResource* peer); |
60 | 60 |
61 CopresencePeerResource* GetPeer(int peer_id); | 61 CopresencePeerResource* GetPeer(int peer_id); |
62 CopresenceSocketResource* GetSocket(int socket_id); | 62 CopresenceSocketResource* GetSocket(int socket_id); |
63 | 63 |
64 void RemovePeer(int peer_id); | 64 void RemovePeer(int peer_id); |
65 void RemoveSocket(int socket_id); | 65 void RemoveSocket(int socket_id); |
66 | 66 |
67 virtual ~CopresenceSocketFunction(); | 67 ~CopresenceSocketFunction() override; |
68 | 68 |
69 private: | 69 private: |
70 void Initialize(); | 70 void Initialize(); |
71 | 71 |
72 ApiResourceManager<CopresencePeerResource>* peers_manager_; | 72 ApiResourceManager<CopresencePeerResource>* peers_manager_; |
73 ApiResourceManager<CopresenceSocketResource>* sockets_manager_; | 73 ApiResourceManager<CopresenceSocketResource>* sockets_manager_; |
74 }; | 74 }; |
75 | 75 |
76 class CopresenceSocketCreatePeerFunction : public CopresenceSocketFunction { | 76 class CopresenceSocketCreatePeerFunction : public CopresenceSocketFunction { |
77 public: | 77 public: |
78 DECLARE_EXTENSION_FUNCTION("copresenceSocket.createPeer", | 78 DECLARE_EXTENSION_FUNCTION("copresenceSocket.createPeer", |
79 COPRESENCESOCKET_CREATEPEER); | 79 COPRESENCESOCKET_CREATEPEER); |
80 | 80 |
81 protected: | 81 protected: |
82 virtual ~CopresenceSocketCreatePeerFunction() {} | 82 ~CopresenceSocketCreatePeerFunction() override {} |
83 virtual ExtensionFunction::ResponseAction Execute() override; | 83 ExtensionFunction::ResponseAction Execute() override; |
84 | 84 |
85 private: | 85 private: |
86 void OnCreated(int peer_id, const std::string& locator); | 86 void OnCreated(int peer_id, const std::string& locator); |
87 }; | 87 }; |
88 | 88 |
89 class CopresenceSocketDestroyPeerFunction : public CopresenceSocketFunction { | 89 class CopresenceSocketDestroyPeerFunction : public CopresenceSocketFunction { |
90 public: | 90 public: |
91 DECLARE_EXTENSION_FUNCTION("copresenceSocket.destroyPeer", | 91 DECLARE_EXTENSION_FUNCTION("copresenceSocket.destroyPeer", |
92 COPRESENCESOCKET_DESTROYPEER); | 92 COPRESENCESOCKET_DESTROYPEER); |
93 | 93 |
94 protected: | 94 protected: |
95 virtual ~CopresenceSocketDestroyPeerFunction() {} | 95 ~CopresenceSocketDestroyPeerFunction() override {} |
96 virtual ExtensionFunction::ResponseAction Execute() override; | 96 ExtensionFunction::ResponseAction Execute() override; |
97 }; | 97 }; |
98 | 98 |
99 class CopresenceSocketSendFunction : public CopresenceSocketFunction { | 99 class CopresenceSocketSendFunction : public CopresenceSocketFunction { |
100 public: | 100 public: |
101 DECLARE_EXTENSION_FUNCTION("copresenceSocket.send", COPRESENCESOCKET_SEND); | 101 DECLARE_EXTENSION_FUNCTION("copresenceSocket.send", COPRESENCESOCKET_SEND); |
102 | 102 |
103 protected: | 103 protected: |
104 virtual ~CopresenceSocketSendFunction() {} | 104 ~CopresenceSocketSendFunction() override {} |
105 virtual ExtensionFunction::ResponseAction Execute() override; | 105 ExtensionFunction::ResponseAction Execute() override; |
106 }; | 106 }; |
107 | 107 |
108 class CopresenceSocketDisconnectFunction : public CopresenceSocketFunction { | 108 class CopresenceSocketDisconnectFunction : public CopresenceSocketFunction { |
109 public: | 109 public: |
110 DECLARE_EXTENSION_FUNCTION("copresenceSocket.disconnect", | 110 DECLARE_EXTENSION_FUNCTION("copresenceSocket.disconnect", |
111 COPRESENCESOCKET_DISCONNECT); | 111 COPRESENCESOCKET_DISCONNECT); |
112 | 112 |
113 protected: | 113 protected: |
114 virtual ~CopresenceSocketDisconnectFunction() {} | 114 ~CopresenceSocketDisconnectFunction() override {} |
115 virtual ExtensionFunction::ResponseAction Execute() override; | 115 ExtensionFunction::ResponseAction Execute() override; |
116 }; | 116 }; |
117 | 117 |
118 } // namespace extensions | 118 } // namespace extensions |
119 | 119 |
120 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_SOCKET_COPRESENCE_SOCKET_API
_H_ | 120 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_SOCKET_COPRESENCE_SOCKET_API
_H_ |
OLD | NEW |