Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: chrome/browser/push_messaging/push_messaging_notification_manager.cc

Issue 2281673002: Full hookup of BudgetManager interfaces to BudgetDatabase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@manager
Patch Set: nits Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/push_messaging/push_messaging_notification_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 platform_notification_service->ClosePersistentNotification( 180 platform_notification_service->ClosePersistentNotification(
181 profile_, notification_database_data.notification_id); 181 profile_, notification_database_data.notification_id);
182 platform_notification_service->OnPersistentNotificationClose( 182 platform_notification_service->OnPersistentNotificationClose(
183 profile_, notification_database_data.notification_id, 183 profile_, notification_database_data.notification_id,
184 notification_database_data.origin, false /* by_user */); 184 notification_database_data.origin, false /* by_user */);
185 185
186 break; 186 break;
187 } 187 }
188 } 188 }
189 189
190 // Get the budget for the origin.
191 BudgetManager* manager = BudgetManagerFactory::GetForProfile(profile_);
192 manager->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 }
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) {
207 // Record the budget available any time the budget is queried.
208 UMA_HISTOGRAM_COUNTS_100("PushMessaging.BackgroundBudget", budget);
209
210 // Get the site engagement score. Only used for UMA recording.
211 SiteEngagementService* ses_service = SiteEngagementService::Get(profile_);
212 double ses_score = ses_service->GetScore(origin);
213
214 // Generate histograms for the GetBudget calls which would return "no budget"
215 // or "low budget" if an API was available to app developers.
216 double cost =
217 BudgetManager::GetCost(blink::mojom::BudgetOperationType::SILENT_PUSH);
218 if (budget < cost)
219 UMA_HISTOGRAM_COUNTS_100("PushMessaging.SESForNoBudgetOrigin", ses_score);
220 else if (budget < 2.0 * cost)
221 UMA_HISTOGRAM_COUNTS_100("PushMessaging.SESForLowBudgetOrigin", ses_score);
222
223 if (notification_needed && !notification_shown) { 190 if (notification_needed && !notification_shown) {
224 // If the worker needed to show a notification and didn't, check the budget 191 // If the worker needed to show a notification and didn't, see if a silent
225 // and take appropriate action. 192 // push was allowed.
226 CheckForMissedNotification(origin, service_worker_registration_id, 193 BudgetManager* manager = BudgetManagerFactory::GetForProfile(profile_);
227 message_handled_closure, budget); 194 manager->Consume(
195 origin, blink::mojom::BudgetOperationType::SILENT_PUSH,
196 base::Bind(&PushMessagingNotificationManager::ProcessSilentPush,
197 weak_factory_.GetWeakPtr(), origin,
198 service_worker_registration_id, message_handled_closure));
228 return; 199 return;
229 } 200 }
230 201
231 if (notification_needed && notification_shown) { 202 if (notification_needed && notification_shown) {
232 RecordUserVisibleStatus( 203 RecordUserVisibleStatus(
233 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_AND_SHOWN); 204 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_AND_SHOWN);
234 } else if (!notification_needed && !notification_shown) { 205 } else if (!notification_needed && !notification_shown) {
235 RecordUserVisibleStatus( 206 RecordUserVisibleStatus(
236 content::PUSH_USER_VISIBLE_STATUS_NOT_REQUIRED_AND_NOT_SHOWN); 207 content::PUSH_USER_VISIBLE_STATUS_NOT_REQUIRED_AND_NOT_SHOWN);
237 } else { 208 } else {
(...skipping 30 matching lines...) Expand all
268 239
269 // view-source: pages are considered to be controlled Service Worker clients 240 // view-source: pages are considered to be controlled Service Worker clients
270 // and thus should be considered when checking the visible URL. However, the 241 // and thus should be considered when checking the visible URL. However, the
271 // prefix has to be removed before the origins can be compared. 242 // prefix has to be removed before the origins can be compared.
272 if (visible_url.SchemeIs(content::kViewSourceScheme)) 243 if (visible_url.SchemeIs(content::kViewSourceScheme))
273 visible_url = GURL(visible_url.GetContent()); 244 visible_url = GURL(visible_url.GetContent());
274 245
275 return visible_url.GetOrigin() == origin; 246 return visible_url.GetOrigin() == origin;
276 } 247 }
277 248
278 void PushMessagingNotificationManager::CheckForMissedNotification( 249 void PushMessagingNotificationManager::ProcessSilentPush(
279 const GURL& origin, 250 const GURL& origin,
280 int64_t service_worker_registration_id, 251 int64_t service_worker_registration_id,
281 const base::Closure& message_handled_closure, 252 const base::Closure& message_handled_closure,
282 const double budget) { 253 bool silent_push_allowed) {
283 DCHECK_CURRENTLY_ON(BrowserThread::UI); 254 DCHECK_CURRENTLY_ON(BrowserThread::UI);
284 255
285 // If the service needed to show a notification but did not, update the 256 // If the origin was allowed to issue a silent push, just return.
286 // budget. 257 if (silent_push_allowed) {
287 double cost =
288 BudgetManager::GetCost(blink::mojom::BudgetOperationType::SILENT_PUSH);
289 if (budget >= cost) {
290 RecordUserVisibleStatus( 258 RecordUserVisibleStatus(
291 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_USED_GRACE); 259 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_USED_GRACE);
292 260 message_handled_closure.Run();
293 BudgetManager* manager = BudgetManagerFactory::GetForProfile(profile_);
294 // Update the stored budget.
295 manager->StoreBudget(origin, budget - cost, message_handled_closure);
296
297 return; 261 return;
298 } 262 }
299 263
300 RecordUserVisibleStatus( 264 RecordUserVisibleStatus(
301 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_GRACE_EXCEEDED); 265 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_GRACE_EXCEEDED);
302 rappor::SampleDomainAndRegistryFromGURL( 266 rappor::SampleDomainAndRegistryFromGURL(
303 g_browser_process->rappor_service(), 267 g_browser_process->rappor_service(),
304 "PushMessaging.GenericNotificationShown.Origin", origin); 268 "PushMessaging.GenericNotificationShown.Origin", origin);
305 269
306 // The site failed to show a notification when one was needed, and they don't 270 // The site failed to show a notification when one was needed, and they don't
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 // Do not pass service worker scope. The origin will be used instead of the 317 // Do not pass service worker scope. The origin will be used instead of the
354 // service worker scope to determine whether a notification should be 318 // service worker scope to determine whether a notification should be
355 // attributed to a WebAPK on Android. This is OK because this code path is hit 319 // attributed to a WebAPK on Android. This is OK because this code path is hit
356 // rarely. 320 // rarely.
357 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( 321 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification(
358 profile_, persistent_notification_id, GURL() /* service_worker_scope */, 322 profile_, persistent_notification_id, GURL() /* service_worker_scope */,
359 origin, notification_data, NotificationResources()); 323 origin, notification_data, NotificationResources());
360 324
361 message_handled_closure.Run(); 325 message_handled_closure.Run();
362 } 326 }
OLDNEW
« no previous file with comments | « chrome/browser/push_messaging/push_messaging_notification_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698