| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_ | |
| 6 #define CHROME_BROWSER_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/ref_counted.h" | |
| 12 #include "base/scoped_ptr.h" | |
| 13 #include "chrome/browser/geolocation/device_data_provider.h" | |
| 14 #include "chrome/common/net/url_fetcher.h" | |
| 15 #include "googleurl/src/gurl.h" | |
| 16 | |
| 17 class URLRequestContextGetter; | |
| 18 class URLFetcher; | |
| 19 struct Geoposition; | |
| 20 struct Position; | |
| 21 | |
| 22 // Takes a set of device data and sends it to a server to get a position fix. | |
| 23 // It performs formatting of the request and interpretation of the response. | |
| 24 class NetworkLocationRequest : private URLFetcher::Delegate { | |
| 25 public: | |
| 26 // ID passed to URLFetcher::Create(). Used for testing. | |
| 27 static int url_fetcher_id_for_tests; | |
| 28 // Interface for receiving callbacks from a NetworkLocationRequest object. | |
| 29 class ListenerInterface { | |
| 30 public: | |
| 31 // Updates the listener with a new position. server_error indicates whether | |
| 32 // was a server or network error - either no response or a 500 error code. | |
| 33 virtual void LocationResponseAvailable( | |
| 34 const Geoposition& position, | |
| 35 bool server_error, | |
| 36 const string16& access_token, | |
| 37 const GatewayData& gateway_data, | |
| 38 const RadioData& radio_data, | |
| 39 const WifiData& wifi_data) = 0; | |
| 40 | |
| 41 protected: | |
| 42 virtual ~ListenerInterface() {} | |
| 43 }; | |
| 44 | |
| 45 // |url| is the server address to which the request wil be sent. | |
| 46 NetworkLocationRequest(URLRequestContextGetter* context, | |
| 47 const GURL& url, | |
| 48 ListenerInterface* listener); | |
| 49 virtual ~NetworkLocationRequest(); | |
| 50 | |
| 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 std::string& host, | |
| 54 const string16& access_token, | |
| 55 const GatewayData& gateway_data, | |
| 56 const RadioData& radio_data, | |
| 57 const WifiData& wifi_data, | |
| 58 const base::Time& timestamp); | |
| 59 | |
| 60 bool is_request_pending() const { return url_fetcher_ != NULL; } | |
| 61 const GURL& url() const { return url_; } | |
| 62 | |
| 63 private: | |
| 64 // URLFetcher::Delegate | |
| 65 virtual void OnURLFetchComplete(const URLFetcher* source, | |
| 66 const GURL& url, | |
| 67 const net::URLRequestStatus& status, | |
| 68 int response_code, | |
| 69 const ResponseCookies& cookies, | |
| 70 const std::string& data); | |
| 71 | |
| 72 scoped_refptr<URLRequestContextGetter> url_context_; | |
| 73 ListenerInterface* listener_; | |
| 74 const GURL url_; | |
| 75 scoped_ptr<URLFetcher> url_fetcher_; | |
| 76 | |
| 77 // Keep a copy of the data sent in the request, so we can refer back to it | |
| 78 // when the response arrives. | |
| 79 GatewayData gateway_data_; | |
| 80 RadioData radio_data_; | |
| 81 WifiData wifi_data_; | |
| 82 base::Time timestamp_; // Timestamp of the above data, not of the request. | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(NetworkLocationRequest); | |
| 85 }; | |
| 86 | |
| 87 #endif // CHROME_BROWSER_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_ | |
| OLD | NEW |