| 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/network_list.h" | 5 #include "chrome/browser/chromeos/network_list.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "chrome/browser/chromeos/cros/cros_library.h" | 9 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 10 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
| 11 | 11 |
| 12 namespace chromeos { | 12 namespace chromeos { |
| 13 | 13 |
| 14 NetworkList::NetworkList() | 14 NetworkList::NetworkList() |
| 15 : connected_network_index_(-1), | 15 : connected_network_index_(-1), |
| 16 connecting_network_index_(-1) { | 16 connecting_network_index_(-1) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 NetworkList::NetworkItem* NetworkList::GetNetworkAt(int index) { | 19 NetworkList::NetworkItem* NetworkList::GetNetworkAt(int index) { |
| 20 return index >= 0 && index < static_cast<int>(networks_.size()) ? | 20 return index >= 0 && index < size() ? &networks_[index] : NULL; |
| 21 &networks_[index] : NULL; | |
| 22 } | 21 } |
| 23 | 22 |
| 24 const NetworkList::NetworkItem* NetworkList::GetNetworkById(NetworkType type, | 23 const NetworkList::NetworkItem* NetworkList::GetNetworkById(NetworkType type, |
| 25 const string16& id) { | 24 const string16& id) { |
| 26 return GetNetworkAt(GetNetworkIndexById(type, id)); | 25 return GetNetworkAt(GetNetworkIndexById(type, id)); |
| 27 } | 26 } |
| 28 | 27 |
| 29 int NetworkList::GetNetworkIndexById(NetworkType type, | 28 int NetworkList::GetNetworkIndexById(NetworkType type, |
| 30 const string16& id) const { | 29 const string16& id) const { |
| 31 if (NETWORK_EMPTY == type || id.empty()) return -1; | 30 if (NETWORK_EMPTY == type || id.empty()) return -1; |
| 32 std::string network_id = UTF16ToASCII(id); | 31 std::string network_id = UTF16ToASCII(id); |
| 33 for (size_t i = 0; i < networks_.size(); i++) { | 32 for (int i = 0; i < size(); ++i) { |
| 34 if (type == networks_[i].network_type) { | 33 if (type == networks_[i].network_type) { |
| 35 switch (type) { | 34 switch (type) { |
| 36 case NETWORK_ETHERNET: | 35 case NETWORK_ETHERNET: |
| 37 // Assuming that there's only single Ethernet network. | 36 // Assuming that there's only single Ethernet network. |
| 38 return i; | 37 return i; |
| 39 | 38 |
| 40 case NETWORK_WIFI: | 39 case NETWORK_WIFI: |
| 41 if (network_id == networks_[i].wifi_network.ssid) | 40 if (network_id == networks_[i].wifi_network.ssid) |
| 42 return i; | 41 return i; |
| 43 break; | 42 break; |
| 44 | 43 |
| 45 case NETWORK_CELLULAR: | 44 case NETWORK_CELLULAR: |
| 46 if (network_id == networks_[i].cellular_network.name) | 45 if (network_id == networks_[i].cellular_network.name) |
| 47 return i; | 46 return i; |
| 48 break; | 47 break; |
| 49 | 48 |
| 50 default: | 49 default: |
| 51 break; | 50 break; |
| 52 } | 51 } |
| 53 } | 52 } |
| 54 } | 53 } |
| 55 return -1; | 54 return -1; |
| 56 } | 55 } |
| 57 | 56 |
| 58 // Returns currently connected network if there is one. | 57 // Returns currently connected network if there is one. |
| 59 const NetworkList::NetworkItem* NetworkList::ConnectedNetwork() const { | 58 const NetworkList::NetworkItem* NetworkList::ConnectedNetwork() const { |
| 60 if (connected_network_index_ >= 0 && | 59 if (connected_network_index_ >= 0 && connected_network_index_ < size()) |
| 61 connected_network_index_ < static_cast<int>(networks_.size())) { | |
| 62 return &networks_[connected_network_index_]; | 60 return &networks_[connected_network_index_]; |
| 63 } else { | 61 return NULL; |
| 64 return NULL; | |
| 65 } | |
| 66 } | 62 } |
| 67 | 63 |
| 68 // Returns currently connecting network if there is one. | 64 // Returns currently connecting network if there is one. |
| 69 const NetworkList::NetworkItem* NetworkList::ConnectingNetwork() const { | 65 const NetworkList::NetworkItem* NetworkList::ConnectingNetwork() const { |
| 70 if (connecting_network_index_ >= 0 && | 66 if (connecting_network_index_ >= 0 && connecting_network_index_ < size()) |
| 71 connecting_network_index_ < static_cast<int>(networks_.size())) { | |
| 72 return &networks_[connecting_network_index_]; | 67 return &networks_[connecting_network_index_]; |
| 73 } else { | 68 return NULL; |
| 74 return NULL; | |
| 75 } | |
| 76 } | 69 } |
| 77 | 70 |
| 78 void NetworkList::NetworkChanged(chromeos::NetworkLibrary* network_lib) { | 71 void NetworkList::NetworkChanged(chromeos::NetworkLibrary* network_lib) { |
| 79 connected_network_index_ = -1; | 72 connected_network_index_ = -1; |
| 80 connecting_network_index_ = -1; | 73 connecting_network_index_ = -1; |
| 81 networks_.clear(); | 74 networks_.clear(); |
| 82 // Index of the last added network item. | 75 // Index of the last added network item. |
| 83 int index = 0; | 76 int index = 0; |
| 84 if (!network_lib || !CrosLibrary::Get()->EnsureLoaded()) | 77 if (!network_lib || !CrosLibrary::Get()->EnsureLoaded()) |
| 85 return; | 78 return; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 network_lib->cellular_connecting()); | 117 network_lib->cellular_connecting()); |
| 125 } | 118 } |
| 126 } | 119 } |
| 127 } | 120 } |
| 128 | 121 |
| 129 void NetworkList::SetNetworksIndices(int index, | 122 void NetworkList::SetNetworksIndices(int index, |
| 130 bool connected, | 123 bool connected, |
| 131 bool connecting) { | 124 bool connecting) { |
| 132 if (connected_network_index_ != -1 || | 125 if (connected_network_index_ != -1 || |
| 133 connecting_network_index_ != -1 || | 126 connecting_network_index_ != -1 || |
| 134 index < 0 || index >= static_cast<int>(networks_.size())) | 127 index < 0 || index >= size()) { |
| 135 return; | 128 return; |
| 129 } |
| 136 | 130 |
| 137 if (connected) { | 131 if (connected) |
| 138 connected_network_index_ = index; | 132 connected_network_index_ = index; |
| 139 } else if (connecting) { | 133 else if (connecting) |
| 140 connecting_network_index_ = index; | 134 connecting_network_index_ = index; |
| 141 } | |
| 142 } | 135 } |
| 143 | 136 |
| 144 } // namespace chromeos | 137 } // namespace chromeos |
| OLD | NEW |