summaryrefslogtreecommitdiffstats
path: root/chrome/browser/geolocation/network_location_request.h
diff options
context:
space:
mode:
authorjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-02 18:28:08 +0000
committerjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-02 18:28:08 +0000
commit9732c032ed9b6664149f03472475d31844a1c8ba (patch)
treea19ee04741c6fe7f5fd0d2f84bd7bd335db9009b /chrome/browser/geolocation/network_location_request.h
parent393b7525cea33eb4030758181a01d6f9c9b7ae82 (diff)
downloadchromium_src-9732c032ed9b6664149f03472475d31844a1c8ba.zip
chromium_src-9732c032ed9b6664149f03472475d31844a1c8ba.tar.gz
chromium_src-9732c032ed9b6664149f03472475d31844a1c8ba.tar.bz2
Port the gears geolocation network provider to Chromium
BUG=http://crbug.com/11246 TEST=See http://codereview.chromium.org/556106 Review URL: http://codereview.chromium.org/552250 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37850 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/geolocation/network_location_request.h')
-rw-r--r--chrome/browser/geolocation/network_location_request.h180
1 files changed, 57 insertions, 123 deletions
diff --git a/chrome/browser/geolocation/network_location_request.h b/chrome/browser/geolocation/network_location_request.h
index 18a9081..4bf77fc 100644
--- a/chrome/browser/geolocation/network_location_request.h
+++ b/chrome/browser/geolocation/network_location_request.h
@@ -1,141 +1,75 @@
-// Copyright 2008, Google Inc.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-// 3. Neither the name of Google Inc. nor the names of its contributors may be
-// used to endorse or promote products derived from this software without
-// specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
-// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
-// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef GEARS_GEOLOCATION_NETWORK_LOCATION_REQUEST_H__
-#define GEARS_GEOLOCATION_NETWORK_LOCATION_REQUEST_H__
-
-// TODO(joth): port to chromium
-#if 0
-
-#include <vector>
-#include "gears/base/common/basictypes.h" // For int64
-#include "gears/base/common/common.h"
-#include "gears/base/common/event.h"
-#include "gears/blob/blob.h"
-#include "gears/geolocation/geolocation.h"
-#include "gears/geolocation/device_data_provider.h"
-#include "gears/localserver/common/async_task.h"
-
-// An implementation of an AsyncTask that takes a set of device data and sends
-// it to a server to get a position fix. It performs formatting of the request
-// and interpretation of the response.
-class NetworkLocationRequest : public AsyncTask {
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_
+#define CHROME_BROWSER_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_
+
+#include <string>
+#include "base/basictypes.h"
+#include "base/ref_counted.h"
+#include "chrome/browser/geolocation/device_data_provider.h"
+#include "chrome/browser/net/url_fetcher.h"
+#include "googleurl/src/gurl.h"
+
+struct Position;
+class URLRequestContextGetter;
+class URLFetcher;
+
+// Takes a set of device data and sends it to a server to get a position fix.
+// It performs formatting of the request and interpretation of the response.
+class NetworkLocationRequest : private URLFetcher::Delegate {
public:
- friend class scoped_ptr<NetworkLocationRequest>; // For use in Create().
-
// Interface for receiving callbacks from a NetworkLocationRequest object.
class ListenerInterface {
public:
// Updates the listener with a new position. server_error indicates whether
// was a server or network error - either no response or a 500 error code.
virtual void LocationResponseAvailable(
- const Position &position,
+ const Position& position,
bool server_error,
- const std::string16 &access_token) = 0;
+ const string16& access_token) = 0;
+
+ protected:
+ virtual ~ListenerInterface() {}
};
- // Creates the object and starts its worker thread running. Returns NULL if
- // creation or initialisation fails.
- static NetworkLocationRequest* Create(BrowsingContext *browsing_context,
- const std::string16 &url,
- const std::string16 &host_name,
- ListenerInterface *listener);
- bool MakeRequest(const std::string16 &access_token,
- const RadioData &radio_data,
- const WifiData &wifi_data,
- bool request_address,
- const std::string16 &address_language,
- double latitude,
- double longitude,
+ // |url| is the server address to which the request wil be sent, |host_name|
+ // is the host of the webpage that caused this request.
+ // TODO(joth): is host needed? What to do when we reuse cached locations?
+ NetworkLocationRequest(URLRequestContextGetter* context,
+ const GURL& url,
+ const string16& host_name,
+ ListenerInterface* listener);
+ virtual ~NetworkLocationRequest();
+
+ // Makes a new request. Returns true if the new request was successfully
+ // started. In all cases, any currently pending request will be canceled.
+ bool MakeRequest(const string16& access_token,
+ const RadioData& radio_data,
+ const WifiData& wifi_data,
int64 timestamp);
- // This method aborts any pending request and instructs the worker thread to
- // terminate. The object is destructed once the thread terminates. This
- // method blocks until the AsyncTask::Run() implementation is complete, after
- // which the thread will not attempt to access external resources such as the
- // listener.
- void StopThreadAndDelete();
-
- private:
- // Private constructor and destructor. Callers should use Create() and
- // StopThreadAndDelete().
- NetworkLocationRequest(BrowsingContext *browsing_context,
- const std::string16 &url,
- const std::string16 &host_name,
- ListenerInterface *listener);
- virtual ~NetworkLocationRequest() {}
-
- void MakeRequestImpl();
- // AsyncTask implementation.
- virtual void Run();
-
- static bool FormRequestBody(const std::string16 &host_name,
- const std::string16 &access_token,
- const RadioData &radio_data,
- const WifiData &wifi_data,
- bool request_address,
- std::string16 address_language,
- double latitude,
- double longitude,
- bool is_reverse_geocode,
- scoped_refptr<BlobInterface> *blob);
-
- static void GetLocationFromResponse(bool http_post_result,
- int status_code,
- const std::string &response_body,
- int64 timestamp,
- const std::string16 &server_url,
- bool is_reverse_geocode,
- Position *position,
- std::string16 *access_token);
+ bool is_request_pending() const { return url_fetcher_ != NULL; }
+ const GURL& url() const { return url_; }
+ private:
+ // URLFetcher::Delegate
+ virtual void OnURLFetchComplete(const URLFetcher* source,
+ const GURL& url,
+ const URLRequestStatus& status,
+ int response_code,
+ const ResponseCookies& cookies,
+ const std::string& data);
+
+ scoped_refptr<URLRequestContextGetter> url_context_;
int64 timestamp_; // The timestamp of the data used to make the request.
- scoped_refptr<BlobInterface> post_body_;
- ListenerInterface *listener_;
- std::string16 url_;
- std::string16 host_name_;
-
- Mutex is_processing_response_mutex_;
-
- bool is_reverse_geocode_;
-
- Event thread_event_;
- bool is_shutting_down_;
-
-#ifdef USING_CCTESTS
- // Uses FormRequestBody for testing.
- friend void TestGeolocationFormRequestBody(JsCallContext *context);
- // Uses GetLocationFromResponse for testing.
- friend void TestGeolocationGetLocationFromResponse(
- JsCallContext *context,
- JsRunnerInterface *js_runner);
-#endif
+ ListenerInterface* listener_;
+ const GURL url_;
+ string16 host_name_;
+ scoped_ptr<URLFetcher> url_fetcher_;
DISALLOW_EVIL_CONSTRUCTORS(NetworkLocationRequest);
};
-#endif // if 0
-
-#endif // GEARS_GEOLOCATION_NETWORK_LOCATION_REQUEST_H__
+#endif // CHROME_BROWSER_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_