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 13 matching lines...) Expand all Loading... |
24 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/platform_notification_context.h" | 26 #include "content/public/browser/platform_notification_context.h" |
27 #include "content/public/browser/push_messaging_service.h" | 27 #include "content/public/browser/push_messaging_service.h" |
28 #include "content/public/browser/render_frame_host.h" | 28 #include "content/public/browser/render_frame_host.h" |
29 #include "content/public/browser/storage_partition.h" | 29 #include "content/public/browser/storage_partition.h" |
30 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
31 #include "content/public/common/notification_resources.h" | 31 #include "content/public/common/notification_resources.h" |
32 #include "content/public/common/url_constants.h" | 32 #include "content/public/common/url_constants.h" |
33 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 33 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 34 #include "third_party/WebKit/public/platform/modules/budget_service/budget_servi
ce.mojom.h" |
34 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
35 #include "url/gurl.h" | 36 #include "url/gurl.h" |
36 | 37 |
37 #if BUILDFLAG(ANDROID_JAVA_UI) | 38 #if BUILDFLAG(ANDROID_JAVA_UI) |
38 #include "chrome/browser/ui/android/tab_model/tab_model.h" | 39 #include "chrome/browser/ui/android/tab_model/tab_model.h" |
39 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 40 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
40 #else | 41 #else |
41 #include "chrome/browser/ui/browser.h" | 42 #include "chrome/browser/ui/browser.h" |
42 #include "chrome/browser/ui/browser_list.h" | 43 #include "chrome/browser/ui/browser_list.h" |
43 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 44 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 const double budget) { | 206 const double budget) { |
206 // Record the budget available any time the budget is queried. | 207 // Record the budget available any time the budget is queried. |
207 UMA_HISTOGRAM_COUNTS_100("PushMessaging.BackgroundBudget", budget); | 208 UMA_HISTOGRAM_COUNTS_100("PushMessaging.BackgroundBudget", budget); |
208 | 209 |
209 // Get the site engagement score. Only used for UMA recording. | 210 // Get the site engagement score. Only used for UMA recording. |
210 SiteEngagementService* ses_service = SiteEngagementService::Get(profile_); | 211 SiteEngagementService* ses_service = SiteEngagementService::Get(profile_); |
211 double ses_score = ses_service->GetScore(origin); | 212 double ses_score = ses_service->GetScore(origin); |
212 | 213 |
213 // Generate histograms for the GetBudget calls which would return "no budget" | 214 // Generate histograms for the GetBudget calls which would return "no budget" |
214 // or "low budget" if an API was available to app developers. | 215 // or "low budget" if an API was available to app developers. |
215 double cost = BudgetManager::GetCost(BudgetManager::CostType::SILENT_PUSH); | 216 double cost = |
| 217 BudgetManager::GetCost(blink::mojom::BudgetOperationType::SILENT_PUSH); |
216 if (budget < cost) | 218 if (budget < cost) |
217 UMA_HISTOGRAM_COUNTS_100("PushMessaging.SESForNoBudgetOrigin", ses_score); | 219 UMA_HISTOGRAM_COUNTS_100("PushMessaging.SESForNoBudgetOrigin", ses_score); |
218 else if (budget < 2.0 * cost) | 220 else if (budget < 2.0 * cost) |
219 UMA_HISTOGRAM_COUNTS_100("PushMessaging.SESForLowBudgetOrigin", ses_score); | 221 UMA_HISTOGRAM_COUNTS_100("PushMessaging.SESForLowBudgetOrigin", ses_score); |
220 | 222 |
221 if (notification_needed && !notification_shown) { | 223 if (notification_needed && !notification_shown) { |
222 // If the worker needed to show a notification and didn't, check the budget | 224 // If the worker needed to show a notification and didn't, check the budget |
223 // and take appropriate action. | 225 // and take appropriate action. |
224 CheckForMissedNotification(origin, service_worker_registration_id, | 226 CheckForMissedNotification(origin, service_worker_registration_id, |
225 message_handled_closure, budget); | 227 message_handled_closure, budget); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 277 |
276 void PushMessagingNotificationManager::CheckForMissedNotification( | 278 void PushMessagingNotificationManager::CheckForMissedNotification( |
277 const GURL& origin, | 279 const GURL& origin, |
278 int64_t service_worker_registration_id, | 280 int64_t service_worker_registration_id, |
279 const base::Closure& message_handled_closure, | 281 const base::Closure& message_handled_closure, |
280 const double budget) { | 282 const double budget) { |
281 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 283 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
282 | 284 |
283 // 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 |
284 // budget. | 286 // budget. |
285 double cost = BudgetManager::GetCost(BudgetManager::CostType::SILENT_PUSH); | 287 double cost = |
| 288 BudgetManager::GetCost(blink::mojom::BudgetOperationType::SILENT_PUSH); |
286 if (budget >= cost) { | 289 if (budget >= cost) { |
287 RecordUserVisibleStatus( | 290 RecordUserVisibleStatus( |
288 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_USED_GRACE); | 291 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_USED_GRACE); |
289 | 292 |
290 BudgetManager* manager = BudgetManagerFactory::GetForProfile(profile_); | 293 BudgetManager* manager = BudgetManagerFactory::GetForProfile(profile_); |
291 // Update the stored budget. | 294 // Update the stored budget. |
292 manager->StoreBudget(origin, budget - cost, message_handled_closure); | 295 manager->StoreBudget(origin, budget - cost, message_handled_closure); |
293 | 296 |
294 return; | 297 return; |
295 } | 298 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 // Do not pass service worker scope. The origin will be used instead of the | 353 // Do not pass service worker scope. The origin will be used instead of the |
351 // service worker scope to determine whether a notification should be | 354 // service worker scope to determine whether a notification should be |
352 // attributed to a WebAPK on Android. This is OK because this code path is hit | 355 // attributed to a WebAPK on Android. This is OK because this code path is hit |
353 // rarely. | 356 // rarely. |
354 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( | 357 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( |
355 profile_, persistent_notification_id, GURL() /* service_worker_scope */, | 358 profile_, persistent_notification_id, GURL() /* service_worker_scope */, |
356 origin, notification_data, NotificationResources()); | 359 origin, notification_data, NotificationResources()); |
357 | 360 |
358 message_handled_closure.Run(); | 361 message_handled_closure.Run(); |
359 } | 362 } |
OLD | NEW |