Skip to content

Commit

Permalink
SetNetworkTimeTracker might be called later than GetNetworkTime in so…
Browse files Browse the repository at this point in the history
…me cases
  • Loading branch information
darkdh committed Jun 11, 2020
1 parent 51b4d3c commit b5f41a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 3 additions & 0 deletions browser/brave_browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "brave/components/brave_shields/browser/https_everywhere_service.h"
#include "brave/components/brave_shields/browser/referrer_whitelist_service.h"
#include "brave/components/brave_shields/browser/tracking_protection_service.h"
#include "brave/components/brave_sync/buildflags/buildflags.h"
#include "brave/components/brave_sync/network_time_helper.h"
#include "brave/components/ntp_background_images/browser/features.h"
#include "brave/components/ntp_background_images/browser/ntp_background_images_service.h"
Expand Down Expand Up @@ -198,8 +199,10 @@ void BraveBrowserProcessImpl::StartBraveServices() {
// Now start the local data files service, which calls all observers.
local_data_files_service()->Start();

#if BUILDFLAG(ENABLE_BRAVE_SYNC)
brave_sync::NetworkTimeHelper::GetInstance()
->SetNetworkTimeTracker(g_browser_process->network_time_tracker());
#endif
}

brave_shields::AdBlockService* BraveBrowserProcessImpl::ad_block_service() {
Expand Down
9 changes: 4 additions & 5 deletions components/brave_sync/network_time_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ void NetworkTimeHelper::SetNetworkTimeForTest(const base::Time& time) {
network_time_for_test_ = time;
}

void NetworkTimeHelper::GetNetworkTimeOnUIThread(
GetNetworkTimeCallback cb) {
void NetworkTimeHelper::GetNetworkTimeOnUIThread(GetNetworkTimeCallback cb) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(network_time_tracker_);
base::Time time;
if (network_time_tracker_->GetNetworkTime(&time, nullptr) !=
network_time::NetworkTimeTracker::NETWORK_TIME_AVAILABLE) {
if (!network_time_tracker_ ||
network_time_tracker_->GetNetworkTime(&time, nullptr) !=
network_time::NetworkTimeTracker::NETWORK_TIME_AVAILABLE) {
VLOG(1) << "Network time not available, using local time";
time = base::Time::Now();
}
Expand Down

0 comments on commit b5f41a3

Please sign in to comment.