Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1194)

Unified Diff: net/log/file_net_log_observer.cc

Issue 2698143004: Add ongoing events to net-export log when logging starts (Closed)
Patch Set: Added/improved some comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« net/log/file_net_log_observer.h ('K') | « net/log/file_net_log_observer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/log/file_net_log_observer.cc
diff --git a/net/log/file_net_log_observer.cc b/net/log/file_net_log_observer.cc
index ef2c6164889a8febb5c2af4152ba9a6b988d8e64..92d156bd7bb0032d5bba23c38463617efda1394a 100644
--- a/net/log/file_net_log_observer.cc
+++ b/net/log/file_net_log_observer.cc
@@ -217,86 +217,57 @@ class FileNetLogObserver::UnboundedFileWriter
};
FileNetLogObserver::FileNetLogObserver(
- scoped_refptr<base::SingleThreadTaskRunner> file_task_runner)
- : file_task_runner_(file_task_runner) {}
-
-FileNetLogObserver::~FileNetLogObserver() {
- if (net_log()) {
- // StopObserving was not called.
- file_task_runner_->PostTask(
- FROM_HERE, base::Bind(&FileNetLogObserver::FileWriter::DeleteAllFiles,
- base::Unretained(file_writer_)));
- net_log()->DeprecatedRemoveObserver(this);
- }
-
- file_task_runner_->DeleteSoon(FROM_HERE, file_writer_);
-}
-
-void FileNetLogObserver::StartObservingBounded(
- NetLog* net_log,
- NetLogCaptureMode capture_mode,
+ scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
const base::FilePath& directory,
- std::unique_ptr<base::Value> constants,
- URLRequestContext* url_request_context,
size_t max_total_size,
- size_t total_num_files) {
+ size_t total_num_files,
+ std::unique_ptr<base::Value> constants)
+ : file_task_runner_(file_task_runner) {
DCHECK_GT(total_num_files, 0u);
-
+ // The BoundedFileWriter uses a soft limit to write events to file that allows
+ // the size of the file to exceed the limit, but the WriteQueue uses a hard
+ // limit which the size of |WriteQueue::queue_| cannot exceed. Thus, the
+ // BoundedFileWriter may write more events to file than can be contained by
+ // the WriteQueue if they have the same size limit. The maximum size of the
+ // WriteQueue is doubled to allow |WriteQueue::queue_| to hold enough events
+ // for the BoundedFileWriter to fill all files. As long as all events have
+ // sizes <= the size of an individual event file, the discrepancy between the
+ // hard limit and the soft limit will not cause an issue.
+ // TODO(dconnol): Handle the case when the WriteQueue still doesn't
+ // contain enough events to fill all files, because of very large events
+ // relative to file size.
file_writer_ =
new BoundedFileWriter(directory, max_total_size / total_num_files,
total_num_files, file_task_runner_);
-
- // The |file_writer_| uses a soft limit to write events to file that allows
- // the size of the file to exceed the limit, but the |write_queue_| uses a
- // hard limit which the size of the |queue_| cannot exceed. Thus, the
- // |file_writer_| may write more events to file than can be contained by the
- // |write_queue_| if they have the same size limit. The maximum size of the
- // |write_queue_| is doubled to allow the |queue_| to hold enough events for
- // the |file_writer_| to fill all files. As long as all events have sizes <=
- // the size of an individual event file, the discrepancy between the hard
- // limit and the soft limit will not cause an issue.
- // TODO(dconnol): Handle the case when the |write_queue_| still doesn't
- // contain enough events to fill all files, because of very large events
- // relative to file size.
write_queue_ = new WriteQueue(max_total_size * 2);
- StartObservingHelper(net_log, capture_mode, std::move(constants),
- url_request_context);
+ InitializeFileWriter(std::move(constants));
}
-void FileNetLogObserver::StartObservingUnbounded(
- NetLog* net_log,
- NetLogCaptureMode capture_mode,
- const base::FilePath& filepath,
- std::unique_ptr<base::Value> constants,
- URLRequestContext* url_request_context) {
- file_writer_ = new UnboundedFileWriter(filepath, file_task_runner_);
-
+FileNetLogObserver::FileNetLogObserver(
+ scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
+ const base::FilePath& log_path,
+ std::unique_ptr<base::Value> constants)
+ : file_task_runner_(file_task_runner) {
+ file_writer_ = new UnboundedFileWriter(log_path, file_task_runner_);
write_queue_ = new WriteQueue(std::numeric_limits<size_t>::max());
- StartObservingHelper(net_log, capture_mode, std::move(constants),
- url_request_context);
+ InitializeFileWriter(std::move(constants));
}
-void FileNetLogObserver::StartObservingHelper(
- NetLog* net_log,
- NetLogCaptureMode capture_mode,
- std::unique_ptr<base::Value> constants,
- URLRequestContext* url_request_context) {
- if (!constants)
- constants = GetNetConstants();
- file_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&FileNetLogObserver::FileWriter::Initialize,
- base::Unretained(file_writer_), base::Passed(&constants)));
-
- if (url_request_context) {
- DCHECK(url_request_context->CalledOnValidThread());
- std::set<URLRequestContext*> contexts;
- contexts.insert(url_request_context);
- CreateNetLogEntriesForActiveObjects(contexts, this);
+FileNetLogObserver::~FileNetLogObserver() {
+ if (net_log()) {
+ // StopObserving was not called.
+ file_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&FileNetLogObserver::FileWriter::DeleteAllFiles,
+ base::Unretained(file_writer_)));
+ net_log()->DeprecatedRemoveObserver(this);
}
+ file_task_runner_->DeleteSoon(FROM_HERE, file_writer_);
+}
+void FileNetLogObserver::StartObserving(NetLog* net_log,
+ NetLogCaptureMode capture_mode) {
net_log->DeprecatedAddObserver(this, capture_mode);
}
@@ -331,6 +302,16 @@ void FileNetLogObserver::OnAddEntry(const NetLogEntry& entry) {
}
}
+void FileNetLogObserver::InitializeFileWriter(
+ std::unique_ptr<base::Value> constants) {
+ if (!constants)
+ constants = GetNetConstants();
+ file_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&FileNetLogObserver::FileWriter::Initialize,
+ base::Unretained(file_writer_), base::Passed(&constants)));
+}
+
FileNetLogObserver::WriteQueue::WriteQueue(size_t memory_max)
: memory_(0), memory_max_(memory_max) {}
« net/log/file_net_log_observer.h ('K') | « net/log/file_net_log_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698