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

Side by Side Diff: components/cronet/ios/cronet_environment.mm

Issue 2465303002: [cronet] make startNetLogToFile write to correct file (Closed)
Patch Set: per #15 Created 4 years 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/cronet/ios/cronet_environment.h" 5 #include "components/cronet/ios/cronet_environment.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/atomicops.h" 10 #include "base/atomicops.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 DCHECK(!base::MessageLoop::current()); 137 DCHECK(!base::MessageLoop::current());
138 DCHECK(!g_main_message_loop); 138 DCHECK(!g_main_message_loop);
139 g_main_message_loop = new base::MessageLoopForUI(); 139 g_main_message_loop = new base::MessageLoopForUI();
140 base::MessageLoopForUI::current()->Attach(); 140 base::MessageLoopForUI::current()->Attach();
141 // The network change notifier must be initialized so that registered 141 // The network change notifier must be initialized so that registered
142 // delegates will receive callbacks. 142 // delegates will receive callbacks.
143 DCHECK(!g_network_change_notifier); 143 DCHECK(!g_network_change_notifier);
144 g_network_change_notifier = net::NetworkChangeNotifier::Create(); 144 g_network_change_notifier = net::NetworkChangeNotifier::Create();
145 } 145 }
146 146
147 void CronetEnvironment::StartNetLog(base::FilePath::StringType file_name, 147 bool CronetEnvironment::StartNetLog(base::FilePath::StringType file_name,
148 bool log_bytes) { 148 bool log_bytes) {
149 DCHECK(file_name.length()); 149 if (!file_name.length())
150 PostToNetworkThread(FROM_HERE, 150 return false;
151 base::Bind(&CronetEnvironment::StartNetLogOnNetworkThread, 151
152 base::Unretained(this), file_name, log_bytes)); 152 base::FilePath path(file_name);
153
154 base::ScopedFILE file(base::OpenFile(path, "w"));
155 if (!file) {
156 LOG(ERROR) << "Can not start NetLog to " << path.value() << ": "
157 << strerror(errno);
158 return false;
159 }
160
161 LOG(WARNING) << "Starting NetLog to " << path.value();
162 PostToNetworkThread(
163 FROM_HERE,
164 base::Bind(&CronetEnvironment::StartNetLogOnNetworkThread,
165 base::Unretained(this), base::Passed(&file), log_bytes));
166
167 return true;
153 } 168 }
154 169
155 void CronetEnvironment::StartNetLogOnNetworkThread( 170 void CronetEnvironment::StartNetLogOnNetworkThread(base::ScopedFILE file,
156 const base::FilePath::StringType& file_name, 171 bool log_bytes) {
157 bool log_bytes) {
158 DCHECK(file_name.length());
159 DCHECK(net_log_); 172 DCHECK(net_log_);
160 173
161 if (net_log_observer_) 174 if (net_log_observer_)
162 return; 175 return;
163 176
164 base::FilePath files_root;
165 if (!PathService::Get(base::DIR_HOME, &files_root))
166 return;
167
168 base::FilePath full_path = files_root.Append(file_name);
169 base::ScopedFILE file(base::OpenFile(full_path, "w"));
170 if (!file) {
171 LOG(ERROR) << "Can not start NetLog to " << full_path.value();
172 return;
173 }
174
175 net::NetLogCaptureMode capture_mode = 177 net::NetLogCaptureMode capture_mode =
176 log_bytes ? net::NetLogCaptureMode::IncludeSocketBytes() 178 log_bytes ? net::NetLogCaptureMode::IncludeSocketBytes()
177 : net::NetLogCaptureMode::Default(); 179 : net::NetLogCaptureMode::Default();
178 180
179 net_log_observer_.reset(new net::WriteToFileNetLogObserver()); 181 net_log_observer_.reset(new net::WriteToFileNetLogObserver());
180 net_log_observer_->set_capture_mode(capture_mode); 182 net_log_observer_->set_capture_mode(capture_mode);
181 net_log_observer_->StartObserving(main_context_->net_log(), std::move(file), 183 net_log_observer_->StartObserving(main_context_->net_log(), std::move(file),
182 nullptr, main_context_.get()); 184 nullptr, main_context_.get());
183 LOG(WARNING) << "Started NetLog to " << full_path.value(); 185 LOG(WARNING) << "Started NetLog";
184 } 186 }
185 187
186 void CronetEnvironment::StopNetLog() { 188 void CronetEnvironment::StopNetLog() {
187 base::WaitableEvent log_stopped_event( 189 base::WaitableEvent log_stopped_event(
188 base::WaitableEvent::ResetPolicy::MANUAL, 190 base::WaitableEvent::ResetPolicy::MANUAL,
189 base::WaitableEvent::InitialState::NOT_SIGNALED); 191 base::WaitableEvent::InitialState::NOT_SIGNALED);
190 PostToNetworkThread(FROM_HERE, 192 PostToNetworkThread(FROM_HERE,
191 base::Bind(&CronetEnvironment::StopNetLogOnNetworkThread, 193 base::Bind(&CronetEnvironment::StopNetLogOnNetworkThread,
192 base::Unretained(this), &log_stopped_event)); 194 base::Unretained(this), &log_stopped_event));
193 log_stopped_event.Wait(); 195 log_stopped_event.Wait();
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 415
414 void CronetEnvironment::SetHostResolverRulesOnNetworkThread( 416 void CronetEnvironment::SetHostResolverRulesOnNetworkThread(
415 const std::string& rules, 417 const std::string& rules,
416 base::WaitableEvent* event) { 418 base::WaitableEvent* event) {
417 static_cast<net::MappedHostResolver*>(main_context_->host_resolver()) 419 static_cast<net::MappedHostResolver*>(main_context_->host_resolver())
418 ->SetRulesFromString(rules); 420 ->SetRulesFromString(rules);
419 event->Signal(); 421 event->Signal();
420 } 422 }
421 423
422 } // namespace cronet 424 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698