| 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/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 "base/metrics/histogram.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/chrome_switches.h" | |
| 17 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 18 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 19 #include "net/base/load_flags.h" | 18 #include "net/base/load_flags.h" |
| 20 #include "net/http/http_response_headers.h" | 19 #include "net/http/http_response_headers.h" |
| 21 #include "net/url_request/url_fetcher.h" | 20 #include "net/url_request/url_fetcher.h" |
| 22 #include "net/url_request/url_request_status.h" | 21 #include "net/url_request/url_request_status.h" |
| 23 | 22 |
| 24 namespace captive_portal { | 23 namespace captive_portal { |
| 25 | 24 |
| 26 namespace { | 25 namespace { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 CaptivePortalResultToString(result), | 87 CaptivePortalResultToString(result), |
| 89 base::TimeDelta::FromSeconds(1), // min | 88 base::TimeDelta::FromSeconds(1), // min |
| 90 base::TimeDelta::FromHours(1), // max | 89 base::TimeDelta::FromHours(1), // max |
| 91 50, // bucket_count | 90 50, // bucket_count |
| 92 base::Histogram::kUmaTargetedHistogramFlag); | 91 base::Histogram::kUmaTargetedHistogramFlag); |
| 93 result_duration_histogram->AddTime(result_duration); | 92 result_duration_histogram->AddTime(result_duration); |
| 94 } | 93 } |
| 95 | 94 |
| 96 } // namespace | 95 } // namespace |
| 97 | 96 |
| 97 bool CaptivePortalService::is_disabled_for_tests_ = false; |
| 98 |
| 98 class CaptivePortalService::RecheckBackoffEntry : public net::BackoffEntry { | 99 class CaptivePortalService::RecheckBackoffEntry : public net::BackoffEntry { |
| 99 public: | 100 public: |
| 100 explicit RecheckBackoffEntry(CaptivePortalService* captive_portal_service) | 101 explicit RecheckBackoffEntry(CaptivePortalService* captive_portal_service) |
| 101 : net::BackoffEntry( | 102 : net::BackoffEntry( |
| 102 &captive_portal_service->recheck_policy().backoff_policy), | 103 &captive_portal_service->recheck_policy().backoff_policy), |
| 103 captive_portal_service_(captive_portal_service) { | 104 captive_portal_service_(captive_portal_service) { |
| 104 } | 105 } |
| 105 | 106 |
| 106 private: | 107 private: |
| 107 virtual base::TimeTicks ImplGetTimeNow() const OVERRIDE { | 108 virtual base::TimeTicks ImplGetTimeNow() const OVERRIDE { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 } else { | 320 } else { |
| 320 recheck_policy_.backoff_policy.initial_delay_ms = | 321 recheck_policy_.backoff_policy.initial_delay_ms = |
| 321 recheck_policy_.initial_backoff_no_portal_ms; | 322 recheck_policy_.initial_backoff_no_portal_ms; |
| 322 } | 323 } |
| 323 | 324 |
| 324 backoff_entry_.reset(new RecheckBackoffEntry(this)); | 325 backoff_entry_.reset(new RecheckBackoffEntry(this)); |
| 325 } | 326 } |
| 326 | 327 |
| 327 void CaptivePortalService::UpdateEnabledState() { | 328 void CaptivePortalService::UpdateEnabledState() { |
| 328 bool enabled_before = enabled_; | 329 bool enabled_before = enabled_; |
| 329 enabled_ = resolve_errors_with_web_service_.GetValue() && | 330 enabled_ = !is_disabled_for_tests_ && |
| 330 CommandLine::ForCurrentProcess()->HasSwitch( | 331 resolve_errors_with_web_service_.GetValue(); |
| 331 switches::kCaptivePortalDetection); | |
| 332 if (enabled_before == enabled_) | 332 if (enabled_before == enabled_) |
| 333 return; | 333 return; |
| 334 | 334 |
| 335 // Clear data used for histograms. | 335 // Clear data used for histograms. |
| 336 num_checks_with_same_result_ = 0; | 336 num_checks_with_same_result_ = 0; |
| 337 first_check_time_with_same_result_ = base::TimeTicks(); | 337 first_check_time_with_same_result_ = base::TimeTicks(); |
| 338 last_check_time_ = base::TimeTicks(); | 338 last_check_time_ = base::TimeTicks(); |
| 339 | 339 |
| 340 ResetBackoffEntry(last_detection_result_); | 340 ResetBackoffEntry(last_detection_result_); |
| 341 | 341 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 | 414 |
| 415 bool CaptivePortalService::FetchingURL() const { | 415 bool CaptivePortalService::FetchingURL() const { |
| 416 return url_fetcher_.get() != NULL; | 416 return url_fetcher_.get() != NULL; |
| 417 } | 417 } |
| 418 | 418 |
| 419 bool CaptivePortalService::TimerRunning() const { | 419 bool CaptivePortalService::TimerRunning() const { |
| 420 return check_captive_portal_timer_.IsRunning(); | 420 return check_captive_portal_timer_.IsRunning(); |
| 421 } | 421 } |
| 422 | 422 |
| 423 } // namespace captive_portal | 423 } // namespace captive_portal |
| OLD | NEW |