summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorAshish Sharma <ashishsharma@google.com>2011-07-08 13:59:58 -0700
committerAshish Sharma <ashishsharma@google.com>2011-08-09 04:32:52 -0700
commite14dcc5a172cad1c4716af7ab94121a73c0c698e (patch)
tree0c237f8f94ee348c717901e7f43cc6f0dcdacac5 /net
parent59ef0e2497e0662fe4a4044c2c50dab449bfcb87 (diff)
downloadexternal_chromium-e14dcc5a172cad1c4716af7ab94121a73c0c698e.zip
external_chromium-e14dcc5a172cad1c4716af7ab94121a73c0c698e.tar.gz
external_chromium-e14dcc5a172cad1c4716af7ab94121a73c0c698e.tar.bz2
Network traffic accounting for client applications that use chromium
URLRequest stack. Change-Id: If7821debd1b10b19ebf5a3e7b9f6570efc73c4fc
Diffstat (limited to 'net')
-rw-r--r--net/http/http_proxy_client_socket.cc5
-rw-r--r--net/http/http_proxy_client_socket.h2
-rw-r--r--net/http/http_proxy_client_socket_pool.cc31
-rw-r--r--net/http/http_proxy_client_socket_pool.h5
-rw-r--r--net/http/http_request_info.h6
-rw-r--r--net/socket/client_socket.h2
-rw-r--r--net/socket/client_socket_pool_base.cc12
-rw-r--r--net/socket/client_socket_pool_base.h43
-rw-r--r--net/socket/client_socket_pool_manager.cc9
-rw-r--r--net/socket/socks5_client_socket.cc2
-rw-r--r--net/socket/socks5_client_socket.h2
-rw-r--r--net/socket/socks_client_socket.cc2
-rw-r--r--net/socket/socks_client_socket.h2
-rw-r--r--net/socket/socks_client_socket_pool.cc22
-rw-r--r--net/socket/socks_client_socket_pool.h5
-rw-r--r--net/socket/ssl_client_socket_openssl.cc2
-rw-r--r--net/socket/ssl_client_socket_openssl.h2
-rw-r--r--net/socket/ssl_client_socket_pool.cc46
-rw-r--r--net/socket/ssl_client_socket_pool.h5
-rw-r--r--net/socket/tcp_client_socket_libevent.cc26
-rw-r--r--net/socket/tcp_client_socket_libevent.h5
-rw-r--r--net/socket/tcp_client_socket_pool.cc33
-rw-r--r--net/socket/tcp_client_socket_pool.h5
-rw-r--r--net/socket/transport_client_socket_pool.cc31
-rw-r--r--net/socket/transport_client_socket_pool.h11
-rw-r--r--net/spdy/spdy_proxy_client_socket.cc2
-rw-r--r--net/spdy/spdy_proxy_client_socket.h3
-rw-r--r--net/url_request/url_request_context.cc27
-rw-r--r--net/url_request/url_request_context.h11
-rw-r--r--net/url_request/url_request_http_job.cc15
30 files changed, 359 insertions, 15 deletions
diff --git a/net/http/http_proxy_client_socket.cc b/net/http/http_proxy_client_socket.cc
index 6cf6b78..8db236d 100644
--- a/net/http/http_proxy_client_socket.cc
+++ b/net/http/http_proxy_client_socket.cc
@@ -92,6 +92,8 @@ HttpStream* HttpProxyClientSocket::CreateConnectResponseStream() {
int HttpProxyClientSocket::Connect(CompletionCallback* callback
#ifdef ANDROID
, bool wait_for_connect
+ , bool valid_uid
+ , uid_t calling_uid
#endif
) {
DCHECK(transport_.get());
@@ -480,12 +482,15 @@ int HttpProxyClientSocket::DoDrainBodyComplete(int result) {
#ifdef ANDROID
// TODO(kristianm): Check if we can find out if Connect should block
+// TODO(ashishsharma): Perhaps make ignore_limits, calling_uid, valid_uid part of ClientSocket
#endif
int HttpProxyClientSocket::DoTCPRestart() {
next_state_ = STATE_TCP_RESTART_COMPLETE;
return transport_->socket()->Connect(&io_callback_
#ifdef ANDROID
, false
+ , false
+ , 0
#endif
);
}
diff --git a/net/http/http_proxy_client_socket.h b/net/http/http_proxy_client_socket.h
index fe2069b..9364bc2 100644
--- a/net/http/http_proxy_client_socket.h
+++ b/net/http/http_proxy_client_socket.h
@@ -72,6 +72,8 @@ class HttpProxyClientSocket : public ProxyClientSocket {
virtual int Connect(CompletionCallback* callback
#ifdef ANDROID
, bool wait_for_connect
+ , bool valid_uid
+ , uid_t calling_uid
#endif
);
virtual void Disconnect();
diff --git a/net/http/http_proxy_client_socket_pool.cc b/net/http/http_proxy_client_socket_pool.cc
index 151cf8a..c28d0e6 100644
--- a/net/http/http_proxy_client_socket_pool.cc
+++ b/net/http/http_proxy_client_socket_pool.cc
@@ -63,6 +63,22 @@ const HostResolver::RequestInfo& HttpProxySocketParams::destination() const {
HttpProxySocketParams::~HttpProxySocketParams() {}
+#ifdef ANDROID
+bool HttpProxySocketParams::getUID(uid_t *uid) const {
+ if (transport_params_ == NULL)
+ return ssl_params_->transport_params()->getUID(uid);
+ else
+ return transport_params_->getUID(uid);
+}
+
+void HttpProxySocketParams::setUID(uid_t uid) {
+ if (transport_params_ == NULL)
+ ssl_params_->transport_params()->setUID(uid);
+ else
+ transport_params_->setUID(uid);
+}
+#endif
+
// HttpProxyConnectJobs will time out after this many seconds. Note this is on
// top of the timeout for the transport socket.
static const int kHttpProxyConnectJobTimeoutInSeconds = 30;
@@ -272,9 +288,17 @@ int HttpProxyConnectJob::DoHttpProxyConnect() {
params_->tunnel(),
using_spdy_,
params_->ssl_params() != NULL));
+
+#ifdef ANDROID
+ uid_t calling_uid = 0;
+ bool valid_uid = params_->transport_params()->getUID(&calling_uid);
+#endif
+
return transport_socket_->Connect(&callback_
#ifdef ANDROID
, false
+ , valid_uid
+ , calling_uid
#endif
);
}
@@ -327,6 +351,11 @@ int HttpProxyConnectJob::DoSpdyProxyCreateStreamComplete(int result) {
if (result < 0)
return result;
+#ifdef ANDROID
+ uid_t calling_uid = 0;
+ bool valid_uid = params_->transport_params()->getUID(&calling_uid);
+#endif
+
next_state_ = STATE_HTTP_PROXY_CONNECT_COMPLETE;
transport_socket_.reset(
new SpdyProxyClientSocket(spdy_stream_,
@@ -339,6 +368,8 @@ int HttpProxyConnectJob::DoSpdyProxyCreateStreamComplete(int result) {
return transport_socket_->Connect(&callback_
#ifdef ANDROID
, false
+ , valid_uid
+ , calling_uid
#endif
);
}
diff --git a/net/http/http_proxy_client_socket_pool.h b/net/http/http_proxy_client_socket_pool.h
index 14bd9be..2ab331e 100644
--- a/net/http/http_proxy_client_socket_pool.h
+++ b/net/http/http_proxy_client_socket_pool.h
@@ -68,6 +68,11 @@ class HttpProxySocketParams : public base::RefCounted<HttpProxySocketParams> {
const HostResolver::RequestInfo& destination() const;
bool tunnel() const { return tunnel_; }
bool ignore_limits() const { return ignore_limits_; }
+#ifdef ANDROID
+ // Gets the UID of the calling process
+ bool getUID(uid_t *uid) const;
+ void setUID(uid_t uid);
+#endif
private:
friend class base::RefCounted<HttpProxySocketParams>;
diff --git a/net/http/http_request_info.h b/net/http/http_request_info.h
index b906cf5..fd83e70 100644
--- a/net/http/http_request_info.h
+++ b/net/http/http_request_info.h
@@ -56,6 +56,12 @@ struct HttpRequestInfo {
// An optional globally unique identifier for this request for use by the
// consumer. 0 is invalid.
uint64 request_id;
+
+#ifdef ANDROID
+ bool valid_uid;
+ uid_t calling_uid;
+#endif
+
};
} // namespace net
diff --git a/net/socket/client_socket.h b/net/socket/client_socket.h
index 346b12d..d14254b 100644
--- a/net/socket/client_socket.h
+++ b/net/socket/client_socket.h
@@ -35,6 +35,8 @@ class ClientSocket : public Socket {
virtual int Connect(CompletionCallback* callback
#ifdef ANDROID
, bool wait_for_connect
+ , bool valid_uid
+ , uid_t calling_uid
#endif
) = 0;
diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc
index e8f53af..b6f6190 100644
--- a/net/socket/client_socket_pool_base.cc
+++ b/net/socket/client_socket_pool_base.cc
@@ -135,13 +135,21 @@ ClientSocketPoolBaseHelper::Request::Request(
RequestPriority priority,
bool ignore_limits,
Flags flags,
- const BoundNetLog& net_log)
+ const BoundNetLog& net_log
+#ifdef ANDROID
+ , bool valid_uid, uid_t calling_uid
+#endif
+ )
: handle_(handle),
callback_(callback),
priority_(priority),
ignore_limits_(ignore_limits),
flags_(flags),
- net_log_(net_log) {}
+ net_log_(net_log)
+#ifdef ANDROID
+ , valid_uid_(valid_uid), calling_uid_(calling_uid)
+#endif
+ {}
ClientSocketPoolBaseHelper::Request::~Request() {}
diff --git a/net/socket/client_socket_pool_base.h b/net/socket/client_socket_pool_base.h
index fe18ff2..b5c4c04 100644
--- a/net/socket/client_socket_pool_base.h
+++ b/net/socket/client_socket_pool_base.h
@@ -173,7 +173,11 @@ class ClientSocketPoolBaseHelper
RequestPriority priority,
bool ignore_limits,
Flags flags,
- const BoundNetLog& net_log);
+ const BoundNetLog& net_log
+#ifdef ANDROID
+ , bool valid_uid, uid_t calling_uid
+#endif
+ );
virtual ~Request();
@@ -191,6 +195,10 @@ class ClientSocketPoolBaseHelper
bool ignore_limits_;
const Flags flags_;
BoundNetLog net_log_;
+#ifdef ANDROID
+ bool valid_uid_;
+ uid_t calling_uid_;
+#endif
DISALLOW_COPY_AND_ASSIGN(Request);
};
@@ -568,9 +576,18 @@ class ClientSocketPoolBase {
internal::ClientSocketPoolBaseHelper::Flags flags,
bool ignore_limits,
const scoped_refptr<SocketParams>& params,
- const BoundNetLog& net_log)
+ const BoundNetLog& net_log
+#ifdef ANDROID
+ , bool valid_uid, int calling_uid
+#endif
+ )
: internal::ClientSocketPoolBaseHelper::Request(
- handle, callback, priority, ignore_limits, flags, net_log),
+ handle, callback, priority, ignore_limits,
+ flags, net_log
+#ifdef ANDROID
+ , valid_uid, calling_uid
+#endif
+ ),
params_(params) {}
const scoped_refptr<SocketParams>& params() const { return params_; }
@@ -625,11 +642,19 @@ class ClientSocketPoolBase {
ClientSocketHandle* handle,
CompletionCallback* callback,
const BoundNetLog& net_log) {
+#ifdef ANDROID
+ uid_t calling_uid = 0;
+ bool valid_uid = params->getUID(&calling_uid);
+#endif
Request* request =
new Request(handle, callback, priority,
internal::ClientSocketPoolBaseHelper::NORMAL,
params->ignore_limits(),
- params, net_log);
+ params, net_log
+#ifdef ANDROID
+ , valid_uid, calling_uid
+#endif
+ );
return helper_.RequestSocket(group_name, request);
}
@@ -640,13 +665,21 @@ class ClientSocketPoolBase {
const scoped_refptr<SocketParams>& params,
int num_sockets,
const BoundNetLog& net_log) {
+#ifdef ANDROID
+ uid_t calling_uid = 0;
+ bool valid_uid = params->getUID(&calling_uid);
+#endif
const Request request(NULL /* no handle */,
NULL /* no callback */,
LOWEST,
internal::ClientSocketPoolBaseHelper::NO_IDLE_SOCKETS,
params->ignore_limits(),
params,
- net_log);
+ net_log
+#ifdef ANDROID
+ , valid_uid, calling_uid
+#endif
+ );
helper_.RequestSockets(group_name, request, num_sockets);
}
diff --git a/net/socket/client_socket_pool_manager.cc b/net/socket/client_socket_pool_manager.cc
index 7277b37..182eb18 100644
--- a/net/socket/client_socket_pool_manager.cc
+++ b/net/socket/client_socket_pool_manager.cc
@@ -104,6 +104,10 @@ int InitSocketPoolHelper(const HttpRequestInfo& request_info,
request_info.referrer,
disable_resolver_cache,
ignore_limits);
+#ifdef ANDROID
+ if (request_info.valid_uid)
+ tcp_params->setUID(request_info.calling_uid);
+#endif
} else {
ProxyServer proxy_server = proxy_info.proxy_server();
proxy_host_port.reset(new HostPortPair(proxy_server.host_port_pair()));
@@ -114,6 +118,11 @@ int InitSocketPoolHelper(const HttpRequestInfo& request_info,
disable_resolver_cache,
ignore_limits));
+#ifdef ANDROID
+ if (request_info.valid_uid)
+ proxy_tcp_params->setUID(request_info.calling_uid);
+#endif
+
if (proxy_info.is_http() || proxy_info.is_https()) {
std::string user_agent;
request_info.extra_headers.GetHeader(HttpRequestHeaders::kUserAgent,
diff --git a/net/socket/socks5_client_socket.cc b/net/socket/socks5_client_socket.cc
index 7cd9fae..b67c737 100644
--- a/net/socket/socks5_client_socket.cc
+++ b/net/socket/socks5_client_socket.cc
@@ -70,6 +70,8 @@ SOCKS5ClientSocket::~SOCKS5ClientSocket() {
int SOCKS5ClientSocket::Connect(CompletionCallback* callback
#ifdef ANDROID
, bool wait_for_connect
+ , bool valid_uid
+ , uid_t calling_uid
#endif
) {
DCHECK(transport_.get());
diff --git a/net/socket/socks5_client_socket.h b/net/socket/socks5_client_socket.h
index 1e18d26..4ac0f0c 100644
--- a/net/socket/socks5_client_socket.h
+++ b/net/socket/socks5_client_socket.h
@@ -54,6 +54,8 @@ class SOCKS5ClientSocket : public ClientSocket {
virtual int Connect(CompletionCallback* callback
#ifdef ANDROID
, bool wait_for_connect
+ , bool valid_uid
+ , uid_t calling_uid
#endif
);
virtual void Disconnect();
diff --git a/net/socket/socks_client_socket.cc b/net/socket/socks_client_socket.cc
index a54f0f1..349dbc0 100644
--- a/net/socket/socks_client_socket.cc
+++ b/net/socket/socks_client_socket.cc
@@ -97,6 +97,8 @@ SOCKSClientSocket::~SOCKSClientSocket() {
int SOCKSClientSocket::Connect(CompletionCallback* callback
#ifdef ANDROID
, bool wait_for_connect
+ , bool valid_uid
+ , uid_t calling_uid
#endif
) {
DCHECK(transport_.get());
diff --git a/net/socket/socks_client_socket.h b/net/socket/socks_client_socket.h
index 43d9e9b..8b651d3 100644
--- a/net/socket/socks_client_socket.h
+++ b/net/socket/socks_client_socket.h
@@ -51,6 +51,8 @@ class SOCKSClientSocket : public ClientSocket {
virtual int Connect(CompletionCallback* callback
#ifdef ANDROID
, bool wait_for_connect
+ , bool valid_uid
+ , uid_t calling_uid
#endif
);
virtual void Disconnect();
diff --git a/net/socket/socks_client_socket_pool.cc b/net/socket/socks_client_socket_pool.cc
index 0a5b996..be563c8 100644
--- a/net/socket/socks_client_socket_pool.cc
+++ b/net/socket/socks_client_socket_pool.cc
@@ -37,6 +37,20 @@ SOCKSSocketParams::SOCKSSocketParams(
destination_.set_priority(priority);
}
+#ifdef ANDROID
+bool SOCKSSocketParams::getUID(uid_t *uid) const {
+ if (transport_params_)
+ return transport_params_->getUID(uid);
+ else
+ return false;
+}
+
+void SOCKSSocketParams::setUID(uid_t uid) {
+ if (transport_params_)
+ return transport_params_->setUID(uid);
+}
+#endif
+
SOCKSSocketParams::~SOCKSSocketParams() {}
// SOCKSConnectJobs will time out after this many seconds. Note this is on
@@ -153,9 +167,17 @@ int SOCKSConnectJob::DoSOCKSConnect() {
socks_params_->destination(),
resolver_));
}
+
+#ifdef ANDROID
+ uid_t calling_uid = 0;
+ bool valid_uid = socks_params_->transport_params()->getUID(&calling_uid);
+#endif
+
return socket_->Connect(&callback_
#ifdef ANDROID
, socks_params_->ignore_limits()
+ , valid_uid
+ , calling_uid
#endif
);
}
diff --git a/net/socket/socks_client_socket_pool.h b/net/socket/socks_client_socket_pool.h
index b66caf2..894ee2b 100644
--- a/net/socket/socks_client_socket_pool.h
+++ b/net/socket/socks_client_socket_pool.h
@@ -37,6 +37,11 @@ class SOCKSSocketParams : public base::RefCounted<SOCKSSocketParams> {
const HostResolver::RequestInfo& destination() const { return destination_; }
bool is_socks_v5() const { return socks_v5_; }
bool ignore_limits() const { return ignore_limits_; }
+#ifdef ANDROID
+ // Gets the UID of the calling process
+ bool getUID(uid_t *uid) const;
+ void setUID(uid_t uid);
+#endif
private:
friend class base::RefCounted<SOCKSSocketParams>;
diff --git a/net/socket/ssl_client_socket_openssl.cc b/net/socket/ssl_client_socket_openssl.cc
index 2776307..588098b 100644
--- a/net/socket/ssl_client_socket_openssl.cc
+++ b/net/socket/ssl_client_socket_openssl.cc
@@ -635,6 +635,8 @@ void SSLClientSocketOpenSSL::DoWriteCallback(int rv) {
int SSLClientSocketOpenSSL::Connect(CompletionCallback* callback
#ifdef ANDROID
, bool wait_for_connect
+ , bool valid_uid
+ , uid_t calling_uid
#endif
) {
net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT, NULL);
diff --git a/net/socket/ssl_client_socket_openssl.h b/net/socket/ssl_client_socket_openssl.h
index b6cc09f..f32534e 100644
--- a/net/socket/ssl_client_socket_openssl.h
+++ b/net/socket/ssl_client_socket_openssl.h
@@ -61,6 +61,8 @@ class SSLClientSocketOpenSSL : public SSLClientSocket {
virtual int Connect(CompletionCallback* callback
#ifdef ANDROID
, bool wait_for_connect
+ , bool valid_uid
+ , uid_t calling_uid
#endif
);
virtual void Disconnect();
diff --git a/net/socket/ssl_client_socket_pool.cc b/net/socket/ssl_client_socket_pool.cc
index b4088c6..d0d069a 100644
--- a/net/socket/ssl_client_socket_pool.cc
+++ b/net/socket/ssl_client_socket_pool.cc
@@ -69,6 +69,44 @@ SSLSocketParams::SSLSocketParams(
SSLSocketParams::~SSLSocketParams() {}
+#ifdef ANDROID
+bool SSLSocketParams::getUID(uid_t *uid) const {
+ bool answer = false;
+ switch (proxy_) {
+ case ProxyServer::SCHEME_DIRECT:
+ break;
+ case ProxyServer::SCHEME_HTTP:
+ case ProxyServer::SCHEME_HTTPS:
+ answer = http_proxy_params_->getUID(uid);
+ break;
+ case ProxyServer::SCHEME_SOCKS4:
+ case ProxyServer::SCHEME_SOCKS5:
+ answer = socks_params_->getUID(uid);
+ break;
+ default:
+ break;
+ }
+ return answer;
+}
+
+void SSLSocketParams::setUID(uid_t uid) {
+ switch (proxy_) {
+ case ProxyServer::SCHEME_DIRECT:
+ break;
+ case ProxyServer::SCHEME_HTTP:
+ case ProxyServer::SCHEME_HTTPS:
+ http_proxy_params_->setUID(uid);
+ break;
+ case ProxyServer::SCHEME_SOCKS4:
+ case ProxyServer::SCHEME_SOCKS5:
+ socks_params_->setUID(uid);
+ break;
+ default:
+ break;
+ }
+}
+#endif
+
// Timeout for the SSL handshake portion of the connect.
static const int kSSLHandshakeTimeoutInSeconds = 30;
@@ -285,9 +323,17 @@ int SSLConnectJob::DoSSLConnect() {
transport_socket_handle_.release(), params_->host_and_port(),
params_->ssl_config(), ssl_host_info_.release(), cert_verifier_,
dns_cert_checker_));
+
+#ifdef ANDROID
+ uid_t calling_uid = 0;
+ bool valid_uid = params_->transport_params()->getUID(&calling_uid);
+#endif
+
return ssl_socket_->Connect(&callback_
#ifdef ANDROID
, params_->ignore_limits()
+ , valid_uid
+ , calling_uid
#endif
);
}
diff --git a/net/socket/ssl_client_socket_pool.h b/net/socket/ssl_client_socket_pool.h
index 5c0ecb4..3f2efc3 100644
--- a/net/socket/ssl_client_socket_pool.h
+++ b/net/socket/ssl_client_socket_pool.h
@@ -68,6 +68,11 @@ class SSLSocketParams : public base::RefCounted<SSLSocketParams> {
bool force_spdy_over_ssl() const { return force_spdy_over_ssl_; }
bool want_spdy_over_npn() const { return want_spdy_over_npn_; }
bool ignore_limits() const { return ignore_limits_; }
+#ifdef ANDROID
+ // Gets the UID of the calling process
+ bool getUID(uid_t *uid) const;
+ void setUID(uid_t uid);
+#endif
private:
friend class base::RefCounted<SSLSocketParams>;
diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc
index 9bd338b..ed9d87d 100644
--- a/net/socket/tcp_client_socket_libevent.cc
+++ b/net/socket/tcp_client_socket_libevent.cc
@@ -31,6 +31,9 @@
#else
#include "third_party/libevent/event.h"
#endif
+#ifdef ANDROID
+#include <cutils/qtaguid.h>
+#endif
namespace net {
@@ -118,6 +121,8 @@ TCPClientSocketLibevent::TCPClientSocketLibevent(
tcp_fastopen_connected_(false)
#ifdef ANDROID
, wait_for_connect_(false)
+ , valid_uid_(false)
+ , calling_uid_(0)
#endif
{
scoped_refptr<NetLog::EventParameters> params;
@@ -149,10 +154,14 @@ void TCPClientSocketLibevent::AdoptSocket(int socket) {
int TCPClientSocketLibevent::Connect(CompletionCallback* callback
#ifdef ANDROID
, bool wait_for_connect
+ , bool valid_uid
+ , uid_t calling_uid
#endif
) {
#ifdef ANDROID
wait_for_connect_ = wait_for_connect;
+ valid_uid_ = valid_uid;
+ calling_uid_ = calling_uid;
#endif
DCHECK(CalledOnValidThread());
@@ -321,6 +330,12 @@ void TCPClientSocketLibevent::DoDisconnect() {
DCHECK(ok);
ok = write_socket_watcher_.StopWatchingFileDescriptor();
DCHECK(ok);
+
+#ifdef ANDROID
+ if (valid_uid_)
+ qtaguid_untagSocket(socket_);
+#endif
+
if (HANDLE_EINTR(close(socket_)) < 0)
PLOG(ERROR) << "close";
socket_ = kInvalidSocket;
@@ -499,6 +514,12 @@ int TCPClientSocketLibevent::CreateSocket(const addrinfo* ai) {
int TCPClientSocketLibevent::SetupSocket() {
if (SetNonBlocking(socket_)) {
const int err = errno;
+
+#ifdef ANDROID
+ if (valid_uid_)
+ qtaguid_untagSocket(socket_);
+#endif
+
close(socket_);
socket_ = kInvalidSocket;
return err;
@@ -509,6 +530,11 @@ int TCPClientSocketLibevent::SetupSocket() {
DisableNagle(socket_); // If DisableNagle fails, we don't care.
SetTCPKeepAlive(socket_);
+#ifdef ANDROID
+ if (valid_uid_)
+ qtaguid_tagSocket(socket_, geteuid(), calling_uid_);
+#endif
+
return 0;
}
diff --git a/net/socket/tcp_client_socket_libevent.h b/net/socket/tcp_client_socket_libevent.h
index 5f34726..15fc378 100644
--- a/net/socket/tcp_client_socket_libevent.h
+++ b/net/socket/tcp_client_socket_libevent.h
@@ -44,6 +44,8 @@ class TCPClientSocketLibevent : public ClientSocket, base::NonThreadSafe {
virtual int Connect(CompletionCallback* callback
#ifdef ANDROID
, bool wait_for_connect
+ , bool valid_uid
+ , uid_t calling_uid
#endif
);
virtual void Disconnect();
@@ -200,7 +202,8 @@ class TCPClientSocketLibevent : public ClientSocket, base::NonThreadSafe {
#ifdef ANDROID
// True if connect should block and not return before the socket is connected
bool wait_for_connect_;
-
+ bool valid_uid_;
+ uid_t calling_uid_;
#endif
DISALLOW_COPY_AND_ASSIGN(TCPClientSocketLibevent);
};
diff --git a/net/socket/tcp_client_socket_pool.cc b/net/socket/tcp_client_socket_pool.cc
index bc708d6..735f498 100644
--- a/net/socket/tcp_client_socket_pool.cc
+++ b/net/socket/tcp_client_socket_pool.cc
@@ -26,7 +26,9 @@ TCPSocketParams::TCPSocketParams(const HostPortPair& host_port_pair,
bool disable_resolver_cache, bool ignore_limits)
: destination_(host_port_pair)
#ifdef ANDROID
- , ignore_limits_(ignore_limits)
+ , ignore_limits_(ignore_limits),
+ valid_uid_(false),
+ calling_uid_(0)
#endif
{
Initialize(priority, referrer, disable_resolver_cache);
@@ -38,7 +40,9 @@ TCPSocketParams::TCPSocketParams(const std::string& host, int port,
bool disable_resolver_cache)
: destination_(HostPortPair(host, port))
#ifdef ANDROID
- , ignore_limits_(false)
+ , ignore_limits_(false),
+ valid_uid_(false),
+ calling_uid_(0)
#endif
{
Initialize(priority, referrer, disable_resolver_cache);
@@ -58,6 +62,21 @@ void TCPSocketParams::Initialize(RequestPriority priority,
destination_.set_allow_cached_response(false);
}
+#ifdef ANDROID
+bool TCPSocketParams::getUID(uid_t *uid) const {
+ if (!valid_uid_) {
+ return false;
+ }
+ *uid = calling_uid_;
+ return true;
+}
+
+void TCPSocketParams::setUID(uid_t uid) {
+ valid_uid_ = true;
+ calling_uid_ = uid;
+}
+#endif
+
// TCPConnectJobs will time out after this many seconds. Note this is the total
// time, including both host resolution and TCP connect() times.
//
@@ -160,9 +179,17 @@ int TCPConnectJob::DoTCPConnect() {
set_socket(client_socket_factory_->CreateTCPClientSocket(
addresses_, net_log().net_log(), net_log().source()));
connect_start_time_ = base::TimeTicks::Now();
+
+#ifdef ANDROID
+ uid_t calling_uid = 0;
+ bool valid_uid = params_->getUID(&calling_uid);
+#endif
+
return socket()->Connect(&callback_,
#ifdef ANDROID
- params_->ignore_limits()
+ params_->ignore_limits(),
+ valid_uid,
+ calling_uid
#endif
);
}
diff --git a/net/socket/tcp_client_socket_pool.h b/net/socket/tcp_client_socket_pool.h
index d93d2be..cb671db 100644
--- a/net/socket/tcp_client_socket_pool.h
+++ b/net/socket/tcp_client_socket_pool.h
@@ -40,6 +40,9 @@ class TCPSocketParams : public base::RefCounted<TCPSocketParams> {
#ifdef ANDROID
bool ignore_limits() const { return ignore_limits_; }
+ // Gets the UID of the calling process
+ bool getUID(uid_t *uid) const;
+ void setUID(uid_t uid);
#endif
private:
@@ -52,6 +55,8 @@ class TCPSocketParams : public base::RefCounted<TCPSocketParams> {
HostResolver::RequestInfo destination_;
#ifdef ANDROID
bool ignore_limits_;
+ bool valid_uid_;
+ int calling_uid_;
#endif
DISALLOW_COPY_AND_ASSIGN(TCPSocketParams);
diff --git a/net/socket/transport_client_socket_pool.cc b/net/socket/transport_client_socket_pool.cc
index 448d4da..966d626 100644
--- a/net/socket/transport_client_socket_pool.cc
+++ b/net/socket/transport_client_socket_pool.cc
@@ -81,6 +81,21 @@ void TransportSocketParams::Initialize(RequestPriority priority,
destination_.set_allow_cached_response(false);
}
+#ifdef ANDROID
+bool TransportSocketParams::getUID(uid_t *uid) const {
+ if (!valid_uid_) {
+ return false;
+ }
+ *uid = calling_uid_;
+ return true;
+}
+
+void TransportSocketParams::setUID(uid_t uid) {
+ valid_uid_ = true;
+ calling_uid_ = uid;
+}
+#endif
+
// TransportConnectJobs will time out after this many seconds. Note this is
// the total time, including both host resolution and TCP connect() times.
//
@@ -219,9 +234,17 @@ int TransportConnectJob::DoTransportConnect() {
transport_socket_.reset(client_socket_factory_->CreateTransportClientSocket(
addresses_, net_log().net_log(), net_log().source()));
connect_start_time_ = base::TimeTicks::Now();
+
+#ifdef ANDROID
+ uid_t calling_uid = 0;
+ bool valid_uid = params_->getUID(&calling_uid);
+#endif
+
int rv = transport_socket_->Connect(&callback_
#ifdef ANDROID
, params_->ignore_limits()
+ , valid_uid
+ , calling_uid
#endif
);
if (rv == ERR_IO_PENDING &&
@@ -303,9 +326,17 @@ void TransportConnectJob::DoIPv6FallbackTransportConnect() {
client_socket_factory_->CreateTransportClientSocket(
*fallback_addresses_, net_log().net_log(), net_log().source()));
fallback_connect_start_time_ = base::TimeTicks::Now();
+
+#ifdef ANDROID
+ uid_t calling_uid = 0;
+ bool valid_uid = params_->getUID(&calling_uid);
+#endif
+
int rv = fallback_transport_socket_->Connect(&fallback_callback_
#ifdef ANDROID
, params_->ignore_limits()
+ , valid_uid
+ , calling_uid
#endif
);
if (rv != ERR_IO_PENDING)
diff --git a/net/socket/transport_client_socket_pool.h b/net/socket/transport_client_socket_pool.h
index bf630f6..c1633bb 100644
--- a/net/socket/transport_client_socket_pool.h
+++ b/net/socket/transport_client_socket_pool.h
@@ -33,6 +33,11 @@ class TransportSocketParams : public base::RefCounted<TransportSocketParams> {
const HostResolver::RequestInfo& destination() const { return destination_; }
bool ignore_limits() const { return ignore_limits_; }
+#ifdef ANDROID
+ // Gets the UID of the calling process
+ bool getUID(uid_t *uid) const;
+ void setUID(uid_t uid);
+#endif
private:
friend class base::RefCounted<TransportSocketParams>;
@@ -43,7 +48,11 @@ class TransportSocketParams : public base::RefCounted<TransportSocketParams> {
HostResolver::RequestInfo destination_;
bool ignore_limits_;
-
+#ifdef ANDROID
+ // Gets the UID of the calling process
+ bool valid_uid_;
+ int calling_uid_;
+#endif
DISALLOW_COPY_AND_ASSIGN(TransportSocketParams);
};
diff --git a/net/spdy/spdy_proxy_client_socket.cc b/net/spdy/spdy_proxy_client_socket.cc
index 2f85584..ef2e913 100644
--- a/net/spdy/spdy_proxy_client_socket.cc
+++ b/net/spdy/spdy_proxy_client_socket.cc
@@ -85,6 +85,8 @@ HttpStream* SpdyProxyClientSocket::CreateConnectResponseStream() {
int SpdyProxyClientSocket::Connect(CompletionCallback* callback
#ifdef ANDROID
, bool wait_for_connect
+ , bool valid_uid
+ , uid_t calling_uid
#endif
) {
DCHECK(!read_callback_);
diff --git a/net/spdy/spdy_proxy_client_socket.h b/net/spdy/spdy_proxy_client_socket.h
index be1560b..3b59d82 100644
--- a/net/spdy/spdy_proxy_client_socket.h
+++ b/net/spdy/spdy_proxy_client_socket.h
@@ -69,7 +69,8 @@ class SpdyProxyClientSocket : public ProxyClientSocket,
// ClientSocket methods:
#ifdef ANDROID
- virtual int Connect(CompletionCallback* callback, bool wait_for_connect);
+ virtual int Connect(CompletionCallback* callback, bool wait_for_connect,
+ bool valid_uid, uid_t calling_uid);
#else
virtual int Connect(CompletionCallback* callback);
#endif
diff --git a/net/url_request/url_request_context.cc b/net/url_request/url_request_context.cc
index 09ac381..fa479a2 100644
--- a/net/url_request/url_request_context.cc
+++ b/net/url_request/url_request_context.cc
@@ -24,8 +24,12 @@ URLRequestContext::URLRequestContext()
cookie_policy_(NULL),
transport_security_state_(NULL),
http_transaction_factory_(NULL),
- ftp_transaction_factory_(NULL) {
-}
+ ftp_transaction_factory_(NULL)
+#ifdef ANDROID
+ valid_uid_(false),
+ calling_uid_(0),
+#endif
+ {}
void URLRequestContext::CopyFrom(URLRequestContext* other) {
// Copy URLRequestContext parameters.
@@ -48,6 +52,10 @@ void URLRequestContext::CopyFrom(URLRequestContext* other) {
set_referrer_charset(other->referrer_charset());
set_http_transaction_factory(other->http_transaction_factory());
set_ftp_transaction_factory(other->ftp_transaction_factory());
+#ifdef ANDROID
+ calling_uid_ = 0;
+ valid_uid_ = other->getUID(&calling_uid_);
+#endif
}
void URLRequestContext::set_cookie_store(CookieStore* cookie_store) {
@@ -67,6 +75,21 @@ bool URLRequestContext::IsSNIAvailable() const {
return ssl_config.tls1_enabled;
}
+#ifdef ANDROID
+void URLRequestContext::setUID(uid_t uid) {
+ valid_uid_ = true;
+ calling_uid_ = uid;
+}
+
+bool URLRequestContext::getUID(uid_t *uid) const {
+ if (!valid_uid_) {
+ return false;
+ }
+ *uid = calling_uid_;
+ return true;
+}
+#endif
+
URLRequestContext::~URLRequestContext() {
}
diff --git a/net/url_request/url_request_context.h b/net/url_request/url_request_context.h
index 11a961a..714eedb 100644
--- a/net/url_request/url_request_context.h
+++ b/net/url_request/url_request_context.h
@@ -187,6 +187,12 @@ class URLRequestContext
// Is SNI available in this request context?
bool IsSNIAvailable() const;
+#ifdef ANDROID
+ // Gets the UID of the calling process
+ bool getUID(uid_t *uid) const;
+ void setUID(uid_t uid);
+#endif
+
protected:
friend class base::RefCountedThreadSafe<URLRequestContext>;
@@ -231,6 +237,11 @@ class URLRequestContext
// be added to CopyFrom.
// ---------------------------------------------------------------------------
+#ifdef ANDROID
+ bool valid_uid_;
+ uid_t calling_uid_;
+#endif
+
DISALLOW_COPY_AND_ASSIGN(URLRequestContext);
};
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
index 19b86a8..95f536f 100644
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -778,6 +778,21 @@ void URLRequestHttpJob::Start() {
}
AddExtraHeaders();
+
+#ifdef ANDROID
+ // Attribute network traffic to the UID of the caller
+ request_info_.valid_uid = false;
+ request_info_.calling_uid = 0;
+
+ if (request_->context()) {
+ uid_t uid;
+ if(request_->context()->getUID(&uid)) {
+ request_info_.valid_uid = true;
+ request_info_.calling_uid = uid;
+ }
+ }
+#endif
+
AddCookieHeaderAndStart();
}