This source file includes following definitions.
- added_events_
- set_log_level
- StartObserving
- StopObserving
- OnAddEntry
- GetConstants
#include "net/base/net_log_logger.h"
#include <stdio.h>
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
#include "net/base/address_family.h"
#include "net/base/load_states.h"
#include "net/quic/quic_protocol.h"
#include "net/quic/quic_utils.h"
namespace net {
static const int kLogFormatVersion = 1;
NetLogLogger::NetLogLogger(FILE* file, const base::Value& constants)
: file_(file), log_level_(NetLog::LOG_ALL_BUT_BYTES), added_events_(false) {
DCHECK(file);
std::string json;
base::JSONWriter::Write(&constants, &json);
fprintf(file_.get(), "{\"constants\": %s,\n", json.c_str());
fprintf(file_.get(), "\"events\": [\n");
}
NetLogLogger::~NetLogLogger() {
if (file_.get())
fprintf(file_.get(), "]}");
}
void NetLogLogger::set_log_level(net::NetLog::LogLevel log_level) {
DCHECK(!net_log());
log_level_ = log_level;
}
void NetLogLogger::StartObserving(net::NetLog* net_log) {
net_log->AddThreadSafeObserver(this, log_level_);
}
void NetLogLogger::StopObserving() {
net_log()->RemoveThreadSafeObserver(this);
}
void NetLogLogger::OnAddEntry(const net::NetLog::Entry& entry) {
scoped_ptr<base::Value> value(entry.ToValue());
std::string json;
base::JSONWriter::Write(value.get(), &json);
fprintf(file_.get(), "%s%s",
(added_events_ ? ",\n" : ""),
json.c_str());
added_events_ = true;
}
base::DictionaryValue* NetLogLogger::GetConstants() {
base::DictionaryValue* constants_dict = new base::DictionaryValue();
constants_dict->SetInteger("logFormatVersion", kLogFormatVersion);
constants_dict->Set("logEventTypes", net::NetLog::GetEventTypesAsValue());
{
base::DictionaryValue* dict = new base::DictionaryValue();
#define LOAD_FLAG(label, value) \
dict->SetInteger(# label, static_cast<int>(value));
#include "net/base/load_flags_list.h"
#undef LOAD_FLAG
constants_dict->Set("loadFlag", dict);
}
{
base::DictionaryValue* dict = new base::DictionaryValue();
#define LOAD_STATE(label) \
dict->SetInteger(# label, net::LOAD_STATE_ ## label);
#include "net/base/load_states_list.h"
#undef LOAD_STATE
constants_dict->Set("loadState", dict);
}
{
base::DictionaryValue* dict = new base::DictionaryValue();
#define NET_ERROR(label, value) \
dict->SetInteger(# label, static_cast<int>(value));
#include "net/base/net_error_list.h"
#undef NET_ERROR
constants_dict->Set("netError", dict);
}
{
base::DictionaryValue* dict = new base::DictionaryValue();
for (net::QuicErrorCode error = net::QUIC_NO_ERROR;
error < net::QUIC_LAST_ERROR;
error = static_cast<net::QuicErrorCode>(error + 1)) {
dict->SetInteger(net::QuicUtils::ErrorToString(error),
static_cast<int>(error));
}
constants_dict->Set("quicError", dict);
}
{
base::DictionaryValue* dict = new base::DictionaryValue();
for (net::QuicRstStreamErrorCode error = net::QUIC_STREAM_NO_ERROR;
error < net::QUIC_STREAM_LAST_ERROR;
error = static_cast<net::QuicRstStreamErrorCode>(error + 1)) {
dict->SetInteger(net::QuicUtils::StreamErrorToString(error),
static_cast<int>(error));
}
constants_dict->Set("quicRstStreamError", dict);
}
{
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetInteger("PHASE_BEGIN", net::NetLog::PHASE_BEGIN);
dict->SetInteger("PHASE_END", net::NetLog::PHASE_END);
dict->SetInteger("PHASE_NONE", net::NetLog::PHASE_NONE);
constants_dict->Set("logEventPhase", dict);
}
constants_dict->Set("logSourceType", net::NetLog::GetSourceTypesAsValue());
{
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetInteger("LOG_ALL", net::NetLog::LOG_ALL);
dict->SetInteger("LOG_ALL_BUT_BYTES", net::NetLog::LOG_ALL_BUT_BYTES);
dict->SetInteger("LOG_STRIP_PRIVATE_DATA",
net::NetLog::LOG_STRIP_PRIVATE_DATA);
constants_dict->Set("logLevelType", dict);
}
{
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetInteger("ADDRESS_FAMILY_UNSPECIFIED",
net::ADDRESS_FAMILY_UNSPECIFIED);
dict->SetInteger("ADDRESS_FAMILY_IPV4",
net::ADDRESS_FAMILY_IPV4);
dict->SetInteger("ADDRESS_FAMILY_IPV6",
net::ADDRESS_FAMILY_IPV6);
constants_dict->Set("addressFamily", dict);
}
{
int64 cur_time_ms = (base::Time::Now() - base::Time()).InMilliseconds();
int64 cur_time_ticks_ms =
(base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds();
int64 tick_to_time_ms = cur_time_ms - cur_time_ticks_ms;
const int64 kUnixEpochMs = 11644473600000LL;
int64 tick_to_unix_time_ms = tick_to_time_ms - kUnixEpochMs;
constants_dict->SetString("timeTickOffset",
base::Int64ToString(tick_to_unix_time_ms));
}
constants_dict->Set("clientInfo", new base::DictionaryValue());
return constants_dict;
}
}