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/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 <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "net/log/net_log_entry.h" |
16 #include "net/log/net_log_util.h" | 17 #include "net/log/net_log_util.h" |
17 #include "net/url_request/url_request_context.h" | 18 #include "net/url_request/url_request_context.h" |
18 | 19 |
19 namespace net { | 20 namespace net { |
20 | 21 |
21 WriteToFileNetLogObserver::WriteToFileNetLogObserver() | 22 WriteToFileNetLogObserver::WriteToFileNetLogObserver() |
22 : capture_mode_(NetLogCaptureMode::Default()), added_events_(false) { | 23 : capture_mode_(NetLogCaptureMode::Default()), added_events_(false) { |
23 } | 24 } |
24 | 25 |
25 WriteToFileNetLogObserver::~WriteToFileNetLogObserver() { | 26 WriteToFileNetLogObserver::~WriteToFileNetLogObserver() { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 std::string json; | 81 std::string json; |
81 base::JSONWriter::Write( | 82 base::JSONWriter::Write( |
82 *GetNetInfo(url_request_context, NET_INFO_ALL_SOURCES), &json); | 83 *GetNetInfo(url_request_context, NET_INFO_ALL_SOURCES), &json); |
83 fprintf(file_.get(), ",\"tabInfo\": %s\n", json.c_str()); | 84 fprintf(file_.get(), ",\"tabInfo\": %s\n", json.c_str()); |
84 } | 85 } |
85 fprintf(file_.get(), "}"); | 86 fprintf(file_.get(), "}"); |
86 | 87 |
87 file_.reset(); | 88 file_.reset(); |
88 } | 89 } |
89 | 90 |
90 void WriteToFileNetLogObserver::OnAddEntry(const NetLog::Entry& entry) { | 91 void WriteToFileNetLogObserver::OnAddEntry(const NetLogEntry& entry) { |
91 // Add a comma and newline for every event but the first. Newlines are needed | 92 // Add a comma and newline for every event but the first. Newlines are needed |
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 std::unique_ptr<base::Value> value(entry.ToValue()); | 95 std::unique_ptr<base::Value> value(entry.ToValue()); |
95 std::string json; | 96 std::string json; |
96 base::JSONWriter::Write(*value, &json); | 97 base::JSONWriter::Write(*value, &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 |
OLD | NEW |