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

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

Powered by Google App Engine
This is Rietveld 408576698