| 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/test/host_list_fetcher.h" | 5 #include "remoting/test/host_list_fetcher.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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 81 } |
| 82 | 82 |
| 83 const base::ListValue* hosts = nullptr; | 83 const base::ListValue* hosts = nullptr; |
| 84 if (!data->GetList("items", &hosts)) { | 84 if (!data->GetList("items", &hosts)) { |
| 85 LOG(ERROR) << "Failed to find hosts in Hostlist response data"; | 85 LOG(ERROR) << "Failed to find hosts in Hostlist response data"; |
| 86 return false; | 86 return false; |
| 87 } | 87 } |
| 88 | 88 |
| 89 // Any host_info with malformed data will not be added to the hostlist. | 89 // Any host_info with malformed data will not be added to the hostlist. |
| 90 base::DictionaryValue* host_dict; | 90 base::DictionaryValue* host_dict; |
| 91 for (base::Value* host_info : *hosts) { | 91 for (const auto& host_info : *hosts) { |
| 92 HostInfo host; | 92 HostInfo host; |
| 93 if (host_info->GetAsDictionary(&host_dict) && | 93 if (host_info->GetAsDictionary(&host_dict) && |
| 94 host.ParseHostInfo(*host_dict)) { | 94 host.ParseHostInfo(*host_dict)) { |
| 95 hostlist->push_back(host); | 95 hostlist->push_back(host); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 return true; | 98 return true; |
| 99 } | 99 } |
| 100 | 100 |
| 101 void HostListFetcher::OnURLFetchComplete( | 101 void HostListFetcher::OnURLFetchComplete( |
| 102 const net::URLFetcher* source) { | 102 const net::URLFetcher* source) { |
| 103 DCHECK(source); | 103 DCHECK(source); |
| 104 VLOG(2) << "URL Fetch Completed for: " << source->GetOriginalURL(); | 104 VLOG(2) << "URL Fetch Completed for: " << source->GetOriginalURL(); |
| 105 | 105 |
| 106 std::vector<HostInfo> hostlist; | 106 std::vector<HostInfo> hostlist; |
| 107 | 107 |
| 108 if (!ProcessResponse(&hostlist)) { | 108 if (!ProcessResponse(&hostlist)) { |
| 109 hostlist.clear(); | 109 hostlist.clear(); |
| 110 } | 110 } |
| 111 base::ResetAndReturn(&hostlist_callback_).Run(hostlist); | 111 base::ResetAndReturn(&hostlist_callback_).Run(hostlist); |
| 112 } | 112 } |
| 113 | 113 |
| 114 } // namespace test | 114 } // namespace test |
| 115 } // namespace remoting | 115 } // namespace remoting |
| OLD | NEW |