| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/device_event_log/device_event_log_impl.h" | 5 #include "components/device_event_log/device_event_log_impl.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <list> | 8 #include <list> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 } | 252 } |
| 253 | 253 |
| 254 DeviceEventLogImpl::~DeviceEventLogImpl() {} | 254 DeviceEventLogImpl::~DeviceEventLogImpl() {} |
| 255 | 255 |
| 256 void DeviceEventLogImpl::AddEntry(const char* file, | 256 void DeviceEventLogImpl::AddEntry(const char* file, |
| 257 int file_line, | 257 int file_line, |
| 258 LogType log_type, | 258 LogType log_type, |
| 259 LogLevel log_level, | 259 LogLevel log_level, |
| 260 const std::string& event) { | 260 const std::string& event) { |
| 261 LogEntry entry(file, file_line, log_type, log_level, event); | 261 LogEntry entry(file, file_line, log_type, log_level, event); |
| 262 if (!task_runner_->RunsTasksOnCurrentThread()) { | 262 if (!task_runner_->RunsTasksInCurrentSequence()) { |
| 263 task_runner_->PostTask(FROM_HERE, | 263 task_runner_->PostTask(FROM_HERE, |
| 264 base::Bind(&DeviceEventLogImpl::AddLogEntry, | 264 base::Bind(&DeviceEventLogImpl::AddLogEntry, |
| 265 weak_ptr_factory_.GetWeakPtr(), entry)); | 265 weak_ptr_factory_.GetWeakPtr(), entry)); |
| 266 return; | 266 return; |
| 267 } | 267 } |
| 268 AddLogEntry(entry); | 268 AddLogEntry(entry); |
| 269 } | 269 } |
| 270 | 270 |
| 271 void DeviceEventLogImpl::AddLogEntry(const LogEntry& entry) { | 271 void DeviceEventLogImpl::AddLogEntry(const LogEntry& entry) { |
| 272 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 272 DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
| 273 if (!entries_.empty()) { | 273 if (!entries_.empty()) { |
| 274 LogEntry& last = entries_.back(); | 274 LogEntry& last = entries_.back(); |
| 275 if (LogEntryMatches(last, entry)) { | 275 if (LogEntryMatches(last, entry)) { |
| 276 IncreaseLogEntryCount(entry, &last); | 276 IncreaseLogEntryCount(entry, &last); |
| 277 return; | 277 return; |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 if (entries_.size() >= max_entries_) | 280 if (entries_.size() >= max_entries_) |
| 281 RemoveEntry(); | 281 RemoveEntry(); |
| 282 entries_.push_back(entry); | 282 entries_.push_back(entry); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 300 } | 300 } |
| 301 // Too many error entries, remove the oldest entry. | 301 // Too many error entries, remove the oldest entry. |
| 302 entries_.pop_front(); | 302 entries_.pop_front(); |
| 303 } | 303 } |
| 304 | 304 |
| 305 std::string DeviceEventLogImpl::GetAsString(StringOrder order, | 305 std::string DeviceEventLogImpl::GetAsString(StringOrder order, |
| 306 const std::string& format, | 306 const std::string& format, |
| 307 const std::string& types, | 307 const std::string& types, |
| 308 LogLevel max_level, | 308 LogLevel max_level, |
| 309 size_t max_events) { | 309 size_t max_events) { |
| 310 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 310 DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
| 311 if (entries_.empty()) | 311 if (entries_.empty()) |
| 312 return "No Log Entries."; | 312 return "No Log Entries."; |
| 313 | 313 |
| 314 bool show_time, show_file, show_type, show_level, format_json; | 314 bool show_time, show_file, show_type, show_level, format_json; |
| 315 GetFormat(format, &show_time, &show_file, &show_type, &show_level, | 315 GetFormat(format, &show_time, &show_file, &show_type, &show_level, |
| 316 &format_json); | 316 &format_json); |
| 317 | 317 |
| 318 std::set<LogType> include_types, exclude_types; | 318 std::set<LogType> include_types, exclude_types; |
| 319 GetLogTypes(types, &include_types, &exclude_types); | 319 GetLogTypes(types, &include_types, &exclude_types); |
| 320 | 320 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 size_t last_slash_pos = file.find_last_of("\\/"); | 398 size_t last_slash_pos = file.find_last_of("\\/"); |
| 399 if (last_slash_pos != std::string::npos) { | 399 if (last_slash_pos != std::string::npos) { |
| 400 file.erase(0, last_slash_pos + 1); | 400 file.erase(0, last_slash_pos + 1); |
| 401 } | 401 } |
| 402 } | 402 } |
| 403 } | 403 } |
| 404 | 404 |
| 405 DeviceEventLogImpl::LogEntry::LogEntry(const LogEntry& other) = default; | 405 DeviceEventLogImpl::LogEntry::LogEntry(const LogEntry& other) = default; |
| 406 | 406 |
| 407 } // namespace device_event_log | 407 } // namespace device_event_log |
| OLD | NEW |