| 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 |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 14 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/push_messaging/background_budget_service.h" | 16 #include "chrome/browser/push_messaging/background_budget_service.h" |
| 17 #include "chrome/browser/push_messaging/background_budget_service_factory.h" |
| 17 #include "chrome/browser/push_messaging/push_messaging_constants.h" | 18 #include "chrome/browser/push_messaging/push_messaging_constants.h" |
| 18 #include "chrome/common/features.h" | 19 #include "chrome/common/features.h" |
| 19 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
| 20 #include "components/rappor/rappor_utils.h" | 21 #include "components/rappor/rappor_utils.h" |
| 21 #include "components/url_formatter/elide_url.h" | 22 #include "components/url_formatter/elide_url.h" |
| 22 #include "content/public/browser/browser_context.h" | 23 #include "content/public/browser/browser_context.h" |
| 23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/platform_notification_context.h" | 25 #include "content/public/browser/platform_notification_context.h" |
| 25 #include "content/public/browser/push_messaging_service.h" | 26 #include "content/public/browser/push_messaging_service.h" |
| 26 #include "content/public/browser/render_frame_host.h" | 27 #include "content/public/browser/render_frame_host.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 notification_database_data.origin, false /* by_user */); | 183 notification_database_data.origin, false /* by_user */); |
| 183 | 184 |
| 184 break; | 185 break; |
| 185 } | 186 } |
| 186 } | 187 } |
| 187 | 188 |
| 188 if (notification_needed && !notification_shown) { | 189 if (notification_needed && !notification_shown) { |
| 189 // Only track budget for messages that needed to show a notification but | 190 // Only track budget for messages that needed to show a notification but |
| 190 // did not. | 191 // did not. |
| 191 double budget = 0; | 192 double budget = 0; |
| 192 BackgroundBudgetService::GetBudget(profile_, origin, budget); | 193 BackgroundBudgetService* service = |
| 194 BackgroundBudgetServiceFactory::GetForProfile(profile_); |
| 195 service->GetBudget(origin, budget); |
| 193 DidGetBudget(origin, service_worker_registration_id, | 196 DidGetBudget(origin, service_worker_registration_id, |
| 194 message_handled_closure, budget); | 197 message_handled_closure, budget); |
| 195 return; | 198 return; |
| 196 } | 199 } |
| 197 | 200 |
| 198 if (notification_needed && notification_shown) { | 201 if (notification_needed && notification_shown) { |
| 199 RecordUserVisibleStatus( | 202 RecordUserVisibleStatus( |
| 200 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_AND_SHOWN); | 203 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_AND_SHOWN); |
| 201 } else if (!notification_needed && !notification_shown) { | 204 } else if (!notification_needed && !notification_shown) { |
| 202 RecordUserVisibleStatus( | 205 RecordUserVisibleStatus( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 const base::Closure& message_handled_closure, | 251 const base::Closure& message_handled_closure, |
| 249 const double budget) { | 252 const double budget) { |
| 250 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 253 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 251 | 254 |
| 252 // If the service needed to show a notification but did not, update the | 255 // If the service needed to show a notification but did not, update the |
| 253 // budget. Currently this just subtracts 1.0, but we may expand the cost to | 256 // budget. Currently this just subtracts 1.0, but we may expand the cost to |
| 254 // include things like whether wifi is available in the mobile case. | 257 // include things like whether wifi is available in the mobile case. |
| 255 double cost = 1.0; | 258 double cost = 1.0; |
| 256 if (budget >= cost) { | 259 if (budget >= cost) { |
| 257 // Update the stored budget. | 260 // Update the stored budget. |
| 258 BackgroundBudgetService::StoreBudget(profile_, origin, budget - cost); | 261 BackgroundBudgetService* service = |
| 262 BackgroundBudgetServiceFactory::GetForProfile(profile_); |
| 263 service->StoreBudget(origin, budget - cost); |
| 259 | 264 |
| 260 RecordUserVisibleStatus( | 265 RecordUserVisibleStatus( |
| 261 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_USED_GRACE); | 266 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_USED_GRACE); |
| 262 message_handled_closure.Run(); | 267 message_handled_closure.Run(); |
| 263 return; | 268 return; |
| 264 } | 269 } |
| 265 | 270 |
| 266 RecordUserVisibleStatus( | 271 RecordUserVisibleStatus( |
| 267 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_GRACE_EXCEEDED); | 272 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_GRACE_EXCEEDED); |
| 268 rappor::SampleDomainAndRegistryFromGURL( | 273 rappor::SampleDomainAndRegistryFromGURL( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 message_handled_closure.Run(); | 320 message_handled_closure.Run(); |
| 316 return; | 321 return; |
| 317 } | 322 } |
| 318 | 323 |
| 319 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( | 324 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( |
| 320 profile_, persistent_notification_id, origin, notification_data, | 325 profile_, persistent_notification_id, origin, notification_data, |
| 321 NotificationResources()); | 326 NotificationResources()); |
| 322 | 327 |
| 323 message_handled_closure.Run(); | 328 message_handled_closure.Run(); |
| 324 } | 329 } |
| OLD | NEW |