summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormvanouwerkerk@chromium.org <mvanouwerkerk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-21 18:55:46 +0000
committermvanouwerkerk@chromium.org <mvanouwerkerk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-21 18:55:46 +0000
commit666b66392f20bd72ed9617d74dcd78fe83db8710 (patch)
tree21f5f008ff4bced985edd65dfad42189d4367943
parenta3c1d451969ce6a8f3d87eb627b21296b10a4d86 (diff)
downloadchromium_src-666b66392f20bd72ed9617d74dcd78fe83db8710.zip
chromium_src-666b66392f20bd72ed9617d74dcd78fe83db8710.tar.gz
chromium_src-666b66392f20bd72ed9617d74dcd78fe83db8710.tar.bz2
Convert NetworkLocationRequest::ListenerInterface to a callback.
Review URL: https://chromiumcodereview.appspot.com/23183008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@218788 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/geolocation/network_location_provider.cc6
-rw-r--r--content/browser/geolocation/network_location_provider.h12
-rw-r--r--content/browser/geolocation/network_location_request.cc12
-rw-r--r--content/browser/geolocation/network_location_request.h27
4 files changed, 25 insertions, 32 deletions
diff --git a/content/browser/geolocation/network_location_provider.cc b/content/browser/geolocation/network_location_provider.cc
index 82171a0..0ea890c 100644
--- a/content/browser/geolocation/network_location_provider.cc
+++ b/content/browser/geolocation/network_location_provider.cc
@@ -118,7 +118,10 @@ NetworkLocationProvider::NetworkLocationProvider(
// Create the position cache.
position_cache_.reset(new PositionCache());
- request_.reset(new NetworkLocationRequest(url_context_getter, url, this));
+ NetworkLocationRequest::LocationResponseCallback callback =
+ base::Bind(&NetworkLocationProvider::LocationResponseAvailable,
+ base::Unretained(this));
+ request_.reset(new NetworkLocationRequest(url_context_getter, url, callback));
}
NetworkLocationProvider::~NetworkLocationProvider() {
@@ -156,7 +159,6 @@ void NetworkLocationProvider::DeviceDataUpdateAvailable(
OnDeviceDataUpdated();
}
-// NetworkLocationRequest::ListenerInterface implementation.
void NetworkLocationProvider::LocationResponseAvailable(
const Geoposition& position,
bool server_error,
diff --git a/content/browser/geolocation/network_location_provider.h b/content/browser/geolocation/network_location_provider.h
index a1ba5b3..84ecfd94 100644
--- a/content/browser/geolocation/network_location_provider.h
+++ b/content/browser/geolocation/network_location_provider.h
@@ -28,8 +28,7 @@ class AccessTokenStore;
class NetworkLocationProvider
: public base::NonThreadSafe,
public LocationProviderBase,
- public WifiDataProvider::ListenerInterface,
- public NetworkLocationRequest::ListenerInterface {
+ public WifiDataProvider::ListenerInterface {
public:
// Cache of recently resolved locations. Public for tests.
class CONTENT_EXPORT PositionCache {
@@ -93,11 +92,10 @@ class NetworkLocationProvider
// DeviceDataProvider::ListenerInterface implementation.
virtual void DeviceDataUpdateAvailable(WifiDataProvider* provider) OVERRIDE;
- // NetworkLocationRequest::ListenerInterface implementation.
- virtual void LocationResponseAvailable(const Geoposition& position,
- bool server_error,
- const string16& access_token,
- const WifiData& wifi_data) OVERRIDE;
+ void LocationResponseAvailable(const Geoposition& position,
+ bool server_error,
+ const string16& access_token,
+ const WifiData& wifi_data);
scoped_refptr<AccessTokenStore> access_token_store_;
diff --git a/content/browser/geolocation/network_location_request.cc b/content/browser/geolocation/network_location_request.cc
index 74a77e1..d11a474 100644
--- a/content/browser/geolocation/network_location_request.cc
+++ b/content/browser/geolocation/network_location_request.cc
@@ -70,10 +70,10 @@ int NetworkLocationRequest::url_fetcher_id_for_tests = 0;
NetworkLocationRequest::NetworkLocationRequest(
net::URLRequestContextGetter* context,
const GURL& url,
- ListenerInterface* listener)
- : url_context_(context), listener_(listener),
+ LocationResponseCallback callback)
+ : url_context_(context),
+ callback_(callback),
url_(url) {
- DCHECK(listener);
}
NetworkLocationRequest::~NetworkLocationRequest() {
@@ -139,10 +139,8 @@ void NetworkLocationRequest::OnURLFetchComplete(
100);
}
- DCHECK(listener_);
- DVLOG(1) << "NetworkLocationRequest::Run() : Calling listener with position.";
- listener_->LocationResponseAvailable(position, server_error, access_token,
- wifi_data_);
+ DVLOG(1) << "NetworkLocationRequest::OnURLFetchComplete() : run callback.";
+ callback_.Run(position, server_error, access_token, wifi_data_);
}
// Local functions.
diff --git a/content/browser/geolocation/network_location_request.h b/content/browser/geolocation/network_location_request.h
index 36e843b..56a6004 100644
--- a/content/browser/geolocation/network_location_request.h
+++ b/content/browser/geolocation/network_location_request.h
@@ -27,25 +27,20 @@ class NetworkLocationRequest : private net::URLFetcherDelegate {
public:
// ID passed to URLFetcher::Create(). Used for testing.
CONTENT_EXPORT static int url_fetcher_id_for_tests;
- // 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 Geoposition& position,
- bool server_error,
- const string16& access_token,
- const WifiData& wifi_data) = 0;
-
- protected:
- virtual ~ListenerInterface() {}
- };
+
+ // Called when a new geo position is available. The second argument indicates
+ // whether there was a server error or not. It is true when there was a
+ // server or network error - either no response or a 500 error code.
+ typedef base::Callback<void(const Geoposition& /* position */,
+ bool /* server_error */,
+ const string16& /* access_token */,
+ const WifiData& /* wifi_data */)>
+ LocationResponseCallback;
// |url| is the server address to which the request wil be sent.
NetworkLocationRequest(net::URLRequestContextGetter* context,
const GURL& url,
- ListenerInterface* listener);
+ LocationResponseCallback callback);
virtual ~NetworkLocationRequest();
// Makes a new request. Returns true if the new request was successfully
@@ -62,7 +57,7 @@ class NetworkLocationRequest : private net::URLFetcherDelegate {
virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
scoped_refptr<net::URLRequestContextGetter> url_context_;
- ListenerInterface* listener_;
+ LocationResponseCallback callback_;
const GURL url_;
scoped_ptr<net::URLFetcher> url_fetcher_;