OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 CONTENT_BROWSER_NAVIGATOR_CONNECT_SERVICE_PORT_SERVICE_IMPL_H_ |
| 6 #define CONTENT_BROWSER_NAVIGATOR_CONNECT_SERVICE_PORT_SERVICE_IMPL_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "content/common/service_port_service.mojom.h" |
| 12 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" |
| 13 |
| 14 namespace content { |
| 15 struct MessagePortMessage; |
| 16 class MessagePortMessageFilter; |
| 17 class NavigatorConnectContextImpl; |
| 18 struct TransferredMessagePort; |
| 19 |
| 20 // Browser side class representing a ServicePortCollection in the renderer. One |
| 21 // instance of this class is created for each ServicePortCollection, and is |
| 22 // automatically destroyed when the ServicePortCollection in the renderer goes |
| 23 // away. |
| 24 class ServicePortServiceImpl : public ServicePortService { |
| 25 public: |
| 26 // Factory method called by mojo to create a new instance of this class to |
| 27 // handle requests from a new ServicePortCollection. |
| 28 static void Create(const scoped_refptr<NavigatorConnectContextImpl>& |
| 29 navigator_connect_context, |
| 30 const scoped_refptr<MessagePortMessageFilter>& |
| 31 message_port_message_filter, |
| 32 mojo::InterfaceRequest<ServicePortService> request); |
| 33 ~ServicePortServiceImpl() override; |
| 34 |
| 35 // Called by NavigatorConnectContextImpl to post a message to a port that is |
| 36 // owned by this ServicePortCollection. |
| 37 void PostMessageToClient( |
| 38 int port_id, |
| 39 const MessagePortMessage& message, |
| 40 const std::vector<TransferredMessagePort>& sent_message_ports); |
| 41 |
| 42 private: |
| 43 static void CreateOnIOThread( |
| 44 const scoped_refptr<NavigatorConnectContextImpl>& |
| 45 navigator_connect_context, |
| 46 const scoped_refptr<MessagePortMessageFilter>& |
| 47 message_port_message_filter, |
| 48 mojo::InterfaceRequest<ServicePortService> request); |
| 49 ServicePortServiceImpl(const scoped_refptr<NavigatorConnectContextImpl>& |
| 50 navigator_connect_context, |
| 51 const scoped_refptr<MessagePortMessageFilter>& |
| 52 message_port_message_filter, |
| 53 mojo::InterfaceRequest<ServicePortService> request); |
| 54 |
| 55 // ServicePortService methods: |
| 56 void SetClient(ServicePortServiceClientPtr client) override; |
| 57 void Connect(const mojo::String& target_url, |
| 58 const mojo::String& origin, |
| 59 const ConnectCallback& callback) override; |
| 60 void PostMessage(int32_t port_id, |
| 61 const mojo::String& message, |
| 62 mojo::Array<MojoTransferredMessagePortPtr> ports) override; |
| 63 void ClosePort(int32_t port_id) override; |
| 64 |
| 65 // Callback called when a connection to a service has been establised or |
| 66 // rejected. |
| 67 void OnConnectResult(const ConnectCallback& callback, |
| 68 int message_port_id, |
| 69 bool success); |
| 70 |
| 71 mojo::StrongBinding<ServicePortService> binding_; |
| 72 scoped_refptr<NavigatorConnectContextImpl> navigator_connect_context_; |
| 73 scoped_refptr<MessagePortMessageFilter> message_port_message_filter_; |
| 74 ServicePortServiceClientPtr client_; |
| 75 base::WeakPtrFactory<ServicePortServiceImpl> weak_ptr_factory_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(ServicePortServiceImpl); |
| 78 }; |
| 79 |
| 80 } // namespace content |
| 81 |
| 82 #endif // CONTENT_BROWSER_NAVIGATOR_CONNECT_SERVICE_PORT_SERVICE_IMPL_H_ |
OLD | NEW |