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

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

Issue 2465303002: [cronet] make startNetLogToFile write to correct file (Closed)
Patch Set: Created 4 years, 1 month 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.cc
diff --git a/components/cronet/ios/cronet_environment.cc b/components/cronet/ios/cronet_environment.cc
index 0fef4af2e2266ab840e1b76a457f213ba763f5a6..b23b61b8b1191274fd79fb418d17e04403fad1f6 100644
--- a/components/cronet/ios/cronet_environment.cc
+++ b/components/cronet/ios/cronet_environment.cc
@@ -146,34 +146,42 @@ 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()) {
+ if (!PathService::Get(base::DIR_HOME, &full_path))
kapishnikov 2016/11/10 20:52:17 What is the value of base::DIR_HOME on iOS? Can ap
lilyhoughton 2016/11/16 16:04:10 iOS apps definitely can't write to it, per bug 616
+ 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;
+ 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));
kapishnikov 2016/11/10 20:52:17 Why do we need base::Passes here?
lilyhoughton 2016/11/16 16:04:10 Because `base::Bind` will not accept an undecorate
+
+ 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();
@@ -182,7 +190,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();
+
+ LOG(WARNING) << "Started NetLog";
kapishnikov 2016/11/10 20:52:17 We already logging a message in StartNetLog(). I t
lilyhoughton 2016/11/16 16:04:10 I wanted to include both whether or not `startNetL
kapishnikov 2016/11/18 22:17:27 If StartNetLogOnNetworkThread is called, this line
}
void CronetEnvironment::StopNetLog() {

Powered by Google App Engine
This is Rietveld 408576698