| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 : network_manager_monitor_(NULL), | 835 : network_manager_monitor_(NULL), |
| 836 data_plan_monitor_(NULL), | 836 data_plan_monitor_(NULL), |
| 837 ethernet_(NULL), | 837 ethernet_(NULL), |
| 838 wifi_(NULL), | 838 wifi_(NULL), |
| 839 cellular_(NULL), | 839 cellular_(NULL), |
| 840 available_devices_(0), | 840 available_devices_(0), |
| 841 enabled_devices_(0), | 841 enabled_devices_(0), |
| 842 connected_devices_(0), | 842 connected_devices_(0), |
| 843 wifi_scanning_(false), | 843 wifi_scanning_(false), |
| 844 offline_mode_(false), | 844 offline_mode_(false), |
| 845 is_locked_(false), |
| 845 update_task_(NULL) { | 846 update_task_(NULL) { |
| 846 if (EnsureCrosLoaded()) { | 847 if (EnsureCrosLoaded()) { |
| 847 Init(); | 848 Init(); |
| 848 network_manager_monitor_ = | 849 network_manager_monitor_ = |
| 849 MonitorNetworkManager(&NetworkManagerStatusChangedHandler, | 850 MonitorNetworkManager(&NetworkManagerStatusChangedHandler, |
| 850 this); | 851 this); |
| 851 data_plan_monitor_ = MonitorCellularDataPlan(&DataPlanUpdateHandler, | 852 data_plan_monitor_ = MonitorCellularDataPlan(&DataPlanUpdateHandler, |
| 852 this); | 853 this); |
| 853 network_login_observer_.reset(new NetworkLoginObserver(this)); | 854 network_login_observer_.reset(new NetworkLoginObserver(this)); |
| 854 } else { | 855 } else { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 map_iter->second->RemoveObserver(observer); | 934 map_iter->second->RemoveObserver(observer); |
| 934 if (!map_iter->second->size()) { | 935 if (!map_iter->second->size()) { |
| 935 delete map_iter->second; | 936 delete map_iter->second; |
| 936 network_observers_.erase(map_iter++); | 937 network_observers_.erase(map_iter++); |
| 937 } else { | 938 } else { |
| 938 ++map_iter; | 939 ++map_iter; |
| 939 } | 940 } |
| 940 } | 941 } |
| 941 } | 942 } |
| 942 | 943 |
| 944 virtual void Lock() { |
| 945 if (is_locked_) |
| 946 return; |
| 947 is_locked_ = true; |
| 948 NotifyNetworkManagerChanged(); |
| 949 } |
| 950 |
| 951 virtual void Unlock() { |
| 952 DCHECK(is_locked_); |
| 953 if (!is_locked_) |
| 954 return; |
| 955 is_locked_ = false; |
| 956 NotifyNetworkManagerChanged(); |
| 957 } |
| 958 |
| 959 virtual bool IsLocked() { |
| 960 return is_locked_; |
| 961 } |
| 962 |
| 943 virtual void AddCellularDataPlanObserver(CellularDataPlanObserver* observer) { | 963 virtual void AddCellularDataPlanObserver(CellularDataPlanObserver* observer) { |
| 944 if (!data_plan_observers_.HasObserver(observer)) | 964 if (!data_plan_observers_.HasObserver(observer)) |
| 945 data_plan_observers_.AddObserver(observer); | 965 data_plan_observers_.AddObserver(observer); |
| 946 } | 966 } |
| 947 | 967 |
| 948 virtual void RemoveCellularDataPlanObserver( | 968 virtual void RemoveCellularDataPlanObserver( |
| 949 CellularDataPlanObserver* observer) { | 969 CellularDataPlanObserver* observer) { |
| 950 data_plan_observers_.RemoveObserver(observer); | 970 data_plan_observers_.RemoveObserver(observer); |
| 951 } | 971 } |
| 952 | 972 |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 } | 1313 } |
| 1294 if (cellular_ && cellular_->connected()) { | 1314 if (cellular_ && cellular_->connected()) { |
| 1295 cellular_->set_active(true); | 1315 cellular_->set_active(true); |
| 1296 return cellular_; | 1316 return cellular_; |
| 1297 } | 1317 } |
| 1298 // END BUG 9310 WORKAROUND | 1318 // END BUG 9310 WORKAROUND |
| 1299 return NULL; | 1319 return NULL; |
| 1300 } | 1320 } |
| 1301 | 1321 |
| 1302 virtual void EnableEthernetNetworkDevice(bool enable) { | 1322 virtual void EnableEthernetNetworkDevice(bool enable) { |
| 1323 if (is_locked_) |
| 1324 return; |
| 1303 EnableNetworkDeviceType(TYPE_ETHERNET, enable); | 1325 EnableNetworkDeviceType(TYPE_ETHERNET, enable); |
| 1304 } | 1326 } |
| 1305 | 1327 |
| 1306 virtual void EnableWifiNetworkDevice(bool enable) { | 1328 virtual void EnableWifiNetworkDevice(bool enable) { |
| 1329 if (is_locked_) |
| 1330 return; |
| 1307 EnableNetworkDeviceType(TYPE_WIFI, enable); | 1331 EnableNetworkDeviceType(TYPE_WIFI, enable); |
| 1308 } | 1332 } |
| 1309 | 1333 |
| 1310 virtual void EnableCellularNetworkDevice(bool enable) { | 1334 virtual void EnableCellularNetworkDevice(bool enable) { |
| 1335 if (is_locked_) |
| 1336 return; |
| 1311 EnableNetworkDeviceType(TYPE_CELLULAR, enable); | 1337 EnableNetworkDeviceType(TYPE_CELLULAR, enable); |
| 1312 } | 1338 } |
| 1313 | 1339 |
| 1314 virtual void EnableOfflineMode(bool enable) { | 1340 virtual void EnableOfflineMode(bool enable) { |
| 1315 if (!EnsureCrosLoaded()) | 1341 if (!EnsureCrosLoaded()) |
| 1316 return; | 1342 return; |
| 1317 | 1343 |
| 1318 // If network device is already enabled/disabled, then don't do anything. | 1344 // If network device is already enabled/disabled, then don't do anything. |
| 1319 if (enable && offline_mode_) { | 1345 if (enable && offline_mode_) { |
| 1320 VLOG(1) << "Trying to enable offline mode when it's already enabled."; | 1346 VLOG(1) << "Trying to enable offline mode when it's already enabled."; |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1590 } | 1616 } |
| 1591 | 1617 |
| 1592 void Init() { | 1618 void Init() { |
| 1593 // First, get the currently available networks. This data is cached | 1619 // First, get the currently available networks. This data is cached |
| 1594 // on the connman side, so the call should be quick. | 1620 // on the connman side, so the call should be quick. |
| 1595 VLOG(1) << "Getting initial CrOS network info."; | 1621 VLOG(1) << "Getting initial CrOS network info."; |
| 1596 UpdateSystemInfo(); | 1622 UpdateSystemInfo(); |
| 1597 } | 1623 } |
| 1598 | 1624 |
| 1599 void InitTestData() { | 1625 void InitTestData() { |
| 1626 is_locked_ = true; |
| 1600 ethernet_ = new EthernetNetwork(); | 1627 ethernet_ = new EthernetNetwork(); |
| 1601 ethernet_->set_connected(true); | 1628 ethernet_->set_connected(true); |
| 1602 ethernet_->set_service_path("eth1"); | 1629 ethernet_->set_service_path("eth1"); |
| 1603 | 1630 |
| 1604 STLDeleteElements(&wifi_networks_); | 1631 STLDeleteElements(&wifi_networks_); |
| 1605 wifi_networks_.clear(); | 1632 wifi_networks_.clear(); |
| 1606 WifiNetwork* wifi1 = new WifiNetwork(); | 1633 WifiNetwork* wifi1 = new WifiNetwork(); |
| 1607 wifi1->set_service_path("fw1"); | 1634 wifi1->set_service_path("fw1"); |
| 1608 wifi1->set_name("Fake Wifi 1"); | 1635 wifi1->set_name("Fake Wifi 1"); |
| 1609 wifi1->set_strength(90); | 1636 wifi1->set_strength(90); |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1907 | 1934 |
| 1908 // The current connected network devices. Bitwise flag of ConnectionTypes. | 1935 // The current connected network devices. Bitwise flag of ConnectionTypes. |
| 1909 int connected_devices_; | 1936 int connected_devices_; |
| 1910 | 1937 |
| 1911 // True if we are currently scanning for wifi networks. | 1938 // True if we are currently scanning for wifi networks. |
| 1912 bool wifi_scanning_; | 1939 bool wifi_scanning_; |
| 1913 | 1940 |
| 1914 // Currently not implemented. TODO: implement or eliminate. | 1941 // Currently not implemented. TODO: implement or eliminate. |
| 1915 bool offline_mode_; | 1942 bool offline_mode_; |
| 1916 | 1943 |
| 1944 // True if access network library is locked. |
| 1945 bool is_locked_; |
| 1946 |
| 1917 // Delayed task to retrieve the network information. | 1947 // Delayed task to retrieve the network information. |
| 1918 CancelableTask* update_task_; | 1948 CancelableTask* update_task_; |
| 1919 | 1949 |
| 1920 // Cellular plan payment time. | 1950 // Cellular plan payment time. |
| 1921 base::Time cellular_plan_payment_time_; | 1951 base::Time cellular_plan_payment_time_; |
| 1922 | 1952 |
| 1923 DISALLOW_COPY_AND_ASSIGN(NetworkLibraryImpl); | 1953 DISALLOW_COPY_AND_ASSIGN(NetworkLibraryImpl); |
| 1924 }; | 1954 }; |
| 1925 | 1955 |
| 1926 class NetworkLibraryStubImpl : public NetworkLibrary { | 1956 class NetworkLibraryStubImpl : public NetworkLibrary { |
| 1927 public: | 1957 public: |
| 1928 NetworkLibraryStubImpl() | 1958 NetworkLibraryStubImpl() |
| 1929 : ip_address_("1.1.1.1"), | 1959 : ip_address_("1.1.1.1"), |
| 1930 ethernet_(new EthernetNetwork()), | 1960 ethernet_(new EthernetNetwork()), |
| 1931 wifi_(NULL), | 1961 wifi_(NULL), |
| 1932 cellular_(NULL) { | 1962 cellular_(NULL) { |
| 1933 } | 1963 } |
| 1934 ~NetworkLibraryStubImpl() { if (ethernet_) delete ethernet_; } | 1964 ~NetworkLibraryStubImpl() { if (ethernet_) delete ethernet_; } |
| 1935 virtual void AddNetworkManagerObserver(NetworkManagerObserver* observer) {} | 1965 virtual void AddNetworkManagerObserver(NetworkManagerObserver* observer) {} |
| 1936 virtual void RemoveNetworkManagerObserver(NetworkManagerObserver* observer) {} | 1966 virtual void RemoveNetworkManagerObserver(NetworkManagerObserver* observer) {} |
| 1937 virtual void AddNetworkObserver(const std::string& service_path, | 1967 virtual void AddNetworkObserver(const std::string& service_path, |
| 1938 NetworkObserver* observer) {} | 1968 NetworkObserver* observer) {} |
| 1939 virtual void RemoveNetworkObserver(const std::string& service_path, | 1969 virtual void RemoveNetworkObserver(const std::string& service_path, |
| 1940 NetworkObserver* observer) {} | 1970 NetworkObserver* observer) {} |
| 1941 virtual void RemoveObserverForAllNetworks(NetworkObserver* observer) {} | 1971 virtual void RemoveObserverForAllNetworks(NetworkObserver* observer) {} |
| 1972 virtual void Lock() {} |
| 1973 virtual void Unlock() {} |
| 1974 virtual bool IsLocked() { return true; } |
| 1942 virtual void AddCellularDataPlanObserver( | 1975 virtual void AddCellularDataPlanObserver( |
| 1943 CellularDataPlanObserver* observer) {} | 1976 CellularDataPlanObserver* observer) {} |
| 1944 virtual void RemoveCellularDataPlanObserver( | 1977 virtual void RemoveCellularDataPlanObserver( |
| 1945 CellularDataPlanObserver* observer) {} | 1978 CellularDataPlanObserver* observer) {} |
| 1946 virtual const EthernetNetwork* ethernet_network() const { | 1979 virtual const EthernetNetwork* ethernet_network() const { |
| 1947 return ethernet_; | 1980 return ethernet_; |
| 1948 } | 1981 } |
| 1949 virtual bool ethernet_connecting() const { return false; } | 1982 virtual bool ethernet_connecting() const { return false; } |
| 1950 virtual bool ethernet_connected() const { return true; } | 1983 virtual bool ethernet_connected() const { return true; } |
| 1951 virtual const WifiNetwork* wifi_network() const { | 1984 virtual const WifiNetwork* wifi_network() const { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2044 return new NetworkLibraryStubImpl(); | 2077 return new NetworkLibraryStubImpl(); |
| 2045 else | 2078 else |
| 2046 return new NetworkLibraryImpl(); | 2079 return new NetworkLibraryImpl(); |
| 2047 } | 2080 } |
| 2048 | 2081 |
| 2049 } // namespace chromeos | 2082 } // namespace chromeos |
| 2050 | 2083 |
| 2051 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 2084 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
| 2052 // won't be deleted until it's last InvokeLater is run. | 2085 // won't be deleted until it's last InvokeLater is run. |
| 2053 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl); | 2086 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl); |
| OLD | NEW |