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

Unified Diff: net/log/file_net_log_observer.cc

Issue 2698143004: Add ongoing events to net-export log when logging starts (Closed)
Patch Set: Updated ios NetExportMessageHandler 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
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..4d6e4e1d4c4c8c9ec7aa8db7063743375f2e8434 100644
--- a/net/log/file_net_log_observer.cc
+++ b/net/log/file_net_log_observer.cc
@@ -216,87 +216,64 @@ class FileNetLogObserver::UnboundedFileWriter
DISALLOW_COPY_AND_ASSIGN(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,
+std::unique_ptr<FileNetLogObserver> FileNetLogObserver::CreateBounded(
+ 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) {
DCHECK_GT(total_num_files, 0u);
-
- 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
+ // 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.
- write_queue_ = new WriteQueue(max_total_size * 2);
+ std::unique_ptr<FileWriter> file_writer(
+ new BoundedFileWriter(directory, max_total_size / total_num_files,
+ total_num_files, file_task_runner));
+
+ scoped_refptr<WriteQueue> write_queue(new WriteQueue(max_total_size * 2));
- StartObservingHelper(net_log, capture_mode, std::move(constants),
- url_request_context);
+ return std::unique_ptr<FileNetLogObserver>(
eroman 2017/02/24 00:17:39 [optional] base::MakeUnique. This has the advanta
wangyix1 2017/02/24 00:58:08 Using MakeUnique failed to compile since the FileN
eroman 2017/02/24 01:05:46 Oh right, good point!
+ new FileNetLogObserver(file_task_runner, std::move(file_writer),
+ write_queue, std::move(constants)));
eroman 2017/02/24 00:17:39 std::move(write_queue) --- saves a refcount incre
wangyix1 2017/02/24 00:58:08 Done.
}
-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_);
+std::unique_ptr<FileNetLogObserver> FileNetLogObserver::CreateUnbounded(
+ scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
+ const base::FilePath& log_path,
+ std::unique_ptr<base::Value> constants) {
+ std::unique_ptr<FileWriter> file_writer(
+ new UnboundedFileWriter(log_path, file_task_runner));
- write_queue_ = new WriteQueue(std::numeric_limits<size_t>::max());
+ scoped_refptr<WriteQueue> write_queue(
+ new WriteQueue(std::numeric_limits<size_t>::max()));
- StartObservingHelper(net_log, capture_mode, std::move(constants),
- url_request_context);
+ return std::unique_ptr<FileNetLogObserver>(
eroman 2017/02/24 00:17:39 [optional] same thing with base::MakeUnique
wangyix1 2017/02/24 00:58:08 Using MakeUnique failed to compile since the FileN
+ new FileNetLogObserver(file_task_runner, std::move(file_writer),
+ write_queue, std::move(constants)));
eroman 2017/02/24 00:17:38 std::move(write_queue)
wangyix1 2017/02/24 00:58:08 Done.
}
-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 +308,22 @@ void FileNetLogObserver::OnAddEntry(const NetLogEntry& entry) {
}
}
+FileNetLogObserver::FileNetLogObserver(
+ scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
+ std::unique_ptr<FileWriter> file_writer,
+ scoped_refptr<WriteQueue> write_queue,
+ std::unique_ptr<base::Value> constants)
+ : file_task_runner_(file_task_runner),
eroman 2017/02/24 00:17:39 std::move()
wangyix1 2017/02/24 00:58:08 Done.
+ write_queue_(write_queue),
eroman 2017/02/24 00:17:39 std::move()
wangyix1 2017/02/24 00:58:08 Done.
+ file_writer_(file_writer.release()) {
+ 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) {}

Powered by Google App Engine
This is Rietveld 408576698