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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_
6 #define CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "content/browser/geolocation/device_data_provider.h"
12 #include "content/common/content_export.h"
13 #include "googleurl/src/gurl.h"
14 #include "net/url_request/url_fetcher_delegate.h"
18 class URLRequestContextGetter
;
24 // Takes a set of device data and sends it to a server to get a position fix.
25 // It performs formatting of the request and interpretation of the response.
26 class NetworkLocationRequest
: private net::URLFetcherDelegate
{
28 // ID passed to URLFetcher::Create(). Used for testing.
29 CONTENT_EXPORT
static int url_fetcher_id_for_tests
;
30 // Interface for receiving callbacks from a NetworkLocationRequest object.
31 class ListenerInterface
{
33 // Updates the listener with a new position. server_error indicates whether
34 // was a server or network error - either no response or a 500 error code.
35 virtual void LocationResponseAvailable(
36 const Geoposition
& position
,
38 const string16
& access_token
,
39 const WifiData
& wifi_data
) = 0;
42 virtual ~ListenerInterface() {}
45 // |url| is the server address to which the request wil be sent.
46 NetworkLocationRequest(net::URLRequestContextGetter
* context
,
48 ListenerInterface
* listener
);
49 virtual ~NetworkLocationRequest();
51 // Makes a new request. Returns true if the new request was successfully
52 // started. In all cases, any currently pending request will be canceled.
53 bool MakeRequest(const string16
& access_token
,
54 const WifiData
& wifi_data
,
55 const base::Time
& timestamp
);
57 bool is_request_pending() const { return url_fetcher_
!= NULL
; }
58 const GURL
& url() const { return url_
; }
61 // net::URLFetcherDelegate
62 virtual void OnURLFetchComplete(const net::URLFetcher
* source
) OVERRIDE
;
64 scoped_refptr
<net::URLRequestContextGetter
> url_context_
;
65 ListenerInterface
* listener_
;
67 scoped_ptr
<net::URLFetcher
> url_fetcher_
;
69 // Keep a copy of the data sent in the request, so we can refer back to it
70 // when the response arrives.
72 base::Time timestamp_
; // Timestamp of the above data, not of the request.
74 // The start time for the request.
75 base::TimeTicks start_time_
;
77 DISALLOW_COPY_AND_ASSIGN(NetworkLocationRequest
);
80 } // namespace content
82 #endif // CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_