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

Side by Side Diff: components/cronet/android/cronet_url_request_context_adapter.cc

Issue 1079163007: net_log_logger_ replaced with write_to_file_observer_ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: net_log_logger_ replaced with write_to_file_observer_ Created 5 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/android/cronet_url_request_context_adapter.h" 5 #include "components/cronet/android/cronet_url_request_context_adapter.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 base::Bind(&CronetURLRequestContextAdapter::StopNetLogOnNetworkThread, 279 base::Bind(&CronetURLRequestContextAdapter::StopNetLogOnNetworkThread,
280 base::Unretained(this))); 280 base::Unretained(this)));
281 } 281 }
282 282
283 void CronetURLRequestContextAdapter::StartNetLogToFileOnNetworkThread( 283 void CronetURLRequestContextAdapter::StartNetLogToFileOnNetworkThread(
284 const std::string& file_name) { 284 const std::string& file_name) {
285 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 285 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
286 DCHECK(is_context_initialized_); 286 DCHECK(is_context_initialized_);
287 DCHECK(context_); 287 DCHECK(context_);
288 // Do nothing if already logging to a file. 288 // Do nothing if already logging to a file.
289 if (net_log_logger_) 289 if (write_to_file_observer_)
290 return; 290 return;
291 base::FilePath file_path(file_name); 291 base::FilePath file_path(file_name);
292 base::ScopedFILE file(base::OpenFile(file_path, "w")); 292 base::ScopedFILE file(base::OpenFile(file_path, "w"));
293 if (!file) 293 if (!file)
294 return; 294 return;
295 295
296 net_log_logger_.reset(new net::WriteToFileNetLogObserver()); 296 write_to_file_observer_.reset(new net::WriteToFileNetLogObserver());
297 net_log_logger_->StartObserving(context_->net_log(), file.Pass(), nullptr, 297 write_to_file_observer_->StartObserving(context_->net_log(), file.Pass(),
298 context_.get()); 298 nullptr, context_.get());
299 } 299 }
300 300
301 void CronetURLRequestContextAdapter::StopNetLogOnNetworkThread() { 301 void CronetURLRequestContextAdapter::StopNetLogOnNetworkThread() {
302 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 302 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
303 if (net_log_logger_) { 303 if (write_to_file_observer_) {
304 net_log_logger_->StopObserving(context_.get()); 304 write_to_file_observer_->StopObserving(context_.get());
305 net_log_logger_.reset(); 305 write_to_file_observer_.reset();
306 } 306 }
307 } 307 }
308 308
309 // Creates RequestContextAdater if config is valid URLRequestContextConfig, 309 // Creates RequestContextAdater if config is valid URLRequestContextConfig,
310 // returns 0 otherwise. 310 // returns 0 otherwise.
311 static jlong CreateRequestContextAdapter(JNIEnv* env, 311 static jlong CreateRequestContextAdapter(JNIEnv* env,
312 jclass jcaller, 312 jclass jcaller,
313 jstring jconfig) { 313 jstring jconfig) {
314 std::string config_string = 314 std::string config_string =
315 base::android::ConvertJavaStringToUTF8(env, jconfig); 315 base::android::ConvertJavaStringToUTF8(env, jconfig);
316 scoped_ptr<URLRequestContextConfig> context_config( 316 scoped_ptr<URLRequestContextConfig> context_config(
317 new URLRequestContextConfig()); 317 new URLRequestContextConfig());
318 if (!context_config->LoadFromJSON(config_string)) 318 if (!context_config->LoadFromJSON(config_string))
319 return 0; 319 return 0;
320 320
321 CronetURLRequestContextAdapter* context_adapter = 321 CronetURLRequestContextAdapter* context_adapter =
322 new CronetURLRequestContextAdapter(context_config.Pass()); 322 new CronetURLRequestContextAdapter(context_config.Pass());
323 return reinterpret_cast<jlong>(context_adapter); 323 return reinterpret_cast<jlong>(context_adapter);
324 } 324 }
325 325
326 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { 326 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) {
327 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); 327 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel());
328 // MinLogLevel is global, shared by all URLRequestContexts. 328 // MinLogLevel is global, shared by all URLRequestContexts.
329 logging::SetMinLogLevel(static_cast<int>(jlog_level)); 329 logging::SetMinLogLevel(static_cast<int>(jlog_level));
330 return old_log_level; 330 return old_log_level;
331 } 331 }
332 332
333 } // namespace cronet 333 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698