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

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

Issue 183973029: Refactoring of the NetworkPortalDetector. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes. Created 6 years, 9 months 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_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..9d18976a79454d42d27c0b7ca7c068070a15cea1
--- /dev/null
+++ b/chrome/browser/chromeos/net/network_portal_detector_strategy.h
@@ -0,0 +1,111 @@
+// 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/memory/scoped_ptr.h"
+#include "base/time/time.h"
+
+namespace chromeos {
+
+class PortalDetectorStrategy {
+ public:
+ enum StrategyId {
+ STRATEGY_ID_LOGIN_SCREEN,
+ STRATEGY_ID_ERROR_SCREEN
+ };
+
+ class Delegate {
+ public:
+ virtual ~Delegate() {}
+
+ // Returns number of performed attempts.
+ virtual int AttemptCount() = 0;
+
+ // Returns time when current attempt was started.
+ virtual base::TimeTicks AttemptStartTime() = 0;
+
+ // Returns current TimeTicks.
+ virtual base::TimeTicks GetCurrentTimeTicks() = 0;
+ };
+
+ virtual ~PortalDetectorStrategy();
+
+ static scoped_ptr<PortalDetectorStrategy> CreateById(StrategyId id);
+
+ void set_delegate(Delegate* delegate) { delegate_ = delegate; }
+
+ // Returns true when detection attempt can be performed according to
+ // current strategy.
+ bool CanPerformAttempt();
+
+ // Returns true if additional attempt could be scheduled after
+ // detection.
+ bool CanPerformAttemptAfterDetection();
+
+ // Returns delay before next detection attempt. This delay is needed
+ // to separate detection attempts in time.
+ base::TimeDelta GetDelayTillNextAttempt();
+
+ // Returns timeout for the next detection attempt.
+ base::TimeDelta GetNextAttemptTimeout();
+
+ virtual StrategyId Id() const = 0;
+
+ protected:
+ PortalDetectorStrategy();
+
+ // Interface for subclasses:
+ virtual bool CanPerformAttemptImpl();
+ virtual bool CanPerformAttemptAfterDetectionImpl();
+ virtual base::TimeDelta GetDelayTillNextAttemptImpl();
+ virtual base::TimeDelta GetNextAttemptTimeoutImpl();
+
+ // Adjusts |delay| according to current attempt count and elapsed time
+ // since previous attempt.
+ base::TimeDelta AdjustDelay(const base::TimeDelta& delay);
+
+ Delegate* delegate_;
+
+ private:
+ friend class NetworkPortalDetectorImplTest;
+
+ static void set_delay_till_next_attempt_for_testing(
+ const base::TimeDelta& timeout) {
+ delay_till_next_attempt_for_testing_ = timeout;
+ delay_till_next_attempt_for_testing_initialized_ = true;
+ }
+
+ static void set_next_attempt_timeout_for_testing(
+ const base::TimeDelta& timeout) {
+ next_attempt_timeout_for_testing_ = timeout;
+ next_attempt_timeout_for_testing_initialized_ = true;
+ }
+
+ static void reset_fields_for_testing() {
+ delay_till_next_attempt_for_testing_initialized_ = false;
+ next_attempt_timeout_for_testing_initialized_ = false;
+ }
+
+ // Test delay before detection attempt, used by unit tests.
+ static base::TimeDelta delay_till_next_attempt_for_testing_;
+
+ // True when |min_time_between_attempts_for_testing_| is initialized.
+ static bool delay_till_next_attempt_for_testing_initialized_;
+
+ // Test timeout for a detection attempt, used by unit tests.
+ static base::TimeDelta next_attempt_timeout_for_testing_;
+
+ // True when |next_attempt_timeout_for_testing_| is initialized.
+ static bool next_attempt_timeout_for_testing_initialized_;
+
+ DISALLOW_COPY_AND_ASSIGN(PortalDetectorStrategy);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_STRATEGY_H_

Powered by Google App Engine
This is Rietveld 408576698