diff options
author | michaelbai@google.com <michaelbai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-11 19:54:37 +0000 |
---|---|---|
committer | michaelbai@google.com <michaelbai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-11 19:54:37 +0000 |
commit | 39588997bced271d4f1f199e7fd99b51438d080e (patch) | |
tree | 09f3869fd0c89efad297de22943ba3e833a8fbb5 /net | |
parent | 76730d0e90f60b0e9b1d4b89d2387855211c59a3 (diff) | |
download | chromium_src-39588997bced271d4f1f199e7fd99b51438d080e.zip chromium_src-39588997bced271d4f1f199e7fd99b51438d080e.tar.gz chromium_src-39588997bced271d4f1f199e7fd99b51438d080e.tar.bz2 |
Upstream android net related code (part 1)
BUG=
TEST=
Review URL: http://codereview.chromium.org/7277057
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92040 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/file_stream_posix.cc | 8 | ||||
-rw-r--r-- | net/base/host_resolver_impl.cc | 3 | ||||
-rw-r--r-- | net/base/host_resolver_proc.cc | 3 | ||||
-rw-r--r-- | net/base/mock_host_resolver.cc | 6 | ||||
-rw-r--r-- | net/base/net_util.cc | 26 | ||||
-rw-r--r-- | net/base/net_util_posix.cc | 14 | ||||
-rw-r--r-- | net/base/network_change_notifier.cc | 4 |
7 files changed, 51 insertions, 13 deletions
diff --git a/net/base/file_stream_posix.cc b/net/base/file_stream_posix.cc index e960267..68732e3 100644 --- a/net/base/file_stream_posix.cc +++ b/net/base/file_stream_posix.cc @@ -27,6 +27,14 @@ #include "base/synchronization/waitable_event.h" #include "net/base/net_errors.h" +#if defined(OS_ANDROID) +// Android's bionic libc only supports the LFS transitional API. +#define off_t off64_t +#define lseek lseek64 +#define stat stat64 +#define fstat fstat64 +#endif + namespace net { // We cast back and forth, so make sure it's the size we're expecting. diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc index 9b412a0..4898d9e 100644 --- a/net/base/host_resolver_impl.cc +++ b/net/base/host_resolver_impl.cc @@ -100,7 +100,10 @@ std::vector<int> GetAllGetAddrinfoOSErrors() { int os_errors[] = { #if defined(OS_POSIX) #if !defined(OS_FREEBSD) +#if !defined(OS_ANDROID) + // EAI_ADDRFAMILY has been declared obsolete in Android's netdb.h. EAI_ADDRFAMILY, +#endif EAI_NODATA, #endif EAI_AGAIN, diff --git a/net/base/host_resolver_proc.cc b/net/base/host_resolver_proc.cc index 10523a3..88e0ba1 100644 --- a/net/base/host_resolver_proc.cc +++ b/net/base/host_resolver_proc.cc @@ -198,7 +198,8 @@ int SystemHostResolverProc(const std::string& host, int err = getaddrinfo(host.c_str(), NULL, &hints, &ai); bool should_retry = false; -#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) +#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \ + !defined(OS_ANDROID) // If we fail, re-initialise the resolver just in case there have been any // changes to /etc/resolv.conf and retry. See http://crbug.com/11380 for info. if (err && DnsReloadTimerHasExpired()) { diff --git a/net/base/mock_host_resolver.cc b/net/base/mock_host_resolver.cc index d8f3acb..3cc4a82 100644 --- a/net/base/mock_host_resolver.cc +++ b/net/base/mock_host_resolver.cc @@ -63,7 +63,13 @@ void MockHostResolverBase::Reset(HostResolverProc* interceptor) { // At the root of the chain, map everything to localhost. scoped_refptr<RuleBasedHostResolverProc> catchall( new RuleBasedHostResolverProc(NULL)); +#if defined(OS_ANDROID) + // In Android emulator, the development machine's '127.0.0.1' is mapped to + // '10.0.2.2'. + catchall->AddRule("*", "10.0.2.2"); +#else catchall->AddRule("*", "127.0.0.1"); +#endif // Next add a rules-based layer the use controls. rules_ = new RuleBasedHostResolverProc(catchall); diff --git a/net/base/net_util.cc b/net/base/net_util.cc index d2b742b..25c0633 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -24,7 +24,9 @@ #pragma comment(lib, "iphlpapi.lib") #elif defined(OS_POSIX) #include <fcntl.h> +#if !defined(OS_ANDROID) #include <ifaddrs.h> +#endif #include <netdb.h> #include <net/if.h> #include <netinet/in.h> @@ -981,7 +983,7 @@ std::string GetSpecificHeader(const std::string& headers, std::string match('\n' + name + ':'); std::string::const_iterator begin = - search(headers.begin(), headers.end(), match.begin(), match.end(), + std::search(headers.begin(), headers.end(), match.begin(), match.end(), base::CaseInsensitiveCompareASCII<char>()); if (begin == headers.end()) @@ -990,8 +992,8 @@ std::string GetSpecificHeader(const std::string& headers, begin += match.length(); std::string ret; - TrimWhitespace(std::string(begin, find(begin, headers.end(), '\n')), TRIM_ALL, - &ret); + TrimWhitespace(std::string(begin, std::find(begin, headers.end(), '\n')), + TRIM_ALL, &ret); return ret; } @@ -1074,8 +1076,8 @@ std::string GetHeaderParamValue(const std::string& header, QuoteRule::Type quote_rule) { // This assumes args are formatted exactly like "bla; arg1=value; arg2=value". std::string::const_iterator param_begin = - search(header.begin(), header.end(), param_name.begin(), param_name.end(), - base::CaseInsensitiveCompareASCII<char>()); + std::search(header.begin(), header.end(), param_name.begin(), + param_name.end(), base::CaseInsensitiveCompareASCII<char>()); if (param_begin == header.end()) return std::string(); @@ -1099,13 +1101,13 @@ std::string GetHeaderParamValue(const std::string& header, std::string::const_iterator param_end; if (*param_begin == '"' && quote_rule == QuoteRule::REMOVE_OUTER_QUOTES) { ++param_begin; // skip past the quote. - param_end = find(param_begin, header.end(), '"'); + param_end = std::find(param_begin, header.end(), '"'); // If the closing quote is missing, we will treat the rest of the // string as the parameter. We can't set |param_end| to the // location of the separator (';'), since the separator is // technically quoted. See: http://crbug.com/58840 } else { - param_end = find(param_begin + 1, header.end(), ';'); + param_end = std::find(param_begin + 1, header.end(), ';'); } return std::string(param_begin, param_end); @@ -1825,7 +1827,13 @@ static void IPv6SupportResults(IPv6SupportStatus result) { // to do a test resolution, and a test connection, to REALLY verify support. // static bool IPv6Supported() { -#if defined(OS_POSIX) +#if defined(OS_ANDROID) + // TODO: We should fully implement IPv6 probe once 'getifaddrs' API available; + // Another approach is implementing the similar feature by + // java.net.NetworkInterface through JNI. + NOTIMPLEMENTED(); + return true; +#elif defined(OS_POSIX) int test_socket = socket(AF_INET6, SOCK_STREAM, 0); if (test_socket == -1) { IPv6SupportResults(IPV6_CANNOT_CREATE_SOCKETS); @@ -1940,7 +1948,7 @@ bool IPv6Supported() { } bool HaveOnlyLoopbackAddresses() { -#if defined(OS_POSIX) +#if defined(OS_POSIX) && !defined(OS_ANDROID) struct ifaddrs* interface_addr = NULL; int rv = getifaddrs(&interface_addr); if (rv != 0) { diff --git a/net/base/net_util_posix.cc b/net/base/net_util_posix.cc index af3d5d1..0412792 100644 --- a/net/base/net_util_posix.cc +++ b/net/base/net_util_posix.cc @@ -4,7 +4,6 @@ #include "net/base/net_util.h" -#include <ifaddrs.h> #include <sys/types.h> #include "base/eintr_wrapper.h" @@ -17,6 +16,10 @@ #include "net/base/ip_endpoint.h" #include "net/base/net_errors.h" +#if !defined(OS_ANDROID) +#include <ifaddrs.h> +#endif + namespace net { bool FileURLToFilePath(const GURL& url, FilePath* path) { @@ -54,6 +57,14 @@ bool FileURLToFilePath(const GURL& url, FilePath* path) { } bool GetNetworkList(NetworkInterfaceList* networks) { +#if defined(OS_ANDROID) + // TODO: Android API doesn't support ifaddrs. This method was only used by + // P2PMessage. Consider to implement it until really needed. The possible + // approach is implementing the similar feature by + // java.net.NetworkInterface through JNI. + NOTIMPLEMENTED(); + return false; +#else // getifaddrs() may require IO operations. base::ThreadRestrictions::AssertIOAllowed(); @@ -79,6 +90,7 @@ bool GetNetworkList(NetworkInterfaceList* networks) { freeifaddrs(ifaddr); return true; +#endif } } // namespace net diff --git a/net/base/network_change_notifier.cc b/net/base/network_change_notifier.cc index aac93f1..5fa0645 100644 --- a/net/base/network_change_notifier.cc +++ b/net/base/network_change_notifier.cc @@ -6,7 +6,7 @@ #include "build/build_config.h" #if defined(OS_WIN) #include "net/base/network_change_notifier_win.h" -#elif defined(OS_LINUX) +#elif defined(OS_LINUX) || defined(OS_ANDROID) #include "net/base/network_change_notifier_linux.h" #elif defined(OS_MACOSX) #include "net/base/network_change_notifier_mac.h" @@ -37,7 +37,7 @@ NetworkChangeNotifier::~NetworkChangeNotifier() { NetworkChangeNotifier* NetworkChangeNotifier::Create() { #if defined(OS_WIN) return new NetworkChangeNotifierWin(); -#elif defined(OS_LINUX) +#elif defined(OS_LINUX) || defined(OS_ANDROID) return new NetworkChangeNotifierLinux(); #elif defined(OS_MACOSX) return new NetworkChangeNotifierMac(); |