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

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

Issue 2910473005: Deprecate NonThreadSafe in net/ in favor of SequenceChecker/ThreadChecker. (Closed)
Patch Set: rebase on r476634 Created 3 years, 6 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
« no previous file with comments | « net/log/net_log_util.cc ('k') | net/proxy/dhcp_proxy_script_adapter_fetcher_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 else 50 else
51 base::JSONWriter::Write(*GetNetConstants(), &json); 51 base::JSONWriter::Write(*GetNetConstants(), &json);
52 52
53 fprintf(file_.get(), "{\"constants\": %s,\n", json.c_str()); 53 fprintf(file_.get(), "{\"constants\": %s,\n", json.c_str());
54 54
55 // Start events array. It's closed in StopObserving(). 55 // Start events array. It's closed in StopObserving().
56 fprintf(file_.get(), "\"events\": [\n"); 56 fprintf(file_.get(), "\"events\": [\n");
57 57
58 // Add events for in progress requests if a context is given. 58 // Add events for in progress requests if a context is given.
59 if (url_request_context) { 59 if (url_request_context) {
60 DCHECK(url_request_context->CalledOnValidThread()); 60 url_request_context->AssertCalledOnValidThread();
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(
71 URLRequestContext* url_request_context) { 71 URLRequestContext* url_request_context) {
72 net_log()->DeprecatedRemoveObserver(this); 72 net_log()->DeprecatedRemoveObserver(this);
73 73
74 // End events array. 74 // End events array.
75 fprintf(file_.get(), "]"); 75 fprintf(file_.get(), "]");
76 76
77 // Write state of the URLRequestContext when logging stopped. 77 // Write state of the URLRequestContext when logging stopped.
78 if (url_request_context) { 78 if (url_request_context) {
79 DCHECK(url_request_context->CalledOnValidThread()); 79 url_request_context->AssertCalledOnValidThread();
80 80
81 std::string json; 81 std::string json;
82 base::JSONWriter::Write( 82 base::JSONWriter::Write(
83 *GetNetInfo(url_request_context, NET_INFO_ALL_SOURCES), &json); 83 *GetNetInfo(url_request_context, NET_INFO_ALL_SOURCES), &json);
84 fprintf(file_.get(), ",\"tabInfo\": %s\n", json.c_str()); 84 fprintf(file_.get(), ",\"tabInfo\": %s\n", json.c_str());
85 } 85 }
86 fprintf(file_.get(), "}"); 86 fprintf(file_.get(), "}");
87 87
88 file_.reset(); 88 file_.reset();
89 } 89 }
90 90
91 void WriteToFileNetLogObserver::OnAddEntry(const NetLogEntry& entry) { 91 void WriteToFileNetLogObserver::OnAddEntry(const NetLogEntry& entry) {
92 // 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
93 // 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
94 // work, lines cannot be pretty printed. 94 // work, lines cannot be pretty printed.
95 std::unique_ptr<base::Value> value(entry.ToValue()); 95 std::unique_ptr<base::Value> value(entry.ToValue());
96 std::string json; 96 std::string json;
97 base::JSONWriter::Write(*value, &json); 97 base::JSONWriter::Write(*value, &json);
98 fprintf(file_.get(), "%s%s", (added_events_ ? ",\n" : ""), json.c_str()); 98 fprintf(file_.get(), "%s%s", (added_events_ ? ",\n" : ""), json.c_str());
99 added_events_ = true; 99 added_events_ = true;
100 } 100 }
101 101
102 } // namespace net 102 } // namespace net
OLDNEW
« no previous file with comments | « net/log/net_log_util.cc ('k') | net/proxy/dhcp_proxy_script_adapter_fetcher_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698