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 CHROMEOS_TIMEZONE_TIMEZONE_PROVIDER_H_
6 #define 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 "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 CHROMEOS_EXPORT 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
,
38 base::TimeDelta timeout
,
39 TimeZoneRequest::TimeZoneResponseCallback callback
);
42 friend class TestTimeZoneAPIURLFetcherCallback
;
44 // Deletes request from requests_.
45 void OnTimezoneResponse(TimeZoneRequest
* request
,
46 TimeZoneRequest::TimeZoneResponseCallback callback
,
47 scoped_ptr
<TimeZoneResponseData
> timezone
,
50 scoped_refptr
<net::URLRequestContextGetter
> url_context_getter_
;
53 // Requests in progress.
54 // TimeZoneProvider owns all requests, so this vector is deleted on destroy.
55 ScopedVector
<TimeZoneRequest
> requests_
;
57 // Creation and destruction should happen on the same thread.
58 base::ThreadChecker thread_checker_
;
60 DISALLOW_COPY_AND_ASSIGN(TimeZoneProvider
);
63 } // namespace chromeos
65 #endif // CHROMEOS_TIMEZONE_TIMEZONE_PROVIDER_H_