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

Side by Side Diff: chromeos/network/portal_detector/network_portal_detector_strategy.h

Issue 1076853003: Refactor net::BackoffEntry to not require subclassing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make DataReductionProxyConfigServiceClient::Now non-const Created 5 years, 8 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 unified diff | Download patch
OLDNEW
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 {
stevenjb 2015/04/13 15:20:10 I'm not actually very familiar with this code, but
pneubeck (no reviews) 2015/04/14 10:27:04 Looking more into the usage of this, I think it mi
johnme 2015/04/20 15:52:44 Acknowledged.
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
37 // Returns current TimeTicks. 38 // TickClock implementation.
pneubeck (no reviews) 2015/04/14 10:27:04 nit: not required to repeat abstract functions. I'
johnme 2015/04/20 15:52:44 Done.
38 virtual base::TimeTicks GetCurrentTimeTicks() = 0; 39 base::TimeTicks NowTicks() override = 0;
39 }; 40 };
40 41
41 virtual ~PortalDetectorStrategy(); 42 virtual ~PortalDetectorStrategy();
42 43
43 static scoped_ptr<PortalDetectorStrategy> CreateById(StrategyId id, 44 static scoped_ptr<PortalDetectorStrategy> CreateById(StrategyId id,
pneubeck (no reviews) 2015/04/14 10:27:04 as you probably had to read/understand this code,
johnme 2015/04/20 15:57:55 Done.
44 Delegate* delegate); 45 Delegate* delegate);
45 46
46 // Returns delay before next detection attempt. This delay is needed 47 // Returns delay before next detection attempt. This delay is needed
47 // to separate detection attempts in time. 48 // to separate detection attempts in time.
48 base::TimeDelta GetDelayTillNextAttempt(); 49 base::TimeDelta GetDelayTillNextAttempt();
49 50
50 // Returns timeout for the next detection attempt. 51 // Returns timeout for the next detection attempt.
51 base::TimeDelta GetNextAttemptTimeout(); 52 base::TimeDelta GetNextAttemptTimeout();
52 53
53 virtual StrategyId Id() const = 0; 54 virtual StrategyId Id() const = 0;
54 55
55 // Resets strategy to the initial state. 56 // Resets strategy to the initial state.
56 void Reset(); 57 void Reset();
57 58
58 const net::BackoffEntry::Policy& policy() const { return policy_; } 59 const net::BackoffEntry::Policy& policy() const { return policy_; }
59 60
60 // Resets strategy to the initial stater and sets custom policy. 61 // Resets strategy to the initial stater and sets custom policy.
61 void SetPolicyAndReset(const net::BackoffEntry::Policy& policy); 62 void SetPolicyAndReset(const net::BackoffEntry::Policy& policy);
62 63
63 // Should be called when portal detection is completed and timeout before next 64 // Should be called when portal detection is completed and timeout before next
64 // attempt should be adjusted. 65 // attempt should be adjusted.
65 void OnDetectionCompleted(); 66 void OnDetectionCompleted();
66 67
67 protected: 68 protected:
68 class BackoffEntryImpl;
69
70 explicit PortalDetectorStrategy(Delegate* delegate); 69 explicit PortalDetectorStrategy(Delegate* delegate);
71 70
72 // Interface for subclasses: 71 // Interface for subclasses:
73 virtual base::TimeDelta GetNextAttemptTimeoutImpl(); 72 virtual base::TimeDelta GetNextAttemptTimeoutImpl();
74 73
75 Delegate* delegate_; 74 Delegate* delegate_;
76 net::BackoffEntry::Policy policy_; 75 net::BackoffEntry::Policy policy_;
77 scoped_ptr<BackoffEntryImpl> backoff_entry_; 76 scoped_ptr<net::BackoffEntry> backoff_entry_;
78 77
79 private: 78 private:
80 friend class NetworkPortalDetectorImplTest; 79 friend class NetworkPortalDetectorImplTest;
81 friend class NetworkPortalDetectorImplBrowserTest; 80 friend class NetworkPortalDetectorImplBrowserTest;
82 81
83 static void set_delay_till_next_attempt_for_testing( 82 static void set_delay_till_next_attempt_for_testing(
84 const base::TimeDelta& timeout) { 83 const base::TimeDelta& timeout) {
85 delay_till_next_attempt_for_testing_ = timeout; 84 delay_till_next_attempt_for_testing_ = timeout;
86 delay_till_next_attempt_for_testing_initialized_ = true; 85 delay_till_next_attempt_for_testing_initialized_ = true;
87 } 86 }
(...skipping 20 matching lines...) Expand all
108 107
109 // True when |next_attempt_timeout_for_testing_| is initialized. 108 // True when |next_attempt_timeout_for_testing_| is initialized.
110 static bool next_attempt_timeout_for_testing_initialized_; 109 static bool next_attempt_timeout_for_testing_initialized_;
111 110
112 DISALLOW_COPY_AND_ASSIGN(PortalDetectorStrategy); 111 DISALLOW_COPY_AND_ASSIGN(PortalDetectorStrategy);
113 }; 112 };
114 113
115 } // namespace chromeos 114 } // namespace chromeos
116 115
117 #endif // CHROMEOS_NETWORK_PORTAL_DETECTOR_NETWORK_PORTAL_DETECTOR_STRATEGY_H_ 116 #endif // CHROMEOS_NETWORK_PORTAL_DETECTOR_NETWORK_PORTAL_DETECTOR_STRATEGY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698