| 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..de2035b63cdc9a2ce294af335600c3f973b14f64 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();
|
| }
|
|
|
| @@ -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 {
|
| @@ -281,8 +256,16 @@ int main(int argc, char* argv[]) {
|
| // which causes the DNS resolution to abort. It's simpler to just
|
| // not instantiate one, since only a single request is sent anyway.
|
|
|
| + // The declaration order for net_log and printing_log_observer is
|
| + // important. The destructor of PrintingLogObserver removes itself
|
| + // from net_log, so net_log must be available for entire lifetime of
|
| + // printing_log_observer.
|
| + 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(
|
|
|