Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / chromeos / net / network_portal_detector_strategy.h
blob36706da9aaf84451ca50a425c9d767ccdc22bab3
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_STRATEGY_H_
6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_STRATEGY_H_
8 #include "base/compiler_specific.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/time/time.h"
13 namespace chromeos {
15 class PortalDetectorStrategy {
16 public:
17 enum StrategyId {
18 STRATEGY_ID_LOGIN_SCREEN,
19 STRATEGY_ID_ERROR_SCREEN,
20 STRATEGY_ID_SESSION,
23 class Delegate {
24 public:
25 virtual ~Delegate() {}
27 // Returns number of performed attempts.
28 virtual int AttemptCount() = 0;
30 // Returns time when current attempt was started.
31 virtual base::TimeTicks AttemptStartTime() = 0;
33 // Returns current TimeTicks.
34 virtual base::TimeTicks GetCurrentTimeTicks() = 0;
37 virtual ~PortalDetectorStrategy();
39 static scoped_ptr<PortalDetectorStrategy> CreateById(StrategyId id);
41 void set_delegate(Delegate* delegate) { delegate_ = delegate; }
43 // Returns true when detection attempt can be performed according to
44 // current strategy.
45 bool CanPerformAttempt();
47 // Returns true if additional attempt could be scheduled after
48 // detection.
49 bool CanPerformAttemptAfterDetection();
51 // Returns delay before next detection attempt. This delay is needed
52 // to separate detection attempts in time.
53 base::TimeDelta GetDelayTillNextAttempt();
55 // Returns timeout for the next detection attempt.
56 base::TimeDelta GetNextAttemptTimeout();
58 virtual StrategyId Id() const = 0;
60 protected:
61 PortalDetectorStrategy();
63 // Interface for subclasses:
64 virtual bool CanPerformAttemptImpl();
65 virtual bool CanPerformAttemptAfterDetectionImpl();
66 virtual base::TimeDelta GetDelayTillNextAttemptImpl();
67 virtual base::TimeDelta GetNextAttemptTimeoutImpl();
69 // Adjusts |delay| according to current attempt count and elapsed time
70 // since previous attempt.
71 base::TimeDelta AdjustDelay(const base::TimeDelta& delay);
73 Delegate* delegate_;
75 private:
76 friend class NetworkPortalDetectorImplTest;
77 friend class NetworkPortalDetectorImplBrowserTest;
79 static void set_delay_till_next_attempt_for_testing(
80 const base::TimeDelta& timeout) {
81 delay_till_next_attempt_for_testing_ = timeout;
82 delay_till_next_attempt_for_testing_initialized_ = true;
85 static void set_next_attempt_timeout_for_testing(
86 const base::TimeDelta& timeout) {
87 next_attempt_timeout_for_testing_ = timeout;
88 next_attempt_timeout_for_testing_initialized_ = true;
91 static void reset_fields_for_testing() {
92 delay_till_next_attempt_for_testing_initialized_ = false;
93 next_attempt_timeout_for_testing_initialized_ = false;
96 // Test delay before detection attempt, used by unit tests.
97 static base::TimeDelta delay_till_next_attempt_for_testing_;
99 // True when |min_time_between_attempts_for_testing_| is initialized.
100 static bool delay_till_next_attempt_for_testing_initialized_;
102 // Test timeout for a detection attempt, used by unit tests.
103 static base::TimeDelta next_attempt_timeout_for_testing_;
105 // True when |next_attempt_timeout_for_testing_| is initialized.
106 static bool next_attempt_timeout_for_testing_initialized_;
108 DISALLOW_COPY_AND_ASSIGN(PortalDetectorStrategy);
111 } // namespace chromeos
113 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_STRATEGY_H_