| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/navigator_connect/navigator_connect_context_impl.h" | 5 #include "content/browser/navigator_connect/navigator_connect_context_impl.h" |
| 6 | 6 |
| 7 #include "content/browser/message_port_message_filter.h" | 7 #include "content/browser/message_port_message_filter.h" |
| 8 #include "content/browser/message_port_service.h" | 8 #include "content/browser/message_port_service.h" |
| 9 #include "content/public/browser/navigator_connect_service_factory.h" | 9 #include "content/public/browser/navigator_connect_service_factory.h" |
| 10 #include "content/public/common/navigator_connect_client.h" | 10 #include "content/public/common/navigator_connect_client.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 for (auto it = service_factories_.rbegin(); it != service_factories_.rend(); | 61 for (auto it = service_factories_.rbegin(); it != service_factories_.rend(); |
| 62 ++it) { | 62 ++it) { |
| 63 if ((*it)->HandlesUrl(client.target_url)) { | 63 if ((*it)->HandlesUrl(client.target_url)) { |
| 64 factory = *it; | 64 factory = *it; |
| 65 break; | 65 break; |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 if (!factory) { | 69 if (!factory) { |
| 70 // No factories found. | 70 // No factories found. |
| 71 // Destroy ports since connection failed. | 71 OnConnectResult(client, client_port, client_port_route_id, |
| 72 message_port_service->Destroy(client_port); | 72 callback, nullptr); |
| 73 message_port_service->Destroy(service_port); | |
| 74 callback.Run(MSG_ROUTING_NONE, MSG_ROUTING_NONE, false); | |
| 75 return; | 73 return; |
| 76 } | 74 } |
| 77 | 75 |
| 78 // Actually initiate connection. | 76 // Actually initiate connection. |
| 79 factory->Connect( | 77 factory->Connect( |
| 80 client, base::Bind(&NavigatorConnectContextImpl::OnConnectResult, this, | 78 client, base::Bind(&NavigatorConnectContextImpl::OnConnectResult, this, |
| 81 client, client_port, client_port_route_id, callback)); | 79 client, client_port, client_port_route_id, callback)); |
| 82 } | 80 } |
| 83 | 81 |
| 84 void NavigatorConnectContextImpl::OnConnectResult( | 82 void NavigatorConnectContextImpl::OnConnectResult( |
| 85 const NavigatorConnectClient& client, | 83 const NavigatorConnectClient& client, |
| 86 int client_message_port_id, | 84 int client_message_port_id, |
| 87 int client_port_route_id, | 85 int client_port_route_id, |
| 88 const ConnectCallback& callback, | 86 const ConnectCallback& callback, |
| 89 MessagePortDelegate* delegate) { | 87 MessagePortDelegate* delegate) { |
| 90 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 88 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 91 if (delegate) { | 89 if (delegate) { |
| 92 // Update service side port with delegate. | 90 // Update service side port with delegate. |
| 93 MessagePortService::GetInstance()->UpdateMessagePort( | 91 MessagePortService::GetInstance()->UpdateMessagePort( |
| 94 client.message_port_id, delegate, client.message_port_id); | 92 client.message_port_id, delegate, client.message_port_id); |
| 95 callback.Run(client_message_port_id, client_port_route_id, true); | 93 TransferredMessagePort port; |
| 94 port.id = client_message_port_id; |
| 95 // TODO(mek): Set port.send_value_as_messages depending on connect result. |
| 96 callback.Run(port, client_port_route_id, true); |
| 96 } else { | 97 } else { |
| 97 // Destroy ports since connection failed. | 98 // Destroy ports since connection failed. |
| 98 MessagePortService::GetInstance()->Destroy(client.message_port_id); | 99 MessagePortService::GetInstance()->Destroy(client.message_port_id); |
| 99 MessagePortService::GetInstance()->Destroy(client_message_port_id); | 100 MessagePortService::GetInstance()->Destroy(client_message_port_id); |
| 100 callback.Run(MSG_ROUTING_NONE, MSG_ROUTING_NONE, false); | 101 callback.Run(TransferredMessagePort(), MSG_ROUTING_NONE, false); |
| 101 } | 102 } |
| 102 } | 103 } |
| 103 | 104 |
| 104 } // namespace content | 105 } // namespace content |
| OLD | NEW |