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/bounded_file_net_log_observer.h" | 5 #include "net/log/bounded_file_net_log_observer.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 void BoundedFileNetLogObserver::OnAddEntry(const NetLogEntry& entry) { | 252 void BoundedFileNetLogObserver::OnAddEntry(const NetLogEntry& entry) { |
253 std::unique_ptr<std::string> json(new std::string); | 253 std::unique_ptr<std::string> json(new std::string); |
254 | 254 |
255 // If |entry| cannot be converted to proper JSON, ignore it. | 255 // If |entry| cannot be converted to proper JSON, ignore it. |
256 if (!base::JSONWriter::Write(*entry.ToValue(), json.get())) | 256 if (!base::JSONWriter::Write(*entry.ToValue(), json.get())) |
257 return; | 257 return; |
258 | 258 |
259 size_t queue_size = write_queue_->AddEntryToQueue(std::move(json)); | 259 size_t queue_size = write_queue_->AddEntryToQueue(std::move(json)); |
260 | 260 |
261 // If events build up in |write_queue_|, trigger the file thread to drain | 261 // If events build up in |write_queue_|, trigger the file thread to drain |
262 // the queue. | 262 // the queue. Because only 1 item is added to the queue at a time, if |
263 if (queue_size >= kNumWriteQueueEvents) { | 263 // queue_size > kNumWriteQueueEvents a task has already been posted, or will |
| 264 // be posted. |
| 265 if (queue_size == kNumWriteQueueEvents) { |
264 task_runner_->PostTask( | 266 task_runner_->PostTask( |
265 FROM_HERE, base::Bind(&BoundedFileNetLogObserver::FileWriter::Flush, | 267 FROM_HERE, base::Bind(&BoundedFileNetLogObserver::FileWriter::Flush, |
266 base::Unretained(file_writer_), write_queue_)); | 268 base::Unretained(file_writer_), write_queue_)); |
267 } | 269 } |
268 } | 270 } |
269 | 271 |
270 BoundedFileNetLogObserver::WriteQueue::WriteQueue(size_t memory_max) | 272 BoundedFileNetLogObserver::WriteQueue::WriteQueue(size_t memory_max) |
271 : memory_(0), memory_max_(memory_max) {} | 273 : memory_(0), memory_max_(memory_max) {} |
272 | 274 |
273 size_t BoundedFileNetLogObserver::WriteQueue::AddEntryToQueue( | 275 size_t BoundedFileNetLogObserver::WriteQueue::AddEntryToQueue( |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 base::DeleteFile(directory_.AppendASCII("constants.json"), false); | 398 base::DeleteFile(directory_.AppendASCII("constants.json"), false); |
397 base::DeleteFile(directory_.AppendASCII("end_netlog.json"), false); | 399 base::DeleteFile(directory_.AppendASCII("end_netlog.json"), false); |
398 for (size_t i = 0; i < total_num_files_; i++) { | 400 for (size_t i = 0; i < total_num_files_; i++) { |
399 base::DeleteFile(directory_.AppendASCII("event_file_" + | 401 base::DeleteFile(directory_.AppendASCII("event_file_" + |
400 base::SizeTToString(i) + ".json"), | 402 base::SizeTToString(i) + ".json"), |
401 false); | 403 false); |
402 } | 404 } |
403 } | 405 } |
404 | 406 |
405 } // namespace net | 407 } // namespace net |
OLD | NEW |