| 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 #include "net/log/file_net_log_observer.h" | 5 #include "net/log/file_net_log_observer.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 } | 290 } |
| 291 file_task_runner_->DeleteSoon(FROM_HERE, file_writer_.release()); | 291 file_task_runner_->DeleteSoon(FROM_HERE, file_writer_.release()); |
| 292 } | 292 } |
| 293 | 293 |
| 294 void FileNetLogObserver::StartObserving(NetLog* net_log, | 294 void FileNetLogObserver::StartObserving(NetLog* net_log, |
| 295 NetLogCaptureMode capture_mode) { | 295 NetLogCaptureMode capture_mode) { |
| 296 net_log->DeprecatedAddObserver(this, capture_mode); | 296 net_log->DeprecatedAddObserver(this, capture_mode); |
| 297 } | 297 } |
| 298 | 298 |
| 299 void FileNetLogObserver::StopObserving(std::unique_ptr<base::Value> polled_data, | 299 void FileNetLogObserver::StopObserving(std::unique_ptr<base::Value> polled_data, |
| 300 const base::Closure& callback) { | 300 base::OnceClosure optional_callback) { |
| 301 net_log()->DeprecatedRemoveObserver(this); | 301 net_log()->DeprecatedRemoveObserver(this); |
| 302 | 302 |
| 303 file_task_runner_->PostTaskAndReply( | 303 base::OnceClosure bound_flush_then_stop = |
| 304 FROM_HERE, | |
| 305 base::Bind(&FileNetLogObserver::FileWriter::FlushThenStop, | 304 base::Bind(&FileNetLogObserver::FileWriter::FlushThenStop, |
| 306 base::Unretained(file_writer_.get()), write_queue_, | 305 base::Unretained(file_writer_.get()), write_queue_, |
| 307 base::Passed(&polled_data)), | 306 base::Passed(&polled_data)); |
| 308 callback); | 307 |
| 308 // Note that PostTaskAndReply() requires a non-null closure. |
| 309 if (!optional_callback.is_null()) { |
| 310 file_task_runner_->PostTaskAndReply(FROM_HERE, |
| 311 std::move(bound_flush_then_stop), |
| 312 std::move(optional_callback)); |
| 313 } else { |
| 314 file_task_runner_->PostTask(FROM_HERE, std::move(bound_flush_then_stop)); |
| 315 } |
| 309 } | 316 } |
| 310 | 317 |
| 311 void FileNetLogObserver::OnAddEntry(const NetLogEntry& entry) { | 318 void FileNetLogObserver::OnAddEntry(const NetLogEntry& entry) { |
| 312 std::unique_ptr<std::string> json(new std::string); | 319 std::unique_ptr<std::string> json(new std::string); |
| 313 | 320 |
| 314 // If |entry| cannot be converted to proper JSON, ignore it. | 321 // If |entry| cannot be converted to proper JSON, ignore it. |
| 315 if (!base::JSONWriter::Write(*entry.ToValue(), json.get())) | 322 if (!base::JSONWriter::Write(*entry.ToValue(), json.get())) |
| 316 return; | 323 return; |
| 317 | 324 |
| 318 size_t queue_size = write_queue_->AddEntryToQueue(std::move(json)); | 325 size_t queue_size = write_queue_->AddEntryToQueue(std::move(json)); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 void FileNetLogObserver::UnboundedFileWriter::DeleteAllFiles() { | 558 void FileNetLogObserver::UnboundedFileWriter::DeleteAllFiles() { |
| 552 DCHECK(task_runner_->RunsTasksInCurrentSequence()); | 559 DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
| 553 | 560 |
| 554 // Reset |file_| to release the file handle so base::DeleteFile can | 561 // Reset |file_| to release the file handle so base::DeleteFile can |
| 555 // safely access it. | 562 // safely access it. |
| 556 file_.reset(); | 563 file_.reset(); |
| 557 base::DeleteFile(file_path_, false); | 564 base::DeleteFile(file_path_, false); |
| 558 } | 565 } |
| 559 | 566 |
| 560 } // namespace net | 567 } // namespace net |
| OLD | NEW |