#ifndef CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_STRATEGY_H_
#define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_STRATEGY_H_
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
namespace chromeos {
class PortalDetectorStrategy {
public:
enum StrategyId {
STRATEGY_ID_LOGIN_SCREEN,
STRATEGY_ID_ERROR_SCREEN,
STRATEGY_ID_SESSION,
};
class Delegate {
public:
virtual ~Delegate() {}
virtual int AttemptCount() = 0;
virtual base::TimeTicks AttemptStartTime() = 0;
virtual base::TimeTicks GetCurrentTimeTicks() = 0;
};
virtual ~PortalDetectorStrategy();
static scoped_ptr<PortalDetectorStrategy> CreateById(StrategyId id);
void set_delegate(Delegate* delegate) { delegate_ = delegate; }
bool CanPerformAttempt();
bool CanPerformAttemptAfterDetection();
base::TimeDelta GetDelayTillNextAttempt();
base::TimeDelta GetNextAttemptTimeout();
virtual StrategyId Id() const = 0;
protected:
PortalDetectorStrategy();
virtual bool CanPerformAttemptImpl();
virtual bool CanPerformAttemptAfterDetectionImpl();
virtual base::TimeDelta GetDelayTillNextAttemptImpl();
virtual base::TimeDelta GetNextAttemptTimeoutImpl();
base::TimeDelta AdjustDelay(const base::TimeDelta& delay);
Delegate* delegate_;
private:
friend class NetworkPortalDetectorImplTest;
friend class NetworkPortalDetectorImplBrowserTest;
static void set_delay_till_next_attempt_for_testing(
const base::TimeDelta& timeout) {
delay_till_next_attempt_for_testing_ = timeout;
delay_till_next_attempt_for_testing_initialized_ = true;
}
static void set_next_attempt_timeout_for_testing(
const base::TimeDelta& timeout) {
next_attempt_timeout_for_testing_ = timeout;
next_attempt_timeout_for_testing_initialized_ = true;
}
static void reset_fields_for_testing() {
delay_till_next_attempt_for_testing_initialized_ = false;
next_attempt_timeout_for_testing_initialized_ = false;
}
static base::TimeDelta delay_till_next_attempt_for_testing_;
static bool delay_till_next_attempt_for_testing_initialized_;
static base::TimeDelta next_attempt_timeout_for_testing_;
static bool next_attempt_timeout_for_testing_initialized_;
DISALLOW_COPY_AND_ASSIGN(PortalDetectorStrategy);
};
}
#endif