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