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

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

Issue 996163005: [Cronet] Delay StartNetLog and StopNetLog until native request context is initialized (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « no previous file | components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 } 258 }
259 259
260 scoped_refptr<base::SingleThreadTaskRunner> 260 scoped_refptr<base::SingleThreadTaskRunner>
261 CronetURLRequestContextAdapter::GetNetworkTaskRunner() const { 261 CronetURLRequestContextAdapter::GetNetworkTaskRunner() const {
262 return network_thread_->task_runner(); 262 return network_thread_->task_runner();
263 } 263 }
264 264
265 void CronetURLRequestContextAdapter::StartNetLogToFile(JNIEnv* env, 265 void CronetURLRequestContextAdapter::StartNetLogToFile(JNIEnv* env,
266 jobject jcaller, 266 jobject jcaller,
267 jstring jfile_name) { 267 jstring jfile_name) {
268 GetNetworkTaskRunner()->PostTask( 268 PostTaskToNetworkThread(
269 FROM_HERE, 269 FROM_HERE,
270 base::Bind( 270 base::Bind(
271 &CronetURLRequestContextAdapter::StartNetLogToFileOnNetworkThread, 271 &CronetURLRequestContextAdapter::StartNetLogToFileOnNetworkThread,
272 base::Unretained(this), 272 base::Unretained(this),
273 base::android::ConvertJavaStringToUTF8(env, jfile_name))); 273 base::android::ConvertJavaStringToUTF8(env, jfile_name)));
274 } 274 }
275 275
276 void CronetURLRequestContextAdapter::StopNetLog(JNIEnv* env, jobject jcaller) { 276 void CronetURLRequestContextAdapter::StopNetLog(JNIEnv* env, jobject jcaller) {
277 GetNetworkTaskRunner()->PostTask( 277 PostTaskToNetworkThread(
278 FROM_HERE, 278 FROM_HERE,
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 // Do nothing if already logging to a file. 286 // Do nothing if already logging to a file.
pauljensen 2015/03/27 13:11:13 Can we add: DCHECK(is_context_initialized_); DCHEC
xunjieli 2015/03/27 13:34:14 Done.
287 if (net_log_logger_) 287 if (net_log_logger_)
288 return; 288 return;
289 base::FilePath file_path(file_name); 289 base::FilePath file_path(file_name);
290 base::ScopedFILE file(base::OpenFile(file_path, "w")); 290 base::ScopedFILE file(base::OpenFile(file_path, "w"));
291 if (!file) 291 if (!file)
292 return; 292 return;
293 293
294 net_log_logger_.reset(new net::NetLogLogger()); 294 net_log_logger_.reset(new net::NetLogLogger());
295 net_log_logger_->StartObserving(context_->net_log(), file.Pass(), nullptr, 295 net_log_logger_->StartObserving(context_->net_log(), file.Pass(), nullptr,
296 context_.get()); 296 context_.get());
(...skipping 25 matching lines...) Expand all
322 } 322 }
323 323
324 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { 324 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) {
325 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); 325 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel());
326 // MinLogLevel is global, shared by all URLRequestContexts. 326 // MinLogLevel is global, shared by all URLRequestContexts.
327 logging::SetMinLogLevel(static_cast<int>(jlog_level)); 327 logging::SetMinLogLevel(static_cast<int>(jlog_level));
328 return old_log_level; 328 return old_log_level;
329 } 329 }
330 330
331 } // namespace cronet 331 } // namespace cronet
OLDNEW
« no previous file with comments | « no previous file | components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698