| 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 4574d1e1324de197428f5dc44864c94350ef4cb9..82195cd6a358dfdf1c80b51242de84a82d57fb75 100644
|
| --- a/chrome/browser/push_messaging/push_messaging_notification_manager.cc
|
| +++ b/chrome/browser/push_messaging/push_messaging_notification_manager.cc
|
| @@ -52,10 +52,6 @@ using content::ServiceWorkerContext;
|
| using content::WebContents;
|
|
|
| namespace {
|
| -// Currently this just costs 1.0, but we may expand the cost to
|
| -// include things like whether wifi is available in the mobile case.
|
| -const double kBackgroundProcessingCost = 1.0;
|
| -
|
| void RecordUserVisibleStatus(content::PushUserVisibleStatus status) {
|
| UMA_HISTOGRAM_ENUMERATION("PushMessaging.UserVisibleStatus", status,
|
| content::PUSH_USER_VISIBLE_STATUS_LAST + 1);
|
| @@ -189,14 +185,20 @@ void PushMessagingNotificationManager::DidGetNotificationsFromDatabase(
|
| }
|
| }
|
|
|
| + // Get the budget for the service worker. This will internally record UMA
|
| + // for budget development work in the future.
|
| + BackgroundBudgetService* service =
|
| + BackgroundBudgetServiceFactory::GetForProfile(profile_);
|
| + double budget = service->GetBudget(origin);
|
| +
|
| + // Record the budget available any time the budget is queried.
|
| + UMA_HISTOGRAM_COUNTS("PushMessaging.BackgroundBudget", budget);
|
| +
|
| if (notification_needed && !notification_shown) {
|
| - // Only track budget for messages that needed to show a notification but
|
| - // did not.
|
| - BackgroundBudgetService* service =
|
| - BackgroundBudgetServiceFactory::GetForProfile(profile_);
|
| - double budget = service->GetBudget(origin);
|
| - DidGetBudget(origin, service_worker_registration_id,
|
| - message_handled_closure, budget);
|
| + // 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);
|
| return;
|
| }
|
|
|
| @@ -247,7 +249,7 @@ bool PushMessagingNotificationManager::IsTabVisible(
|
| return visible_url.GetOrigin() == origin;
|
| }
|
|
|
| -void PushMessagingNotificationManager::DidGetBudget(
|
| +void PushMessagingNotificationManager::CheckForMissedNotification(
|
| const GURL& origin,
|
| int64_t service_worker_registration_id,
|
| const base::Closure& message_handled_closure,
|
| @@ -256,11 +258,14 @@ void PushMessagingNotificationManager::DidGetBudget(
|
|
|
| // If the service needed to show a notification but did not, update the
|
| // budget.
|
| - if (budget >= kBackgroundProcessingCost) {
|
| + double background_processing_cost =
|
| + BackgroundBudgetService::GetBackgroundProcessingCost(
|
| + BackgroundBudgetService::SILENT_PUSH_COST);
|
| + if (budget >= background_processing_cost) {
|
| // Update the stored budget.
|
| BackgroundBudgetService* service =
|
| BackgroundBudgetServiceFactory::GetForProfile(profile_);
|
| - service->StoreBudget(origin, budget - kBackgroundProcessingCost);
|
| + service->StoreBudget(origin, budget - background_processing_cost);
|
|
|
| RecordUserVisibleStatus(
|
| content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_USED_GRACE);
|
| @@ -274,9 +279,9 @@ void PushMessagingNotificationManager::DidGetBudget(
|
| g_browser_process->rappor_service(),
|
| "PushMessaging.GenericNotificationShown.Origin", origin);
|
|
|
| - // The site failed to show a notification when one was needed, and they have
|
| - // already failed once in the previous 10 push messages, so we will show a
|
| - // generic notification. See https://crbug.com/437277.
|
| + // The site failed to show a notification when one was needed, and they don't
|
| + // have enough budget to cover the cost of suppressing, so we will show a
|
| + // generic notification.
|
| NotificationDatabaseData database_data =
|
| CreateDatabaseData(origin, service_worker_registration_id);
|
| scoped_refptr<PlatformNotificationContext> notification_context =
|
|
|