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

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

Issue 2000803003: Use std::unique_ptr for base::DictionaryValue and base::ListValue's internal store. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix various builds. Created 4 years, 6 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/http_ice_config_request.h" 5 #include "remoting/protocol/http_ice_config_request.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // the config as expired so it will refreshed for the next session. 154 // the config as expired so it will refreshed for the next session.
155 ice_config.expiration_time = base::Time::Now(); 155 ice_config.expiration_time = base::Time::Now();
156 } else { 156 } else {
157 ice_config.expiration_time = 157 ice_config.expiration_time =
158 base::Time::Now() + lifetime - 158 base::Time::Now() + lifetime -
159 base::TimeDelta::FromSeconds(kMinimumConfigLifetimeSeconds); 159 base::TimeDelta::FromSeconds(kMinimumConfigLifetimeSeconds);
160 } 160 }
161 161
162 // Parse iceServers list and store them in |ice_config|. 162 // Parse iceServers list and store them in |ice_config|.
163 bool errors_found = false; 163 bool errors_found = false;
164 for (base::Value* server : *ice_servers_list) { 164 for (const auto& server : *ice_servers_list) {
165 base::DictionaryValue* server_dict; 165 base::DictionaryValue* server_dict;
166 if (!server->GetAsDictionary(&server_dict)) { 166 if (!server->GetAsDictionary(&server_dict)) {
167 errors_found = true; 167 errors_found = true;
168 continue; 168 continue;
169 } 169 }
170 170
171 base::ListValue* urls_list = nullptr; 171 base::ListValue* urls_list = nullptr;
172 if (!server_dict->GetList("urls", &urls_list)) { 172 if (!server_dict->GetList("urls", &urls_list)) {
173 errors_found = true; 173 errors_found = true;
174 continue; 174 continue;
175 } 175 }
176 176
177 std::string username; 177 std::string username;
178 server_dict->GetString("username", &username); 178 server_dict->GetString("username", &username);
179 179
180 std::string password; 180 std::string password;
181 server_dict->GetString("credential", &password); 181 server_dict->GetString("credential", &password);
182 182
183 for (base::Value* url : *urls_list) { 183 for (const auto& url : *urls_list) {
184 std::string url_str; 184 std::string url_str;
185 if (!url->GetAsString(&url_str)) { 185 if (!url->GetAsString(&url_str)) {
186 errors_found = true; 186 errors_found = true;
187 continue; 187 continue;
188 } 188 }
189 if (!AddServerToConfig(url_str, username, password, &ice_config)) { 189 if (!AddServerToConfig(url_str, username, password, &ice_config)) {
190 LOG(ERROR) << "Invalid ICE server URL: " << url_str; 190 LOG(ERROR) << "Invalid ICE server URL: " << url_str;
191 } 191 }
192 } 192 }
193 } 193 }
194 194
195 if (errors_found) { 195 if (errors_found) {
196 LOG(ERROR) << "Received ICE config from the server that contained errors: " 196 LOG(ERROR) << "Received ICE config from the server that contained errors: "
197 << result.response_body; 197 << result.response_body;
198 } 198 }
199 199
200 // If there are no STUN or no TURN servers then mark the config as expired so 200 // If there are no STUN or no TURN servers then mark the config as expired so
201 // it will refreshed for the next session. 201 // it will refreshed for the next session.
202 if (errors_found || ice_config.stun_servers.empty() || 202 if (errors_found || ice_config.stun_servers.empty() ||
203 ice_config.turn_servers.empty()) { 203 ice_config.turn_servers.empty()) {
204 ice_config.expiration_time = base::Time::Now(); 204 ice_config.expiration_time = base::Time::Now();
205 } 205 }
206 206
207 base::ResetAndReturn(&on_ice_config_callback_).Run(ice_config); 207 base::ResetAndReturn(&on_ice_config_callback_).Run(ice_config);
208 } 208 }
209 209
210 } // namespace protocol 210 } // namespace protocol
211 } // namespace remoting 211 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698