OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 NET_LOG_FILE_NET_LOG_OBSERVER_H_ | 5 #ifndef NET_LOG_FILE_NET_LOG_OBSERVER_H_ |
6 #define NET_LOG_FILE_NET_LOG_OBSERVER_H_ | 6 #define NET_LOG_FILE_NET_LOG_OBSERVER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 // | 35 // |
36 // The user is able to specify an approximate maximum cumulative size for the | 36 // The user is able to specify an approximate maximum cumulative size for the |
37 // netlog files and the observer overwrites old events when the maximum file | 37 // netlog files and the observer overwrites old events when the maximum file |
38 // size is reached. | 38 // size is reached. |
39 // | 39 // |
40 // Unbounded mode: | 40 // Unbounded mode: |
41 // The entire JSON object is put into one file. There is no size limit to how | 41 // The entire JSON object is put into one file. There is no size limit to how |
42 // large this file can grow; all events added will be written to the file. | 42 // large this file can grow; all events added will be written to the file. |
43 // | 43 // |
44 // The consumer must call StartObserving before calling StopObserving, and must | 44 // The consumer must call StartObserving before calling StopObserving, and must |
45 // call each method exactly once in the lifetime of the observer. StartObserving | 45 // call each method exactly once in the lifetime of the observer. |
46 // and StopObserving must be called on the same thread, but there is no | |
47 // restriction on which thread is used. | |
48 class NET_EXPORT FileNetLogObserver : public NetLog::ThreadSafeObserver { | 46 class NET_EXPORT FileNetLogObserver : public NetLog::ThreadSafeObserver { |
49 public: | 47 public: |
50 // Creates a FileNetLogObserver in bounded mode. | 48 // Creates a FileNetLogObserver in bounded mode. |
51 // | 49 // |
52 // |directory| is the directory where the log files will be written to. | 50 // |directory| is the directory where the log files will be written to. |
53 // | 51 // |
54 // |max_total_size| is the approximate limit on the cumulative size of all | 52 // |max_total_size| is the approximate limit on the cumulative size of all |
55 // netlog files. | 53 // netlog files. |
56 // | 54 // |
57 // |total_num_files| sets the total number of event files that are used to | 55 // |total_num_files| sets the total number of event files that are used to |
(...skipping 25 matching lines...) Expand all Loading... |
83 void StartObserving(NetLog* net_log, NetLogCaptureMode capture_mode); | 81 void StartObserving(NetLog* net_log, NetLogCaptureMode capture_mode); |
84 | 82 |
85 // Stops observing net_log() and closes the output file(s). Must be called | 83 // Stops observing net_log() and closes the output file(s). Must be called |
86 // after StartObserving. Should be called before destruction of the | 84 // after StartObserving. Should be called before destruction of the |
87 // FileNetLogObserver and the NetLog, or the NetLog files will be deleted when | 85 // FileNetLogObserver and the NetLog, or the NetLog files will be deleted when |
88 // the observer is destroyed. | 86 // the observer is destroyed. |
89 // | 87 // |
90 // |polled_data| is an optional argument used to add additional network stack | 88 // |polled_data| is an optional argument used to add additional network stack |
91 // state to the log. | 89 // state to the log. |
92 // | 90 // |
93 // |callback| will be run on whichever thread StopObserving() was called on | 91 // If non-null, |optional_callback| will be run on whichever thread |
94 // once all file writing is complete and the netlog files can be accessed | 92 // StopObserving() was called on once all file writing is complete and the |
95 // safely. | 93 // netlog files can be accessed safely. |
96 void StopObserving(std::unique_ptr<base::Value> polled_data, | 94 void StopObserving(std::unique_ptr<base::Value> polled_data, |
97 const base::Closure& callback); | 95 base::OnceClosure optional_callback); |
98 | 96 |
99 // NetLog::ThreadSafeObserver | 97 // NetLog::ThreadSafeObserver |
100 void OnAddEntry(const NetLogEntry& entry) override; | 98 void OnAddEntry(const NetLogEntry& entry) override; |
101 | 99 |
102 private: | 100 private: |
103 class WriteQueue; | 101 class WriteQueue; |
104 class FileWriter; | 102 class FileWriter; |
105 class BoundedFileWriter; | 103 class BoundedFileWriter; |
106 class UnboundedFileWriter; | 104 class UnboundedFileWriter; |
107 | 105 |
(...skipping 17 matching lines...) Expand all Loading... |
125 // deletion is deferred until outstanding tasks on |file_task_runner_| have | 123 // deletion is deferred until outstanding tasks on |file_task_runner_| have |
126 // finished (since it is posted using base::Unretained()). | 124 // finished (since it is posted using base::Unretained()). |
127 std::unique_ptr<FileWriter> file_writer_; | 125 std::unique_ptr<FileWriter> file_writer_; |
128 | 126 |
129 DISALLOW_COPY_AND_ASSIGN(FileNetLogObserver); | 127 DISALLOW_COPY_AND_ASSIGN(FileNetLogObserver); |
130 }; | 128 }; |
131 | 129 |
132 } // namespace net | 130 } // namespace net |
133 | 131 |
134 #endif // NET_LOG_FILE_NET_LOG_OBSERVER_H_ | 132 #endif // NET_LOG_FILE_NET_LOG_OBSERVER_H_ |
OLD | NEW |