| 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 EXTENSIONS_BROWSER_API_COPRESENCE_ENDPOINTS_COPRESENCE_ENDPOINTS_API_H_ | |
| 6 #define EXTENSIONS_BROWSER_API_COPRESENCE_ENDPOINTS_COPRESENCE_ENDPOINTS_API_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/memory/scoped_ptr.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_endpoints { | |
| 21 class CopresenceEndpoint; | |
| 22 } | |
| 23 | |
| 24 namespace net { | |
| 25 class IOBuffer; | |
| 26 } | |
| 27 | |
| 28 namespace extensions { | |
| 29 | |
| 30 class CopresenceEndpointResource; | |
| 31 | |
| 32 class CopresenceEndpointFunction : public UIThreadExtensionFunction { | |
| 33 public: | |
| 34 CopresenceEndpointFunction(); | |
| 35 | |
| 36 void DispatchOnConnectedEvent(int endpoint_id); | |
| 37 | |
| 38 // Needs to be used from CreateLocalEndpoint. | |
| 39 void OnDataReceived(int endpoint_id, | |
| 40 const scoped_refptr<net::IOBuffer>& buffer, | |
| 41 int size); | |
| 42 | |
| 43 protected: | |
| 44 ~CopresenceEndpointFunction() override; | |
| 45 | |
| 46 // Override this and do actual work here. | |
| 47 virtual ExtensionFunction::ResponseAction Execute() = 0; | |
| 48 | |
| 49 // Takes ownership of endpoint. | |
| 50 int AddEndpoint(CopresenceEndpointResource* endpoint); | |
| 51 | |
| 52 // Takes ownership of endpoint. | |
| 53 void ReplaceEndpoint(const std::string& extension_id, | |
| 54 int endpoint_id, | |
| 55 CopresenceEndpointResource* endpoint); | |
| 56 | |
| 57 CopresenceEndpointResource* GetEndpoint(int endpoint_id); | |
| 58 | |
| 59 void RemoveEndpoint(int endpoint_id); | |
| 60 | |
| 61 // ExtensionFunction overrides: | |
| 62 ExtensionFunction::ResponseAction Run() override; | |
| 63 | |
| 64 private: | |
| 65 void Initialize(); | |
| 66 | |
| 67 void DispatchOnReceiveEvent(int local_endpoint_id, | |
| 68 int remote_endpoint_id, | |
| 69 const std::string& data); | |
| 70 | |
| 71 ApiResourceManager<CopresenceEndpointResource>* endpoints_manager_; | |
| 72 }; | |
| 73 | |
| 74 class CopresenceEndpointsCreateLocalEndpointFunction | |
| 75 : public CopresenceEndpointFunction { | |
| 76 public: | |
| 77 DECLARE_EXTENSION_FUNCTION("copresenceEndpoints.createLocalEndpoint", | |
| 78 COPRESENCEENDPOINTS_CREATELOCALENDPOINT); | |
| 79 | |
| 80 protected: | |
| 81 ~CopresenceEndpointsCreateLocalEndpointFunction() override {} | |
| 82 ExtensionFunction::ResponseAction Execute() override; | |
| 83 | |
| 84 private: | |
| 85 void OnCreated(int endpoint_id, const std::string& locator); | |
| 86 }; | |
| 87 | |
| 88 class CopresenceEndpointsDestroyEndpointFunction | |
| 89 : public CopresenceEndpointFunction { | |
| 90 public: | |
| 91 DECLARE_EXTENSION_FUNCTION("copresenceEndpoints.destroyLocalEndpoint", | |
| 92 COPRESENCEENDPOINTS_DESTROYLOCALENDPOINT); | |
| 93 | |
| 94 protected: | |
| 95 ~CopresenceEndpointsDestroyEndpointFunction() override {} | |
| 96 ExtensionFunction::ResponseAction Execute() override; | |
| 97 }; | |
| 98 | |
| 99 class CopresenceEndpointsSendFunction : public CopresenceEndpointFunction { | |
| 100 public: | |
| 101 DECLARE_EXTENSION_FUNCTION("copresenceEndpoints.send", | |
| 102 COPRESENCEENDPOINTS_SEND); | |
| 103 | |
| 104 protected: | |
| 105 ~CopresenceEndpointsSendFunction() override {} | |
| 106 ExtensionFunction::ResponseAction Execute() override; | |
| 107 }; | |
| 108 | |
| 109 } // namespace extensions | |
| 110 | |
| 111 #endif // EXTENSIONS_BROWSER_API_COPRESENCE_ENDPOINTS_COPRESENCE_ENDPOINTS_API_
H_ | |
| OLD | NEW |