| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/login/screens/network_screen.h" | 5 #include "chrome/browser/chromeos/login/screens/network_screen.h" |
| 6 | 6 |
| 7 #include "base/location.h" |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/chromeos/login/help_app_launcher.h" | 11 #include "chrome/browser/chromeos/login/help_app_launcher.h" |
| 11 #include "chrome/browser/chromeos/login/helper.h" | 12 #include "chrome/browser/chromeos/login/helper.h" |
| 12 #include "chrome/browser/chromeos/login/login_utils.h" | 13 #include "chrome/browser/chromeos/login/login_utils.h" |
| 13 #include "chrome/browser/chromeos/login/screens/screen_observer.h" | 14 #include "chrome/browser/chromeos/login/screens/screen_observer.h" |
| 14 #include "chrome/browser/chromeos/login/wizard_controller.h" | 15 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 15 #include "chrome/browser/chromeos/net/connectivity_state_helper.h" | 16 #include "chromeos/network/network_handler.h" |
| 17 #include "chromeos/network/network_state_handler.h" |
| 16 #include "grit/chromium_strings.h" | 18 #include "grit/chromium_strings.h" |
| 17 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 18 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| 21 | 23 |
| 22 namespace { | 24 namespace { |
| 23 | 25 |
| 24 // Time in seconds for connection timeout. | 26 // Time in seconds for connection timeout. |
| 25 const int kConnectionTimeoutSec = 15; | 27 const int kConnectionTimeoutSec = 15; |
| 26 | 28 |
| 27 } // namespace | 29 } // namespace |
| 28 | 30 |
| 29 namespace chromeos { | 31 namespace chromeos { |
| 30 | 32 |
| 31 /////////////////////////////////////////////////////////////////////////////// | 33 /////////////////////////////////////////////////////////////////////////////// |
| 32 // NetworkScreen, public: | 34 // NetworkScreen, public: |
| 33 | 35 |
| 34 NetworkScreen::NetworkScreen(ScreenObserver* screen_observer, | 36 NetworkScreen::NetworkScreen(ScreenObserver* screen_observer, |
| 35 NetworkScreenActor* actor) | 37 NetworkScreenActor* actor) |
| 36 : WizardScreen(screen_observer), | 38 : WizardScreen(screen_observer), |
| 37 is_network_subscribed_(false), | 39 is_network_subscribed_(false), |
| 38 continue_pressed_(false), | 40 continue_pressed_(false), |
| 39 actor_(actor) { | 41 actor_(actor), |
| 42 network_state_helper_(new login::NetworkStateHelper) { |
| 40 DCHECK(actor_); | 43 DCHECK(actor_); |
| 41 if (actor_) | 44 if (actor_) |
| 42 actor_->SetDelegate(this); | 45 actor_->SetDelegate(this); |
| 43 } | 46 } |
| 44 | 47 |
| 45 NetworkScreen::~NetworkScreen() { | 48 NetworkScreen::~NetworkScreen() { |
| 46 if (actor_) | 49 if (actor_) |
| 47 actor_->SetDelegate(NULL); | 50 actor_->SetDelegate(NULL); |
| 48 connection_timer_.Stop(); | 51 connection_timer_.Stop(); |
| 49 UnsubscribeNetworkNotification(); | 52 UnsubscribeNetworkNotification(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 66 void NetworkScreen::Hide() { | 69 void NetworkScreen::Hide() { |
| 67 if (actor_) | 70 if (actor_) |
| 68 actor_->Hide(); | 71 actor_->Hide(); |
| 69 } | 72 } |
| 70 | 73 |
| 71 std::string NetworkScreen::GetName() const { | 74 std::string NetworkScreen::GetName() const { |
| 72 return WizardController::kNetworkScreenName; | 75 return WizardController::kNetworkScreenName; |
| 73 } | 76 } |
| 74 | 77 |
| 75 //////////////////////////////////////////////////////////////////////////////// | 78 //////////////////////////////////////////////////////////////////////////////// |
| 76 // NetworkScreen, ConnectivityStateHelperObserver implementation: | 79 // NetworkScreen, NetworkStateHandlerObserver implementation: |
| 77 | 80 |
| 78 void NetworkScreen::NetworkManagerChanged() { | 81 void NetworkScreen::NetworkManagerChanged() { |
| 79 UpdateStatus(); | 82 UpdateStatus(); |
| 80 } | 83 } |
| 81 | 84 |
| 82 void NetworkScreen::DefaultNetworkChanged() { | 85 void NetworkScreen::DefaultNetworkChanged(const NetworkState* network) { |
| 83 NetworkManagerChanged(); | 86 NetworkManagerChanged(); |
| 84 } | 87 } |
| 85 | 88 |
| 86 //////////////////////////////////////////////////////////////////////////////// | 89 //////////////////////////////////////////////////////////////////////////////// |
| 87 // NetworkScreen, public: | 90 // NetworkScreen, public: |
| 88 | 91 |
| 89 void NetworkScreen::Refresh() { | 92 void NetworkScreen::Refresh() { |
| 90 SubscribeNetworkNotification(); | 93 SubscribeNetworkNotification(); |
| 91 NetworkManagerChanged(); | 94 NetworkManagerChanged(); |
| 92 } | 95 } |
| 93 | 96 |
| 94 /////////////////////////////////////////////////////////////////////////////// | 97 /////////////////////////////////////////////////////////////////////////////// |
| 95 // NetworkScreen, NetworkScreenActor::Delegate implementation: | 98 // NetworkScreen, NetworkScreenActor::Delegate implementation: |
| 96 | 99 |
| 97 void NetworkScreen::OnActorDestroyed(NetworkScreenActor* actor) { | 100 void NetworkScreen::OnActorDestroyed(NetworkScreenActor* actor) { |
| 98 if (actor_ == actor) | 101 if (actor_ == actor) |
| 99 actor_ = NULL; | 102 actor_ = NULL; |
| 100 } | 103 } |
| 101 | 104 |
| 102 void NetworkScreen::OnContinuePressed() { | 105 void NetworkScreen::OnContinuePressed() { |
| 103 if (ConnectivityStateHelper::Get()->IsConnected()) { | 106 if (network_state_helper_->IsConnected()) { |
| 104 NotifyOnConnection(); | 107 NotifyOnConnection(); |
| 105 } else { | 108 } else { |
| 106 continue_pressed_ = true; | 109 continue_pressed_ = true; |
| 107 WaitForConnection(network_id_); | 110 WaitForConnection(network_id_); |
| 108 } | 111 } |
| 109 } | 112 } |
| 110 | 113 |
| 111 //////////////////////////////////////////////////////////////////////////////// | 114 //////////////////////////////////////////////////////////////////////////////// |
| 112 // NetworkScreen, private: | 115 // NetworkScreen, private: |
| 113 | 116 |
| 117 void NetworkScreen::SetNetworkStateHelperForTest( |
| 118 login::NetworkStateHelper* helper) { |
| 119 network_state_helper_.reset(helper); |
| 120 } |
| 121 |
| 114 void NetworkScreen::SubscribeNetworkNotification() { | 122 void NetworkScreen::SubscribeNetworkNotification() { |
| 115 if (!is_network_subscribed_) { | 123 if (!is_network_subscribed_) { |
| 116 is_network_subscribed_ = true; | 124 is_network_subscribed_ = true; |
| 117 ConnectivityStateHelper::Get()->AddNetworkManagerObserver(this); | 125 NetworkHandler::Get()->network_state_handler()->AddObserver( |
| 126 this, FROM_HERE); |
| 118 } | 127 } |
| 119 } | 128 } |
| 120 | 129 |
| 121 void NetworkScreen::UnsubscribeNetworkNotification() { | 130 void NetworkScreen::UnsubscribeNetworkNotification() { |
| 122 if (is_network_subscribed_) { | 131 if (is_network_subscribed_) { |
| 123 is_network_subscribed_ = false; | 132 is_network_subscribed_ = false; |
| 124 ConnectivityStateHelper::Get()->RemoveNetworkManagerObserver(this); | 133 NetworkHandler::Get()->network_state_handler()->RemoveObserver( |
| 134 this, FROM_HERE); |
| 125 } | 135 } |
| 126 } | 136 } |
| 127 | 137 |
| 128 void NetworkScreen::NotifyOnConnection() { | 138 void NetworkScreen::NotifyOnConnection() { |
| 129 // TODO(nkostylev): Check network connectivity. | 139 // TODO(nkostylev): Check network connectivity. |
| 130 UnsubscribeNetworkNotification(); | 140 UnsubscribeNetworkNotification(); |
| 131 connection_timer_.Stop(); | 141 connection_timer_.Stop(); |
| 132 get_screen_observer()->OnExit(ScreenObserver::NETWORK_CONNECTED); | 142 get_screen_observer()->OnExit(ScreenObserver::NETWORK_CONNECTED); |
| 133 } | 143 } |
| 134 | 144 |
| 135 void NetworkScreen::OnConnectionTimeout() { | 145 void NetworkScreen::OnConnectionTimeout() { |
| 136 StopWaitingForConnection(network_id_); | 146 StopWaitingForConnection(network_id_); |
| 137 if (!ConnectivityStateHelper::Get()->IsConnected() && actor_) { | 147 if (!network_state_helper_->IsConnected() && actor_) { |
| 138 // Show error bubble. | 148 // Show error bubble. |
| 139 actor_->ShowError( | 149 actor_->ShowError( |
| 140 l10n_util::GetStringFUTF16( | 150 l10n_util::GetStringFUTF16( |
| 141 IDS_NETWORK_SELECTION_ERROR, | 151 IDS_NETWORK_SELECTION_ERROR, |
| 142 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME), | 152 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME), |
| 143 network_id_)); | 153 network_id_)); |
| 144 } | 154 } |
| 145 } | 155 } |
| 146 | 156 |
| 147 void NetworkScreen::UpdateStatus() { | 157 void NetworkScreen::UpdateStatus() { |
| 148 if (!actor_) | 158 if (!actor_) |
| 149 return; | 159 return; |
| 150 | 160 |
| 151 bool is_connected = ConnectivityStateHelper::Get()->IsConnected(); | 161 bool is_connected = network_state_helper_->IsConnected(); |
| 152 if (is_connected) | 162 if (is_connected) |
| 153 actor_->ClearErrors(); | 163 actor_->ClearErrors(); |
| 154 | 164 |
| 155 string16 network_name = GetCurrentNetworkName(); | 165 string16 network_name = network_state_helper_->GetCurrentNetworkName(); |
| 156 if (is_connected) { | 166 if (is_connected) { |
| 157 StopWaitingForConnection(network_name); | 167 StopWaitingForConnection(network_name); |
| 158 } else if (ConnectivityStateHelper::Get()->IsConnecting()) { | 168 } else if (network_state_helper_->IsConnecting()) { |
| 159 WaitForConnection(network_name); | 169 WaitForConnection(network_name); |
| 160 } else { | 170 } else { |
| 161 StopWaitingForConnection(network_id_); | 171 StopWaitingForConnection(network_id_); |
| 162 } | 172 } |
| 163 } | 173 } |
| 164 | 174 |
| 165 void NetworkScreen::StopWaitingForConnection(const string16& network_id) { | 175 void NetworkScreen::StopWaitingForConnection(const string16& network_id) { |
| 166 bool is_connected = ConnectivityStateHelper::Get()->IsConnected(); | 176 bool is_connected = network_state_helper_->IsConnected(); |
| 167 if (is_connected && continue_pressed_) { | 177 if (is_connected && continue_pressed_) { |
| 168 NotifyOnConnection(); | 178 NotifyOnConnection(); |
| 169 return; | 179 return; |
| 170 } | 180 } |
| 171 | 181 |
| 172 continue_pressed_ = false; | 182 continue_pressed_ = false; |
| 173 connection_timer_.Stop(); | 183 connection_timer_.Stop(); |
| 174 | 184 |
| 175 network_id_ = network_id; | 185 network_id_ = network_id; |
| 176 if (actor_) { | 186 if (actor_) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 189 } | 199 } |
| 190 | 200 |
| 191 network_id_ = network_id; | 201 network_id_ = network_id; |
| 192 if (actor_) { | 202 if (actor_) { |
| 193 actor_->ShowConnectingStatus(continue_pressed_, network_id_); | 203 actor_->ShowConnectingStatus(continue_pressed_, network_id_); |
| 194 actor_->EnableContinue(false); | 204 actor_->EnableContinue(false); |
| 195 } | 205 } |
| 196 } | 206 } |
| 197 | 207 |
| 198 } // namespace chromeos | 208 } // namespace chromeos |
| OLD | NEW |