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/captive_portal/captive_portal_service.h" | 5 #include "chrome/browser/captive_portal/captive_portal_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 16 #include "components/captive_portal/captive_portal_types.h" | |
| 16 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 17 | 18 |
| 18 #if defined(OS_MACOSX) | 19 #if defined(OS_MACOSX) |
| 19 #include "base/mac/mac_util.h" | 20 #include "base/mac/mac_util.h" |
| 20 #endif | 21 #endif |
| 21 | 22 |
| 22 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 23 #include "base/win/windows_version.h" | 24 #include "base/win/windows_version.h" |
| 24 #endif | 25 #endif |
| 25 | 26 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 46 // Records histograms relating to how often captive portal detection attempts | 47 // Records histograms relating to how often captive portal detection attempts |
| 47 // ended with |result| in a row, and for how long |result| was the last result | 48 // ended with |result| in a row, and for how long |result| was the last result |
| 48 // of a detection attempt. Recorded both on quit and on a new Result. | 49 // of a detection attempt. Recorded both on quit and on a new Result. |
| 49 // | 50 // |
| 50 // |repeat_count| may be 0 if there were no captive portal checks during | 51 // |repeat_count| may be 0 if there were no captive portal checks during |
| 51 // a session. | 52 // a session. |
| 52 // | 53 // |
| 53 // |result_duration| is the time between when a captive portal check first | 54 // |result_duration| is the time between when a captive portal check first |
| 54 // returned |result| and when a check returned a different result, or when the | 55 // returned |result| and when a check returned a different result, or when the |
| 55 // CaptivePortalService was shut down. | 56 // CaptivePortalService was shut down. |
| 56 void RecordRepeatHistograms(Result result, | 57 void RecordRepeatHistograms(CaptivePortalResult result, |
| 57 int repeat_count, | 58 int repeat_count, |
| 58 base::TimeDelta result_duration) { | 59 base::TimeDelta result_duration) { |
| 59 // Histogram macros can't be used with variable names, since they cache | 60 // Histogram macros can't be used with variable names, since they cache |
| 60 // pointers, so have to use the histogram functions directly. | 61 // pointers, so have to use the histogram functions directly. |
| 61 | 62 |
| 62 // Record number of times the last result was received in a row. | 63 // Record number of times the last result was received in a row. |
| 63 base::HistogramBase* result_repeated_histogram = | 64 base::HistogramBase* result_repeated_histogram = |
| 64 base::Histogram::FactoryGet( | 65 base::Histogram::FactoryGet( |
| 65 "CaptivePortal.ResultRepeated." + | 66 "CaptivePortal.ResultRepeated." + |
| 66 CaptivePortalDetector::CaptivePortalResultToString(result), | 67 captive_portal::CaptivePortalResultToString(result), |
|
ygorshenin1
2014/04/21 13:36:45
Why do you need to explicitly specify namespace he
stevenjb
2014/04/21 16:42:27
Done.
| |
| 67 1, // min | 68 1, // min |
| 68 100, // max | 69 100, // max |
| 69 100, // bucket_count | 70 100, // bucket_count |
| 70 base::Histogram::kUmaTargetedHistogramFlag); | 71 base::Histogram::kUmaTargetedHistogramFlag); |
| 71 result_repeated_histogram->Add(repeat_count); | 72 result_repeated_histogram->Add(repeat_count); |
| 72 | 73 |
| 73 if (repeat_count == 0) | 74 if (repeat_count == 0) |
| 74 return; | 75 return; |
| 75 | 76 |
| 76 // Time between first request that returned |result| and now. | 77 // Time between first request that returned |result| and now. |
| 77 base::HistogramBase* result_duration_histogram = | 78 base::HistogramBase* result_duration_histogram = |
| 78 base::Histogram::FactoryTimeGet( | 79 base::Histogram::FactoryTimeGet( |
| 79 "CaptivePortal.ResultDuration." + | 80 "CaptivePortal.ResultDuration." + |
| 80 CaptivePortalDetector::CaptivePortalResultToString(result), | 81 captive_portal::CaptivePortalResultToString(result), |
| 81 base::TimeDelta::FromSeconds(1), // min | 82 base::TimeDelta::FromSeconds(1), // min |
| 82 base::TimeDelta::FromHours(1), // max | 83 base::TimeDelta::FromHours(1), // max |
| 83 50, // bucket_count | 84 50, // bucket_count |
| 84 base::Histogram::kUmaTargetedHistogramFlag); | 85 base::Histogram::kUmaTargetedHistogramFlag); |
| 85 result_duration_histogram->AddTime(result_duration); | 86 result_duration_histogram->AddTime(result_duration); |
| 86 } | 87 } |
| 87 | 88 |
| 88 int GetHistogramEntryForDetectionResult( | 89 int GetHistogramEntryForDetectionResult( |
| 89 const CaptivePortalDetector::Results& results) { | 90 const CaptivePortalDetector::Results& results) { |
| 90 bool is_https = results.landing_url.SchemeIs("https"); | 91 bool is_https = results.landing_url.SchemeIs("https"); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 base::Unretained(this))); | 234 base::Unretained(this))); |
| 234 } | 235 } |
| 235 | 236 |
| 236 void CaptivePortalService::OnPortalDetectionCompleted( | 237 void CaptivePortalService::OnPortalDetectionCompleted( |
| 237 const CaptivePortalDetector::Results& results) { | 238 const CaptivePortalDetector::Results& results) { |
| 238 DCHECK(CalledOnValidThread()); | 239 DCHECK(CalledOnValidThread()); |
| 239 DCHECK_EQ(STATE_CHECKING_FOR_PORTAL, state_); | 240 DCHECK_EQ(STATE_CHECKING_FOR_PORTAL, state_); |
| 240 DCHECK(!TimerRunning()); | 241 DCHECK(!TimerRunning()); |
| 241 DCHECK(enabled_); | 242 DCHECK(enabled_); |
| 242 | 243 |
| 243 Result result = results.result; | 244 CaptivePortalResult result = results.result; |
| 244 const base::TimeDelta& retry_after_delta = results.retry_after_delta; | 245 const base::TimeDelta& retry_after_delta = results.retry_after_delta; |
| 245 base::TimeTicks now = GetCurrentTimeTicks(); | 246 base::TimeTicks now = GetCurrentTimeTicks(); |
| 246 | 247 |
| 247 // Record histograms. | 248 // Record histograms. |
| 248 UMA_HISTOGRAM_ENUMERATION("CaptivePortal.DetectResult", | 249 UMA_HISTOGRAM_ENUMERATION("CaptivePortal.DetectResult", |
| 249 GetHistogramEntryForDetectionResult(results), | 250 GetHistogramEntryForDetectionResult(results), |
| 250 DETECTION_RESULT_COUNT); | 251 DETECTION_RESULT_COUNT); |
| 251 | 252 |
| 252 // If this isn't the first captive portal result, record stats. | 253 // If this isn't the first captive portal result, record stats. |
| 253 if (!last_check_time_.is_null()) { | 254 if (!last_check_time_.is_null()) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 void CaptivePortalService::Shutdown() { | 296 void CaptivePortalService::Shutdown() { |
| 296 DCHECK(CalledOnValidThread()); | 297 DCHECK(CalledOnValidThread()); |
| 297 if (enabled_) { | 298 if (enabled_) { |
| 298 RecordRepeatHistograms( | 299 RecordRepeatHistograms( |
| 299 last_detection_result_, | 300 last_detection_result_, |
| 300 num_checks_with_same_result_, | 301 num_checks_with_same_result_, |
| 301 GetCurrentTimeTicks() - first_check_time_with_same_result_); | 302 GetCurrentTimeTicks() - first_check_time_with_same_result_); |
| 302 } | 303 } |
| 303 } | 304 } |
| 304 | 305 |
| 305 void CaptivePortalService::OnResult(Result result) { | 306 void CaptivePortalService::OnResult(CaptivePortalResult result) { |
| 306 DCHECK_EQ(STATE_CHECKING_FOR_PORTAL, state_); | 307 DCHECK_EQ(STATE_CHECKING_FOR_PORTAL, state_); |
| 307 state_ = STATE_IDLE; | 308 state_ = STATE_IDLE; |
| 308 | 309 |
| 309 Results results; | 310 Results results; |
| 310 results.previous_result = last_detection_result_; | 311 results.previous_result = last_detection_result_; |
| 311 results.result = result; | 312 results.result = result; |
| 312 last_detection_result_ = result; | 313 last_detection_result_ = result; |
| 313 | 314 |
| 314 content::NotificationService::current()->Notify( | 315 content::NotificationService::current()->Notify( |
| 315 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, | 316 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, |
| 316 content::Source<Profile>(profile_), | 317 content::Source<Profile>(profile_), |
| 317 content::Details<Results>(&results)); | 318 content::Details<Results>(&results)); |
| 318 } | 319 } |
| 319 | 320 |
| 320 void CaptivePortalService::ResetBackoffEntry(Result result) { | 321 void CaptivePortalService::ResetBackoffEntry(CaptivePortalResult result) { |
| 321 if (!enabled_ || result == RESULT_BEHIND_CAPTIVE_PORTAL) { | 322 if (!enabled_ || result == RESULT_BEHIND_CAPTIVE_PORTAL) { |
| 322 // Use the shorter time when the captive portal service is not enabled, or | 323 // Use the shorter time when the captive portal service is not enabled, or |
| 323 // behind a captive portal. | 324 // behind a captive portal. |
| 324 recheck_policy_.backoff_policy.initial_delay_ms = | 325 recheck_policy_.backoff_policy.initial_delay_ms = |
| 325 recheck_policy_.initial_backoff_portal_ms; | 326 recheck_policy_.initial_backoff_portal_ms; |
| 326 } else { | 327 } else { |
| 327 recheck_policy_.backoff_policy.initial_delay_ms = | 328 recheck_policy_.backoff_policy.initial_delay_ms = |
| 328 recheck_policy_.initial_backoff_no_portal_ms; | 329 recheck_policy_.initial_backoff_no_portal_ms; |
| 329 } | 330 } |
| 330 | 331 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 | 375 |
| 375 bool CaptivePortalService::DetectionInProgress() const { | 376 bool CaptivePortalService::DetectionInProgress() const { |
| 376 return state_ == STATE_CHECKING_FOR_PORTAL; | 377 return state_ == STATE_CHECKING_FOR_PORTAL; |
| 377 } | 378 } |
| 378 | 379 |
| 379 bool CaptivePortalService::TimerRunning() const { | 380 bool CaptivePortalService::TimerRunning() const { |
| 380 return check_captive_portal_timer_.IsRunning(); | 381 return check_captive_portal_timer_.IsRunning(); |
| 381 } | 382 } |
| 382 | 383 |
| 383 } // namespace captive_portal | 384 } // namespace captive_portal |
| OLD | NEW |