OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include "chrome/browser/chromeos/net/network_portal_detector_impl.h" | 5 #include "chrome/browser/chromeos/net/network_portal_detector_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 content::NotificationService::AllSources()); | 94 content::NotificationService::AllSources()); |
95 } | 95 } |
96 | 96 |
97 NetworkPortalDetectorImpl::~NetworkPortalDetectorImpl() { | 97 NetworkPortalDetectorImpl::~NetworkPortalDetectorImpl() { |
98 } | 98 } |
99 | 99 |
100 void NetworkPortalDetectorImpl::Init() { | 100 void NetworkPortalDetectorImpl::Init() { |
101 DCHECK(CalledOnValidThread()); | 101 DCHECK(CalledOnValidThread()); |
102 | 102 |
103 state_ = STATE_IDLE; | 103 state_ = STATE_IDLE; |
104 NetworkStateHandler::Get()->AddObserver(this); | 104 NetworkHandler::Get()->network_state_handler()->AddObserver(this); |
105 } | 105 } |
106 | 106 |
107 void NetworkPortalDetectorImpl::Shutdown() { | 107 void NetworkPortalDetectorImpl::Shutdown() { |
108 DCHECK(CalledOnValidThread()); | 108 DCHECK(CalledOnValidThread()); |
109 | 109 |
110 detection_task_.Cancel(); | 110 detection_task_.Cancel(); |
111 detection_timeout_.Cancel(); | 111 detection_timeout_.Cancel(); |
112 | 112 |
113 captive_portal_detector_->Cancel(); | 113 captive_portal_detector_->Cancel(); |
114 captive_portal_detector_.reset(); | 114 captive_portal_detector_.reset(); |
115 observers_.Clear(); | 115 observers_.Clear(); |
116 if (NetworkStateHandler::IsInitialized()) | 116 if (NetworkHandler::IsInitialized()) |
117 NetworkStateHandler::Get()->RemoveObserver(this); | 117 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this); |
118 } | 118 } |
119 | 119 |
120 void NetworkPortalDetectorImpl::AddObserver(Observer* observer) { | 120 void NetworkPortalDetectorImpl::AddObserver(Observer* observer) { |
121 DCHECK(CalledOnValidThread()); | 121 DCHECK(CalledOnValidThread()); |
122 if (!observer || observers_.HasObserver(observer)) | 122 if (!observer || observers_.HasObserver(observer)) |
123 return; | 123 return; |
124 observers_.AddObserver(observer); | 124 observers_.AddObserver(observer); |
125 } | 125 } |
126 | 126 |
127 void NetworkPortalDetectorImpl::AddAndFireObserver(Observer* observer) { | 127 void NetworkPortalDetectorImpl::AddAndFireObserver(Observer* observer) { |
128 DCHECK(CalledOnValidThread()); | 128 DCHECK(CalledOnValidThread()); |
129 if (!observer) | 129 if (!observer) |
130 return; | 130 return; |
131 AddObserver(observer); | 131 AddObserver(observer); |
132 const NetworkState* network = NetworkStateHandler::Get()->DefaultNetwork(); | 132 const NetworkState* network = |
| 133 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); |
133 observer->OnPortalDetectionCompleted(network, GetCaptivePortalState(network)); | 134 observer->OnPortalDetectionCompleted(network, GetCaptivePortalState(network)); |
134 } | 135 } |
135 | 136 |
136 void NetworkPortalDetectorImpl::RemoveObserver(Observer* observer) { | 137 void NetworkPortalDetectorImpl::RemoveObserver(Observer* observer) { |
137 DCHECK(CalledOnValidThread()); | 138 DCHECK(CalledOnValidThread()); |
138 if (observer) | 139 if (observer) |
139 observers_.RemoveObserver(observer); | 140 observers_.RemoveObserver(observer); |
140 } | 141 } |
141 | 142 |
142 bool NetworkPortalDetectorImpl::IsEnabled() { | 143 bool NetworkPortalDetectorImpl::IsEnabled() { |
143 return enabled_; | 144 return enabled_; |
144 } | 145 } |
145 | 146 |
146 void NetworkPortalDetectorImpl::Enable(bool start_detection) { | 147 void NetworkPortalDetectorImpl::Enable(bool start_detection) { |
147 DCHECK(CalledOnValidThread()); | 148 DCHECK(CalledOnValidThread()); |
148 if (enabled_) | 149 if (enabled_) |
149 return; | 150 return; |
150 enabled_ = true; | 151 enabled_ = true; |
151 DCHECK(!IsPortalCheckPending()); | 152 DCHECK(!IsPortalCheckPending()); |
152 DCHECK(!IsCheckingForPortal()); | 153 DCHECK(!IsCheckingForPortal()); |
153 DCHECK(!lazy_detection_enabled()); | 154 DCHECK(!lazy_detection_enabled()); |
154 if (!start_detection) | 155 if (!start_detection) |
155 return; | 156 return; |
156 state_ = STATE_IDLE; | 157 state_ = STATE_IDLE; |
157 attempt_count_ = 0; | 158 attempt_count_ = 0; |
158 const NetworkState* default_network = | 159 const NetworkState* default_network = |
159 NetworkStateHandler::Get()->DefaultNetwork(); | 160 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); |
160 if (!default_network) | 161 if (!default_network) |
161 return; | 162 return; |
162 portal_state_map_.erase(default_network->path()); | 163 portal_state_map_.erase(default_network->path()); |
163 DCHECK(CanPerformDetection()); | 164 DCHECK(CanPerformDetection()); |
164 DetectCaptivePortal(base::TimeDelta()); | 165 DetectCaptivePortal(base::TimeDelta()); |
165 } | 166 } |
166 | 167 |
167 NetworkPortalDetectorImpl::CaptivePortalState | 168 NetworkPortalDetectorImpl::CaptivePortalState |
168 NetworkPortalDetectorImpl::GetCaptivePortalState(const NetworkState* network) { | 169 NetworkPortalDetectorImpl::GetCaptivePortalState(const NetworkState* network) { |
169 DCHECK(CalledOnValidThread()); | 170 DCHECK(CalledOnValidThread()); |
(...skipping 26 matching lines...) Expand all Loading... |
196 | 197 |
197 void NetworkPortalDetectorImpl::DisableLazyDetection() { | 198 void NetworkPortalDetectorImpl::DisableLazyDetection() { |
198 CHECK(lazy_detection_enabled()); | 199 CHECK(lazy_detection_enabled()); |
199 lazy_detection_enabled_ = false; | 200 lazy_detection_enabled_ = false; |
200 VLOG(1) << "Lazy detection mode disabled."; | 201 VLOG(1) << "Lazy detection mode disabled."; |
201 } | 202 } |
202 | 203 |
203 void NetworkPortalDetectorImpl::NetworkManagerChanged() { | 204 void NetworkPortalDetectorImpl::NetworkManagerChanged() { |
204 DCHECK(CalledOnValidThread()); | 205 DCHECK(CalledOnValidThread()); |
205 const NetworkState* default_network = | 206 const NetworkState* default_network = |
206 NetworkStateHandler::Get()->DefaultNetwork(); | 207 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); |
207 if (!default_network) { | 208 if (!default_network) { |
208 default_network_id_.clear(); | 209 default_network_id_.clear(); |
209 return; | 210 return; |
210 } | 211 } |
211 | 212 |
212 default_network_id_ = default_network->guid(); | 213 default_network_id_ = default_network->guid(); |
213 | 214 |
214 bool network_changed = (default_service_path_ != default_network->path()); | 215 bool network_changed = (default_service_path_ != default_network->path()); |
215 default_service_path_ = default_network->path(); | 216 default_service_path_ = default_network->path(); |
216 | 217 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 VLOG(1) << "Portal detection completed: " | 355 VLOG(1) << "Portal detection completed: " |
355 << "network=" << default_network_id_ << ", " | 356 << "network=" << default_network_id_ << ", " |
356 << "result=" << CaptivePortalDetector::CaptivePortalResultToString( | 357 << "result=" << CaptivePortalDetector::CaptivePortalResultToString( |
357 results.result) << ", " | 358 results.result) << ", " |
358 << "response_code=" << results.response_code; | 359 << "response_code=" << results.response_code; |
359 | 360 |
360 state_ = STATE_IDLE; | 361 state_ = STATE_IDLE; |
361 detection_timeout_.Cancel(); | 362 detection_timeout_.Cancel(); |
362 | 363 |
363 const NetworkState* default_network = | 364 const NetworkState* default_network = |
364 NetworkStateHandler::Get()->DefaultNetwork(); | 365 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); |
365 | 366 |
366 CaptivePortalState state; | 367 CaptivePortalState state; |
367 state.response_code = results.response_code; | 368 state.response_code = results.response_code; |
368 switch (results.result) { | 369 switch (results.result) { |
369 case captive_portal::RESULT_NO_RESPONSE: | 370 case captive_portal::RESULT_NO_RESPONSE: |
370 if (attempt_count_ >= kMaxRequestAttempts) { | 371 if (attempt_count_ >= kMaxRequestAttempts) { |
371 if (state.response_code == net::HTTP_PROXY_AUTHENTICATION_REQUIRED) { | 372 if (state.response_code == net::HTTP_PROXY_AUTHENTICATION_REQUIRED) { |
372 state.status = CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED; | 373 state.status = CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED; |
373 } else if (default_network && (default_network->connection_state() == | 374 } else if (default_network && (default_network->connection_state() == |
374 flimflam::kStatePortal)) { | 375 flimflam::kStatePortal)) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 return base::TimeTicks::Now(); | 473 return base::TimeTicks::Now(); |
473 return time_ticks_for_testing_; | 474 return time_ticks_for_testing_; |
474 } | 475 } |
475 | 476 |
476 bool NetworkPortalDetectorImpl::DetectionTimeoutIsCancelledForTesting() const { | 477 bool NetworkPortalDetectorImpl::DetectionTimeoutIsCancelledForTesting() const { |
477 return detection_timeout_.IsCancelled(); | 478 return detection_timeout_.IsCancelled(); |
478 } | 479 } |
479 | 480 |
480 int NetworkPortalDetectorImpl::GetRequestTimeoutSec() const { | 481 int NetworkPortalDetectorImpl::GetRequestTimeoutSec() const { |
481 DCHECK_LE(0, attempt_count_); | 482 DCHECK_LE(0, attempt_count_); |
482 const NetworkState* network = NetworkStateHandler::Get()->DefaultNetwork(); | 483 const NetworkState* network = |
| 484 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); |
483 if (!network) | 485 if (!network) |
484 return kBaseRequestTimeoutSec; | 486 return kBaseRequestTimeoutSec; |
485 if (lazy_detection_enabled_) | 487 if (lazy_detection_enabled_) |
486 return kLazyRequestTimeoutSec; | 488 return kLazyRequestTimeoutSec; |
487 return attempt_count_ * kBaseRequestTimeoutSec; | 489 return attempt_count_ * kBaseRequestTimeoutSec; |
488 } | 490 } |
489 | 491 |
490 } // namespace chromeos | 492 } // namespace chromeos |
OLD | NEW |