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

Unified 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 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..d1624c3de12c2bd1d1a1b5e624fe984029cabbc0 100644
--- a/components/cronet/ios/cronet_environment.mm
+++ b/components/cronet/ios/cronet_environment.mm
@@ -144,34 +144,36 @@ 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;
+
+ base::FilePath path(file_name);
+
+ base::ScopedFILE file(base::OpenFile(path, "w"));
+ if (!file) {
+ LOG(ERROR) << "Can not start NetLog to " << path.value() << ": "
+ << strerror(errno);
+ return false;
+ }
+
+ LOG(WARNING) << "Starting NetLog to " << path.value();
+ PostToNetworkThread(
+ FROM_HERE,
+ base::Bind(&CronetEnvironment::StartNetLogOnNetworkThread,
+ base::Unretained(this), base::Passed(&file), log_bytes));
+
+ return true;
}
-void CronetEnvironment::StartNetLogOnNetworkThread(
- const base::FilePath::StringType& file_name,
- bool log_bytes) {
- DCHECK(file_name.length());
+void CronetEnvironment::StartNetLogOnNetworkThread(base::ScopedFILE file,
+ bool log_bytes) {
DCHECK(net_log_);
if (net_log_observer_)
return;
- base::FilePath files_root;
- if (!PathService::Get(base::DIR_HOME, &files_root))
- return;
-
- 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;
- }
-
net::NetLogCaptureMode capture_mode =
log_bytes ? net::NetLogCaptureMode::IncludeSocketBytes()
: net::NetLogCaptureMode::Default();
@@ -180,7 +182,7 @@ 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";
}
void CronetEnvironment::StopNetLog() {

Powered by Google App Engine
This is Rietveld 408576698