Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(346)

Side by Side Diff: net/log/net_log_logger.cc

Issue 1059843002: Refactor NetLog::LogLevel --> NetLogCaptureMode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add header for std::max Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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::Default()), added_events_(false) {
22 } 22 }
23 23
24 NetLogLogger::~NetLogLogger() { 24 NetLogLogger::~NetLogLogger() {
25 } 25 }
26 26
27 void NetLogLogger::set_log_level(net::NetLog::LogLevel log_level) { 27 void NetLogLogger::set_capture_mode(net::NetLogCaptureMode capture_mode) {
28 DCHECK(!net_log()); 28 DCHECK(!net_log());
29 log_level_ = log_level; 29 capture_mode_ = capture_mode;
30 } 30 }
31 31
32 void NetLogLogger::StartObserving(net::NetLog* net_log, 32 void NetLogLogger::StartObserving(net::NetLog* net_log,
33 base::ScopedFILE file, 33 base::ScopedFILE file,
34 base::Value* constants, 34 base::Value* constants,
35 net::URLRequestContext* url_request_context) { 35 net::URLRequestContext* url_request_context) {
36 DCHECK(file.get()); 36 DCHECK(file.get());
37 file_ = file.Pass(); 37 file_ = file.Pass();
38 added_events_ = false; 38 added_events_ = false;
39 39
(...skipping 14 matching lines...) Expand all
54 54
55 // Add events for in progress requests if a context is given. 55 // Add events for in progress requests if a context is given.
56 if (url_request_context) { 56 if (url_request_context) {
57 DCHECK(url_request_context->CalledOnValidThread()); 57 DCHECK(url_request_context->CalledOnValidThread());
58 58
59 std::set<URLRequestContext*> contexts; 59 std::set<URLRequestContext*> contexts;
60 contexts.insert(url_request_context); 60 contexts.insert(url_request_context);
61 CreateNetLogEntriesForActiveObjects(contexts, this); 61 CreateNetLogEntriesForActiveObjects(contexts, this);
62 } 62 }
63 63
64 net_log->DeprecatedAddObserver(this, log_level_); 64 net_log->DeprecatedAddObserver(this, capture_mode_);
65 } 65 }
66 66
67 void NetLogLogger::StopObserving(net::URLRequestContext* url_request_context) { 67 void NetLogLogger::StopObserving(net::URLRequestContext* url_request_context) {
68 net_log()->DeprecatedRemoveObserver(this); 68 net_log()->DeprecatedRemoveObserver(this);
69 69
70 // End events array. 70 // End events array.
71 fprintf(file_.get(), "]"); 71 fprintf(file_.get(), "]");
72 72
73 // Write state of the URLRequestContext when logging stopped. 73 // Write state of the URLRequestContext when logging stopped.
74 if (url_request_context) { 74 if (url_request_context) {
(...skipping 15 matching lines...) Expand all
90 // so can load partial log files by just ignoring the last line. For this to 90 // so can load partial log files by just ignoring the last line. For this to
91 // work, lines cannot be pretty printed. 91 // work, lines cannot be pretty printed.
92 scoped_ptr<base::Value> value(entry.ToValue()); 92 scoped_ptr<base::Value> value(entry.ToValue());
93 std::string json; 93 std::string json;
94 base::JSONWriter::Write(value.get(), &json); 94 base::JSONWriter::Write(value.get(), &json);
95 fprintf(file_.get(), "%s%s", (added_events_ ? ",\n" : ""), json.c_str()); 95 fprintf(file_.get(), "%s%s", (added_events_ ? ",\n" : ""), json.c_str());
96 added_events_ = true; 96 added_events_ = true;
97 } 97 }
98 98
99 } // namespace net 99 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698