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

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

Issue 2243813002: Rename BackgroundBudgetService to BudgetManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@budget_database
Patch Set: Created 4 years, 4 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
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
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/budget_service/background_budget_service.h" 14 #include "chrome/browser/budget_service/budget_manager.h"
15 #include "chrome/browser/budget_service/background_budget_service_factory.h" 15 #include "chrome/browser/budget_service/budget_manager_factory.h"
16 #include "chrome/browser/engagement/site_engagement_service.h" 16 #include "chrome/browser/engagement/site_engagement_service.h"
17 #include "chrome/browser/notifications/platform_notification_service_impl.h" 17 #include "chrome/browser/notifications/platform_notification_service_impl.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/push_messaging/push_messaging_constants.h" 19 #include "chrome/browser/push_messaging/push_messaging_constants.h"
20 #include "chrome/common/features.h" 20 #include "chrome/common/features.h"
21 #include "chrome/grit/generated_resources.h" 21 #include "chrome/grit/generated_resources.h"
22 #include "components/rappor/rappor_utils.h" 22 #include "components/rappor/rappor_utils.h"
23 #include "components/url_formatter/elide_url.h" 23 #include "components/url_formatter/elide_url.h"
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"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
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. 189 // Get the budget for the service worker.
Peter Beverloo 2016/08/12 12:39:46 nit: origin
harkness 2016/08/15 08:05:41 Done.
190 BackgroundBudgetService* service = 190 BudgetManager* service = BudgetManagerFactory::GetForProfile(profile_);
Peter Beverloo 2016/08/12 12:39:47 nit: s/service/manager/?
harkness 2016/08/15 08:05:41 Done.
191 BackgroundBudgetServiceFactory::GetForProfile(profile_);
192 service->GetBudget( 191 service->GetBudget(
193 origin, 192 origin,
194 base::Bind(&PushMessagingNotificationManager::DidGetBudget, 193 base::Bind(&PushMessagingNotificationManager::DidGetBudget,
195 weak_factory_.GetWeakPtr(), origin, 194 weak_factory_.GetWeakPtr(), origin,
196 service_worker_registration_id, message_handled_closure, 195 service_worker_registration_id, message_handled_closure,
197 notification_needed, notification_shown)); 196 notification_needed, notification_shown));
198 } 197 }
199 198
200 void PushMessagingNotificationManager::DidGetBudget( 199 void PushMessagingNotificationManager::DidGetBudget(
201 const GURL& origin, 200 const GURL& origin,
202 int64_t service_worker_registration_id, 201 int64_t service_worker_registration_id,
203 const base::Closure& message_handled_closure, 202 const base::Closure& message_handled_closure,
204 bool notification_needed, 203 bool notification_needed,
205 bool notification_shown, 204 bool notification_shown,
206 const double budget) { 205 const double budget) {
207 // Record the budget available any time the budget is queried. 206 // Record the budget available any time the budget is queried.
208 UMA_HISTOGRAM_COUNTS_100("PushMessaging.BackgroundBudget", budget); 207 UMA_HISTOGRAM_COUNTS_100("PushMessaging.BudgetManager", budget);
209 208
210 // Get the site engagement score. Only used for UMA recording. 209 // Get the site engagement score. Only used for UMA recording.
211 SiteEngagementService* ses_service = SiteEngagementService::Get(profile_); 210 SiteEngagementService* ses_service = SiteEngagementService::Get(profile_);
212 double ses_score = ses_service->GetScore(origin); 211 double ses_score = ses_service->GetScore(origin);
213 212
214 // Generate histograms for the GetBudget calls which would return "no budget" 213 // Generate histograms for the GetBudget calls which would return "no budget"
215 // or "low budget" if an API was available to app developers. 214 // or "low budget" if an API was available to app developers.
216 double cost = BackgroundBudgetService::GetCost( 215 double cost = BudgetManager::GetCost(BudgetManager::CostType::SILENT_PUSH);
217 BackgroundBudgetService::CostType::SILENT_PUSH);
218 if (budget < cost) 216 if (budget < cost)
219 UMA_HISTOGRAM_COUNTS_100("PushMessaging.SESForNoBudgetOrigin", ses_score); 217 UMA_HISTOGRAM_COUNTS_100("PushMessaging.SESForNoBudgetOrigin", ses_score);
220 else if (budget < 2.0 * cost) 218 else if (budget < 2.0 * cost)
221 UMA_HISTOGRAM_COUNTS_100("PushMessaging.SESForLowBudgetOrigin", ses_score); 219 UMA_HISTOGRAM_COUNTS_100("PushMessaging.SESForLowBudgetOrigin", ses_score);
222 220
223 if (notification_needed && !notification_shown) { 221 if (notification_needed && !notification_shown) {
224 // If the worker needed to show a notification and didn't, check the budget 222 // If the worker needed to show a notification and didn't, check the budget
225 // and take appropriate action. 223 // and take appropriate action.
226 CheckForMissedNotification(origin, service_worker_registration_id, 224 CheckForMissedNotification(origin, service_worker_registration_id,
227 message_handled_closure, budget); 225 message_handled_closure, budget);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 275
278 void PushMessagingNotificationManager::CheckForMissedNotification( 276 void PushMessagingNotificationManager::CheckForMissedNotification(
279 const GURL& origin, 277 const GURL& origin,
280 int64_t service_worker_registration_id, 278 int64_t service_worker_registration_id,
281 const base::Closure& message_handled_closure, 279 const base::Closure& message_handled_closure,
282 const double budget) { 280 const double budget) {
283 DCHECK_CURRENTLY_ON(BrowserThread::UI); 281 DCHECK_CURRENTLY_ON(BrowserThread::UI);
284 282
285 // If the service needed to show a notification but did not, update the 283 // If the service needed to show a notification but did not, update the
286 // budget. 284 // budget.
287 double cost = BackgroundBudgetService::GetCost( 285 double cost = BudgetManager::GetCost(BudgetManager::CostType::SILENT_PUSH);
288 BackgroundBudgetService::CostType::SILENT_PUSH);
289 if (budget >= cost) { 286 if (budget >= cost) {
290 RecordUserVisibleStatus( 287 RecordUserVisibleStatus(
291 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_USED_GRACE); 288 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_USED_GRACE);
292 289
293 BackgroundBudgetService* service = 290 BudgetManager* service = BudgetManagerFactory::GetForProfile(profile_);
Peter Beverloo 2016/08/12 12:39:47 nit: s/service/manager/
harkness 2016/08/15 08:05:41 Done.
294 BackgroundBudgetServiceFactory::GetForProfile(profile_);
295 // Update the stored budget. 291 // Update the stored budget.
296 service->StoreBudget(origin, budget - cost, message_handled_closure); 292 service->StoreBudget(origin, budget - cost, message_handled_closure);
297 293
298 return; 294 return;
299 } 295 }
300 296
301 RecordUserVisibleStatus( 297 RecordUserVisibleStatus(
302 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_GRACE_EXCEEDED); 298 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_GRACE_EXCEEDED);
303 rappor::SampleDomainAndRegistryFromGURL( 299 rappor::SampleDomainAndRegistryFromGURL(
304 g_browser_process->rappor_service(), 300 g_browser_process->rappor_service(),
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 // Do not pass service worker scope. The origin will be used instead of the 350 // Do not pass service worker scope. The origin will be used instead of the
355 // service worker scope to determine whether a notification should be 351 // service worker scope to determine whether a notification should be
356 // attributed to a WebAPK on Android. This is OK because this code path is hit 352 // attributed to a WebAPK on Android. This is OK because this code path is hit
357 // rarely. 353 // rarely.
358 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( 354 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification(
359 profile_, persistent_notification_id, GURL() /* service_worker_scope */, 355 profile_, persistent_notification_id, GURL() /* service_worker_scope */,
360 origin, notification_data, NotificationResources()); 356 origin, notification_data, NotificationResources());
361 357
362 message_handled_closure.Run(); 358 message_handled_closure.Run();
363 } 359 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698