#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/device_event_log/device_event_log_impl.h"
#include <cmath>
#include <list>
#include <set>
#include <string_view>
#include "base/containers/adapters.h"
#include "base/functional/bind.h"
#include "base/i18n/time_formatting.h"
#include "base/json/json_string_value_serializer.h"
#include "base/json/json_writer.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/process/process_handle.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/values.h"
#include "build/build_config.h"
namespace device_event_log {
namespace {
const char* const kLogLevelName[] = …;
const char kLogTypeNetworkDesc[] = …;
const char kLogTypePowerDesc[] = …;
const char kLogTypeLoginDesc[] = …;
const char kLogTypeBluetoothDesc[] = …;
const char kLogTypeUsbDesc[] = …;
const char kLogTypeHidDesc[] = …;
const char kLogTypeMemoryDesc[] = …;
const char kLogTypePrinterDesc[] = …;
const char kLogTypeFidoDesc[] = …;
const char kLogTypeSerialDesc[] = …;
const char kLogTypeCameraDesc[] = …;
const char kLogTypeGeolocationDesc[] = …;
const char kLogTypeExtensionsDesc[] = …;
const char kLogTypeDisplayDesc[] = …;
const char kLogTypeFirmwareDesc[] = …;
enum class ShowTime { … };
std::string GetLogTypeString(LogType type) { … }
LogType GetLogTypeFromString(std::string_view desc) { … }
std::string DateAndTimeWithMicroseconds(const base::Time& time) { … }
std::string TimeWithSeconds(const base::Time& time) { … }
std::string TimeWithMillieconds(const base::Time& time) { … }
#if BUILDFLAG(IS_POSIX)
std::string UnixTime(const base::Time& time) { … }
#endif
std::string LogEntryToString(const DeviceEventLogImpl::LogEntry& log_entry,
ShowTime show_time,
bool show_file,
bool show_type,
bool show_level) { … }
base::Value::Dict LogEntryToDictionary(
const DeviceEventLogImpl::LogEntry& log_entry) { … }
std::string LogEntryAsJSON(const DeviceEventLogImpl::LogEntry& log_entry) { … }
void SendLogEntryToVLogOrErrorLog(
const DeviceEventLogImpl::LogEntry& log_entry) { … }
bool LogEntryMatches(const DeviceEventLogImpl::LogEntry& first,
const DeviceEventLogImpl::LogEntry& second) { … }
bool LogEntryMatchesTypes(const DeviceEventLogImpl::LogEntry& entry,
const std::set<LogType>& include_types,
const std::set<LogType>& exclude_types) { … }
void GetFormat(const std::string& format_string,
ShowTime* show_time,
bool* show_file,
bool* show_type,
bool* show_level,
bool* format_json) { … }
void GetLogTypes(const std::string& types,
std::set<LogType>* include_types,
std::set<LogType>* exclude_types) { … }
void IncreaseLogEntryCount(const DeviceEventLogImpl::LogEntry& new_entry,
DeviceEventLogImpl::LogEntry* cur_entry) { … }
}
void DeviceEventLogImpl::SendToVLogOrErrorLog(const char* file,
int file_line,
LogType log_type,
LogLevel log_level,
const std::string& event) { … }
DeviceEventLogImpl::DeviceEventLogImpl(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
size_t max_entries)
: … { … }
DeviceEventLogImpl::~DeviceEventLogImpl() { … }
void DeviceEventLogImpl::AddEntry(const char* file,
int file_line,
LogType log_type,
LogLevel log_level,
const std::string& event) { … }
void DeviceEventLogImpl::AddEntryWithTimestampForTesting(
const char* file,
int file_line,
LogType log_type,
LogLevel log_level,
const std::string& event,
base::Time time) { … }
void DeviceEventLogImpl::AddLogEntry(const LogEntry& entry) { … }
void DeviceEventLogImpl::RemoveEntry() { … }
std::string DeviceEventLogImpl::GetAsString(StringOrder order,
const std::string& format,
const std::string& types,
LogLevel max_level,
size_t max_events) { … }
void DeviceEventLogImpl::ClearAll() { … }
void DeviceEventLogImpl::Clear(const base::Time& begin, const base::Time& end) { … }
int DeviceEventLogImpl::GetCountByLevelForTesting(LogLevel level) { … }
DeviceEventLogImpl::LogEntry::LogEntry(const char* filedesc,
int file_line,
LogType log_type,
LogLevel log_level,
const std::string& event)
: … { … }
DeviceEventLogImpl::LogEntry::LogEntry(const char* filedesc,
int file_line,
LogType log_type,
LogLevel log_level,
const std::string& event,
base::Time time_for_testing)
: … { … }
DeviceEventLogImpl::LogEntry::LogEntry(const LogEntry& other) = default;
}