Upload upstream chromium 85.0.4183.93
[platform/framework/web/chromium-efl.git] / chromeos / timezone / timezone_provider.h
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.
4
5 #ifndef CHROMEOS_TIMEZONE_TIMEZONE_PROVIDER_H_
6 #define CHROMEOS_TIMEZONE_TIMEZONE_PROVIDER_H_
7
8 #include <memory>
9 #include <vector>
10
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"
18 #include "url/gurl.h"
19
20 namespace network {
21 class SharedURLLoaderFactory;
22 }
23
24 namespace chromeos {
25
26 struct Geoposition;
27
28 // This class implements Google TimeZone API.
29 //
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 {
33  public:
34   TimeZoneProvider(scoped_refptr<network::SharedURLLoaderFactory> factory,
35                    const GURL& url);
36   virtual ~TimeZoneProvider();
37
38   // Initiates new request (See TimeZoneRequest for parameters description.)
39   void RequestTimezone(const Geoposition& position,
40                        base::TimeDelta timeout,
41                        TimeZoneRequest::TimeZoneResponseCallback callback);
42
43  private:
44   friend class TestTimeZoneAPILoaderFactory;
45
46   // Deletes request from requests_.
47   void OnTimezoneResponse(TimeZoneRequest* request,
48                           TimeZoneRequest::TimeZoneResponseCallback callback,
49                           std::unique_ptr<TimeZoneResponseData> timezone,
50                           bool server_error);
51
52   scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory_;
53   const GURL url_;
54
55   // Requests in progress.
56   // TimeZoneProvider owns all requests, so this vector is deleted on destroy.
57   std::vector<std::unique_ptr<TimeZoneRequest>> requests_;
58
59   // Creation and destruction should happen on the same thread.
60   base::ThreadChecker thread_checker_;
61
62   DISALLOW_COPY_AND_ASSIGN(TimeZoneProvider);
63 };
64
65 }  // namespace chromeos
66
67 #endif  // CHROMEOS_TIMEZONE_TIMEZONE_PROVIDER_H_