OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_ | 5 #ifndef CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_ |
6 #define CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_ | 6 #define CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "content/browser/geolocation/device_data_provider.h" | 12 #include "content/browser/geolocation/device_data_provider.h" |
13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
14 #include "content/public/common/url_fetcher_delegate.h" | |
15 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
16 | 15 #include "net/url_request/url_fetcher_delegate.h" |
17 class URLFetcher; | |
18 | 16 |
19 namespace content { | 17 namespace content { |
20 struct Geoposition; | 18 struct Geoposition; |
| 19 class URLFetcher; |
21 } | 20 } |
22 | 21 |
23 namespace net { | 22 namespace net { |
24 class URLRequestContextGetter; | 23 class URLRequestContextGetter; |
25 } | 24 } |
26 | 25 |
27 // Takes a set of device data and sends it to a server to get a position fix. | 26 // Takes a set of device data and sends it to a server to get a position fix. |
28 // It performs formatting of the request and interpretation of the response. | 27 // It performs formatting of the request and interpretation of the response. |
29 class NetworkLocationRequest : private content::URLFetcherDelegate { | 28 class NetworkLocationRequest : private net::URLFetcherDelegate { |
30 public: | 29 public: |
31 // ID passed to URLFetcher::Create(). Used for testing. | 30 // ID passed to URLFetcher::Create(). Used for testing. |
32 CONTENT_EXPORT static int url_fetcher_id_for_tests; | 31 CONTENT_EXPORT static int url_fetcher_id_for_tests; |
33 // Interface for receiving callbacks from a NetworkLocationRequest object. | 32 // Interface for receiving callbacks from a NetworkLocationRequest object. |
34 class ListenerInterface { | 33 class ListenerInterface { |
35 public: | 34 public: |
36 // Updates the listener with a new position. server_error indicates whether | 35 // Updates the listener with a new position. server_error indicates whether |
37 // was a server or network error - either no response or a 500 error code. | 36 // was a server or network error - either no response or a 500 error code. |
38 virtual void LocationResponseAvailable( | 37 virtual void LocationResponseAvailable( |
39 const content::Geoposition& position, | 38 const content::Geoposition& position, |
(...skipping 16 matching lines...) Expand all Loading... |
56 // started. In all cases, any currently pending request will be canceled. | 55 // started. In all cases, any currently pending request will be canceled. |
57 bool MakeRequest(const string16& access_token, | 56 bool MakeRequest(const string16& access_token, |
58 const RadioData& radio_data, | 57 const RadioData& radio_data, |
59 const WifiData& wifi_data, | 58 const WifiData& wifi_data, |
60 const base::Time& timestamp); | 59 const base::Time& timestamp); |
61 | 60 |
62 bool is_request_pending() const { return url_fetcher_ != NULL; } | 61 bool is_request_pending() const { return url_fetcher_ != NULL; } |
63 const GURL& url() const { return url_; } | 62 const GURL& url() const { return url_; } |
64 | 63 |
65 private: | 64 private: |
66 // content::URLFetcherDelegate | 65 // net::URLFetcherDelegate |
67 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 66 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
68 | 67 |
69 scoped_refptr<net::URLRequestContextGetter> url_context_; | 68 scoped_refptr<net::URLRequestContextGetter> url_context_; |
70 ListenerInterface* listener_; | 69 ListenerInterface* listener_; |
71 const GURL url_; | 70 const GURL url_; |
72 scoped_ptr<content::URLFetcher> url_fetcher_; | 71 scoped_ptr<content::URLFetcher> url_fetcher_; |
73 | 72 |
74 // Keep a copy of the data sent in the request, so we can refer back to it | 73 // Keep a copy of the data sent in the request, so we can refer back to it |
75 // when the response arrives. | 74 // when the response arrives. |
76 RadioData radio_data_; | 75 RadioData radio_data_; |
77 WifiData wifi_data_; | 76 WifiData wifi_data_; |
78 base::Time timestamp_; // Timestamp of the above data, not of the request. | 77 base::Time timestamp_; // Timestamp of the above data, not of the request. |
79 | 78 |
80 DISALLOW_COPY_AND_ASSIGN(NetworkLocationRequest); | 79 DISALLOW_COPY_AND_ASSIGN(NetworkLocationRequest); |
81 }; | 80 }; |
82 | 81 |
83 #endif // CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_ | 82 #endif // CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_ |
OLD | NEW |