Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / content / browser / geolocation / network_location_request.h
blobf0734e00c25757e9b336e3fa7f14e85bd11be29a
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/wifi_data_provider.h"
12 #include "content/common/content_export.h"
13 #include "net/url_request/url_fetcher_delegate.h"
14 #include "url/gurl.h"
16 namespace net {
17 class URLFetcher;
18 class URLRequestContextGetter;
21 namespace content {
22 struct Geoposition;
24 // Takes wifi 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 {
27 public:
28 // ID passed to URLFetcher::Create(). Used for testing.
29 CONTENT_EXPORT static int url_fetcher_id_for_tests;
31 // Called when a new geo position is available. The second argument indicates
32 // whether there was a server error or not. It is true when there was a
33 // server or network error - either no response or a 500 error code.
34 typedef base::Callback<void(const Geoposition& /* position */,
35 bool /* server_error */,
36 const base::string16& /* access_token */,
37 const WifiData& /* wifi_data */)>
38 LocationResponseCallback;
40 // |url| is the server address to which the request wil be sent.
41 NetworkLocationRequest(net::URLRequestContextGetter* context,
42 const GURL& url,
43 LocationResponseCallback callback);
44 ~NetworkLocationRequest() override;
46 // Makes a new request. Returns true if the new request was successfully
47 // started. In all cases, any currently pending request will be canceled.
48 bool MakeRequest(const base::string16& access_token,
49 const WifiData& wifi_data,
50 const base::Time& timestamp);
52 bool is_request_pending() const { return url_fetcher_ != NULL; }
53 const GURL& url() const { return url_; }
55 private:
56 // net::URLFetcherDelegate
57 void OnURLFetchComplete(const net::URLFetcher* source) override;
59 scoped_refptr<net::URLRequestContextGetter> url_context_;
60 LocationResponseCallback location_response_callback_;
61 const GURL url_;
62 scoped_ptr<net::URLFetcher> url_fetcher_;
64 // Keep a copy of the data sent in the request, so we can refer back to it
65 // when the response arrives.
66 WifiData wifi_data_;
67 base::Time wifi_data_timestamp_;
69 // The start time for the request.
70 base::TimeTicks request_start_time_;
72 DISALLOW_COPY_AND_ASSIGN(NetworkLocationRequest);
75 } // namespace content
77 #endif // CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_