Commit f3b1c76f authored by mef@chromium.org's avatar mef@chromium.org

Fix Cronet mapping of Android log level into Chrome LogSeverity.

See VLOG(1) and VLOG(2) logging:
TEST=adb shell setprop log.tag.ChromiumNetwork VERBOSE

See VLOG(1) logging:
TEST=adb shell setprop log.tag.ChromiumNetwork DEBUG

See NO (only FATAL) logging:
TEST=adb shell setprop log.tag.ChromiumNetwork NONE

BUG=400956

Review URL: https://codereview.chromium.org/447653002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288088 0039d316-1c4b-4281-b951-d872f2087c98
parent 097a51d5
...@@ -17,9 +17,9 @@ import org.chromium.base.JNINamespace; ...@@ -17,9 +17,9 @@ import org.chromium.base.JNINamespace;
*/ */
@JNINamespace("cronet") @JNINamespace("cronet")
public class UrlRequestContext { public class UrlRequestContext {
private static final int LOG_NONE = 0; private static final int LOG_NONE = 3; // LOG(FATAL), no VLOG.
private static final int LOG_DEBUG = 1; private static final int LOG_DEBUG = -1; // LOG(FATAL...INFO), VLOG(1)
private static final int LOG_VERBOSE = 2; private static final int LOG_VERBOSE = -2; // LOG(FATAL...INFO), VLOG(2)
private static final String LOG_TAG = "ChromiumNetwork"; private static final String LOG_TAG = "ChromiumNetwork";
/** /**
......
...@@ -109,8 +109,7 @@ static jlong CreateRequestPeer(JNIEnv* env, ...@@ -109,8 +109,7 @@ static jlong CreateRequestPeer(JNIEnv* env,
const char* url_utf8 = env->GetStringUTFChars(url_string, NULL); const char* url_utf8 = env->GetStringUTFChars(url_string, NULL);
DVLOG(context->logging_level()) VLOG(1) << "New chromium network request. URL:" << url_utf8;
<< "New chromium network request. URL:" << url_utf8;
GURL url(url_utf8); GURL url(url_utf8);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/metrics/statistics_recorder.h" #include "base/metrics/statistics_recorder.h"
#include "base/values.h" #include "base/values.h"
...@@ -86,13 +87,13 @@ static jlong CreateRequestContextPeer(JNIEnv* env, ...@@ -86,13 +87,13 @@ static jlong CreateRequestContextPeer(JNIEnv* env,
base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context);
base::android::InitApplicationContext(env, scoped_context); base::android::InitApplicationContext(env, scoped_context);
int logging_level = log_level; // TODO(mef): MinLogLevel is global, shared by all URLRequestContexts.
// Revisit this if each URLRequestContext would need an individual log level.
logging::SetMinLogLevel(static_cast<int>(log_level));
// TODO(dplotnikov): set application context. // TODO(dplotnikov): set application context.
URLRequestContextPeer* peer = new URLRequestContextPeer( URLRequestContextPeer* peer = new URLRequestContextPeer(
new JniURLRequestContextPeerDelegate(env, object), new JniURLRequestContextPeerDelegate(env, object), user_agent_string);
user_agent_string,
logging_level);
peer->AddRef(); // Hold onto this ref-counted object. peer->AddRef(); // Hold onto this ref-counted object.
peer->Initialize(context_config.Pass()); peer->Initialize(context_config.Pass());
return reinterpret_cast<jlong>(peer); return reinterpret_cast<jlong>(peer);
......
...@@ -114,11 +114,9 @@ namespace cronet { ...@@ -114,11 +114,9 @@ namespace cronet {
URLRequestContextPeer::URLRequestContextPeer( URLRequestContextPeer::URLRequestContextPeer(
URLRequestContextPeerDelegate* delegate, URLRequestContextPeerDelegate* delegate,
std::string user_agent, std::string user_agent) {
int logging_level) {
delegate_ = delegate; delegate_ = delegate;
user_agent_ = user_agent; user_agent_ = user_agent;
logging_level_ = logging_level;
} }
void URLRequestContextPeer::Initialize( void URLRequestContextPeer::Initialize(
...@@ -147,7 +145,7 @@ void URLRequestContextPeer::InitializeURLRequestContext( ...@@ -147,7 +145,7 @@ void URLRequestContextPeer::InitializeURLRequestContext(
context_.reset(context_builder.Build()); context_.reset(context_builder.Build());
if (VLOG_IS_ON(2)) { if (VLOG_IS_ON(2)) {
net_log_observer_.reset(new NetLogObserver(logging_level_)); net_log_observer_.reset(new NetLogObserver());
context_->net_log()->AddThreadSafeObserver(net_log_observer_.get(), context_->net_log()->AddThreadSafeObserver(net_log_observer_.get(),
net::NetLog::LOG_ALL_BUT_BYTES); net::NetLog::LOG_ALL_BUT_BYTES);
} }
...@@ -203,11 +201,9 @@ void URLRequestContextPeer::StopNetLog() { ...@@ -203,11 +201,9 @@ void URLRequestContextPeer::StopNetLog() {
} }
void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) {
if (VLOG_IS_ON(2)) { VLOG(2) << "Net log entry: type=" << entry.type()
VLOG(2) << "Net log entry: type=" << entry.type() << ", source=" << entry.source().type
<< ", source=" << entry.source().type << ", phase=" << entry.phase();
<< ", phase=" << entry.phase();
}
} }
} // namespace cronet } // namespace cronet
...@@ -28,15 +28,13 @@ struct URLRequestContextConfig; ...@@ -28,15 +28,13 @@ struct URLRequestContextConfig;
// Implementation of the Chromium NetLog observer interface. // Implementation of the Chromium NetLog observer interface.
class NetLogObserver : public net::NetLog::ThreadSafeObserver { class NetLogObserver : public net::NetLog::ThreadSafeObserver {
public: public:
explicit NetLogObserver(int log_level) { log_level_ = log_level; } explicit NetLogObserver() {}
virtual ~NetLogObserver() {} virtual ~NetLogObserver() {}
virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE; virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE;
private: private:
int log_level_;
DISALLOW_COPY_AND_ASSIGN(NetLogObserver); DISALLOW_COPY_AND_ASSIGN(NetLogObserver);
}; };
...@@ -55,14 +53,11 @@ class URLRequestContextPeer : public net::URLRequestContextGetter { ...@@ -55,14 +53,11 @@ class URLRequestContextPeer : public net::URLRequestContextGetter {
}; };
URLRequestContextPeer(URLRequestContextPeerDelegate* delegate, URLRequestContextPeer(URLRequestContextPeerDelegate* delegate,
std::string user_agent, std::string user_agent);
int log_level);
void Initialize(scoped_ptr<URLRequestContextConfig> config); void Initialize(scoped_ptr<URLRequestContextConfig> config);
const std::string& GetUserAgent(const GURL& url) const; const std::string& GetUserAgent(const GURL& url) const;
int logging_level() const { return logging_level_; }
// net::URLRequestContextGetter implementation: // net::URLRequestContextGetter implementation:
virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
virtual scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() virtual scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
...@@ -74,7 +69,6 @@ class URLRequestContextPeer : public net::URLRequestContextGetter { ...@@ -74,7 +69,6 @@ class URLRequestContextPeer : public net::URLRequestContextGetter {
private: private:
scoped_refptr<URLRequestContextPeerDelegate> delegate_; scoped_refptr<URLRequestContextPeerDelegate> delegate_;
scoped_ptr<net::URLRequestContext> context_; scoped_ptr<net::URLRequestContext> context_;
int logging_level_;
std::string user_agent_; std::string user_agent_;
base::Thread* network_thread_; base::Thread* network_thread_;
scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
......
...@@ -86,9 +86,9 @@ void URLRequestPeer::OnInitiateConnection() { ...@@ -86,9 +86,9 @@ void URLRequestPeer::OnInitiateConnection() {
return; return;
} }
VLOG(context_->logging_level()) VLOG(1) << "Starting chromium request: "
<< "Starting chromium request: " << url_.possibly_invalid_spec().c_str() << url_.possibly_invalid_spec().c_str()
<< " priority: " << RequestPriorityToString(priority_); << " priority: " << RequestPriorityToString(priority_);
url_request_ = new net::URLRequest( url_request_ = new net::URLRequest(
url_, net::DEFAULT_PRIORITY, this, context_->GetURLRequestContext()); url_, net::DEFAULT_PRIORITY, this, context_->GetURLRequestContext());
url_request_->SetLoadFlags(net::LOAD_DISABLE_CACHE | url_request_->SetLoadFlags(net::LOAD_DISABLE_CACHE |
...@@ -124,8 +124,7 @@ void URLRequestPeer::Cancel() { ...@@ -124,8 +124,7 @@ void URLRequestPeer::Cancel() {
} }
void URLRequestPeer::OnCancelRequest() { void URLRequestPeer::OnCancelRequest() {
VLOG(context_->logging_level()) VLOG(1) << "Canceling chromium request: " << url_.possibly_invalid_spec();
<< "Canceling chromium request: " << url_.possibly_invalid_spec();
if (url_request_ != NULL) { if (url_request_ != NULL) {
url_request_->Cancel(); url_request_->Cancel();
...@@ -141,8 +140,8 @@ void URLRequestPeer::Destroy() { ...@@ -141,8 +140,8 @@ void URLRequestPeer::Destroy() {
// static // static
void URLRequestPeer::OnDestroyRequest(URLRequestPeer* self) { void URLRequestPeer::OnDestroyRequest(URLRequestPeer* self) {
VLOG(self->context_->logging_level()) VLOG(1) << "Destroying chromium request: "
<< "Destroying chromium request: " << self->url_.possibly_invalid_spec(); << self->url_.possibly_invalid_spec();
delete self; delete self;
} }
...@@ -153,8 +152,7 @@ void URLRequestPeer::OnResponseStarted(net::URLRequest* request) { ...@@ -153,8 +152,7 @@ void URLRequestPeer::OnResponseStarted(net::URLRequest* request) {
} }
http_status_code_ = request->GetResponseCode(); http_status_code_ = request->GetResponseCode();
VLOG(context_->logging_level()) VLOG(1) << "Response started with status: " << http_status_code_;
<< "Response started with status: " << http_status_code_;
request->GetResponseHeaderByName("Content-Type", &content_type_); request->GetResponseHeaderByName("Content-Type", &content_type_);
expected_size_ = request->GetExpectedContentSize(); expected_size_ = request->GetExpectedContentSize();
...@@ -179,20 +177,18 @@ void URLRequestPeer::Read() { ...@@ -179,20 +177,18 @@ void URLRequestPeer::Read() {
break; break;
} }
VLOG(context_->logging_level()) << "Synchronously read: " << bytes_read VLOG(1) << "Synchronously read: " << bytes_read << " bytes";
<< " bytes";
OnBytesRead(bytes_read); OnBytesRead(bytes_read);
} else if (url_request_->status().status() == } else if (url_request_->status().status() ==
net::URLRequestStatus::IO_PENDING) { net::URLRequestStatus::IO_PENDING) {
if (bytes_read_ != 0) { if (bytes_read_ != 0) {
VLOG(context_->logging_level()) << "Flushing buffer: " << bytes_read_ VLOG(1) << "Flushing buffer: " << bytes_read_ << " bytes";
<< " bytes";
delegate_->OnBytesRead(this); delegate_->OnBytesRead(this);
read_buffer_->set_offset(0); read_buffer_->set_offset(0);
bytes_read_ = 0; bytes_read_ = 0;
} }
VLOG(context_->logging_level()) << "Started async read"; VLOG(1) << "Started async read";
break; break;
} else { } else {
OnRequestFailed(); OnRequestFailed();
...@@ -202,8 +198,7 @@ void URLRequestPeer::Read() { ...@@ -202,8 +198,7 @@ void URLRequestPeer::Read() {
} }
void URLRequestPeer::OnReadCompleted(net::URLRequest* request, int bytes_read) { void URLRequestPeer::OnReadCompleted(net::URLRequest* request, int bytes_read) {
VLOG(context_->logging_level()) << "Asynchronously read: " << bytes_read VLOG(1) << "Asynchronously read: " << bytes_read << " bytes";
<< " bytes";
if (bytes_read < 0) { if (bytes_read < 0) {
OnRequestFailed(); OnRequestFailed();
return; return;
...@@ -227,9 +222,8 @@ void URLRequestPeer::OnRequestSucceeded() { ...@@ -227,9 +222,8 @@ void URLRequestPeer::OnRequestSucceeded() {
return; return;
} }
VLOG(context_->logging_level()) VLOG(1) << "Request completed with HTTP status: " << http_status_code_
<< "Request completed with HTTP status: " << http_status_code_ << ". Total bytes read: " << total_bytes_read_;
<< ". Total bytes read: " << total_bytes_read_;
OnRequestCompleted(); OnRequestCompleted();
} }
...@@ -240,17 +234,15 @@ void URLRequestPeer::OnRequestFailed() { ...@@ -240,17 +234,15 @@ void URLRequestPeer::OnRequestFailed() {
} }
error_code_ = url_request_->status().error(); error_code_ = url_request_->status().error();
VLOG(context_->logging_level()) VLOG(1) << "Request failed with status: " << url_request_->status().status()
<< "Request failed with status: " << url_request_->status().status() << " and error: " << net::ErrorToString(error_code_);
<< " and error: " << net::ErrorToString(error_code_);
OnRequestCompleted(); OnRequestCompleted();
} }
void URLRequestPeer::OnRequestCanceled() { OnRequestCompleted(); } void URLRequestPeer::OnRequestCanceled() { OnRequestCompleted(); }
void URLRequestPeer::OnRequestCompleted() { void URLRequestPeer::OnRequestCompleted() {
VLOG(context_->logging_level()) VLOG(1) << "Completed: " << url_.possibly_invalid_spec();
<< "Completed: " << url_.possibly_invalid_spec();
if (url_request_ != NULL) { if (url_request_ != NULL) {
delete url_request_; delete url_request_;
url_request_ = NULL; url_request_ = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment