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 // This is a small utility that snarfs the server time from the | 5 // This is a small utility that snarfs the server time from the |
6 // response headers of an http/https HEAD request and compares it to | 6 // response headers of an http/https HEAD request and compares it to |
7 // the local time. | 7 // the local time. |
8 // | 8 // |
9 // TODO(akalin): Also snarf the server time from the TLS handshake, if | 9 // TODO(akalin): Also snarf the server time from the TLS handshake, if |
10 // any (http://crbug.com/146090). | 10 // any (http://crbug.com/146090). |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 QuitDelegate delegate; | 267 QuitDelegate delegate; |
268 scoped_ptr<net::URLFetcher> fetcher( | 268 scoped_ptr<net::URLFetcher> fetcher( |
269 net::URLFetcher::Create(url, net::URLFetcher::HEAD, &delegate)); | 269 net::URLFetcher::Create(url, net::URLFetcher::HEAD, &delegate)); |
270 fetcher->SetRequestContext(context_getter.get()); | 270 fetcher->SetRequestContext(context_getter.get()); |
271 | 271 |
272 const base::Time start_time = base::Time::Now(); | 272 const base::Time start_time = base::Time::Now(); |
273 const base::TimeTicks start_ticks = base::TimeTicks::Now(); | 273 const base::TimeTicks start_ticks = base::TimeTicks::Now(); |
274 | 274 |
275 fetcher->Start(); | 275 fetcher->Start(); |
276 std::printf( | 276 std::printf( |
277 "Request started at %s (ticks = %"PRId64")\n", | 277 "Request started at %s (ticks = %" PRId64 ")\n", |
278 UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(start_time)).c_str(), | 278 UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(start_time)).c_str(), |
279 start_ticks.ToInternalValue()); | 279 start_ticks.ToInternalValue()); |
280 | 280 |
281 // |delegate| quits |main_loop| when the request is done. | 281 // |delegate| quits |main_loop| when the request is done. |
282 main_loop.Run(); | 282 main_loop.Run(); |
283 | 283 |
284 const base::Time end_time = base::Time::Now(); | 284 const base::Time end_time = base::Time::Now(); |
285 const base::TimeTicks end_ticks = base::TimeTicks::Now(); | 285 const base::TimeTicks end_ticks = base::TimeTicks::Now(); |
286 | 286 |
287 std::printf( | 287 std::printf( |
288 "Request ended at %s (ticks = %"PRId64")\n", | 288 "Request ended at %s (ticks = %" PRId64 ")\n", |
289 UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(end_time)).c_str(), | 289 UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(end_time)).c_str(), |
290 end_ticks.ToInternalValue()); | 290 end_ticks.ToInternalValue()); |
291 | 291 |
292 const int64 delta_ticks_internal = | 292 const int64 delta_ticks_internal = |
293 end_ticks.ToInternalValue() - start_ticks.ToInternalValue(); | 293 end_ticks.ToInternalValue() - start_ticks.ToInternalValue(); |
294 const base::TimeDelta delta_ticks = end_ticks - start_ticks; | 294 const base::TimeDelta delta_ticks = end_ticks - start_ticks; |
295 | 295 |
296 std::printf( | 296 std::printf( |
297 "Request took %"PRId64" ticks (%.2f ms)\n", | 297 "Request took %" PRId64 " ticks (%.2f ms)\n", |
298 delta_ticks_internal, delta_ticks.InMillisecondsF()); | 298 delta_ticks_internal, delta_ticks.InMillisecondsF()); |
299 | 299 |
300 const net::URLRequestStatus status = fetcher->GetStatus(); | 300 const net::URLRequestStatus status = fetcher->GetStatus(); |
301 if (status.status() != net::URLRequestStatus::SUCCESS) { | 301 if (status.status() != net::URLRequestStatus::SUCCESS) { |
302 LOG(ERROR) << "Request failed with error code: " | 302 LOG(ERROR) << "Request failed with error code: " |
303 << net::ErrorToString(status.error()); | 303 << net::ErrorToString(status.error()); |
304 return EXIT_FAILURE; | 304 return EXIT_FAILURE; |
305 } | 305 } |
306 | 306 |
307 const net::HttpResponseHeaders* const headers = | 307 const net::HttpResponseHeaders* const headers = |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 &skew, &skew_uncertainty); | 345 &skew, &skew_uncertainty); |
346 | 346 |
347 std::printf( | 347 std::printf( |
348 "An estimate for the local clock skew is %.2f ms with " | 348 "An estimate for the local clock skew is %.2f ms with " |
349 "uncertainty %.2f ms\n", | 349 "uncertainty %.2f ms\n", |
350 skew.InMillisecondsF(), | 350 skew.InMillisecondsF(), |
351 skew_uncertainty.InMillisecondsF()); | 351 skew_uncertainty.InMillisecondsF()); |
352 | 352 |
353 return EXIT_SUCCESS; | 353 return EXIT_SUCCESS; |
354 } | 354 } |
OLD | NEW |