| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/net_log_logger.h" | 5 #include "net/log/net_log_logger.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "net/log/net_log_util.h" | 15 #include "net/log/net_log_util.h" |
| 16 #include "net/url_request/url_request_context.h" | 16 #include "net/url_request/url_request_context.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 | 19 |
| 20 NetLogLogger::NetLogLogger() | 20 NetLogLogger::NetLogLogger() |
| 21 : log_level_(NetLog::LOG_STRIP_PRIVATE_DATA), added_events_(false) { | 21 : capture_mode_(NetLogCaptureMode::StripPrivateData()), |
| 22 added_events_(false) { |
| 22 } | 23 } |
| 23 | 24 |
| 24 NetLogLogger::~NetLogLogger() { | 25 NetLogLogger::~NetLogLogger() { |
| 25 } | 26 } |
| 26 | 27 |
| 27 void NetLogLogger::set_log_level(net::NetLog::LogLevel log_level) { | 28 void NetLogLogger::set_capture_mode(net::NetLogCaptureMode capture_mode) { |
| 28 DCHECK(!net_log()); | 29 DCHECK(!net_log()); |
| 29 log_level_ = log_level; | 30 capture_mode_ = capture_mode; |
| 30 } | 31 } |
| 31 | 32 |
| 32 void NetLogLogger::StartObserving(net::NetLog* net_log, | 33 void NetLogLogger::StartObserving(net::NetLog* net_log, |
| 33 base::ScopedFILE file, | 34 base::ScopedFILE file, |
| 34 base::Value* constants, | 35 base::Value* constants, |
| 35 net::URLRequestContext* url_request_context) { | 36 net::URLRequestContext* url_request_context) { |
| 36 DCHECK(file.get()); | 37 DCHECK(file.get()); |
| 37 file_ = file.Pass(); | 38 file_ = file.Pass(); |
| 38 added_events_ = false; | 39 added_events_ = false; |
| 39 | 40 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 54 | 55 |
| 55 // Add events for in progress requests if a context is given. | 56 // Add events for in progress requests if a context is given. |
| 56 if (url_request_context) { | 57 if (url_request_context) { |
| 57 DCHECK(url_request_context->CalledOnValidThread()); | 58 DCHECK(url_request_context->CalledOnValidThread()); |
| 58 | 59 |
| 59 std::set<URLRequestContext*> contexts; | 60 std::set<URLRequestContext*> contexts; |
| 60 contexts.insert(url_request_context); | 61 contexts.insert(url_request_context); |
| 61 CreateNetLogEntriesForActiveObjects(contexts, this); | 62 CreateNetLogEntriesForActiveObjects(contexts, this); |
| 62 } | 63 } |
| 63 | 64 |
| 64 net_log->DeprecatedAddObserver(this, log_level_); | 65 net_log->DeprecatedAddObserver(this, capture_mode_); |
| 65 } | 66 } |
| 66 | 67 |
| 67 void NetLogLogger::StopObserving(net::URLRequestContext* url_request_context) { | 68 void NetLogLogger::StopObserving(net::URLRequestContext* url_request_context) { |
| 68 net_log()->DeprecatedRemoveObserver(this); | 69 net_log()->DeprecatedRemoveObserver(this); |
| 69 | 70 |
| 70 // End events array. | 71 // End events array. |
| 71 fprintf(file_.get(), "]"); | 72 fprintf(file_.get(), "]"); |
| 72 | 73 |
| 73 // Write state of the URLRequestContext when logging stopped. | 74 // Write state of the URLRequestContext when logging stopped. |
| 74 if (url_request_context) { | 75 if (url_request_context) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 90 // so can load partial log files by just ignoring the last line. For this to | 91 // so can load partial log files by just ignoring the last line. For this to |
| 91 // work, lines cannot be pretty printed. | 92 // work, lines cannot be pretty printed. |
| 92 scoped_ptr<base::Value> value(entry.ToValue()); | 93 scoped_ptr<base::Value> value(entry.ToValue()); |
| 93 std::string json; | 94 std::string json; |
| 94 base::JSONWriter::Write(value.get(), &json); | 95 base::JSONWriter::Write(value.get(), &json); |
| 95 fprintf(file_.get(), "%s%s", (added_events_ ? ",\n" : ""), json.c_str()); | 96 fprintf(file_.get(), "%s%s", (added_events_ ? ",\n" : ""), json.c_str()); |
| 96 added_events_ = true; | 97 added_events_ = true; |
| 97 } | 98 } |
| 98 | 99 |
| 99 } // namespace net | 100 } // namespace net |
| OLD | NEW |