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

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: rebase again Created 7 years, 7 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 if (elapsed_time < delay_between_attempts && 278 if (elapsed_time < delay_between_attempts &&
279 delay_between_attempts - elapsed_time > next_attempt_delay_) { 279 delay_between_attempts - elapsed_time > next_attempt_delay_) {
280 next_attempt_delay_ = delay_between_attempts - elapsed_time; 280 next_attempt_delay_ = delay_between_attempts - elapsed_time;
281 } 281 }
282 } else { 282 } else {
283 detection_start_time_ = GetCurrentTimeTicks(); 283 detection_start_time_ = GetCurrentTimeTicks();
284 } 284 }
285 detection_task_.Reset( 285 detection_task_.Reset(
286 base::Bind(&NetworkPortalDetectorImpl::DetectCaptivePortalTask, 286 base::Bind(&NetworkPortalDetectorImpl::DetectCaptivePortalTask,
287 weak_ptr_factory_.GetWeakPtr())); 287 weak_ptr_factory_.GetWeakPtr()));
288 MessageLoop::current()->PostDelayedTask(FROM_HERE, 288 base::MessageLoop::current()->PostDelayedTask(
289 detection_task_.callback(), 289 FROM_HERE, detection_task_.callback(), next_attempt_delay_);
290 next_attempt_delay_);
291 } 290 }
292 291
293 void NetworkPortalDetectorImpl::DetectCaptivePortalTask() { 292 void NetworkPortalDetectorImpl::DetectCaptivePortalTask() {
294 DCHECK(IsPortalCheckPending()); 293 DCHECK(IsPortalCheckPending());
295 294
296 state_ = STATE_CHECKING_FOR_PORTAL; 295 state_ = STATE_CHECKING_FOR_PORTAL;
297 attempt_start_time_ = GetCurrentTimeTicks(); 296 attempt_start_time_ = GetCurrentTimeTicks();
298 297
299 if (attempt_count_ < kMaxRequestAttempts) { 298 if (attempt_count_ < kMaxRequestAttempts) {
300 ++attempt_count_; 299 ++attempt_count_;
(...skipping 13 matching lines...) Expand all
314 base::Bind(&NetworkPortalDetectorImpl::PortalDetectionTimeout, 313 base::Bind(&NetworkPortalDetectorImpl::PortalDetectionTimeout,
315 weak_ptr_factory_.GetWeakPtr())); 314 weak_ptr_factory_.GetWeakPtr()));
316 base::TimeDelta request_timeout; 315 base::TimeDelta request_timeout;
317 316
318 // For easier unit testing check for testing state is performed here 317 // For easier unit testing check for testing state is performed here
319 // and not in the GetRequestTimeoutSec(). 318 // and not in the GetRequestTimeoutSec().
320 if (request_timeout_for_testing_initialized_) 319 if (request_timeout_for_testing_initialized_)
321 request_timeout = request_timeout_for_testing_; 320 request_timeout = request_timeout_for_testing_;
322 else 321 else
323 request_timeout = base::TimeDelta::FromSeconds(GetRequestTimeoutSec()); 322 request_timeout = base::TimeDelta::FromSeconds(GetRequestTimeoutSec());
324 MessageLoop::current()->PostDelayedTask(FROM_HERE, 323 base::MessageLoop::current()->PostDelayedTask(
325 detection_timeout_.callback(), 324 FROM_HERE, detection_timeout_.callback(), request_timeout);
326 request_timeout);
327 } 325 }
328 326
329 void NetworkPortalDetectorImpl::PortalDetectionTimeout() { 327 void NetworkPortalDetectorImpl::PortalDetectionTimeout() {
330 DCHECK(CalledOnValidThread()); 328 DCHECK(CalledOnValidThread());
331 DCHECK(IsCheckingForPortal()); 329 DCHECK(IsCheckingForPortal());
332 330
333 VLOG(1) << "Portal detection timeout: network=" << default_network_id_; 331 VLOG(1) << "Portal detection timeout: network=" << default_network_id_;
334 332
335 captive_portal_detector_->Cancel(); 333 captive_portal_detector_->Cancel();
336 CaptivePortalDetector::Results results; 334 CaptivePortalDetector::Results results;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 DCHECK_LE(0, attempt_count_); 480 DCHECK_LE(0, attempt_count_);
483 const NetworkState* network = NetworkStateHandler::Get()->DefaultNetwork(); 481 const NetworkState* network = NetworkStateHandler::Get()->DefaultNetwork();
484 if (!network) 482 if (!network)
485 return kBaseRequestTimeoutSec; 483 return kBaseRequestTimeoutSec;
486 if (lazy_detection_enabled_) 484 if (lazy_detection_enabled_)
487 return kLazyRequestTimeoutSec; 485 return kLazyRequestTimeoutSec;
488 return attempt_count_ * kBaseRequestTimeoutSec; 486 return attempt_count_ * kBaseRequestTimeoutSec;
489 } 487 }
490 488
491 } // namespace chromeos 489 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698