Home | History | Annotate | Download | only in net
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_NET_NET_LOG_LOGGER_H_
      6 #define CHROME_BROWSER_NET_NET_LOG_LOGGER_H_
      7 #pragma once
      8 
      9 #include "base/memory/scoped_handle.h"
     10 #include "chrome/browser/net/chrome_net_log.h"
     11 
     12 class FilePath;
     13 
     14 // NetLogLogger watches the NetLog event stream, and sends all entries to
     15 // VLOG(1) or a path specified on creation.  This is to debug errors that
     16 // prevent getting to the about:net-internals page.
     17 //
     18 // Relies on ChromeNetLog only calling an Observer once at a time for
     19 // thread-safety.
     20 class NetLogLogger : public ChromeNetLog::ThreadSafeObserver {
     21  public:
     22   // If |log_path| is empty or file creation fails, writes to VLOG(1).
     23   // Otherwise, writes to |log_path|.  Uses one line per entry, for
     24   // easy parsing.
     25   explicit NetLogLogger(const FilePath &log_path);
     26   ~NetLogLogger();
     27 
     28   // ThreadSafeObserver implementation:
     29   virtual void OnAddEntry(net::NetLog::EventType type,
     30                           const base::TimeTicks& time,
     31                           const net::NetLog::Source& source,
     32                           net::NetLog::EventPhase phase,
     33                           net::NetLog::EventParameters* params);
     34 
     35  private:
     36   ScopedStdioHandle file_;
     37 
     38   DISALLOW_COPY_AND_ASSIGN(NetLogLogger);
     39 };
     40 
     41 #endif  // CHROME_BROWSER_NET_NET_LOG_LOGGER_H_
     42 
     43