| 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 | 9 |
| 9 #include <algorithm> | 10 #include <algorithm> |
| 10 | 11 |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/macros.h" |
| 14 #include "base/power_monitor/power_monitor.h" | 16 #include "base/power_monitor/power_monitor.h" |
| 15 #include "base/power_monitor/power_observer.h" | 17 #include "base/power_monitor/power_observer.h" |
| 16 #include "base/prefs/pref_registry_simple.h" | 18 #include "base/prefs/pref_registry_simple.h" |
| 17 #include "base/prefs/pref_service.h" | 19 #include "base/prefs/pref_service.h" |
| 18 #include "base/rand_util.h" | 20 #include "base/rand_util.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 21 #include "chromeos/geolocation/geoposition.h" | 23 #include "chromeos/geolocation/geoposition.h" |
| 22 #include "chromeos/geolocation/simple_geolocation_provider.h" | 24 #include "chromeos/geolocation/simple_geolocation_provider.h" |
| 23 #include "chromeos/timezone/timezone_provider.h" | 25 #include "chromeos/timezone/timezone_provider.h" |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 timezone_provider_(resolver->context().get(), | 257 timezone_provider_(resolver->context().get(), |
| 256 DefaultTimezoneProviderURL()), | 258 DefaultTimezoneProviderURL()), |
| 257 requests_count_(0), | 259 requests_count_(0), |
| 258 weak_ptr_factory_(this) { | 260 weak_ptr_factory_(this) { |
| 259 DCHECK(!resolver_->apply_timezone().is_null()); | 261 DCHECK(!resolver_->apply_timezone().is_null()); |
| 260 DCHECK(!resolver_->delay_network_call().is_null()); | 262 DCHECK(!resolver_->delay_network_call().is_null()); |
| 261 | 263 |
| 262 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); | 264 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
| 263 power_monitor->AddObserver(this); | 265 power_monitor->AddObserver(this); |
| 264 | 266 |
| 265 const int64 last_refresh_at_raw = | 267 const int64_t last_refresh_at_raw = |
| 266 resolver_->local_state()->GetInt64(kLastTimeZoneRefreshTime); | 268 resolver_->local_state()->GetInt64(kLastTimeZoneRefreshTime); |
| 267 const base::Time last_refresh_at = | 269 const base::Time last_refresh_at = |
| 268 base::Time::FromInternalValue(last_refresh_at_raw); | 270 base::Time::FromInternalValue(last_refresh_at_raw); |
| 269 const base::Time next_refresh_not_before = | 271 const base::Time next_refresh_not_before = |
| 270 last_refresh_at + | 272 last_refresh_at + |
| 271 base::TimeDelta::FromSecondsD(kRefreshTimeZoneMinimumDelayOnRestartSec); | 273 base::TimeDelta::FromSecondsD(kRefreshTimeZoneMinimumDelayOnRestartSec); |
| 272 if (next_refresh_not_before > base::Time::Now()) { | 274 if (next_refresh_not_before > base::Time::Now()) { |
| 273 requests_count_ = kRefreshTimeZoneInitialRequestCountOnRateLimit; | 275 requests_count_ = kRefreshTimeZoneInitialRequestCountOnRateLimit; |
| 274 VLOG(1) << "TimeZoneResolverImpl(): initialize requests_count_=" | 276 VLOG(1) << "TimeZoneResolverImpl(): initialize requests_count_=" |
| 275 << requests_count_ << " because of rate limit."; | 277 << requests_count_ << " because of rate limit."; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 int TimeZoneResolver::IntervalForNextRequestForTesting(const int requests) { | 414 int TimeZoneResolver::IntervalForNextRequestForTesting(const int requests) { |
| 413 return IntervalForNextRequest(requests); | 415 return IntervalForNextRequest(requests); |
| 414 } | 416 } |
| 415 | 417 |
| 416 // static | 418 // static |
| 417 void TimeZoneResolver::RegisterPrefs(PrefRegistrySimple* registry) { | 419 void TimeZoneResolver::RegisterPrefs(PrefRegistrySimple* registry) { |
| 418 registry->RegisterInt64Pref(kLastTimeZoneRefreshTime, 0); | 420 registry->RegisterInt64Pref(kLastTimeZoneRefreshTime, 0); |
| 419 } | 421 } |
| 420 | 422 |
| 421 } // namespace chromeos | 423 } // namespace chromeos |
| OLD | NEW |