1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_TIMEZONE_TIMEZONE_PROVIDER_H_
6 #define CHROME_BROWSER_CHROMEOS_TIMEZONE_TIMEZONE_PROVIDER_H_
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/scoped_vector.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/threading/thread_checker.h"
14 #include "base/time/time.h"
15 #include "chrome/browser/chromeos/timezone/timezone_request.h"
19 class URLRequestContextGetter
;
26 // This class implements Google TimeZone API.
28 // Note: this should probably be a singleton to monitor requests rate.
29 // But as it is used only from WizardController, it can be owned by it for now.
30 class TimeZoneProvider
{
32 TimeZoneProvider(net::URLRequestContextGetter
* url_context_getter
,
34 virtual ~TimeZoneProvider();
36 // Initiates new request (See TimeZoneRequest for parameters description.)
37 void RequestTimezone(const Geoposition
& position
,
39 base::TimeDelta timeout
,
40 TimeZoneRequest::TimeZoneResponseCallback callback
);
43 // Deletes request from requests_.
44 void OnTimezoneResponse(TimeZoneRequest
* request
,
45 TimeZoneRequest::TimeZoneResponseCallback callback
,
46 scoped_ptr
<TimeZoneResponseData
> timezone
,
49 scoped_refptr
<net::URLRequestContextGetter
> url_context_getter_
;
52 // Requests in progress.
53 // TimeZoneProvider owns all requests, so this vector is deleted on destroy.
54 ScopedVector
<TimeZoneRequest
> requests_
;
56 // Creation and destruction should happen on the same thread.
57 base::ThreadChecker thread_checker_
;
59 DISALLOW_COPY_AND_ASSIGN(TimeZoneProvider
);
62 } // namespace chromeos
64 #endif // CHROME_BROWSER_CHROMEOS_TIMEZONE_TIMEZONE_PROVIDER_H_