blob: 91340b59ced097cfc0fddb52e262aed819cf36ea [file] [log] [blame]
[email protected]72660d92014-03-24 02:25:261// 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
satorux07e690912014-12-16 08:29:535#ifndef CHROMEOS_TIMEZONE_TIMEZONE_PROVIDER_H_
6#define CHROMEOS_TIMEZONE_TIMEZONE_PROVIDER_H_
[email protected]72660d92014-03-24 02:25:267
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"
satorux07e690912014-12-16 08:29:5315#include "chromeos/timezone/timezone_request.h"
[email protected]72660d92014-03-24 02:25:2616#include "url/gurl.h"
17
18namespace net {
19class URLRequestContextGetter;
20}
21
[email protected]72660d92014-03-24 02:25:2622namespace chromeos {
23
[email protected]9e844cf2014-04-19 02:36:0124struct Geoposition;
25
[email protected]72660d92014-03-24 02:25:2626// This class implements Google TimeZone API.
27//
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.
satorux07e690912014-12-16 08:29:5330class CHROMEOS_EXPORT TimeZoneProvider {
[email protected]72660d92014-03-24 02:25:2631 public:
32 TimeZoneProvider(net::URLRequestContextGetter* url_context_getter,
33 const GURL& url);
34 virtual ~TimeZoneProvider();
35
36 // Initiates new request (See TimeZoneRequest for parameters description.)
[email protected]9e844cf2014-04-19 02:36:0137 void RequestTimezone(const Geoposition& position,
[email protected]72660d92014-03-24 02:25:2638 base::TimeDelta timeout,
39 TimeZoneRequest::TimeZoneResponseCallback callback);
40
41 private:
[email protected]56d77552014-05-22 05:51:5142 friend class TestTimeZoneAPIURLFetcherCallback;
43
[email protected]72660d92014-03-24 02:25:2644 // Deletes request from requests_.
45 void OnTimezoneResponse(TimeZoneRequest* request,
46 TimeZoneRequest::TimeZoneResponseCallback callback,
47 scoped_ptr<TimeZoneResponseData> timezone,
48 bool server_error);
49
50 scoped_refptr<net::URLRequestContextGetter> url_context_getter_;
51 const GURL url_;
52
53 // Requests in progress.
54 // TimeZoneProvider owns all requests, so this vector is deleted on destroy.
55 ScopedVector<TimeZoneRequest> requests_;
56
57 // Creation and destruction should happen on the same thread.
58 base::ThreadChecker thread_checker_;
59
60 DISALLOW_COPY_AND_ASSIGN(TimeZoneProvider);
61};
62
63} // namespace chromeos
64
satorux07e690912014-12-16 08:29:5365#endif // CHROMEOS_TIMEZONE_TIMEZONE_PROVIDER_H_