OLD | NEW |
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 <stdio.h> | 5 #include <stdio.h> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 entry.start_time = delta; | 175 entry.start_time = delta; |
176 entry.domain_name = time_and_name[1]; | 176 entry.domain_name = time_and_name[1]; |
177 replay_log->push_back(entry); | 177 replay_log->push_back(entry); |
178 } | 178 } |
179 return !bad_parse; | 179 return !bad_parse; |
180 } | 180 } |
181 | 181 |
182 class GDig { | 182 class GDig { |
183 public: | 183 public: |
184 GDig(); | 184 GDig(); |
| 185 ~GDig(); |
185 | 186 |
186 enum Result { | 187 enum Result { |
187 RESULT_NO_RESOLVE = -3, | 188 RESULT_NO_RESOLVE = -3, |
188 RESULT_NO_CONFIG = -2, | 189 RESULT_NO_CONFIG = -2, |
189 RESULT_WRONG_USAGE = -1, | 190 RESULT_WRONG_USAGE = -1, |
190 RESULT_OK = 0, | 191 RESULT_OK = 0, |
191 RESULT_PENDING = 1, | 192 RESULT_PENDING = 1, |
192 }; | 193 }; |
193 | 194 |
194 Result Main(int argc, const char* argv[]); | 195 Result Main(int argc, const char* argv[]); |
(...skipping 17 matching lines...) Expand all Loading... |
212 base::TimeDelta timeout_; | 213 base::TimeDelta timeout_; |
213 int parallellism_; | 214 int parallellism_; |
214 ReplayLog replay_log_; | 215 ReplayLog replay_log_; |
215 unsigned replay_log_index_; | 216 unsigned replay_log_index_; |
216 base::Time start_time_; | 217 base::Time start_time_; |
217 int active_resolves_; | 218 int active_resolves_; |
218 Result result_; | 219 Result result_; |
219 | 220 |
220 base::CancelableClosure timeout_closure_; | 221 base::CancelableClosure timeout_closure_; |
221 scoped_ptr<DnsConfigService> dns_config_service_; | 222 scoped_ptr<DnsConfigService> dns_config_service_; |
222 scoped_ptr<FileNetLog> log_; | 223 scoped_ptr<FileNetLogObserver> log_observer_; |
| 224 scoped_ptr<NetLog> log_; |
223 scoped_ptr<HostResolver> resolver_; | 225 scoped_ptr<HostResolver> resolver_; |
224 }; | 226 }; |
225 | 227 |
226 GDig::GDig() | 228 GDig::GDig() |
227 : config_timeout_(base::TimeDelta::FromSeconds(5)), | 229 : config_timeout_(base::TimeDelta::FromSeconds(5)), |
228 print_config_(false), | 230 print_config_(false), |
229 print_hosts_(false), | 231 print_hosts_(false), |
230 parallellism_(6), | 232 parallellism_(6), |
231 replay_log_index_(0u), | 233 replay_log_index_(0u), |
232 active_resolves_(0) { | 234 active_resolves_(0) { |
233 } | 235 } |
234 | 236 |
| 237 GDig::~GDig() { |
| 238 if (log_) |
| 239 log_->RemoveThreadSafeObserver(log_observer_.get()); |
| 240 } |
| 241 |
235 GDig::Result GDig::Main(int argc, const char* argv[]) { | 242 GDig::Result GDig::Main(int argc, const char* argv[]) { |
236 if (!ParseCommandLine(argc, argv)) { | 243 if (!ParseCommandLine(argc, argv)) { |
237 fprintf(stderr, | 244 fprintf(stderr, |
238 "usage: %s [--net_log[=<basic|no_bytes|all>]]" | 245 "usage: %s [--net_log[=<basic|no_bytes|all>]]" |
239 " [--print_config] [--print_hosts]" | 246 " [--print_config] [--print_hosts]" |
240 " [--nameserver=<ip_address[:port]>]" | 247 " [--nameserver=<ip_address[:port]>]" |
241 " [--timeout=<milliseconds>]" | 248 " [--timeout=<milliseconds>]" |
242 " [--config_timeout=<seconds>]" | 249 " [--config_timeout=<seconds>]" |
243 " [--j=<parallel resolves>]" | 250 " [--j=<parallel resolves>]" |
244 " [--replay_file=<path>]" | 251 " [--replay_file=<path>]" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 log_levels["no_bytes"] = NetLog::LOG_ALL_BUT_BYTES; | 299 log_levels["no_bytes"] = NetLog::LOG_ALL_BUT_BYTES; |
293 log_levels["basic"] = NetLog::LOG_BASIC; | 300 log_levels["basic"] = NetLog::LOG_BASIC; |
294 | 301 |
295 if (log_levels.find(log_param) != log_levels.end()) { | 302 if (log_levels.find(log_param) != log_levels.end()) { |
296 level = log_levels[log_param]; | 303 level = log_levels[log_param]; |
297 } else { | 304 } else { |
298 fprintf(stderr, "Invalid net_log parameter\n"); | 305 fprintf(stderr, "Invalid net_log parameter\n"); |
299 return false; | 306 return false; |
300 } | 307 } |
301 } | 308 } |
302 log_.reset(new FileNetLog(stderr, level)); | 309 log_.reset(new NetLog); |
| 310 log_observer_.reset(new FileNetLogObserver(stderr)); |
| 311 log_->AddThreadSafeObserver(log_observer_.get(), level); |
303 } | 312 } |
304 | 313 |
305 print_config_ = parsed_command_line.HasSwitch("print_config"); | 314 print_config_ = parsed_command_line.HasSwitch("print_config"); |
306 print_hosts_ = parsed_command_line.HasSwitch("print_hosts"); | 315 print_hosts_ = parsed_command_line.HasSwitch("print_hosts"); |
307 | 316 |
308 if (parsed_command_line.HasSwitch("nameserver")) { | 317 if (parsed_command_line.HasSwitch("nameserver")) { |
309 std::string nameserver = | 318 std::string nameserver = |
310 parsed_command_line.GetSwitchValueASCII("nameserver"); | 319 parsed_command_line.GetSwitchValueASCII("nameserver"); |
311 if (!StringToIPEndPoint(nameserver, &nameserver_)) { | 320 if (!StringToIPEndPoint(nameserver, &nameserver_)) { |
312 fprintf(stderr, | 321 fprintf(stderr, |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 } | 500 } |
492 | 501 |
493 } // empty namespace | 502 } // empty namespace |
494 | 503 |
495 } // namespace net | 504 } // namespace net |
496 | 505 |
497 int main(int argc, const char* argv[]) { | 506 int main(int argc, const char* argv[]) { |
498 net::GDig dig; | 507 net::GDig dig; |
499 return dig.Main(argc, argv); | 508 return dig.Main(argc, argv); |
500 } | 509 } |
OLD | NEW |