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

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

Issue 99223009: Fixed current OOBE captive portal metrics. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix. Created 6 years, 11 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/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 21 matching lines...) Expand all
32 // Minimum timeout between consecutive portal checks for the same 32 // Minimum timeout between consecutive portal checks for the same
33 // network. 33 // network.
34 const int kMinTimeBetweenAttemptsSec = 3; 34 const int kMinTimeBetweenAttemptsSec = 3;
35 35
36 // Delay before portal detection caused by changes in proxy settings. 36 // Delay before portal detection caused by changes in proxy settings.
37 const int kProxyChangeDelaySec = 1; 37 const int kProxyChangeDelaySec = 1;
38 38
39 // Delay between consecutive portal checks for a network in lazy mode. 39 // Delay between consecutive portal checks for a network in lazy mode.
40 const int kLazyCheckIntervalSec = 5; 40 const int kLazyCheckIntervalSec = 5;
41 41
42 const char kCaptivePortalStatusUnknown[] = "Unknown"; 42 void RecordDiscrepancyWithShill(
43 const char kCaptivePortalStatusOffline[] = "Offline"; 43 const NetworkState* network,
44 const char kCaptivePortalStatusOnline[] = "Online"; 44 const NetworkPortalDetector::CaptivePortalStatus status) {
45 const char kCaptivePortalStatusPortal[] = "Portal"; 45 if (network->connection_state() == shill::kStateOnline) {
46 const char kCaptivePortalStatusProxyAuthRequired[] = 46 UMA_HISTOGRAM_ENUMERATION(
47 "Proxy authentication required"; 47 NetworkPortalDetectorImpl::kShillOnlineHistogram,
48 const char kCaptivePortalStatusUnrecognized[] = "Unrecognized"; 48 status,
49 49 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT);
50 std::string CaptivePortalStatusString( 50 } else if (network->connection_state() == shill::kStatePortal) {
51 NetworkPortalDetectorImpl::CaptivePortalStatus status) { 51 UMA_HISTOGRAM_ENUMERATION(
52 switch (status) { 52 NetworkPortalDetectorImpl::kShillPortalHistogram,
53 case NetworkPortalDetectorImpl::CAPTIVE_PORTAL_STATUS_UNKNOWN: 53 status,
54 return kCaptivePortalStatusUnknown; 54 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT);
55 case NetworkPortalDetectorImpl::CAPTIVE_PORTAL_STATUS_OFFLINE: 55 } else if (network->connection_state() == shill::kStateOffline) {
56 return kCaptivePortalStatusOffline; 56 UMA_HISTOGRAM_ENUMERATION(
57 case NetworkPortalDetectorImpl::CAPTIVE_PORTAL_STATUS_ONLINE: 57 NetworkPortalDetectorImpl::kShillOfflineHistogram,
58 return kCaptivePortalStatusOnline; 58 status,
59 case NetworkPortalDetectorImpl::CAPTIVE_PORTAL_STATUS_PORTAL: 59 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT);
60 return kCaptivePortalStatusPortal;
61 case NetworkPortalDetectorImpl::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED:
62 return kCaptivePortalStatusProxyAuthRequired;
63 case NetworkPortalDetectorImpl::CAPTIVE_PORTAL_STATUS_COUNT:
64 NOTREACHED();
65 } 60 }
66 return kCaptivePortalStatusUnrecognized;
67 } 61 }
68 62
69 } // namespace 63 } // namespace
70 64
71 //////////////////////////////////////////////////////////////////////////////// 65 ////////////////////////////////////////////////////////////////////////////////
72 // NetworkPortalDetectorImpl, public: 66 // NetworkPortalDetectorImpl, public:
73 67
68 const char NetworkPortalDetectorImpl::kDetectionResultHistogram[] =
69 "CaptivePortal.OOBE.DetectionResult";
70 const char NetworkPortalDetectorImpl::kDetectionDurationHistogram[] =
71 "CaptivePortal.OOBE.DetectionDuration";
72 const char NetworkPortalDetectorImpl::kShillOnlineHistogram[] =
73 "CaptivePortal.OOBE.DiscrepancyWithShill_Online";
74 const char NetworkPortalDetectorImpl::kShillPortalHistogram[] =
75 "CaptivePortal.OOBE.DiscrepancyWithShill_RestrictedPool";
76 const char NetworkPortalDetectorImpl::kShillOfflineHistogram[] =
77 "CaptivePortal.OOBE.DiscrepancyWithShill_Offline";
78
74 NetworkPortalDetectorImpl::NetworkPortalDetectorImpl( 79 NetworkPortalDetectorImpl::NetworkPortalDetectorImpl(
75 const scoped_refptr<net::URLRequestContextGetter>& request_context) 80 const scoped_refptr<net::URLRequestContextGetter>& request_context)
76 : state_(STATE_IDLE), 81 : state_(STATE_IDLE),
77 test_url_(CaptivePortalDetector::kDefaultURL), 82 test_url_(CaptivePortalDetector::kDefaultURL),
78 enabled_(false), 83 enabled_(false),
79 weak_ptr_factory_(this), 84 weak_ptr_factory_(this),
80 attempt_count_(0), 85 attempt_count_(0),
81 lazy_detection_enabled_(false), 86 lazy_detection_enabled_(false),
82 lazy_check_interval_(base::TimeDelta::FromSeconds(kLazyCheckIntervalSec)), 87 lazy_check_interval_(base::TimeDelta::FromSeconds(kLazyCheckIntervalSec)),
83 min_time_between_attempts_( 88 min_time_between_attempts_(
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 return state_ == STATE_PORTAL_CHECK_PENDING; 450 return state_ == STATE_PORTAL_CHECK_PENDING;
446 } 451 }
447 452
448 bool NetworkPortalDetectorImpl::IsCheckingForPortal() const { 453 bool NetworkPortalDetectorImpl::IsCheckingForPortal() const {
449 return state_ == STATE_CHECKING_FOR_PORTAL; 454 return state_ == STATE_CHECKING_FOR_PORTAL;
450 } 455 }
451 456
452 void NetworkPortalDetectorImpl::SetCaptivePortalState( 457 void NetworkPortalDetectorImpl::SetCaptivePortalState(
453 const NetworkState* network, 458 const NetworkState* network,
454 const CaptivePortalState& state) { 459 const CaptivePortalState& state) {
455 if (!detection_start_time_.is_null()) {
456 UMA_HISTOGRAM_TIMES("CaptivePortal.OOBE.DetectionDuration",
457 GetCurrentTimeTicks() - detection_start_time_);
458 }
459
460 if (!network) { 460 if (!network) {
461 NotifyPortalDetectionCompleted(network, state); 461 NotifyPortalDetectionCompleted(network, state);
462 return; 462 return;
463 } 463 }
464 464
465 CaptivePortalStateMap::const_iterator it = 465 CaptivePortalStateMap::const_iterator it =
466 portal_state_map_.find(network->path()); 466 portal_state_map_.find(network->path());
467 if (it == portal_state_map_.end() || 467 if (it == portal_state_map_.end() ||
468 it->second.status != state.status || 468 it->second.status != state.status ||
469 it->second.response_code != state.response_code) { 469 it->second.response_code != state.response_code) {
470 VLOG(1) << "Updating Chrome Captive Portal state: " 470 VLOG(1) << "Updating Chrome Captive Portal state: "
471 << "name=" << network->name() << ", " 471 << "name=" << network->name() << ", "
472 << "id=" << network->guid() << ", " 472 << "id=" << network->guid() << ", "
473 << "status=" << CaptivePortalStatusString(state.status) << ", " 473 << "status=" << CaptivePortalStatusString(state.status) << ", "
474 << "response_code=" << state.response_code; 474 << "response_code=" << state.response_code;
475
476 // Record detection duration iff detection result differs from the
477 // previous one for this network. The reason is to record all stats
478 // only when network changes it's state.
479 RecordDetectionStats(network, state.status);
480
475 portal_state_map_[network->path()] = state; 481 portal_state_map_[network->path()] = state;
476 } 482 }
477 NotifyPortalDetectionCompleted(network, state); 483 NotifyPortalDetectionCompleted(network, state);
478 } 484 }
479 485
480 void NetworkPortalDetectorImpl::NotifyPortalDetectionCompleted( 486 void NetworkPortalDetectorImpl::NotifyPortalDetectionCompleted(
481 const NetworkState* network, 487 const NetworkState* network,
482 const CaptivePortalState& state) { 488 const CaptivePortalState& state) {
483 FOR_EACH_OBSERVER(Observer, observers_, 489 FOR_EACH_OBSERVER(Observer, observers_,
484 OnPortalDetectionCompleted(network, state)); 490 OnPortalDetectionCompleted(network, state));
(...skipping 13 matching lines...) Expand all
498 DCHECK_LE(0, attempt_count_); 504 DCHECK_LE(0, attempt_count_);
499 const NetworkState* network = 505 const NetworkState* network =
500 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); 506 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
501 if (!network) 507 if (!network)
502 return kBaseRequestTimeoutSec; 508 return kBaseRequestTimeoutSec;
503 if (lazy_detection_enabled_) 509 if (lazy_detection_enabled_)
504 return kLazyRequestTimeoutSec; 510 return kLazyRequestTimeoutSec;
505 return attempt_count_ * kBaseRequestTimeoutSec; 511 return attempt_count_ * kBaseRequestTimeoutSec;
506 } 512 }
507 513
514 void NetworkPortalDetectorImpl::RecordDetectionStats(
515 const NetworkState* network,
516 CaptivePortalStatus status) {
517 // Don't record stats for offline state.
518 if (!network)
519 return;
520
521 if (!detection_start_time_.is_null()) {
522 UMA_HISTOGRAM_MEDIUM_TIMES(kDetectionDurationHistogram,
523 GetCurrentTimeTicks() - detection_start_time_);
524 }
525 UMA_HISTOGRAM_ENUMERATION(kDetectionResultHistogram,
526 status,
527 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT);
528 switch (status) {
529 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN:
530 NOTREACHED();
531 break;
532 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE:
533 if (network->connection_state() == shill::kStateOnline ||
534 network->connection_state() == shill::kStatePortal) {
535 RecordDiscrepancyWithShill(network, status);
536 }
537 break;
538 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE:
539 if (network->connection_state() != shill::kStateOnline)
540 RecordDiscrepancyWithShill(network, status);
541 break;
542 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL:
543 if (network->connection_state() != shill::kStatePortal)
544 RecordDiscrepancyWithShill(network, status);
545 break;
546 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED:
547 if (network->connection_state() != shill::kStateOnline)
548 RecordDiscrepancyWithShill(network, status);
549 break;
550 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT:
551 NOTREACHED();
552 break;
553 }
554 }
555
508 } // namespace chromeos 556 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698