| 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 #ifndef CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_SERVICE_H_ |
| 6 #define CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_SERVICE_H_ | 6 #define CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_SERVICE_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/prefs/public/pref_observer.h" |
| 10 #include "base/threading/non_thread_safe.h" | 11 #include "base/threading/non_thread_safe.h" |
| 11 #include "base/time.h" | 12 #include "base/time.h" |
| 12 #include "base/timer.h" | 13 #include "base/timer.h" |
| 13 #include "chrome/browser/api/prefs/pref_member.h" | 14 #include "chrome/browser/api/prefs/pref_member.h" |
| 14 #include "chrome/browser/captive_portal/captive_portal_detector.h" | 15 #include "chrome/browser/captive_portal/captive_portal_detector.h" |
| 15 #include "chrome/browser/profiles/profile_keyed_service.h" | 16 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 16 #include "content/public/browser/notification_observer.h" | |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 #include "net/base/backoff_entry.h" | 18 #include "net/base/backoff_entry.h" |
| 19 | 19 |
| 20 class Profile; | 20 class Profile; |
| 21 | 21 |
| 22 namespace captive_portal { | 22 namespace captive_portal { |
| 23 | 23 |
| 24 // Service that checks for captive portals when queried, and sends a | 24 // Service that checks for captive portals when queried, and sends a |
| 25 // NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT with the Profile as the source and | 25 // NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT with the Profile as the source and |
| 26 // a CaptivePortalService::Results as the details. | 26 // a CaptivePortalService::Results as the details. |
| 27 // | 27 // |
| 28 // Captive portal checks are rate-limited. The CaptivePortalService may only | 28 // Captive portal checks are rate-limited. The CaptivePortalService may only |
| 29 // be accessed on the UI thread. | 29 // be accessed on the UI thread. |
| 30 // Design doc: https://docs.google.com/document/d/1k-gP2sswzYNvryu9NcgN7q5XrsMlU
dlUdoW9WRaEmfM/edit | 30 // Design doc: https://docs.google.com/document/d/1k-gP2sswzYNvryu9NcgN7q5XrsMlU
dlUdoW9WRaEmfM/edit |
| 31 class CaptivePortalService : public ProfileKeyedService, | 31 class CaptivePortalService : public ProfileKeyedService, |
| 32 public content::NotificationObserver, | 32 public PrefObserver, |
| 33 public base::NonThreadSafe { | 33 public base::NonThreadSafe { |
| 34 public: | 34 public: |
| 35 enum TestingState { | 35 enum TestingState { |
| 36 NOT_TESTING, | 36 NOT_TESTING, |
| 37 DISABLED_FOR_TESTING, // The service is always disabled. | 37 DISABLED_FOR_TESTING, // The service is always disabled. |
| 38 SKIP_OS_CHECK_FOR_TESTING // The service can be enabled even if the OS has | 38 SKIP_OS_CHECK_FOR_TESTING // The service can be enabled even if the OS has |
| 39 // native captive portal detection. | 39 // native captive portal detection. |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 // The details sent via a NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT. | 42 // The details sent via a NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 // Initiates a captive portal check, without any throttling. If the service | 111 // Initiates a captive portal check, without any throttling. If the service |
| 112 // is disabled, just acts like there's an Internet connection. | 112 // is disabled, just acts like there's an Internet connection. |
| 113 void DetectCaptivePortalInternal(); | 113 void DetectCaptivePortalInternal(); |
| 114 | 114 |
| 115 // Called by CaptivePortalDetector when detection completes. | 115 // Called by CaptivePortalDetector when detection completes. |
| 116 void OnPortalDetectionCompleted( | 116 void OnPortalDetectionCompleted( |
| 117 const CaptivePortalDetector::Results& results); | 117 const CaptivePortalDetector::Results& results); |
| 118 | 118 |
| 119 // content::NotificationObserver: | 119 // PrefObserver |
| 120 virtual void Observe( | 120 virtual void OnPreferenceChanged(PrefServiceBase* service, |
| 121 int type, | 121 const std::string& pref_name) OVERRIDE; |
| 122 const content::NotificationSource& source, | |
| 123 const content::NotificationDetails& details) OVERRIDE; | |
| 124 | 122 |
| 125 // ProfileKeyedService: | 123 // ProfileKeyedService: |
| 126 virtual void Shutdown() OVERRIDE; | 124 virtual void Shutdown() OVERRIDE; |
| 127 | 125 |
| 128 // Called when a captive portal check completes. Passes the result to all | 126 // Called when a captive portal check completes. Passes the result to all |
| 129 // observers. | 127 // observers. |
| 130 void OnResult(Result result); | 128 void OnResult(Result result); |
| 131 | 129 |
| 132 // Updates BackoffEntry::Policy and creates a new BackoffEntry, which | 130 // Updates BackoffEntry::Policy and creates a new BackoffEntry, which |
| 133 // resets the count used for throttling. | 131 // resets the count used for throttling. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 210 |
| 213 // Test time ticks used by unit tests. | 211 // Test time ticks used by unit tests. |
| 214 base::TimeTicks time_ticks_for_testing_; | 212 base::TimeTicks time_ticks_for_testing_; |
| 215 | 213 |
| 216 DISALLOW_COPY_AND_ASSIGN(CaptivePortalService); | 214 DISALLOW_COPY_AND_ASSIGN(CaptivePortalService); |
| 217 }; | 215 }; |
| 218 | 216 |
| 219 } // namespace captive_portal | 217 } // namespace captive_portal |
| 220 | 218 |
| 221 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_SERVICE_H_ | 219 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_SERVICE_H_ |
| OLD | NEW |