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

Unified Diff: chrome/browser/push_messaging/push_messaging_notification_manager.cc

Issue 2281673002: Full hookup of BudgetManager interfaces to BudgetDatabase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@manager
Patch Set: nits Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/push_messaging/push_messaging_notification_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/push_messaging/push_messaging_notification_manager.cc
diff --git a/chrome/browser/push_messaging/push_messaging_notification_manager.cc b/chrome/browser/push_messaging/push_messaging_notification_manager.cc
index 0050c182d3af5f8bcd026e17748a867bd2dd648c..1568a412865ec0a6a58f3744178b4053c562a15c 100644
--- a/chrome/browser/push_messaging/push_messaging_notification_manager.cc
+++ b/chrome/browser/push_messaging/push_messaging_notification_manager.cc
@@ -187,44 +187,15 @@ void PushMessagingNotificationManager::DidGetNotificationsFromDatabase(
}
}
- // Get the budget for the origin.
- BudgetManager* manager = BudgetManagerFactory::GetForProfile(profile_);
- manager->GetBudget(
- origin,
- base::Bind(&PushMessagingNotificationManager::DidGetBudget,
- weak_factory_.GetWeakPtr(), origin,
- service_worker_registration_id, message_handled_closure,
- notification_needed, notification_shown));
-}
-
-void PushMessagingNotificationManager::DidGetBudget(
- const GURL& origin,
- int64_t service_worker_registration_id,
- const base::Closure& message_handled_closure,
- bool notification_needed,
- bool notification_shown,
- const double budget) {
- // Record the budget available any time the budget is queried.
- UMA_HISTOGRAM_COUNTS_100("PushMessaging.BackgroundBudget", budget);
-
- // Get the site engagement score. Only used for UMA recording.
- SiteEngagementService* ses_service = SiteEngagementService::Get(profile_);
- double ses_score = ses_service->GetScore(origin);
-
- // Generate histograms for the GetBudget calls which would return "no budget"
- // or "low budget" if an API was available to app developers.
- double cost =
- BudgetManager::GetCost(blink::mojom::BudgetOperationType::SILENT_PUSH);
- if (budget < cost)
- UMA_HISTOGRAM_COUNTS_100("PushMessaging.SESForNoBudgetOrigin", ses_score);
- else if (budget < 2.0 * cost)
- UMA_HISTOGRAM_COUNTS_100("PushMessaging.SESForLowBudgetOrigin", ses_score);
-
if (notification_needed && !notification_shown) {
- // If the worker needed to show a notification and didn't, check the budget
- // and take appropriate action.
- CheckForMissedNotification(origin, service_worker_registration_id,
- message_handled_closure, budget);
+ // If the worker needed to show a notification and didn't, see if a silent
+ // push was allowed.
+ BudgetManager* manager = BudgetManagerFactory::GetForProfile(profile_);
+ manager->Consume(
+ origin, blink::mojom::BudgetOperationType::SILENT_PUSH,
+ base::Bind(&PushMessagingNotificationManager::ProcessSilentPush,
+ weak_factory_.GetWeakPtr(), origin,
+ service_worker_registration_id, message_handled_closure));
return;
}
@@ -275,25 +246,18 @@ bool PushMessagingNotificationManager::IsTabVisible(
return visible_url.GetOrigin() == origin;
}
-void PushMessagingNotificationManager::CheckForMissedNotification(
+void PushMessagingNotificationManager::ProcessSilentPush(
const GURL& origin,
int64_t service_worker_registration_id,
const base::Closure& message_handled_closure,
- const double budget) {
+ bool silent_push_allowed) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- // If the service needed to show a notification but did not, update the
- // budget.
- double cost =
- BudgetManager::GetCost(blink::mojom::BudgetOperationType::SILENT_PUSH);
- if (budget >= cost) {
+ // If the origin was allowed to issue a silent push, just return.
+ if (silent_push_allowed) {
RecordUserVisibleStatus(
content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_USED_GRACE);
-
- BudgetManager* manager = BudgetManagerFactory::GetForProfile(profile_);
- // Update the stored budget.
- manager->StoreBudget(origin, budget - cost, message_handled_closure);
-
+ message_handled_closure.Run();
return;
}
« no previous file with comments | « chrome/browser/push_messaging/push_messaging_notification_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698