Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: remoting/protocol/session_config.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/protocol/session_config.h ('k') | remoting/protocol/session_config_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/session_config.h" 5 #include "remoting/protocol/session_config.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h"
11 12
12 namespace remoting { 13 namespace remoting {
13 namespace protocol { 14 namespace protocol {
14 15
15 namespace { 16 namespace {
16 17
17 bool IsChannelConfigSupported(const std::list<ChannelConfig>& list, 18 bool IsChannelConfigSupported(const std::list<ChannelConfig>& list,
18 const ChannelConfig& value) { 19 const ChannelConfig& value) {
19 return std::find(list.begin(), list.end(), value) != list.end(); 20 return std::find(list.begin(), list.end(), value) != list.end();
20 } 21 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 64 }
64 65
65 bool ChannelConfig::operator==(const ChannelConfig& b) const { 66 bool ChannelConfig::operator==(const ChannelConfig& b) const {
66 // If the transport field is set to NONE then all other fields are irrelevant. 67 // If the transport field is set to NONE then all other fields are irrelevant.
67 if (transport == ChannelConfig::TRANSPORT_NONE) 68 if (transport == ChannelConfig::TRANSPORT_NONE)
68 return transport == b.transport; 69 return transport == b.transport;
69 return transport == b.transport && version == b.version && codec == b.codec; 70 return transport == b.transport && version == b.version && codec == b.codec;
70 } 71 }
71 72
72 // static 73 // static
73 scoped_ptr<SessionConfig> SessionConfig::SelectCommon( 74 std::unique_ptr<SessionConfig> SessionConfig::SelectCommon(
74 const CandidateSessionConfig* client_config, 75 const CandidateSessionConfig* client_config,
75 const CandidateSessionConfig* host_config) { 76 const CandidateSessionConfig* host_config) {
76
77 // Use WebRTC if both host and client support it. 77 // Use WebRTC if both host and client support it.
78 if (client_config->webrtc_supported() && host_config->webrtc_supported()) 78 if (client_config->webrtc_supported() && host_config->webrtc_supported())
79 return make_scoped_ptr(new SessionConfig(Protocol::WEBRTC)); 79 return base::WrapUnique(new SessionConfig(Protocol::WEBRTC));
80 80
81 // Reject connection if ICE is not supported by either of the peers. 81 // Reject connection if ICE is not supported by either of the peers.
82 if (!host_config->ice_supported() || !client_config->ice_supported()) 82 if (!host_config->ice_supported() || !client_config->ice_supported())
83 return nullptr; 83 return nullptr;
84 84
85 scoped_ptr<SessionConfig> result(new SessionConfig(Protocol::ICE)); 85 std::unique_ptr<SessionConfig> result(new SessionConfig(Protocol::ICE));
86 ChannelConfig control_config; 86 ChannelConfig control_config;
87 ChannelConfig event_config; 87 ChannelConfig event_config;
88 ChannelConfig video_config; 88 ChannelConfig video_config;
89 ChannelConfig audio_config; 89 ChannelConfig audio_config;
90 90
91 // If neither host nor the client have VP9 experiment enabled then remove it 91 // If neither host nor the client have VP9 experiment enabled then remove it
92 // from the list of host video configs. 92 // from the list of host video configs.
93 std::list<ChannelConfig> host_video_configs = host_config->video_configs(); 93 std::list<ChannelConfig> host_video_configs = host_config->video_configs();
94 if (!client_config->vp9_experiment_enabled() && 94 if (!client_config->vp9_experiment_enabled() &&
95 !host_config->vp9_experiment_enabled()) { 95 !host_config->vp9_experiment_enabled()) {
(...skipping 14 matching lines...) Expand all
110 !SelectCommonChannelConfig(host_config->audio_configs(), 110 !SelectCommonChannelConfig(host_config->audio_configs(),
111 client_config->audio_configs(), 111 client_config->audio_configs(),
112 &result->audio_config_)) { 112 &result->audio_config_)) {
113 return nullptr; 113 return nullptr;
114 } 114 }
115 115
116 return result; 116 return result;
117 } 117 }
118 118
119 // static 119 // static
120 scoped_ptr<SessionConfig> SessionConfig::GetFinalConfig( 120 std::unique_ptr<SessionConfig> SessionConfig::GetFinalConfig(
121 const CandidateSessionConfig* candidate_config) { 121 const CandidateSessionConfig* candidate_config) {
122 if (candidate_config->webrtc_supported()) { 122 if (candidate_config->webrtc_supported()) {
123 if (candidate_config->ice_supported()) { 123 if (candidate_config->ice_supported()) {
124 LOG(ERROR) << "Received candidate config is ambiguous."; 124 LOG(ERROR) << "Received candidate config is ambiguous.";
125 return nullptr; 125 return nullptr;
126 } 126 }
127 return make_scoped_ptr(new SessionConfig(Protocol::WEBRTC)); 127 return base::WrapUnique(new SessionConfig(Protocol::WEBRTC));
128 } 128 }
129 129
130 if (!candidate_config->ice_supported()) 130 if (!candidate_config->ice_supported())
131 return nullptr; 131 return nullptr;
132 132
133 if (candidate_config->control_configs().size() != 1 || 133 if (candidate_config->control_configs().size() != 1 ||
134 candidate_config->event_configs().size() != 1 || 134 candidate_config->event_configs().size() != 1 ||
135 candidate_config->video_configs().size() != 1 || 135 candidate_config->video_configs().size() != 1 ||
136 candidate_config->audio_configs().size() != 1) { 136 candidate_config->audio_configs().size() != 1) {
137 return nullptr; 137 return nullptr;
138 } 138 }
139 139
140 scoped_ptr<SessionConfig> result(new SessionConfig(Protocol::ICE)); 140 std::unique_ptr<SessionConfig> result(new SessionConfig(Protocol::ICE));
141 result->control_config_ = candidate_config->control_configs().front(); 141 result->control_config_ = candidate_config->control_configs().front();
142 result->event_config_ = candidate_config->event_configs().front(); 142 result->event_config_ = candidate_config->event_configs().front();
143 result->video_config_ = candidate_config->video_configs().front(); 143 result->video_config_ = candidate_config->video_configs().front();
144 result->audio_config_ = candidate_config->audio_configs().front(); 144 result->audio_config_ = candidate_config->audio_configs().front();
145 145
146 return result; 146 return result;
147 } 147 }
148 148
149 // static 149 // static
150 scoped_ptr<SessionConfig> SessionConfig::ForTest() { 150 std::unique_ptr<SessionConfig> SessionConfig::ForTest() {
151 scoped_ptr<SessionConfig> result(new SessionConfig(Protocol::ICE)); 151 std::unique_ptr<SessionConfig> result(new SessionConfig(Protocol::ICE));
152 result->control_config_ = ChannelConfig(ChannelConfig::TRANSPORT_MUX_STREAM, 152 result->control_config_ = ChannelConfig(ChannelConfig::TRANSPORT_MUX_STREAM,
153 kControlStreamVersion, 153 kControlStreamVersion,
154 ChannelConfig::CODEC_UNDEFINED); 154 ChannelConfig::CODEC_UNDEFINED);
155 result->event_config_ = ChannelConfig(ChannelConfig::TRANSPORT_MUX_STREAM, 155 result->event_config_ = ChannelConfig(ChannelConfig::TRANSPORT_MUX_STREAM,
156 kDefaultStreamVersion, 156 kDefaultStreamVersion,
157 ChannelConfig::CODEC_UNDEFINED); 157 ChannelConfig::CODEC_UNDEFINED);
158 result->video_config_ = ChannelConfig(ChannelConfig::TRANSPORT_STREAM, 158 result->video_config_ = ChannelConfig(ChannelConfig::TRANSPORT_STREAM,
159 kDefaultStreamVersion, 159 kDefaultStreamVersion,
160 ChannelConfig::CODEC_VP8); 160 ChannelConfig::CODEC_VP8);
161 result->audio_config_ = ChannelConfig(ChannelConfig::TRANSPORT_NONE, 161 result->audio_config_ = ChannelConfig(ChannelConfig::TRANSPORT_NONE,
162 kDefaultStreamVersion, 162 kDefaultStreamVersion,
163 ChannelConfig::CODEC_UNDEFINED); 163 ChannelConfig::CODEC_UNDEFINED);
164 return result; 164 return result;
165 } 165 }
166 166
167 scoped_ptr<SessionConfig> SessionConfig::ForTestWithVerbatimVideo() { 167 std::unique_ptr<SessionConfig> SessionConfig::ForTestWithVerbatimVideo() {
168 scoped_ptr<SessionConfig> result = ForTest(); 168 std::unique_ptr<SessionConfig> result = ForTest();
169 result->video_config_ = ChannelConfig(ChannelConfig::TRANSPORT_STREAM, 169 result->video_config_ = ChannelConfig(ChannelConfig::TRANSPORT_STREAM,
170 kDefaultStreamVersion, 170 kDefaultStreamVersion,
171 ChannelConfig::CODEC_VERBATIM); 171 ChannelConfig::CODEC_VERBATIM);
172 return result; 172 return result;
173 } 173 }
174 174
175 scoped_ptr<SessionConfig> SessionConfig::ForTestWithWebrtc() { 175 std::unique_ptr<SessionConfig> SessionConfig::ForTestWithWebrtc() {
176 return make_scoped_ptr(new SessionConfig(Protocol::WEBRTC)); 176 return base::WrapUnique(new SessionConfig(Protocol::WEBRTC));
177 } 177 }
178 178
179 const ChannelConfig& SessionConfig::control_config() const { 179 const ChannelConfig& SessionConfig::control_config() const {
180 DCHECK(protocol_ == Protocol::ICE); 180 DCHECK(protocol_ == Protocol::ICE);
181 return control_config_; 181 return control_config_;
182 } 182 }
183 const ChannelConfig& SessionConfig::event_config() const { 183 const ChannelConfig& SessionConfig::event_config() const {
184 DCHECK(protocol_ == Protocol::ICE); 184 DCHECK(protocol_ == Protocol::ICE);
185 return event_config_; 185 return event_config_;
186 } 186 }
(...skipping 24 matching lines...) Expand all
211 IsChannelConfigSupported(audio_configs_, config.audio_config()); 211 IsChannelConfigSupported(audio_configs_, config.audio_config());
212 212
213 case SessionConfig::Protocol::WEBRTC: 213 case SessionConfig::Protocol::WEBRTC:
214 return webrtc_supported(); 214 return webrtc_supported();
215 } 215 }
216 216
217 NOTREACHED(); 217 NOTREACHED();
218 return false; 218 return false;
219 } 219 }
220 220
221 scoped_ptr<CandidateSessionConfig> CandidateSessionConfig::Clone() const { 221 std::unique_ptr<CandidateSessionConfig> CandidateSessionConfig::Clone() const {
222 return make_scoped_ptr(new CandidateSessionConfig(*this)); 222 return base::WrapUnique(new CandidateSessionConfig(*this));
223 } 223 }
224 224
225 // static 225 // static
226 scoped_ptr<CandidateSessionConfig> CandidateSessionConfig::CreateEmpty() { 226 std::unique_ptr<CandidateSessionConfig> CandidateSessionConfig::CreateEmpty() {
227 return make_scoped_ptr(new CandidateSessionConfig()); 227 return base::WrapUnique(new CandidateSessionConfig());
228 } 228 }
229 229
230 // static 230 // static
231 scoped_ptr<CandidateSessionConfig> CandidateSessionConfig::CreateFrom( 231 std::unique_ptr<CandidateSessionConfig> CandidateSessionConfig::CreateFrom(
232 const SessionConfig& config) { 232 const SessionConfig& config) {
233 scoped_ptr<CandidateSessionConfig> result = CreateEmpty(); 233 std::unique_ptr<CandidateSessionConfig> result = CreateEmpty();
234 234
235 switch (config.protocol()) { 235 switch (config.protocol()) {
236 case SessionConfig::Protocol::WEBRTC: 236 case SessionConfig::Protocol::WEBRTC:
237 result->set_webrtc_supported(true); 237 result->set_webrtc_supported(true);
238 result->set_ice_supported(false); 238 result->set_ice_supported(false);
239 break; 239 break;
240 240
241 case SessionConfig::Protocol::ICE: 241 case SessionConfig::Protocol::ICE:
242 result->set_webrtc_supported(false); 242 result->set_webrtc_supported(false);
243 result->set_ice_supported(true); 243 result->set_ice_supported(true);
244 result->mutable_control_configs()->push_back(config.control_config()); 244 result->mutable_control_configs()->push_back(config.control_config());
245 result->mutable_event_configs()->push_back(config.event_config()); 245 result->mutable_event_configs()->push_back(config.event_config());
246 result->mutable_video_configs()->push_back(config.video_config()); 246 result->mutable_video_configs()->push_back(config.video_config());
247 result->mutable_audio_configs()->push_back(config.audio_config()); 247 result->mutable_audio_configs()->push_back(config.audio_config());
248 break; 248 break;
249 } 249 }
250 250
251 return result; 251 return result;
252 } 252 }
253 253
254 // static 254 // static
255 scoped_ptr<CandidateSessionConfig> CandidateSessionConfig::CreateDefault() { 255 std::unique_ptr<CandidateSessionConfig>
256 scoped_ptr<CandidateSessionConfig> result = CreateEmpty(); 256 CandidateSessionConfig::CreateDefault() {
257 std::unique_ptr<CandidateSessionConfig> result = CreateEmpty();
257 258
258 result->set_ice_supported(true); 259 result->set_ice_supported(true);
259 260
260 // Control channel. 261 // Control channel.
261 result->mutable_control_configs()->push_back( 262 result->mutable_control_configs()->push_back(
262 ChannelConfig(ChannelConfig::TRANSPORT_MUX_STREAM, 263 ChannelConfig(ChannelConfig::TRANSPORT_MUX_STREAM,
263 kControlStreamVersion, 264 kControlStreamVersion,
264 ChannelConfig::CODEC_UNDEFINED)); 265 ChannelConfig::CODEC_UNDEFINED));
265 266
266 // Event channel. 267 // Event channel.
(...skipping 30 matching lines...) Expand all
297 void CandidateSessionConfig::PreferTransport( 298 void CandidateSessionConfig::PreferTransport(
298 ChannelConfig::TransportType transport) { 299 ChannelConfig::TransportType transport) {
299 UpdateConfigListToPreferTransport(&control_configs_, transport); 300 UpdateConfigListToPreferTransport(&control_configs_, transport);
300 UpdateConfigListToPreferTransport(&event_configs_, transport); 301 UpdateConfigListToPreferTransport(&event_configs_, transport);
301 UpdateConfigListToPreferTransport(&video_configs_, transport); 302 UpdateConfigListToPreferTransport(&video_configs_, transport);
302 UpdateConfigListToPreferTransport(&audio_configs_, transport); 303 UpdateConfigListToPreferTransport(&audio_configs_, transport);
303 } 304 }
304 305
305 } // namespace protocol 306 } // namespace protocol
306 } // namespace remoting 307 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/session_config.h ('k') | remoting/protocol/session_config_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698