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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 void NetworkStateHandler::AddObserver(NetworkStateHandlerObserver* observer) { | 124 void NetworkStateHandler::AddObserver(NetworkStateHandlerObserver* observer) { |
125 observers_.AddObserver(observer); | 125 observers_.AddObserver(observer); |
126 } | 126 } |
127 | 127 |
128 void NetworkStateHandler::RemoveObserver( | 128 void NetworkStateHandler::RemoveObserver( |
129 NetworkStateHandlerObserver* observer) { | 129 NetworkStateHandlerObserver* observer) { |
130 observers_.RemoveObserver(observer); | 130 observers_.RemoveObserver(observer); |
131 } | 131 } |
132 | 132 |
133 bool NetworkStateHandler::TechnologyAvailable(const std::string& type) const { | 133 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState( |
134 if (type == kMatchTypeMobile) { | 134 const std::string& type) const { |
135 return shill_property_handler_->TechnologyAvailable(flimflam::kTypeWimax) || | 135 std::string technology = GetTechnologyForType(type); |
136 shill_property_handler_->TechnologyAvailable(flimflam::kTypeCellular); | 136 TechnologyState state; |
137 } | 137 if (shill_property_handler_->IsTechnologyEnabled(technology)) |
138 return shill_property_handler_->TechnologyAvailable(type); | 138 state = TECHNOLOGY_ENABLED; |
| 139 else if (shill_property_handler_->IsTechnologyEnabling(technology)) |
| 140 state = TECHNOLOGY_ENABLING; |
| 141 else if (shill_property_handler_->IsTechnologyUninitialized(technology)) |
| 142 state = TECHNOLOGY_UNINITIALIZED; |
| 143 else if (shill_property_handler_->IsTechnologyAvailable(technology)) |
| 144 state = TECHNOLOGY_AVAILABLE; |
| 145 else |
| 146 state = TECHNOLOGY_UNINITIALIZED; |
| 147 VLOG(2) << "GetTechnologyState: " << type << " = " << state; |
| 148 return state; |
139 } | 149 } |
140 | 150 |
141 bool NetworkStateHandler::TechnologyEnabled(const std::string& type) const { | |
142 if (type == kMatchTypeMobile) { | |
143 return shill_property_handler_->TechnologyEnabled(flimflam::kTypeWimax) || | |
144 shill_property_handler_->TechnologyEnabled(flimflam::kTypeCellular); | |
145 } | |
146 return shill_property_handler_->TechnologyEnabled(type); | |
147 } | |
148 | |
149 bool NetworkStateHandler::TechnologyUninitialized( | |
150 const std::string& type) const { | |
151 if (type == kMatchTypeMobile) { | |
152 return | |
153 shill_property_handler_->TechnologyUninitialized( | |
154 flimflam::kTypeWimax) || | |
155 shill_property_handler_->TechnologyUninitialized( | |
156 flimflam::kTypeCellular); | |
157 } | |
158 return shill_property_handler_->TechnologyUninitialized(type); | |
159 } | |
160 | |
161 | |
162 void NetworkStateHandler::SetTechnologyEnabled( | 151 void NetworkStateHandler::SetTechnologyEnabled( |
163 const std::string& type, | 152 const std::string& type, |
164 bool enabled, | 153 bool enabled, |
165 const network_handler::ErrorCallback& error_callback) { | 154 const network_handler::ErrorCallback& error_callback) { |
166 if (type == kMatchTypeMobile) { | 155 std::string technology = GetTechnologyForType(type); |
167 shill_property_handler_->SetTechnologyEnabled( | 156 network_event_log::AddEntry( |
168 flimflam::kTypeCellular, enabled, error_callback); | 157 kLogModule, "SetTechnologyEnabled", |
169 shill_property_handler_->SetTechnologyEnabled( | 158 base::StringPrintf("%s:%d", technology.c_str(), enabled)); |
170 flimflam::kTypeWimax, enabled, error_callback); | 159 shill_property_handler_->SetTechnologyEnabled( |
171 } else { | 160 technology, enabled, error_callback); |
172 shill_property_handler_->SetTechnologyEnabled( | 161 ManagerPropertyChanged(); // Technology state changed -> ENABLING |
173 type, enabled, error_callback); | |
174 } | |
175 } | 162 } |
176 | 163 |
177 const DeviceState* NetworkStateHandler::GetDeviceState( | 164 const DeviceState* NetworkStateHandler::GetDeviceState( |
178 const std::string& device_path) const { | 165 const std::string& device_path) const { |
179 return GetModifiableDeviceState(device_path); | 166 return GetModifiableDeviceState(device_path); |
180 } | 167 } |
181 | 168 |
182 const DeviceState* NetworkStateHandler::GetDeviceStateByType( | 169 const DeviceState* NetworkStateHandler::GetDeviceStateByType( |
183 const std::string& type) const { | 170 const std::string& type) const { |
184 for (ManagedStateList::const_iterator iter = device_list_.begin(); | 171 for (ManagedStateList::const_iterator iter = device_list_.begin(); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 network_event_log::AddEntry(kLogModule, "DevicePropertyUpdated", detail); | 458 network_event_log::AddEntry(kLogModule, "DevicePropertyUpdated", detail); |
472 | 459 |
473 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 460 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
474 DeviceListChanged()); | 461 DeviceListChanged()); |
475 | 462 |
476 if (key == flimflam::kScanningProperty && device->scanning() == false) | 463 if (key == flimflam::kScanningProperty && device->scanning() == false) |
477 ScanCompleted(device->type()); | 464 ScanCompleted(device->type()); |
478 } | 465 } |
479 | 466 |
480 void NetworkStateHandler::ManagerPropertyChanged() { | 467 void NetworkStateHandler::ManagerPropertyChanged() { |
| 468 network_event_log::AddEntry(kLogModule, "NetworkManagerChanged", ""); |
481 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 469 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
482 NetworkManagerChanged()); | 470 NetworkManagerChanged()); |
483 } | 471 } |
484 | 472 |
485 void NetworkStateHandler::ManagedStateListChanged( | 473 void NetworkStateHandler::ManagedStateListChanged( |
486 ManagedState::ManagedType type) { | 474 ManagedState::ManagedType type) { |
487 if (type == ManagedState::MANAGED_TYPE_NETWORK) { | 475 if (type == ManagedState::MANAGED_TYPE_NETWORK) { |
488 // Notify observers that the list of networks has changed. | 476 // Notify observers that the list of networks has changed. |
489 network_event_log::AddEntry( | 477 network_event_log::AddEntry( |
490 kLogModule, "NetworkListChanged", | 478 kLogModule, "NetworkListChanged", |
491 base::StringPrintf("Size: %"PRIuS, network_list_.size())); | 479 base::StringPrintf("Size:%"PRIuS, network_list_.size())); |
492 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 480 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
493 NetworkListChanged()); | 481 NetworkListChanged()); |
494 // The list order may have changed, so check if the default network changed. | 482 // The list order may have changed, so check if the default network changed. |
495 if (CheckDefaultNetworkChanged()) | 483 if (CheckDefaultNetworkChanged()) |
496 OnDefaultNetworkChanged(); | 484 OnDefaultNetworkChanged(); |
497 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { | 485 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { |
498 network_event_log::AddEntry( | 486 network_event_log::AddEntry( |
499 kLogModule, "DeviceListChanged", | 487 kLogModule, "DeviceListChanged", |
500 base::StringPrintf("Size: %"PRIuS, device_list_.size())); | 488 base::StringPrintf("Size:%"PRIuS, device_list_.size())); |
501 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 489 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
502 DeviceListChanged()); | 490 DeviceListChanged()); |
503 } else { | 491 } else { |
504 NOTREACHED(); | 492 NOTREACHED(); |
505 } | 493 } |
506 } | 494 } |
507 | 495 |
508 //------------------------------------------------------------------------------ | 496 //------------------------------------------------------------------------------ |
509 // Private methods | 497 // Private methods |
510 | 498 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 case ManagedState::MANAGED_TYPE_DEVICE: | 533 case ManagedState::MANAGED_TYPE_DEVICE: |
546 return &device_list_; | 534 return &device_list_; |
547 } | 535 } |
548 NOTREACHED(); | 536 NOTREACHED(); |
549 return NULL; | 537 return NULL; |
550 } | 538 } |
551 | 539 |
552 void NetworkStateHandler::OnNetworkConnectionStateChanged( | 540 void NetworkStateHandler::OnNetworkConnectionStateChanged( |
553 NetworkState* network) { | 541 NetworkState* network) { |
554 DCHECK(network); | 542 DCHECK(network); |
555 std::string desc = base::StringPrintf( | |
556 "%s: %s", network->path().c_str(), network->connection_state().c_str()); | |
557 network_event_log::AddEntry( | 543 network_event_log::AddEntry( |
558 kLogModule, "NetworkConnectionStateChanged", desc); | 544 kLogModule, "NetworkConnectionStateChanged", |
| 545 base::StringPrintf("%s:%s", network->path().c_str(), |
| 546 network->connection_state().c_str())); |
559 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 547 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
560 NetworkConnectionStateChanged(network)); | 548 NetworkConnectionStateChanged(network)); |
561 if (CheckDefaultNetworkChanged() || network->path() == default_network_path_) | 549 if (CheckDefaultNetworkChanged() || network->path() == default_network_path_) |
562 OnDefaultNetworkChanged(); | 550 OnDefaultNetworkChanged(); |
563 } | 551 } |
564 | 552 |
565 bool NetworkStateHandler::CheckDefaultNetworkChanged() { | 553 bool NetworkStateHandler::CheckDefaultNetworkChanged() { |
566 std::string new_default_network_path; | 554 std::string new_default_network_path; |
567 const NetworkState* new_default_network = DefaultNetwork(); | 555 const NetworkState* new_default_network = DefaultNetwork(); |
568 if (new_default_network) | 556 if (new_default_network) |
(...skipping 18 matching lines...) Expand all Loading... |
587 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 575 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
588 NetworkPropertiesUpdated(network)); | 576 NetworkPropertiesUpdated(network)); |
589 // If |connecting_network_| transitions to a non-idle, non-connecting state, | 577 // If |connecting_network_| transitions to a non-idle, non-connecting state, |
590 // clear it *after* signalling observers. | 578 // clear it *after* signalling observers. |
591 if (network->path() == connecting_network_ && | 579 if (network->path() == connecting_network_ && |
592 !network->IsConnectingState() && | 580 !network->IsConnectingState() && |
593 network->connection_state() != flimflam::kStateIdle) { | 581 network->connection_state() != flimflam::kStateIdle) { |
594 connecting_network_.clear(); | 582 connecting_network_.clear(); |
595 network_event_log::AddEntry( | 583 network_event_log::AddEntry( |
596 kLogModule, "ClearConnectingNetwork", | 584 kLogModule, "ClearConnectingNetwork", |
597 base::StringPrintf("%s: %s", network->path().c_str(), | 585 base::StringPrintf("%s:%s", network->path().c_str(), |
598 network->connection_state().c_str())); | 586 network->connection_state().c_str())); |
599 } | 587 } |
600 } | 588 } |
601 | 589 |
602 void NetworkStateHandler::ScanCompleted(const std::string& type) { | 590 void NetworkStateHandler::ScanCompleted(const std::string& type) { |
603 size_t num_callbacks = scan_complete_callbacks_.count(type); | 591 size_t num_callbacks = scan_complete_callbacks_.count(type); |
604 network_event_log::AddEntry( | 592 network_event_log::AddEntry( |
605 kLogModule, "ScanCompleted", | 593 kLogModule, "ScanCompleted", |
606 base::StringPrintf("%s: %"PRIuS, type.c_str(), num_callbacks)); | 594 base::StringPrintf("%s:%"PRIuS, type.c_str(), num_callbacks)); |
607 if (num_callbacks == 0) | 595 if (num_callbacks == 0) |
608 return; | 596 return; |
609 ScanCallbackList& callback_list = scan_complete_callbacks_[type]; | 597 ScanCallbackList& callback_list = scan_complete_callbacks_[type]; |
610 for (ScanCallbackList::iterator iter = callback_list.begin(); | 598 for (ScanCallbackList::iterator iter = callback_list.begin(); |
611 iter != callback_list.end(); ++iter) { | 599 iter != callback_list.end(); ++iter) { |
612 (*iter).Run(); | 600 (*iter).Run(); |
613 } | 601 } |
614 scan_complete_callbacks_.erase(type); | 602 scan_complete_callbacks_.erase(type); |
615 } | 603 } |
616 | 604 |
| 605 std::string NetworkStateHandler::GetTechnologyForType( |
| 606 const std::string& type) const { |
| 607 if (type == kMatchTypeMobile) { |
| 608 if (shill_property_handler_->IsTechnologyAvailable(flimflam::kTypeWimax)) |
| 609 return flimflam::kTypeWimax; |
| 610 else |
| 611 return flimflam::kTypeCellular; |
| 612 } |
| 613 if (type == kMatchTypeDefault || type == kMatchTypeNonVirtual || |
| 614 type == kMatchTypeWireless) { |
| 615 NOTREACHED(); |
| 616 return flimflam::kTypeWifi; |
| 617 } |
| 618 return type; |
| 619 } |
| 620 |
617 } // namespace chromeos | 621 } // namespace chromeos |
OLD | NEW |