#include "base/observer_list.h"
#include "base/threading/non_thread_safe.h"
#include "base/time/time.h"
-#include "chrome/browser/captive_portal/captive_portal_detector.h"
-#include "chrome/browser/chromeos/net/network_portal_detector.h"
-#include "chrome/browser/chromeos/net/network_portal_detector_strategy.h"
#include "chrome/browser/chromeos/net/network_portal_notification_controller.h"
#include "chromeos/network/network_state_handler_observer.h"
+#include "chromeos/network/portal_detector/network_portal_detector.h"
+#include "chromeos/network/portal_detector/network_portal_detector_strategy.h"
+#include "components/captive_portal/captive_portal_detector.h"
+#include "components/captive_portal/captive_portal_types.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "net/url_request/url_fetcher.h"
static const char kOobeShillOnlineHistogram[];
static const char kOobeShillPortalHistogram[];
static const char kOobeShillOfflineHistogram[];
+ static const char kOobePortalToOnlineHistogram[];
static const char kSessionDetectionResultHistogram[];
static const char kSessionDetectionDurationHistogram[];
static const char kSessionShillOnlineHistogram[];
static const char kSessionShillPortalHistogram[];
static const char kSessionShillOfflineHistogram[];
+ static const char kSessionPortalToOnlineHistogram[];
+
+ // Creates an instance of NetworkPortalDetectorImpl.
+ static void Initialize(net::URLRequestContextGetter* url_context);
explicit NetworkPortalDetectorImpl(
const scoped_refptr<net::URLRequestContextGetter>& request_context);
virtual ~NetworkPortalDetectorImpl();
// NetworkPortalDetector implementation:
- virtual void AddObserver(Observer* observer) OVERRIDE;
- virtual void AddAndFireObserver(Observer* observer) OVERRIDE;
- virtual void RemoveObserver(Observer* observer) OVERRIDE;
+ virtual void AddObserver(Observer* observer) override;
+ virtual void AddAndFireObserver(Observer* observer) override;
+ virtual void RemoveObserver(Observer* observer) override;
virtual CaptivePortalState GetCaptivePortalState(
- const std::string& service_path) OVERRIDE;
- virtual bool IsEnabled() OVERRIDE;
- virtual void Enable(bool start_detection) OVERRIDE;
- virtual bool StartDetectionIfIdle() OVERRIDE;
+ const std::string& guid) override;
+ virtual bool IsEnabled() override;
+ virtual void Enable(bool start_detection) override;
+ virtual bool StartDetectionIfIdle() override;
+ virtual void SetStrategy(PortalDetectorStrategy::StrategyId id) override;
// NetworkStateHandlerObserver implementation:
- virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE;
+ virtual void DefaultNetworkChanged(const NetworkState* network) override;
// PortalDetectorStrategy::Delegate implementation:
- virtual int AttemptCount() OVERRIDE;
- virtual base::TimeTicks AttemptStartTime() OVERRIDE;
- virtual base::TimeTicks GetCurrentTimeTicks() OVERRIDE;
-
- // ErrorScreen::Observer implementation:
- virtual void OnErrorScreenShow() OVERRIDE;
- virtual void OnErrorScreenHide() OVERRIDE;
+ virtual int NoResponseResultCount() override;
+ virtual base::TimeTicks AttemptStartTime() override;
+ virtual base::TimeTicks GetCurrentTimeTicks() override;
private:
friend class NetworkPortalDetectorImplTest;
friend class NetworkPortalDetectorImplBrowserTest;
+ struct DetectionAttemptCompletedReport {
+ DetectionAttemptCompletedReport();
+
+ DetectionAttemptCompletedReport(const std::string network_name,
+ const std::string network_id,
+ captive_portal::CaptivePortalResult result,
+ int response_code);
+
+ void Report() const;
+
+ bool Equals(const DetectionAttemptCompletedReport& o) const;
+
+ std::string network_name;
+ std::string network_id;
+ captive_portal::CaptivePortalResult result;
+ int response_code;
+ };
+
typedef std::string NetworkId;
typedef base::hash_map<NetworkId, CaptivePortalState> CaptivePortalStateMap;
// Stops whole detection process.
void StopDetection();
- // Internal predicate which describes set of states from which
- // DetectCaptivePortal() can be called.
- bool CanPerformAttempt() const;
-
// Initiates Captive Portal detection attempt after |delay|.
- // You should check CanPerformAttempt() before calling this method.
void ScheduleAttempt(const base::TimeDelta& delay);
// Starts detection attempt.
// content::NotificationObserver implementation:
virtual void Observe(int type,
const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE;
+ const content::NotificationDetails& details) override;
// Stores captive portal state for a |network| and notifies observers.
void OnDetectionCompleted(const NetworkState* network,
void NotifyDetectionCompleted(const NetworkState* network,
const CaptivePortalState& state);
- // Updates current detection strategy according to the curren state:
- // error screen, login screen or user session.
- void UpdateCurrentStrategy();
-
- // Sets current strategy according to |id|. If current detection id
- // doesn't equal to |id|, detection is restarted.
- void SetStrategy(PortalDetectorStrategy::StrategyId id);
-
State state() const { return state_; }
bool is_idle() const {
return state_ == STATE_CHECKING_FOR_PORTAL;
}
- int attempt_count_for_testing() {
- return attempt_count_;
+ int same_detection_result_count_for_testing() const {
+ return same_detection_result_count_;
}
- void set_attempt_count_for_testing(int attempt_count) {
- attempt_count_ = attempt_count;
+ int no_response_result_count_for_testing() const {
+ return no_response_result_count_;
+ }
+
+ void set_no_response_result_count_for_testing(int count) {
+ no_response_result_count_ = count;
}
// Returns delay before next portal check. Used by unit tests.
void RecordDetectionStats(const NetworkState* network,
CaptivePortalStatus status);
+ // Resets strategy and all counters used in computations of
+ // timeouts.
+ void ResetStrategyAndCounters();
+
// Sets current test time ticks. Used by unit tests.
void set_time_ticks_for_testing(const base::TimeTicks& time_ticks) {
time_ticks_for_testing_ = time_ticks;
// Unique identifier of the default network.
std::string default_network_id_;
- // Service path of the default network.
- std::string default_service_path_;
-
// Connection state of the default network.
std::string default_connection_state_;
// True if the NetworkPortalDetector is enabled.
bool enabled_;
- base::WeakPtrFactory<NetworkPortalDetectorImpl> weak_factory_;
-
// Start time of portal detection.
base::TimeTicks detection_start_time_;
// Start time of detection attempt.
base::TimeTicks attempt_start_time_;
- // Number of already performed detection attempts.
- int attempt_count_;
-
// Delay before next portal detection.
base::TimeDelta next_attempt_delay_;
// Current detection strategy.
scoped_ptr<PortalDetectorStrategy> strategy_;
- // True when error screen is displayed.
- bool error_screen_displayed_;
+ // Last received result from captive portal detector.
+ CaptivePortalStatus last_detection_result_;
+
+ // Number of detection attempts with same result in a row.
+ int same_detection_result_count_;
+
+ // Number of detection attempts in a row with NO RESPONSE result.
+ int no_response_result_count_;
// UI notification controller about captive portal state.
NetworkPortalNotificationController notification_controller_;
// Test time ticks used by unit tests.
base::TimeTicks time_ticks_for_testing_;
+ // Contents of a last log message about completed detection attempt.
+ DetectionAttemptCompletedReport attempt_completed_report_;
+
+ base::WeakPtrFactory<NetworkPortalDetectorImpl> weak_factory_;
+
DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetectorImpl);
};