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 "remoting/host/cast_extension_session.h" | 5 #include "remoting/host/cast_extension_session.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 FROM_HERE, | 195 FROM_HERE, |
196 base::Bind(&CastExtensionSession::OnCreateSessionDescription, | 196 base::Bind(&CastExtensionSession::OnCreateSessionDescription, |
197 base::Unretained(this), | 197 base::Unretained(this), |
198 desc)); | 198 desc)); |
199 return; | 199 return; |
200 } | 200 } |
201 | 201 |
202 peer_connection_->SetLocalDescription( | 202 peer_connection_->SetLocalDescription( |
203 CastSetSessionDescriptionObserver::Create(), desc); | 203 CastSetSessionDescriptionObserver::Create(), desc); |
204 | 204 |
205 scoped_ptr<base::DictionaryValue> json(new base::DictionaryValue()); | 205 base::DictionaryValue json; |
206 json->SetString(kWebRtcSessionDescType, desc->type()); | 206 json.SetString(kWebRtcSessionDescType, desc->type()); |
207 std::string subject = | 207 std::string subject = |
208 (desc->type() == "offer") ? kSubjectOffer : kSubjectAnswer; | 208 (desc->type() == "offer") ? kSubjectOffer : kSubjectAnswer; |
209 std::string desc_str; | 209 std::string desc_str; |
210 desc->ToString(&desc_str); | 210 desc->ToString(&desc_str); |
211 json->SetString(kWebRtcSessionDescSDP, desc_str); | 211 json.SetString(kWebRtcSessionDescSDP, desc_str); |
212 std::string json_str; | 212 std::string json_str; |
213 if (!base::JSONWriter::Write(json.get(), &json_str)) { | 213 if (!base::JSONWriter::Write(json, &json_str)) { |
214 LOG(ERROR) << "Failed to serialize sdp message."; | 214 LOG(ERROR) << "Failed to serialize sdp message."; |
215 return; | 215 return; |
216 } | 216 } |
217 | 217 |
218 SendMessageToClient(subject.c_str(), json_str); | 218 SendMessageToClient(subject.c_str(), json_str); |
219 } | 219 } |
220 | 220 |
221 void CastExtensionSession::OnCreateSessionDescriptionFailure( | 221 void CastExtensionSession::OnCreateSessionDescriptionFailure( |
222 const std::string& error) { | 222 const std::string& error) { |
223 VLOG(1) << "Creating Session Description failed: " << error; | 223 VLOG(1) << "Creating Session Description failed: " << error; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 if (client_stub_ == nullptr) { | 413 if (client_stub_ == nullptr) { |
414 LOG(ERROR) << "No Client Stub. Cannot send message to client."; | 414 LOG(ERROR) << "No Client Stub. Cannot send message to client."; |
415 return false; | 415 return false; |
416 } | 416 } |
417 | 417 |
418 base::DictionaryValue message_dict; | 418 base::DictionaryValue message_dict; |
419 message_dict.SetString(kTopLevelSubject, subject); | 419 message_dict.SetString(kTopLevelSubject, subject); |
420 message_dict.SetString(kTopLevelData, data); | 420 message_dict.SetString(kTopLevelData, data); |
421 std::string message_json; | 421 std::string message_json; |
422 | 422 |
423 if (!base::JSONWriter::Write(&message_dict, &message_json)) { | 423 if (!base::JSONWriter::Write(message_dict, &message_json)) { |
424 LOG(ERROR) << "Failed to serialize JSON message."; | 424 LOG(ERROR) << "Failed to serialize JSON message."; |
425 return false; | 425 return false; |
426 } | 426 } |
427 | 427 |
428 protocol::ExtensionMessage message; | 428 protocol::ExtensionMessage message; |
429 message.set_type(kExtensionMessageType); | 429 message.set_type(kExtensionMessageType); |
430 message.set_data(message_json); | 430 message.set_data(message_json); |
431 client_stub_->DeliverHostMessage(message); | 431 client_stub_->DeliverHostMessage(message); |
432 return true; | 432 return true; |
433 } | 433 } |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 VLOG(1) << "PeerConnectionObserver: all ICE candidates found."; | 640 VLOG(1) << "PeerConnectionObserver: all ICE candidates found."; |
641 } | 641 } |
642 | 642 |
643 void CastExtensionSession::OnIceCandidate( | 643 void CastExtensionSession::OnIceCandidate( |
644 const webrtc::IceCandidateInterface* candidate) { | 644 const webrtc::IceCandidateInterface* candidate) { |
645 std::string candidate_str; | 645 std::string candidate_str; |
646 if (!candidate->ToString(&candidate_str)) { | 646 if (!candidate->ToString(&candidate_str)) { |
647 LOG(ERROR) << "PeerConnectionObserver: failed to serialize candidate."; | 647 LOG(ERROR) << "PeerConnectionObserver: failed to serialize candidate."; |
648 return; | 648 return; |
649 } | 649 } |
650 scoped_ptr<base::DictionaryValue> json(new base::DictionaryValue()); | 650 base::DictionaryValue json; |
651 json->SetString(kWebRtcSDPMid, candidate->sdp_mid()); | 651 json.SetString(kWebRtcSDPMid, candidate->sdp_mid()); |
652 json->SetInteger(kWebRtcSDPMLineIndex, candidate->sdp_mline_index()); | 652 json.SetInteger(kWebRtcSDPMLineIndex, candidate->sdp_mline_index()); |
653 json->SetString(kWebRtcCandidate, candidate_str); | 653 json.SetString(kWebRtcCandidate, candidate_str); |
654 std::string json_str; | 654 std::string json_str; |
655 if (!base::JSONWriter::Write(json.get(), &json_str)) { | 655 if (!base::JSONWriter::Write(json, &json_str)) { |
656 LOG(ERROR) << "Failed to serialize candidate message."; | 656 LOG(ERROR) << "Failed to serialize candidate message."; |
657 return; | 657 return; |
658 } | 658 } |
659 SendMessageToClient(kSubjectNewCandidate, json_str); | 659 SendMessageToClient(kSubjectNewCandidate, json_str); |
660 } | 660 } |
661 | 661 |
662 } // namespace remoting | 662 } // namespace remoting |
OLD | NEW |