| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/net/network_portal_notification_controller.h" | 5 #include "chrome/browser/chromeos/net/network_portal_notification_controller.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 if (NetworkHandler::IsInitialized()) { | 252 if (NetworkHandler::IsInitialized()) { |
| 253 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, | 253 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, |
| 254 FROM_HERE); | 254 FROM_HERE); |
| 255 } | 255 } |
| 256 } | 256 } |
| 257 | 257 |
| 258 void NetworkPortalNotificationController::DefaultNetworkChanged( | 258 void NetworkPortalNotificationController::DefaultNetworkChanged( |
| 259 const NetworkState* network) { | 259 const NetworkState* network) { |
| 260 if (!network) | 260 if (!network) |
| 261 return; | 261 return; |
| 262 |
| 263 bool network_changed = (default_network_id_ != network->guid()); |
| 264 default_network_id_ = network->guid(); |
| 265 if (!network_changed && network->connection_state() == shill::kStateOnline && |
| 266 dialog_) { |
| 267 dialog_->Close(); |
| 268 } |
| 269 |
| 262 Profile* profile = GetProfileForPrimaryUser(); | 270 Profile* profile = GetProfileForPrimaryUser(); |
| 263 extensions::NetworkingConfigService* networking_config_service = | 271 extensions::NetworkingConfigService* networking_config_service = |
| 264 GetNetworkingConfigService(profile); | 272 GetNetworkingConfigService(profile); |
| 265 if (!networking_config_service) | 273 if (!networking_config_service) |
| 266 return; | 274 return; |
| 267 networking_config_service->ResetAuthenticationResult(); | 275 networking_config_service->ResetAuthenticationResult(); |
| 268 } | 276 } |
| 269 | 277 |
| 270 void NetworkPortalNotificationController::OnPortalDetectionCompleted( | 278 void NetworkPortalNotificationController::OnPortalDetectionCompleted( |
| 271 const NetworkState* network, | 279 const NetworkState* network, |
| 272 const NetworkPortalDetector::CaptivePortalState& state) { | 280 const NetworkPortalDetector::CaptivePortalState& state) { |
| 273 if (!IsPortalNotificationEnabled()) | 281 if (!IsPortalNotificationEnabled()) |
| 274 return; | 282 return; |
| 275 | 283 |
| 276 if (!network || | 284 if (!network || |
| 277 state.status != NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL) { | 285 state.status != NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL) { |
| 278 last_network_guid_.clear(); | 286 last_network_guid_.clear(); |
| 279 | |
| 280 // In browser tests we initiate fake network portal detection, but network | |
| 281 // state usually stays connected. This way, after dialog is shown, it is | |
| 282 // immediately closed. The testing check below prevents dialog from closing. | |
| 283 if (dialog_ && | |
| 284 (!ignore_no_network_for_testing_ || | |
| 285 state.status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE)) { | |
| 286 dialog_->Close(); | |
| 287 } | |
| 288 | |
| 289 CloseNotification(); | 287 CloseNotification(); |
| 290 return; | 288 return; |
| 291 } | 289 } |
| 292 | 290 |
| 293 // Don't do anything if we're currently activating the device. | 291 // Don't do anything if we're currently activating the device. |
| 294 if (MobileActivator::GetInstance()->RunningActivation()) | 292 if (MobileActivator::GetInstance()->RunningActivation()) |
| 295 return; | 293 return; |
| 296 | 294 |
| 297 // Don't do anything if notification for |network| already was | 295 // Don't do anything if notification for |network| already was |
| 298 // displayed. | 296 // displayed. |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 } else { | 423 } else { |
| 426 return CreateDefaultCaptivePortalNotification(network); | 424 return CreateDefaultCaptivePortalNotification(network); |
| 427 } | 425 } |
| 428 } | 426 } |
| 429 | 427 |
| 430 void NetworkPortalNotificationController::OnExtensionFinishedAuthentication() { | 428 void NetworkPortalNotificationController::OnExtensionFinishedAuthentication() { |
| 431 if (!retry_detection_callback_.is_null()) | 429 if (!retry_detection_callback_.is_null()) |
| 432 retry_detection_callback_.Run(); | 430 retry_detection_callback_.Run(); |
| 433 } | 431 } |
| 434 | 432 |
| 435 void NetworkPortalNotificationController::SetIgnoreNoNetworkForTesting() { | |
| 436 ignore_no_network_for_testing_ = true; | |
| 437 } | |
| 438 | |
| 439 void NetworkPortalNotificationController::CloseDialog() { | 433 void NetworkPortalNotificationController::CloseDialog() { |
| 440 if (dialog_) | 434 if (dialog_) |
| 441 dialog_->Close(); | 435 dialog_->Close(); |
| 442 } | 436 } |
| 443 | 437 |
| 444 const NetworkPortalWebDialog* | 438 const NetworkPortalWebDialog* |
| 445 NetworkPortalNotificationController::GetDialogForTesting() const { | 439 NetworkPortalNotificationController::GetDialogForTesting() const { |
| 446 return dialog_; | 440 return dialog_; |
| 447 } | 441 } |
| 448 | 442 |
| 449 } // namespace chromeos | 443 } // namespace chromeos |
| OLD | NEW |