OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/ios/facade/host_list_fetcher.h" | 5 #include "remoting/ios/facade/host_list_fetcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <thread> | 8 #include <thread> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 97 } |
98 | 98 |
99 const base::DictionaryValue* data = nullptr; | 99 const base::DictionaryValue* data = nullptr; |
100 if (!response->GetDictionary("data", &data)) { | 100 if (!response->GetDictionary("data", &data)) { |
101 LOG(ERROR) << "Hostlist response data is empty"; | 101 LOG(ERROR) << "Hostlist response data is empty"; |
102 return false; | 102 return false; |
103 } | 103 } |
104 | 104 |
105 const base::ListValue* hosts = nullptr; | 105 const base::ListValue* hosts = nullptr; |
106 if (!data->GetList("items", &hosts)) { | 106 if (!data->GetList("items", &hosts)) { |
107 LOG(ERROR) << "Failed to find hosts in Hostlist response data"; | 107 // This will happen if the user has no host. |
108 return false; | 108 return true; |
109 } | 109 } |
110 | 110 |
111 // Any host_info with malformed data will not be added to the hostlist. | 111 // Any host_info with malformed data will not be added to the hostlist. |
112 const base::DictionaryValue* host_dict; | 112 const base::DictionaryValue* host_dict; |
113 for (const auto& host_info : *hosts) { | 113 for (const auto& host_info : *hosts) { |
114 remoting::HostInfo host; | 114 remoting::HostInfo host; |
115 if (host_info.GetAsDictionary(&host_dict) && | 115 if (host_info.GetAsDictionary(&host_dict) && |
116 host.ParseHostInfo(*host_dict)) { | 116 host.ParseHostInfo(*host_dict)) { |
117 hostlist->push_back(host); | 117 hostlist->push_back(host); |
118 } | 118 } |
119 } | 119 } |
120 return true; | 120 return true; |
121 } | 121 } |
122 | 122 |
123 void HostListFetcher::OnURLFetchComplete(const net::URLFetcher* source) { | 123 void HostListFetcher::OnURLFetchComplete(const net::URLFetcher* source) { |
124 DCHECK(source); | 124 DCHECK(source); |
125 | 125 |
126 std::vector<HostInfo> hostlist; | 126 std::vector<HostInfo> hostlist; |
127 if (!ProcessResponse(&hostlist)) { | 127 if (!ProcessResponse(&hostlist)) { |
128 hostlist.clear(); | 128 hostlist.clear(); |
129 } | 129 } |
130 std::sort(hostlist.begin(), hostlist.end(), &compareHost); | 130 std::sort(hostlist.begin(), hostlist.end(), &compareHost); |
131 base::ResetAndReturn(&hostlist_callback_).Run(hostlist); | 131 base::ResetAndReturn(&hostlist_callback_).Run(hostlist); |
132 } | 132 } |
133 | 133 |
134 } // namespace remoting | 134 } // namespace remoting |
OLD | NEW |