| Index: net/base/net_log_logger.cc
|
| diff --git a/net/base/net_log_logger.cc b/net/base/net_log_logger.cc
|
| index bb0331badeff0560333a0afd8b6bb418ed858b4a..9b46ab1477d14aebbb3e21590d2b3af5b3df9811 100644
|
| --- a/net/base/net_log_logger.cc
|
| +++ b/net/base/net_log_logger.cc
|
| @@ -6,32 +6,22 @@
|
|
|
| #include <stdio.h>
|
|
|
| +#include <set>
|
| +
|
| #include "base/json/json_writer.h"
|
| #include "base/logging.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/values.h"
|
| #include "net/base/net_log_util.h"
|
| +#include "net/url_request/url_request_context.h"
|
|
|
| namespace net {
|
|
|
| -NetLogLogger::NetLogLogger(FILE* file, const base::Value& constants)
|
| - : file_(file),
|
| - log_level_(NetLog::LOG_STRIP_PRIVATE_DATA),
|
| - added_events_(false) {
|
| - DCHECK(file);
|
| -
|
| - // Write constants to the output file. This allows loading files that have
|
| - // different source and event types, as they may be added and removed
|
| - // between Chrome versions.
|
| - std::string json;
|
| - base::JSONWriter::Write(&constants, &json);
|
| - fprintf(file_.get(), "{\"constants\": %s,\n", json.c_str());
|
| - fprintf(file_.get(), "\"events\": [\n");
|
| +NetLogLogger::NetLogLogger()
|
| + : log_level_(NetLog::LOG_STRIP_PRIVATE_DATA), added_events_(false) {
|
| }
|
|
|
| NetLogLogger::~NetLogLogger() {
|
| - if (file_.get())
|
| - fprintf(file_.get(), "]}");
|
| }
|
|
|
| void NetLogLogger::set_log_level(net::NetLog::LogLevel log_level) {
|
| @@ -39,12 +29,60 @@ void NetLogLogger::set_log_level(net::NetLog::LogLevel log_level) {
|
| log_level_ = log_level;
|
| }
|
|
|
| -void NetLogLogger::StartObserving(net::NetLog* net_log) {
|
| +void NetLogLogger::StartObserving(net::NetLog* net_log,
|
| + base::ScopedFILE file,
|
| + base::Value* constants,
|
| + net::URLRequestContext* url_request_context) {
|
| + DCHECK(file.get());
|
| + file_ = file.Pass();
|
| + added_events_ = false;
|
| +
|
| + // Write constants to the output file. This allows loading files that have
|
| + // different source and event types, as they may be added and removed
|
| + // between Chrome versions.
|
| + std::string json;
|
| + if (constants) {
|
| + base::JSONWriter::Write(constants, &json);
|
| + } else {
|
| + scoped_ptr<base::DictionaryValue> scoped_constants(GetNetConstants());
|
| + base::JSONWriter::Write(scoped_constants.get(), &json);
|
| + }
|
| + fprintf(file_.get(), "{\"constants\": %s,\n", json.c_str());
|
| +
|
| + // Start events array. It's closed in StopObserving().
|
| + fprintf(file_.get(), "\"events\": [\n");
|
| +
|
| + // Add events for in progress requests if a context is given.
|
| + if (url_request_context) {
|
| + DCHECK(url_request_context->CalledOnValidThread());
|
| +
|
| + std::set<URLRequestContext*> contexts;
|
| + contexts.insert(url_request_context);
|
| + CreateNetLogEntriesForActiveObjects(contexts, this);
|
| + }
|
| +
|
| net_log->AddThreadSafeObserver(this, log_level_);
|
| }
|
|
|
| -void NetLogLogger::StopObserving() {
|
| +void NetLogLogger::StopObserving(net::URLRequestContext* url_request_context) {
|
| net_log()->RemoveThreadSafeObserver(this);
|
| +
|
| + // End events array.
|
| + fprintf(file_.get(), "]");
|
| +
|
| + // Write state of the URLRequestContext when logging stopped.
|
| + if (url_request_context) {
|
| + DCHECK(url_request_context->CalledOnValidThread());
|
| +
|
| + std::string json;
|
| + scoped_ptr<base::DictionaryValue> net_info =
|
| + GetNetInfo(url_request_context, NET_INFO_ALL_SOURCES);
|
| + base::JSONWriter::Write(net_info.get(), &json);
|
| + fprintf(file_.get(), ",\"tabInfo\": %s\n", json.c_str());
|
| + }
|
| + fprintf(file_.get(), "}");
|
| +
|
| + file_.reset();
|
| }
|
|
|
| void NetLogLogger::OnAddEntry(const net::NetLog::Entry& entry) {
|
| @@ -60,9 +98,4 @@ void NetLogLogger::OnAddEntry(const net::NetLog::Entry& entry) {
|
| added_events_ = true;
|
| }
|
|
|
| -// static
|
| -base::DictionaryValue* NetLogLogger::GetConstants() {
|
| - return GetNetConstants().release();
|
| -}
|
| -
|
| } // namespace net
|
|
|