OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 CHROMEOS_NETWORK_PORTAL_DETECTOR_NETWORK_PORTAL_DETECTOR_STRATEGY_H_ | 5 #ifndef CHROMEOS_NETWORK_PORTAL_DETECTOR_NETWORK_PORTAL_DETECTOR_STRATEGY_H_ |
6 #define CHROMEOS_NETWORK_PORTAL_DETECTOR_NETWORK_PORTAL_DETECTOR_STRATEGY_H_ | 6 #define CHROMEOS_NETWORK_PORTAL_DETECTOR_NETWORK_PORTAL_DETECTOR_STRATEGY_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/time/tick_clock.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "chromeos/chromeos_export.h" | 14 #include "chromeos/chromeos_export.h" |
14 #include "net/base/backoff_entry.h" | 15 #include "net/base/backoff_entry.h" |
15 | 16 |
16 namespace chromeos { | 17 namespace chromeos { |
17 | 18 |
18 class CHROMEOS_EXPORT PortalDetectorStrategy { | 19 class CHROMEOS_EXPORT PortalDetectorStrategy { |
19 public: | 20 public: |
20 enum StrategyId { | 21 enum StrategyId { |
21 STRATEGY_ID_LOGIN_SCREEN, | 22 STRATEGY_ID_LOGIN_SCREEN, |
22 STRATEGY_ID_ERROR_SCREEN, | 23 STRATEGY_ID_ERROR_SCREEN, |
23 STRATEGY_ID_SESSION | 24 STRATEGY_ID_SESSION |
24 }; | 25 }; |
25 | 26 |
26 class Delegate { | 27 class Delegate : public base::TickClock { |
27 public: | 28 public: |
28 virtual ~Delegate() {} | 29 ~Delegate() override; |
29 | 30 |
30 // Returns number of attempts in a row with NO RESPONSE result. | 31 // Returns number of attempts in a row with NO RESPONSE result. |
31 // If last detection attempt has different result, returns 0. | 32 // If last detection attempt has different result, returns 0. |
32 virtual int NoResponseResultCount() = 0; | 33 virtual int NoResponseResultCount() = 0; |
33 | 34 |
34 // Returns time when current attempt was started. | 35 // Returns time when current attempt was started. |
35 virtual base::TimeTicks AttemptStartTime() = 0; | 36 virtual base::TimeTicks AttemptStartTime() = 0; |
36 | |
37 // Returns current TimeTicks. | |
38 virtual base::TimeTicks GetCurrentTimeTicks() = 0; | |
39 }; | 37 }; |
40 | 38 |
41 virtual ~PortalDetectorStrategy(); | 39 virtual ~PortalDetectorStrategy(); |
42 | 40 |
| 41 // Lifetime of delegate must enclose lifetime of PortalDetectorStrategy. |
43 static scoped_ptr<PortalDetectorStrategy> CreateById(StrategyId id, | 42 static scoped_ptr<PortalDetectorStrategy> CreateById(StrategyId id, |
44 Delegate* delegate); | 43 Delegate* delegate); |
45 | 44 |
46 // Returns delay before next detection attempt. This delay is needed | 45 // Returns delay before next detection attempt. This delay is needed |
47 // to separate detection attempts in time. | 46 // to separate detection attempts in time. |
48 base::TimeDelta GetDelayTillNextAttempt(); | 47 base::TimeDelta GetDelayTillNextAttempt(); |
49 | 48 |
50 // Returns timeout for the next detection attempt. | 49 // Returns timeout for the next detection attempt. |
51 base::TimeDelta GetNextAttemptTimeout(); | 50 base::TimeDelta GetNextAttemptTimeout(); |
52 | 51 |
53 virtual StrategyId Id() const = 0; | 52 virtual StrategyId Id() const = 0; |
54 | 53 |
55 // Resets strategy to the initial state. | 54 // Resets strategy to the initial state. |
56 void Reset(); | 55 void Reset(); |
57 | 56 |
58 const net::BackoffEntry::Policy& policy() const { return policy_; } | 57 const net::BackoffEntry::Policy& policy() const { return policy_; } |
59 | 58 |
60 // Resets strategy to the initial stater and sets custom policy. | 59 // Resets strategy to the initial stater and sets custom policy. |
61 void SetPolicyAndReset(const net::BackoffEntry::Policy& policy); | 60 void SetPolicyAndReset(const net::BackoffEntry::Policy& policy); |
62 | 61 |
63 // Should be called when portal detection is completed and timeout before next | 62 // Should be called when portal detection is completed and timeout before next |
64 // attempt should be adjusted. | 63 // attempt should be adjusted. |
65 void OnDetectionCompleted(); | 64 void OnDetectionCompleted(); |
66 | 65 |
67 protected: | 66 protected: |
68 class BackoffEntryImpl; | 67 // Lifetime of delegate must enclose lifetime of PortalDetectorStrategy. |
69 | |
70 explicit PortalDetectorStrategy(Delegate* delegate); | 68 explicit PortalDetectorStrategy(Delegate* delegate); |
71 | 69 |
72 // Interface for subclasses: | 70 // Interface for subclasses: |
73 virtual base::TimeDelta GetNextAttemptTimeoutImpl(); | 71 virtual base::TimeDelta GetNextAttemptTimeoutImpl(); |
74 | 72 |
75 Delegate* delegate_; | 73 Delegate* delegate_; |
76 net::BackoffEntry::Policy policy_; | 74 net::BackoffEntry::Policy policy_; |
77 scoped_ptr<BackoffEntryImpl> backoff_entry_; | 75 scoped_ptr<net::BackoffEntry> backoff_entry_; |
78 | 76 |
79 private: | 77 private: |
80 friend class NetworkPortalDetectorImplTest; | 78 friend class NetworkPortalDetectorImplTest; |
81 friend class NetworkPortalDetectorImplBrowserTest; | 79 friend class NetworkPortalDetectorImplBrowserTest; |
82 | 80 |
83 static void set_delay_till_next_attempt_for_testing( | 81 static void set_delay_till_next_attempt_for_testing( |
84 const base::TimeDelta& timeout) { | 82 const base::TimeDelta& timeout) { |
85 delay_till_next_attempt_for_testing_ = timeout; | 83 delay_till_next_attempt_for_testing_ = timeout; |
86 delay_till_next_attempt_for_testing_initialized_ = true; | 84 delay_till_next_attempt_for_testing_initialized_ = true; |
87 } | 85 } |
(...skipping 20 matching lines...) Expand all Loading... |
108 | 106 |
109 // True when |next_attempt_timeout_for_testing_| is initialized. | 107 // True when |next_attempt_timeout_for_testing_| is initialized. |
110 static bool next_attempt_timeout_for_testing_initialized_; | 108 static bool next_attempt_timeout_for_testing_initialized_; |
111 | 109 |
112 DISALLOW_COPY_AND_ASSIGN(PortalDetectorStrategy); | 110 DISALLOW_COPY_AND_ASSIGN(PortalDetectorStrategy); |
113 }; | 111 }; |
114 | 112 |
115 } // namespace chromeos | 113 } // namespace chromeos |
116 | 114 |
117 #endif // CHROMEOS_NETWORK_PORTAL_DETECTOR_NETWORK_PORTAL_DETECTOR_STRATEGY_H_ | 115 #endif // CHROMEOS_NETWORK_PORTAL_DETECTOR_NETWORK_PORTAL_DETECTOR_STRATEGY_H_ |
OLD | NEW |