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 23 matching lines...) Expand all Loading... | |
34 #include "net/base/net_errors.h" | 34 #include "net/base/net_errors.h" |
35 #include "net/base/net_log.h" | 35 #include "net/base/net_log.h" |
36 #include "net/http/http_response_headers.h" | 36 #include "net/http/http_response_headers.h" |
37 #include "net/url_request/url_fetcher.h" | 37 #include "net/url_request/url_fetcher.h" |
38 #include "net/url_request/url_fetcher_delegate.h" | 38 #include "net/url_request/url_fetcher_delegate.h" |
39 #include "net/url_request/url_request_context.h" | 39 #include "net/url_request/url_request_context.h" |
40 #include "net/url_request/url_request_context_builder.h" | 40 #include "net/url_request/url_request_context_builder.h" |
41 #include "net/url_request/url_request_context_getter.h" | 41 #include "net/url_request/url_request_context_getter.h" |
42 #include "net/url_request/url_request_status.h" | 42 #include "net/url_request/url_request_status.h" |
43 | 43 |
44 #if defined(OS_LINUX) || defined(OS_OPENBSD) | |
digit1
2012/10/19 10:32:46
Any reason to include OS_OPENBSD here? It looks li
| |
45 #include <glib-object.h> | |
46 #endif | |
47 | |
44 #if defined(OS_MACOSX) | 48 #if defined(OS_MACOSX) |
45 #include "base/mac/scoped_nsautorelease_pool.h" | 49 #include "base/mac/scoped_nsautorelease_pool.h" |
46 #elif defined(OS_LINUX) | 50 #elif defined(OS_LINUX) |
47 #include "net/proxy/proxy_config.h" | 51 #include "net/proxy/proxy_config.h" |
48 #include "net/proxy/proxy_config_service_fixed.h" | 52 #include "net/proxy/proxy_config_service_fixed.h" |
49 #endif | 53 #endif |
50 | 54 |
51 namespace { | 55 namespace { |
52 | 56 |
53 // base::TimeTicks::Now() is documented to have a resolution of | 57 // base::TimeTicks::Now() is documented to have a resolution of |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 NOTIMPLEMENTED(); | 167 NOTIMPLEMENTED(); |
164 } | 168 } |
165 | 169 |
166 private: | 170 private: |
167 uint32 next_id_; | 171 uint32 next_id_; |
168 | 172 |
169 DISALLOW_COPY_AND_ASSIGN(PrintingLog); | 173 DISALLOW_COPY_AND_ASSIGN(PrintingLog); |
170 }; | 174 }; |
171 | 175 |
172 // Builds a URLRequestContext assuming there's only a single loop. | 176 // Builds a URLRequestContext assuming there's only a single loop. |
173 scoped_ptr<net::URLRequestContext> BuildURLRequestContext() { | 177 scoped_ptr<net::URLRequestContext> BuildURLRequestContext( |
178 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner) { | |
174 net::URLRequestContextBuilder builder; | 179 net::URLRequestContextBuilder builder; |
175 #if defined(OS_LINUX) | 180 #if defined(OS_LINUX) |
176 // On Linux, use a fixed ProxyConfigService, since the default one | 181 builder.set_glib_task_runner(main_task_runner); |
177 // depends on glib. | |
178 // | |
179 // TODO(akalin): Remove this once http://crbug.com/146421 is fixed. | |
180 builder.set_proxy_config_service( | |
181 new net::ProxyConfigServiceFixed(net::ProxyConfig())); | |
182 #endif | 182 #endif |
183 scoped_ptr<net::URLRequestContext> context(builder.Build()); | 183 scoped_ptr<net::URLRequestContext> context(builder.Build()); |
184 context->set_net_log(new PrintingLog()); | 184 context->set_net_log(new PrintingLog()); |
185 return context.Pass(); | 185 return context.Pass(); |
186 } | 186 } |
187 | 187 |
188 class SingleThreadRequestContextGetter : public net::URLRequestContextGetter { | 188 class SingleThreadRequestContextGetter : public net::URLRequestContextGetter { |
189 public: | 189 public: |
190 // Since there's only a single thread, there's no need to worry | 190 // Since there's only a single thread, there's no need to worry |
191 // about when |context_| gets created. | 191 // about when |context_| gets created. |
192 explicit SingleThreadRequestContextGetter( | 192 explicit SingleThreadRequestContextGetter( |
193 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner) | 193 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner) |
194 : context_(BuildURLRequestContext()), | 194 : context_(BuildURLRequestContext(main_task_runner)), |
195 main_task_runner_(main_task_runner) {} | 195 main_task_runner_(main_task_runner) {} |
196 | 196 |
197 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE { | 197 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE { |
198 return context_.get(); | 198 return context_.get(); |
199 } | 199 } |
200 | 200 |
201 virtual scoped_refptr<base::SingleThreadTaskRunner> | 201 virtual scoped_refptr<base::SingleThreadTaskRunner> |
202 GetNetworkTaskRunner() const OVERRIDE { | 202 GetNetworkTaskRunner() const OVERRIDE { |
203 return main_task_runner_; | 203 return main_task_runner_; |
204 } | 204 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 *skew = server_now - now; | 245 *skew = server_now - now; |
246 *skew_uncertainty = server_now_uncertainty + now_uncertainty; | 246 *skew_uncertainty = server_now_uncertainty + now_uncertainty; |
247 } | 247 } |
248 | 248 |
249 } // namespace | 249 } // namespace |
250 | 250 |
251 int main(int argc, char* argv[]) { | 251 int main(int argc, char* argv[]) { |
252 #if defined(OS_MACOSX) | 252 #if defined(OS_MACOSX) |
253 base::mac::ScopedNSAutoreleasePool pool; | 253 base::mac::ScopedNSAutoreleasePool pool; |
254 #endif | 254 #endif |
255 #if defined(OS_LINUX) || defined(OS_OPENBSD) | |
256 // Needed so ProxyConfigServiceLinux can use gconf. | |
257 // Normally handled by BrowserMainLoop::InitializeToolkit(). | |
258 g_type_init(); | |
259 #endif | |
255 | 260 |
256 base::AtExitManager exit_manager; | 261 base::AtExitManager exit_manager; |
257 CommandLine::Init(argc, argv); | 262 CommandLine::Init(argc, argv); |
258 logging::InitLogging( | 263 logging::InitLogging( |
259 NULL, | 264 NULL, |
260 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, | 265 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, |
261 logging::LOCK_LOG_FILE, | 266 logging::LOCK_LOG_FILE, |
262 logging::DELETE_OLD_LOG_FILE, | 267 logging::DELETE_OLD_LOG_FILE, |
263 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); | 268 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); |
264 | 269 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 &skew, &skew_uncertainty); | 370 &skew, &skew_uncertainty); |
366 | 371 |
367 std::printf( | 372 std::printf( |
368 "An estimate for the local clock skew is %.2f ms with " | 373 "An estimate for the local clock skew is %.2f ms with " |
369 "uncertainty %.2f ms\n", | 374 "uncertainty %.2f ms\n", |
370 skew.InMillisecondsF(), | 375 skew.InMillisecondsF(), |
371 skew_uncertainty.InMillisecondsF()); | 376 skew_uncertainty.InMillisecondsF()); |
372 | 377 |
373 return EXIT_SUCCESS; | 378 return EXIT_SUCCESS; |
374 } | 379 } |
OLD | NEW |