Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1740)

Unified Diff: chrome/browser/chromeos/net/network_portal_detector.h

Issue 11419070: Added detection timeouts and usage of Retry-After HTTP header. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/net/network_portal_detector.h
diff --git a/chrome/browser/chromeos/net/network_portal_detector.h b/chrome/browser/chromeos/net/network_portal_detector.h
index 9915de810f23e5d25cc5215c34abc464c41c1424..0d7475045efaa0c5c0b4584e743370e5ab4e3a75 100644
--- a/chrome/browser/chromeos/net/network_portal_detector.h
+++ b/chrome/browser/chromeos/net/network_portal_detector.h
@@ -7,11 +7,14 @@
#include <string>
+#include "base/cancelable_callback.h"
#include "base/hash_tables.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/threading/non_thread_safe.h"
+#include "base/time.h"
#include "chrome/browser/captive_portal/captive_portal_detector.h"
#include "chrome/browser/chromeos/cros/network_library.h"
#include "googleurl/src/gurl.h"
@@ -77,24 +80,34 @@ class NetworkPortalDetector
enum State {
// No portal check is running.
STATE_IDLE,
+ // Waiting for portal check.
+ STATE_PORTAL_CHECK_PENDING,
// Portal check is in progress.
STATE_CHECKING_FOR_PORTAL,
- // Portal check is in progress, but other portal detection request
- // is pending.
- STATE_CHECKING_FOR_PORTAL_NETWORK_CHANGED,
};
explicit NetworkPortalDetector(
const scoped_refptr<net::URLRequestContextGetter>& request_context);
- // Initiates Captive Portal detection. If currently portal detection
- // in in progress, then delays portal detection.
- void DetectCaptivePortal();
+ // Initiates Captive Portal detection after |delay|.
+ void DetectCaptivePortal(const base::TimeDelta& delay);
+
+ void DetectCaptivePortalTask();
+
+ // Called when portal check is timed out. Cancels portal check and
+ // calls OnPortalDetectionCompleted() with RESULT_NO_RESPONSE as
+ // a result.
+ void PortalDetectionTimeout();
+
+ void CancelPortalDetection();
// Called by CaptivePortalDetector when detection completes.
void OnPortalDetectionCompleted(
const captive_portal::CaptivePortalDetector::Results& results);
+ // Returns true if we're waiting for portal check.
+ bool IsPortalCheckPending() const;
+
// Returns true if portal check is in progress.
bool IsCheckingForPortal() const;
@@ -106,18 +119,77 @@ class NetworkPortalDetector
void NotifyPortalStateChanged(const Network* network,
CaptivePortalState state);
+ // Returns the current TimeTicks.
+ base::TimeTicks GetCurrentTimeTicks() const;
+
State state() { return state_; }
+ // Returns current number of portal detection attempts.
+ // Used by unit tests.
+ int attempt_count_for_testing() { return attempt_count_; }
+
+ // Sets minimum time between consecutive portal checks for the same
+ // network. Used by unit tests.
+ void set_min_time_between_attempts_for_testing(const base::TimeDelta& delta) {
+ min_time_between_attempts_ = delta;
+ }
+
+ // Sets portal detection timeout. Used by unit tests.
+ void set_request_timeout_for_testing(const base::TimeDelta& timeout) {
+ request_timeout_ = timeout;
+ }
+
+ // Returns delay before next portal check. Used by unit tests.
+ const base::TimeDelta& next_attempt_delay_for_testing() {
+ return next_attempt_delay_;
+ }
+
+ // Sets current test time ticks. Used by unit tests.
+ void set_time_ticks_for_testing(const base::TimeTicks& time_ticks) {
+ time_ticks_for_testing_ = time_ticks;
+ }
+
+ // Advances current test time ticks. Used by unit tests.
+ void advance_time_ticks_for_testing(const base::TimeDelta& delta) {
+ time_ticks_for_testing_ += delta;
+ }
+
std::string active_network_id_;
State state_;
CaptivePortalStateMap captive_portal_state_map_;
ObserverList<Observer> observers_;
+ base::CancelableClosure detection_task_;
+ base::CancelableClosure detection_timeout_;
+
// URL that returns a 204 response code when connected to the Internet.
GURL test_url_;
// Detector for checking active network for a portal state.
scoped_ptr<captive_portal::CaptivePortalDetector> captive_portal_detector_;
+
+ base::WeakPtrFactory<NetworkPortalDetector> weak_ptr_factory_;
+
+ // Number of portal detection attemps for an active network.
+ int attempt_count_;
+
+ // Minimum time between consecutive portal checks for the same
+ // active network.
+ base::TimeDelta min_time_between_attempts_;
+
+ // Start time of portal detection attempt.
+ base::TimeTicks attempt_start_time_;
+
+ // Timeout for a portal detection.
+ base::TimeDelta request_timeout_;
+
+ // Delay before next portal detection.
+ base::TimeDelta next_attempt_delay_;
+
+ // Test time ticks used by unit tests.
+ base::TimeTicks time_ticks_for_testing_;
+
+ DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetector);
};
} // namespace chromeos
« no previous file with comments | « chrome/browser/captive_portal/testing_utils.cc ('k') | chrome/browser/chromeos/net/network_portal_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698