Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: chromeos/network/network_state_handler.cc

Issue 14137017: Add TechnologyState to NetworkStateHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 = TechnologyForType(type);
136 shill_property_handler_->TechnologyAvailable(flimflam::kTypeCellular); 136 TechnologyState state;
137 } 137 if (shill_property_handler_->TechnologyEnabled(technology))
138 return shill_property_handler_->TechnologyAvailable(type); 138 state = TECHNOLOGY_ENABLED;
139 else if (shill_property_handler_->TechnologyEnabling(technology))
140 state = TECHNOLOGY_ENABLING;
141 else if (shill_property_handler_->TechnologyUninitialized(technology))
142 state = TECHNOLOGY_UNINITIALIZED;
143 else if (shill_property_handler_->TechnologyAvailable(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 = TechnologyForType(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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 network_event_log::AddEntry(kLogModule, "DevicePropertyUpdated", detail); 448 network_event_log::AddEntry(kLogModule, "DevicePropertyUpdated", detail);
462 449
463 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 450 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
464 DeviceListChanged()); 451 DeviceListChanged());
465 452
466 if (key == flimflam::kScanningProperty && device->scanning() == false) 453 if (key == flimflam::kScanningProperty && device->scanning() == false)
467 ScanCompleted(device->type()); 454 ScanCompleted(device->type());
468 } 455 }
469 456
470 void NetworkStateHandler::ManagerPropertyChanged() { 457 void NetworkStateHandler::ManagerPropertyChanged() {
458 network_event_log::AddEntry(kLogModule, "NetworkManagerChanged", "");
471 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 459 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
472 NetworkManagerChanged()); 460 NetworkManagerChanged());
473 } 461 }
474 462
475 void NetworkStateHandler::ManagedStateListChanged( 463 void NetworkStateHandler::ManagedStateListChanged(
476 ManagedState::ManagedType type) { 464 ManagedState::ManagedType type) {
477 if (type == ManagedState::MANAGED_TYPE_NETWORK) { 465 if (type == ManagedState::MANAGED_TYPE_NETWORK) {
478 // Notify observers that the list of networks has changed. 466 // Notify observers that the list of networks has changed.
479 network_event_log::AddEntry( 467 network_event_log::AddEntry(
480 kLogModule, "NetworkListChanged", 468 kLogModule, "NetworkListChanged",
481 base::StringPrintf("Size: %"PRIuS, network_list_.size())); 469 base::StringPrintf("Size:%"PRIuS, network_list_.size()));
482 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 470 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
483 NetworkListChanged()); 471 NetworkListChanged());
484 // The list order may have changed, so check if the default network changed. 472 // The list order may have changed, so check if the default network changed.
485 if (CheckDefaultNetworkChanged()) 473 if (CheckDefaultNetworkChanged())
486 OnDefaultNetworkChanged(); 474 OnDefaultNetworkChanged();
487 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { 475 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) {
488 network_event_log::AddEntry( 476 network_event_log::AddEntry(
489 kLogModule, "DeviceListChanged", 477 kLogModule, "DeviceListChanged",
490 base::StringPrintf("Size: %"PRIuS, device_list_.size())); 478 base::StringPrintf("Size:%"PRIuS, device_list_.size()));
491 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 479 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
492 DeviceListChanged()); 480 DeviceListChanged());
493 } else { 481 } else {
494 NOTREACHED(); 482 NOTREACHED();
495 } 483 }
496 } 484 }
497 485
498 //------------------------------------------------------------------------------ 486 //------------------------------------------------------------------------------
499 // Private methods 487 // Private methods
500 488
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 case ManagedState::MANAGED_TYPE_DEVICE: 523 case ManagedState::MANAGED_TYPE_DEVICE:
536 return &device_list_; 524 return &device_list_;
537 } 525 }
538 NOTREACHED(); 526 NOTREACHED();
539 return NULL; 527 return NULL;
540 } 528 }
541 529
542 void NetworkStateHandler::OnNetworkConnectionStateChanged( 530 void NetworkStateHandler::OnNetworkConnectionStateChanged(
543 NetworkState* network) { 531 NetworkState* network) {
544 DCHECK(network); 532 DCHECK(network);
545 std::string desc = base::StringPrintf(
546 "%s: %s", network->path().c_str(), network->connection_state().c_str());
547 network_event_log::AddEntry( 533 network_event_log::AddEntry(
548 kLogModule, "NetworkConnectionStateChanged", desc); 534 kLogModule, "NetworkConnectionStateChanged",
535 base::StringPrintf("%s:%s", network->path().c_str(),
536 network->connection_state().c_str()));
549 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 537 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
550 NetworkConnectionStateChanged(network)); 538 NetworkConnectionStateChanged(network));
551 if (CheckDefaultNetworkChanged() || network->path() == default_network_path_) 539 if (CheckDefaultNetworkChanged() || network->path() == default_network_path_)
552 OnDefaultNetworkChanged(); 540 OnDefaultNetworkChanged();
553 } 541 }
554 542
555 bool NetworkStateHandler::CheckDefaultNetworkChanged() { 543 bool NetworkStateHandler::CheckDefaultNetworkChanged() {
556 std::string new_default_network_path; 544 std::string new_default_network_path;
557 const NetworkState* new_default_network = DefaultNetwork(); 545 const NetworkState* new_default_network = DefaultNetwork();
558 if (new_default_network) 546 if (new_default_network)
(...skipping 18 matching lines...) Expand all
577 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 565 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
578 NetworkPropertiesUpdated(network)); 566 NetworkPropertiesUpdated(network));
579 // If |connecting_network_| transitions to a non-idle, non-connecting state, 567 // If |connecting_network_| transitions to a non-idle, non-connecting state,
580 // clear it *after* signalling observers. 568 // clear it *after* signalling observers.
581 if (network->path() == connecting_network_ && 569 if (network->path() == connecting_network_ &&
582 !network->IsConnectingState() && 570 !network->IsConnectingState() &&
583 network->connection_state() != flimflam::kStateIdle) { 571 network->connection_state() != flimflam::kStateIdle) {
584 connecting_network_.clear(); 572 connecting_network_.clear();
585 network_event_log::AddEntry( 573 network_event_log::AddEntry(
586 kLogModule, "ClearConnectingNetwork", 574 kLogModule, "ClearConnectingNetwork",
587 base::StringPrintf("%s: %s", network->path().c_str(), 575 base::StringPrintf("%s:%s", network->path().c_str(),
588 network->connection_state().c_str())); 576 network->connection_state().c_str()));
589 } 577 }
590 } 578 }
591 579
592 void NetworkStateHandler::ScanCompleted(const std::string& type) { 580 void NetworkStateHandler::ScanCompleted(const std::string& type) {
593 size_t num_callbacks = scan_complete_callbacks_.count(type); 581 size_t num_callbacks = scan_complete_callbacks_.count(type);
594 network_event_log::AddEntry( 582 network_event_log::AddEntry(
595 kLogModule, "ScanCompleted", 583 kLogModule, "ScanCompleted",
596 base::StringPrintf("%s: %"PRIuS, type.c_str(), num_callbacks)); 584 base::StringPrintf("%s:%"PRIuS, type.c_str(), num_callbacks));
597 if (num_callbacks == 0) 585 if (num_callbacks == 0)
598 return; 586 return;
599 ScanCallbackList& callback_list = scan_complete_callbacks_[type]; 587 ScanCallbackList& callback_list = scan_complete_callbacks_[type];
600 for (ScanCallbackList::iterator iter = callback_list.begin(); 588 for (ScanCallbackList::iterator iter = callback_list.begin();
601 iter != callback_list.end(); ++iter) { 589 iter != callback_list.end(); ++iter) {
602 (*iter).Run(); 590 (*iter).Run();
603 } 591 }
604 scan_complete_callbacks_.erase(type); 592 scan_complete_callbacks_.erase(type);
605 } 593 }
606 594
595 std::string NetworkStateHandler::TechnologyForType(
596 const std::string& type) const {
597 if (type == kMatchTypeMobile) {
598 if (shill_property_handler_->TechnologyAvailable(flimflam::kTypeWimax))
599 return flimflam::kTypeWimax;
600 else
601 return flimflam::kTypeCellular;
602 }
603 if (type == kMatchTypeDefault || type == kMatchTypeNonVirtual ||
604 type == kMatchTypeWireless) {
605 NOTREACHED();
606 return flimflam::kTypeWifi;
607 }
608 return type;
609 }
610
607 } // namespace chromeos 611 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698