#ifndef CHROME_BROWSER_CHROMEOS_TIMEZONE_TIMEZONE_REQUEST_H_
#define CHROME_BROWSER_CHROMEOS_TIMEZONE_TIMEZONE_REQUEST_H_
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/thread_checker.h"
#include "base/timer/timer.h"
#include "content/public/common/geoposition.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "url/gurl.h"
namespace net {
class URLRequestContextGetter;
}
namespace chromeos {
struct TimeZoneResponseData {
enum Status {
OK,
INVALID_REQUEST,
OVER_QUERY_LIMIT,
REQUEST_DENIED,
UNKNOWN_ERROR,
ZERO_RESULTS,
REQUEST_ERROR
};
TimeZoneResponseData();
std::string ToStringForDebug() const;
double dstOffset;
double rawOffset;
std::string timeZoneId;
std::string timeZoneName;
std::string error_message;
Status status;
};
GURL DefaultTimezoneProviderURL();
class TimeZoneRequest : private net::URLFetcherDelegate {
public:
typedef base::Callback<void(scoped_ptr<TimeZoneResponseData> ,
bool )>
TimeZoneResponseCallback;
TimeZoneRequest(net::URLRequestContextGetter* url_context_getter,
const GURL& service_url,
const content::Geoposition& geoposition,
bool sensor,
base::TimeDelta retry_timeout);
virtual ~TimeZoneRequest();
void MakeRequest(TimeZoneResponseCallback callback);
private:
virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
void StartRequest();
void Retry(bool server_error);
scoped_refptr<net::URLRequestContextGetter> url_context_getter_;
const GURL service_url_;
content::Geoposition geoposition_;
const bool sensor_;
TimeZoneResponseCallback callback_;
GURL request_url_;
scoped_ptr<net::URLFetcher> url_fetcher_;
base::Time request_started_at_;
base::Time retry_timeout_abs_;
base::OneShotTimer<TimeZoneRequest> timezone_request_scheduled_;
unsigned retries_;
base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(TimeZoneRequest);
};
}
#endif