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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // | 65 // |
66 // TODO(akalin): Figure out the real resolution. | 66 // TODO(akalin): Figure out the real resolution. |
67 const int64 kTimeResolutionMs = kTicksResolutionMs; | 67 const int64 kTimeResolutionMs = kTicksResolutionMs; |
68 | 68 |
69 // Simply quits the current message loop when finished. Used to make | 69 // Simply quits the current message loop when finished. Used to make |
70 // URLFetcher synchronous. | 70 // URLFetcher synchronous. |
71 class QuitDelegate : public net::URLFetcherDelegate { | 71 class QuitDelegate : public net::URLFetcherDelegate { |
72 public: | 72 public: |
73 QuitDelegate() {} | 73 QuitDelegate() {} |
74 | 74 |
75 virtual ~QuitDelegate() {} | 75 ~QuitDelegate() override {} |
76 | 76 |
77 // net::URLFetcherDelegate implementation. | 77 // net::URLFetcherDelegate implementation. |
78 virtual void OnURLFetchComplete(const net::URLFetcher* source) override { | 78 void OnURLFetchComplete(const net::URLFetcher* source) override { |
79 base::MessageLoop::current()->Quit(); | 79 base::MessageLoop::current()->Quit(); |
80 } | 80 } |
81 | 81 |
82 virtual void OnURLFetchDownloadProgress( | 82 void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
83 const net::URLFetcher* source, | 83 int64 current, |
84 int64 current, int64 total) override { | 84 int64 total) override { |
85 NOTREACHED(); | 85 NOTREACHED(); |
86 } | 86 } |
87 | 87 |
88 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, | 88 void OnURLFetchUploadProgress(const net::URLFetcher* source, |
89 int64 current, int64 total) override { | 89 int64 current, |
| 90 int64 total) override { |
90 NOTREACHED(); | 91 NOTREACHED(); |
91 } | 92 } |
92 | 93 |
93 private: | 94 private: |
94 DISALLOW_COPY_AND_ASSIGN(QuitDelegate); | 95 DISALLOW_COPY_AND_ASSIGN(QuitDelegate); |
95 }; | 96 }; |
96 | 97 |
97 // NetLog::ThreadSafeObserver implementation that simply prints events | 98 // NetLog::ThreadSafeObserver implementation that simply prints events |
98 // to the logs. | 99 // to the logs. |
99 class PrintingLogObserver : public net::NetLog::ThreadSafeObserver { | 100 class PrintingLogObserver : public net::NetLog::ThreadSafeObserver { |
100 public: | 101 public: |
101 PrintingLogObserver() {} | 102 PrintingLogObserver() {} |
102 | 103 |
103 virtual ~PrintingLogObserver() { | 104 ~PrintingLogObserver() override { |
104 // This is guaranteed to be safe as this program is single threaded. | 105 // This is guaranteed to be safe as this program is single threaded. |
105 net_log()->RemoveThreadSafeObserver(this); | 106 net_log()->RemoveThreadSafeObserver(this); |
106 } | 107 } |
107 | 108 |
108 // NetLog::ThreadSafeObserver implementation: | 109 // NetLog::ThreadSafeObserver implementation: |
109 virtual void OnAddEntry(const net::NetLog::Entry& entry) override { | 110 void OnAddEntry(const net::NetLog::Entry& entry) override { |
110 // The log level of the entry is unknown, so just assume it maps | 111 // The log level of the entry is unknown, so just assume it maps |
111 // to VLOG(1). | 112 // to VLOG(1). |
112 if (!VLOG_IS_ON(1)) | 113 if (!VLOG_IS_ON(1)) |
113 return; | 114 return; |
114 | 115 |
115 const char* const source_type = | 116 const char* const source_type = |
116 net::NetLog::SourceTypeToString(entry.source().type); | 117 net::NetLog::SourceTypeToString(entry.source().type); |
117 const char* const event_type = | 118 const char* const event_type = |
118 net::NetLog::EventTypeToString(entry.type()); | 119 net::NetLog::EventTypeToString(entry.type()); |
119 const char* const event_phase = | 120 const char* const event_phase = |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 &skew, &skew_uncertainty); | 316 &skew, &skew_uncertainty); |
316 | 317 |
317 std::printf( | 318 std::printf( |
318 "An estimate for the local clock skew is %.2f ms with " | 319 "An estimate for the local clock skew is %.2f ms with " |
319 "uncertainty %.2f ms\n", | 320 "uncertainty %.2f ms\n", |
320 skew.InMillisecondsF(), | 321 skew.InMillisecondsF(), |
321 skew_uncertainty.InMillisecondsF()); | 322 skew_uncertainty.InMillisecondsF()); |
322 | 323 |
323 return EXIT_SUCCESS; | 324 return EXIT_SUCCESS; |
324 } | 325 } |
OLD | NEW |