diff options
25 files changed, 386 insertions, 352 deletions
diff --git a/chrome/browser/chromeos/login/managed/locally_managed_user_creation_screen.cc b/chrome/browser/chromeos/login/managed/locally_managed_user_creation_screen.cc index 4984fc2..7e8df91 100644 --- a/chrome/browser/chromeos/login/managed/locally_managed_user_creation_screen.cc +++ b/chrome/browser/chromeos/login/managed/locally_managed_user_creation_screen.cc @@ -4,13 +4,12 @@ #include "chrome/browser/chromeos/login/managed/locally_managed_user_creation_screen.h" -#include "base/values.h" +#include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/login/existing_user_controller.h" #include "chrome/browser/chromeos/login/managed/locally_managed_user_controller.h" #include "chrome/browser/chromeos/login/screens/error_screen.h" #include "chrome/browser/chromeos/login/screens/screen_observer.h" #include "chrome/browser/chromeos/login/wizard_controller.h" -#include "chromeos/network/network_state.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" @@ -19,7 +18,7 @@ namespace chromeos { namespace { void ConfigureErrorScreen(ErrorScreen* screen, - const NetworkState* network, + const Network* network, const NetworkPortalDetector::CaptivePortalStatus status) { switch (status) { case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN: @@ -87,7 +86,7 @@ void LocallyManagedUserCreationScreen::Show() { } void LocallyManagedUserCreationScreen::OnPortalDetectionCompleted( - const NetworkState* network, + const Network* network, const NetworkPortalDetector::CaptivePortalState& state) { if (state.status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE) { get_screen_observer()->HideErrorScreen(this); diff --git a/chrome/browser/chromeos/login/managed/locally_managed_user_creation_screen.h b/chrome/browser/chromeos/login/managed/locally_managed_user_creation_screen.h index 14ba3b0..b652f50 100644 --- a/chrome/browser/chromeos/login/managed/locally_managed_user_creation_screen.h +++ b/chrome/browser/chromeos/login/managed/locally_managed_user_creation_screen.h @@ -16,8 +16,6 @@ namespace chromeos { -class NetworkState; - // Class that controls screen showing ui for locally managed user creation. class LocallyManagedUserCreationScreen : public WizardScreen, @@ -78,9 +76,9 @@ class LocallyManagedUserCreationScreen bool recoverable) OVERRIDE; virtual void OnCreationSuccess() OVERRIDE; - // NetworkPortalDetector::Observer implementation: + // ConnectivityStateHelperObserver implementation: virtual void OnPortalDetectionCompleted( - const NetworkState* network, + const Network* network, const NetworkPortalDetector::CaptivePortalState& state) OVERRIDE; private: LocallyManagedUserCreationScreenHandler* actor_; diff --git a/chrome/browser/chromeos/login/screens/update_screen.cc b/chrome/browser/chromeos/login/screens/update_screen.cc index f36473d..4fd7b76 100644 --- a/chrome/browser/chromeos/login/screens/update_screen.cc +++ b/chrome/browser/chromeos/login/screens/update_screen.cc @@ -12,6 +12,8 @@ #include "base/logging.h" #include "base/message_loop.h" #include "base/threading/thread_restrictions.h" +#include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/login/screens/error_screen.h" #include "chrome/browser/chromeos/login/screens/screen_observer.h" #include "chrome/browser/chromeos/login/screens/update_screen_actor.h" @@ -19,7 +21,6 @@ #include "chrome/browser/chromeos/login/wizard_controller.h" #include "chromeos/chromeos_switches.h" #include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/network/network_state.h" #include "content/public/browser/browser_thread.h" using content::BrowserThread; @@ -83,6 +84,17 @@ bool IsBlockingUpdateEnabledInCommandLine() { chromeos::switches::kDisableOOBEBlockingUpdate); } +// TODO (ygorshenin@): switch over to use NetworkStateHandler. +const Network* GetDefaultNetwork() { + CrosLibrary* cros = CrosLibrary::Get(); + if (!cros) + return NULL; + NetworkLibrary* network_library = cros->GetNetworkLibrary(); + if (!network_library) + return NULL; + return network_library->active_network(); +} + } // anonymous namespace // static @@ -240,10 +252,10 @@ void UpdateScreen::UpdateStatusChanged( } void UpdateScreen::OnPortalDetectionCompleted( - const NetworkState* network, + const Network* network, const NetworkPortalDetector::CaptivePortalState& state) { LOG(WARNING) << "UpdateScreen::PortalDetectionCompleted(): " - << "network=" << (network ? network->path() : "") << ", " + << "network=" << (network ? network->service_path() : "") << ", " << "state.status=" << state.status << ", " << "state.response_code=" << state.response_code; @@ -505,7 +517,7 @@ void UpdateScreen::HideErrorMessage() { } void UpdateScreen::UpdateErrorMessage( - const NetworkState* network, + const Network* network, const NetworkPortalDetector::CaptivePortalStatus status) { switch (status) { case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE: diff --git a/chrome/browser/chromeos/login/screens/update_screen.h b/chrome/browser/chromeos/login/screens/update_screen.h index bdfd26b..a4ad065 100644 --- a/chrome/browser/chromeos/login/screens/update_screen.h +++ b/chrome/browser/chromeos/login/screens/update_screen.h @@ -21,7 +21,6 @@ namespace chromeos { class ErrorScreen; -class NetworkState; class ScreenObserver; // Controller for the update screen. It does not depend on the specific @@ -72,7 +71,7 @@ class UpdateScreen: public UpdateEngineClient::Observer, // NetworkPortalDetector::Observer implementation: virtual void OnPortalDetectionCompleted( - const NetworkState* network, + const Network* network, const NetworkPortalDetector::CaptivePortalState& state) OVERRIDE; private: @@ -107,7 +106,7 @@ class UpdateScreen: public UpdateEngineClient::Observer, void ShowErrorMessage(); void HideErrorMessage(); void UpdateErrorMessage( - const NetworkState* network, + const Network* network, const NetworkPortalDetector::CaptivePortalStatus status); // Timer for the interval to wait for the reboot. // If reboot didn't happen - ask user to reboot manually. diff --git a/chrome/browser/chromeos/login/screens/update_screen_browsertest.cc b/chrome/browser/chromeos/login/screens/update_screen_browsertest.cc index 81c21de..5314ae2 100644 --- a/chrome/browser/chromeos/login/screens/update_screen_browsertest.cc +++ b/chrome/browser/chromeos/login/screens/update_screen_browsertest.cc @@ -29,8 +29,8 @@ namespace chromeos { namespace { -const char kStubEthernetServicePath[] = "eth0"; -const char kStubWifiServicePath[] = "wlan0"; +const char kDefaultEthernetServicePath[] = "eth0"; +const char kDefaultWifiServicePath[] = "wlan0"; } // namespace @@ -55,10 +55,29 @@ class UpdateScreenTest : public WizardInProcessBrowserTest { = mock_dbus_thread_manager->fake_update_engine_client(); mock_network_library_ = cros_mock_->mock_network_library(); + stub_ethernet_.reset(new EthernetNetwork(kDefaultEthernetServicePath)); + stub_wifi_.reset(new WifiNetwork(kDefaultWifiServicePath)); EXPECT_CALL(*mock_network_library_, SetDefaultCheckPortalList()) .Times(1); + EXPECT_CALL(*mock_network_library_, AddNetworkManagerObserver(_)) + .Times(1) + .RetiresOnSaturation(); + EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_)) + .Times(AnyNumber()); + EXPECT_CALL(*mock_network_library_, FindWifiDevice()) + .Times(AnyNumber()); + EXPECT_CALL(*mock_network_library_, FindEthernetDevice()) + .Times(AnyNumber()); EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _)) .Times(AnyNumber()); + EXPECT_CALL(*mock_network_library_, + FindNetworkByPath(kDefaultEthernetServicePath)) + .Times(AnyNumber()) + .WillRepeatedly((Return(stub_ethernet_.get()))); + EXPECT_CALL(*mock_network_library_, + FindNetworkByPath(kDefaultWifiServicePath)) + .Times(AnyNumber()) + .WillRepeatedly((Return(stub_wifi_.get()))); // Setup network portal detector to return online state for both // ethernet and wifi networks. Ethernet is an active network by @@ -69,9 +88,9 @@ class UpdateScreenTest : public WizardInProcessBrowserTest { NetworkPortalDetector::CaptivePortalState online_state; online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; online_state.response_code = 204; - SetDefaultNetworkPath(kStubEthernetServicePath); - SetDetectionResults(kStubEthernetServicePath, online_state); - SetDetectionResults(kStubWifiServicePath, online_state); + SetActiveNetwork(stub_ethernet_.get()); + SetDetectionResults(stub_ethernet_.get(), online_state); + SetDetectionResults(stub_wifi_.get(), online_state); } virtual void SetUpOnMainThread() OVERRIDE { @@ -101,17 +120,16 @@ class UpdateScreenTest : public WizardInProcessBrowserTest { DBusThreadManager::Shutdown(); } - void SetDefaultNetworkPath(const std::string& service_path) { + void SetActiveNetwork(const Network* network) { DCHECK(network_portal_detector_stub_); - network_portal_detector_stub_->SetDefaultNetworkPathForTesting( - service_path); + network_portal_detector_stub_->SetActiveNetworkForTesting(network); } void SetDetectionResults( - const std::string& service_path, + const Network* network, const NetworkPortalDetector::CaptivePortalState& state) { DCHECK(network_portal_detector_stub_); - network_portal_detector_stub_->SetDetectionResultsForTesting(service_path, + network_portal_detector_stub_->SetDetectionResultsForTesting(network, state); } @@ -122,6 +140,8 @@ class UpdateScreenTest : public WizardInProcessBrowserTest { FakeUpdateEngineClient* fake_update_engine_client_; MockNetworkLibrary* mock_network_library_; + scoped_ptr<Network> stub_ethernet_; + scoped_ptr<Network> stub_wifi_; scoped_ptr<MockScreenObserver> mock_screen_observer_; scoped_ptr<MockErrorScreenActor> mock_error_screen_actor_; scoped_ptr<MockErrorScreen> mock_error_screen_; @@ -242,7 +262,7 @@ IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestTemproraryOfflineNetwork) { NetworkPortalDetector::CaptivePortalState portal_state; portal_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; portal_state.response_code = 200; - SetDetectionResults(kStubEthernetServicePath, portal_state); + SetDetectionResults(stub_ethernet_.get(), portal_state); // Update screen will show error message about portal state because // ethernet is behind captive portal. @@ -262,7 +282,7 @@ IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestTemproraryOfflineNetwork) { NetworkPortalDetector::CaptivePortalState online_state; online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; online_state.response_code = 204; - SetDetectionResults(kStubEthernetServicePath, online_state); + SetDetectionResults(stub_ethernet_.get(), online_state); // Second notification from portal detector will be about online state, // so update screen will hide error message and proceed to update. @@ -288,7 +308,7 @@ IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestTwoOfflineNetworks) { NetworkPortalDetector::CaptivePortalState portal_state; portal_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; portal_state.response_code = 200; - SetDetectionResults(kStubEthernetServicePath, portal_state); + SetDetectionResults(stub_ethernet_.get(), portal_state); // Update screen will show error message about portal state because // ethernet is behind captive portal. @@ -310,8 +330,8 @@ IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestTwoOfflineNetworks) { proxy_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED; proxy_state.response_code = -1; - SetDefaultNetworkPath(kStubWifiServicePath); - SetDetectionResults(kStubWifiServicePath, proxy_state); + SetActiveNetwork(stub_wifi_.get()); + SetDetectionResults(stub_wifi_.get(), proxy_state); // Update screen will show message about proxy error because wifie // network requires proxy authentication. @@ -323,7 +343,7 @@ IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestTwoOfflineNetworks) { } IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestVoidNetwork) { - SetDefaultNetworkPath(""); + SetActiveNetwork(NULL); // Cancels pending update request. EXPECT_CALL(*mock_screen_observer_, diff --git a/chrome/browser/chromeos/net/network_portal_detector.h b/chrome/browser/chromeos/net/network_portal_detector.h index fba5a6f..b67980c 100644 --- a/chrome/browser/chromeos/net/network_portal_detector.h +++ b/chrome/browser/chromeos/net/network_portal_detector.h @@ -10,7 +10,7 @@ namespace chromeos { -class NetworkState; +class Network; // This class handles all notifications about network changes from // NetworkLibrary and delegates portal detection for the active @@ -46,7 +46,7 @@ class NetworkPortalDetector { // detection is in process for the active network. Note, that // |network| may be NULL. virtual void OnPortalDetectionCompleted( - const NetworkState* network, + const Network* network, const CaptivePortalState& state) = 0; protected: @@ -76,7 +76,7 @@ class NetworkPortalDetector { // Returns Captive Portal state for a given |network|. virtual CaptivePortalState GetCaptivePortalState( - const chromeos::NetworkState* network) = 0; + const chromeos::Network* network) = 0; // Returns true if portal detection is enabled. virtual bool IsEnabled() = 0; diff --git a/chrome/browser/chromeos/net/network_portal_detector_impl.cc b/chrome/browser/chromeos/net/network_portal_detector_impl.cc index ff6e918..4d3b452 100644 --- a/chrome/browser/chromeos/net/network_portal_detector_impl.cc +++ b/chrome/browser/chromeos/net/network_portal_detector_impl.cc @@ -12,12 +12,9 @@ #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" -#include "chromeos/network/network_state.h" -#include "chromeos/network/network_state_handler.h" #include "content/public/browser/notification_service.h" #include "grit/generated_resources.h" #include "net/http/http_status_code.h" -#include "third_party/cros_system_api/dbus/service_constants.h" #include "ui/base/l10n/l10n_util.h" using captive_portal::CaptivePortalDetector; @@ -26,7 +23,7 @@ namespace chromeos { namespace { -// Maximum number of portal detections for the same default network +// Maximum number of portal detections for the same active network // after network change. const int kMaxRequestAttempts = 3; @@ -68,11 +65,31 @@ std::string CaptivePortalStatusString( IDS_CHROMEOS_CAPTIVE_PORTAL_STATUS_UNRECOGNIZED); } +NetworkLibrary* GetNetworkLibrary() { + CHECK(CrosLibrary::Get()); + return CrosLibrary::Get()->GetNetworkLibrary(); +} + +const Network* GetActiveNetwork() { + NetworkLibrary* cros = GetNetworkLibrary(); + if (!cros) + return NULL; + return cros->active_network(); +} + +const Network* FindNetworkByPath(const std::string& service_path) { + NetworkLibrary* cros = GetNetworkLibrary(); + if (!cros) + return NULL; + return cros->FindNetworkByPath(service_path); +} + } // namespace NetworkPortalDetectorImpl::NetworkPortalDetectorImpl( const scoped_refptr<net::URLRequestContextGetter>& request_context) - : test_url_(CaptivePortalDetector::kDefaultURL), + : active_connection_state_(STATE_UNKNOWN), + test_url_(CaptivePortalDetector::kDefaultURL), enabled_(false), weak_ptr_factory_(this), attempt_count_(0), @@ -101,7 +118,10 @@ void NetworkPortalDetectorImpl::Init() { DCHECK(CalledOnValidThread()); state_ = STATE_IDLE; - NetworkStateHandler::Get()->AddObserver(this); + chromeos::NetworkLibrary* network_library = GetNetworkLibrary(); + DCHECK(network_library); + network_library->AddNetworkManagerObserver(this); + network_library->RemoveObserverForAllNetworks(this); } void NetworkPortalDetectorImpl::Shutdown() { @@ -113,8 +133,9 @@ void NetworkPortalDetectorImpl::Shutdown() { captive_portal_detector_->Cancel(); captive_portal_detector_.reset(); observers_.Clear(); - if (NetworkStateHandler::IsInitialized()) - NetworkStateHandler::Get()->RemoveObserver(this); + chromeos::NetworkLibrary* network_library = GetNetworkLibrary(); + if (network_library) + network_library->RemoveNetworkManagerObserver(this); } void NetworkPortalDetectorImpl::AddObserver(Observer* observer) { @@ -129,7 +150,7 @@ void NetworkPortalDetectorImpl::AddAndFireObserver(Observer* observer) { if (!observer) return; AddObserver(observer); - const NetworkState* network = NetworkStateHandler::Get()->DefaultNetwork(); + const Network* network = GetActiveNetwork(); observer->OnPortalDetectionCompleted(network, GetCaptivePortalState(network)); } @@ -155,21 +176,20 @@ void NetworkPortalDetectorImpl::Enable(bool start_detection) { return; state_ = STATE_IDLE; attempt_count_ = 0; - const NetworkState* default_network = - NetworkStateHandler::Get()->DefaultNetwork(); - if (!default_network) + const Network* active_network = GetActiveNetwork(); + if (!active_network) return; - portal_state_map_.erase(default_network->path()); + portal_state_map_.erase(active_network->service_path()); DetectCaptivePortal(base::TimeDelta()); } NetworkPortalDetectorImpl::CaptivePortalState -NetworkPortalDetectorImpl::GetCaptivePortalState(const NetworkState* network) { +NetworkPortalDetectorImpl::GetCaptivePortalState(const Network* network) { DCHECK(CalledOnValidThread()); if (!network) return CaptivePortalState(); CaptivePortalStateMap::const_iterator it = - portal_state_map_.find(network->path()); + portal_state_map_.find(network->service_path()); if (it == portal_state_map_.end()) return CaptivePortalState(); return it->second; @@ -196,23 +216,29 @@ void NetworkPortalDetectorImpl::DisableLazyDetection() { VLOG(1) << "Lazy detection mode disabled."; } -void NetworkPortalDetectorImpl::NetworkManagerChanged() { +void NetworkPortalDetectorImpl::OnNetworkManagerChanged(NetworkLibrary* cros) { DCHECK(CalledOnValidThread()); - const NetworkState* default_network = - NetworkStateHandler::Get()->DefaultNetwork(); - if (!default_network) { - default_network_id_.clear(); + CHECK(cros); + const Network* active_network = cros->active_network(); + if (!active_network) { + active_network_id_.clear(); return; } - default_network_id_ = default_network->guid(); + active_network_id_ = active_network->unique_id(); - bool network_changed = (default_service_path_ != default_network->path()); - default_service_path_ = default_network->path(); + bool network_changed = + (active_service_path_ != active_network->service_path()); + if (network_changed) { + if (!active_service_path_.empty()) + cros->RemoveNetworkObserver(active_service_path_, this); + active_service_path_ = active_network->service_path(); + cros->AddNetworkObserver(active_service_path_, this); + } - bool connection_state_changed = (default_connection_state_ != - default_network->connection_state()); - default_connection_state_ = default_network->connection_state(); + bool connection_state_changed = + (active_connection_state_ != active_network->connection_state()); + active_connection_state_ = active_network->connection_state(); if (network_changed || connection_state_changed) { attempt_count_ = 0; @@ -220,12 +246,14 @@ void NetworkPortalDetectorImpl::NetworkManagerChanged() { } if (!IsCheckingForPortal() && !IsPortalCheckPending() && - NetworkState::StateIsConnected(default_connection_state_) && + Network::IsConnectedState(active_connection_state_) && (attempt_count_ < kMaxRequestAttempts || lazy_detection_enabled())) { + DCHECK(active_network); + // Initiate Captive Portal detection if network's captive // portal state is unknown (e.g. for freshly created networks), // offline or if network connection state was changed. - CaptivePortalState state = GetCaptivePortalState(default_network); + CaptivePortalState state = GetCaptivePortalState(active_network); if (state.status == CAPTIVE_PORTAL_STATUS_UNKNOWN || state.status == CAPTIVE_PORTAL_STATUS_OFFLINE || (!network_changed && connection_state_changed)) { @@ -234,9 +262,11 @@ void NetworkPortalDetectorImpl::NetworkManagerChanged() { } } -void NetworkPortalDetectorImpl::DefaultNetworkChanged( - const NetworkState* network) { - NetworkManagerChanged(); +void NetworkPortalDetectorImpl::OnNetworkChanged( + chromeos::NetworkLibrary* cros, + const chromeos::Network* network) { + DCHECK(CalledOnValidThread()); + OnNetworkManagerChanged(cros); } void NetworkPortalDetectorImpl::DetectCaptivePortal( @@ -288,7 +318,7 @@ void NetworkPortalDetectorImpl::DetectCaptivePortalTask() { if (attempt_count_ < kMaxRequestAttempts) { ++attempt_count_; VLOG(1) << "Portal detection started: " - << "network=" << default_network_id_ << ", " + << "network=" << active_network_id_ << ", " << "attempt=" << attempt_count_ << " of " << kMaxRequestAttempts; } else { DCHECK(lazy_detection_enabled()); @@ -311,7 +341,7 @@ void NetworkPortalDetectorImpl::PortalDetectionTimeout() { DCHECK(CalledOnValidThread()); DCHECK(IsCheckingForPortal()); - VLOG(1) << "Portal detection timeout: network=" << default_network_id_; + VLOG(1) << "Portal detection timeout: network=" << active_network_id_; captive_portal_detector_->Cancel(); CaptivePortalDetector::Results results; @@ -334,7 +364,7 @@ void NetworkPortalDetectorImpl::OnPortalDetectionCompleted( DCHECK(IsCheckingForPortal()); VLOG(1) << "Portal detection completed: " - << "network=" << default_network_id_ << ", " + << "network=" << active_network_id_ << ", " << "result=" << CaptivePortalDetector::CaptivePortalResultToString( results.result) << ", " << "response_code=" << results.response_code; @@ -342,8 +372,8 @@ void NetworkPortalDetectorImpl::OnPortalDetectionCompleted( state_ = STATE_IDLE; detection_timeout_.Cancel(); - const NetworkState* default_network = - NetworkStateHandler::Get()->DefaultNetwork(); + NetworkLibrary* cros = GetNetworkLibrary(); + const Network* active_network = cros->active_network(); CaptivePortalState state; state.response_code = results.response_code; @@ -352,11 +382,10 @@ void NetworkPortalDetectorImpl::OnPortalDetectionCompleted( if (attempt_count_ >= kMaxRequestAttempts) { if (state.response_code == net::HTTP_PROXY_AUTHENTICATION_REQUIRED) { state.status = CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED; - } else if (default_network && (default_network->connection_state() == - flimflam::kStatePortal)) { + } else if (active_network && active_network->restricted_pool()) { // Take into account shill's detection results. state.status = CAPTIVE_PORTAL_STATUS_PORTAL; - LOG(WARNING) << "Network " << default_network->guid() << " " + LOG(WARNING) << "Network " << active_network->unique_id() << " " << "is marked as " << CaptivePortalStatusString(state.status) << " " << "despite the fact that CaptivePortalDetector " @@ -364,18 +393,18 @@ void NetworkPortalDetectorImpl::OnPortalDetectionCompleted( } else { state.status = CAPTIVE_PORTAL_STATUS_OFFLINE; } - SetCaptivePortalState(default_network, state); + SetCaptivePortalState(active_network, state); } else { DetectCaptivePortal(results.retry_after_delta); } break; case captive_portal::RESULT_INTERNET_CONNECTED: state.status = CAPTIVE_PORTAL_STATUS_ONLINE; - SetCaptivePortalState(default_network, state); + SetCaptivePortalState(active_network, state); break; case captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL: state.status = CAPTIVE_PORTAL_STATUS_PORTAL; - SetCaptivePortalState(default_network, state); + SetCaptivePortalState(active_network, state); break; default: break; @@ -416,7 +445,7 @@ bool NetworkPortalDetectorImpl::IsCheckingForPortal() const { } void NetworkPortalDetectorImpl::SetCaptivePortalState( - const NetworkState* network, + const Network* network, const CaptivePortalState& state) { if (!detection_start_time_.is_null()) { UMA_HISTOGRAM_TIMES("CaptivePortal.OOBE.DetectionDuration", @@ -429,21 +458,21 @@ void NetworkPortalDetectorImpl::SetCaptivePortalState( } CaptivePortalStateMap::const_iterator it = - portal_state_map_.find(network->path()); + portal_state_map_.find(network->service_path()); if (it == portal_state_map_.end() || it->second.status != state.status || it->second.response_code != state.response_code) { VLOG(1) << "Updating Chrome Captive Portal state: " - << "network=" << network->guid() << ", " + << "network=" << network->unique_id() << ", " << "status=" << CaptivePortalStatusString(state.status) << ", " << "response_code=" << state.response_code; - portal_state_map_[network->path()] = state; + portal_state_map_[network->service_path()] = state; } NotifyPortalDetectionCompleted(network, state); } void NetworkPortalDetectorImpl::NotifyPortalDetectionCompleted( - const NetworkState* network, + const Network* network, const CaptivePortalState& state) { FOR_EACH_OBSERVER(Observer, observers_, OnPortalDetectionCompleted(network, state)); diff --git a/chrome/browser/chromeos/net/network_portal_detector_impl.h b/chrome/browser/chromeos/net/network_portal_detector_impl.h index 60ad25b..cbae7b2 100644 --- a/chrome/browser/chromeos/net/network_portal_detector_impl.h +++ b/chrome/browser/chromeos/net/network_portal_detector_impl.h @@ -18,8 +18,8 @@ #include "base/threading/non_thread_safe.h" #include "base/time.h" #include "chrome/browser/captive_portal/captive_portal_detector.h" +#include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/net/network_portal_detector.h" -#include "chromeos/network/network_state_handler_observer.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "googleurl/src/gurl.h" @@ -31,15 +31,14 @@ class URLRequestContextGetter; namespace chromeos { -class NetworkState; - // This class handles all notifications about network changes from -// NetworkLibrary and delegates portal detection for the default +// NetworkLibrary and delegates portal detection for the active // network to CaptivePortalService. class NetworkPortalDetectorImpl : public NetworkPortalDetector, public base::NonThreadSafe, - public chromeos::NetworkStateHandlerObserver, + public chromeos::NetworkLibrary::NetworkManagerObserver, + public chromeos::NetworkLibrary::NetworkObserver, public content::NotificationObserver { public: explicit NetworkPortalDetectorImpl( @@ -53,16 +52,19 @@ class NetworkPortalDetectorImpl virtual void AddAndFireObserver(Observer* observer) OVERRIDE; virtual void RemoveObserver(Observer* observer) OVERRIDE; virtual CaptivePortalState GetCaptivePortalState( - const chromeos::NetworkState* network) OVERRIDE; + const chromeos::Network* network) OVERRIDE; virtual bool IsEnabled() OVERRIDE; virtual void Enable(bool start_detection) OVERRIDE; virtual bool StartDetectionIfIdle() OVERRIDE; virtual void EnableLazyDetection() OVERRIDE; virtual void DisableLazyDetection() OVERRIDE; - // NetworkStateHandlerObserver implementation: - virtual void NetworkManagerChanged() OVERRIDE; - virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE; + // NetworkLibrary::NetworkManagerObserver implementation: + virtual void OnNetworkManagerChanged(chromeos::NetworkLibrary* cros) OVERRIDE; + + // NetworkLibrary::NetworkObserver implementation: + virtual void OnNetworkChanged(chromeos::NetworkLibrary* cros, + const chromeos::Network* network) OVERRIDE; private: friend class NetworkPortalDetectorImplTest; @@ -110,11 +112,11 @@ class NetworkPortalDetectorImpl bool IsCheckingForPortal() const; // Stores captive portal state for a |network|. - void SetCaptivePortalState(const NetworkState* network, + void SetCaptivePortalState(const Network* network, const CaptivePortalState& results); // Notifies observers that portal detection is completed for a |network|. - void NotifyPortalDetectionCompleted(const NetworkState* network, + void NotifyPortalDetectionCompleted(const Network* network, const CaptivePortalState& state); // Returns the current TimeTicks. @@ -164,14 +166,14 @@ class NetworkPortalDetectorImpl // cancelled. bool DetectionTimeoutIsCancelledForTesting() const; - // Unique identifier of the default network. - std::string default_network_id_; + // Unique identifier of the active network. + std::string active_network_id_; - // Service path of the default network. - std::string default_service_path_; + // Service path of the active network. + std::string active_service_path_; - // Connection state of the default network. - std::string default_connection_state_; + // Connection state of the active network. + ConnectionState active_connection_state_; State state_; CaptivePortalStateMap portal_state_map_; @@ -183,7 +185,7 @@ class NetworkPortalDetectorImpl // URL that returns a 204 response code when connected to the Internet. GURL test_url_; - // Detector for checking default network for a portal state. + // Detector for checking active network for a portal state. scoped_ptr<captive_portal::CaptivePortalDetector> captive_portal_detector_; // True if the NetworkPortalDetector is enabled. @@ -191,7 +193,7 @@ class NetworkPortalDetectorImpl base::WeakPtrFactory<NetworkPortalDetectorImpl> weak_ptr_factory_; - // Number of portal detection attemps for a default network. + // Number of portal detection attemps for an active network. int attempt_count_; bool lazy_detection_enabled_; @@ -201,7 +203,7 @@ class NetworkPortalDetectorImpl base::TimeDelta lazy_check_interval_; // Minimum time between consecutive portal checks for the same - // default network. + // active network. base::TimeDelta min_time_between_attempts_; // Start time of portal detection. diff --git a/chrome/browser/chromeos/net/network_portal_detector_impl_unittest.cc b/chrome/browser/chromeos/net/network_portal_detector_impl_unittest.cc index 9a25bfd..9f819c6 100644 --- a/chrome/browser/chromeos/net/network_portal_detector_impl_unittest.cc +++ b/chrome/browser/chromeos/net/network_portal_detector_impl_unittest.cc @@ -9,34 +9,15 @@ #include "chrome/browser/captive_portal/captive_portal_detector.h" #include "chrome/browser/captive_portal/testing_utils.h" #include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/browser/chromeos/cros/network_library.h" +#include "chrome/browser/chromeos/cros/network_library_impl_base.h" #include "chrome/browser/chromeos/net/network_portal_detector_impl.h" #include "chrome/test/base/testing_profile.h" -#include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/dbus/shill_device_client.h" -#include "chromeos/dbus/shill_service_client.h" -#include "chromeos/network/network_state.h" -#include "chromeos/network/network_state_handler.h" -#include "dbus/object_path.h" #include "net/base/net_errors.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/cros_system_api/dbus/service_constants.h" namespace chromeos { -namespace { - -void ErrorCallbackFunction(const std::string& error_name, - const std::string& error_message) { - LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; -} - -} // namespace - -// Service paths for stub network devices. -const char* kStubEthernet = "stub_ethernet"; -const char* kStubWireless1 = "stub_wifi1"; -const char* kStubWireless2 = "stub_wifi2"; - class NetworkPortalDetectorImplTest : public testing::Test, public captive_portal::CaptivePortalDetectorTestBase { @@ -45,8 +26,18 @@ class NetworkPortalDetectorImplTest virtual ~NetworkPortalDetectorImplTest() {} virtual void SetUp() { - DBusThreadManager::InitializeWithStub(); - SetupNetworkStateHandler(); + CrosLibrary::Initialize(true); + network_library_ = CrosLibrary::Get()->GetNetworkLibrary(); + DCHECK(network_library_); + + ethernet_network_ = network_library_->FindNetworkByPath("eth1"); + DCHECK(ethernet_network_); + + wifi1_network_ = network_library_->FindNetworkByPath("wifi1"); + DCHECK(wifi1_network_); + + wifi2_network_ = network_library_->FindNetworkByPath("wifi2"); + DCHECK(wifi2_network_); profile_.reset(new TestingProfile()); network_portal_detector_.reset( @@ -62,22 +53,23 @@ class NetworkPortalDetectorImplTest virtual void TearDown() { network_portal_detector_->Shutdown(); - profile_.reset(); - NetworkStateHandler::Shutdown(); - DBusThreadManager::Shutdown(); + CrosLibrary::Shutdown(); } void CheckPortalState(NetworkPortalDetector::CaptivePortalStatus status, int response_code, - const std::string& network_service_path) { - const NetworkState* network = - NetworkStateHandler::Get()->GetNetworkState(network_service_path); + const Network* network) { NetworkPortalDetector::CaptivePortalState state = network_portal_detector()->GetCaptivePortalState(network); ASSERT_EQ(status, state.status); ASSERT_EQ(response_code, state.response_code); } + NetworkLibrary* network_library() { return network_library_; } + Network* ethernet_network() { return ethernet_network_; } + Network* wifi1_network() { return wifi1_network_; } + Network* wifi2_network() { return wifi2_network_; } + Profile* profile() { return profile_.get(); } NetworkPortalDetectorImpl* network_portal_detector() { @@ -145,49 +137,36 @@ class NetworkPortalDetectorImplTest network_portal_detector()->set_time_ticks_for_testing(time_ticks); } - void SetBehindPortal(const std::string& service_path) { - DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( - dbus::ObjectPath(service_path), - flimflam::kStateProperty, base::StringValue(flimflam::kStatePortal), - base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); + void SetBehindPortal(Network* network) { + Network::TestApi test_api(network); + test_api.SetBehindPortal(); + static_cast<NetworkLibraryImplBase*>( + network_library())->CallConnectToNetwork(network); MessageLoop::current()->RunUntilIdle(); } - void SetConnected(const std::string& service_path) { - DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( - dbus::ObjectPath(service_path), - flimflam::kStateProperty, base::StringValue(flimflam::kStateOnline), - base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); + void SetConnected(Network* network) { + Network::TestApi test_api(network); + test_api.SetConnected(); + static_cast<NetworkLibraryImplBase*>( + network_library())->CallConnectToNetwork(network); MessageLoop::current()->RunUntilIdle(); } private: - void SetupDefaultShillState() { - MessageLoop::current()->RunUntilIdle(); - ShillServiceClient::TestInterface* service_test = - DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); - service_test->ClearServices(); - const bool add_to_watchlist = true; - service_test->AddService(kStubEthernet, - kStubEthernet, - flimflam::kTypeEthernet, flimflam::kStateIdle, - add_to_watchlist); - service_test->AddService(kStubWireless1, - kStubWireless1, - flimflam::kTypeWifi, flimflam::kStateIdle, - add_to_watchlist); - service_test->AddService(kStubWireless2, - kStubWireless2, - flimflam::kTypeWifi, flimflam::kStateIdle, - add_to_watchlist); - } + NetworkLibrary* network_library_; - void SetupNetworkStateHandler() { - SetupDefaultShillState(); - NetworkStateHandler::Initialize(); - } + // Pointer to a fake ethernet network. + Network* ethernet_network_; + + // Pointer to a fake wifi1 network. + Network* wifi1_network_; + + // Pointer to a fake wifi2 network. + Network* wifi2_network_; MessageLoop message_loop_; + scoped_ptr<TestingProfile> profile_; scoped_ptr<NetworkPortalDetectorImpl> network_portal_detector_; }; @@ -195,86 +174,86 @@ class NetworkPortalDetectorImplTest TEST_F(NetworkPortalDetectorImplTest, NoPortal) { ASSERT_TRUE(is_state_idle()); - SetConnected(kStubWireless1); + SetConnected(wifi1_network()); ASSERT_TRUE(is_state_checking_for_portal()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN, -1, - kStubWireless1); + wifi1_network()); CompleteURLFetch(net::OK, 204, NULL); ASSERT_TRUE(is_state_idle()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204, - kStubWireless1); + wifi1_network()); } TEST_F(NetworkPortalDetectorImplTest, Portal) { ASSERT_TRUE(is_state_idle()); // Check HTTP 200 response code. - SetConnected(kStubWireless1); + SetConnected(wifi1_network()); ASSERT_TRUE(is_state_checking_for_portal()); CompleteURLFetch(net::OK, 200, NULL); ASSERT_TRUE(is_state_idle()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, - kStubWireless1); + wifi1_network()); // Check HTTP 301 response code. - SetConnected(kStubWireless2); + SetConnected(wifi2_network()); ASSERT_TRUE(is_state_checking_for_portal()); CompleteURLFetch(net::OK, 301, NULL); ASSERT_TRUE(is_state_idle()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 301, - kStubWireless2); + wifi2_network()); // Check HTTP 302 response code. - SetConnected(kStubEthernet); + SetConnected(ethernet_network()); ASSERT_TRUE(is_state_checking_for_portal()); CompleteURLFetch(net::OK, 302, NULL); ASSERT_TRUE(is_state_idle()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 302, - kStubEthernet); + ethernet_network()); } TEST_F(NetworkPortalDetectorImplTest, TwoNetworks) { ASSERT_TRUE(is_state_idle()); - SetConnected(kStubWireless1); + SetConnected(wifi1_network()); ASSERT_TRUE(is_state_checking_for_portal()); // wifi is in portal state. CompleteURLFetch(net::OK, 200, NULL); ASSERT_TRUE(is_state_idle()); - SetConnected(kStubEthernet); + SetConnected(ethernet_network()); ASSERT_TRUE(is_state_checking_for_portal()); // ethernet is in online state. CompleteURLFetch(net::OK, 204, NULL); ASSERT_TRUE(is_state_idle()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204, - kStubEthernet); + ethernet_network()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, - kStubWireless1); + wifi1_network()); } TEST_F(NetworkPortalDetectorImplTest, NetworkChanged) { ASSERT_TRUE(is_state_idle()); - SetConnected(kStubWireless1); + SetConnected(wifi1_network()); // WiFi is in portal state. fetcher()->set_response_code(200); ASSERT_TRUE(is_state_checking_for_portal()); // Active network is changed during portal detection for wifi. - SetConnected(kStubEthernet); + SetConnected(ethernet_network()); // Portal detection for wifi is cancelled, portal detection for // ethernet is initiated. @@ -284,27 +263,27 @@ TEST_F(NetworkPortalDetectorImplTest, NetworkChanged) { CompleteURLFetch(net::OK, 204, NULL); ASSERT_TRUE(is_state_idle()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204, - kStubEthernet); + ethernet_network()); // As active network was changed during portal detection for wifi // network, it's state must be unknown. CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN, -1, - kStubWireless1); + wifi1_network()); } TEST_F(NetworkPortalDetectorImplTest, NetworkStateNotChanged) { ASSERT_TRUE(is_state_idle()); - SetConnected(kStubWireless1); + SetConnected(wifi1_network()); ASSERT_TRUE(is_state_checking_for_portal()); CompleteURLFetch(net::OK, 204, NULL); ASSERT_TRUE(is_state_idle()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204, - kStubWireless1); + wifi1_network()); - SetConnected(kStubWireless1); + SetConnected(wifi1_network()); ASSERT_TRUE(is_state_idle()); } @@ -312,32 +291,32 @@ TEST_F(NetworkPortalDetectorImplTest, NetworkStateChanged) { // Test for Portal -> Online -> Portal network state transitions. ASSERT_TRUE(is_state_idle()); - SetBehindPortal(kStubWireless1); + SetBehindPortal(wifi1_network()); ASSERT_TRUE(is_state_checking_for_portal()); CompleteURLFetch(net::OK, 200, NULL); ASSERT_TRUE(is_state_idle()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, - kStubWireless1); + wifi1_network()); - SetConnected(kStubWireless1); + SetConnected(wifi1_network()); ASSERT_TRUE(is_state_checking_for_portal()); CompleteURLFetch(net::OK, 204, NULL); ASSERT_TRUE(is_state_idle()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204, - kStubWireless1); + wifi1_network()); - SetBehindPortal(kStubWireless1); + SetBehindPortal(wifi1_network()); ASSERT_TRUE(is_state_checking_for_portal()); CompleteURLFetch(net::OK, 200, NULL); ASSERT_TRUE(is_state_idle()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, - kStubWireless1); + wifi1_network()); } TEST_F(NetworkPortalDetectorImplTest, PortalDetectionTimeout) { @@ -349,7 +328,7 @@ TEST_F(NetworkPortalDetectorImplTest, PortalDetectionTimeout) { ASSERT_TRUE(is_state_idle()); ASSERT_EQ(0, attempt_count()); - SetConnected(kStubWireless1); + SetConnected(wifi1_network()); MessageLoop::current()->RunUntilIdle(); // First portal detection timeouts, next portal detection is @@ -367,7 +346,7 @@ TEST_F(NetworkPortalDetectorImplTest, PortalDetectionRetryAfter) { ASSERT_TRUE(is_state_idle()); ASSERT_EQ(0, attempt_count()); - SetConnected(kStubWireless1); + SetConnected(wifi1_network()); CompleteURLFetch(net::OK, 503, retry_after); // First portal detection completed, next portal detection is @@ -385,7 +364,7 @@ TEST_F(NetworkPortalDetectorImplTest, PortalDetectorRetryAfterIsSmall) { ASSERT_TRUE(is_state_idle()); ASSERT_EQ(0, attempt_count()); - SetConnected(kStubWireless1); + SetConnected(wifi1_network()); CompleteURLFetch(net::OK, 503, retry_after); // First portal detection completed, next portal detection is @@ -405,7 +384,7 @@ TEST_F(NetworkPortalDetectorImplTest, FirstAttemptFailed) { ASSERT_TRUE(is_state_idle()); ASSERT_EQ(0, attempt_count()); - SetConnected(kStubWireless1); + SetConnected(wifi1_network()); CompleteURLFetch(net::OK, 503, retry_after); ASSERT_TRUE(is_state_portal_detection_pending()); @@ -419,7 +398,7 @@ TEST_F(NetworkPortalDetectorImplTest, FirstAttemptFailed) { ASSERT_TRUE(is_state_idle()); ASSERT_EQ(2, attempt_count()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204, - kStubWireless1); + wifi1_network()); } TEST_F(NetworkPortalDetectorImplTest, AllAttemptsFailed) { @@ -431,7 +410,7 @@ TEST_F(NetworkPortalDetectorImplTest, AllAttemptsFailed) { ASSERT_TRUE(is_state_idle()); ASSERT_EQ(0, attempt_count()); - SetConnected(kStubWireless1); + SetConnected(wifi1_network()); CompleteURLFetch(net::OK, 503, retry_after); ASSERT_TRUE(is_state_portal_detection_pending()); @@ -453,19 +432,19 @@ TEST_F(NetworkPortalDetectorImplTest, AllAttemptsFailed) { ASSERT_TRUE(is_state_idle()); ASSERT_EQ(3, attempt_count()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE, 503, - kStubWireless1); + wifi1_network()); } TEST_F(NetworkPortalDetectorImplTest, ProxyAuthRequired) { ASSERT_TRUE(is_state_idle()); set_min_time_between_attempts(base::TimeDelta()); - SetConnected(kStubWireless1); + SetConnected(wifi1_network()); CompleteURLFetch(net::OK, 407, NULL); ASSERT_EQ(1, attempt_count()); ASSERT_TRUE(is_state_portal_detection_pending()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN, -1, - kStubWireless1); + wifi1_network()); // To run CaptivePortalDetector::DetectCaptivePortal(). MessageLoop::current()->RunUntilIdle(); @@ -474,7 +453,7 @@ TEST_F(NetworkPortalDetectorImplTest, ProxyAuthRequired) { ASSERT_EQ(2, attempt_count()); ASSERT_TRUE(is_state_portal_detection_pending()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN, -1, - kStubWireless1); + wifi1_network()); // To run CaptivePortalDetector::DetectCaptivePortal(). MessageLoop::current()->RunUntilIdle(); @@ -484,14 +463,14 @@ TEST_F(NetworkPortalDetectorImplTest, ProxyAuthRequired) { ASSERT_TRUE(is_state_idle()); CheckPortalState( NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED, 407, - kStubWireless1); + wifi1_network()); } TEST_F(NetworkPortalDetectorImplTest, NoResponseButBehindPortal) { ASSERT_TRUE(is_state_idle()); set_min_time_between_attempts(base::TimeDelta()); - SetBehindPortal(kStubWireless1); + SetBehindPortal(wifi1_network()); ASSERT_TRUE(is_state_checking_for_portal()); CompleteURLFetch(net::ERR_CONNECTION_CLOSED, @@ -520,7 +499,7 @@ TEST_F(NetworkPortalDetectorImplTest, NoResponseButBehindPortal) { CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, net::URLFetcher::RESPONSE_CODE_INVALID, - kStubWireless1); + wifi1_network()); } TEST_F(NetworkPortalDetectorImplTest, LazyDetectionForOnlineNetwork) { @@ -528,7 +507,7 @@ TEST_F(NetworkPortalDetectorImplTest, LazyDetectionForOnlineNetwork) { set_min_time_between_attempts(base::TimeDelta()); set_lazy_check_interval(base::TimeDelta()); - SetConnected(kStubWireless1); + SetConnected(wifi1_network()); enable_lazy_detection(); CompleteURLFetch(net::OK, 204, NULL); @@ -536,7 +515,7 @@ TEST_F(NetworkPortalDetectorImplTest, LazyDetectionForOnlineNetwork) { ASSERT_TRUE(is_state_portal_detection_pending()); CheckPortalState( NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204, - kStubWireless1); + wifi1_network()); // To run CaptivePortalDetector::DetectCaptivePortal(). MessageLoop::current()->RunUntilIdle(); @@ -547,7 +526,7 @@ TEST_F(NetworkPortalDetectorImplTest, LazyDetectionForOnlineNetwork) { ASSERT_TRUE(is_state_portal_detection_pending()); CheckPortalState( NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204, - kStubWireless1); + wifi1_network()); // To run CaptivePortalDetector::DetectCaptivePortal(). MessageLoop::current()->RunUntilIdle(); @@ -561,7 +540,7 @@ TEST_F(NetworkPortalDetectorImplTest, LazyDetectionForOnlineNetwork) { ASSERT_TRUE(is_state_idle()); CheckPortalState( NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204, - kStubWireless1); + wifi1_network()); } TEST_F(NetworkPortalDetectorImplTest, LazyDetectionForPortalNetwork) { @@ -569,7 +548,7 @@ TEST_F(NetworkPortalDetectorImplTest, LazyDetectionForPortalNetwork) { set_min_time_between_attempts(base::TimeDelta()); set_lazy_check_interval(base::TimeDelta()); - SetConnected(kStubWireless1); + SetConnected(wifi1_network()); enable_lazy_detection(); CompleteURLFetch(net::ERR_CONNECTION_CLOSED, @@ -578,7 +557,7 @@ TEST_F(NetworkPortalDetectorImplTest, LazyDetectionForPortalNetwork) { ASSERT_EQ(1, attempt_count()); ASSERT_TRUE(is_state_portal_detection_pending()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN, -1, - kStubWireless1); + wifi1_network()); // To run CaptivePortalDetector::DetectCaptivePortal(). MessageLoop::current()->RunUntilIdle(); @@ -589,7 +568,7 @@ TEST_F(NetworkPortalDetectorImplTest, LazyDetectionForPortalNetwork) { ASSERT_EQ(2, attempt_count()); ASSERT_TRUE(is_state_portal_detection_pending()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN, -1, - kStubWireless1); + wifi1_network()); // To run CaptivePortalDetector::DetectCaptivePortal(). MessageLoop::current()->RunUntilIdle(); @@ -598,7 +577,7 @@ TEST_F(NetworkPortalDetectorImplTest, LazyDetectionForPortalNetwork) { ASSERT_EQ(3, attempt_count()); ASSERT_TRUE(is_state_portal_detection_pending()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, - kStubWireless1); + wifi1_network()); // To run CaptivePortalDetector::DetectCaptivePortal(). MessageLoop::current()->RunUntilIdle(); @@ -611,24 +590,24 @@ TEST_F(NetworkPortalDetectorImplTest, LazyDetectionForPortalNetwork) { ASSERT_EQ(3, attempt_count()); ASSERT_TRUE(is_state_idle()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, - kStubWireless1); + wifi1_network()); } TEST_F(NetworkPortalDetectorImplTest, DetectionTimeoutIsCancelled) { ASSERT_TRUE(is_state_idle()); set_min_time_between_attempts(base::TimeDelta()); - SetConnected(kStubWireless1); + SetConnected(wifi1_network()); ASSERT_TRUE(is_state_checking_for_portal()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN, -1, - kStubWireless1); + wifi1_network()); cancel_portal_detection(); ASSERT_TRUE(is_state_idle()); ASSERT_TRUE(detection_timeout_is_cancelled()); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN, -1, - kStubWireless1); + wifi1_network()); } TEST_F(NetworkPortalDetectorImplTest, TestDetectionRestart) { @@ -636,14 +615,14 @@ TEST_F(NetworkPortalDetectorImplTest, TestDetectionRestart) { set_min_time_between_attempts(base::TimeDelta()); // First portal detection attempts determines ONLINE state. - SetConnected(kStubWireless1); + SetConnected(wifi1_network()); ASSERT_TRUE(is_state_checking_for_portal()); ASSERT_FALSE(start_detection_if_idle()); CompleteURLFetch(net::OK, 204, NULL); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204, - kStubWireless1); + wifi1_network()); ASSERT_TRUE(is_state_idle()); // First portal detection attempts determines PORTAL state. @@ -656,7 +635,7 @@ TEST_F(NetworkPortalDetectorImplTest, TestDetectionRestart) { CompleteURLFetch(net::OK, 200, NULL); CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, - kStubWireless1); + wifi1_network()); ASSERT_TRUE(is_state_idle()); } diff --git a/chrome/browser/chromeos/net/network_portal_detector_stub.cc b/chrome/browser/chromeos/net/network_portal_detector_stub.cc index 176c684..35af222 100644 --- a/chrome/browser/chromeos/net/network_portal_detector_stub.cc +++ b/chrome/browser/chromeos/net/network_portal_detector_stub.cc @@ -4,12 +4,11 @@ #include "chrome/browser/chromeos/net/network_portal_detector_stub.h" -#include "chromeos/network/network_state.h" +#include "chrome/browser/chromeos/cros/network_library.h" namespace chromeos { -NetworkPortalDetectorStub::NetworkPortalDetectorStub() - : default_network_(NULL) { +NetworkPortalDetectorStub::NetworkPortalDetectorStub() : active_network_(NULL) { } NetworkPortalDetectorStub::~NetworkPortalDetectorStub() { @@ -30,14 +29,13 @@ void NetworkPortalDetectorStub::AddAndFireObserver(Observer* observer) { AddObserver(observer); if (!observer) return; - if (!default_network_ || - !portal_state_map_.count(default_network_->path())) { - observer->OnPortalDetectionCompleted(default_network_.get(), - CaptivePortalState()); + if (!active_network_ || + !portal_state_map_.count(active_network_->service_path())) { + observer->OnPortalDetectionCompleted(active_network_, CaptivePortalState()); } else { observer->OnPortalDetectionCompleted( - default_network_.get(), - portal_state_map_[default_network_->path()]); + active_network_, + portal_state_map_[active_network_->service_path()]); } } @@ -48,10 +46,10 @@ void NetworkPortalDetectorStub::RemoveObserver(Observer* observer) { NetworkPortalDetector::CaptivePortalState NetworkPortalDetectorStub::GetCaptivePortalState( - const chromeos::NetworkState* network) { - if (!network || !portal_state_map_.count(network->path())) + const chromeos::Network* network) { + if (!network || !portal_state_map_.count(network->service_path())) return CaptivePortalState(); - return portal_state_map_[network->path()]; + return portal_state_map_[network->service_path()]; } bool NetworkPortalDetectorStub::IsEnabled() { @@ -71,30 +69,27 @@ void NetworkPortalDetectorStub::EnableLazyDetection() { void NetworkPortalDetectorStub::DisableLazyDetection() { } -void NetworkPortalDetectorStub::SetDefaultNetworkPathForTesting( - const std::string& service_path) { - if (service_path.empty()) - default_network_.reset(); - else - default_network_.reset(new NetworkState(service_path)); +void NetworkPortalDetectorStub::SetActiveNetworkForTesting( + const Network* network) { + active_network_ = network; } void NetworkPortalDetectorStub::SetDetectionResultsForTesting( - const std::string& service_path, + const Network* network, const CaptivePortalState& state) { - if (service_path.empty()) + if (!network) return; - portal_state_map_[service_path] = state; + portal_state_map_[network->service_path()] = state; } void NetworkPortalDetectorStub::NotifyObserversForTesting() { CaptivePortalState state; - if (default_network_ && - portal_state_map_.count(default_network_->path())) { - state = portal_state_map_[default_network_->path()]; + if (active_network_ && + portal_state_map_.count(active_network_->service_path())) { + state = portal_state_map_[active_network_->service_path()]; } FOR_EACH_OBSERVER(Observer, observers_, - OnPortalDetectionCompleted(default_network_.get(), state)); + OnPortalDetectionCompleted(active_network_, state)); } } // namespace chromeos diff --git a/chrome/browser/chromeos/net/network_portal_detector_stub.h b/chrome/browser/chromeos/net/network_portal_detector_stub.h index bfdf36f..e3b8c2af 100644 --- a/chrome/browser/chromeos/net/network_portal_detector_stub.h +++ b/chrome/browser/chromeos/net/network_portal_detector_stub.h @@ -10,7 +10,6 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/hash_tables.h" -#include "base/memory/scoped_ptr.h" #include "base/observer_list.h" #include "chrome/browser/chromeos/net/network_portal_detector.h" @@ -28,7 +27,7 @@ class NetworkPortalDetectorStub : public NetworkPortalDetector { virtual void AddAndFireObserver(Observer* observer) OVERRIDE; virtual void RemoveObserver(Observer* observer) OVERRIDE; virtual CaptivePortalState GetCaptivePortalState( - const chromeos::NetworkState* network) OVERRIDE; + const chromeos::Network* network) OVERRIDE; virtual bool IsEnabled() OVERRIDE; virtual void Enable(bool start_detection) OVERRIDE; virtual bool StartDetectionIfIdle() OVERRIDE; @@ -41,13 +40,13 @@ class NetworkPortalDetectorStub : public NetworkPortalDetector { typedef std::string NetworkId; typedef base::hash_map<NetworkId, CaptivePortalState> CaptivePortalStateMap; - void SetDefaultNetworkPathForTesting(const std::string& service_path); - void SetDetectionResultsForTesting(const std::string& service_path, + void SetActiveNetworkForTesting(const Network* network); + void SetDetectionResultsForTesting(const Network* network, const CaptivePortalState& state); void NotifyObserversForTesting(); ObserverList<Observer> observers_; - scoped_ptr<NetworkState> default_network_; + const Network* active_network_; CaptivePortalStateMap portal_state_map_; DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetectorStub); diff --git a/chrome/browser/chromeos/proxy_config_service_impl.cc b/chrome/browser/chromeos/proxy_config_service_impl.cc index cc0c964..71ba976 100644 --- a/chrome/browser/chromeos/proxy_config_service_impl.cc +++ b/chrome/browser/chromeos/proxy_config_service_impl.cc @@ -573,12 +573,11 @@ void ProxyConfigServiceImpl::OnNetworkChanged(NetworkLibrary* network_lib, } // static -bool ProxyConfigServiceImpl::ParseProxyConfig( - const std::string& proxy_config_string, - net::ProxyConfig* proxy_config) { - if (!proxy_config) +bool ProxyConfigServiceImpl::ParseProxyConfig(const Network* network, + net::ProxyConfig* proxy_config) { + if (!network || !proxy_config) return false; - JSONStringValueSerializer serializer(proxy_config_string); + JSONStringValueSerializer serializer(network->proxy_config()); scoped_ptr<Value> value(serializer.Deserialize(NULL, NULL)); if (!value.get() || value->GetType() != Value::TYPE_DICTIONARY) return false; @@ -759,7 +758,7 @@ void ProxyConfigServiceImpl::DetermineEffectiveConfig(const Network* network, network_availability = net::ProxyConfigService::CONFIG_VALID; } else if (!network->proxy_config().empty()) { // Network is private or shared with user using shared proxies. - if (ParseProxyConfig(network->proxy_config(), &network_config)) { + if (ParseProxyConfig(network, &network_config)) { VLOG(1) << this << ": using network proxy: " << network->proxy_config(); network_availability = net::ProxyConfigService::CONFIG_VALID; diff --git a/chrome/browser/chromeos/proxy_config_service_impl.h b/chrome/browser/chromeos/proxy_config_service_impl.h index 12fac79..730e003 100644 --- a/chrome/browser/chromeos/proxy_config_service_impl.h +++ b/chrome/browser/chromeos/proxy_config_service_impl.h @@ -198,9 +198,9 @@ class ProxyConfigServiceImpl : public PrefProxyConfigTrackerImpl, virtual void OnNetworkChanged(NetworkLibrary* cros, const Network* network) OVERRIDE; - // Parse |proxy_config_string| and store result in |proxy_config|. + // Parse |network| proxy config and store result in |proxy_config|. // Returns true if proxy config was successfully parsed. - static bool ParseProxyConfig(const std::string& proxy_config_string, + static bool ParseProxyConfig(const Network* network, net::ProxyConfig* proxy_config); // Register UseShardProxies preference. diff --git a/chrome/browser/resources/chromeos/login/network_dropdown.js b/chrome/browser/resources/chromeos/login/network_dropdown.js index 084ca72..0e429cd 100644 --- a/chrome/browser/resources/chromeos/login/network_dropdown.js +++ b/chrome/browser/resources/chromeos/login/network_dropdown.js @@ -388,12 +388,14 @@ cr.define('cr.ui', function() { * the previous one. * @param {string} elementId Id of network drop-down element. * @param {boolean} isOobe Whether drop-down is used by an Oobe screen. + * @param {integer} lastNetworkType Last active network type. Pass -1 if it + * isn't known. */ - DropDown.show = function(elementId, isOobe) { + DropDown.show = function(elementId, isOobe, lastNetworkType) { $(elementId).isShown = false; if (DropDown.activeElementId_ != elementId) { DropDown.activeElementId_ = elementId; - chrome.send('networkDropdownShow', [elementId, isOobe]); + chrome.send('networkDropdownShow', [elementId, isOobe, lastNetworkType]); } }; diff --git a/chrome/browser/resources/chromeos/login/screen_error_message.js b/chrome/browser/resources/chromeos/login/screen_error_message.js index b6cd0b0..c642869 100644 --- a/chrome/browser/resources/chromeos/login/screen_error_message.js +++ b/chrome/browser/resources/chromeos/login/screen_error_message.js @@ -136,7 +136,10 @@ login.createScreen('ErrorMessageScreen', 'error-message', function() { */ onBeforeShow: function(data) { cr.ui.Oobe.clearErrors(); - cr.ui.DropDown.show('offline-networks-list', false); + var lastNetworkType = 0; + if (data && data['lastNetworkType']) + lastNetworkType = data['lastNetworkType']; + cr.ui.DropDown.show('offline-networks-list', false, lastNetworkType); }, /** diff --git a/chrome/browser/ui/webui/chromeos/login/network_dropdown.cc b/chrome/browser/ui/webui/chromeos/login/network_dropdown.cc index 7993b037..7e0ee39 100644 --- a/chrome/browser/ui/webui/chromeos/login/network_dropdown.cc +++ b/chrome/browser/ui/webui/chromeos/login/network_dropdown.cc @@ -126,6 +126,10 @@ NetworkDropdown::~NetworkDropdown() { CrosLibrary::Get()->GetNetworkLibrary()->RemoveNetworkManagerObserver(this); } +void NetworkDropdown::SetLastNetworkType(ConnectionType last_network_type) { + // No longer implemented. TODO(stevenjb): Purge from JS. +} + void NetworkDropdown::OnItemChosen(int id) { network_menu_->OnItemChosen(id); } diff --git a/chrome/browser/ui/webui/chromeos/login/network_dropdown.h b/chrome/browser/ui/webui/chromeos/login/network_dropdown.h index 83cd5ba..6b9fd2f 100644 --- a/chrome/browser/ui/webui/chromeos/login/network_dropdown.h +++ b/chrome/browser/ui/webui/chromeos/login/network_dropdown.h @@ -28,6 +28,9 @@ class NetworkDropdown : public NetworkMenu::Delegate, NetworkDropdown(content::WebUI* web_ui, bool oobe); virtual ~NetworkDropdown(); + // Sets last active network type. Used to show correct disconnected icon. + void SetLastNetworkType(ConnectionType last_network_type); + // This method should be called, when item with the given id is chosen. void OnItemChosen(int id); diff --git a/chrome/browser/ui/webui/chromeos/login/network_dropdown_handler.cc b/chrome/browser/ui/webui/chromeos/login/network_dropdown_handler.cc index e920e32..499cf6d1 100644 --- a/chrome/browser/ui/webui/chromeos/login/network_dropdown_handler.cc +++ b/chrome/browser/ui/webui/chromeos/login/network_dropdown_handler.cc @@ -57,9 +57,12 @@ void NetworkDropdownHandler::HandleNetworkItemChosen(double id) { } void NetworkDropdownHandler::HandleNetworkDropdownShow( - const std::string& element_id, - bool oobe) { + const std::string& element_id, bool oobe, double last_network_type) { dropdown_.reset(new NetworkDropdown(web_ui(), oobe)); + if (last_network_type >= 0) { + dropdown_->SetLastNetworkType( + static_cast<ConnectionType>(last_network_type)); + } } void NetworkDropdownHandler::HandleNetworkDropdownHide() { diff --git a/chrome/browser/ui/webui/chromeos/login/network_dropdown_handler.h b/chrome/browser/ui/webui/chromeos/login/network_dropdown_handler.h index 0279229..df13b51 100644 --- a/chrome/browser/ui/webui/chromeos/login/network_dropdown_handler.h +++ b/chrome/browser/ui/webui/chromeos/login/network_dropdown_handler.h @@ -31,7 +31,8 @@ class NetworkDropdownHandler : public BaseScreenHandler { void HandleNetworkItemChosen(double id); // Handles network drop-down showing. void HandleNetworkDropdownShow(const std::string& element_id, - bool oobe); + bool oobe, + double last_network_type); // Handles network drop-down hiding. void HandleNetworkDropdownHide(); // Handles network drop-down refresh. diff --git a/chrome/browser/ui/webui/chromeos/login/network_state_informer.cc b/chrome/browser/ui/webui/chromeos/login/network_state_informer.cc index 555239d..34d6272 100644 --- a/chrome/browser/ui/webui/chromeos/login/network_state_informer.cc +++ b/chrome/browser/ui/webui/chromeos/login/network_state_informer.cc @@ -7,12 +7,10 @@ #include "base/bind.h" #include "base/logging.h" #include "base/message_loop.h" +#include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/proxy_config_service_impl.h" #include "chrome/common/chrome_notification_types.h" -#include "chromeos/network/network_state.h" -#include "chromeos/network/network_state_handler.h" #include "net/proxy/proxy_config.h" -#include "third_party/cros_system_api/dbus/service_constants.h" namespace { @@ -25,11 +23,13 @@ namespace chromeos { NetworkStateInformer::NetworkStateInformer() : state_(OFFLINE), - delegate_(NULL) { + delegate_(NULL), + last_network_type_(TYPE_WIFI) { } NetworkStateInformer::~NetworkStateInformer() { - NetworkStateHandler::Get()->RemoveObserver(this); + CrosLibrary::Get()->GetNetworkLibrary()-> + RemoveNetworkManagerObserver(this); if (NetworkPortalDetector::IsEnabledInCommandLine() && NetworkPortalDetector::GetInstance()) { NetworkPortalDetector::GetInstance()->RemoveObserver(this); @@ -37,8 +37,9 @@ NetworkStateInformer::~NetworkStateInformer() { } void NetworkStateInformer::Init() { - UpdateState(); - NetworkStateHandler::Get()->AddObserver(this); + NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); + UpdateState(cros); + cros->AddNetworkManagerObserver(this); if (NetworkPortalDetector::IsEnabledInCommandLine() && NetworkPortalDetector::GetInstance()) { @@ -67,14 +68,13 @@ void NetworkStateInformer::RemoveObserver( observers_.RemoveObserver(observer); } -void NetworkStateInformer::NetworkManagerChanged() { - const NetworkState* default_network = - NetworkStateHandler::Get()->DefaultNetwork(); +void NetworkStateInformer::OnNetworkManagerChanged(NetworkLibrary* cros) { + const Network* active_network = cros->active_network(); State new_state = OFFLINE; std::string new_network_service_path; - if (default_network) { - new_state = GetNetworkState(default_network); - new_network_service_path = default_network->path(); + if (active_network) { + new_state = GetNetworkState(active_network); + new_network_service_path = active_network->service_path(); } if ((state_ != ONLINE && (new_state == ONLINE || new_state == CONNECTING)) || (state_ == ONLINE && (new_state == ONLINE || new_state == CONNECTING) && @@ -101,16 +101,14 @@ void NetworkStateInformer::NetworkManagerChanged() { } } -void NetworkStateInformer::DefaultNetworkChanged(const NetworkState* network) { - NetworkManagerChanged(); -} - void NetworkStateInformer::OnPortalDetectionCompleted( - const NetworkState* network, + const Network* network, const NetworkPortalDetector::CaptivePortalState& state) { - if (NetworkStateHandler::IsInitialized() && - NetworkStateHandler::Get()->DefaultNetwork() == network) - NetworkManagerChanged(); + if (CrosLibrary::Get() && network) { + NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); + if (network_library && network_library->active_network() == network) + OnNetworkManagerChanged(network_library); + } } void NetworkStateInformer::Observe( @@ -129,15 +127,14 @@ void NetworkStateInformer::OnPortalDetected() { SendStateToObservers(ErrorScreenActor::ERROR_REASON_PORTAL_DETECTED); } -bool NetworkStateInformer::UpdateState() { +bool NetworkStateInformer::UpdateState(NetworkLibrary* cros) { State new_state = OFFLINE; - const NetworkState* default_network = - NetworkStateHandler::Get()->DefaultNetwork(); - if (default_network) { - new_state = GetNetworkState(default_network); - last_network_service_path_ = default_network->path(); - last_network_type_ = default_network->type(); + const Network* active_network = cros->active_network(); + if (active_network) { + new_state = GetNetworkState(active_network); + last_network_service_path_ = active_network->service_path(); + last_network_type_ = active_network->type(); } bool updated = (new_state != state_) || @@ -157,7 +154,7 @@ void NetworkStateInformer::UpdateStateAndNotify() { // Cancel pending update request if any. check_state_.Cancel(); - if (UpdateState()) + if (UpdateState(CrosLibrary::Get()->GetNetworkLibrary())) SendStateToObservers(ErrorScreenActor::ERROR_REASON_NETWORK_STATE_CHANGED); else SendStateToObservers(ErrorScreenActor::ERROR_REASON_UPDATE); @@ -170,7 +167,7 @@ void NetworkStateInformer::SendStateToObservers( } NetworkStateInformer::State NetworkStateInformer::GetNetworkState( - const NetworkState* network) { + const Network* network) { DCHECK(network); if (NetworkPortalDetector::IsEnabledInCommandLine() && NetworkPortalDetector::GetInstance()) { @@ -178,15 +175,14 @@ NetworkStateInformer::State NetworkStateInformer::GetNetworkState( NetworkPortalDetector::GetInstance()->GetCaptivePortalState(network); NetworkPortalDetector::CaptivePortalStatus status = state.status; if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN && - NetworkState::StateIsConnecting(network->connection_state())) { + network->connecting()) { return CONNECTING; } // For proxy-less networks rely on shill's online state if // NetworkPortalDetector's state of current network is unknown. if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE || (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN && - !IsProxyConfigured(network) && - network->connection_state() == flimflam::kStateOnline)) { + !IsProxyConfigured(network) && network->online())) { return ONLINE; } if (status == @@ -196,33 +192,31 @@ NetworkStateInformer::State NetworkStateInformer::GetNetworkState( } if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL || (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN && - network->connection_state() == flimflam::kStatePortal)) + network->restricted_pool())) return CAPTIVE_PORTAL; } else { - if (NetworkState::StateIsConnecting(network->connection_state())) + if (network->connecting()) return CONNECTING; - if (network->connection_state() == flimflam::kStateOnline) + if (network->online()) return ONLINE; - if (network->connection_state() == flimflam::kStatePortal) + if (network->restricted_pool()) return CAPTIVE_PORTAL; } return OFFLINE; } -bool NetworkStateInformer::IsProxyConfigured(const NetworkState* network) { +bool NetworkStateInformer::IsProxyConfigured(const Network* network) { DCHECK(network); - - ProxyStateMap::iterator it = proxy_state_map_.find(network->guid()); + ProxyStateMap::iterator it = proxy_state_map_.find(network->unique_id()); if (it != proxy_state_map_.end() && it->second.proxy_config == network->proxy_config()) { return it->second.configured; } net::ProxyConfig proxy_config; - if (!ProxyConfigServiceImpl::ParseProxyConfig(network->proxy_config(), - &proxy_config)) + if (!ProxyConfigServiceImpl::ParseProxyConfig(network, &proxy_config)) return false; bool configured = !proxy_config.proxy_rules().empty(); - proxy_state_map_[network->guid()] = + proxy_state_map_[network->unique_id()] = ProxyState(network->proxy_config(), configured); return configured; } diff --git a/chrome/browser/ui/webui/chromeos/login/network_state_informer.h b/chrome/browser/ui/webui/chromeos/login/network_state_informer.h index 180cb3b..0296b4e 100644 --- a/chrome/browser/ui/webui/chromeos/login/network_state_informer.h +++ b/chrome/browser/ui/webui/chromeos/login/network_state_informer.h @@ -9,21 +9,18 @@ #include <string> #include "base/cancelable_callback.h" -#include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "base/observer_list.h" +#include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/login/captive_portal_window_proxy.h" #include "chrome/browser/chromeos/login/screens/error_screen_actor.h" #include "chrome/browser/chromeos/net/network_portal_detector.h" -#include "chromeos/network/network_state_handler_observer.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_service.h" namespace chromeos { -class NetworkState; - class NetworkStateInformerDelegate { public: NetworkStateInformerDelegate() {} @@ -37,7 +34,7 @@ class NetworkStateInformerDelegate { // State is considered changed if connection or the active network has been // changed. Also, it answers to the requests about current network state. class NetworkStateInformer - : public chromeos::NetworkStateHandlerObserver, + : public chromeos::NetworkLibrary::NetworkManagerObserver, public chromeos::NetworkPortalDetector::Observer, public content::NotificationObserver, public CaptivePortalWindowProxyDelegate, @@ -73,13 +70,12 @@ class NetworkStateInformer // Removes observer. void RemoveObserver(NetworkStateInformerObserver* observer); - // NetworkStateHandlerObserver implementation: - virtual void NetworkManagerChanged() OVERRIDE; - virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE; + // NetworkLibrary::NetworkManagerObserver implementation: + virtual void OnNetworkManagerChanged(chromeos::NetworkLibrary* cros) OVERRIDE; // NetworkPortalDetector::Observer implementation: virtual void OnPortalDetectionCompleted( - const NetworkState* network, + const Network* network, const NetworkPortalDetector::CaptivePortalState& state) OVERRIDE; // content::NotificationObserver implementation. @@ -101,7 +97,7 @@ class NetworkStateInformer std::string last_network_service_path() const { return last_network_service_path_; } - std::string last_network_type() const { return last_network_type_; } + ConnectionType last_network_type() const { return last_network_type_; } private: struct ProxyState { @@ -123,14 +119,14 @@ class NetworkStateInformer virtual ~NetworkStateInformer(); - bool UpdateState(); + bool UpdateState(chromeos::NetworkLibrary* cros); void UpdateStateAndNotify(); void SendStateToObservers(ErrorScreenActor::ErrorReason reason); - State GetNetworkState(const NetworkState* network); - bool IsProxyConfigured(const NetworkState* network); + State GetNetworkState(const Network* network); + bool IsProxyConfigured(const Network* network); content::NotificationRegistrar registrar_; State state_; @@ -139,7 +135,7 @@ class NetworkStateInformer std::string last_online_service_path_; std::string last_connected_service_path_; std::string last_network_service_path_; - std::string last_network_type_; + ConnectionType last_network_type_; base::CancelableClosure check_state_; // Caches proxy state for active networks. diff --git a/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc b/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc index ff36192..41d24c5 100644 --- a/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc +++ b/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc @@ -17,6 +17,8 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process_platform_part_chromeos.h" #include "chrome/browser/browser_shutdown.h" +#include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" #include "chrome/browser/chromeos/login/hwid_checker.h" #include "chrome/browser/chromeos/login/login_display_host_impl.h" @@ -43,8 +45,6 @@ #include "chromeos/dbus/power_manager_client.h" #include "chromeos/ime/input_method_manager.h" #include "chromeos/ime/xkeyboard.h" -#include "chromeos/network/network_state.h" -#include "chromeos/network/network_state_handler.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" #include "google_apis/gaia/gaia_auth_util.h" @@ -52,7 +52,6 @@ #include "google_apis/gaia/gaia_urls.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" -#include "third_party/cros_system_api/dbus/service_constants.h" #include "ui/base/l10n/l10n_util.h" #if defined(USE_AURA) @@ -222,10 +221,21 @@ bool IsSigninScreenError(ErrorScreen::ErrorState error_state) { error_state == ErrorScreen::ERROR_STATE_AUTH_EXT_TIMEOUT; } +// Returns a pointer to a Network instance by service path or NULL if +// network can not be found. +Network* FindNetworkByPath(const std::string& service_path) { + CrosLibrary* cros = CrosLibrary::Get(); + if (!cros) + return NULL; + NetworkLibrary* network_library = cros->GetNetworkLibrary(); + if (!network_library) + return NULL; + return network_library->FindNetworkByPath(service_path); +} + // Returns network name by service path. std::string GetNetworkName(const std::string& service_path) { - const NetworkState* network = - NetworkStateHandler::Get()->GetNetworkState(service_path); + Network* network = FindNetworkByPath(service_path); if (!network) return std::string(); return network->name(); @@ -233,33 +243,31 @@ std::string GetNetworkName(const std::string& service_path) { // Returns network unique id by service path. std::string GetNetworkUniqueId(const std::string& service_path) { - const NetworkState* network = - NetworkStateHandler::Get()->GetNetworkState(service_path); + Network* network = FindNetworkByPath(service_path); if (!network) return std::string(); - return network->guid(); + return network->unique_id(); } // Returns captive portal state for a network by its service path. NetworkPortalDetector::CaptivePortalState GetCaptivePortalState( const std::string& service_path) { NetworkPortalDetector* detector = NetworkPortalDetector::GetInstance(); - const NetworkState* network = - NetworkStateHandler::Get()->GetNetworkState(service_path); + Network* network = FindNetworkByPath(service_path); if (!detector || !network) return NetworkPortalDetector::CaptivePortalState(); return detector->GetCaptivePortalState(network); } void RecordDiscrepancyWithShill( - const NetworkState* network, + const Network* network, const NetworkPortalDetector::CaptivePortalStatus status) { - if (network->connection_state() == flimflam::kStateOnline) { + if (network->online()) { UMA_HISTOGRAM_ENUMERATION( "CaptivePortal.OOBE.DiscrepancyWithShill_Online", status, NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT); - } else if (network->connection_state() == flimflam::kStatePortal) { + } else if (network->restricted_pool()) { UMA_HISTOGRAM_ENUMERATION( "CaptivePortal.OOBE.DiscrepancyWithShill_RestrictedPool", status, @@ -276,8 +284,7 @@ void RecordDiscrepancyWithShill( // network is online but NetworkPortalDetector claims that it's behind // portal) for the network identified by |service_path|. void RecordNetworkPortalDetectorStats(const std::string& service_path) { - const NetworkState* network = - NetworkStateHandler::Get()->GetNetworkState(service_path); + const Network* network = FindNetworkByPath(service_path); if (!network) return; NetworkPortalDetector::CaptivePortalState state = @@ -294,20 +301,19 @@ void RecordNetworkPortalDetectorStats(const std::string& service_path) { NOTREACHED(); break; case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE: - if (network->connection_state() == flimflam::kStateOnline || - network->connection_state() == flimflam::kStatePortal) + if (network->online() || network->restricted_pool()) RecordDiscrepancyWithShill(network, state.status); break; case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE: - if (network->connection_state() != flimflam::kStateOnline) + if (!network->online()) RecordDiscrepancyWithShill(network, state.status); break; case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL: - if (network->connection_state() != flimflam::kStatePortal) + if (!network->restricted_pool()) RecordDiscrepancyWithShill(network, state.status); break; case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED: - if (network->connection_state() != flimflam::kStateOnline) + if (!network->online()) RecordDiscrepancyWithShill(network, state.status); break; case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT: @@ -696,9 +702,9 @@ void SigninScreenHandler::SetupAndShowOfflineMessage( if (GetCurrentScreen() != OobeUI::SCREEN_ERROR_MESSAGE) { DictionaryValue params; - const std::string connection_type = + const ConnectionType connection_type = network_state_informer_->last_network_type(); - params.SetString("lastNetworkType", connection_type); + params.SetInteger("lastNetworkType", static_cast<int>(connection_type)); error_screen_actor_->SetUIState(ErrorScreen::UI_STATE_SIGNIN); error_screen_actor_->Show(OobeUI::SCREEN_GAIA_SIGNIN, ¶ms); } diff --git a/chromeos/dbus/shill_service_client_stub.cc b/chromeos/dbus/shill_service_client_stub.cc index d4e131d..af4245c 100644 --- a/chromeos/dbus/shill_service_client_stub.cc +++ b/chromeos/dbus/shill_service_client_stub.cc @@ -106,13 +106,10 @@ void ShillServiceClientStub::SetProperty(const dbus::ObjectPath& service_path, return; } if (name == flimflam::kStateProperty) { - // If the service went into a connected state, then move it to the top of - // the list in the manager client. - // TODO(gauravsh): Generalize to sort services properly to allow for testing - // more complex scenarios. + // If we connect to a service, then we move it to the top of the list in + // the manager client. std::string state; - if (value.GetAsString(&state) && (state == flimflam::kStateOnline || - state == flimflam::kStatePortal)) { + if (value.GetAsString(&state) && state == flimflam::kStateOnline) { ShillManagerClient* manager_client = DBusThreadManager::Get()->GetShillManagerClient(); manager_client->GetTestInterface()->MoveServiceToIndex( diff --git a/chromeos/network/network_state.cc b/chromeos/network/network_state.cc index bb2735d..84ff8f3 100644 --- a/chromeos/network/network_state.cc +++ b/chromeos/network/network_state.cc @@ -109,8 +109,6 @@ bool NetworkState::PropertyChanged(const std::string& key, return GetStringValue(key, value, &guid_); } else if (key == flimflam::kProfileProperty) { return GetStringValue(key, value, &profile_path_); - } else if (key == flimflam::kProxyConfigProperty) { - return GetStringValue(key, value, &proxy_config_); } else if (key == shill::kActivateOverNonCellularNetworkProperty) { return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); } else if (key == shill::kOutOfCreditsProperty) { @@ -175,8 +173,6 @@ void NetworkState::GetProperties(base::DictionaryValue* dictionary) const { dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, profile_path_); - dictionary->SetStringWithoutPathExpansion(flimflam::kProxyConfigProperty, - proxy_config_); dictionary->SetBooleanWithoutPathExpansion( shill::kActivateOverNonCellularNetworkProperty, activate_over_non_cellular_networks_); diff --git a/chromeos/network/network_state.h b/chromeos/network/network_state.h index 5ce82fb..b8b867e 100644 --- a/chromeos/network/network_state.h +++ b/chromeos/network/network_state.h @@ -45,7 +45,6 @@ class CHROMEOS_EXPORT NetworkState : public ManagedState { const std::string& guid() const { return guid_; } const std::string& connection_state() const { return connection_state_; } const std::string& profile_path() const { return profile_path_; } - const std::string& proxy_config() const { return proxy_config_; } const std::string& error() const { return error_; } bool auto_connect() const { return auto_connect_; } bool favorite() const { return favorite_; } @@ -99,7 +98,6 @@ class CHROMEOS_EXPORT NetworkState : public ManagedState { std::string guid_; std::string connection_state_; std::string profile_path_; - std::string proxy_config_; std::string error_; bool auto_connect_; bool favorite_; |