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_GEOLOCATION_SIMPLE_GEOLOCATION_PROVIDER_H_
6 #define CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_PROVIDER_H_
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_vector.h"
11 #include "base/threading/thread_checker.h"
12 #include "base/time/time.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/geolocation/simple_geolocation_request.h"
18 class URLRequestContextGetter
;
23 // This class implements Google Maps Geolocation API.
25 // SimpleGeolocationProvider must be created and used on the same thread.
27 // Note: this should probably be a singleton to monitor requests rate.
28 // But as it is used only diring ChromeOS Out-of-Box, it can be owned by
29 // WizardController for now.
30 class CHROMEOS_EXPORT SimpleGeolocationProvider
{
32 SimpleGeolocationProvider(net::URLRequestContextGetter
* url_context_getter
,
34 virtual ~SimpleGeolocationProvider();
36 // Initiates new request (See SimpleGeolocationRequest for parameters
38 void RequestGeolocation(base::TimeDelta timeout
,
39 SimpleGeolocationRequest::ResponseCallback callback
);
41 // Returns default geolocation service URL.
42 static GURL
DefaultGeolocationProviderURL();
45 friend class TestGeolocationAPIURLFetcherCallback
;
47 // Geolocation response callback. Deletes request from requests_.
48 void OnGeolocationResponse(
49 SimpleGeolocationRequest
* request
,
50 SimpleGeolocationRequest::ResponseCallback callback
,
51 const Geoposition
& geoposition
,
53 const base::TimeDelta elapsed
);
55 scoped_refptr
<net::URLRequestContextGetter
> url_context_getter_
;
57 // URL of the Google Maps Geolocation API.
60 // Requests in progress.
61 // SimpleGeolocationProvider owns all requests, so this vector is deleted on
63 ScopedVector
<SimpleGeolocationRequest
> requests_
;
65 // Creation and destruction should happen on the same thread.
66 base::ThreadChecker thread_checker_
;
68 DISALLOW_COPY_AND_ASSIGN(SimpleGeolocationProvider
);
71 } // namespace chromeos
73 #endif // CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_PROVIDER_H_