Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of P3A (Privacy-Preserving Product Analytics) #3242

Merged
merged 75 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
6982b45
The initial Privacy-Preserving Product Analytics impl.
Mar 12, 2019
8b7dbea
P3A: Add some VLOGs to the core service.
Mar 13, 2019
017e463
P3A: adding Week of Survey, Country Code, Refcode.
Mar 29, 2019
86d933a
P2A: Add years of install and survey to the packet
Apr 12, 2019
81770af
P3A: Fix threading issue in p3a service.
Apr 18, 2019
e995099
P3A: Adding a sync status histogram.
Mar 14, 2019
b6ee44b
P3A: Importer source histogram.
Mar 19, 2019
15a7505
Clang-format.
Mar 19, 2019
a2cf68a
P3A: Adding metric for shields usage status.
Mar 21, 2019
9a82351
P3A: Adding windows/tabs and other core metrics.
Mar 25, 2019
1d8126d
P2A: Rewards metrics.
Apr 12, 2019
01f3598
P3A: Typo in ads metrics.
Apr 18, 2019
a56222f
P3A: Uptime metrics.
Apr 15, 2019
b07100f
P3A: Onboarding metric.
bsclifton Apr 18, 2019
7127bb4
Encode p3a protobuf to base64.
Apr 23, 2019
575f652
P3A: updating prochlo keys.
May 8, 2019
c1c8654
Update main p3a URL.
May 8, 2019
f780b64
Adjusting the uploading interval randomization.
May 8, 2019
462d9c5
P3A: Fix macos build.
May 14, 2019
b90ddb9
Fixing the MacOS build.
May 16, 2019
47123c1
Pleasing the linter.
May 16, 2019
d0e63f4
Pinning certificates for P3A endpoints.
Jun 4, 2019
91ca988
P3A: Improving randomization of uploads order.
Jun 4, 2019
88339fc
Minor compilation fix after rebase.
Jun 7, 2019
b8848e6
P3A: Adding brave-specific header to P3A upload requests.
Jun 7, 2019
4ced136
P3A: Adding traces to cpu-heavy functions.
Jun 10, 2019
bb15b1b
P3A: Improve upload interval randomization.
Jun 10, 2019
2e573bf
Clang-format.
Jun 10, 2019
72ceefc
P3A: Making metrics buckets even more private.
Jun 19, 2019
6088598
P3A: Save the bare minimum of stats regarding tor.
Jun 20, 2019
2f11a62
P3A: Disable PROCHLO.
Jul 1, 2019
19fcaac
P3A: Fix the Answer Count metric.
Jul 10, 2019
1ec80b1
Fix compilation errors
bsclifton Jul 25, 2019
5474b74
Initial implementation of P3A infobar
bsclifton Aug 5, 2019
526aec3
Added P3A setting to brave://settings
bsclifton Aug 7, 2019
e20f494
Cleanup per review feedback
bsclifton Aug 9, 2019
da2a2bb
Fixed most compile errors that happened after rebase
bsclifton Aug 21, 2019
2ef207e
p3a welcome screen
rossmoody Aug 12, 2019
b964eef
Don't show P3A infobar for new users; they are shown a different noti…
bsclifton Aug 12, 2019
23bb018
Update shields logic after refactor was done with https://github.com/…
bsclifton Aug 21, 2019
d164e02
Fix compile error for P3A wallet question
bsclifton Aug 22, 2019
30438b8
Update string on shields (p3a) page to be tokenized
bsclifton Aug 22, 2019
d5f297f
Small text change to welcome page, per feedback
bsclifton Aug 29, 2019
b5c9ff9
Final tweaks, per @bradleyrichter and @diracdeltas
bsclifton Aug 30, 2019
5fc97f8
Updates to network annotation per review feedback
bsclifton Sep 3, 2019
c6077e4
Update to use smart quotes on welcome screen
bsclifton Sep 4, 2019
ed109c2
Lint clean up (both C++ and JS)
bsclifton Sep 4, 2019
f91e896
unit test fix, after `const` was removed from method
bsclifton Sep 4, 2019
242e1ea
Minor renaming.
Sep 5, 2019
f8d6f99
Delete obsolete file (theme screen was removed)
bsclifton Sep 5, 2019
56dec6c
Fix Windows compile error
bsclifton Sep 5, 2019
c288726
more windows specific fixes
bsclifton Sep 5, 2019
dc04788
Fix nits
bsclifton Sep 5, 2019
db85f06
P3A: Fix android build.
Sep 6, 2019
6850f1b
Simplifying query in rewards P3A.
Sep 6, 2019
4af229a
P3A: Extract some code to a separate file.
Sep 6, 2019
f485f60
rename BraveWindowsTracker => BraveWindowTracker
bsclifton Sep 17, 2019
cb79e1e
Updated shields graphic, per Karen :)
bsclifton Sep 18, 2019
2f114cc
Improve P3A GN files.
Sep 19, 2019
faf20d2
P3A: refactor shields stats.
Sep 23, 2019
2e6802d
Minor refactoring of ads P3A.
Sep 23, 2019
a9e0160
Minor rename.
Sep 23, 2019
8657cdd
Minor renaming.
Sep 23, 2019
7beddf1
P3A infobar: fix android build.
Sep 24, 2019
0a06899
Pleasing linter.
Sep 26, 2019
54bedf0
Fixing build, disabling P3A on android.
Sep 26, 2019
26ec2c1
Fix tests after rebase.
Sep 27, 2019
795ef88
Fix android build.
Sep 30, 2019
6637ae8
Minor rewording in rewards service.
Oct 1, 2019
05a27da
Restore occasionally deleted block.
Oct 1, 2019
5505737
Better OS and feature guards for P3A.
Oct 1, 2019
d428fa1
Some more deps.
Oct 1, 2019
5c5fe9f
Drop unwanted dep.
Oct 1, 2019
24e28f6
Add missing dependency for p3a.
simonhong Oct 1, 2019
66dd2fd
Check null local_state in tests.
Oct 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,22 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
Black Stripes
</message>
</if>
<!-- P3A -->
<message name="IDS_BRAVE_CONFIRM_P3A_INFO_BAR" desc="Text that shows on the info bar where user acknowledges the P3A message">
Brave uses completely private product analytics to estimate the overall usage of certain features
</message>
<message name="IDS_BRAVE_CONFIRM_P3A_INFO_BAR_ACKNOWLEDGE" desc="OK button that shows on the info bar where user acknowledges the P3A message">
Got it
</message>
<message name="IDS_BRAVE_CONFIRM_P3A_INFO_BAR_DISABLE" desc="Disable button that shows on the info bar where user acknowledges the P3A message">
Disable
</message>
<message name="IDS_BRAVE_P3A_ENABLE_SETTING" desc="Description that shows in settings for toggling P3A">
Automatically send completely private product analytics to Brave
</message>
<message name="IDS_BRAVE_P3A_ENABLE_SETTING_SUBITEM" desc="Description that shows under main toggle setting for P3A">
This anonymous info only lets Brave estimate the overall usage of certain features.
</message>
</messages>
<includes>
<include name="IDR_BRAVE_GOOGLE_ANALYTICS_POLYFILL" file="resources/js/google_analytics_polyfill.js" type="BINDATA" />
Expand Down
3 changes: 3 additions & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import("//build/buildflag_header.gni")
import("//build/config/features.gni")
import("//extensions/buildflags/buildflags.gni")
import("//third_party/widevine/cdm/widevine.gni")
import("//third_party/protobuf/proto_library.gni")

source_set("browser_process") {
visibility = [
Expand Down Expand Up @@ -115,6 +116,7 @@ source_set("browser_process") {
"//brave/components/content_settings/core/browser",
"//brave/components/greaselion/browser/buildflags",
"//brave/components/ntp_tiles",
"//brave/components/p3a",
"//brave/components/resources",
"//brave/components/services:brave_content_manifest_overlays",
"//chrome/common",
Expand Down Expand Up @@ -159,6 +161,7 @@ source_set("browser_process") {

deps += [
"importer",
"infobars",
"//brave/app:brave_generated_resources_grit",
]
} else {
Expand Down
41 changes: 40 additions & 1 deletion browser/brave_browser_main_extra_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,39 @@
#include "brave/browser/brave_browser_main_extra_parts.h"

#include "brave/browser/brave_browser_process_impl.h"
#include "chrome/browser/first_run/first_run.h"
#include "brave/components/brave_shields/browser/brave_shields_p3a.h"
bsclifton marked this conversation as resolved.
Show resolved Hide resolved
#include "brave/components/p3a/buildflags.h"
#include "brave/components/p3a/brave_p3a_service.h"
#include "third_party/widevine/cdm/buildflags.h"

#if !defined(OS_ANDROID)
#include "brave/browser/importer/brave_importer_p3a.h"
#include "brave/components/p3a/p3a_core_metrics.h"
#include "chrome/browser/first_run/first_run.h"
#endif // !defined(OS_ANDROID)

#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
#include "brave/browser/widevine/brave_widevine_bundle_manager.h"
#endif

namespace {

// Records default values for some histograms because we want these stats to be
// uploaded anyways. Corresponding components will write new values according
// to their usage scenarios.
void RecordInitialP3AValues() {
#if !defined(OS_ANDROID)
if (first_run::IsChromeFirstRun()) {
RecordImporterP3A(importer::ImporterType::TYPE_UNKNOWN);
}
#endif // !defined(OS_ANDROID)

brave_shields::MaybeRecordShieldsUsageP3A(brave_shields::kNeverClicked,
g_browser_process->local_state());
}

} // namespace

BraveBrowserMainExtraParts::BraveBrowserMainExtraParts() {
}

Expand All @@ -35,4 +61,17 @@ void BraveBrowserMainExtraParts::PreMainMessageLoopRun() {
// So, call it after browser threads are created.
g_brave_browser_process->brave_widevine_bundle_manager()->StartupCheck();
#endif
// Disabled on mobile platforms, see for instance issues/6176
#if BUILDFLAG(BRAVE_P3A_ENABLED)
// TODO(iefremov): Maybe find a better place for this initialization.
g_brave_browser_process->brave_p3a_service()->Init();
bsclifton marked this conversation as resolved.
Show resolved Hide resolved
#endif // BUILDFLAG(BRAVE_P3A_ENABLED)

RecordInitialP3AValues();

// The code below is not supported on android.
#if !defined(OS_ANDROID)
brave::BraveWindowTracker::CreateInstance(g_browser_process->local_state());
brave::BraveUptimeTracker::CreateInstance(g_browser_process->local_state());
#endif // !defined(OS_ANDROID)
}
31 changes: 31 additions & 0 deletions browser/brave_browser_main_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,39 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/brave_browser_main_parts.h"

#include "brave/browser/browsing_data/brave_clear_browsing_data.h"

#if !defined(OS_ANDROID)
#include "brave/browser/infobars/brave_confirm_p3a_infobar_delegate.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "content/public/browser/web_contents.h"
#endif

void BraveBrowserMainParts::PostBrowserStart() {
ChromeBrowserMainParts::PostBrowserStart();
#if !defined(OS_ANDROID)
Browser* browser = chrome::FindLastActive();
content::WebContents* active_web_contents = nullptr;
bsclifton marked this conversation as resolved.
Show resolved Hide resolved

if (browser) {
active_web_contents = browser->tab_strip_model()->GetActiveWebContents();

if (active_web_contents) {
InfoBarService* infobar_service =
InfoBarService::FromWebContents(active_web_contents);

if (infobar_service) {
BraveConfirmP3AInfoBarDelegate::Create(
infobar_service, g_browser_process->local_state());
}
}
}
#endif // !defined(OS_ANDROID)
}

void BraveBrowserMainParts::PreShutdown() {
content::BraveClearBrowsingData::ClearOnExit();
}
1 change: 1 addition & 0 deletions browser/brave_browser_main_parts.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class BraveBrowserMainParts : public ChromeBrowserMainParts {
using ChromeBrowserMainParts::ChromeBrowserMainParts;
~BraveBrowserMainParts() override = default;

void PostBrowserStart() override;
void PreShutdown() override;

private:
Expand Down
33 changes: 26 additions & 7 deletions browser/brave_browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#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/p3a/buildflags.h"
#include "brave/components/p3a/brave_histogram_rewrite.h"
#include "brave/components/p3a/brave_p3a_service.h"
bsclifton marked this conversation as resolved.
Show resolved Hide resolved
#include "chrome/common/chrome_paths.h"
#include "components/component_updater/component_updater_service.h"
#include "components/component_updater/timer_update_scheduler.h"
Expand Down Expand Up @@ -80,6 +83,13 @@ BraveBrowserProcessImpl::BraveBrowserProcessImpl(StartupData* startup_data)
stats_updater->Start();
},
base::Unretained(brave_stats_updater())));
// Disabled on mobile platforms, see for instance issues/6176
#if BUILDFLAG(BRAVE_P3A_ENABLED)
// Create P3A Service early to catch more histograms. The full initialization
// should be started once browser process impl is ready.
brave_p3a_service();
brave::SetupHistogramsBraveization();
#endif // BUILDFLAG(BRAVE_P3A_ENABLED)
}

brave_component_updater::BraveComponent::Delegate*
Expand Down Expand Up @@ -228,13 +238,13 @@ BraveBrowserProcessImpl::tor_client_updater() {
}
#endif

void BraveBrowserProcessImpl::CreateProfileManager() {
DCHECK(!created_profile_manager_ && !profile_manager_);
created_profile_manager_ = true;

base::FilePath user_data_dir;
base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
profile_manager_ = std::make_unique<BraveProfileManager>(user_data_dir);
brave::BraveP3AService* BraveBrowserProcessImpl::brave_p3a_service() {
if (brave_p3a_service_) {
return brave_p3a_service_.get();
}
brave_p3a_service_ = new brave::BraveP3AService(local_state());
brave_p3a_service()->InitCallbacks();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need a separate call for this? Can it just happen as part of new?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this a part of the constructor can make testing problematic

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move https://github.com/brave/brave-core/pull/3242/files#diff-ce86d8f829640e5e88ce2b71c4e22b01R63 here then and call InitCallbacks inside Init? It just seems weird that we're calling InitCallbacks() here and then Init() in PreMainMessageLoopRun?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the comments, but PreMainMessageLoopRun is the first time this gets called, right? So it's all happening in the same place anyway?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not exactly, this code is eagerly called in BraveBrowserProcessImpl. So I think we can't do much about this separation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here? https://github.com/brave/brave-core/pull/3242/files#diff-f4fa6d8248b71f0edf636150386e89ceR88
why are we eagerly calling it there? I think either way we need some comments to help explain

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't we just have a static override for testing? I just saw this again recently and brought me back to this conversation. This doesn't seem like a great way to handle the testing issue imo

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment now says Can't call it in constructor because of refcounted peculiarities. - but why is this refcounted in the first place? The lifetime is already tied to BraveBrowserProcessImpl so it will outlive everything

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well there is a TODO in p3a_service.h saying that we should get rid of recounting :D
I don't remember the exact reason, probably it is due tothe fact that histogram events can happen really early and really late. But maybe just switching it to unique_ptr + Unretained will be fine as is, actualy

return brave_p3a_service_.get();
}

#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
Expand All @@ -251,3 +261,12 @@ brave::BraveStatsUpdater* BraveBrowserProcessImpl::brave_stats_updater() {
brave_stats_updater_ = brave::BraveStatsUpdaterFactory(local_state());
return brave_stats_updater_.get();
}

void BraveBrowserProcessImpl::CreateProfileManager() {
bsclifton marked this conversation as resolved.
Show resolved Hide resolved
DCHECK(!created_profile_manager_ && !profile_manager_);
created_profile_manager_ = true;

base::FilePath user_data_dir;
base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
profile_manager_ = std::make_unique<BraveProfileManager>(user_data_dir);
}
4 changes: 4 additions & 0 deletions browser/brave_browser_process_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <memory>

#include "base/memory/ref_counted.h"
#include "brave/browser/tor/buildflags.h"
#include "brave/components/brave_component_updater/browser/brave_component.h"
#include "brave/components/brave_referrals/buildflags/buildflags.h"
Expand All @@ -19,6 +20,7 @@
namespace brave {
class BraveReferralsService;
class BraveStatsUpdater;
class BraveP3AService;
} // namespace brave

#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
Expand Down Expand Up @@ -83,6 +85,7 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl {
#if BUILDFLAG(ENABLE_TOR)
extensions::BraveTorClientUpdater* tor_client_updater();
#endif
brave::BraveP3AService* brave_p3a_service();
#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
BraveWidevineBundleManager* brave_widevine_bundle_manager();
#endif
Expand Down Expand Up @@ -129,6 +132,7 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl {
#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
std::unique_ptr<BraveWidevineBundleManager> brave_widevine_bundle_manager_;
#endif
scoped_refptr<brave::BraveP3AService> brave_p3a_service_;

SEQUENCE_CHECKER(sequence_checker_);

Expand Down
20 changes: 18 additions & 2 deletions browser/brave_local_state_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
#include "brave/browser/tor/buildflags.h"
#include "brave/components/brave_referrals/buildflags/buildflags.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "chrome/browser/first_run/first_run.h"
#include "brave/components/brave_shields/browser/brave_shields_p3a.h"
#include "brave/components/p3a/buildflags.h"
#include "brave/components/p3a/brave_p3a_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/browser/first_run/first_run.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/prefs/pref_registry_simple.h"

Expand All @@ -24,6 +27,10 @@
#include "brave/browser/tor/tor_profile_service.h"
#endif

#if !defined(OS_ANDROID)
#include "brave/components/p3a/p3a_core_metrics.h"
#endif // !defined(OS_ANDROID)

namespace brave {

void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
Expand All @@ -43,10 +50,19 @@ void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
#if !defined(OS_ANDROID)
RegisterPrefsForMuonMigration(registry);
#endif

registry->SetDefaultPrefValue(
metrics::prefs::kMetricsReportingEnabled,
base::Value(GetDefaultPrefValueForMetricsReporting()));

#if BUILDFLAG(BRAVE_P3A_ENABLED)
brave::BraveP3AService::RegisterPrefs(registry);
#endif // BUILDFLAG(BRAVE_P3A_ENABLED)

brave_shields::RegisterShieldsP3APrefs(registry);
#if !defined(OS_ANDROID)
BraveWindowTracker::RegisterPrefs(registry);
BraveUptimeTracker::RegisterPrefs(registry);
#endif
}

} // namespace brave
33 changes: 4 additions & 29 deletions browser/brave_stats_updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,15 @@ const int kUpdateServerPeriodicPingFrequency = 5 * 60;

namespace {

std::string GetChannelName() {
std::string channel = chrome::GetChannelName();
if (channel.empty())
channel = "release";
return channel;
}

std::string GetPlatformIdentifier() {
#if defined(OS_WIN)
if (base::SysInfo::OperatingSystemArchitecture() == "x86")
return "winia32-bc";
else
return "winx64-bc";
#elif defined(OS_MACOSX)
return "osx-bc";
#elif defined(OS_ANDROID)
return "android-bc";
#elif defined(OS_LINUX)
return "linux-bc";
#else
return std::string();
#endif
}

GURL GetUpdateURL(const GURL& base_update_url,
const brave::BraveStatsUpdaterParams& stats_updater_params) {
GURL update_url(base_update_url);
update_url = net::AppendQueryParameter(update_url, "platform",
GetPlatformIdentifier());
brave::GetPlatformIdentifier());
update_url =
net::AppendQueryParameter(update_url, "channel", GetChannelName());
update_url = net::AppendQueryParameter(
update_url, "version",
version_info::GetBraveVersionWithoutChromiumMajorVersion());
net::AppendQueryParameter(update_url, "channel", brave::GetChannelName());
update_url = net::AppendQueryParameter(update_url, "version",
version_info::GetBraveVersionWithoutChromiumMajorVersion());
update_url = net::AppendQueryParameter(update_url, "daily",
stats_updater_params.GetDailyParam());
update_url = net::AppendQueryParameter(update_url, "weekly",
Expand Down
33 changes: 1 addition & 32 deletions browser/brave_stats_updater_params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,38 +112,7 @@ int BraveStatsUpdaterParams::GetCurrentMonth() const {
}

int BraveStatsUpdaterParams::GetCurrentISOWeekNumber() const {
base::Time now = GetCurrentTimeNow();
base::Time::Exploded now_exploded;
now.LocalExplode(&now_exploded);
now_exploded.hour = 0;
now_exploded.minute = 0;
now_exploded.second = 0;
now_exploded.millisecond = 0;
now_exploded.day_of_month =
now_exploded.day_of_month + 3 - ((now_exploded.day_of_week + 6) % 7);

base::Time now_adjusted;
if (!base::Time::FromLocalExploded(now_exploded, &now_adjusted))
return 0;

base::Time::Exploded jan4_exploded = {0};
jan4_exploded.year = now_exploded.year;
jan4_exploded.month = 1;
jan4_exploded.day_of_week = 0;
jan4_exploded.day_of_month = 4;
jan4_exploded.hour = 0;
jan4_exploded.minute = 0;
jan4_exploded.second = 0;
jan4_exploded.millisecond = 0;

base::Time jan4_time;
if (!base::Time::FromLocalExploded(jan4_exploded, &jan4_time))
return 0;

return 1 + std::round(
((now_adjusted.ToJsTime() - jan4_time.ToJsTime()) / 86400000 -
3 + (jan4_exploded.day_of_week + 6) % 7) /
7);
return GetIsoWeekNumber(GetCurrentTimeNow());
}

base::Time BraveStatsUpdaterParams::GetCurrentTimeNow() const {
Expand Down
Loading