Chromium Code Reviews| 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..0c531351b95124e662b6c83098c24b30e32bc7dc 100644 |
| --- a/chrome/browser/push_messaging/push_messaging_notification_manager.cc |
| +++ b/chrome/browser/push_messaging/push_messaging_notification_manager.cc |
| @@ -52,15 +52,15 @@ 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); |
| } |
| +void RecordBackgroundBudget(double budget) { |
|
Peter Beverloo
2016/05/17 11:04:34
dito re: inline
harkness
2016/05/17 13:08:16
Done.
|
| + UMA_HISTOGRAM_COUNTS("PushMessaging.BackgroundBudget", budget); |
| +} |
| + |
| content::StoragePartition* GetStoragePartition(Profile* profile, |
| const GURL& origin) { |
| return content::BrowserContext::GetStoragePartitionForSite(profile, origin); |
| @@ -189,14 +189,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. |
| + RecordBackgroundBudget(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 +253,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 +262,13 @@ void PushMessagingNotificationManager::DidGetBudget( |
| // If the service needed to show a notification but did not, update the |
| // budget. |
| - if (budget >= kBackgroundProcessingCost) { |
| + double backgroundProcessingCost = |
|
Peter Beverloo
2016/05/17 11:04:34
nit: background_processing_cost
harkness
2016/05/17 13:08:16
Done.
|
| + BackgroundBudgetService::GetBackgroundProcessingCost(); |
| + if (budget >= backgroundProcessingCost) { |
| // Update the stored budget. |
| BackgroundBudgetService* service = |
| BackgroundBudgetServiceFactory::GetForProfile(profile_); |
| - service->StoreBudget(origin, budget - kBackgroundProcessingCost); |
| + service->StoreBudget(origin, budget - backgroundProcessingCost); |
| RecordUserVisibleStatus( |
| content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_USED_GRACE); |
| @@ -274,9 +282,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 = |