OLD | NEW |
| (Empty) |
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 CHROME_BROWSER_CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_PROVIDER_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_PROVIDER_H_ | |
7 | |
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 "chrome/browser/chromeos/geolocation/simple_geolocation_request.h" | |
14 #include "url/gurl.h" | |
15 | |
16 namespace net { | |
17 class URLRequestContextGetter; | |
18 } | |
19 | |
20 namespace chromeos { | |
21 | |
22 // This class implements Google Maps Geolocation API. | |
23 // | |
24 // SimpleGeolocationProvider must be created and used on the same thread. | |
25 // | |
26 // Note: this should probably be a singleton to monitor requests rate. | |
27 // But as it is used only diring ChromeOS Out-of-Box, it can be owned by | |
28 // WizardController for now. | |
29 class SimpleGeolocationProvider { | |
30 public: | |
31 SimpleGeolocationProvider(net::URLRequestContextGetter* url_context_getter, | |
32 const GURL& url); | |
33 virtual ~SimpleGeolocationProvider(); | |
34 | |
35 // Initiates new request (See SimpleGeolocationRequest for parameters | |
36 // description.) | |
37 void RequestGeolocation(base::TimeDelta timeout, | |
38 SimpleGeolocationRequest::ResponseCallback callback); | |
39 | |
40 // Returns default geolocation service URL. | |
41 static GURL DefaultGeolocationProviderURL(); | |
42 | |
43 private: | |
44 friend class TestGeolocationAPIURLFetcherCallback; | |
45 | |
46 // Geolocation response callback. Deletes request from requests_. | |
47 void OnGeolocationResponse( | |
48 SimpleGeolocationRequest* request, | |
49 SimpleGeolocationRequest::ResponseCallback callback, | |
50 const Geoposition& geoposition, | |
51 bool server_error, | |
52 const base::TimeDelta elapsed); | |
53 | |
54 scoped_refptr<net::URLRequestContextGetter> url_context_getter_; | |
55 | |
56 // URL of the Google Maps Geolocation API. | |
57 const GURL url_; | |
58 | |
59 // Requests in progress. | |
60 // SimpleGeolocationProvider owns all requests, so this vector is deleted on | |
61 // destroy. | |
62 ScopedVector<SimpleGeolocationRequest> requests_; | |
63 | |
64 // Creation and destruction should happen on the same thread. | |
65 base::ThreadChecker thread_checker_; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(SimpleGeolocationProvider); | |
68 }; | |
69 | |
70 } // namespace chromeos | |
71 | |
72 #endif // CHROME_BROWSER_CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_PROVIDER_H_ | |
OLD | NEW |