OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/push_messaging/push_messaging_notification_manager.h" | 5 #include "chrome/browser/push_messaging/push_messaging_notification_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <bitset> | 9 #include <bitset> |
10 | 10 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 platform_notification_service->ClosePersistentNotification( | 179 platform_notification_service->ClosePersistentNotification( |
180 profile_, notification_database_data.notification_id); | 180 profile_, notification_database_data.notification_id); |
181 platform_notification_service->OnPersistentNotificationClose( | 181 platform_notification_service->OnPersistentNotificationClose( |
182 profile_, notification_database_data.notification_id, | 182 profile_, notification_database_data.notification_id, |
183 notification_database_data.origin, false /* by_user */); | 183 notification_database_data.origin, false /* by_user */); |
184 | 184 |
185 break; | 185 break; |
186 } | 186 } |
187 } | 187 } |
188 | 188 |
189 // Get the budget for the service worker. This will internally record UMA | 189 // Get the budget for the service worker. |
190 // for budget development work in the future. | |
191 BackgroundBudgetService* service = | 190 BackgroundBudgetService* service = |
192 BackgroundBudgetServiceFactory::GetForProfile(profile_); | 191 BackgroundBudgetServiceFactory::GetForProfile(profile_); |
193 double budget = service->GetBudget(origin); | 192 service->GetBudget( |
| 193 origin, |
| 194 base::Bind(&PushMessagingNotificationManager::DidGetBudget, |
| 195 weak_factory_.GetWeakPtr(), origin, |
| 196 service_worker_registration_id, message_handled_closure, |
| 197 notification_needed, notification_shown)); |
| 198 } |
194 | 199 |
| 200 void PushMessagingNotificationManager::DidGetBudget( |
| 201 const GURL& origin, |
| 202 int64_t service_worker_registration_id, |
| 203 const base::Closure& message_handled_closure, |
| 204 bool notification_needed, |
| 205 bool notification_shown, |
| 206 const double budget) { |
195 // Record the budget available any time the budget is queried. | 207 // Record the budget available any time the budget is queried. |
196 UMA_HISTOGRAM_COUNTS_100("PushMessaging.BackgroundBudget", budget); | 208 UMA_HISTOGRAM_COUNTS_100("PushMessaging.BackgroundBudget", budget); |
197 | 209 |
198 // Get the site engagement score. Only used for UMA recording. | 210 // Get the site engagement score. Only used for UMA recording. |
199 SiteEngagementService* ses_service = SiteEngagementService::Get(profile_); | 211 SiteEngagementService* ses_service = SiteEngagementService::Get(profile_); |
200 double ses_score = ses_service->GetScore(origin); | 212 double ses_score = ses_service->GetScore(origin); |
201 | 213 |
202 // Generate histograms for the GetBudget calls which would return "no budget" | 214 // Generate histograms for the GetBudget calls which would return "no budget" |
203 // or "low budget" if an API was available to app developers. | 215 // or "low budget" if an API was available to app developers. |
204 double cost = BackgroundBudgetService::GetCost( | 216 double cost = BackgroundBudgetService::GetCost( |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 int64_t service_worker_registration_id, | 280 int64_t service_worker_registration_id, |
269 const base::Closure& message_handled_closure, | 281 const base::Closure& message_handled_closure, |
270 const double budget) { | 282 const double budget) { |
271 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 283 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
272 | 284 |
273 // If the service needed to show a notification but did not, update the | 285 // If the service needed to show a notification but did not, update the |
274 // budget. | 286 // budget. |
275 double cost = BackgroundBudgetService::GetCost( | 287 double cost = BackgroundBudgetService::GetCost( |
276 BackgroundBudgetService::CostType::SILENT_PUSH); | 288 BackgroundBudgetService::CostType::SILENT_PUSH); |
277 if (budget >= cost) { | 289 if (budget >= cost) { |
278 // Update the stored budget. | 290 RecordUserVisibleStatus( |
| 291 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_USED_GRACE); |
| 292 |
279 BackgroundBudgetService* service = | 293 BackgroundBudgetService* service = |
280 BackgroundBudgetServiceFactory::GetForProfile(profile_); | 294 BackgroundBudgetServiceFactory::GetForProfile(profile_); |
281 service->StoreBudget(origin, budget - cost); | 295 // Update the stored budget. |
| 296 service->StoreBudget(origin, budget - cost, message_handled_closure); |
282 | 297 |
283 RecordUserVisibleStatus( | |
284 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_USED_GRACE); | |
285 message_handled_closure.Run(); | |
286 return; | 298 return; |
287 } | 299 } |
288 | 300 |
289 RecordUserVisibleStatus( | 301 RecordUserVisibleStatus( |
290 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_GRACE_EXCEEDED); | 302 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_GRACE_EXCEEDED); |
291 rappor::SampleDomainAndRegistryFromGURL( | 303 rappor::SampleDomainAndRegistryFromGURL( |
292 g_browser_process->rappor_service(), | 304 g_browser_process->rappor_service(), |
293 "PushMessaging.GenericNotificationShown.Origin", origin); | 305 "PushMessaging.GenericNotificationShown.Origin", origin); |
294 | 306 |
295 // The site failed to show a notification when one was needed, and they don't | 307 // The site failed to show a notification when one was needed, and they don't |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 message_handled_closure.Run(); | 350 message_handled_closure.Run(); |
339 return; | 351 return; |
340 } | 352 } |
341 | 353 |
342 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( | 354 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( |
343 profile_, persistent_notification_id, origin, notification_data, | 355 profile_, persistent_notification_id, origin, notification_data, |
344 NotificationResources()); | 356 NotificationResources()); |
345 | 357 |
346 message_handled_closure.Run(); | 358 message_handled_closure.Run(); |
347 } | 359 } |
OLD | NEW |