Chromium Code Reviews| Index: net/tools/get_server_time/get_server_time.cc |
| diff --git a/net/tools/get_server_time/get_server_time.cc b/net/tools/get_server_time/get_server_time.cc |
| index bbac01192d0c677bb8b9199616e6b59e9b9c4d46..bdc7b7e2f02cc82cef31255121e596ff20d2ba4e 100644 |
| --- a/net/tools/get_server_time/get_server_time.cc |
| +++ b/net/tools/get_server_time/get_server_time.cc |
| @@ -103,14 +103,18 @@ class QuitDelegate : public net::URLFetcherDelegate { |
| DISALLOW_COPY_AND_ASSIGN(QuitDelegate); |
| }; |
| -// NetLog implementation that simply prints events to the logs. |
| -class PrintingLog : public net::NetLog { |
| +// NetLog::ThreadSafeObserver implementation that simply prints events |
| +// to the logs. |
| +class PrintingLogObserver : public net::NetLog::ThreadSafeObserver { |
| public: |
| - PrintingLog() : next_id_(1) {} |
| + PrintingLogObserver() {} |
| - virtual ~PrintingLog() {} |
| + virtual ~PrintingLogObserver() { |
| + // This is guaranteed to be safe as this program is single threaded. |
| + net_log()->RemoveThreadSafeObserver(this); |
| + } |
| - // NetLog implementation: |
| + // NetLog::ThreadSafeObserver implementation: |
| virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE { |
| // The log level of the entry is unknown, so just assume it maps |
| // to VLOG(1). |
| @@ -134,43 +138,13 @@ class PrintingLog : public net::NetLog { |
| << event_type << ": " << event_phase << params_str; |
| } |
| - virtual uint32 NextID() OVERRIDE { |
| - return next_id_++; |
| - } |
| - |
| - virtual LogLevel GetLogLevel() const OVERRIDE { |
| - const int vlog_level = logging::GetVlogLevel(__FILE__); |
| - if (vlog_level <= 0) { |
| - return LOG_BASIC; |
| - } |
| - if (vlog_level == 1) { |
| - return LOG_ALL_BUT_BYTES; |
| - } |
| - return LOG_ALL; |
| - } |
| - |
| - virtual void AddThreadSafeObserver(ThreadSafeObserver* observer, |
| - LogLevel log_level) OVERRIDE { |
| - NOTIMPLEMENTED(); |
| - } |
| - |
| - virtual void SetObserverLogLevel(ThreadSafeObserver* observer, |
| - LogLevel log_level) OVERRIDE { |
| - NOTIMPLEMENTED(); |
| - } |
| - |
| - virtual void RemoveThreadSafeObserver(ThreadSafeObserver* observer) OVERRIDE { |
| - NOTIMPLEMENTED(); |
| - } |
| - |
| private: |
| - uint32 next_id_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(PrintingLog); |
| + DISALLOW_COPY_AND_ASSIGN(PrintingLogObserver); |
| }; |
| // Builds a URLRequestContext assuming there's only a single loop. |
| -scoped_ptr<net::URLRequestContext> BuildURLRequestContext() { |
| +scoped_ptr<net::URLRequestContext> |
| +BuildURLRequestContext(net::NetLog* net_log) { |
| net::URLRequestContextBuilder builder; |
| #if defined(OS_LINUX) |
| // On Linux, use a fixed ProxyConfigService, since the default one |
| @@ -181,7 +155,7 @@ scoped_ptr<net::URLRequestContext> BuildURLRequestContext() { |
| new net::ProxyConfigServiceFixed(net::ProxyConfig())); |
| #endif |
| scoped_ptr<net::URLRequestContext> context(builder.Build()); |
| - context->set_net_log(new PrintingLog()); |
| + context->set_net_log(net_log); |
| return context.Pass(); |
| } |
| @@ -190,8 +164,9 @@ class SingleThreadRequestContextGetter : public net::URLRequestContextGetter { |
| // Since there's only a single thread, there's no need to worry |
| // about when |context_| gets created. |
| explicit SingleThreadRequestContextGetter( |
|
mmenke
2013/05/30 18:18:59
nit: Explicit not needed when there is more (or l
kouhei (in TOK)
2013/05/31 06:30:03
Done.
|
| + net::NetLog* net_log, |
| const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner) |
| - : context_(BuildURLRequestContext()), |
| + : context_(BuildURLRequestContext(net_log)), |
| main_task_runner_(main_task_runner) {} |
| virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE { |
| @@ -280,9 +255,12 @@ int main(int argc, char* argv[]) { |
| // implementations always send out an OnIPAddressChanged() message, |
| // which causes the DNS resolution to abort. It's simpler to just |
| // not instantiate one, since only a single request is sent anyway. |
| - |
| + net::NetLog net_log; |
| + PrintingLogObserver printing_log_observer; |
| + net_log.AddThreadSafeObserver(&printing_log_observer, net::NetLog::LOG_ALL); |
| scoped_refptr<SingleThreadRequestContextGetter> context_getter( |
| - new SingleThreadRequestContextGetter(main_loop.message_loop_proxy())); |
| + new SingleThreadRequestContextGetter(&net_log, |
| + main_loop.message_loop_proxy())); |
| QuitDelegate delegate; |
| scoped_ptr<net::URLFetcher> fetcher( |