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

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

Issue 2465303002: [cronet] make startNetLogToFile write to correct file (Closed)
Patch Set: sync Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/cronet/ios/cronet_environment.h ('k') | components/cronet/ios/test/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cronet/ios/cronet_environment.mm
diff --git a/components/cronet/ios/cronet_environment.mm b/components/cronet/ios/cronet_environment.mm
index 6bab40ed1242f25e06d9b6d318e3b46388b007ab..65a59172b507af83ad38b88b1913b9d0abc85c5b 100644
--- a/components/cronet/ios/cronet_environment.mm
+++ b/components/cronet/ios/cronet_environment.mm
@@ -135,34 +135,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();
@@ -171,7 +173,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() {
@@ -234,17 +236,6 @@ void CronetEnvironment::Start() {
file_user_blocking_thread_->StartWithOptions(
base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
- static bool ssl_key_log_file_set = false;
- if (!ssl_key_log_file_set && !ssl_key_log_file_name_.empty()) {
- ssl_key_log_file_set = true;
- base::FilePath ssl_key_log_file;
- if (!PathService::Get(base::DIR_HOME, &ssl_key_log_file))
- return;
- net::SSLClientSocket::SetSSLKeyLogFile(
- ssl_key_log_file.Append(ssl_key_log_file_name_),
- file_thread_->task_runner());
- }
-
main_context_getter_ = new CronetURLRequestContextGetter(
this, network_io_thread_->task_runner());
base::subtle::MemoryBarrier();
@@ -261,6 +252,17 @@ void CronetEnvironment::InitializeOnNetworkThread() {
DCHECK(network_io_thread_->task_runner()->BelongsToCurrentThread());
base::FeatureList::InitializeInstance(std::string(), std::string());
+ static bool ssl_key_log_file_set = false;
+ if (!ssl_key_log_file_set && !ssl_key_log_file_name_.empty()) {
+ ssl_key_log_file_set = true;
+ base::FilePath ssl_key_log_file;
+ if (!PathService::Get(base::DIR_HOME, &ssl_key_log_file))
+ return;
+ net::SSLClientSocket::SetSSLKeyLogFile(
+ ssl_key_log_file.Append(ssl_key_log_file_name_),
+ file_thread_->task_runner());
+ }
+
if (user_agent_partial_)
user_agent_ = web::BuildUserAgentFromProduct(user_agent_);
« no previous file with comments | « components/cronet/ios/cronet_environment.h ('k') | components/cronet/ios/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698