Index: chrome/browser/chromeos/net/network_portal_detector_strategy.h |
diff --git a/chrome/browser/chromeos/net/network_portal_detector_strategy.h b/chrome/browser/chromeos/net/network_portal_detector_strategy.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2928b3747d1de4a9b2829c223940e1229c607733 |
--- /dev/null |
+++ b/chrome/browser/chromeos/net/network_portal_detector_strategy.h |
@@ -0,0 +1,146 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_STRATEGY_H_ |
+#define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_STRATEGY_H_ |
+ |
+#include "base/compiler_specific.h" |
+#include "base/macros.h" |
+#include "base/time/time.h" |
+ |
+namespace chromeos { |
+ |
+class PortalDetectorStrategy { |
+ public: |
+ class Delegate { |
+ public: |
+ virtual ~Delegate() {} |
+ virtual base::TimeTicks GetCurrentTimeTicks() = 0; |
+ }; |
+ |
+ explicit PortalDetectorStrategy(Delegate* delegate); |
+ virtual ~PortalDetectorStrategy(); |
+ |
+ void Reset(); |
+ bool CanPerformAttempt(); |
+ base::TimeDelta GetDelayBeforeCurrentAttempt(); |
Denis Kuznetsov (DE-MUC)
2014/03/05 16:59:09
GetDelayTillNextAttempt ?
ygorshenin1
2014/03/06 11:59:33
Done.
|
+ base::TimeDelta GetCurrentAttemptTimeout(); |
Denis Kuznetsov (DE-MUC)
2014/03/05 16:59:09
comments for methods?
ygorshenin1
2014/03/06 11:59:33
Done.
|
+ void OnAttemptStarted(); |
+ void OnDetectionCompleted(); |
+ |
+ protected: |
+ base::TimeTicks GetCurrentTimeTicks() { |
+ return delegate_->GetCurrentTimeTicks(); |
+ } |
+ |
+ // Interface for subclasses: |
+ virtual void ResetImpl(); |
+ virtual bool CanPerformAttemptImpl(); |
+ virtual base::TimeDelta GetDelayBeforeCurrentAttemptImpl(); |
+ virtual base::TimeDelta GetCurrentAttemptTimeoutImpl(); |
+ virtual void OnAttemptStartedImpl(); |
+ virtual void OnDetectionCompletedImpl(); |
+ |
+ Delegate* delegate_; |
+ |
+ // Start time of portal detection attempt. |
+ base::TimeTicks attempt_start_time_; |
+ |
+ private: |
+ friend class NetworkPortalDetectorImplTest; |
+ |
+ // Sets portal detection timeout. Used by unit tests. |
+ static void set_request_timeout_for_testing(const base::TimeDelta& timeout) { |
+ request_timeout_for_testing_ = timeout; |
+ request_timeout_for_testing_initialized_ = true; |
+ } |
+ |
+ static void reset_request_timeout_for_testing() { |
+ request_timeout_for_testing_initialized_ = false; |
+ } |
+ |
+ static void set_min_time_between_attempts_for_testing( |
+ const base::TimeDelta& timeout) { |
+ min_time_between_attempts_for_testing_ = timeout; |
+ min_time_between_attempts_for_testing_initialized_ = true; |
+ } |
+ |
+ static void reset_min_time_between_attempts_for_testing() { |
+ min_time_between_attempts_for_testing_initialized_ = false; |
+ } |
+ |
+ // Test timeout for a portal detection used by unit tests. |
+ static base::TimeDelta request_timeout_for_testing_; |
+ |
+ // True if |request_timeout_for_testing_| is initialized. |
+ static bool request_timeout_for_testing_initialized_; |
+ |
+ static base::TimeDelta min_time_between_attempts_for_testing_; |
+ static bool min_time_between_attempts_for_testing_initialized_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PortalDetectorStrategy); |
+}; |
+ |
+class LoginScreenStrategy : public PortalDetectorStrategy { |
+ public: |
+ static const int kMaxRequestAttempts = 3; |
+ static const int kMinTimeBetweenAttemptsSec = 3; |
+ static const int kBaseRequestTimeoutSec = 5; |
+ |
+ explicit LoginScreenStrategy(PortalDetectorStrategy::Delegate* delegate); |
+ virtual ~LoginScreenStrategy(); |
+ |
+ protected: |
+ // PortalDetectorStrategy overrides: |
+ virtual void ResetImpl() OVERRIDE; |
+ virtual bool CanPerformAttemptImpl() OVERRIDE; |
+ virtual base::TimeDelta GetDelayBeforeCurrentAttemptImpl() OVERRIDE; |
+ virtual base::TimeDelta GetCurrentAttemptTimeoutImpl() OVERRIDE; |
+ virtual void OnAttemptStartedImpl() OVERRIDE; |
+ virtual void OnDetectionCompletedImpl() OVERRIDE; |
+ |
+ private: |
+ friend class NetworkPortalDetectorImplTest; |
+ |
+ int attempt_count_for_testing() const { return attempt_count_; } |
+ void set_attempt_count_for_testing(int attempt_count) { |
+ attempt_count_ = attempt_count; |
+ } |
+ |
+ int attempt_count_; |
+ bool detection_completed_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(LoginScreenStrategy); |
+}; |
+ |
+class ErrorScreenStrategy : public PortalDetectorStrategy { |
+ public: |
+ static const int kMinTimeBetweenAttemptsSec = 3; |
+ static const int kRequestTimeoutSec = 15; |
+ |
+ explicit ErrorScreenStrategy(PortalDetectorStrategy::Delegate* delegate); |
+ virtual ~ErrorScreenStrategy(); |
+ |
+ protected: |
+ // PortalDetectorStrategy overrides: |
+ virtual bool CanPerformAttemptImpl() OVERRIDE; |
+ virtual base::TimeDelta GetDelayBeforeCurrentAttemptImpl() OVERRIDE; |
+ virtual base::TimeDelta GetCurrentAttemptTimeoutImpl() OVERRIDE; |
+ virtual void OnAttemptStartedImpl() OVERRIDE; |
+ |
+ private: |
+ friend class NetworkPortalDetectorImplTest; |
+ |
+ void set_delay_between_attempts_for_testing(const base::TimeDelta& delay) { |
+ delay_between_attempts_ = delay; |
+ } |
+ |
+ base::TimeDelta delay_between_attempts_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ErrorScreenStrategy); |
+}; |
+ |
+} // namespace chromeos |
+ |
+#endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_STRATEGY_H_ |