Chromium Code Reviews| 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/net/network_portal_detector.h" | 5 #include "chrome/browser/chromeos/net/network_portal_detector.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/metrics/histogram.h" | |
| 11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/chromeos/cros/cros_library.h" | 13 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 13 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
| 14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 15 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 16 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 17 #include "net/http/http_status_code.h" | 18 #include "net/http/http_status_code.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 19 | 20 |
| 20 using captive_portal::CaptivePortalDetector; | 21 using captive_portal::CaptivePortalDetector; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 48 IDS_CHROMEOS_CAPTIVE_PORTAL_STATUS_OFFLINE); | 49 IDS_CHROMEOS_CAPTIVE_PORTAL_STATUS_OFFLINE); |
| 49 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE: | 50 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE: |
| 50 return l10n_util::GetStringUTF8( | 51 return l10n_util::GetStringUTF8( |
| 51 IDS_CHROMEOS_CAPTIVE_PORTAL_STATUS_ONLINE); | 52 IDS_CHROMEOS_CAPTIVE_PORTAL_STATUS_ONLINE); |
| 52 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL: | 53 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL: |
| 53 return l10n_util::GetStringUTF8( | 54 return l10n_util::GetStringUTF8( |
| 54 IDS_CHROMEOS_CAPTIVE_PORTAL_STATUS_PORTAL); | 55 IDS_CHROMEOS_CAPTIVE_PORTAL_STATUS_PORTAL); |
| 55 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED: | 56 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED: |
| 56 return l10n_util::GetStringUTF8( | 57 return l10n_util::GetStringUTF8( |
| 57 IDS_CHROMEOS_CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED); | 58 IDS_CHROMEOS_CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED); |
| 59 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT: | |
| 60 NOTREACHED(); | |
| 58 } | 61 } |
| 59 return l10n_util::GetStringUTF8( | 62 return l10n_util::GetStringUTF8( |
| 60 IDS_CHROMEOS_CAPTIVE_PORTAL_STATUS_UNRECOGNIZED); | 63 IDS_CHROMEOS_CAPTIVE_PORTAL_STATUS_UNRECOGNIZED); |
| 61 } | 64 } |
| 62 | 65 |
| 63 NetworkPortalDetector* g_network_portal_detector = NULL; | 66 NetworkPortalDetector* g_network_portal_detector = NULL; |
| 64 | 67 |
| 65 } // namespace | 68 } // namespace |
| 66 | 69 |
| 67 NetworkPortalDetector::NetworkPortalDetector( | 70 NetworkPortalDetector::NetworkPortalDetector( |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 next_attempt_delay_ = delay; | 235 next_attempt_delay_ = delay; |
| 233 if (attempt_count_ > 0) { | 236 if (attempt_count_ > 0) { |
| 234 base::TimeTicks now = GetCurrentTimeTicks(); | 237 base::TimeTicks now = GetCurrentTimeTicks(); |
| 235 base::TimeDelta elapsed_time; | 238 base::TimeDelta elapsed_time; |
| 236 if (now > attempt_start_time_) | 239 if (now > attempt_start_time_) |
| 237 elapsed_time = now - attempt_start_time_; | 240 elapsed_time = now - attempt_start_time_; |
| 238 if (elapsed_time < min_time_between_attempts_ && | 241 if (elapsed_time < min_time_between_attempts_ && |
| 239 min_time_between_attempts_ - elapsed_time > next_attempt_delay_) { | 242 min_time_between_attempts_ - elapsed_time > next_attempt_delay_) { |
| 240 next_attempt_delay_ = min_time_between_attempts_ - elapsed_time; | 243 next_attempt_delay_ = min_time_between_attempts_ - elapsed_time; |
| 241 } | 244 } |
| 245 } else { | |
| 246 detection_start_time_ = GetCurrentTimeTicks(); | |
| 242 } | 247 } |
| 243 detection_task_.Reset( | 248 detection_task_.Reset( |
| 244 base::Bind(&NetworkPortalDetector::DetectCaptivePortalTask, | 249 base::Bind(&NetworkPortalDetector::DetectCaptivePortalTask, |
| 245 weak_ptr_factory_.GetWeakPtr())); | 250 weak_ptr_factory_.GetWeakPtr())); |
| 246 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 251 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 247 detection_task_.callback(), | 252 detection_task_.callback(), |
| 248 next_attempt_delay_); | 253 next_attempt_delay_); |
| 249 } | 254 } |
| 250 | 255 |
| 251 void NetworkPortalDetector::DetectCaptivePortalTask() { | 256 void NetworkPortalDetector::DetectCaptivePortalTask() { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 | 364 |
| 360 bool NetworkPortalDetector::IsCheckingForPortal() const { | 365 bool NetworkPortalDetector::IsCheckingForPortal() const { |
| 361 return state_ == STATE_CHECKING_FOR_PORTAL; | 366 return state_ == STATE_CHECKING_FOR_PORTAL; |
| 362 } | 367 } |
| 363 | 368 |
| 364 void NetworkPortalDetector::SetCaptivePortalState( | 369 void NetworkPortalDetector::SetCaptivePortalState( |
| 365 const Network* network, | 370 const Network* network, |
| 366 const CaptivePortalState& state) { | 371 const CaptivePortalState& state) { |
| 367 DCHECK(network); | 372 DCHECK(network); |
| 368 | 373 |
| 374 if (!detection_start_time_.is_null()) { | |
| 375 UMA_HISTOGRAM_LONG_TIMES("CaptivePortal.OOBE.DetectionDuration", | |
|
Nikita (slow)
2013/02/11 16:26:41
Comment says: Use this macro when times can routin
ygorshenin1
2013/02/12 14:20:06
Done.
| |
| 376 GetCurrentTimeTicks() - detection_start_time_); | |
| 377 } | |
| 378 | |
| 369 CaptivePortalStateMap::const_iterator it = | 379 CaptivePortalStateMap::const_iterator it = |
| 370 portal_state_map_.find(network->service_path()); | 380 portal_state_map_.find(network->service_path()); |
| 371 if (it == portal_state_map_.end() || | 381 if (it == portal_state_map_.end() || |
| 372 it->second.status != state.status || | 382 it->second.status != state.status || |
| 373 it->second.response_code != state.response_code) { | 383 it->second.response_code != state.response_code) { |
| 374 VLOG(1) << "Updating Chrome Captive Portal state: " | 384 VLOG(1) << "Updating Chrome Captive Portal state: " |
| 375 << "network=" << network->unique_id() << ", " | 385 << "network=" << network->unique_id() << ", " |
| 376 << "status=" << CaptivePortalStatusString(state.status) << ", " | 386 << "status=" << CaptivePortalStatusString(state.status) << ", " |
| 377 << "response_code=" << state.response_code; | 387 << "response_code=" << state.response_code; |
| 378 portal_state_map_[network->service_path()] = state; | 388 portal_state_map_[network->service_path()] = state; |
| 379 NotifyPortalStateChanged(network, state); | 389 NotifyPortalStateChanged(network, state); |
| 380 } | 390 } |
| 381 } | 391 } |
| 382 | 392 |
| 383 void NetworkPortalDetector::NotifyPortalStateChanged( | 393 void NetworkPortalDetector::NotifyPortalStateChanged( |
| 384 const Network* network, | 394 const Network* network, |
| 385 const CaptivePortalState& state) { | 395 const CaptivePortalState& state) { |
| 386 FOR_EACH_OBSERVER(Observer, observers_, OnPortalStateChanged(network, state)); | 396 FOR_EACH_OBSERVER(Observer, observers_, OnPortalStateChanged(network, state)); |
| 387 } | 397 } |
| 388 | 398 |
| 389 base::TimeTicks NetworkPortalDetector::GetCurrentTimeTicks() const { | 399 base::TimeTicks NetworkPortalDetector::GetCurrentTimeTicks() const { |
| 390 if (time_ticks_for_testing_.is_null()) | 400 if (time_ticks_for_testing_.is_null()) |
| 391 return base::TimeTicks::Now(); | 401 return base::TimeTicks::Now(); |
| 392 else | 402 else |
| 393 return time_ticks_for_testing_; | 403 return time_ticks_for_testing_; |
| 394 } | 404 } |
| 395 | 405 |
| 396 } // namespace chromeos | 406 } // namespace chromeos |
| OLD | NEW |