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

Side by Side Diff: extensions/browser/api/copresence_socket/copresence_socket_api.h

Issue 610633002: Prototype for copresenceSockets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: format specifiers build fix Created 6 years, 2 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
OLDNEW
(Empty)
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
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_SOCKET_COPRESENCE_SOCKET_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_SOCKET_COPRESENCE_SOCKET_API_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "extensions/browser/api/api_resource.h"
15 #include "extensions/browser/api/api_resource_manager.h"
16 #include "extensions/browser/browser_context_keyed_api_factory.h"
17 #include "extensions/browser/extension_function.h"
18 #include "extensions/browser/extension_function_histogram_value.h"
19
20 namespace copresence_sockets {
21 class CopresenceSocket;
22 }
23
24 namespace net {
25 class IOBuffer;
26 }
27
28 namespace extensions {
29
30 class CopresencePeerResource;
31 class CopresenceSocketResource;
32
33 class CopresenceSocketFunction : public UIThreadExtensionFunction {
34 public:
35 CopresenceSocketFunction();
36
37 void DispatchOnConnectedEvent(
38 int peer_id,
39 scoped_ptr<copresence_sockets::CopresenceSocket> socket);
40 void DispatchOnReceiveEvent(int socket_id,
41 const scoped_refptr<net::IOBuffer>& buffer,
42 int size);
43
44 protected:
45 // ExtensionFunction overrides:
46 virtual ExtensionFunction::ResponseAction Run() override;
47
48 // Override this and do actual work here.
49 virtual ExtensionFunction::ResponseAction Execute() = 0;
50
51 // Takes ownership of peer.
52 int AddPeer(CopresencePeerResource* peer);
53 // Takes ownership of socket.
54 int AddSocket(CopresenceSocketResource* socket);
55
56 // Takes ownership of peer.
57 void ReplacePeer(const std::string& extension_id,
58 int peer_id,
59 CopresencePeerResource* peer);
60
61 CopresencePeerResource* GetPeer(int peer_id);
62 CopresenceSocketResource* GetSocket(int socket_id);
63
64 void RemovePeer(int peer_id);
65 void RemoveSocket(int socket_id);
66
67 virtual ~CopresenceSocketFunction();
68
69 private:
70 void Initialize();
71
72 ApiResourceManager<CopresencePeerResource>* peers_manager_;
73 ApiResourceManager<CopresenceSocketResource>* sockets_manager_;
74 };
75
76 class CopresenceSocketCreatePeerFunction : public CopresenceSocketFunction {
77 public:
78 DECLARE_EXTENSION_FUNCTION("copresenceSocket.createPeer",
79 COPRESENCESOCKET_CREATEPEER);
80
81 protected:
82 virtual ~CopresenceSocketCreatePeerFunction() {}
83 virtual ExtensionFunction::ResponseAction Execute() override;
84
85 private:
86 void OnCreated(int peer_id, const std::string& locator);
87 };
88
89 class CopresenceSocketDestroyPeerFunction : public CopresenceSocketFunction {
90 public:
91 DECLARE_EXTENSION_FUNCTION("copresenceSocket.destroyPeer",
92 COPRESENCESOCKET_DESTROYPEER);
93
94 protected:
95 virtual ~CopresenceSocketDestroyPeerFunction() {}
96 virtual ExtensionFunction::ResponseAction Execute() override;
97 };
98
99 class CopresenceSocketSendFunction : public CopresenceSocketFunction {
100 public:
101 DECLARE_EXTENSION_FUNCTION("copresenceSocket.send", COPRESENCESOCKET_SEND);
102
103 protected:
104 virtual ~CopresenceSocketSendFunction() {}
105 virtual ExtensionFunction::ResponseAction Execute() override;
106 };
107
108 class CopresenceSocketDisconnectFunction : public CopresenceSocketFunction {
109 public:
110 DECLARE_EXTENSION_FUNCTION("copresenceSocket.disconnect",
111 COPRESENCESOCKET_DISCONNECT);
112
113 protected:
114 virtual ~CopresenceSocketDisconnectFunction() {}
115 virtual ExtensionFunction::ResponseAction Execute() override;
116 };
117
118 } // namespace extensions
119
120 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_SOCKET_COPRESENCE_SOCKET_API _H_
OLDNEW
« no previous file with comments | « extensions/browser/api/copresence_socket/OWNERS ('k') | extensions/browser/api/copresence_socket/copresence_socket_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698