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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_STRATEGY_H_
6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_STRATEGY_H_
7
8 #include "base/compiler_specific.h"
9 #include "base/macros.h"
10 #include "base/time/time.h"
11
12 namespace chromeos {
13
14 class PortalDetectorStrategy {
15 public:
16 class Delegate {
17 public:
18 virtual ~Delegate() {}
19 virtual base::TimeTicks GetCurrentTimeTicks() = 0;
20 };
21
22 explicit PortalDetectorStrategy(Delegate* delegate);
23 virtual ~PortalDetectorStrategy();
24
25 void Reset();
26 bool CanPerformAttempt();
27 base::TimeDelta GetDelayBeforeCurrentAttempt();
Denis Kuznetsov (DE-MUC) 2014/03/05 16:59:09 GetDelayTillNextAttempt ?
ygorshenin1 2014/03/06 11:59:33 Done.
28 base::TimeDelta GetCurrentAttemptTimeout();
Denis Kuznetsov (DE-MUC) 2014/03/05 16:59:09 comments for methods?
ygorshenin1 2014/03/06 11:59:33 Done.
29 void OnAttemptStarted();
30 void OnDetectionCompleted();
31
32 protected:
33 base::TimeTicks GetCurrentTimeTicks() {
34 return delegate_->GetCurrentTimeTicks();
35 }
36
37 // Interface for subclasses:
38 virtual void ResetImpl();
39 virtual bool CanPerformAttemptImpl();
40 virtual base::TimeDelta GetDelayBeforeCurrentAttemptImpl();
41 virtual base::TimeDelta GetCurrentAttemptTimeoutImpl();
42 virtual void OnAttemptStartedImpl();
43 virtual void OnDetectionCompletedImpl();
44
45 Delegate* delegate_;
46
47 // Start time of portal detection attempt.
48 base::TimeTicks attempt_start_time_;
49
50 private:
51 friend class NetworkPortalDetectorImplTest;
52
53 // Sets portal detection timeout. Used by unit tests.
54 static void set_request_timeout_for_testing(const base::TimeDelta& timeout) {
55 request_timeout_for_testing_ = timeout;
56 request_timeout_for_testing_initialized_ = true;
57 }
58
59 static void reset_request_timeout_for_testing() {
60 request_timeout_for_testing_initialized_ = false;
61 }
62
63 static void set_min_time_between_attempts_for_testing(
64 const base::TimeDelta& timeout) {
65 min_time_between_attempts_for_testing_ = timeout;
66 min_time_between_attempts_for_testing_initialized_ = true;
67 }
68
69 static void reset_min_time_between_attempts_for_testing() {
70 min_time_between_attempts_for_testing_initialized_ = false;
71 }
72
73 // Test timeout for a portal detection used by unit tests.
74 static base::TimeDelta request_timeout_for_testing_;
75
76 // True if |request_timeout_for_testing_| is initialized.
77 static bool request_timeout_for_testing_initialized_;
78
79 static base::TimeDelta min_time_between_attempts_for_testing_;
80 static bool min_time_between_attempts_for_testing_initialized_;
81
82 DISALLOW_COPY_AND_ASSIGN(PortalDetectorStrategy);
83 };
84
85 class LoginScreenStrategy : public PortalDetectorStrategy {
86 public:
87 static const int kMaxRequestAttempts = 3;
88 static const int kMinTimeBetweenAttemptsSec = 3;
89 static const int kBaseRequestTimeoutSec = 5;
90
91 explicit LoginScreenStrategy(PortalDetectorStrategy::Delegate* delegate);
92 virtual ~LoginScreenStrategy();
93
94 protected:
95 // PortalDetectorStrategy overrides:
96 virtual void ResetImpl() OVERRIDE;
97 virtual bool CanPerformAttemptImpl() OVERRIDE;
98 virtual base::TimeDelta GetDelayBeforeCurrentAttemptImpl() OVERRIDE;
99 virtual base::TimeDelta GetCurrentAttemptTimeoutImpl() OVERRIDE;
100 virtual void OnAttemptStartedImpl() OVERRIDE;
101 virtual void OnDetectionCompletedImpl() OVERRIDE;
102
103 private:
104 friend class NetworkPortalDetectorImplTest;
105
106 int attempt_count_for_testing() const { return attempt_count_; }
107 void set_attempt_count_for_testing(int attempt_count) {
108 attempt_count_ = attempt_count;
109 }
110
111 int attempt_count_;
112 bool detection_completed_;
113
114 DISALLOW_COPY_AND_ASSIGN(LoginScreenStrategy);
115 };
116
117 class ErrorScreenStrategy : public PortalDetectorStrategy {
118 public:
119 static const int kMinTimeBetweenAttemptsSec = 3;
120 static const int kRequestTimeoutSec = 15;
121
122 explicit ErrorScreenStrategy(PortalDetectorStrategy::Delegate* delegate);
123 virtual ~ErrorScreenStrategy();
124
125 protected:
126 // PortalDetectorStrategy overrides:
127 virtual bool CanPerformAttemptImpl() OVERRIDE;
128 virtual base::TimeDelta GetDelayBeforeCurrentAttemptImpl() OVERRIDE;
129 virtual base::TimeDelta GetCurrentAttemptTimeoutImpl() OVERRIDE;
130 virtual void OnAttemptStartedImpl() OVERRIDE;
131
132 private:
133 friend class NetworkPortalDetectorImplTest;
134
135 void set_delay_between_attempts_for_testing(const base::TimeDelta& delay) {
136 delay_between_attempts_ = delay;
137 }
138
139 base::TimeDelta delay_between_attempts_;
140
141 DISALLOW_COPY_AND_ASSIGN(ErrorScreenStrategy);
142 };
143
144 } // namespace chromeos
145
146 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_STRATEGY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698