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

Side by Side Diff: chrome/browser/chromeos/cros/network_library.cc

Issue 6899025: Show hardware addresses for wifi and ethernet networks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: z Created 9 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 | Annotate | Revision Log
OLDNEW
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 "chrome/browser/chromeos/cros/network_library.h" 5 #include "chrome/browser/chromeos/cros/network_library.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/i18n/time_formatting.h" 10 #include "base/i18n/time_formatting.h"
(...skipping 2198 matching lines...) Expand 10 before | Expand all | Expand 10 after
2209 2209
2210 virtual const NetworkDevice* FindCellularDevice() const { 2210 virtual const NetworkDevice* FindCellularDevice() const {
2211 for (NetworkDeviceMap::const_iterator iter = device_map_.begin(); 2211 for (NetworkDeviceMap::const_iterator iter = device_map_.begin();
2212 iter != device_map_.end(); ++iter) { 2212 iter != device_map_.end(); ++iter) {
2213 if (iter->second->type() == TYPE_CELLULAR) 2213 if (iter->second->type() == TYPE_CELLULAR)
2214 return iter->second; 2214 return iter->second;
2215 } 2215 }
2216 return NULL; 2216 return NULL;
2217 } 2217 }
2218 2218
2219 virtual NetworkDeviceVector FindEthernetDevices() const {
2220 NetworkDeviceVector rv;
2221 for (NetworkDeviceMap::const_iterator iter = device_map_.begin();
2222 iter != device_map_.end(); ++iter) {
2223 if (iter->second->type() == TYPE_ETHERNET)
2224 rv.push_back(iter->second);
stevenjb 2011/04/25 17:54:27 return iter->second (first ethernet device; see co
Denis Lagno 2011/04/26 15:54:58 Done.
2225 }
2226 return rv;
2227 }
2228
2229 virtual NetworkDeviceVector FindWifiDevices() const {
2230 NetworkDeviceVector rv;
2231 for (NetworkDeviceMap::const_iterator iter = device_map_.begin();
2232 iter != device_map_.end(); ++iter) {
2233 if (iter->second->type() == TYPE_WIFI)
2234 rv.push_back(iter->second);
stevenjb 2011/04/25 17:54:27 return iter->second (first wifi device; see commen
Denis Lagno 2011/04/26 15:54:58 Done.
2235 }
2236 return rv;
2237 }
2238
2219 virtual Network* FindNetworkByPath(const std::string& path) const { 2239 virtual Network* FindNetworkByPath(const std::string& path) const {
2220 NetworkMap::const_iterator iter = network_map_.find(path); 2240 NetworkMap::const_iterator iter = network_map_.find(path);
2221 if (iter != network_map_.end()) 2241 if (iter != network_map_.end())
2222 return iter->second; 2242 return iter->second;
2223 return NULL; 2243 return NULL;
2224 } 2244 }
2225 2245
2226 WirelessNetwork* FindWirelessNetworkByPath(const std::string& path) const { 2246 WirelessNetwork* FindWirelessNetworkByPath(const std::string& path) const {
2227 Network* network = FindNetworkByPath(path); 2247 Network* network = FindNetworkByPath(path);
2228 if (network && 2248 if (network &&
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
2824 VLOG(1) << "Trying to disable offline mode when it's already disabled."; 2844 VLOG(1) << "Trying to disable offline mode when it's already disabled.";
2825 return; 2845 return;
2826 } 2846 }
2827 2847
2828 if (SetOfflineMode(enable)) { 2848 if (SetOfflineMode(enable)) {
2829 offline_mode_ = enable; 2849 offline_mode_ = enable;
2830 } 2850 }
2831 } 2851 }
2832 2852
2833 virtual NetworkIPConfigVector GetIPConfigs(const std::string& device_path, 2853 virtual NetworkIPConfigVector GetIPConfigs(const std::string& device_path,
2834 std::string* hardware_address) { 2854 std::string* hardware_address,
2855 HardwareAddressFormat format) {
stevenjb 2011/04/25 17:54:27 DCHECK(hardware_address)
Denis Lagno 2011/04/26 15:54:58 Done.
2835 hardware_address->clear(); 2856 hardware_address->clear();
2836 NetworkIPConfigVector ipconfig_vector; 2857 NetworkIPConfigVector ipconfig_vector;
2837 if (EnsureCrosLoaded() && !device_path.empty()) { 2858 if (EnsureCrosLoaded() && !device_path.empty()) {
2838 IPConfigStatus* ipconfig_status = ListIPConfigs(device_path.c_str()); 2859 IPConfigStatus* ipconfig_status = ListIPConfigs(device_path.c_str());
2839 if (ipconfig_status) { 2860 if (ipconfig_status) {
2840 for (int i = 0; i < ipconfig_status->size; i++) { 2861 for (int i = 0; i < ipconfig_status->size; i++) {
2841 IPConfig ipconfig = ipconfig_status->ips[i]; 2862 IPConfig ipconfig = ipconfig_status->ips[i];
2842 ipconfig_vector.push_back( 2863 ipconfig_vector.push_back(
2843 NetworkIPConfig(device_path, ipconfig.type, ipconfig.address, 2864 NetworkIPConfig(device_path, ipconfig.type, ipconfig.address,
2844 ipconfig.netmask, ipconfig.gateway, 2865 ipconfig.netmask, ipconfig.gateway,
2845 ipconfig.name_servers)); 2866 ipconfig.name_servers));
2846 } 2867 }
2847 *hardware_address = ipconfig_status->hardware_address; 2868 *hardware_address = ipconfig_status->hardware_address;
2848 FreeIPConfigStatus(ipconfig_status); 2869 FreeIPConfigStatus(ipconfig_status);
2849 // Sort the list of ip configs by type. 2870 // Sort the list of ip configs by type.
2850 std::sort(ipconfig_vector.begin(), ipconfig_vector.end()); 2871 std::sort(ipconfig_vector.begin(), ipconfig_vector.end());
2851 } 2872 }
2852 } 2873 }
2874
2875 for (size_t i = 0; i < hardware_address->size(); ++i)
2876 (*hardware_address)[i] = toupper((*hardware_address)[i]);
2877 if (format == FORMAT_COLON_SEPARATED_HEX) {
2878 if (hardware_address->size() == 6 * 2) {
2879 std::string output;
2880 for (size_t i = 0; i < hardware_address->size(); ++i) {
2881 if (i != 0 && i % 2 == 0)
stevenjb 2011/04/25 17:54:27 nit: if ((i != 0) && (i % 2 == 0))
Denis Lagno 2011/04/26 15:54:58 Done.
2882 output.push_back(':');
2883 output.push_back((*hardware_address)[i]);
2884 }
2885 hardware_address->swap(output);
stevenjb 2011/04/25 17:54:27 hardware_address = output; (no reason to swap)
Denis Lagno 2011/04/26 15:54:58 Done.
2886 }
2887 } else {
2888 DCHECK(format == FORMAT_RAW_HEX);
2889 }
2890
2853 return ipconfig_vector; 2891 return ipconfig_vector;
2854 } 2892 }
2855 2893
2856 private: 2894 private:
2857 2895
2858 typedef std::map<std::string, Network*> NetworkMap; 2896 typedef std::map<std::string, Network*> NetworkMap;
2859 typedef std::map<std::string, int> PriorityMap; 2897 typedef std::map<std::string, int> PriorityMap;
2860 typedef std::map<std::string, NetworkDevice*> NetworkDeviceMap; 2898 typedef std::map<std::string, NetworkDevice*> NetworkDeviceMap;
2861 typedef std::map<std::string, CellularDataPlanVector*> CellularDataPlanMap; 2899 typedef std::map<std::string, CellularDataPlanVector*> CellularDataPlanMap;
2862 2900
(...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after
4195 virtual bool has_cellular_networks() const { 4233 virtual bool has_cellular_networks() const {
4196 return cellular_networks_.begin() != cellular_networks_.end(); 4234 return cellular_networks_.begin() != cellular_networks_.end();
4197 } 4235 }
4198 ///////////////////////////////////////////////////////////////////////////// 4236 /////////////////////////////////////////////////////////////////////////////
4199 4237
4200 virtual const NetworkDevice* FindNetworkDeviceByPath( 4238 virtual const NetworkDevice* FindNetworkDeviceByPath(
4201 const std::string& path) const { return NULL; } 4239 const std::string& path) const { return NULL; }
4202 virtual const NetworkDevice* FindCellularDevice() const { 4240 virtual const NetworkDevice* FindCellularDevice() const {
4203 return NULL; 4241 return NULL;
4204 } 4242 }
4243 virtual NetworkDeviceVector FindEthernetDevices() const {
4244 return NetworkDeviceVector();
4245 }
4246 virtual NetworkDeviceVector FindWifiDevices() const {
4247 return NetworkDeviceVector();
4248 }
4205 virtual Network* FindNetworkByPath( 4249 virtual Network* FindNetworkByPath(
4206 const std::string& path) const { return NULL; } 4250 const std::string& path) const { return NULL; }
4207 virtual WifiNetwork* FindWifiNetworkByPath( 4251 virtual WifiNetwork* FindWifiNetworkByPath(
4208 const std::string& path) const { return NULL; } 4252 const std::string& path) const { return NULL; }
4209 virtual CellularNetwork* FindCellularNetworkByPath( 4253 virtual CellularNetwork* FindCellularNetworkByPath(
4210 const std::string& path) const { return NULL; } 4254 const std::string& path) const { return NULL; }
4211 virtual VirtualNetwork* FindVirtualNetworkByPath( 4255 virtual VirtualNetwork* FindVirtualNetworkByPath(
4212 const std::string& path) const { return NULL; } 4256 const std::string& path) const { return NULL; }
4213 virtual Network* FindNetworkFromRemembered( 4257 virtual Network* FindNetworkFromRemembered(
4214 const Network* remembered) const { return NULL; } 4258 const Network* remembered) const { return NULL; }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
4266 virtual bool cellular_enabled() const { return false; } 4310 virtual bool cellular_enabled() const { return false; }
4267 virtual bool wifi_scanning() const { return false; } 4311 virtual bool wifi_scanning() const { return false; }
4268 virtual const Network* active_network() const { return NULL; } 4312 virtual const Network* active_network() const { return NULL; }
4269 virtual const Network* connected_network() const { return NULL; } 4313 virtual const Network* connected_network() const { return NULL; }
4270 virtual bool offline_mode() const { return false; } 4314 virtual bool offline_mode() const { return false; }
4271 virtual void EnableEthernetNetworkDevice(bool enable) {} 4315 virtual void EnableEthernetNetworkDevice(bool enable) {}
4272 virtual void EnableWifiNetworkDevice(bool enable) {} 4316 virtual void EnableWifiNetworkDevice(bool enable) {}
4273 virtual void EnableCellularNetworkDevice(bool enable) {} 4317 virtual void EnableCellularNetworkDevice(bool enable) {}
4274 virtual void EnableOfflineMode(bool enable) {} 4318 virtual void EnableOfflineMode(bool enable) {}
4275 virtual NetworkIPConfigVector GetIPConfigs(const std::string& device_path, 4319 virtual NetworkIPConfigVector GetIPConfigs(const std::string& device_path,
4276 std::string* hardware_address) { 4320 std::string* hardware_address,
4321 HardwareAddressFormat) {
4277 hardware_address->clear(); 4322 hardware_address->clear();
4278 return NetworkIPConfigVector(); 4323 return NetworkIPConfigVector();
4279 } 4324 }
4280 4325
4281 private: 4326 private:
4282 std::string ip_address_; 4327 std::string ip_address_;
4283 EthernetNetwork* ethernet_; 4328 EthernetNetwork* ethernet_;
4284 WifiNetwork* active_wifi_; 4329 WifiNetwork* active_wifi_;
4285 CellularNetwork* active_cellular_; 4330 CellularNetwork* active_cellular_;
4286 VirtualNetwork* active_virtual_; 4331 VirtualNetwork* active_virtual_;
4287 WifiNetworkVector wifi_networks_; 4332 WifiNetworkVector wifi_networks_;
4288 CellularNetworkVector cellular_networks_; 4333 CellularNetworkVector cellular_networks_;
4289 VirtualNetworkVector virtual_networks_; 4334 VirtualNetworkVector virtual_networks_;
4290 }; 4335 };
4291 4336
4292 // static 4337 // static
4293 NetworkLibrary* NetworkLibrary::GetImpl(bool stub) { 4338 NetworkLibrary* NetworkLibrary::GetImpl(bool stub) {
4294 if (stub) 4339 if (stub)
4295 return new NetworkLibraryStubImpl(); 4340 return new NetworkLibraryStubImpl();
4296 else 4341 else
4297 return new NetworkLibraryImpl(); 4342 return new NetworkLibraryImpl();
4298 } 4343 }
4299 4344
4300 } // namespace chromeos 4345 } // namespace chromeos
4301 4346
4302 // Allows InvokeLater without adding refcounting. This class is a Singleton and 4347 // Allows InvokeLater without adding refcounting. This class is a Singleton and
4303 // won't be deleted until it's last InvokeLater is run. 4348 // won't be deleted until it's last InvokeLater is run.
4304 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl); 4349 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698