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_
11 #include "base/component_export.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/threading/thread_checker.h"
16 #include "base/time/time.h"
17 #include "chromeos/timezone/timezone_request.h"
21 class SharedURLLoaderFactory;
28 // This class implements Google TimeZone API.
30 // Note: this should probably be a singleton to monitor requests rate.
31 // But as it is used only from WizardController, it can be owned by it for now.
32 class COMPONENT_EXPORT(CHROMEOS_TIMEZONE) TimeZoneProvider {
34 TimeZoneProvider(scoped_refptr<network::SharedURLLoaderFactory> factory,
36 virtual ~TimeZoneProvider();
38 // Initiates new request (See TimeZoneRequest for parameters description.)
39 void RequestTimezone(const Geoposition& position,
40 base::TimeDelta timeout,
41 TimeZoneRequest::TimeZoneResponseCallback callback);
44 friend class TestTimeZoneAPILoaderFactory;
46 // Deletes request from requests_.
47 void OnTimezoneResponse(TimeZoneRequest* request,
48 TimeZoneRequest::TimeZoneResponseCallback callback,
49 std::unique_ptr<TimeZoneResponseData> timezone,
52 scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory_;
55 // Requests in progress.
56 // TimeZoneProvider owns all requests, so this vector is deleted on destroy.
57 std::vector<std::unique_ptr<TimeZoneRequest>> requests_;
59 // Creation and destruction should happen on the same thread.
60 base::ThreadChecker thread_checker_;
62 DISALLOW_COPY_AND_ASSIGN(TimeZoneProvider);
65 } // namespace chromeos
67 #endif // CHROMEOS_TIMEZONE_TIMEZONE_PROVIDER_H_