From 240638ea924546296719b0b57f56609bbf35070d Mon Sep 17 00:00:00 2001 From: Aleksei Seren Date: Tue, 19 Nov 2024 10:40:47 -0500 Subject: [PATCH] Improve NTP Sponsored Images logs --- .../browser/ntp_background_images_service.cc | 81 +++++++++---------- 1 file changed, 38 insertions(+), 43 deletions(-) diff --git a/components/ntp_background_images/browser/ntp_background_images_service.cc b/components/ntp_background_images/browser/ntp_background_images_service.cc index cfb71177e356..d5f57d86e011 100644 --- a/components/ntp_background_images/browser/ntp_background_images_service.cc +++ b/components/ntp_background_images/browser/ntp_background_images_service.cc @@ -73,14 +73,14 @@ std::string HandleComponentData(const base::FilePath& installed_dir) { if (json_path.empty()) { // NTP sponsored component should have photo.json always but anything can // happen outside of browser. Handle it gracefully instead of crash. - DVLOG(2) << __func__ << ": Can't find valid manifest file in " - << installed_dir; + VLOG(6) << "Cannot find valid component manifest file in: " + << installed_dir; return contents; } bool success = base::ReadFileToString(json_path, &contents); if (!success || contents.empty()) { - DVLOG(2) << __func__ << ": cannot read json file " << json_path; + VLOG(6) << "Cannot read component manifest file at: " << json_path; return contents; } @@ -121,8 +121,8 @@ void NTPBackgroundImagesService::Init() { switches::kNTPSponsoredImagesDataPathForTesting)); if (!forced_local_path.empty()) { test_data_used_ = true; - DVLOG(2) << __func__ << ": NTP SI test data will be loaded" - << " from local path at: " << forced_local_path.LossyDisplayName(); + DVLOG(6) << "NTP SI test data will be loaded from local path at: " + << forced_local_path.LossyDisplayName(); OnSponsoredComponentReady(false, forced_local_path); } else { RegisterBackgroundImagesComponent(); @@ -142,9 +142,9 @@ void NTPBackgroundImagesService::Init() { switches::kNTPSuperReferralDataPathForTesting)); if (!forced_local_path_super_referral.empty()) { test_data_used_ = true; - DVLOG(2) << __func__ << ": NTP SR test data will be loaded" - << " from local path at: " - << forced_local_path_super_referral.LossyDisplayName(); + DVLOG(6) + << "NTP Super Referral test data will be loaded from local path at: " + << forced_local_path_super_referral.LossyDisplayName(); OnSponsoredComponentReady(false, forced_local_path_super_referral); } else { CheckSuperReferralComponent(); @@ -166,7 +166,7 @@ void NTPBackgroundImagesService::CheckNTPSIComponentUpdateIfNeeded() { void NTPBackgroundImagesService::CheckImagesComponentUpdate( const std::string& component_id) { - DVLOG(2) << __func__ << ": Check NTP Images component update"; + VLOG(6) << "Check for NTP Sponsored Images component update"; last_update_check_time_ = base::Time::Now(); si_update_check_timer_.Start( @@ -177,7 +177,7 @@ void NTPBackgroundImagesService::CheckImagesComponentUpdate( } void NTPBackgroundImagesService::RegisterBackgroundImagesComponent() { - DVLOG(2) << __func__ << ": Start NTP BI component"; + VLOG(6) << "Register NTP Background Images component"; RegisterNTPBackgroundImagesComponent( component_update_service_, base::BindRepeating(&NTPBackgroundImagesService::OnComponentReady, @@ -189,8 +189,8 @@ void NTPBackgroundImagesService::RegisterSponsoredImagesComponent() { const auto data = GetSponsoredImagesComponentData(country_code); if (!data) { - DVLOG(2) << __func__ << ": Not support NTP SI component for " - << country_code; + VLOG(6) << "NTP Sponsored Images component is not supported for " + << country_code; return; } @@ -204,7 +204,7 @@ void NTPBackgroundImagesService::RegisterSponsoredImagesComponent() { } sponsored_images_component_id_ = data->component_id.data(); - DVLOG(2) << __func__ << ": Start NTP SI component"; + VLOG(6) << "Register NTP Sposored Images component"; RegisterNTPSponsoredImagesComponent( component_update_service_, data->component_base64_public_key.data(), data->component_id.data(), @@ -238,7 +238,7 @@ void NTPBackgroundImagesService::CheckSuperReferralComponent() { const std::string cached_data = local_pref_->GetString( prefs::kNewTabPageCachedSuperReferralComponentData); if (!cached_data.empty()) { - DVLOG(2) << __func__ << ": Initialized SR Data from cache."; + DVLOG(6) << "Initialize Super Referral Data from cache."; sr_images_data_ = std::make_unique( cached_data, sr_installed_dir_); } @@ -275,9 +275,8 @@ void NTPBackgroundImagesService::CheckSuperReferralComponent() { !local_pref_->GetBoolean( prefs::kNewTabPageGetInitialSRComponentInProgress)) { MarkThisInstallIsNotSuperReferralForever(); - DVLOG(2) << __func__ << ": Cached SR Info is clean and Referral Service" - << " is not in initial state." - << " Mark this is not SR install."; + DVLOG(6) << "Cached SR Info is clean and Referral Service is not in " + "initial state. Mark this is not SR install."; return; } @@ -305,15 +304,15 @@ void NTPBackgroundImagesService::CheckSuperReferralComponent() { } } - DVLOG(2) << __func__ << ": This has invalid component info."; - DVLOG(2) << __func__ << ": In this case, this install is campaign ended super" - << " referral, default referral or non super referral."; + DVLOG(6) << "This has invalid component info. In this case, this install is " + "campaign ended super referral, default referral or non super " + "referral."; #endif // BUILDFLAG(IS_IOS) } void NTPBackgroundImagesService::MonitorReferralPromoCodeChange() { #if !BUILDFLAG(IS_IOS) - DVLOG(2) << __func__ << ": Monitor referral promo code change"; + DVLOG(6) << "Monitor for referral promo code change"; pref_change_registrar_.Add( kReferralPromoCode, @@ -327,18 +326,16 @@ void NTPBackgroundImagesService::OnPreferenceChanged( #if !BUILDFLAG(IS_IOS) DCHECK_EQ(kReferralPromoCode, pref_name); const std::string new_referral_code = GetReferralPromoCode(); - DVLOG(2) << __func__ << ": Got referral promo code: " - << new_referral_code; + DVLOG(6) << "Got referral promo code: " << new_referral_code; DCHECK(!new_referral_code.empty()); if (brave::BraveReferralsService::IsDefaultReferralCode(new_referral_code)) { - DVLOG(2) << __func__ << ": This has default referral promo code."; + DVLOG(6) << "This has default referral promo code."; MarkThisInstallIsNotSuperReferralForever(); return; } - DVLOG(2) << __func__ << ": This has non default referral promo code." - << " Let's check this code is super referral or not" - << " after downloading mapping table."; + DVLOG(6) << "This has non default referral promo code. Let's check this code " + "is super referral or not after downloading mapping table."; DownloadSuperReferralMappingTable(); #endif } @@ -348,7 +345,7 @@ void NTPBackgroundImagesService::OnCountryCodePrefChanged() { } void NTPBackgroundImagesService::RegisterSuperReferralComponent() { - DVLOG(2) << __func__ << ": Register NTP SR component"; + VLOG(6) << "Register NTP Super Referral component"; std::string public_key; std::string id; @@ -374,7 +371,7 @@ void NTPBackgroundImagesService::RegisterSuperReferralComponent() { } void NTPBackgroundImagesService::DownloadSuperReferralMappingTable() { - DVLOG(2) << __func__ << ": Try to download super referral mapping table."; + DVLOG(6) << "Try to download super referral mapping table."; if (!component_update_service_) return; @@ -392,8 +389,7 @@ void NTPBackgroundImagesService::OnMappingTableComponentReady( if (!local_pref_->FindPreference( prefs::kNewTabPageCachedSuperReferralComponentInfo)-> IsDefaultValue()) { - DVLOG(2) << __func__ - << ": We don't need to handle mapping table update now."; + DVLOG(6) << "We don't need to handle mapping table update now."; return; } @@ -407,7 +403,7 @@ void NTPBackgroundImagesService::OnMappingTableComponentReady( void NTPBackgroundImagesService::OnGetMappingTableData( const std::string& json_string) { if (json_string.empty()) { - DVLOG(2) << __func__ << ": Mapping table is empty."; + DVLOG(6) << "Mapping table is empty."; return; } @@ -415,21 +411,20 @@ void NTPBackgroundImagesService::OnGetMappingTableData( base::JSONReader::Read(json_string); if (!mapping_table_value) { - DVLOG(2) << __func__ << ": has invalid mapping table."; + DVLOG(6) << "Mapping table is invalid."; return; } if (!mapping_table_value->is_dict()) { - DVLOG(2) << __func__ << ": Mapping table is empty."; + DVLOG(6) << "Mapping table is empty."; return; } - DVLOG(2) << __func__ << ": Downloaded valid mapping table."; + DVLOG(6) << "Downloaded valid mapping table."; if (base::Value::Dict* value = mapping_table_value->GetDict().FindDict(GetReferralPromoCode())) { - DVLOG(2) << __func__ - << ": This is super referral. Cache SR's referral code"; + DVLOG(6) << "This is super referral. Cache SR's referral code"; initial_sr_component_info_ = std::move(*value); RegisterSuperReferralComponent(); local_pref_->SetString(prefs::kNewTabPageCachedSuperReferralCode, @@ -437,7 +432,7 @@ void NTPBackgroundImagesService::OnGetMappingTableData( return; } - DVLOG(2) << __func__ << ": This is non super referral."; + DVLOG(6) << "This is non super referral."; MarkThisInstallIsNotSuperReferralForever(); } @@ -496,7 +491,7 @@ void NTPBackgroundImagesService::OnComponentReady( const base::FilePath& installed_dir) { bi_installed_dir_ = installed_dir; - DVLOG(2) << __func__ << ": NTP BI Component is ready"; + VLOG(6) << "NTP Background Images Component is ready"; base::ThreadPool::PostTaskAndReplyWithResult( FROM_HERE, {base::MayBlock()}, @@ -523,8 +518,8 @@ void NTPBackgroundImagesService::OnSponsoredComponentReady( else si_installed_dir_ = installed_dir; - DVLOG(2) << __func__ << (is_super_referral ? ": NPT SR Component is ready" - : ": NTP SI Component is ready"); + VLOG(6) << (is_super_referral ? "NPT Super Referral Component is ready" + : "NTP Sponsored Images Component is ready"); base::ThreadPool::PostTaskAndReplyWithResult( FROM_HERE, {base::MayBlock()}, @@ -557,7 +552,7 @@ void NTPBackgroundImagesService::OnGetSponsoredComponentJsonData( } if (is_super_referral && !sr_images_data_->IsValid()) { - DVLOG(2) << __func__ << ": NTP SR campaign ends."; + DVLOG(6) << "NTP Super Referral campaign ends."; UnRegisterSuperReferralComponent(); MarkThisInstallIsNotSuperReferralForever(); return; @@ -595,7 +590,7 @@ void NTPBackgroundImagesService::UnRegisterSuperReferralComponent() { const auto& value = local_pref_->GetDict(prefs::kNewTabPageCachedSuperReferralComponentInfo); const std::string sr_component_id = *value.FindString(kComponentIDKey); - DVLOG(2) << __func__ << ": Unregister NTP SR component"; + VLOG(6) << "Unregister NTP Super Referral component"; component_update_service_->UnregisterComponent(sr_component_id); }