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

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: 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 extensions {
25
26 class CopresencePeerResource;
27 class CopresenceSocketResource;
28
29 class CopresenceSocketFunction : public UIThreadExtensionFunction {
30 public:
31 CopresenceSocketFunction();
32
33 void DispatchOnConnectedEvent(
34 int peer_id,
35 scoped_ptr<copresence_sockets::CopresenceSocket> socket);
36 void DispatchOnReceiveEvent(int socket_id, const std::string& data);
37
38 protected:
39 // ExtensionFunction overrides:
40 virtual ExtensionFunction::ResponseAction Run() override;
41
42 // Override this and do actual work here.
43 virtual ExtensionFunction::ResponseAction Execute() = 0;
44
45 // Takes ownership of peer.
46 int AddPeer(CopresencePeerResource* peer);
47 // Takes ownership of socket.
48 int AddSocket(CopresenceSocketResource* socket);
49
50 // Takes ownership of peer.
51 void ReplacePeer(const std::string& extension_id,
52 int peer_id,
53 CopresencePeerResource* peer);
54
55 CopresencePeerResource* GetPeer(int peer_id);
56 CopresenceSocketResource* GetSocket(int socket_id);
57
58 void RemovePeer(int peer_id);
59 void RemoveSocket(int socket_id);
60
61 virtual ~CopresenceSocketFunction();
62
63 private:
64 void Initialize();
65
66 ApiResourceManager<CopresencePeerResource>* peers_manager_;
67 ApiResourceManager<CopresenceSocketResource>* sockets_manager_;
68 };
69
70 class CopresenceSocketCreatePeerFunction : public CopresenceSocketFunction {
71 public:
72 DECLARE_EXTENSION_FUNCTION("copresenceSocket.createPeer",
73 COPRESENCESOCKET_CREATEPEER);
74
75 protected:
76 virtual ~CopresenceSocketCreatePeerFunction() {}
77 virtual ExtensionFunction::ResponseAction Execute() override;
78
79 private:
80 void OnCreated(int peer_id, const std::string& locator);
81 };
82
83 class CopresenceSocketDestroyPeerFunction : public CopresenceSocketFunction {
84 public:
85 DECLARE_EXTENSION_FUNCTION("copresenceSocket.destroyPeer",
86 COPRESENCESOCKET_DESTROYPEER);
87
88 protected:
89 virtual ~CopresenceSocketDestroyPeerFunction() {}
90 virtual ExtensionFunction::ResponseAction Execute() override;
91 };
92
93 class CopresenceSocketSendFunction : public CopresenceSocketFunction {
94 public:
95 DECLARE_EXTENSION_FUNCTION("copresenceSocket.send", COPRESENCESOCKET_SEND);
96
97 protected:
98 virtual ~CopresenceSocketSendFunction() {}
99 virtual ExtensionFunction::ResponseAction Execute() override;
100 };
101
102 class CopresenceSocketDisconnectFunction : public CopresenceSocketFunction {
103 public:
104 DECLARE_EXTENSION_FUNCTION("copresenceSocket.disconnect",
105 COPRESENCESOCKET_DISCONNECT);
106
107 protected:
108 virtual ~CopresenceSocketDisconnectFunction() {}
109 virtual ExtensionFunction::ResponseAction Execute() override;
110 };
111
112 } // namespace extensions
113
114 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_SOCKET_COPRESENCE_SOCKET_API _H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698