• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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 NET_BASE_NET_LOG_LOGGER_H_
6 #define NET_BASE_NET_LOG_LOGGER_H_
7 
8 #include <stdio.h>
9 
10 #include "base/memory/scoped_handle.h"
11 #include "net/base/net_log.h"
12 
13 namespace base {
14 class FilePath;
15 class Value;
16 }
17 
18 namespace net {
19 
20 // NetLogLogger watches the NetLog event stream, and sends all entries to
21 // a file specified on creation.
22 //
23 // The text file will contain a single JSON object.
24 class NET_EXPORT NetLogLogger : public NetLog::ThreadSafeObserver {
25  public:
26   // Takes ownership of |file| and will write network events to it once logging
27   // starts.  |file| must be non-NULL handle and be open for writing.
28   // |constants| is a legend for decoding constant values used in the log.
29   NetLogLogger(FILE* file, const base::Value& constants);
30   virtual ~NetLogLogger();
31 
32   // Starts observing specified NetLog.  Must not already be watching a NetLog.
33   // Separate from constructor to enforce thread safety.
34   void StartObserving(NetLog* net_log);
35 
36   // Stops observing net_log().  Must already be watching.
37   void StopObserving();
38 
39   // net::NetLog::ThreadSafeObserver implementation:
40   virtual void OnAddEntry(const NetLog::Entry& entry) OVERRIDE;
41 
42   // Create a dictionary containing legend for net/ constants.  Caller takes
43   // ownership of returned value.
44   static base::DictionaryValue* GetConstants();
45 
46  private:
47   ScopedStdioHandle file_;
48 
49   // True if OnAddEntry() has been called at least once.
50   bool added_events_;
51 
52   DISALLOW_COPY_AND_ASSIGN(NetLogLogger);
53 };
54 
55 }  // namespace net
56 
57 #endif  // NET_BASE_NET_LOG_LOGGER_H_
58