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 "remoting/protocol/transport_context.h" | 5 #include "remoting/protocol/transport_context.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 TransportRole role) | 45 TransportRole role) |
46 : signal_strategy_(signal_strategy), | 46 : signal_strategy_(signal_strategy), |
47 port_allocator_factory_(std::move(port_allocator_factory)), | 47 port_allocator_factory_(std::move(port_allocator_factory)), |
48 url_request_factory_(std::move(url_request_factory)), | 48 url_request_factory_(std::move(url_request_factory)), |
49 network_settings_(network_settings), | 49 network_settings_(network_settings), |
50 role_(role) {} | 50 role_(role) {} |
51 | 51 |
52 TransportContext::~TransportContext() {} | 52 TransportContext::~TransportContext() {} |
53 | 53 |
54 void TransportContext::Prepare() { | 54 void TransportContext::Prepare() { |
55 EnsureFreshJingleInfo(); | 55 EnsureFreshIceConfig(); |
56 } | 56 } |
57 | 57 |
58 void TransportContext::GetIceConfig(const GetIceConfigCallback& callback) { | 58 void TransportContext::GetIceConfig(const GetIceConfigCallback& callback) { |
59 EnsureFreshJingleInfo(); | 59 EnsureFreshIceConfig(); |
60 | 60 |
61 // If there is a pending |ice_config_request_| delay the callback until the | 61 // If there is a pending |ice_config_request_| for the current |relay_mode_| |
62 // request is finished. | 62 // then delay the callback until the request is finished. |
63 if (ice_config_request_) { | 63 if (ice_config_request_[relay_mode_]) { |
64 pending_ice_config_callbacks_.push_back(callback); | 64 pending_ice_config_callbacks_[relay_mode_].push_back(callback); |
65 } else { | 65 } else { |
66 callback.Run(ice_config_); | 66 callback.Run(ice_config_[relay_mode_]); |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 void TransportContext::EnsureFreshJingleInfo() { | 70 void TransportContext::EnsureFreshIceConfig() { |
71 // Check if request is already pending. | 71 // Check if request is already pending. |
72 if (ice_config_request_) | 72 if (ice_config_request_[relay_mode_]) |
73 return; | 73 return; |
74 | 74 |
75 // Don't need to make jingleinfo request if both STUN and Relay are disabled. | 75 // Don't need to make jingleinfo request if both STUN and Relay are disabled. |
76 if ((network_settings_.flags & (NetworkSettings::NAT_TRAVERSAL_STUN | | 76 if ((network_settings_.flags & (NetworkSettings::NAT_TRAVERSAL_STUN | |
77 NetworkSettings::NAT_TRAVERSAL_RELAY)) == 0) { | 77 NetworkSettings::NAT_TRAVERSAL_RELAY)) == 0) { |
78 return; | 78 return; |
79 } | 79 } |
80 | 80 |
81 if (ice_config_.is_null() || | 81 if (ice_config_[relay_mode_].is_null() || |
82 base::Time::Now() > ice_config_.expiration_time) { | 82 base::Time::Now() > ice_config_[relay_mode_].expiration_time) { |
83 if (!ice_config_url_.empty()) { | 83 scoped_ptr<IceConfigRequest> request; |
84 ice_config_request_.reset(new HttpIceConfigRequest( | 84 switch (relay_mode_) { |
85 url_request_factory_.get(), ice_config_url_)); | 85 case RelayMode::TURN: |
86 } else { | 86 if (ice_config_url_.empty()) { |
87 ice_config_request_.reset(new JingleInfoRequest(signal_strategy_)); | 87 LOG(WARNING) << "ice_config_url isn't set."; |
garykac
2016/03/15 20:38:59
Should this be an error? If the config url is not
Sergey Ulanov
2016/03/15 21:54:53
There are cases when this URL won't be set and it'
garykac
2016/03/16 00:58:21
Acknowledged.
| |
88 return; | |
89 } | |
90 request.reset(new HttpIceConfigRequest(url_request_factory_.get(), | |
91 ice_config_url_)); | |
92 break; | |
93 case RelayMode::GTURN: | |
94 request.reset(new JingleInfoRequest(signal_strategy_)); | |
95 break; | |
88 } | 96 } |
89 ice_config_request_->Send(base::Bind( | 97 ice_config_request_[relay_mode_] = std::move(request); |
90 &TransportContext::OnIceConfig, base::Unretained(this))); | 98 ice_config_request_[relay_mode_]->Send(base::Bind( |
99 &TransportContext::OnIceConfig, base::Unretained(this), relay_mode_)); | |
91 } | 100 } |
92 } | 101 } |
93 | 102 |
94 void TransportContext::OnIceConfig(const IceConfig& ice_config) { | 103 void TransportContext::OnIceConfig(RelayMode relay_mode, |
95 ice_config_ = ice_config; | 104 const IceConfig& ice_config) { |
96 ice_config_request_.reset(); | 105 ice_config_[relay_mode] = ice_config; |
106 ice_config_request_[relay_mode].reset(); | |
97 | 107 |
98 while (!pending_ice_config_callbacks_.empty()) { | 108 auto& callback_list = pending_ice_config_callbacks_[relay_mode]; |
99 pending_ice_config_callbacks_.begin()->Run(ice_config_); | 109 while (!callback_list.empty()) { |
100 pending_ice_config_callbacks_.pop_front(); | 110 callback_list.begin()->Run(ice_config); |
111 callback_list.pop_front(); | |
101 } | 112 } |
102 } | 113 } |
103 | 114 |
104 } // namespace protocol | 115 } // namespace protocol |
105 } // namespace remoting | 116 } // namespace remoting |
OLD | NEW |