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

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

Issue 2603523002: Move net-export thread-hopping code into NetLogFileWriter and add IO polled data. (Closed)
Patch Set: Various refactors to make code cleaner Created 3 years, 11 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 <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 DCHECK(url_request_context->CalledOnValidThread()); 60 DCHECK(url_request_context->CalledOnValidThread());
61 61
62 std::set<URLRequestContext*> contexts; 62 std::set<URLRequestContext*> contexts;
63 contexts.insert(url_request_context); 63 contexts.insert(url_request_context);
64 CreateNetLogEntriesForActiveObjects(contexts, this); 64 CreateNetLogEntriesForActiveObjects(contexts, this);
65 } 65 }
66 66
67 net_log->DeprecatedAddObserver(this, capture_mode_); 67 net_log->DeprecatedAddObserver(this, capture_mode_);
68 } 68 }
69 69
70 void WriteToFileNetLogObserver::StopObserving( 70 void WriteToFileNetLogObserver::StopObserving(base::Value* polled_data) {
71 URLRequestContext* url_request_context) {
72 net_log()->DeprecatedRemoveObserver(this); 71 net_log()->DeprecatedRemoveObserver(this);
73 72
74 // End events array. 73 // End events array.
75 fprintf(file_.get(), "]"); 74 fprintf(file_.get(), "]");
76 75
77 // Write state of the URLRequestContext when logging stopped. 76 if (polled_data) {
78 if (url_request_context) {
79 DCHECK(url_request_context->CalledOnValidThread());
80
81 std::string json; 77 std::string json;
82 base::JSONWriter::Write( 78 base::JSONWriter::Write(*polled_data, &json);
83 *GetNetInfo(url_request_context, NET_INFO_ALL_SOURCES), &json); 79 fprintf(file_.get(), ",\"polledData\": %s\n", json.c_str());
84 fprintf(file_.get(), ",\"tabInfo\": %s\n", json.c_str());
85 } 80 }
86 fprintf(file_.get(), "}"); 81 fprintf(file_.get(), "}");
87 82
88 file_.reset(); 83 file_.reset();
89 } 84 }
90 85
91 void WriteToFileNetLogObserver::OnAddEntry(const NetLogEntry& entry) { 86 void WriteToFileNetLogObserver::OnAddEntry(const NetLogEntry& entry) {
92 // Add a comma and newline for every event but the first. Newlines are needed 87 // Add a comma and newline for every event but the first. Newlines are needed
93 // so can load partial log files by just ignoring the last line. For this to 88 // so can load partial log files by just ignoring the last line. For this to
94 // work, lines cannot be pretty printed. 89 // work, lines cannot be pretty printed.
95 std::unique_ptr<base::Value> value(entry.ToValue()); 90 std::unique_ptr<base::Value> value(entry.ToValue());
96 std::string json; 91 std::string json;
97 base::JSONWriter::Write(*value, &json); 92 base::JSONWriter::Write(*value, &json);
98 fprintf(file_.get(), "%s%s", (added_events_ ? ",\n" : ""), json.c_str()); 93 fprintf(file_.get(), "%s%s", (added_events_ ? ",\n" : ""), json.c_str());
99 added_events_ = true; 94 added_events_ = true;
100 } 95 }
101 96
102 } // namespace net 97 } // namespace net
OLDNEW
« components/net_log/resources/net_export.js ('K') | « net/log/write_to_file_net_log_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698