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

Side by Side Diff: chrome/browser/chromeos/net/network_portal_detector_impl.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 if (elapsed_time < delay_between_attempts && 290 if (elapsed_time < delay_between_attempts &&
291 delay_between_attempts - elapsed_time > next_attempt_delay_) { 291 delay_between_attempts - elapsed_time > next_attempt_delay_) {
292 next_attempt_delay_ = delay_between_attempts - elapsed_time; 292 next_attempt_delay_ = delay_between_attempts - elapsed_time;
293 } 293 }
294 } else { 294 } else {
295 detection_start_time_ = GetCurrentTimeTicks(); 295 detection_start_time_ = GetCurrentTimeTicks();
296 } 296 }
297 detection_task_.Reset( 297 detection_task_.Reset(
298 base::Bind(&NetworkPortalDetectorImpl::DetectCaptivePortalTask, 298 base::Bind(&NetworkPortalDetectorImpl::DetectCaptivePortalTask,
299 weak_ptr_factory_.GetWeakPtr())); 299 weak_ptr_factory_.GetWeakPtr()));
300 MessageLoop::current()->PostDelayedTask(FROM_HERE, 300 base::MessageLoop::current()->PostDelayedTask(
301 detection_task_.callback(), 301 FROM_HERE, detection_task_.callback(), next_attempt_delay_);
302 next_attempt_delay_);
303 } 302 }
304 303
305 void NetworkPortalDetectorImpl::DetectCaptivePortalTask() { 304 void NetworkPortalDetectorImpl::DetectCaptivePortalTask() {
306 DCHECK(IsPortalCheckPending()); 305 DCHECK(IsPortalCheckPending());
307 306
308 state_ = STATE_CHECKING_FOR_PORTAL; 307 state_ = STATE_CHECKING_FOR_PORTAL;
309 attempt_start_time_ = GetCurrentTimeTicks(); 308 attempt_start_time_ = GetCurrentTimeTicks();
310 309
311 if (attempt_count_ < kMaxRequestAttempts) { 310 if (attempt_count_ < kMaxRequestAttempts) {
312 ++attempt_count_; 311 ++attempt_count_;
313 VLOG(1) << "Portal detection started: " 312 VLOG(1) << "Portal detection started: "
314 << "network=" << active_network_id_ << ", " 313 << "network=" << active_network_id_ << ", "
315 << "attempt=" << attempt_count_ << " of " << kMaxRequestAttempts; 314 << "attempt=" << attempt_count_ << " of " << kMaxRequestAttempts;
316 } else { 315 } else {
317 DCHECK(lazy_detection_enabled_); 316 DCHECK(lazy_detection_enabled_);
318 VLOG(1) << "Lazy portal detection attempt started"; 317 VLOG(1) << "Lazy portal detection attempt started";
319 } 318 }
320 319
321 captive_portal_detector_->DetectCaptivePortal( 320 captive_portal_detector_->DetectCaptivePortal(
322 test_url_, 321 test_url_,
323 base::Bind(&NetworkPortalDetectorImpl::OnPortalDetectionCompleted, 322 base::Bind(&NetworkPortalDetectorImpl::OnPortalDetectionCompleted,
324 weak_ptr_factory_.GetWeakPtr())); 323 weak_ptr_factory_.GetWeakPtr()));
325 detection_timeout_.Reset( 324 detection_timeout_.Reset(
326 base::Bind(&NetworkPortalDetectorImpl::PortalDetectionTimeout, 325 base::Bind(&NetworkPortalDetectorImpl::PortalDetectionTimeout,
327 weak_ptr_factory_.GetWeakPtr())); 326 weak_ptr_factory_.GetWeakPtr()));
328 MessageLoop::current()->PostDelayedTask(FROM_HERE, 327 base::MessageLoop::current()->PostDelayedTask(
329 detection_timeout_.callback(), 328 FROM_HERE, detection_timeout_.callback(), request_timeout_);
330 request_timeout_);
331 } 329 }
332 330
333 void NetworkPortalDetectorImpl::PortalDetectionTimeout() { 331 void NetworkPortalDetectorImpl::PortalDetectionTimeout() {
334 DCHECK(CalledOnValidThread()); 332 DCHECK(CalledOnValidThread());
335 DCHECK(IsCheckingForPortal()); 333 DCHECK(IsCheckingForPortal());
336 334
337 VLOG(1) << "Portal detection timeout: network=" << active_network_id_; 335 VLOG(1) << "Portal detection timeout: network=" << active_network_id_;
338 336
339 captive_portal_detector_->Cancel(); 337 captive_portal_detector_->Cancel();
340 CaptivePortalDetector::Results results; 338 CaptivePortalDetector::Results results;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 return base::TimeTicks::Now(); 475 return base::TimeTicks::Now();
478 else 476 else
479 return time_ticks_for_testing_; 477 return time_ticks_for_testing_;
480 } 478 }
481 479
482 bool NetworkPortalDetectorImpl::DetectionTimeoutIsCancelledForTesting() const { 480 bool NetworkPortalDetectorImpl::DetectionTimeoutIsCancelledForTesting() const {
483 return detection_timeout_.IsCancelled(); 481 return detection_timeout_.IsCancelled();
484 } 482 }
485 483
486 } // namespace chromeos 484 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698