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

Unified Diff: components/cronet/ios/cronet_environment.mm

Issue 2465303002: [cronet] make startNetLogToFile write to correct file (Closed)
Patch Set: Sync 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 side-by-side diff with in-line comments
Download patch
Index: components/cronet/ios/cronet_environment.mm
diff --git a/components/cronet/ios/cronet_environment.mm b/components/cronet/ios/cronet_environment.mm
index 101e1f4db64ca8b5a470571b7999ed2d96389537..02cf63ba3e69617016b00cbd979bc278f1f9a6de 100644
--- a/components/cronet/ios/cronet_environment.mm
+++ b/components/cronet/ios/cronet_environment.mm
@@ -144,34 +144,43 @@ void CronetEnvironment::Initialize() {
g_network_change_notifier = net::NetworkChangeNotifier::Create();
}
-void CronetEnvironment::StartNetLog(base::FilePath::StringType file_name,
+bool CronetEnvironment::StartNetLog(base::FilePath::StringType file_name,
bool log_bytes) {
- DCHECK(file_name.length());
- PostToNetworkThread(FROM_HERE,
- base::Bind(&CronetEnvironment::StartNetLogOnNetworkThread,
- base::Unretained(this), file_name, log_bytes));
-}
+ if (!file_name.length())
+ return false;
-void CronetEnvironment::StartNetLogOnNetworkThread(
- const base::FilePath::StringType& file_name,
- bool log_bytes) {
- DCHECK(file_name.length());
- DCHECK(net_log_);
+ base::FilePath full_path(file_name);
- if (net_log_observer_)
- return;
+ if (!full_path.IsAbsolute()) {
mef 2016/12/09 18:30:41 This seems redundant now that we get absolute path
lilyhoughton 2016/12/09 19:42:50 The only reason I left it was because I wasn't sur
+ if (!PathService::Get(base::DIR_HOME, &full_path))
+ return false;
- base::FilePath files_root;
- if (!PathService::Get(base::DIR_HOME, &files_root))
- return;
+ full_path = full_path.Append(file_name);
+ }
- base::FilePath full_path = files_root.Append(file_name);
base::ScopedFILE file(base::OpenFile(full_path, "w"));
if (!file) {
- LOG(ERROR) << "Can not start NetLog to " << full_path.value();
- return;
+ LOG(ERROR) << "Can not start NetLog to " << full_path.value() << ": "
+ << strerror(errno);
+ return false;
}
+ LOG(WARNING) << "Starting NetLog to " << full_path.value();
+ PostToNetworkThread(
+ FROM_HERE,
+ base::Bind(&CronetEnvironment::StartNetLogOnNetworkThread,
+ base::Unretained(this), base::Passed(&file), log_bytes));
+
+ return true;
+}
+
+void CronetEnvironment::StartNetLogOnNetworkThread(base::ScopedFILE file,
+ bool log_bytes) {
+ DCHECK(net_log_);
+
+ if (net_log_observer_)
+ return;
+
net::NetLogCaptureMode capture_mode =
log_bytes ? net::NetLogCaptureMode::IncludeSocketBytes()
: net::NetLogCaptureMode::Default();
@@ -180,7 +189,8 @@ void CronetEnvironment::StartNetLogOnNetworkThread(
net_log_observer_->set_capture_mode(capture_mode);
net_log_observer_->StartObserving(main_context_->net_log(), std::move(file),
nullptr, main_context_.get());
- LOG(WARNING) << "Started NetLog to " << full_path.value();
+
mef 2016/12/09 18:30:40 nit: spurious nl
lilyhoughton 2016/12/09 19:42:50 Done.
+ LOG(WARNING) << "Started NetLog";
}
void CronetEnvironment::StopNetLog() {

Powered by Google App Engine
This is Rietveld 408576698