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

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

Issue 1059843002: Refactor NetLog::LogLevel --> NetLogCaptureMode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase again to fix a merge conflict 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/write_to_file_net_log_observer.h" 5 #include "net/log/write_to_file_net_log_observer.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 WriteToFileNetLogObserver::WriteToFileNetLogObserver() 20 WriteToFileNetLogObserver::WriteToFileNetLogObserver()
21 : log_level_(NetLog::LOG_STRIP_PRIVATE_DATA), added_events_(false) { 21 : capture_mode_(NetLogCaptureMode::Default()), added_events_(false) {
22 } 22 }
23 23
24 WriteToFileNetLogObserver::~WriteToFileNetLogObserver() { 24 WriteToFileNetLogObserver::~WriteToFileNetLogObserver() {
25 } 25 }
26 26
27 void WriteToFileNetLogObserver::set_log_level(net::NetLog::LogLevel log_level) { 27 void WriteToFileNetLogObserver::set_capture_mode(
28 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 WriteToFileNetLogObserver::StartObserving( 33 void WriteToFileNetLogObserver::StartObserving(
33 net::NetLog* net_log, 34 net::NetLog* net_log,
34 base::ScopedFILE file, 35 base::ScopedFILE file,
35 base::Value* constants, 36 base::Value* constants,
36 net::URLRequestContext* url_request_context) { 37 net::URLRequestContext* url_request_context) {
37 DCHECK(file.get()); 38 DCHECK(file.get());
38 file_ = file.Pass(); 39 file_ = file.Pass();
39 added_events_ = false; 40 added_events_ = false;
(...skipping 15 matching lines...) Expand all
55 56
56 // Add events for in progress requests if a context is given. 57 // Add events for in progress requests if a context is given.
57 if (url_request_context) { 58 if (url_request_context) {
58 DCHECK(url_request_context->CalledOnValidThread()); 59 DCHECK(url_request_context->CalledOnValidThread());
59 60
60 std::set<URLRequestContext*> contexts; 61 std::set<URLRequestContext*> contexts;
61 contexts.insert(url_request_context); 62 contexts.insert(url_request_context);
62 CreateNetLogEntriesForActiveObjects(contexts, this); 63 CreateNetLogEntriesForActiveObjects(contexts, this);
63 } 64 }
64 65
65 net_log->DeprecatedAddObserver(this, log_level_); 66 net_log->DeprecatedAddObserver(this, capture_mode_);
66 } 67 }
67 68
68 void WriteToFileNetLogObserver::StopObserving( 69 void WriteToFileNetLogObserver::StopObserving(
69 net::URLRequestContext* url_request_context) { 70 net::URLRequestContext* url_request_context) {
70 net_log()->DeprecatedRemoveObserver(this); 71 net_log()->DeprecatedRemoveObserver(this);
71 72
72 // End events array. 73 // End events array.
73 fprintf(file_.get(), "]"); 74 fprintf(file_.get(), "]");
74 75
75 // Write state of the URLRequestContext when logging stopped. 76 // Write state of the URLRequestContext when logging stopped.
(...skipping 16 matching lines...) Expand all
92 // so can load partial log files by just ignoring the last line. For this to 93 // so can load partial log files by just ignoring the last line. For this to
93 // work, lines cannot be pretty printed. 94 // work, lines cannot be pretty printed.
94 scoped_ptr<base::Value> value(entry.ToValue()); 95 scoped_ptr<base::Value> value(entry.ToValue());
95 std::string json; 96 std::string json;
96 base::JSONWriter::Write(value.get(), &json); 97 base::JSONWriter::Write(value.get(), &json);
97 fprintf(file_.get(), "%s%s", (added_events_ ? ",\n" : ""), json.c_str()); 98 fprintf(file_.get(), "%s%s", (added_events_ ? ",\n" : ""), json.c_str());
98 added_events_ = true; 99 added_events_ = true;
99 } 100 }
100 101
101 } // namespace net 102 } // namespace net
OLDNEW
« no previous file with comments | « net/log/write_to_file_net_log_observer.h ('k') | net/log/write_to_file_net_log_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698