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

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

Issue 1099093003: Push API: Forced notifications should use Notifications database (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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_service_impl.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_service_impl.h" 5 #include "chrome/browser/push_messaging/push_messaging_service_impl.h"
6 6
7 #include <bitset> 7 #include <bitset>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/barrier_closure.h" 10 #include "base/barrier_closure.h"
(...skipping 19 matching lines...) Expand all
30 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
31 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
32 #include "chrome/grit/generated_resources.h" 32 #include "chrome/grit/generated_resources.h"
33 #include "components/content_settings/core/browser/host_content_settings_map.h" 33 #include "components/content_settings/core/browser/host_content_settings_map.h"
34 #include "components/content_settings/core/common/permission_request_id.h" 34 #include "components/content_settings/core/common/permission_request_id.h"
35 #include "components/gcm_driver/gcm_driver.h" 35 #include "components/gcm_driver/gcm_driver.h"
36 #include "components/pref_registry/pref_registry_syncable.h" 36 #include "components/pref_registry/pref_registry_syncable.h"
37 #include "components/rappor/rappor_utils.h" 37 #include "components/rappor/rappor_utils.h"
38 #include "content/public/browser/browser_context.h" 38 #include "content/public/browser/browser_context.h"
39 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
40 #include "content/public/browser/notification_database_data.h"
41 #include "content/public/browser/platform_notification_context.h"
40 #include "content/public/browser/render_frame_host.h" 42 #include "content/public/browser/render_frame_host.h"
41 #include "content/public/browser/service_worker_context.h" 43 #include "content/public/browser/service_worker_context.h"
42 #include "content/public/browser/storage_partition.h" 44 #include "content/public/browser/storage_partition.h"
43 #include "content/public/browser/web_contents.h" 45 #include "content/public/browser/web_contents.h"
44 #include "content/public/common/child_process_host.h" 46 #include "content/public/common/child_process_host.h"
45 #include "content/public/common/content_switches.h" 47 #include "content/public/common/content_switches.h"
46 #include "content/public/common/platform_notification_data.h" 48 #include "content/public/common/platform_notification_data.h"
47 #include "content/public/common/push_messaging_status.h" 49 #include "content/public/common/push_messaging_status.h"
48 #include "third_party/skia/include/core/SkBitmap.h" 50 #include "third_party/skia/include/core/SkBitmap.h"
49 #include "ui/base/l10n/l10n_util.h" 51 #include "ui/base/l10n/l10n_util.h"
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 Unregister(app_id_guid, message.sender_id, UnregisterCallback()); 269 Unregister(app_id_guid, message.sender_id, UnregisterCallback());
268 break; 270 break;
269 } 271 }
270 RecordDeliveryStatus(status); 272 RecordDeliveryStatus(status);
271 } 273 }
272 274
273 void PushMessagingServiceImpl::RequireUserVisibleUX( 275 void PushMessagingServiceImpl::RequireUserVisibleUX(
274 const GURL& requesting_origin, int64 service_worker_registration_id) { 276 const GURL& requesting_origin, int64 service_worker_registration_id) {
275 #if defined(ENABLE_NOTIFICATIONS) 277 #if defined(ENABLE_NOTIFICATIONS)
276 // TODO(johnme): Relax this heuristic slightly. 278 // TODO(johnme): Relax this heuristic slightly.
277 PlatformNotificationServiceImpl* notification_service = 279 content::PlatformNotificationContext* notification_context =
278 PlatformNotificationServiceImpl::GetInstance(); 280 content::BrowserContext::GetStoragePartitionForSite(
279 // Can't use g_browser_process->notification_ui_manager(), since the test uses 281 profile_, requesting_origin)->GetPlatformNotificationContext();
280 // PlatformNotificationServiceImpl::SetNotificationUIManagerForTesting. 282 notification_context->ReadAllNotificationDataForServiceWorkerRegistration(
Peter Beverloo 2015/04/21 18:06:17 We're on the UI thread here, right? We need to cal
johnme 2015/04/23 16:51:17 Done (heh, this was just an early work in progress
281 // TODO(peter): Remove the need to use both APIs here once Notification.get() 283 requesting_origin, service_worker_registration_id,
282 // is supported. 284 base::Bind(&PushMessagingServiceImpl::DidGetNotificationsShowing,
283 int notification_count = notification_service->GetNotificationUIManager()-> 285 weak_factory_.GetWeakPtr(),
284 GetAllIdsByProfileAndSourceOrigin(profile_, requesting_origin).size(); 286 requesting_origin, service_worker_registration_id));
287 #endif // defined(ENABLE_NOTIFICATIONS)
288 }
289
290 void PushMessagingServiceImpl::DidGetNotificationsShowing(
291 const GURL& requesting_origin, int64 service_worker_registration_id,
292 bool success, const std::vector<content::NotificationDatabaseData>& data) {
285 // TODO(johnme): Hiding an existing notification should also count as a useful 293 // TODO(johnme): Hiding an existing notification should also count as a useful
286 // user-visible action done in response to a push message - but make sure that 294 // user-visible action done in response to a push message - but make sure that
287 // sending two messages in rapid succession which show then hide a 295 // sending two messages in rapid succession which show then hide a
288 // notification doesn't count. 296 // notification doesn't count.
297 int notification_count = success ? data.size() : 0;
289 bool notification_shown = notification_count > 0; 298 bool notification_shown = notification_count > 0;
290 299
291 bool notification_needed = true; 300 bool notification_needed = true;
292 // Sites with a currently visible tab don't need to show notifications. 301 // Sites with a currently visible tab don't need to show notifications.
293 #if defined(OS_ANDROID) 302 #if defined(OS_ANDROID)
294 for (auto it = TabModelList::begin(); it != TabModelList::end(); ++it) { 303 for (auto it = TabModelList::begin(); it != TabModelList::end(); ++it) {
295 Profile* profile = (*it)->GetProfile(); 304 Profile* profile = (*it)->GetProfile();
296 content::WebContents* active_web_contents = 305 content::WebContents* active_web_contents =
297 (*it)->GetActiveWebContents(); 306 (*it)->GetActiveWebContents();
298 #else 307 #else
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 GetNotificationsShownByLastFewPushes( 349 GetNotificationsShownByLastFewPushes(
341 service_worker_context, service_worker_registration_id, 350 service_worker_context, service_worker_registration_id,
342 base::Bind(&PushMessagingServiceImpl::DidGetNotificationsShown, 351 base::Bind(&PushMessagingServiceImpl::DidGetNotificationsShown,
343 weak_factory_.GetWeakPtr(), 352 weak_factory_.GetWeakPtr(),
344 requesting_origin, service_worker_registration_id, 353 requesting_origin, service_worker_registration_id,
345 notification_shown, notification_needed)); 354 notification_shown, notification_needed));
346 } else { 355 } else {
347 RecordUserVisibleStatus( 356 RecordUserVisibleStatus(
348 content::PUSH_USER_VISIBLE_STATUS_NOT_REQUIRED_AND_NOT_SHOWN); 357 content::PUSH_USER_VISIBLE_STATUS_NOT_REQUIRED_AND_NOT_SHOWN);
349 } 358 }
350 #endif // defined(ENABLE_NOTIFICATIONS)
351 } 359 }
352 360
353 static void IgnoreResult(bool unused) { 361 static void IgnoreResult(bool unused) {
354 } 362 }
355 363
356 void PushMessagingServiceImpl::DidGetNotificationsShown( 364 void PushMessagingServiceImpl::DidGetNotificationsShown(
357 const GURL& requesting_origin, int64 service_worker_registration_id, 365 const GURL& requesting_origin, int64 service_worker_registration_id,
358 bool notification_shown, bool notification_needed, 366 bool notification_shown, bool notification_needed,
359 const std::string& data, bool success, bool not_found) { 367 const std::string& data, bool success, bool not_found) {
360 content::ServiceWorkerContext* service_worker_context = 368 content::ServiceWorkerContext* service_worker_context =
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 CONTENT_SETTING_ALLOW; 804 CONTENT_SETTING_ALLOW;
797 } 805 }
798 806
799 gcm::GCMDriver* PushMessagingServiceImpl::GetGCMDriver() const { 807 gcm::GCMDriver* PushMessagingServiceImpl::GetGCMDriver() const {
800 gcm::GCMProfileService* gcm_profile_service = 808 gcm::GCMProfileService* gcm_profile_service =
801 gcm::GCMProfileServiceFactory::GetForProfile(profile_); 809 gcm::GCMProfileServiceFactory::GetForProfile(profile_);
802 CHECK(gcm_profile_service); 810 CHECK(gcm_profile_service);
803 CHECK(gcm_profile_service->driver()); 811 CHECK(gcm_profile_service->driver());
804 return gcm_profile_service->driver(); 812 return gcm_profile_service->driver();
805 } 813 }
OLDNEW
« no previous file with comments | « chrome/browser/push_messaging/push_messaging_service_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698