Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/media/router/presentation_service_delegate_impl.h" | 5 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <unordered_map> | 8 #include <unordered_map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 const MediaRoute::Id& route_id, | 82 const MediaRoute::Id& route_id, |
| 83 const content::PresentationConnectionMessageCallback& message_cb) | 83 const content::PresentationConnectionMessageCallback& message_cb) |
| 84 : RouteMessageObserver(router, route_id), message_cb_(message_cb) { | 84 : RouteMessageObserver(router, route_id), message_cb_(message_cb) { |
| 85 DCHECK(!message_cb_.is_null()); | 85 DCHECK(!message_cb_.is_null()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 ~PresentationSessionMessagesObserver() final {} | 88 ~PresentationSessionMessagesObserver() final {} |
| 89 | 89 |
| 90 void OnMessagesReceived(const std::vector<RouteMessage>& messages) final { | 90 void OnMessagesReceived(const std::vector<RouteMessage>& messages) final { |
| 91 DVLOG(2) << __func__ << ", number of messages : " << messages.size(); | 91 DVLOG(2) << __func__ << ", number of messages : " << messages.size(); |
| 92 std::vector<std::unique_ptr<content::PresentationConnectionMessage>> | 92 std::vector<content::PresentationConnectionMessage> presentation_messages; |
| 93 presentation_messages; | |
| 94 for (const RouteMessage& message : messages) { | 93 for (const RouteMessage& message : messages) { |
| 95 if (message.type == RouteMessage::TEXT && message.text) { | 94 if (message.type == RouteMessage::TEXT && message.text) { |
| 96 presentation_messages.push_back( | 95 presentation_messages.emplace_back(message.text.value()); |
| 97 base::MakeUnique<content::PresentationConnectionMessage>( | |
| 98 content::PresentationMessageType::TEXT)); | |
| 99 presentation_messages.back()->message = *message.text; | |
| 100 } else if (message.type == RouteMessage::BINARY && message.binary) { | 96 } else if (message.type == RouteMessage::BINARY && message.binary) { |
| 101 presentation_messages.push_back( | 97 presentation_messages.emplace_back(message.binary.value()); |
| 102 base::MakeUnique<content::PresentationConnectionMessage>( | 98 } else { |
| 103 content::PresentationMessageType::BINARY)); | 99 NOTREACHED() << "Unknown route message type"; |
| 104 presentation_messages.back()->data.reset( | |
| 105 new std::vector<uint8_t>(*message.binary)); | |
| 106 } | 100 } |
| 107 } | 101 } |
| 108 // TODO(miu): Remove second argument from PresentationSessionMessageCallback | 102 message_cb_.Run(presentation_messages); |
| 109 // since it's always true now. | |
| 110 message_cb_.Run(presentation_messages, true); | |
| 111 } | 103 } |
| 112 | 104 |
| 113 private: | 105 private: |
| 114 const content::PresentationConnectionMessageCallback message_cb_; | 106 const content::PresentationConnectionMessageCallback message_cb_; |
| 115 | 107 |
| 116 DISALLOW_COPY_AND_ASSIGN(PresentationSessionMessagesObserver); | 108 DISALLOW_COPY_AND_ASSIGN(PresentationSessionMessagesObserver); |
| 117 }; | 109 }; |
| 118 | 110 |
| 119 } // namespace | 111 } // namespace |
| 120 | 112 |
| (...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 944 const content::PresentationConnectionMessageCallback& message_cb) { | 936 const content::PresentationConnectionMessageCallback& message_cb) { |
| 945 frame_manager_->ListenForSessionMessages( | 937 frame_manager_->ListenForSessionMessages( |
| 946 RenderFrameHostId(render_process_id, render_frame_id), session, | 938 RenderFrameHostId(render_process_id, render_frame_id), session, |
| 947 message_cb); | 939 message_cb); |
| 948 } | 940 } |
| 949 | 941 |
| 950 void PresentationServiceDelegateImpl::SendMessage( | 942 void PresentationServiceDelegateImpl::SendMessage( |
| 951 int render_process_id, | 943 int render_process_id, |
| 952 int render_frame_id, | 944 int render_frame_id, |
| 953 const content::PresentationSessionInfo& session, | 945 const content::PresentationSessionInfo& session, |
| 954 std::unique_ptr<content::PresentationConnectionMessage> message, | 946 const content::PresentationConnectionMessage& message, |
| 955 const SendMessageCallback& send_message_cb) { | 947 const SendMessageCallback& send_message_cb) { |
| 956 const MediaRoute::Id& route_id = frame_manager_->GetRouteId( | 948 const MediaRoute::Id& route_id = frame_manager_->GetRouteId( |
| 957 RenderFrameHostId(render_process_id, render_frame_id), | 949 RenderFrameHostId(render_process_id, render_frame_id), |
| 958 session.presentation_id); | 950 session.presentation_id); |
| 959 if (route_id.empty()) { | 951 if (route_id.empty()) { |
| 960 DVLOG(1) << "No active route for " << session.presentation_id; | 952 DVLOG(1) << "No active route for " << session.presentation_id; |
| 961 send_message_cb.Run(false); | 953 send_message_cb.Run(false); |
| 962 return; | 954 return; |
| 963 } | 955 } |
| 964 | 956 |
| 965 if (message->is_binary()) { | 957 if (message.is_binary()) { |
| 966 router_->SendRouteBinaryMessage(route_id, std::move(message->data), | 958 router_->SendRouteBinaryMessage(route_id, std::move(message.data.value()), |
|
dcheng
2017/02/28 06:45:26
Note that this doesn't move, since |message| is a
mark a. foltz
2017/02/28 18:35:21
message is now non-const
| |
| 967 send_message_cb); | 959 send_message_cb); |
| 968 } else { | 960 } else { |
| 969 router_->SendRouteMessage(route_id, message->message, send_message_cb); | 961 router_->SendRouteMessage(route_id, std::move(message.message.value()), |
| 962 send_message_cb); | |
| 970 } | 963 } |
| 971 } | 964 } |
| 972 | 965 |
| 973 void PresentationServiceDelegateImpl::ListenForConnectionStateChange( | 966 void PresentationServiceDelegateImpl::ListenForConnectionStateChange( |
| 974 int render_process_id, | 967 int render_process_id, |
| 975 int render_frame_id, | 968 int render_frame_id, |
| 976 const content::PresentationSessionInfo& connection, | 969 const content::PresentationSessionInfo& connection, |
| 977 const content::PresentationConnectionStateChangedCallback& | 970 const content::PresentationConnectionStateChangedCallback& |
| 978 state_changed_cb) { | 971 state_changed_cb) { |
| 979 frame_manager_->ListenForConnectionStateChange( | 972 frame_manager_->ListenForConnectionStateChange( |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1054 const base::ListValue* origins = | 1047 const base::ListValue* origins = |
| 1055 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) | 1048 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) |
| 1056 ->GetPrefs() | 1049 ->GetPrefs() |
| 1057 ->GetList(prefs::kMediaRouterTabMirroringSources); | 1050 ->GetList(prefs::kMediaRouterTabMirroringSources); |
| 1058 return origins && | 1051 return origins && |
| 1059 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); | 1052 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); |
| 1060 } | 1053 } |
| 1061 #endif // !defined(OS_ANDROID) | 1054 #endif // !defined(OS_ANDROID) |
| 1062 | 1055 |
| 1063 } // namespace media_router | 1056 } // namespace media_router |
| OLD | NEW |