| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chromeos/network/network_state_handler.h" | 5 #include "chromeos/network/network_state_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
| 12 #include "base/guid.h" | 12 #include "base/guid.h" |
| 13 #include "base/json/json_string_value_serializer.h" | 13 #include "base/json/json_string_value_serializer.h" |
| 14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/logging.h" | |
| 17 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 18 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
| 19 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 21 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 22 #include "base/values.h" | 21 #include "base/values.h" |
| 23 #include "chromeos/chromeos_switches.h" | 22 #include "chromeos/chromeos_switches.h" |
| 24 #include "chromeos/network/device_state.h" | 23 #include "chromeos/network/device_state.h" |
| 25 #include "chromeos/network/network_event_log.h" | 24 #include "chromeos/network/network_event_log.h" |
| 26 #include "chromeos/network/network_state.h" | 25 #include "chromeos/network/network_state.h" |
| 27 #include "chromeos/network/network_state_handler_observer.h" | 26 #include "chromeos/network/network_state_handler_observer.h" |
| 27 #include "chromeos/network/tether_constants.h" |
| 28 #include "third_party/cros_system_api/dbus/service_constants.h" | 28 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 29 | 29 |
| 30 namespace chromeos { | 30 namespace chromeos { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 bool ConnectionStateChanged(NetworkState* network, | 34 bool ConnectionStateChanged(NetworkState* network, |
| 35 const std::string& prev_connection_state, | 35 const std::string& prev_connection_state, |
| 36 bool prev_is_captive_portal) { | 36 bool prev_is_captive_portal) { |
| 37 return ((network->connection_state() != prev_connection_state) && | 37 return ((network->connection_state() != prev_connection_state) && |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 GetVisibleNetworkListByType(NetworkTypePattern::Default(), list); | 290 GetVisibleNetworkListByType(NetworkTypePattern::Default(), list); |
| 291 } | 291 } |
| 292 | 292 |
| 293 void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type, | 293 void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type, |
| 294 bool configured_only, | 294 bool configured_only, |
| 295 bool visible_only, | 295 bool visible_only, |
| 296 int limit, | 296 int limit, |
| 297 NetworkStateList* list) { | 297 NetworkStateList* list) { |
| 298 DCHECK(list); | 298 DCHECK(list); |
| 299 list->clear(); | 299 list->clear(); |
| 300 int count = 0; | 300 |
| 301 if (type.MatchesPattern(NetworkTypePattern::Tether())) { |
| 302 GetTetherNetworkList(limit, list); |
| 303 } |
| 304 |
| 305 int count = list->size(); |
| 306 |
| 307 if (type.Equals(NetworkTypePattern::Tether()) || |
| 308 (limit != 0 && count >= limit)) { |
| 309 // If only searching for tether networks, there is no need to continue |
| 310 // searching through other network types; likewise, if the limit has already |
| 311 // been reached, there is no need to continue searching. |
| 312 return; |
| 313 } |
| 314 |
| 301 // Sort the network list if necessary. | 315 // Sort the network list if necessary. |
| 302 if (!network_list_sorted_) | 316 if (!network_list_sorted_) |
| 303 SortNetworkList(); | 317 SortNetworkList(); |
| 304 for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) { | 318 for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) { |
| 305 const NetworkState* network = (*iter)->AsNetworkState(); | 319 const NetworkState* network = (*iter)->AsNetworkState(); |
| 306 DCHECK(network); | 320 DCHECK(network); |
| 307 if (!network->update_received() || !network->Matches(type)) | 321 if (!network->update_received() || !network->Matches(type)) |
| 308 continue; | 322 continue; |
| 309 if (configured_only && !network->IsInProfile()) | 323 if (configured_only && !network->IsInProfile()) |
| 310 continue; | 324 continue; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 // If the network already exists, do nothing. | 373 // If the network already exists, do nothing. |
| 360 if (GetNetworkStateFromGuid(guid)) { | 374 if (GetNetworkStateFromGuid(guid)) { |
| 361 NET_LOG(ERROR) << "AddTetherNetworkState: " << name | 375 NET_LOG(ERROR) << "AddTetherNetworkState: " << name |
| 362 << " called with existing guid:" << guid; | 376 << " called with existing guid:" << guid; |
| 363 return; | 377 return; |
| 364 } | 378 } |
| 365 | 379 |
| 366 std::unique_ptr<NetworkState> tether_network_state = | 380 std::unique_ptr<NetworkState> tether_network_state = |
| 367 base::MakeUnique<NetworkState>(guid); | 381 base::MakeUnique<NetworkState>(guid); |
| 368 | 382 |
| 383 // Tether networks are always connectable |
| 384 tether_network_state->connectable_ = true; |
| 369 tether_network_state->set_name(name); | 385 tether_network_state->set_name(name); |
| 370 tether_network_state->set_type(kTypeTether); | 386 tether_network_state->set_type(kTypeTether); |
| 371 tether_network_state->SetGuid(guid); | 387 tether_network_state->SetGuid(guid); |
| 372 tether_network_state->set_visible(true); | 388 tether_network_state->set_visible(true); |
| 373 tether_network_state->set_update_received(); | 389 tether_network_state->set_update_received(); |
| 374 | 390 |
| 375 tether_network_list_.push_back(std::move(tether_network_state)); | 391 tether_network_list_.push_back(std::move(tether_network_state)); |
| 376 NotifyNetworkListChanged(); | 392 NotifyNetworkListChanged(); |
| 377 } | 393 } |
| 378 | 394 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 service_path.c_str())); | 583 service_path.c_str())); |
| 568 return nullptr; | 584 return nullptr; |
| 569 } | 585 } |
| 570 return list.front(); | 586 return list.front(); |
| 571 } | 587 } |
| 572 | 588 |
| 573 void NetworkStateHandler::SetLastErrorForTest(const std::string& service_path, | 589 void NetworkStateHandler::SetLastErrorForTest(const std::string& service_path, |
| 574 const std::string& error) { | 590 const std::string& error) { |
| 575 NetworkState* network_state = GetModifiableNetworkState(service_path); | 591 NetworkState* network_state = GetModifiableNetworkState(service_path); |
| 576 if (!network_state) { | 592 if (!network_state) { |
| 577 LOG(ERROR) << "No matching NetworkState for: " << service_path; | 593 NET_LOG(ERROR) << "No matching NetworkState for: " << service_path; |
| 578 return; | 594 return; |
| 579 } | 595 } |
| 580 network_state->last_error_ = error; | 596 network_state->last_error_ = error; |
| 581 } | 597 } |
| 582 | 598 |
| 583 //------------------------------------------------------------------------------ | 599 //------------------------------------------------------------------------------ |
| 584 // ShillPropertyHandler::Delegate overrides | 600 // ShillPropertyHandler::Delegate overrides |
| 585 | 601 |
| 586 void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type, | 602 void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type, |
| 587 const base::ListValue& entries) { | 603 const base::ListValue& entries) { |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 if (type.MatchesType(shill::kTypeBluetooth)) | 1184 if (type.MatchesType(shill::kTypeBluetooth)) |
| 1169 technologies.emplace_back(shill::kTypeBluetooth); | 1185 technologies.emplace_back(shill::kTypeBluetooth); |
| 1170 if (type.MatchesType(shill::kTypeVPN)) | 1186 if (type.MatchesType(shill::kTypeVPN)) |
| 1171 technologies.emplace_back(shill::kTypeVPN); | 1187 technologies.emplace_back(shill::kTypeVPN); |
| 1172 | 1188 |
| 1173 CHECK_GT(technologies.size(), 0ul); | 1189 CHECK_GT(technologies.size(), 0ul); |
| 1174 return technologies; | 1190 return technologies; |
| 1175 } | 1191 } |
| 1176 | 1192 |
| 1177 } // namespace chromeos | 1193 } // namespace chromeos |
| OLD | NEW |