| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 profile_, notification_database_data.notification_id, | 182 profile_, notification_database_data.notification_id, |
| 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 // Don't track push messages that didn't show a notification but were exempt | 189 // Don't track push messages that didn't show a notification but were exempt |
| 189 // from needing to do so. | 190 // from needing to do so. |
| 190 if (notification_shown || notification_needed) { | 191 if (notification_shown || notification_needed) { |
| 191 std::string notification_history = | 192 BackgroundBudgetService* service = |
| 192 BackgroundBudgetService::GetBudget(profile_, origin); | 193 BackgroundBudgetServiceFactory::GetForProfile(profile_); |
| 194 std::string notification_history = service->GetBudget(origin); |
| 193 DidGetBudget(origin, service_worker_registration_id, notification_shown, | 195 DidGetBudget(origin, service_worker_registration_id, notification_shown, |
| 194 notification_needed, message_handled_closure, | 196 notification_needed, message_handled_closure, |
| 195 notification_history); | 197 notification_history); |
| 196 } else { | 198 } else { |
| 197 RecordUserVisibleStatus( | 199 RecordUserVisibleStatus( |
| 198 content::PUSH_USER_VISIBLE_STATUS_NOT_REQUIRED_AND_NOT_SHOWN); | 200 content::PUSH_USER_VISIBLE_STATUS_NOT_REQUIRED_AND_NOT_SHOWN); |
| 199 message_handled_closure.Run(); | 201 message_handled_closure.Run(); |
| 200 } | 202 } |
| 201 } | 203 } |
| 202 | 204 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 252 |
| 251 DCHECK(notification_shown || notification_needed); // Caller must ensure this | 253 DCHECK(notification_shown || notification_needed); // Caller must ensure this |
| 252 bool needed_but_not_shown = notification_needed && !notification_shown; | 254 bool needed_but_not_shown = notification_needed && !notification_shown; |
| 253 | 255 |
| 254 // New entries go at the end, and old ones are shifted off the beginning once | 256 // New entries go at the end, and old ones are shifted off the beginning once |
| 255 // the history length is exceeded. | 257 // the history length is exceeded. |
| 256 missed_notifications <<= 1; | 258 missed_notifications <<= 1; |
| 257 missed_notifications[0] = needed_but_not_shown; | 259 missed_notifications[0] = needed_but_not_shown; |
| 258 std::string updated_data(missed_notifications. | 260 std::string updated_data(missed_notifications. |
| 259 to_string<char, std::string::traits_type, std::string::allocator_type>()); | 261 to_string<char, std::string::traits_type, std::string::allocator_type>()); |
| 260 BackgroundBudgetService::StoreBudget(profile_, origin, updated_data); | 262 BackgroundBudgetService* service = |
| 263 BackgroundBudgetServiceFactory::GetForProfile(profile_); |
| 264 service->StoreBudget(origin, updated_data); |
| 261 | 265 |
| 262 if (notification_shown) { | 266 if (notification_shown) { |
| 263 RecordUserVisibleStatus( | 267 RecordUserVisibleStatus( |
| 264 notification_needed | 268 notification_needed |
| 265 ? content::PUSH_USER_VISIBLE_STATUS_REQUIRED_AND_SHOWN | 269 ? content::PUSH_USER_VISIBLE_STATUS_REQUIRED_AND_SHOWN |
| 266 : content::PUSH_USER_VISIBLE_STATUS_NOT_REQUIRED_BUT_SHOWN); | 270 : content::PUSH_USER_VISIBLE_STATUS_NOT_REQUIRED_BUT_SHOWN); |
| 267 message_handled_closure.Run(); | 271 message_handled_closure.Run(); |
| 268 return; | 272 return; |
| 269 } | 273 } |
| 270 DCHECK(needed_but_not_shown); | 274 DCHECK(needed_but_not_shown); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 message_handled_closure.Run(); | 330 message_handled_closure.Run(); |
| 327 return; | 331 return; |
| 328 } | 332 } |
| 329 | 333 |
| 330 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( | 334 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( |
| 331 profile_, persistent_notification_id, origin, notification_data, | 335 profile_, persistent_notification_id, origin, notification_data, |
| 332 NotificationResources()); | 336 NotificationResources()); |
| 333 | 337 |
| 334 message_handled_closure.Run(); | 338 message_handled_closure.Run(); |
| 335 } | 339 } |
| OLD | NEW |