Rename various Geolocation bits for clarity and consistency.

Review URL: https://codereview.chromium.org/477633002

Cr-Commit-Position: refs/heads/master@{#289678}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289678 0039d316-1c4b-4281-b951-d872f2087c98
parent 24e4f0a9
...@@ -28,9 +28,9 @@ const int64 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds = ...@@ -28,9 +28,9 @@ const int64 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds =
LocationArbitratorImpl::LocationArbitratorImpl( LocationArbitratorImpl::LocationArbitratorImpl(
const LocationUpdateCallback& callback) const LocationUpdateCallback& callback)
: callback_(callback), : arbitrator_update_callback_(callback),
provider_callback_( provider_update_callback_(
base::Bind(&LocationArbitratorImpl::LocationUpdateAvailable, base::Bind(&LocationArbitratorImpl::OnLocationUpdate,
base::Unretained(this))), base::Unretained(this))),
position_provider_(NULL), position_provider_(NULL),
is_permission_granted_(false), is_permission_granted_(false),
...@@ -116,15 +116,14 @@ void LocationArbitratorImpl::RegisterProvider( ...@@ -116,15 +116,14 @@ void LocationArbitratorImpl::RegisterProvider(
LocationProvider* provider) { LocationProvider* provider) {
if (!provider) if (!provider)
return; return;
provider->SetUpdateCallback(provider_callback_); provider->SetUpdateCallback(provider_update_callback_);
if (is_permission_granted_) if (is_permission_granted_)
provider->OnPermissionGranted(); provider->OnPermissionGranted();
providers_.push_back(provider); providers_.push_back(provider);
} }
void LocationArbitratorImpl::LocationUpdateAvailable( void LocationArbitratorImpl::OnLocationUpdate(const LocationProvider* provider,
const LocationProvider* provider, const Geoposition& new_position) {
const Geoposition& new_position) {
DCHECK(new_position.Validate() || DCHECK(new_position.Validate() ||
new_position.error_code != Geoposition::ERROR_CODE_NONE); new_position.error_code != Geoposition::ERROR_CODE_NONE);
if (!IsNewPositionBetter(position_, new_position, if (!IsNewPositionBetter(position_, new_position,
...@@ -132,7 +131,7 @@ void LocationArbitratorImpl::LocationUpdateAvailable( ...@@ -132,7 +131,7 @@ void LocationArbitratorImpl::LocationUpdateAvailable(
return; return;
position_provider_ = provider; position_provider_ = provider;
position_ = new_position; position_ = new_position;
callback_.Run(position_); arbitrator_update_callback_.Run(position_);
} }
AccessTokenStore* LocationArbitratorImpl::NewAccessTokenStore() { AccessTokenStore* LocationArbitratorImpl::NewAccessTokenStore() {
......
...@@ -70,9 +70,9 @@ class CONTENT_EXPORT LocationArbitratorImpl : public LocationArbitrator { ...@@ -70,9 +70,9 @@ class CONTENT_EXPORT LocationArbitratorImpl : public LocationArbitrator {
net::URLRequestContextGetter* context_getter); net::URLRequestContextGetter* context_getter);
void DoStartProviders(); void DoStartProviders();
// The providers call this function when a new position is available. // Gets called when a provider has a new position.
void LocationUpdateAvailable(const LocationProvider* provider, void OnLocationUpdate(const LocationProvider* provider,
const Geoposition& new_position); const Geoposition& new_position);
// Returns true if |new_position| is an improvement over |old_position|. // Returns true if |new_position| is an improvement over |old_position|.
// Set |from_same_provider| to true if both the positions came from the same // Set |from_same_provider| to true if both the positions came from the same
...@@ -82,8 +82,8 @@ class CONTENT_EXPORT LocationArbitratorImpl : public LocationArbitrator { ...@@ -82,8 +82,8 @@ class CONTENT_EXPORT LocationArbitratorImpl : public LocationArbitrator {
bool from_same_provider) const; bool from_same_provider) const;
scoped_refptr<AccessTokenStore> access_token_store_; scoped_refptr<AccessTokenStore> access_token_store_;
LocationUpdateCallback callback_; LocationUpdateCallback arbitrator_update_callback_;
LocationProvider::LocationProviderUpdateCallback provider_callback_; LocationProvider::LocationProviderUpdateCallback provider_update_callback_;
ScopedVector<LocationProvider> providers_; ScopedVector<LocationProvider> providers_;
bool use_high_accuracy_; bool use_high_accuracy_;
// The provider which supplied the current |position_| // The provider which supplied the current |position_|
......
...@@ -110,7 +110,7 @@ NetworkLocationProvider::NetworkLocationProvider( ...@@ -110,7 +110,7 @@ NetworkLocationProvider::NetworkLocationProvider(
: access_token_store_(access_token_store), : access_token_store_(access_token_store),
wifi_data_provider_(NULL), wifi_data_provider_(NULL),
wifi_data_update_callback_( wifi_data_update_callback_(
base::Bind(&NetworkLocationProvider::WifiDataUpdateAvailable, base::Bind(&NetworkLocationProvider::OnWifiDataUpdate,
base::Unretained(this))), base::Unretained(this))),
is_wifi_data_complete_(false), is_wifi_data_complete_(false),
access_token_(access_token), access_token_(access_token),
...@@ -120,10 +120,11 @@ NetworkLocationProvider::NetworkLocationProvider( ...@@ -120,10 +120,11 @@ NetworkLocationProvider::NetworkLocationProvider(
// Create the position cache. // Create the position cache.
position_cache_.reset(new PositionCache()); position_cache_.reset(new PositionCache());
NetworkLocationRequest::LocationResponseCallback callback = request_.reset(new NetworkLocationRequest(
base::Bind(&NetworkLocationProvider::LocationResponseAvailable, url_context_getter,
base::Unretained(this)); url,
request_.reset(new NetworkLocationRequest(url_context_getter, url, callback)); base::Bind(&NetworkLocationProvider::OnLocationResponse,
base::Unretained(this))));
} }
NetworkLocationProvider::~NetworkLocationProvider() { NetworkLocationProvider::~NetworkLocationProvider() {
...@@ -153,14 +154,13 @@ void NetworkLocationProvider::OnPermissionGranted() { ...@@ -153,14 +154,13 @@ void NetworkLocationProvider::OnPermissionGranted() {
} }
} }
void NetworkLocationProvider::WifiDataUpdateAvailable( void NetworkLocationProvider::OnWifiDataUpdate(WifiDataProvider* provider) {
WifiDataProvider* provider) {
DCHECK(provider == wifi_data_provider_); DCHECK(provider == wifi_data_provider_);
is_wifi_data_complete_ = wifi_data_provider_->GetData(&wifi_data_); is_wifi_data_complete_ = wifi_data_provider_->GetData(&wifi_data_);
OnWifiDataUpdated(); OnWifiDataUpdated();
} }
void NetworkLocationProvider::LocationResponseAvailable( void NetworkLocationProvider::OnLocationResponse(
const Geoposition& position, const Geoposition& position,
bool server_error, bool server_error,
const base::string16& access_token, const base::string16& access_token,
......
...@@ -82,18 +82,18 @@ class NetworkLocationProvider ...@@ -82,18 +82,18 @@ class NetworkLocationProvider
// Satisfies a position request from cache or network. // Satisfies a position request from cache or network.
void RequestPosition(); void RequestPosition();
// Called from a callback when new wifi data is available. // Gets called when new wifi data is available.
void WifiDataUpdateAvailable(WifiDataProvider* provider); void OnWifiDataUpdate(WifiDataProvider* provider);
// Internal helper used by WifiDataUpdateAvailable. // Internal helper used by OnWifiDataUpdate.
void OnWifiDataUpdated(); void OnWifiDataUpdated();
bool IsStarted() const; bool IsStarted() const;
void LocationResponseAvailable(const Geoposition& position, void OnLocationResponse(const Geoposition& position,
bool server_error, bool server_error,
const base::string16& access_token, const base::string16& access_token,
const WifiData& wifi_data); const WifiData& wifi_data);
scoped_refptr<AccessTokenStore> access_token_store_; scoped_refptr<AccessTokenStore> access_token_store_;
......
...@@ -35,8 +35,8 @@ class MessageLoopQuitListener { ...@@ -35,8 +35,8 @@ class MessageLoopQuitListener {
CHECK(client_message_loop_); CHECK(client_message_loop_);
} }
void LocationUpdateAvailable(const LocationProvider* provider, void OnLocationUpdate(const LocationProvider* provider,
const Geoposition& position) { const Geoposition& position) {
EXPECT_EQ(client_message_loop_, base::MessageLoop::current()); EXPECT_EQ(client_message_loop_, base::MessageLoop::current());
updated_provider_ = provider; updated_provider_ = provider;
client_message_loop_->Quit(); client_message_loop_->Quit();
...@@ -473,9 +473,8 @@ TEST_F(GeolocationNetworkProviderTest, NoRequestOnStartupUntilWifiData) { ...@@ -473,9 +473,8 @@ TEST_F(GeolocationNetworkProviderTest, NoRequestOnStartupUntilWifiData) {
scoped_ptr<LocationProvider> provider(CreateProvider(true)); scoped_ptr<LocationProvider> provider(CreateProvider(true));
EXPECT_TRUE(provider->StartProvider(false)); EXPECT_TRUE(provider->StartProvider(false));
provider->SetUpdateCallback( provider->SetUpdateCallback(base::Bind(
base::Bind(&MessageLoopQuitListener::LocationUpdateAvailable, &MessageLoopQuitListener::OnLocationUpdate, base::Unretained(&listener)));
base::Unretained(&listener)));
main_message_loop_.RunUntilIdle(); main_message_loop_.RunUntilIdle();
EXPECT_FALSE(get_url_fetcher_and_advance_id()) EXPECT_FALSE(get_url_fetcher_and_advance_id())
......
...@@ -103,9 +103,7 @@ NetworkLocationRequest::NetworkLocationRequest( ...@@ -103,9 +103,7 @@ NetworkLocationRequest::NetworkLocationRequest(
net::URLRequestContextGetter* context, net::URLRequestContextGetter* context,
const GURL& url, const GURL& url,
LocationResponseCallback callback) LocationResponseCallback callback)
: url_context_(context), : url_context_(context), location_response_callback_(callback), url_(url) {
callback_(callback),
url_(url) {
} }
NetworkLocationRequest::~NetworkLocationRequest() { NetworkLocationRequest::~NetworkLocationRequest() {
...@@ -122,7 +120,7 @@ bool NetworkLocationRequest::MakeRequest(const base::string16& access_token, ...@@ -122,7 +120,7 @@ bool NetworkLocationRequest::MakeRequest(const base::string16& access_token,
url_fetcher_.reset(); url_fetcher_.reset();
} }
wifi_data_ = wifi_data; wifi_data_ = wifi_data;
timestamp_ = timestamp; wifi_data_timestamp_ = timestamp;
GURL request_url = FormRequestURL(url_); GURL request_url = FormRequestURL(url_);
url_fetcher_.reset(net::URLFetcher::Create( url_fetcher_.reset(net::URLFetcher::Create(
...@@ -136,7 +134,7 @@ bool NetworkLocationRequest::MakeRequest(const base::string16& access_token, ...@@ -136,7 +134,7 @@ bool NetworkLocationRequest::MakeRequest(const base::string16& access_token,
net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES |
net::LOAD_DO_NOT_SEND_AUTH_DATA); net::LOAD_DO_NOT_SEND_AUTH_DATA);
start_time_ = base::TimeTicks::Now(); request_start_time_ = base::TimeTicks::Now();
url_fetcher_->Start(); url_fetcher_->Start();
return true; return true;
} }
...@@ -156,7 +154,7 @@ void NetworkLocationRequest::OnURLFetchComplete( ...@@ -156,7 +154,7 @@ void NetworkLocationRequest::OnURLFetchComplete(
GetLocationFromResponse(status.is_success(), GetLocationFromResponse(status.is_success(),
response_code, response_code,
data, data,
timestamp_, wifi_data_timestamp_,
source->GetURL(), source->GetURL(),
&position, &position,
&access_token); &access_token);
...@@ -165,7 +163,8 @@ void NetworkLocationRequest::OnURLFetchComplete( ...@@ -165,7 +163,8 @@ void NetworkLocationRequest::OnURLFetchComplete(
url_fetcher_.reset(); url_fetcher_.reset();
if (!server_error) { if (!server_error) {
const base::TimeDelta request_time = base::TimeTicks::Now() - start_time_; const base::TimeDelta request_time =
base::TimeTicks::Now() - request_start_time_;
UMA_HISTOGRAM_CUSTOM_TIMES( UMA_HISTOGRAM_CUSTOM_TIMES(
"Net.Wifi.LbsLatency", "Net.Wifi.LbsLatency",
...@@ -176,7 +175,8 @@ void NetworkLocationRequest::OnURLFetchComplete( ...@@ -176,7 +175,8 @@ void NetworkLocationRequest::OnURLFetchComplete(
} }
DVLOG(1) << "NetworkLocationRequest::OnURLFetchComplete() : run callback."; DVLOG(1) << "NetworkLocationRequest::OnURLFetchComplete() : run callback.";
callback_.Run(position, server_error, access_token, wifi_data_); location_response_callback_.Run(
position, server_error, access_token, wifi_data_);
} }
// Local functions. // Local functions.
......
...@@ -57,17 +57,17 @@ class NetworkLocationRequest : private net::URLFetcherDelegate { ...@@ -57,17 +57,17 @@ class NetworkLocationRequest : private net::URLFetcherDelegate {
virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
scoped_refptr<net::URLRequestContextGetter> url_context_; scoped_refptr<net::URLRequestContextGetter> url_context_;
LocationResponseCallback callback_; LocationResponseCallback location_response_callback_;
const GURL url_; const GURL url_;
scoped_ptr<net::URLFetcher> url_fetcher_; scoped_ptr<net::URLFetcher> url_fetcher_;
// Keep a copy of the data sent in the request, so we can refer back to it // Keep a copy of the data sent in the request, so we can refer back to it
// when the response arrives. // when the response arrives.
WifiData wifi_data_; WifiData wifi_data_;
base::Time timestamp_; // Timestamp of the above data, not of the request. base::Time wifi_data_timestamp_;
// The start time for the request. // The start time for the request.
base::TimeTicks start_time_; base::TimeTicks request_start_time_;
DISALLOW_COPY_AND_ASSIGN(NetworkLocationRequest); DISALLOW_COPY_AND_ASSIGN(NetworkLocationRequest);
}; };
......
...@@ -62,12 +62,12 @@ class MessageLoopQuitter { ...@@ -62,12 +62,12 @@ class MessageLoopQuitter {
public: public:
explicit MessageLoopQuitter(base::MessageLoop* message_loop) explicit MessageLoopQuitter(base::MessageLoop* message_loop)
: message_loop_to_quit_(message_loop), : message_loop_to_quit_(message_loop),
callback_(base::Bind(&MessageLoopQuitter::WifiDataUpdateAvailable, callback_(base::Bind(&MessageLoopQuitter::OnWifiDataUpdate,
base::Unretained(this))) { base::Unretained(this))) {
CHECK(message_loop_to_quit_ != NULL); CHECK(message_loop_to_quit_ != NULL);
} }
void WifiDataUpdateAvailable(WifiDataProvider* provider) { void OnWifiDataUpdate(WifiDataProvider* provider) {
// Provider should call back on client's thread. // Provider should call back on client's thread.
EXPECT_EQ(base::MessageLoop::current(), message_loop_to_quit_); EXPECT_EQ(base::MessageLoop::current(), message_loop_to_quit_);
message_loop_to_quit_->QuitNow(); message_loop_to_quit_->QuitNow();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment