| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "net/base/net_util.h" | 5 #include "net/base/net_util.h" |
| 6 | 6 |
| 7 #include <sys/types.h> | 7 #include <sys/types.h> |
| 8 | 8 |
| 9 #include "base/eintr_wrapper.h" | 9 #include "base/eintr_wrapper.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/string_tokenizer.h" |
| 12 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 13 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
| 14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 15 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
| 16 #include "net/base/ip_endpoint.h" | 17 #include "net/base/ip_endpoint.h" |
| 17 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 18 | 19 |
| 19 #if !defined(OS_ANDROID) | 20 #if !defined(OS_ANDROID) |
| 20 #include <ifaddrs.h> | 21 #include <ifaddrs.h> |
| 21 #endif | 22 #endif |
| 22 #include <net/if.h> | 23 #include <net/if.h> |
| 23 #include <netinet/in.h> | 24 #include <netinet/in.h> |
| 24 | 25 |
| 26 #if defined(OS_ANDROID) |
| 27 #include "net/android/network_library.h" |
| 28 #endif |
| 29 |
| 25 namespace net { | 30 namespace net { |
| 26 | 31 |
| 27 bool FileURLToFilePath(const GURL& url, FilePath* path) { | 32 bool FileURLToFilePath(const GURL& url, FilePath* path) { |
| 28 *path = FilePath(); | 33 *path = FilePath(); |
| 29 std::string& file_path_str = const_cast<std::string&>(path->value()); | 34 std::string& file_path_str = const_cast<std::string&>(path->value()); |
| 30 file_path_str.clear(); | 35 file_path_str.clear(); |
| 31 | 36 |
| 32 if (!url.is_valid()) | 37 if (!url.is_valid()) |
| 33 return false; | 38 return false; |
| 34 | 39 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 53 old_path.swap(new_path); | 58 old_path.swap(new_path); |
| 54 } while (new_path != old_path); | 59 } while (new_path != old_path); |
| 55 | 60 |
| 56 file_path_str.assign(old_path); | 61 file_path_str.assign(old_path); |
| 57 | 62 |
| 58 return !file_path_str.empty(); | 63 return !file_path_str.empty(); |
| 59 } | 64 } |
| 60 | 65 |
| 61 bool GetNetworkList(NetworkInterfaceList* networks) { | 66 bool GetNetworkList(NetworkInterfaceList* networks) { |
| 62 #if defined(OS_ANDROID) | 67 #if defined(OS_ANDROID) |
| 63 // TODO: Android API doesn't support ifaddrs. This method was only used by | 68 std::string network_list = android::GetNetworkList(); |
| 64 // P2PMessage. Consider to implement it until really needed. The possible | 69 StringTokenizer network_interfaces(network_list, ";"); |
| 65 // approach is implementing the similar feature by | 70 while (network_interfaces.GetNext()) { |
| 66 // java.net.NetworkInterface through JNI. | 71 std::string network_item = network_interfaces.token(); |
| 67 NOTIMPLEMENTED(); | 72 StringTokenizer network_tokenizer(network_item, ","); |
| 68 return false; | 73 std::string name; |
| 74 if (!network_tokenizer.GetNext()) |
| 75 continue; |
| 76 name = network_tokenizer.token(); |
| 77 |
| 78 std::string literal_address; |
| 79 if (!network_tokenizer.GetNext()) |
| 80 continue; |
| 81 literal_address = network_tokenizer.token(); |
| 82 |
| 83 IPAddressNumber address; |
| 84 if (!ParseIPLiteralToNumber(literal_address, &address)) |
| 85 continue; |
| 86 networks->push_back(NetworkInterface(name, address)); |
| 87 } |
| 88 return true; |
| 69 #else | 89 #else |
| 70 // getifaddrs() may require IO operations. | 90 // getifaddrs() may require IO operations. |
| 71 base::ThreadRestrictions::AssertIOAllowed(); | 91 base::ThreadRestrictions::AssertIOAllowed(); |
| 72 | 92 |
| 73 ifaddrs *interfaces; | 93 ifaddrs *interfaces; |
| 74 if (getifaddrs(&interfaces) < 0) { | 94 if (getifaddrs(&interfaces) < 0) { |
| 75 PLOG(ERROR) << "getifaddrs"; | 95 PLOG(ERROR) << "getifaddrs"; |
| 76 return false; | 96 return false; |
| 77 } | 97 } |
| 78 | 98 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 } | 135 } |
| 116 } | 136 } |
| 117 | 137 |
| 118 freeifaddrs(interfaces); | 138 freeifaddrs(interfaces); |
| 119 | 139 |
| 120 return true; | 140 return true; |
| 121 #endif | 141 #endif |
| 122 } | 142 } |
| 123 | 143 |
| 124 } // namespace net | 144 } // namespace net |
| OLD | NEW |