OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_NET_NET_LOG_LOGGER_H_ | 5 #ifndef CHROME_BROWSER_NET_NET_LOG_LOGGER_H_ |
6 #define CHROME_BROWSER_NET_NET_LOG_LOGGER_H_ | 6 #define CHROME_BROWSER_NET_NET_LOG_LOGGER_H_ |
7 | 7 |
8 #include "base/memory/scoped_handle.h" | 8 #include "base/memory/scoped_handle.h" |
9 #include "net/base/net_log.h" | 9 #include "net/base/net_log.h" |
10 | 10 |
| 11 namespace base { |
11 class FilePath; | 12 class FilePath; |
| 13 } |
12 | 14 |
13 // NetLogLogger watches the NetLog event stream, and sends all entries to | 15 // NetLogLogger watches the NetLog event stream, and sends all entries to |
14 // VLOG(1) or a path specified on creation. This is to debug errors that | 16 // VLOG(1) or a path specified on creation. This is to debug errors that |
15 // prevent getting to the about:net-internals page. | 17 // prevent getting to the about:net-internals page. |
16 // | 18 // |
17 // When writing directly to a file rather than VLOG(1), the text file will | 19 // When writing directly to a file rather than VLOG(1), the text file will |
18 // contain a single JSON object, with an extra comma on the end and missing | 20 // contain a single JSON object, with an extra comma on the end and missing |
19 // a terminal "]}". | 21 // a terminal "]}". |
20 // | 22 // |
21 // Relies on ChromeNetLog only calling an Observer once at a time for | 23 // Relies on ChromeNetLog only calling an Observer once at a time for |
22 // thread-safety. | 24 // thread-safety. |
23 class NetLogLogger : public net::NetLog::ThreadSafeObserver { | 25 class NetLogLogger : public net::NetLog::ThreadSafeObserver { |
24 public: | 26 public: |
25 // If |log_path| is empty or file creation fails, writes to VLOG(1). | 27 // If |log_path| is empty or file creation fails, writes to VLOG(1). |
26 // Otherwise, writes to |log_path|. Uses one line per entry, for | 28 // Otherwise, writes to |log_path|. Uses one line per entry, for |
27 // easy parsing. | 29 // easy parsing. |
28 explicit NetLogLogger(const FilePath &log_path); | 30 explicit NetLogLogger(const base::FilePath &log_path); |
29 virtual ~NetLogLogger(); | 31 virtual ~NetLogLogger(); |
30 | 32 |
31 // Starts observing specified NetLog. Must not already be watching a NetLog. | 33 // Starts observing specified NetLog. Must not already be watching a NetLog. |
32 // Separate from constructor to enforce thread safety. | 34 // Separate from constructor to enforce thread safety. |
33 void StartObserving(net::NetLog* net_log); | 35 void StartObserving(net::NetLog* net_log); |
34 | 36 |
35 // Stops observing net_log(). Must already be watching. | 37 // Stops observing net_log(). Must already be watching. |
36 void StopObserving(); | 38 void StopObserving(); |
37 | 39 |
38 // net::NetLog::ThreadSafeObserver implementation: | 40 // net::NetLog::ThreadSafeObserver implementation: |
39 virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE; | 41 virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE; |
40 | 42 |
41 private: | 43 private: |
42 ScopedStdioHandle file_; | 44 ScopedStdioHandle file_; |
43 | 45 |
44 DISALLOW_COPY_AND_ASSIGN(NetLogLogger); | 46 DISALLOW_COPY_AND_ASSIGN(NetLogLogger); |
45 }; | 47 }; |
46 | 48 |
47 #endif // CHROME_BROWSER_NET_NET_LOG_LOGGER_H_ | 49 #endif // CHROME_BROWSER_NET_NET_LOG_LOGGER_H_ |
OLD | NEW |