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