| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2008, Google Inc. |
| 2 // |
| 3 // Redistribution and use in source and binary forms, with or without |
| 4 // modification, are permitted provided that the following conditions are met: |
| 5 // |
| 6 // 1. Redistributions of source code must retain the above copyright notice, |
| 7 // this list of conditions and the following disclaimer. |
| 8 // 2. Redistributions in binary form must reproduce the above copyright notice, |
| 9 // this list of conditions and the following disclaimer in the documentation |
| 10 // and/or other materials provided with the distribution. |
| 11 // 3. Neither the name of Google Inc. nor the names of its contributors may be |
| 12 // used to endorse or promote products derived from this software without |
| 13 // specific prior written permission. |
| 14 // |
| 15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 |
| 26 #ifndef GEARS_GEOLOCATION_NETWORK_LOCATION_REQUEST_H__ |
| 27 #define GEARS_GEOLOCATION_NETWORK_LOCATION_REQUEST_H__ |
| 28 |
| 29 // TODO(joth): port to chromium |
| 30 #if 0 |
| 31 |
| 32 #include <vector> |
| 33 #include "gears/base/common/basictypes.h" // For int64 |
| 34 #include "gears/base/common/common.h" |
| 35 #include "gears/base/common/event.h" |
| 36 #include "gears/blob/blob.h" |
| 37 #include "gears/geolocation/geolocation.h" |
| 38 #include "gears/geolocation/device_data_provider.h" |
| 39 #include "gears/localserver/common/async_task.h" |
| 40 |
| 41 // An implementation of an AsyncTask that takes a set of device data and sends |
| 42 // it to a server to get a position fix. It performs formatting of the request |
| 43 // and interpretation of the response. |
| 44 class NetworkLocationRequest : public AsyncTask { |
| 45 public: |
| 46 friend class scoped_ptr<NetworkLocationRequest>; // For use in Create(). |
| 47 |
| 48 // Interface for receiving callbacks from a NetworkLocationRequest object. |
| 49 class ListenerInterface { |
| 50 public: |
| 51 // Updates the listener with a new position. server_error indicates whether |
| 52 // was a server or network error - either no response or a 500 error code. |
| 53 virtual void LocationResponseAvailable( |
| 54 const Position &position, |
| 55 bool server_error, |
| 56 const std::string16 &access_token) = 0; |
| 57 }; |
| 58 |
| 59 // Creates the object and starts its worker thread running. Returns NULL if |
| 60 // creation or initialisation fails. |
| 61 static NetworkLocationRequest* Create(BrowsingContext *browsing_context, |
| 62 const std::string16 &url, |
| 63 const std::string16 &host_name, |
| 64 ListenerInterface *listener); |
| 65 bool MakeRequest(const std::string16 &access_token, |
| 66 const RadioData &radio_data, |
| 67 const WifiData &wifi_data, |
| 68 bool request_address, |
| 69 const std::string16 &address_language, |
| 70 double latitude, |
| 71 double longitude, |
| 72 int64 timestamp); |
| 73 // This method aborts any pending request and instructs the worker thread to |
| 74 // terminate. The object is destructed once the thread terminates. This |
| 75 // method blocks until the AsyncTask::Run() implementation is complete, after |
| 76 // which the thread will not attempt to access external resources such as the |
| 77 // listener. |
| 78 void StopThreadAndDelete(); |
| 79 |
| 80 private: |
| 81 // Private constructor and destructor. Callers should use Create() and |
| 82 // StopThreadAndDelete(). |
| 83 NetworkLocationRequest(BrowsingContext *browsing_context, |
| 84 const std::string16 &url, |
| 85 const std::string16 &host_name, |
| 86 ListenerInterface *listener); |
| 87 virtual ~NetworkLocationRequest() {} |
| 88 |
| 89 void MakeRequestImpl(); |
| 90 |
| 91 // AsyncTask implementation. |
| 92 virtual void Run(); |
| 93 |
| 94 static bool FormRequestBody(const std::string16 &host_name, |
| 95 const std::string16 &access_token, |
| 96 const RadioData &radio_data, |
| 97 const WifiData &wifi_data, |
| 98 bool request_address, |
| 99 std::string16 address_language, |
| 100 double latitude, |
| 101 double longitude, |
| 102 bool is_reverse_geocode, |
| 103 scoped_refptr<BlobInterface> *blob); |
| 104 |
| 105 static void GetLocationFromResponse(bool http_post_result, |
| 106 int status_code, |
| 107 const std::string &response_body, |
| 108 int64 timestamp, |
| 109 const std::string16 &server_url, |
| 110 bool is_reverse_geocode, |
| 111 Position *position, |
| 112 std::string16 *access_token); |
| 113 |
| 114 int64 timestamp_; // The timestamp of the data used to make the request. |
| 115 scoped_refptr<BlobInterface> post_body_; |
| 116 ListenerInterface *listener_; |
| 117 std::string16 url_; |
| 118 std::string16 host_name_; |
| 119 |
| 120 Mutex is_processing_response_mutex_; |
| 121 |
| 122 bool is_reverse_geocode_; |
| 123 |
| 124 Event thread_event_; |
| 125 bool is_shutting_down_; |
| 126 |
| 127 #ifdef USING_CCTESTS |
| 128 // Uses FormRequestBody for testing. |
| 129 friend void TestGeolocationFormRequestBody(JsCallContext *context); |
| 130 // Uses GetLocationFromResponse for testing. |
| 131 friend void TestGeolocationGetLocationFromResponse( |
| 132 JsCallContext *context, |
| 133 JsRunnerInterface *js_runner); |
| 134 #endif |
| 135 |
| 136 DISALLOW_EVIL_CONSTRUCTORS(NetworkLocationRequest); |
| 137 }; |
| 138 |
| 139 #endif // if 0 |
| 140 |
| 141 #endif // GEARS_GEOLOCATION_NETWORK_LOCATION_REQUEST_H__ |
| OLD | NEW |