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..eb6cb191d42a7993810c2e3f3a89254634e845f2 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); |
mmenke
2013/06/03 14:27:09
Hmm... This was leaked before?
kouhei (in TOK)
2013/06/04 15:41:44
I think so.
|
return context.Pass(); |
} |
@@ -189,9 +163,10 @@ class SingleThreadRequestContextGetter : public net::URLRequestContextGetter { |
public: |
// Since there's only a single thread, there's no need to worry |
// about when |context_| gets created. |
- explicit SingleThreadRequestContextGetter( |
+ SingleThreadRequestContextGetter( |
+ 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( |