diff options
author | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-15 21:09:25 +0000 |
---|---|---|
committer | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-15 21:09:25 +0000 |
commit | b15f493aef4dd2edd4d8d8b9960c62a8e1692cae (patch) | |
tree | 7ccb816f8e9c5778a1af31adab76b2b899eeb1ba /chromeos/network | |
parent | 5a1c3ad624b745fbf88c0ecf0f55dc4e1d998365 (diff) | |
download | chromium_src-b15f493aef4dd2edd4d8d8b9960c62a8e1692cae.zip chromium_src-b15f493aef4dd2edd4d8d8b9960c62a8e1692cae.tar.gz chromium_src-b15f493aef4dd2edd4d8d8b9960c62a8e1692cae.tar.bz2 |
Add TechnologyState to NetworkStateHandler.
This introduces a local "enabling" state for technology and
adds UI for the intermittent state.
It will also make it easier to switch to Shill technology
states once those are implemented.
BUG=223986
Review URL: https://codereview.chromium.org/14137017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194233 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/network')
-rw-r--r-- | chromeos/network/device_state.cc | 20 | ||||
-rw-r--r-- | chromeos/network/device_state.h | 7 | ||||
-rw-r--r-- | chromeos/network/network_state_handler.cc | 88 | ||||
-rw-r--r-- | chromeos/network/network_state_handler.h | 22 | ||||
-rw-r--r-- | chromeos/network/network_state_handler_unittest.cc | 16 | ||||
-rw-r--r-- | chromeos/network/shill_property_handler.cc | 30 | ||||
-rw-r--r-- | chromeos/network/shill_property_handler.h | 16 | ||||
-rw-r--r-- | chromeos/network/shill_property_handler_unittest.cc | 10 |
8 files changed, 143 insertions, 66 deletions
diff --git a/chromeos/network/device_state.cc b/chromeos/network/device_state.cc index 78a8674..61f14d8 100644 --- a/chromeos/network/device_state.cc +++ b/chromeos/network/device_state.cc @@ -15,7 +15,8 @@ DeviceState::DeviceState(const std::string& path) : ManagedState(MANAGED_TYPE_DEVICE, path), provider_requires_roaming_(false), support_network_scan_(false), - scanning_(false) { + scanning_(false), + sim_present_(true) { } DeviceState::~DeviceState() { @@ -56,8 +57,25 @@ bool DeviceState::PropertyChanged(const std::string& key, << home_provider_id_; } return true; + } else if (key == flimflam::kTechnologyFamilyProperty) { + return GetStringValue(key, value, &technology_family_); + } else if (key == flimflam::kSIMLockStatusProperty) { + const DictionaryValue* dict = NULL; + if (!value.GetAsDictionary(&dict)) + return false; + if (!dict->GetStringWithoutPathExpansion(flimflam::kSIMLockTypeProperty, + &sim_lock_type_)) + return false; + // Ignore other SIMLockStatus properties. + return true; + } else if (key == shill::kSIMPresentProperty) { + return GetBooleanValue(key, value, &sim_present_); } return false; } +bool DeviceState::IsSimAbsent() const { + return technology_family_ == flimflam::kTechnologyFamilyGsm && !sim_present_; +} + } // namespace chromeos diff --git a/chromeos/network/device_state.h b/chromeos/network/device_state.h index 2547017..37f9fb8 100644 --- a/chromeos/network/device_state.h +++ b/chromeos/network/device_state.h @@ -25,6 +25,10 @@ class CHROMEOS_EXPORT DeviceState : public ManagedState { bool provider_requires_roaming() const { return provider_requires_roaming_; } bool support_network_scan() const { return support_network_scan_; } bool scanning() const { return scanning_; } + std::string sim_lock_type() const { return sim_lock_type_; } + + // Returns true if the technology family is GSM and sim_present_ is false. + bool IsSimAbsent() const; private: // Common Device Properties @@ -34,6 +38,9 @@ class CHROMEOS_EXPORT DeviceState : public ManagedState { bool provider_requires_roaming_; bool support_network_scan_; bool scanning_; + std::string technology_family_; + std::string sim_lock_type_; + bool sim_present_; DISALLOW_COPY_AND_ASSIGN(DeviceState); }; diff --git a/chromeos/network/network_state_handler.cc b/chromeos/network/network_state_handler.cc index 60ae038..047c54b 100644 --- a/chromeos/network/network_state_handler.cc +++ b/chromeos/network/network_state_handler.cc @@ -130,48 +130,35 @@ void NetworkStateHandler::RemoveObserver( observers_.RemoveObserver(observer); } -bool NetworkStateHandler::TechnologyAvailable(const std::string& type) const { - if (type == kMatchTypeMobile) { - return shill_property_handler_->TechnologyAvailable(flimflam::kTypeWimax) || - shill_property_handler_->TechnologyAvailable(flimflam::kTypeCellular); - } - return shill_property_handler_->TechnologyAvailable(type); -} - -bool NetworkStateHandler::TechnologyEnabled(const std::string& type) const { - if (type == kMatchTypeMobile) { - return shill_property_handler_->TechnologyEnabled(flimflam::kTypeWimax) || - shill_property_handler_->TechnologyEnabled(flimflam::kTypeCellular); - } - return shill_property_handler_->TechnologyEnabled(type); -} - -bool NetworkStateHandler::TechnologyUninitialized( +NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState( const std::string& type) const { - if (type == kMatchTypeMobile) { - return - shill_property_handler_->TechnologyUninitialized( - flimflam::kTypeWimax) || - shill_property_handler_->TechnologyUninitialized( - flimflam::kTypeCellular); - } - return shill_property_handler_->TechnologyUninitialized(type); + std::string technology = GetTechnologyForType(type); + TechnologyState state; + if (shill_property_handler_->IsTechnologyEnabled(technology)) + state = TECHNOLOGY_ENABLED; + else if (shill_property_handler_->IsTechnologyEnabling(technology)) + state = TECHNOLOGY_ENABLING; + else if (shill_property_handler_->IsTechnologyUninitialized(technology)) + state = TECHNOLOGY_UNINITIALIZED; + else if (shill_property_handler_->IsTechnologyAvailable(technology)) + state = TECHNOLOGY_AVAILABLE; + else + state = TECHNOLOGY_UNINITIALIZED; + VLOG(2) << "GetTechnologyState: " << type << " = " << state; + return state; } - void NetworkStateHandler::SetTechnologyEnabled( const std::string& type, bool enabled, const network_handler::ErrorCallback& error_callback) { - if (type == kMatchTypeMobile) { - shill_property_handler_->SetTechnologyEnabled( - flimflam::kTypeCellular, enabled, error_callback); - shill_property_handler_->SetTechnologyEnabled( - flimflam::kTypeWimax, enabled, error_callback); - } else { - shill_property_handler_->SetTechnologyEnabled( - type, enabled, error_callback); - } + std::string technology = GetTechnologyForType(type); + network_event_log::AddEntry( + kLogModule, "SetTechnologyEnabled", + base::StringPrintf("%s:%d", technology.c_str(), enabled)); + shill_property_handler_->SetTechnologyEnabled( + technology, enabled, error_callback); + ManagerPropertyChanged(); // Technology state changed -> ENABLING } const DeviceState* NetworkStateHandler::GetDeviceState( @@ -478,6 +465,7 @@ void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, } void NetworkStateHandler::ManagerPropertyChanged() { + network_event_log::AddEntry(kLogModule, "NetworkManagerChanged", ""); FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, NetworkManagerChanged()); } @@ -488,7 +476,7 @@ void NetworkStateHandler::ManagedStateListChanged( // Notify observers that the list of networks has changed. network_event_log::AddEntry( kLogModule, "NetworkListChanged", - base::StringPrintf("Size: %"PRIuS, network_list_.size())); + base::StringPrintf("Size:%"PRIuS, network_list_.size())); FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, NetworkListChanged()); // The list order may have changed, so check if the default network changed. @@ -497,7 +485,7 @@ void NetworkStateHandler::ManagedStateListChanged( } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { network_event_log::AddEntry( kLogModule, "DeviceListChanged", - base::StringPrintf("Size: %"PRIuS, device_list_.size())); + base::StringPrintf("Size:%"PRIuS, device_list_.size())); FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, DeviceListChanged()); } else { @@ -552,10 +540,10 @@ NetworkStateHandler::ManagedStateList* NetworkStateHandler::GetManagedList( void NetworkStateHandler::OnNetworkConnectionStateChanged( NetworkState* network) { DCHECK(network); - std::string desc = base::StringPrintf( - "%s: %s", network->path().c_str(), network->connection_state().c_str()); network_event_log::AddEntry( - kLogModule, "NetworkConnectionStateChanged", desc); + kLogModule, "NetworkConnectionStateChanged", + base::StringPrintf("%s:%s", network->path().c_str(), + network->connection_state().c_str())); FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, NetworkConnectionStateChanged(network)); if (CheckDefaultNetworkChanged() || network->path() == default_network_path_) @@ -594,7 +582,7 @@ void NetworkStateHandler::NetworkPropertiesUpdated( connecting_network_.clear(); network_event_log::AddEntry( kLogModule, "ClearConnectingNetwork", - base::StringPrintf("%s: %s", network->path().c_str(), + base::StringPrintf("%s:%s", network->path().c_str(), network->connection_state().c_str())); } } @@ -603,7 +591,7 @@ void NetworkStateHandler::ScanCompleted(const std::string& type) { size_t num_callbacks = scan_complete_callbacks_.count(type); network_event_log::AddEntry( kLogModule, "ScanCompleted", - base::StringPrintf("%s: %"PRIuS, type.c_str(), num_callbacks)); + base::StringPrintf("%s:%"PRIuS, type.c_str(), num_callbacks)); if (num_callbacks == 0) return; ScanCallbackList& callback_list = scan_complete_callbacks_[type]; @@ -614,4 +602,20 @@ void NetworkStateHandler::ScanCompleted(const std::string& type) { scan_complete_callbacks_.erase(type); } +std::string NetworkStateHandler::GetTechnologyForType( + const std::string& type) const { + if (type == kMatchTypeMobile) { + if (shill_property_handler_->IsTechnologyAvailable(flimflam::kTypeWimax)) + return flimflam::kTypeWimax; + else + return flimflam::kTypeCellular; + } + if (type == kMatchTypeDefault || type == kMatchTypeNonVirtual || + type == kMatchTypeWireless) { + NOTREACHED(); + return flimflam::kTypeWifi; + } + return type; +} + } // namespace chromeos diff --git a/chromeos/network/network_state_handler.h b/chromeos/network/network_state_handler.h index 92bb01e..a68e33a 100644 --- a/chromeos/network/network_state_handler.h +++ b/chromeos/network/network_state_handler.h @@ -57,6 +57,14 @@ class CHROMEOS_EXPORT NetworkStateHandler typedef std::vector<ManagedState*> ManagedStateList; typedef std::vector<const NetworkState*> NetworkStateList; + enum TechnologyState { + TECHNOLOGY_UNAVAILABLE, + TECHNOLOGY_AVAILABLE, + TECHNOLOGY_UNINITIALIZED, + TECHNOLOGY_ENABLING, + TECHNOLOGY_ENABLED + }; + virtual ~NetworkStateHandler(); // Sets the global instance. Must be called before any calls to Get(). @@ -75,11 +83,12 @@ class CHROMEOS_EXPORT NetworkStateHandler void AddObserver(NetworkStateHandlerObserver* observer); void RemoveObserver(NetworkStateHandlerObserver* observer); - // Returns true if technology for |type| is available/ enabled/uninitialized. - // kMatchTypeMobile (only) is also supported. - bool TechnologyAvailable(const std::string& type) const; - bool TechnologyEnabled(const std::string& type) const; - bool TechnologyUninitialized(const std::string& type) const; + // Returns the state for technology |type|. kMatchTypeMobile (only) is + // also supported. + TechnologyState GetTechnologyState(const std::string& type) const; + bool IsTechnologyEnabled(const std::string& type) const { + return GetTechnologyState(type) == TECHNOLOGY_ENABLED; + } // Asynchronously sets the technology enabled property for |type|. // kMatchTypeMobile (only) is also supported. @@ -244,6 +253,9 @@ class CHROMEOS_EXPORT NetworkStateHandler // Called whenever Device.Scanning state transitions to false. void ScanCompleted(const std::string& type); + // Returns the technology type for |type|. + std::string GetTechnologyForType(const std::string& type) const; + // Shill property handler instance, owned by this class. scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; diff --git a/chromeos/network/network_state_handler_unittest.cc b/chromeos/network/network_state_handler_unittest.cc index 685d913..1d9ce15 100644 --- a/chromeos/network/network_state_handler_unittest.cc +++ b/chromeos/network/network_state_handler_unittest.cc @@ -216,13 +216,21 @@ TEST_F(NetworkStateHandlerTest, TechnologyChanged) { message_loop_.RunUntilIdle(); EXPECT_EQ(1u, test_observer_->manager_changed_count()); // Enable a technology. - EXPECT_FALSE(network_state_handler_->TechnologyEnabled(flimflam::kTypeWimax)); + EXPECT_NE(NetworkStateHandler::TECHNOLOGY_ENABLED, + network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); network_state_handler_->SetTechnologyEnabled( flimflam::kTypeWimax, true, network_handler::ErrorCallback()); - message_loop_.RunUntilIdle(); - // Ensure we get a manager changed callback when we change a property. + // The technology state should immediately change to ENABLING and we should + // receive a manager changed callback. EXPECT_EQ(2u, test_observer_->manager_changed_count()); - EXPECT_TRUE(network_state_handler_->TechnologyEnabled(flimflam::kTypeWimax)); + EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_ENABLING, + network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); + message_loop_.RunUntilIdle(); + // Ensure we receive another manager changed callbacks when the technology + // becomes enabled. + EXPECT_EQ(3u, test_observer_->manager_changed_count()); + EXPECT_EQ(NetworkStateHandler::TECHNOLOGY_ENABLED, + network_state_handler_->GetTechnologyState(flimflam::kTypeWimax)); } TEST_F(NetworkStateHandlerTest, ServicePropertyChanged) { diff --git a/chromeos/network/shill_property_handler.cc b/chromeos/network/shill_property_handler.cc index fad1d75..e6efd65 100644 --- a/chromeos/network/shill_property_handler.cc +++ b/chromeos/network/shill_property_handler.cc @@ -121,17 +121,22 @@ void ShillPropertyHandler::Init() { shill_manager_->AddPropertyChangedObserver(this); } -bool ShillPropertyHandler::TechnologyAvailable( +bool ShillPropertyHandler::IsTechnologyAvailable( const std::string& technology) const { return available_technologies_.count(technology) != 0; } -bool ShillPropertyHandler::TechnologyEnabled( +bool ShillPropertyHandler::IsTechnologyEnabled( const std::string& technology) const { return enabled_technologies_.count(technology) != 0; } -bool ShillPropertyHandler::TechnologyUninitialized( +bool ShillPropertyHandler::IsTechnologyEnabling( + const std::string& technology) const { + return enabling_technologies_.count(technology) != 0; +} + +bool ShillPropertyHandler::IsTechnologyUninitialized( const std::string& technology) const { return uninitialized_technologies_.count(technology) != 0; } @@ -141,12 +146,16 @@ void ShillPropertyHandler::SetTechnologyEnabled( bool enabled, const network_handler::ErrorCallback& error_callback) { if (enabled) { + enabling_technologies_.insert(technology); shill_manager_->EnableTechnology( technology, base::Bind(&base::DoNothing), - base::Bind(&network_handler::ShillErrorCallbackFunction, - kLogModule, technology, error_callback)); + base::Bind(&ShillPropertyHandler::EnableTechnologyFailed, + AsWeakPtr(), technology, error_callback)); } else { + // Imediately clear locally from enabled and enabling lists. + enabled_technologies_.erase(technology); + enabling_technologies_.erase(technology); shill_manager_->DisableTechnology( technology, base::Bind(&base::DoNothing), @@ -351,6 +360,7 @@ void ShillPropertyHandler::UpdateEnabledTechnologies( (*iter)->GetAsString(&technology); DCHECK(!technology.empty()); enabled_technologies_.insert(technology); + enabling_technologies_.erase(technology); } } @@ -369,6 +379,16 @@ void ShillPropertyHandler::UpdateUninitializedTechnologies( } } +void ShillPropertyHandler::EnableTechnologyFailed( + const std::string& technology, + const network_handler::ErrorCallback& error_callback, + const std::string& error_name, + const std::string& error_message) { + enabling_technologies_.erase(technology); + network_handler::ShillErrorCallbackFunction( + kLogModule, technology, error_callback, error_name, error_message); +} + void ShillPropertyHandler::GetPropertiesCallback( ManagedState::ManagedType type, const std::string& path, diff --git a/chromeos/network/shill_property_handler.h b/chromeos/network/shill_property_handler.h index 0749e34..33627ef 100644 --- a/chromeos/network/shill_property_handler.h +++ b/chromeos/network/shill_property_handler.h @@ -90,10 +90,11 @@ class CHROMEOS_EXPORT ShillPropertyHandler // Sends an initial property request and sets up the observer. void Init(); - // Returns true if |technology| is available / enabled / uninitialized. - bool TechnologyAvailable(const std::string& technology) const; - bool TechnologyEnabled(const std::string& technology) const; - bool TechnologyUninitialized(const std::string& technology) const; + // Returns true if |technology| is available, enabled, etc. + bool IsTechnologyAvailable(const std::string& technology) const; + bool IsTechnologyEnabled(const std::string& technology) const; + bool IsTechnologyEnabling(const std::string& technology) const; + bool IsTechnologyUninitialized(const std::string& technology) const; // Asynchronously sets the enabled state for |technology|. // Note: Modifes Manager state. Calls |error_callback| on failure. @@ -139,6 +140,12 @@ class CHROMEOS_EXPORT ShillPropertyHandler void UpdateEnabledTechnologies(const base::ListValue& technologies); void UpdateUninitializedTechnologies(const base::ListValue& technologies); + void EnableTechnologyFailed( + const std::string& technology, + const network_handler::ErrorCallback& error_callback, + const std::string& error_name, + const std::string& error_message); + // Called when Shill returns the properties for a service or device. void GetPropertiesCallback(ManagedState::ManagedType type, const std::string& path, @@ -183,6 +190,7 @@ class CHROMEOS_EXPORT ShillPropertyHandler // Lists of available / enabled / uninitialized technologies std::set<std::string> available_technologies_; std::set<std::string> enabled_technologies_; + std::set<std::string> enabling_technologies_; std::set<std::string> uninitialized_technologies_; DISALLOW_COPY_AND_ASSIGN(ShillPropertyHandler); diff --git a/chromeos/network/shill_property_handler_unittest.cc b/chromeos/network/shill_property_handler_unittest.cc index b724ae4..34e685a 100644 --- a/chromeos/network/shill_property_handler_unittest.cc +++ b/chromeos/network/shill_property_handler_unittest.cc @@ -249,9 +249,9 @@ class ShillPropertyHandlerTest : public testing::Test { TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerStub) { EXPECT_EQ(1, listener_->manager_updates()); - EXPECT_TRUE(shill_property_handler_->TechnologyAvailable( + EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable( flimflam::kTypeWifi)); - EXPECT_TRUE(shill_property_handler_->TechnologyEnabled( + EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled( flimflam::kTypeWifi)); const size_t kNumShillManagerClientStubImplDevices = 2; EXPECT_EQ(kNumShillManagerClientStubImplDevices, @@ -269,9 +269,9 @@ TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerTechnologyChanged) { manager_test_->AddTechnology(flimflam::kTypeWimax, false); message_loop_.RunUntilIdle(); EXPECT_EQ(2, listener_->manager_updates()); - EXPECT_TRUE(shill_property_handler_->TechnologyAvailable( + EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable( flimflam::kTypeWimax)); - EXPECT_FALSE(shill_property_handler_->TechnologyEnabled( + EXPECT_FALSE(shill_property_handler_->IsTechnologyEnabled( flimflam::kTypeWimax)); // Enable the technology. @@ -280,7 +280,7 @@ TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerTechnologyChanged) { base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); message_loop_.RunUntilIdle(); EXPECT_EQ(3, listener_->manager_updates()); - EXPECT_TRUE(shill_property_handler_->TechnologyEnabled( + EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled( flimflam::kTypeWimax)); EXPECT_EQ(0, listener_->errors()); |