| 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.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
| 15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 17 | 17 |
| 18 #if defined(OS_MACOSX) | 18 #if defined(OS_MACOSX) |
| 19 #include "base/mac/mac_util.h" | 19 #include "base/mac/mac_util.h" |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
| 23 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 namespace captive_portal { | 26 namespace captive_portal { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // Used for histograms. | |
| 31 const char* const kCaptivePortalResultNames[] = { | |
| 32 "InternetConnected", | |
| 33 "NoResponse", | |
| 34 "BehindCaptivePortal", | |
| 35 "NumCaptivePortalResults", | |
| 36 }; | |
| 37 COMPILE_ASSERT(arraysize(kCaptivePortalResultNames) == RESULT_COUNT + 1, | |
| 38 captive_portal_result_name_count_mismatch); | |
| 39 | |
| 40 // Used for histograms. | |
| 41 std::string CaptivePortalResultToString(Result result) { | |
| 42 DCHECK_GE(result, 0); | |
| 43 DCHECK_LT(static_cast<unsigned int>(result), | |
| 44 arraysize(kCaptivePortalResultNames)); | |
| 45 return kCaptivePortalResultNames[result]; | |
| 46 } | |
| 47 | |
| 48 // Records histograms relating to how often captive portal detection attempts | 30 // Records histograms relating to how often captive portal detection attempts |
| 49 // ended with |result| in a row, and for how long |result| was the last result | 31 // ended with |result| in a row, and for how long |result| was the last result |
| 50 // of a detection attempt. Recorded both on quit and on a new Result. | 32 // of a detection attempt. Recorded both on quit and on a new Result. |
| 51 // | 33 // |
| 52 // |repeat_count| may be 0 if there were no captive portal checks during | 34 // |repeat_count| may be 0 if there were no captive portal checks during |
| 53 // a session. | 35 // a session. |
| 54 // | 36 // |
| 55 // |result_duration| is the time between when a captive portal check first | 37 // |result_duration| is the time between when a captive portal check first |
| 56 // returned |result| and when a check returned a different result, or when the | 38 // returned |result| and when a check returned a different result, or when the |
| 57 // CaptivePortalService was shut down. | 39 // CaptivePortalService was shut down. |
| 58 void RecordRepeatHistograms(Result result, | 40 void RecordRepeatHistograms(Result result, |
| 59 int repeat_count, | 41 int repeat_count, |
| 60 base::TimeDelta result_duration) { | 42 base::TimeDelta result_duration) { |
| 61 // Histogram macros can't be used with variable names, since they cache | 43 // Histogram macros can't be used with variable names, since they cache |
| 62 // pointers, so have to use the histogram functions directly. | 44 // pointers, so have to use the histogram functions directly. |
| 63 | 45 |
| 64 // Record number of times the last result was received in a row. | 46 // Record number of times the last result was received in a row. |
| 65 base::Histogram* result_repeated_histogram = | 47 base::Histogram* result_repeated_histogram = |
| 66 base::Histogram::FactoryGet( | 48 base::Histogram::FactoryGet( |
| 67 "CaptivePortal.ResultRepeated." + | 49 "CaptivePortal.ResultRepeated." + |
| 68 CaptivePortalResultToString(result), | 50 CaptivePortalDetector::CaptivePortalResultToString(result), |
| 69 1, // min | 51 1, // min |
| 70 100, // max | 52 100, // max |
| 71 100, // bucket_count | 53 100, // bucket_count |
| 72 base::Histogram::kUmaTargetedHistogramFlag); | 54 base::Histogram::kUmaTargetedHistogramFlag); |
| 73 result_repeated_histogram->Add(repeat_count); | 55 result_repeated_histogram->Add(repeat_count); |
| 74 | 56 |
| 75 if (repeat_count == 0) | 57 if (repeat_count == 0) |
| 76 return; | 58 return; |
| 77 | 59 |
| 78 // Time between first request that returned |result| and now. | 60 // Time between first request that returned |result| and now. |
| 79 base::Histogram* result_duration_histogram = | 61 base::Histogram* result_duration_histogram = |
| 80 base::Histogram::FactoryTimeGet( | 62 base::Histogram::FactoryTimeGet( |
| 81 "CaptivePortal.ResultDuration." + | 63 "CaptivePortal.ResultDuration." + |
| 82 CaptivePortalResultToString(result), | 64 CaptivePortalDetector::CaptivePortalResultToString(result), |
| 83 base::TimeDelta::FromSeconds(1), // min | 65 base::TimeDelta::FromSeconds(1), // min |
| 84 base::TimeDelta::FromHours(1), // max | 66 base::TimeDelta::FromHours(1), // max |
| 85 50, // bucket_count | 67 50, // bucket_count |
| 86 base::Histogram::kUmaTargetedHistogramFlag); | 68 base::Histogram::kUmaTargetedHistogramFlag); |
| 87 result_duration_histogram->AddTime(result_duration); | 69 result_duration_histogram->AddTime(result_duration); |
| 88 } | 70 } |
| 89 | 71 |
| 90 bool HasNativeCaptivePortalDetection() { | 72 bool HasNativeCaptivePortalDetection() { |
| 91 // Lion and Windows 8 have their own captive portal detection that will open | 73 // Lion and Windows 8 have their own captive portal detection that will open |
| 92 // a browser window as needed. | 74 // a browser window as needed. |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 | 336 |
| 355 bool CaptivePortalService::DetectionInProgress() const { | 337 bool CaptivePortalService::DetectionInProgress() const { |
| 356 return state_ == STATE_CHECKING_FOR_PORTAL; | 338 return state_ == STATE_CHECKING_FOR_PORTAL; |
| 357 } | 339 } |
| 358 | 340 |
| 359 bool CaptivePortalService::TimerRunning() const { | 341 bool CaptivePortalService::TimerRunning() const { |
| 360 return check_captive_portal_timer_.IsRunning(); | 342 return check_captive_portal_timer_.IsRunning(); |
| 361 } | 343 } |
| 362 | 344 |
| 363 } // namespace captive_portal | 345 } // namespace captive_portal |
| OLD | NEW |