| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(); | 121 bool ShouldSendWiFiGeolocationData(); |
| 122 bool ShouldSendCellularGeolocationData(); |
| 122 | 123 |
| 123 private: | 124 private: |
| 124 const TimeZoneResolver* resolver_; | 125 const TimeZoneResolver* resolver_; |
| 125 | 126 |
| 126 // Returns delay to next timezone update request | 127 // Returns delay to next timezone update request |
| 127 base::TimeDelta CalculateNextInterval(); | 128 base::TimeDelta CalculateNextInterval(); |
| 128 | 129 |
| 129 SimpleGeolocationProvider geolocation_provider_; | 130 SimpleGeolocationProvider geolocation_provider_; |
| 130 TimeZoneProvider timezone_provider_; | 131 TimeZoneProvider timezone_provider_; |
| 131 | 132 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 }; | 180 }; |
| 180 | 181 |
| 181 TZRequest::~TZRequest() { | 182 TZRequest::~TZRequest() { |
| 182 } | 183 } |
| 183 | 184 |
| 184 void TZRequest::StartRequestOnNetworkAvailable() { | 185 void TZRequest::StartRequestOnNetworkAvailable() { |
| 185 resolver_->RecordAttempt(); | 186 resolver_->RecordAttempt(); |
| 186 resolver_->geolocation_provider()->RequestGeolocation( | 187 resolver_->geolocation_provider()->RequestGeolocation( |
| 187 base::TimeDelta::FromSeconds(kRefreshTimeZoneTimeoutSeconds), | 188 base::TimeDelta::FromSeconds(kRefreshTimeZoneTimeoutSeconds), |
| 188 resolver_->ShouldSendWiFiGeolocationData(), | 189 resolver_->ShouldSendWiFiGeolocationData(), |
| 190 resolver_->ShouldSendCellularGeolocationData(), |
| 189 base::Bind(&TZRequest::OnLocationResolved, AsWeakPtr())); | 191 base::Bind(&TZRequest::OnLocationResolved, AsWeakPtr())); |
| 190 } | 192 } |
| 191 | 193 |
| 192 void TZRequest::Start() { | 194 void TZRequest::Start() { |
| 193 // call to chromeos::DelayNetworkCall | 195 // call to chromeos::DelayNetworkCall |
| 194 resolver_->delay_network_call().Run( | 196 resolver_->delay_network_call().Run( |
| 195 base::Bind(&TZRequest::StartRequestOnNetworkAvailable, AsWeakPtr())); | 197 base::Bind(&TZRequest::StartRequestOnNetworkAvailable, AsWeakPtr())); |
| 196 } | 198 } |
| 197 | 199 |
| 198 void TZRequest::OnLocationResolved(const Geoposition& position, | 200 void TZRequest::OnLocationResolved(const Geoposition& position, |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 | 368 |
| 367 void TimeZoneResolver::TimeZoneResolverImpl::ApplyTimeZone( | 369 void TimeZoneResolver::TimeZoneResolverImpl::ApplyTimeZone( |
| 368 const TimeZoneResponseData* timezone) { | 370 const TimeZoneResponseData* timezone) { |
| 369 resolver_->apply_timezone().Run(timezone); | 371 resolver_->apply_timezone().Run(timezone); |
| 370 } | 372 } |
| 371 | 373 |
| 372 bool TimeZoneResolver::TimeZoneResolverImpl::ShouldSendWiFiGeolocationData() { | 374 bool TimeZoneResolver::TimeZoneResolverImpl::ShouldSendWiFiGeolocationData() { |
| 373 return resolver_->ShouldSendWiFiGeolocationData(); | 375 return resolver_->ShouldSendWiFiGeolocationData(); |
| 374 } | 376 } |
| 375 | 377 |
| 378 bool TimeZoneResolver::TimeZoneResolverImpl:: |
| 379 ShouldSendCellularGeolocationData() { |
| 380 return resolver_->ShouldSendCellularGeolocationData(); |
| 381 } |
| 382 |
| 376 base::WeakPtr<TimeZoneResolver::TimeZoneResolverImpl> | 383 base::WeakPtr<TimeZoneResolver::TimeZoneResolverImpl> |
| 377 TimeZoneResolver::TimeZoneResolverImpl::AsWeakPtr() { | 384 TimeZoneResolver::TimeZoneResolverImpl::AsWeakPtr() { |
| 378 return weak_ptr_factory_.GetWeakPtr(); | 385 return weak_ptr_factory_.GetWeakPtr(); |
| 379 } | 386 } |
| 380 | 387 |
| 381 // ------------------------------------------------------------------------ | 388 // ------------------------------------------------------------------------ |
| 382 // TimeZoneResolver::Delegate implementation | 389 // TimeZoneResolver::Delegate implementation |
| 383 TimeZoneResolver::Delegate::Delegate() {} | 390 TimeZoneResolver::Delegate::Delegate() {} |
| 384 TimeZoneResolver::Delegate::~Delegate() {} | 391 TimeZoneResolver::Delegate::~Delegate() {} |
| 385 | 392 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 | 440 |
| 434 // static | 441 // static |
| 435 void TimeZoneResolver::RegisterPrefs(PrefRegistrySimple* registry) { | 442 void TimeZoneResolver::RegisterPrefs(PrefRegistrySimple* registry) { |
| 436 registry->RegisterInt64Pref(kLastTimeZoneRefreshTime, 0); | 443 registry->RegisterInt64Pref(kLastTimeZoneRefreshTime, 0); |
| 437 } | 444 } |
| 438 | 445 |
| 439 bool TimeZoneResolver::ShouldSendWiFiGeolocationData() const { | 446 bool TimeZoneResolver::ShouldSendWiFiGeolocationData() const { |
| 440 return delegate_->ShouldSendWiFiGeolocationData(); | 447 return delegate_->ShouldSendWiFiGeolocationData(); |
| 441 } | 448 } |
| 442 | 449 |
| 450 bool TimeZoneResolver::ShouldSendCellularGeolocationData() const { |
| 451 return delegate_->ShouldSendCellularGeolocationData(); |
| 452 } |
| 453 |
| 443 } // namespace chromeos | 454 } // namespace chromeos |
| OLD | NEW |