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 "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 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1818 } | 1818 } |
1819 | 1819 |
1820 void NetworkLibraryImplBase::RemoveUserActionObserver( | 1820 void NetworkLibraryImplBase::RemoveUserActionObserver( |
1821 UserActionObserver* observer) { | 1821 UserActionObserver* observer) { |
1822 user_action_observers_.RemoveObserver(observer); | 1822 user_action_observers_.RemoveObserver(observer); |
1823 } | 1823 } |
1824 | 1824 |
1825 // Use flimflam's ordering of the services to determine which type of | 1825 // Use flimflam's ordering of the services to determine which type of |
1826 // network to return (i.e. don't assume priority of network types). | 1826 // network to return (i.e. don't assume priority of network types). |
1827 // Note: This does not include any virtual networks. | 1827 // Note: This does not include any virtual networks. |
| 1828 namespace { |
| 1829 Network* highest_priority(Network* a, Network*b) { |
| 1830 if (!a) |
| 1831 return b; |
| 1832 if (!b) |
| 1833 return a; |
| 1834 if (b->priority_order() < a->priority_order()) |
| 1835 return b; |
| 1836 return a; |
| 1837 } |
| 1838 } |
| 1839 |
1828 const Network* NetworkLibraryImplBase::active_network() const { | 1840 const Network* NetworkLibraryImplBase::active_network() const { |
1829 Network* result = NULL; | 1841 Network* result = NULL; |
1830 if (ethernet_ && ethernet_->is_active()) | 1842 if (ethernet_ && ethernet_->is_active()) |
1831 result = ethernet_; | 1843 result = ethernet_; |
1832 if ((active_wifi_ && active_wifi_->is_active()) && | 1844 if (active_wifi_ && active_wifi_->is_active()) |
1833 (!result || | 1845 result = highest_priority(result, active_wifi_); |
1834 active_wifi_->priority_order_ < result->priority_order_)) | 1846 if (active_cellular_ && active_cellular_->is_active()) |
1835 result = active_wifi_; | 1847 result = highest_priority(result, active_cellular_); |
1836 if ((active_cellular_ && active_cellular_->is_active()) && | 1848 if (active_virtual_ && active_virtual_->is_active()) |
1837 (!result || | 1849 result = highest_priority(result, active_virtual_); |
1838 active_cellular_->priority_order_ < result->priority_order_)) | |
1839 result = active_cellular_; | |
1840 return result; | 1850 return result; |
1841 } | 1851 } |
1842 | 1852 |
1843 const Network* NetworkLibraryImplBase::connected_network() const { | 1853 const Network* NetworkLibraryImplBase::connected_network() const { |
1844 Network* result = NULL; | 1854 Network* result = NULL; |
1845 if (ethernet_ && ethernet_->connected()) | 1855 if (ethernet_ && ethernet_->connected()) |
1846 result = ethernet_; | 1856 result = ethernet_; |
1847 if ((active_wifi_ && active_wifi_->connected()) && | 1857 if (active_wifi_ && active_wifi_->connected()) |
1848 (!result || | 1858 result = highest_priority(result, active_wifi_); |
1849 active_wifi_->priority_order_ < result->priority_order_)) | 1859 if (active_cellular_ && active_cellular_->connected()) |
1850 result = active_wifi_; | 1860 result = highest_priority(result, active_cellular_); |
1851 if ((active_cellular_ && active_cellular_->connected()) && | |
1852 (!result || | |
1853 active_cellular_->priority_order_ < result->priority_order_)) | |
1854 result = active_cellular_; | |
1855 return result; | 1861 return result; |
1856 } | 1862 } |
1857 | 1863 |
1858 // Connecting order in logical prefernce. | 1864 // Connecting order in logical prefernce. |
1859 const Network* NetworkLibraryImplBase::connecting_network() const { | 1865 const Network* NetworkLibraryImplBase::connecting_network() const { |
1860 if (ethernet_connecting()) | 1866 if (ethernet_connecting()) |
1861 return ethernet_network(); | 1867 return ethernet_network(); |
1862 else if (wifi_connecting()) | 1868 else if (wifi_connecting()) |
1863 return wifi_network(); | 1869 return wifi_network(); |
1864 else if (cellular_connecting()) | 1870 else if (cellular_connecting()) |
(...skipping 2729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4594 return network_library; | 4600 return network_library; |
4595 } | 4601 } |
4596 | 4602 |
4597 ///////////////////////////////////////////////////////////////////////////// | 4603 ///////////////////////////////////////////////////////////////////////////// |
4598 | 4604 |
4599 } // namespace chromeos | 4605 } // namespace chromeos |
4600 | 4606 |
4601 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 4607 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
4602 // won't be deleted until it's last InvokeLater is run. | 4608 // won't be deleted until it's last InvokeLater is run. |
4603 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); | 4609 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); |
OLD | NEW |