OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/timezone/timezone_resolver.h" | 5 #include "chromeos/timezone/timezone_resolver.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 void RequestIsFinished(); | 111 void RequestIsFinished(); |
112 | 112 |
113 void ApplyTimeZone(const TimeZoneResponseData* timezone); | 113 void ApplyTimeZone(const TimeZoneResponseData* timezone); |
114 | 114 |
115 TimeZoneResolver::DelayNetworkCallClosure delay_network_call() const { | 115 TimeZoneResolver::DelayNetworkCallClosure delay_network_call() const { |
116 return resolver_->delay_network_call(); | 116 return resolver_->delay_network_call(); |
117 } | 117 } |
118 | 118 |
119 base::WeakPtr<TimeZoneResolver::TimeZoneResolverImpl> AsWeakPtr(); | 119 base::WeakPtr<TimeZoneResolver::TimeZoneResolverImpl> AsWeakPtr(); |
120 | 120 |
121 bool ShouldSendWiFiGeolocationData(); | |
122 | |
121 private: | 123 private: |
122 const TimeZoneResolver* resolver_; | 124 const TimeZoneResolver* resolver_; |
123 | 125 |
124 // Returns delay to next timezone update request | 126 // Returns delay to next timezone update request |
125 base::TimeDelta CalculateNextInterval(); | 127 base::TimeDelta CalculateNextInterval(); |
126 | 128 |
127 SimpleGeolocationProvider geolocation_provider_; | 129 SimpleGeolocationProvider geolocation_provider_; |
128 TimeZoneProvider timezone_provider_; | 130 TimeZoneProvider timezone_provider_; |
129 | 131 |
130 base::OneShotTimer refresh_timer_; | 132 base::OneShotTimer refresh_timer_; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 DISALLOW_COPY_AND_ASSIGN(TZRequest); | 178 DISALLOW_COPY_AND_ASSIGN(TZRequest); |
177 }; | 179 }; |
178 | 180 |
179 TZRequest::~TZRequest() { | 181 TZRequest::~TZRequest() { |
180 } | 182 } |
181 | 183 |
182 void TZRequest::StartRequestOnNetworkAvailable() { | 184 void TZRequest::StartRequestOnNetworkAvailable() { |
183 resolver_->RecordAttempt(); | 185 resolver_->RecordAttempt(); |
184 resolver_->geolocation_provider()->RequestGeolocation( | 186 resolver_->geolocation_provider()->RequestGeolocation( |
185 base::TimeDelta::FromSeconds(kRefreshTimeZoneTimeoutSeconds), | 187 base::TimeDelta::FromSeconds(kRefreshTimeZoneTimeoutSeconds), |
186 false /* send_wifi_geolocation_data */, | 188 resolver_->ShouldSendWiFiGeolocationData(), |
187 base::Bind(&TZRequest::OnLocationResolved, AsWeakPtr())); | 189 base::Bind(&TZRequest::OnLocationResolved, AsWeakPtr())); |
188 } | 190 } |
189 | 191 |
190 void TZRequest::Start() { | 192 void TZRequest::Start() { |
191 // call to chromeos::DelayNetworkCall | 193 // call to chromeos::DelayNetworkCall |
192 resolver_->delay_network_call().Run( | 194 resolver_->delay_network_call().Run( |
193 base::Bind(&TZRequest::StartRequestOnNetworkAvailable, AsWeakPtr())); | 195 base::Bind(&TZRequest::StartRequestOnNetworkAvailable, AsWeakPtr())); |
194 } | 196 } |
195 | 197 |
196 void TZRequest::OnLocationResolved(const Geoposition& position, | 198 void TZRequest::OnLocationResolved(const Geoposition& position, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 void TimeZoneResolver::TimeZoneResolverImpl::RequestIsFinished() { | 361 void TimeZoneResolver::TimeZoneResolverImpl::RequestIsFinished() { |
360 request_.reset(); | 362 request_.reset(); |
361 ScheduleRequest(); | 363 ScheduleRequest(); |
362 } | 364 } |
363 | 365 |
364 void TimeZoneResolver::TimeZoneResolverImpl::ApplyTimeZone( | 366 void TimeZoneResolver::TimeZoneResolverImpl::ApplyTimeZone( |
365 const TimeZoneResponseData* timezone) { | 367 const TimeZoneResponseData* timezone) { |
366 resolver_->apply_timezone().Run(timezone); | 368 resolver_->apply_timezone().Run(timezone); |
367 } | 369 } |
368 | 370 |
371 bool TimeZoneResolver::TimeZoneResolverImpl::ShouldSendWiFiGeolocationData() { | |
372 return resolver_->ShouldSendWiFiGeolocationData(); | |
373 } | |
374 | |
369 base::WeakPtr<TimeZoneResolver::TimeZoneResolverImpl> | 375 base::WeakPtr<TimeZoneResolver::TimeZoneResolverImpl> |
370 TimeZoneResolver::TimeZoneResolverImpl::AsWeakPtr() { | 376 TimeZoneResolver::TimeZoneResolverImpl::AsWeakPtr() { |
371 return weak_ptr_factory_.GetWeakPtr(); | 377 return weak_ptr_factory_.GetWeakPtr(); |
372 } | 378 } |
373 | 379 |
374 // ------------------------------------------------------------------------ | 380 // ------------------------------------------------------------------------ |
381 // TimeZoneResolver::Delegate implementation | |
382 TimeZoneResolver::Delegate::Delegate() {} | |
383 TimeZoneResolver::Delegate::~Delegate() {} | |
384 | |
385 // ------------------------------------------------------------------------ | |
375 // TimeZoneResolver implementation | 386 // TimeZoneResolver implementation |
376 | 387 |
377 TimeZoneResolver::TimeZoneResolver( | 388 TimeZoneResolver::TimeZoneResolver( |
389 Delegate* delegate, | |
378 scoped_refptr<net::URLRequestContextGetter> context, | 390 scoped_refptr<net::URLRequestContextGetter> context, |
379 const GURL& url, | 391 const GURL& url, |
380 const ApplyTimeZoneCallback& apply_timezone, | 392 const ApplyTimeZoneCallback& apply_timezone, |
381 const DelayNetworkCallClosure& delay_network_call, | 393 const DelayNetworkCallClosure& delay_network_call, |
382 PrefService* local_state) | 394 PrefService* local_state) |
383 : context_(context), | 395 : delegate_(delegate), |
396 context_(context), | |
384 url_(url), | 397 url_(url), |
385 apply_timezone_(apply_timezone), | 398 apply_timezone_(apply_timezone), |
386 delay_network_call_(delay_network_call), | 399 delay_network_call_(delay_network_call), |
387 local_state_(local_state), | 400 local_state_(local_state), |
388 send_wifi_data_to_geolocation_api_(false) { | 401 send_wifi_data_to_geolocation_api_(false) { |
389 DCHECK(!apply_timezone.is_null()); | 402 DCHECK(!apply_timezone.is_null()); |
390 } | 403 } |
391 | 404 |
392 TimeZoneResolver::~TimeZoneResolver() { | 405 TimeZoneResolver::~TimeZoneResolver() { |
393 Stop(); | 406 Stop(); |
(...skipping 21 matching lines...) Expand all Loading... | |
415 // static | 428 // static |
416 int TimeZoneResolver::IntervalForNextRequestForTesting(const int requests) { | 429 int TimeZoneResolver::IntervalForNextRequestForTesting(const int requests) { |
417 return IntervalForNextRequest(requests); | 430 return IntervalForNextRequest(requests); |
418 } | 431 } |
419 | 432 |
420 // static | 433 // static |
421 void TimeZoneResolver::RegisterPrefs(PrefRegistrySimple* registry) { | 434 void TimeZoneResolver::RegisterPrefs(PrefRegistrySimple* registry) { |
422 registry->RegisterInt64Pref(kLastTimeZoneRefreshTime, 0); | 435 registry->RegisterInt64Pref(kLastTimeZoneRefreshTime, 0); |
423 } | 436 } |
424 | 437 |
438 bool TimeZoneResolver::ShouldSendWiFiGeolocationData() const { | |
439 DCHECK(delegate_); | |
stevenjb
2016/03/29 02:15:55
nit: move DCHECK to the constructor where it is se
Alexander Alekseev
2016/03/29 03:46:35
Done.
| |
440 return delegate_->ShouldSendWiFiGeolocationData(); | |
441 } | |
442 | |
425 } // namespace chromeos | 443 } // namespace chromeos |
OLD | NEW |