Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: chromeos/timezone/timezone_resolver.cc

Issue 1837893003: ChromeOS: Refactor TimeZoneResolver, add TimeZoneResolverManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/timezone/timezone_resolver.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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());
403 DCHECK(delegate_);
390 } 404 }
391 405
392 TimeZoneResolver::~TimeZoneResolver() { 406 TimeZoneResolver::~TimeZoneResolver() {
393 Stop(); 407 Stop();
394 } 408 }
395 409
396 void TimeZoneResolver::Start() { 410 void TimeZoneResolver::Start() {
397 DCHECK(thread_checker_.CalledOnValidThread()); 411 DCHECK(thread_checker_.CalledOnValidThread());
398 if (!implementation_) { 412 if (!implementation_) {
399 implementation_.reset(new TimeZoneResolverImpl(this)); 413 implementation_.reset(new TimeZoneResolverImpl(this));
(...skipping 15 matching lines...) Expand all
415 // static 429 // static
416 int TimeZoneResolver::IntervalForNextRequestForTesting(const int requests) { 430 int TimeZoneResolver::IntervalForNextRequestForTesting(const int requests) {
417 return IntervalForNextRequest(requests); 431 return IntervalForNextRequest(requests);
418 } 432 }
419 433
420 // static 434 // static
421 void TimeZoneResolver::RegisterPrefs(PrefRegistrySimple* registry) { 435 void TimeZoneResolver::RegisterPrefs(PrefRegistrySimple* registry) {
422 registry->RegisterInt64Pref(kLastTimeZoneRefreshTime, 0); 436 registry->RegisterInt64Pref(kLastTimeZoneRefreshTime, 0);
423 } 437 }
424 438
439 bool TimeZoneResolver::ShouldSendWiFiGeolocationData() const {
440 return delegate_->ShouldSendWiFiGeolocationData();
441 }
442
425 } // namespace chromeos 443 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/timezone/timezone_resolver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698